strafe left / right
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
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
hope that helps
-Dan
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
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
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
-Dan
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
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
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.
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.
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
-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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement