• Create Account

# Confused with matrices in XNA

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1dustin321  Members   -  Reputation: 154

Like
0Likes
Like

Posted 26 August 2012 - 11:32 AM

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.

### #2Tom KQT  Members   -  Reputation: 1666

Like
0Likes
Like

Posted 27 August 2012 - 01:06 AM

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.

### #3BCullis  Crossbones+   -  Reputation: 1943

Like
0Likes
Like

Posted 27 August 2012 - 08:38 AM

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 ;)
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

### #4CC Ricers  Members   -  Reputation: 1486

Like
0Likes
Like

Posted 27 August 2012 - 09:39 AM

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, 27 August 2012 - 09:39 AM.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS