# how do i optimize my 3d rotations?

Started by Moe, Feb 04 2000 05:04 PM

10 replies to this topic

###
#1
Crossbones+ - Reputation: **1254**

Posted 04 February 2000 - 05:04 PM

how can i optimize my 3d rotation?
NewY = (OldY*Cos(ThetaX)) - (OldZ*Sin(ThetaX)) ** X axis rotation **
NewZ = (OldZ*Cos(ThetaX)) + (OldY*Sin(ThetaX))
(Copy NewY and NewZ into OldY and OldZ)
is it faster to use some sort of a lookup table for calculating the cosines and sines on the fly? how would i do this?

###
#3
Members - Reputation: **122**

Posted 05 February 2000 - 08:28 AM

You just make two global arrays

Sine[360]

Cosine[360]

and have an initialization loop:

for(int i=0; i < 360; i++)

{

Sine[ i ] = sin( i * PI /180); // I think thats the radian conversion

Cosine[ i ] = cos(i * PI / 180);

}

Edited by - logistix on 2/5/00 2:31:47 PM

Sine[360]

Cosine[360]

and have an initialization loop:

for(int i=0; i < 360; i++)

{

Sine[ i ] = sin( i * PI /180); // I think thats the radian conversion

Cosine[ i ] = cos(i * PI / 180);

}

Edited by - logistix on 2/5/00 2:31:47 PM

###
#5
Members - Reputation: **204**

Posted 05 February 2000 - 10:42 PM

What are you coding in/with/for?

If you are using DirectX then that comes with some helper functions for matrix math, but they are pretty basic routines.

You are worrying too much about optimization at this stage, I take it you are just starting out in 3d programming so make everything math intensive and do not feel guilty about it!

Remember that floating point math is VERY fast these days, there are cases against using look up tables that state that if your look up table is not in cpu cache memory then it would take the processor longer to find the look up result than it would just to do the damn calculation.

Get the code working first, optimize later. And after every optimization test like hell!

Bye

Matt

If you are using DirectX then that comes with some helper functions for matrix math, but they are pretty basic routines.

You are worrying too much about optimization at this stage, I take it you are just starting out in 3d programming so make everything math intensive and do not feel guilty about it!

Remember that floating point math is VERY fast these days, there are cases against using look up tables that state that if your look up table is not in cpu cache memory then it would take the processor longer to find the look up result than it would just to do the damn calculation.

Get the code working first, optimize later. And after every optimization test like hell!

Bye

Matt

###
#6
Members - Reputation: **122**

Posted 06 February 2000 - 02:11 AM

Hi Moe,

take a look at Reference/Programming section, then select Graphics/3D Graphics and Theory. Here is a nice article about doing a rotation using quaternions called Orientation with Quaternions and another one called Rotating Objects Using Quaternions.

Edited by - QWERTY on 2/6/00 8:16:52 AM

take a look at Reference/Programming section, then select Graphics/3D Graphics and Theory. Here is a nice article about doing a rotation using quaternions called Orientation with Quaternions and another one called Rotating Objects Using Quaternions.

Edited by - QWERTY on 2/6/00 8:16:52 AM

###
#7
Crossbones+ - Reputation: **1254**

Posted 07 February 2000 - 12:08 PM

wow, thanks.

I am using Direct X 7. I ordered a book on it a week or so ago. It should be here in 3-4 weeks

I think you''re right about getting this thing off the ground before i optimize it.

Thanks for the refrences, i will be sure to check them out.

I had a few small doubts about the lookup table idea. thanks for clarifying things for me.

does anyone here know any good books on graphics programming?

-Moe-

I am using Direct X 7. I ordered a book on it a week or so ago. It should be here in 3-4 weeks

I think you''re right about getting this thing off the ground before i optimize it.

Thanks for the refrences, i will be sure to check them out.

I had a few small doubts about the lookup table idea. thanks for clarifying things for me.

does anyone here know any good books on graphics programming?

-Moe-

###
#8
Members - Reputation: **122**

Posted 07 February 2000 - 12:15 PM

I tried to make a lookup table for my sin/cos/etc. I had four 720 element arrays of floats. It took just as long to pull the value out of the array as it did to do the calculation. Plus, if you ever use hardware acceleration, you can push the work over to the graphics card.

E:cb woof!

E:cb woof!

###
#10
Crossbones+ - Reputation: **1254**

Posted 08 February 2000 - 12:29 PM

thanks. i just got windows 98 programming from the ground up, and sams teach yourself direct x 7 in 24 hours. i think i will be pretty busy for the next couple months. who knows, i could get around to reading your sugestion. the only thing is, is i like the code examples. i think they help me conciderably.

###
#11
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 09 February 2000 - 08:04 AM

A) 3D cards don''t perform sin/cos/tan etc. in hardware. This is wrong. Calling sin/cos are scalar functions in MSVCRT.DLL if using MSVC. You can take a look at the the developer.intel.com pages for fast libs for math/matrix stuff but _only_ bother if you really know what you are doing.

B) The easiest code opt to what you posted is the most obvious. You calculate the sin and cos of X twice each time. Instead calculate each once and throw into a local and then use that local for the mults.

B) The easiest code opt to what you posted is the most obvious. You calculate the sin and cos of X twice each time. Instead calculate each once and throw into a local and then use that local for the mults.