• Create Account

## how do i optimize my 3d rotations?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1Moe  Members

1255
Like
Likes
Like

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?

### #2zd97le  Members

122
Like
Likes
Like

Posted 04 February 2000 - 10:31 PM

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

### #3logistix  Members

122
Like
Likes
Like

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

### #4Moe  Members

1255
Like
Likes
Like

Posted 05 February 2000 - 10:45 AM

would lookup tables be faster?

where can i learn about quaternarians?

### #5matibee  Members

204
Like
Likes
Like

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

### #6QWERTY  Members

122
Like
Likes
Like

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

### #7Moe  Members

1255
Like
Likes
Like

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-

### #8dog135  Members

122
Like
Likes
Like

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!

### #9Vetinari  Members

133
Like
Likes
Like

Posted 07 February 2000 - 05:51 PM

::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

### #10Moe  Members

1255
Like
Likes
Like

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

Likes

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.