Sign in to follow this  

building a camera system ...

This topic is 3664 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

Hello everyone, i am trying these days to implement a camera system so i get rid of gluLookAt() >.>;; so i started building the modelview matrix and it worked after testing values on my owe matrix and using gluLookAt() after that i decide to implement simply operations on the camera (pitch,yew,slide,roll) then when i tested it i didn't face any problem until i do 2 operations in row like pitch -> roll or roll -> yew the camera goes crazy >.>;; i tried everything to figure the problem but no luck = i hope anyone can help me = code :
	void setupMVMatrix(){
		float tmp[16];
		ModelView.arrMat[0]=u.x; ModelView.arrMat[1]=u.y; ModelView.arrMat[2]=u.z; ModelView.arrMat[3]=-eye.Dot3(u);
		ModelView.arrMat[4]=v.x; ModelView.arrMat[5]=v.y; ModelView.arrMat[6]=v.z; ModelView.arrMat[7]=-eye.Dot3(v);
		ModelView.arrMat[8]=n.x; ModelView.arrMat[9]=n.y; ModelView.arrMat[10]=n.z;ModelView.arrMat[11]=-eye.Dot3(n);
		ModelView.SetOpenGLMatrix(tmp);
		glMultMatrixf(tmp);	

	}
	void setupCamera(_3DVECTOR<float> Eye,_3DVECTOR<float> Look,_3DVECTOR<float> Up){
		eye=Eye;
		look=Look;
		up=Up;
		n=look;
		n.normalize();
		n=n.operator *(-1);
		u.CrossProduct(up,n);
		u.normalize();
		v.CrossProduct(n,u);
		v.normalize();
		U=u;V=v;N=n;EYE=eye;
		setupMVMatrix();

	}
	void slide(float du,float dv,float dn){
		eye =EYE+u*du+v*dv+n*dn;
	}
	void roll(float angle){
		u= U*cosf(angle)+V*sinf(angle);
		v= U*sinf(-angle)+V*cosf(angle);
	}
	void pitch(float angle){
		v=V*cosf(angle)+N*sinf(-angle);
		n=V*sinf(angle)+N*cosf(angle);

	}
	void yaw(float angle){
		u= U*cosf(angle)+N*sinf(angle);
		n= U*sinf(-angle)+N*cosf(angle);
	}

thank you, ^^

Share this post


Link to post
Share on other sites
Camera systems are more simple than they seem when your in the middle of writing one.

My camera system works on the principle of three vectors:

position of camera
direction of camera
roll of camera


When I need to move the camera, I rotate the vector passed in by the cameras rotation matrix, and then translate it by that value, so if the camera is facing in the -Z direction and you move it forwards it will still move in the -Z direction.


When I rotate the camera I don't change the roll vector, so the camera is always looking up. I have a separate method to roll the camera by a scalar, and then use this for the OpenGL UP vector.

My renderer is passed a camera and calculates the view frustum based on the viewing angle of the camera.
I then use GluLookAt(
c.eye.x, c.eye.y,c.eye.z,
c.center.x,c.center.y,c.center.z,
c.roll.x, c.roll.y, c.roll.z)

Share this post


Link to post
Share on other sites

This topic is 3664 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this