Jump to content
  • Advertisement
Sign in to follow this  
dustin321

Confused with matrices in XNA

This topic is 2302 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 read several detailed tutorials about matrices, but I never can get them to work right. In my game, the player's position on the map is a Vector3 at the player's head . This vector is altered by keyboard input, so for example if Keys.W is pressed then position.Z+=speed*time since last frame. Then I create a new view matrix each frame with the new player position. Is this a good way to do a first person camera? It never seems to work right for me. Even without doing rotations, it rotates all over the place and goes out of view.

Share this post


Link to post
Share on other sites
Advertisement
I think we would need more code from you to be able to tell what are you doing wrong.

In theory, what you said should work, so if it doesn't then you have some error somewhere. But of course it's only a very simple implementation, I think you are aware of the fact that you are not moving the player "forward" (in the direction he's facing) but always on the Z axis.

We really need more info from you, not just an example of what the W key is doing.

Share this post


Link to post
Share on other sites
I've run into this kind of problem before, and it always stemmed from my camera/player's movement update function. If you have a method that updates position or rotation every frame based on another vector (modified by player input), make sure you zero out the referenced vector after you create the transformation matrix.

That's just a blind guess though, so like Tom mentioned, some code would be helpful ;)

Share this post


Link to post
Share on other sites
I don't know whether your problem is related to the order of matrix operations you're doing, because matrix multiplication is not commutative. Also I don't quite understand what you mean when you say the first-person camera goes "out of view" from itself. But as a rule of thumb, for most cases you would need to follow the S-R-T mnemonic, that is, Scale, Rotate, then Translate in that order. This would help keep your camera from rotating around a point that's different from its own location. Edited by CC Ricers

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!