Jump to content
  • Advertisement
Sign in to follow this  
programmermattc

Problem with Screen Position and Rotation (XNA)

This topic is 2833 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 am having an issue in an asteroids-style game where theplayer will pass the screen borders and the code makes them appear on the opposite screen edge (for example, passing too far to the right makes you appear on the left).

However, it seems like the movement vector I use to define which was to go gets all messed up until I rotate and fly around for awhile. Here is some of my ship rotation code where I believe the issue is happening:


private void UpdateRotationData(KeyboardState kbs)
{
if (kbs.IsKeyDown(Keys.A))
{
this.Rotation -= MathHelper.ToRadians(5);
float translatedRot = MathHelper.ToRadians(MathHelper.ToDegrees
(this.Rotation) + 240);
Matrix transform = new Matrix();
transform = Matrix.CreateTranslation(new Vector3(this.Position, 1.0f))
* Matrix.CreateRotationZ(translatedRot);
_movementDir = Vector2.Transform(_movementDir, transform);
_movementDir.Normalize();
}

if (kbs.IsKeyDown(Keys.D))
{
this.Rotation += MathHelper.ToRadians(5);
float translatedRot = MathHelper.ToRadians(MathHelper.ToDegrees
(this.Rotation) + 240);
Matrix transform = new Matrix();
transform = Matrix.CreateTranslation(new Vector3(this.Position, 1.0f))
* Matrix.CreateRotationZ(translatedRot);
_movementDir = Vector2.Transform(_movementDir, transform);
_movementDir.Normalize();
}
}


The 240 offset in the rotation is compensation for the movement vector (which, while typing this I realized a solution for).

Does anyone see why, if the this.Position changes to the other side of the screen, the transformation of this vector wouldn't work properly?

Share this post


Link to post
Share on other sites
Advertisement
I only skimmed your code so my reply may not be particularly relevant, but make sure you're combining your translation and rotation transforms in the right order, and also make sure that you're treating the movement vector as a vector rather than a point when you transform it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!