x rotation

Started by
7 comments, last by BinaryZero 21 years, 10 months ago
I am 17 yeats old from london, I am currently learning 3d and am now coding the s axis rotation. I have coded the rotation and it seems to be working fine but theres a bug!!! for some reason the poly seems to be moving out of position as it rotates, my prime suspect was my rotation formula but evena after using someone else''s formula from the net it did the same thing. Could someone please help :-( here is a sample of my code for the rotation of one vertex. I am using psx primitives as a friend of mine simulated the psx chip. thanx! your help would be greatly appreciated and would save me nights of sleep. if (MyRotAngle<360)MyRotAngle+=0.1f; else MyRotAngle=0.0f; // X Rotations CurrVPos.x=VPos0.x; CurrVPos.y=VPos0.y; CurrVPos.z=VPos0.z; VPos0.y=(CurrVPos.x*0 + CurrVPos.y*rcosf(MyRotAngle) +currVPos.z*rsinf(MyRotAngle)); VPos0.z=(CurrVPos.x*0 - CurrVPos.y*rsinf(MyRotAngle) + CurrVPos.z*rcosf(MyRotAngle)) + 150; ft4.x0=((VPos0.x*256)/VPos0.z)+50; ft4.y0=((VPos0.y*256)/VPos0.z);
Advertisement
Don''t rsinf() and rcosf() expect you to give them radians, and not degres ?
yeagh usually but i wrote my own version that uses degrees instead of radeons. any other suggestions?
yeagh usually but i wrote my own version that uses degrees instead of radeons. any other suggestions?
That''s not a bug, that''s what''s called a pivot. By default, a simple rotation (without translation) will rotate your object around the origin of your coordinate system, and that is 0,0,0. If your object is positioned somewhere else, it will appear to move while rotating, since the rotation pivot is far way.

To solve it, you have to reposition the pivot: translate (move) your object back to the origin, rotate, and move it back where it originally was.
1. Rotate objects at (0,0,0) then...
2. Place them out in your scene.

think about this:
What happends if you translate (position the object) then rotate..or rotate & then translate (one of theese produces wrong result)??
______________________________Only dead fish go with the main-stream.
thanx, could someone please verify that my formula is correct
quote:Original post by BinaryZero

VPos0.y=(CurrVPos.x*0 + CurrVPos.y*rcosf(MyRotAngle) +currVPos.z*rsinf(MyRotAngle)); VPos0.z=(CurrVPos.x*0 - CurrVPos.y*rsinf(MyRotAngle) + CurrVPos.z*rcosf(MyRotAngle)) + 150;


- huurr...(Shiver) -

Use matrices instead. If you don't know them, learn! It will pay off...


[edited by - ekas78 on June 9, 2002 10:27:29 PM]
______________________________Only dead fish go with the main-stream.
He is actually using a (limited) matrix transform, perhaps without even knowing it. But the equation is not correct.

P'' = MP

Where M is the rotation matrix around the x axis, defined as:
1  0  0  00  c -s  00  s  c  00  0  0  1 

c = cos(angle), s = sin(angle)

If we multiply that out, we get:

x'' = x
y'' = y*cos(angle) - z*sin(angle)
z'' = y*sin(angle) + z*cos(angle)

But I would also strongly recommend looking up matrix transforms. It will definitely pay off...

/ Yann

This topic is closed to new replies.

Advertisement