Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

camera movement????

Started by Laserus Jan 8, 2005 at 7:00 PM 2 replies 550+ views
Original Post
Laserus
Laserus
Hey Im making a camera class for opengl using quaternions and im having some trouble getting movement down here is my logic: 1. get movement and rotation amounts from input and save them in floats 2. using axis angles turn rotation amounts into quaternions 3. multiply quaternions together and form matrix from them 4. allow glmultmatrix()to do its thing ***All of the above works fine*** 5. get the direction vector from the matrix 6. get the strafe vector using cross product of the forward vector and the up vector 7. multiply forward and strafe vectors by their movement amounts 8. add forward and strave vectors to position vector 9. glTranslatef() and whalla How do i do step 5? this is the code. it may be important to note that i am using the math3d++ library to do all the math


void CCamera::Update () {

	//this is to hold the perspective matrix
	mat4 m;
	//uh forward, and strafe
	vec3 f, s;
	
	//get our rotation
	quat q= heading*pitch;

	
        ***this is it how do i get the vector 
           of the forward direction from my martix***
       
        f=???????????;
	
	//get the strafe direction
	s =  cross (f, vec3(0.f, 1.f, 0.f));

	//get the movement amounts
	f *= fVel;
	s *= sVel;

	//update position vector
	pos += (s+f);

	// rotate
	glMultMatrix (m);

	//move
	glTranslatef(-pos[0], -pos[1], pos[2]);//
}



thanks - las
JohnBolton
JohnBolton
First of all, using quaternions in steps 2 and 3 is unnecessary. You can convert the movement and rotation amounts to a transformation matrix directly without using quaternions.

Next, the matrix that is passed to OpenGL is the "view" matrix. The "view" matrix is the inverse of camera's orientation/position matrix.

An unrotated camera in OpenGL points down the -Z axis, the Y axis is up and the X axis is right. When the camera is rotated, those directions still correspond to the camera's local -Z, Y, and X axes. Conveniently, these axes can be extracted from the camera's orientation/position matrix:

The camera's direction vector is ( -M[8], -M[9], -M[10] ).
The camera's up vector is ( M[4], M[5], M[6] ).
The camera's right vector is ( M[0], M[1], M[2] ).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Laserus
Laserus
thanks for the reply, here is the thing i was using m[8], [9] and [10] to get the forward vector, but i left it out of the post because it wasnt working. i could move and strafe fine as long at i was pointing down the -z, but if i rotated everything went hay wire and i began to move at sort of a slant. pluss i used quats because i figure i might want to do some interpolations at some point.

thanks
- las
Laserus
Laserus
Well i figured out part of the problem i think. math3d++ (the math library i am using) didnt have a quat to matrix4 er, thingy, so i made my own and aparently got the rows and columns mixed up. the thing is now i have to hold my mouse upside down and press backwards to make it work correctly. I know i can just inverse all my inputs, but that seems more like a quick fix than a solution because strafe works correctly cause its based off the cross product, so anybody got any ideas?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.