strafe left / right

Started by
7 comments, last by Trienco 19 years, 7 months ago
Hi all, The translation part of the view matrix is in position _41, _42 and _43, these being x,y,z respectively. Am I right in thinking that if I was to add or subtract a value from ViewMatrix._41, the view would strafe left/right ? Any help is much appreciated. Steve

If it isn't working, take a bath, have a think and try again...

Advertisement
no, im pretty sure it would move along the x, y, and z axis, to make it strafe left and right, youd need to MULTIPLY it by a matrix which you had donet that to (unfortunately i dont know if its AB or BA, i dont know, try it out)

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Thanks Dan,

I'm confused with this to tell you the truth. I'm trying to implement a first person camera in dx and just trying to understand the math behind it - with not much success. Why do you think by adding a value to _41 would make it move along x, y and z ? I'm confused ?

Many thanks,
Steve

If it isn't working, take a bath, have a think and try again...

well, because, the properties of matricies that cause them to move along their own axis, is a result of the way they are multiplied, that was a poor explanation, but thats what i have to say... Start learning some matrix math, its... confusing... but... it comes in handy, and is always good to know, sorry im not much of a teacher... lol
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Thanks again Dan,

I do know matrix math, I've studied lots of math, but still struggle grasping how the view matrix etc is set up. I now believe it is the same as the following 4x4 matrix :

Right.x Up.x Look.x 0.0f
Right.y Up.y Look.y 0.0f
Right.z Up.z Look.z 0.0f
-position.right -position.up -position.look 1.0f

I guess it is best to draw this sort of stuff down on paper ? I do know you would need 4 vectors, one for up, right, look at and position of the camera. The right, up and look at all describe the cameras orientation in the world and these will have to be orthonormal (perpendicular to each other).

Best wishes,
Steve

If it isn't working, take a bath, have a think and try again...

I don't know whether this helps or not but this works:

strafe left:
Player.X = Player.X - Sin(Player.Yaw + (90 * (pi / 180)))
Player.Z = Player.Z - Cos(Player.Yaw + (90 * (pi / 180)))

Add where subtracting to strafe right. That's basically my movement code with the modifier (90 * (pi / 180)) thrown in to move sideways instead of forward.
______________________________Perry Butler aka iosysiosys Website | iosys Music | iosys Engine
i find that the easiest conceptual way to do movement is to calculate a movement vector, scale it to reflect the movement speed, and add it into the position vector/matrix. so to calculate a strafe vector take the cross product of the view vector and the up vector. that'll give you a rightward strafe vector. you'll flip the sign of the vector (i.e. scale by -1) to get leftward movement. normalisze that and scale it by the movement amount that frame and there's your delta position. just add that into the object's orientation matrix and you're done.

-me
Move and orient the camera just like any other object in the world. The view matrix is the inverse of the camera's orientation/position.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:Original post by steg
Thanks again Dan,

I do know matrix math, I've studied lots of math, but still struggle grasping how the view matrix etc is set up. I now believe it is the same as the following 4x4 matrix :

Right.x Up.x Look.x 0.0f
Right.y Up.y Look.y 0.0f
Right.z Up.z Look.z 0.0f
-position.right -position.up -position.look 1.0f


is this the "math" order or the "memory" order? anyway, i will stick with the memory order (ie. consider it a float[16]).

a "normal" matrix has its right/up/forward/position vectors, for the view matrix you need the inverse, which happens to be simple (as long as you avoid sheering or scaling etc.)

you transpose the rotation part (as you did) and use -(vec,pos) for the 3 position components with vec being the right/up/front vectors. but usually id also suggest to do yourself the favor and handle the camera like every other object and only invert it to set up the view or modelview matrix.
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement