Sign in to follow this  

Xna Sprite Rotation Problem

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

This may not be a problem just how the rotation works but unsure so i came here to ask. Well i got this texture and when i rotate it by making origin the center of the image it rotates fine but when i use the origin of 0,0 as the vector to rotat it on the texture rotates in a small circle around the point. Well I want to rotate the texture right on a pinpoint without it moving off in an orbit around the point. Is that possible? Thanks, Much appreciated, Anthony out

Share this post


Link to post
Share on other sites
You did basically answer you own question. The origin sets the point the sprite will rotate around. If you leave it at the default the sprite will rotate around the 0,0 point, if you set it to the centre then it will rotate around the centre... That's just the way it works.

Share this post


Link to post
Share on other sites
All I want to do is turn a texture at a point and when it turns its a different angle of course but its still fixed at a point. I dont want the image to orbit around a point, I want the image to turn at a point. AT being the operative word.

Let me make an example. hmmm now what kind of example can I make...lets say theres a crank to turn a gear. Well the crank turns but doesnt leave its central point. If the crank orbited the point it would be in the wrong positions and look weird LOl.

Anthony out
Thanks for the replies.

Share this post


Link to post
Share on other sites
Quote:
Original post by writtensouls
All I want to do is turn a texture at a point and when it turns its a different angle of course but its still fixed at a point. I dont want the image to orbit around a point, I want the image to turn at a point. AT being the operative word.


So rotate around the center of the texture. Normally, the process here is to translate your object to the origin, perform the rotation, and translate back.

Share this post


Link to post
Share on other sites
Maybe i should just give up lol no one seems to get what im saying. Well Rotate is not the function i need obviously. Now that i understand what it does it just isnt going to work. I never thought it would be this difficult. with a circle rotating at the center it doesnt move from its spot and it spins, Yay. lol and if you rotate a line from the center it will look like a helicoper yay lol. ok my problem comes in when you dont want that to happen.

say you have a arm connected to a joint. Well the arm turns at the joint. The arm is connected to the joint. it moves but stays connected to the joint. Now a Arm doesnt orbit around the joint Lol when we move our arm it doesnt leave the joint in orbit lol. thats just wrong, not right, evil. well that is my problem. I want the point to be as a joint that it turns at. I dont want the arm to orbit around the joint like some demented planet LOL

Anthony out

Share this post


Link to post
Share on other sites
Quote:
Original post by writtensouls
say you have a arm connected to a joint. Well the arm turns at the joint. The arm is connected to the joint. it moves but stays connected to the joint. Now a Arm doesnt orbit around the joint Lol when we move our arm it doesnt leave the joint in orbit lol. thats just wrong, not right, evil. well that is my problem. I want the point to be as a joint that it turns at. I dont want the arm to orbit around the joint like some demented planet LOL


Right, so translate your object such that the pivot point is at the origin, perform the rotation, and translate back...

Share this post


Link to post
Share on other sites
so basically do the rotation outside of the spritebatch.draw function. So rotate it outside of draw then draw it at the point I want? Isnt that somewhat slow? Well thanks I think that helps a lot if i understand right.

Anthony out

Share this post


Link to post
Share on other sites
Yes, what Driv3MeFar said. For example:


Matrix transformation = Matrix.CreateTranslation(new Vector3(distanceToOrigin.X, distanceToOrigin.Y, distanceToOrigin.Z)) * Matrix.CreateRotationZ(rotationAmount) * Matrix.CreateTranslation(new Vector3(-distanceToOrigin.X, -distanceToOrigin.Y, -distanceToOrigin.Z));



Then just translate your points with the transformation matrix.

Share this post


Link to post
Share on other sites
ok thanks for all the help everyone. I'm new to programming and I dont know about matrices yet so i guess ill have to learn about them before I can do what i wanted. Math sucks lol. You use matricies for 2d stuff too? oh wells. thanks now i know what i was doing wrong. :D

Anthony out

Share this post


Link to post
Share on other sites
I think I know what you mean:

Texture2D image;
Vector2 origin;

origin = new Vector2(image.width/2, image.height/2);

Now in draw you do something like this:

batch.Draw(tex, Position, null, Color.White, angle, origin, 1.0f, SpriteEffects.None, 1.0f);

You'll have to use SpriteBatch's 5th to 7th overload to have access to rotation.
Just make sure that your origin is the center of the image like people before have said.

Share this post


Link to post
Share on other sites

This topic is 3846 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this