IMO this is really overkill as it outputs 32-bits results. A simple 6-bits + sign COS LUT has always been enough for me to do 3D stuffs (by that I mean cos(0) = 64, sin(x) = cos(x - 64) ).
what sort of routines do you use, mat ref?
I use to use a 256-entries LUT, then pass the angle in A.


Code:
sin:
 sub 64
cos:
 ld l,a
 ld h,0
 ld de, cosLUT
 add hl,de
 ld a,(hl)
 ret
cosLUT:
...
LUT stands for Lookup Table, right?
Exactly.
ACagliano wrote:
LUT stands for Lookup Table, right?
I'm sorry to do this for you, but I need to draw the line somewhere:

http://lmgtfy.com/?q=lut+programming&l=1
Ok, and my last question: this one's for Tari:

As per the wiki on the rotation matrix, should I be aiming to use the big one (the 3 x 3 matrix), or the R = with the identity and tensor product? And if I have a unit vector matrix and put it through that formula, I come out with a unit vector matrix as well, correct?

(sorry, if it seems these are dumb questions..i just started looking over the wiki and want to make sure my understanding is correct)

@Kerm... yeah, i seem to forget about Google every now and again.
If you want to rotate vertices around the X and Y axis, use this :


Code:
Rxy =
[ cosY                          0      sinY                         ]
[ (cos(X-Y) - cos(X+Y))/2   cosX   (-sin(X-Y) - sin(X+Y))/2 ]
[ (sin(X-Y) - sin(X+Y))/2     sinX    (cos(X-Y) + cos(X+Y))/2 ]

With X and Y being the rotation angles between the X and Y axis.
A 3x3 rotation matrix is enough in my opinion. You can just store the position(or translation) vector separately.
Well, I guess I'll only be moving either left to right, or up and down. So what is that, pitch and yaw? (x, and y it seems to be)

What if I don't have an angle of rotation around that axis, but only a set of vectors? Can I work with that, or must I get the angle out? Or should I maintain an angle variable?

ps: I'm creating a system in which you can rotate only in increments of 5 degrees.
What I always do is maintening angle variables, this way you just use them as-is in the matrix and you don't need any extra calculation.
So maintain an angle of rotation around x and around y, use the sin cos routine from earlier in the thread, and use a LUT. Anything I'm missing lol?
Yes Razz you mention a LUT and cos/sin routines, but your LUT IS your cos/sin routine ! Also, use the 3*3 matrix I showed you.
Ok. Sounds good. And for angles, -180 - 180? or 0-360? But I know either way, a 1 byte number can't fit that. So should I do an incremented system where an angle of 0 is 0, an angle of 1 is 5, an angle of 2 is 10, etc., where the conversion is 5n = angle.?
You can fit a 256-bytes cos LUT and one-byte angles together pretty easily, so that all angles are between -128 and 127. On top of that, let the cos values be -64 to 64 so that you don't lose precision - compared to -128,127.
Wait... but, what if you are making rotation of 180 backwards? The signed byte won't go that high... I'm not sure I'm following lol

Also, in your routine, each entry in the LUT is a single byte. How do you do decimal support then?

And lastly, its [unit vectors] * [3x3 rotation] = [new unit vectors], where the unit vector matrices are 1 row by 3 column, right?
ACagliano wrote:
Wait... but, what if you are making rotation of 180 backwards? The signed byte won't go that high... I'm not sure I'm following 0x5
Instead of using standard degrees (360 degrees in a circle), we define a new unit where a circle is 256 "units". So if you have what we usually call a 180 degree turn, that translates into 128 "units", so you just look up 128 (or -128) in the LUT.
So essentially, 256 units equals 360 degrees, and each unit is actually like around a degree and a half?
You don't understand Razz you're trying to use angles as degrees, which are -180 to 180 ; I'm saying you should use angles between -128 and 127, let's call them byte degrees. So 180 degrees = pi radians = 128 byte degrees.

Now let's say you want to have the cosine of -90°. In byte degrees, this is -64. Since your LUT holds 256 bytes, you use the angle as an unsigned offset. So cos(-64 byte degrees) = 192th entry of the LUT.

Since the cos LUT is made of values between -64 and 64, each time you multiply a value by a cosine, you must divide the result by 64. This way, cos(0) = 64 acts as 1, and anything under 64 and over -64 act as decimal values.

And yes to your last question.

EDIT : 3h long edit session >_> this is the answer to over 2 posts above.
Ok, so I have that understood...

Now, onto result... the result is what? An 8.8 fixed point? Or a 1-byte integer?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement