Jump to content
• Advertisement

Archived

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

Object rotation...

This topic is 6083 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

I have make a demo, when you can move some objets with keyboard, but i want to the models to rotate for te position yo are going. If you press left, the model will go to left and will rotate at the same time, and when the model is rotated to the left, the rotate need to stop. I have make some demos, but i cant do thsi correct...

Share this post

Share on other sites
Advertisement
I don''t know if I understood your question correctly, but this is the code I use to move the object in the direction it is facing:

playerTank->TankBody->Pos.x -= 1.5*FPS.speedfactor * (float) sin(playerTank->TankBody->Rotation.y);
playerTank->TankBody->Pos.y += 1.5*FPS.speedfactor * (float) sin(playerTank->TankBody->Rotation.x);
playerTank->TankBody->Pos.z -= 1.5*FPS.speedfactor * (float) cos(playerTank->TankBody->Rotation.y) * (float) cos(playerTank->TankBody->Rotation.x);

where Pos and Rotation are vectors(float x,y,z).

FPS.speedfactor is what I use to make the object move at the same speed on different computers...

Share this post

Share on other sites
I'm assuming this is 3D. If you are using matrices for your rotation, it sounds like you might need to switch the order that you are multiplying the matrices. For example if you have something like: playerMatrix = playerMatrix * rotationMatrix, change it to: playerMatrix = rotationMatrix * playerMatrix. Matrix multiplication is not commutative.

Edited by - KrazeIke on February 24, 2002 3:36:34 PM

Share this post

Share on other sites
Man I dont understand your code correctly..

What I want to do is, if you press left th model will rotate at left, and move to left at the same time, but if you press left, and dont wait the model to rotate all, and press right, iwill rotate ro right, and will move to right...

And if you press up, and left at the same time, it will move to upper left... It will rotate at the point e move, when its point to upper left its only move, dont rotate more...

Share this post

Share on other sites
I make the rotate with matrizes like this:

Object->Rotate(x,y,z).
if(x)
{
// Rotaciona ao redor do eixo x
D3DXMatrixRotationX(&objMatTT, x);
objMatR *= objMatTT;
}

And move with vectors:

Object->Move(D3DXVECTOR3 Vector)

And I have one vector with the posiiton of the object.

D3DXVECTOR3 objPos;

Share this post

Share on other sites
I''m still not sure what you mean. Do you mean that after the object has been rotated a certain amount, it will stop rotating, even though the user is still telling it to rotate? Like limiting the amount of rotation?

If that''s what you mean, you could keep track of a total rotation variable by adding the rotation value to it each frame and then not let the object rotate if the total rotation is greater than a given value. I have no idea if this is what you want, though.

Share this post

Share on other sites
Yes. If you press left the model will rotate to left and move to left at the same time, when the modelare rotated, they will only move to left.

I have tried but I can''t make a good function for this.!

If anyone can post a code to do this for me.

Share this post

Share on other sites
totalX += x;

if (totalX > maxX)
{
x -= totalX - maxX;
totalX = maxX;
}
else if (totalX < minX)
{
x -= totalX - minX;
totalX = minX;
}

if(x)
{
// Rotaciona ao redor do eixo x
D3DXMatrixRotationX(&objMatTT, x);
objMatR *= objMatTT;
}

You must store a totalX for each object. minX and maxX are the minimum and maximum rotation.

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632992
• Total Posts
3009755
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!