#### Archived

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

# x rotation

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

## 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 on other sites
Don''t rsinf() and rcosf() expect you to give them radians, and not degres ?

##### Share on other sites
yeagh usually but i wrote my own version that uses degrees instead of radeons. any other suggestions?

##### Share on other sites
yeagh usually but i wrote my own version that uses degrees instead of radeons. any other suggestions?

##### 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 on other sites
1. Rotate objects at (0,0,0) then...
2. Place them out in your scene.

What happends if you translate (position the object) then rotate..or rotate & then translate (one of theese produces wrong result)??

##### Share on other sites
thanx, could someone please verify that my formula is correct

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

• 36
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631359
• Total Posts
2999545
×