Home | Forums | What's new | Resources | |
Help the Newbie |
Quick Man - Oct 23, 2005 |
RockinB | Oct 23, 2005 | ||||||||||||||||||||||
Hi Quick Man! The function slCrossProduct(VECTOR u, VECTOR v) is wrong in at least 2 concerns: Returning a pointer to local variable VECTOR cross does not work to return the result, as the content will be lost after the function exits. Instead do this: slCrossProduct(VECTOR u, VECTOR v, VECTOR cross) The normalization is wrong, it will overwrite the computed cross vector completely. Normalization is done when FIXED len = slMulFX(cross[X], cross[X]) + slMulFX(cross[Y], cross[Y]) + slMulFX(cross[Z], cross[Z]) > toFIXED(1.0) then it's normalized this way: len = slSquartFX(l); cross[X] = slDivFX(len, cross[X]); cross[Y] = slDivFX(len, cross[Y]); cross[Z] = slDivFX(len, cross[Z]); But that's just the mathematics behind, I would try to use a CORDIC algorithm, maybe I did it somewhere.
Oh, it does got a function for this:
Code:
But I don't know if the vector is already normalized. Okay, let's go on in the code... These vectors have no length in initialization, I inserted the length here: (note: you can't use global variables to set the length, that's why #define)
Code:
You can do this assignment only when declaring variables:
Code:
Furthermore, this will potentially not compute what you want: toFIXED(m/nx). The macro toFIXED() is used best with constant arguments, not variables. So the C compiler can do the floating point computation. A POINT has got no 4th component. And this here: height[((n-1)*nz)+m] results in a negative index when n = 0. Instead do this:
Code:
Now let's have a look on this:
Code:
First VECTOR is a structure, you can't apply integer arithmetics like done here:
Code:
But when you use slNormalVector(), you don't have to care about component wise arithmetics. Okay, I'll stop here now. Assignments for poly[t] and attr[t] are wrong, as they are declaration style. I'm kind of confused because you mixed the declarations with code. |