• Advertisement

Archived

This topic is now archived and is closed to further replies.

how do i optimize my 3d rotations?

This topic is 6556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Hi there. I saw your post and i wanted to tell you that you should use matrices or quartenions. You can also have 2 lookup tables for sine and cosine.Have to go now bye

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
would lookup tables be faster?

where can i learn about quaternarians?
what about matrices?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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-

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
::does anyone here know any good books on graphics programming?

Check out Real Time Rendering. No code, all graphics theory. Sometimes tough though, know your math.

Mike

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

  • Advertisement