Archived

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

BinaryZero

x rotation

Recommended Posts

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);

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites