Jump to content
  • Advertisement
Sign in to follow this  
ff8

building a camera system ...

This topic is 3883 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!