First Person Camera using sceGumLookAt..

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
roland
Posts: 13
Joined: Sat Feb 11, 2006 9:11 pm

First Person Camera using sceGumLookAt..

Post by roland »

I am trying to put some sort of First Person Camera in my scene that can move in all directions..

I have sucessfully implemented the function so I can move forward and backward and also rotate left and right aswell as looking up and down..

the thing is that once I turn left or right by 90°, the up and down does not work anymore.. It works fine when I look forward or backward..

I can't find a solution on this and it's bugging me for a while now.. Anybody out there that can give me some sort of hint on this..

Below is some code to show what I am doing:


Init:

Code: Select all

eye.x = 0.0f; 
eye.y = -10.0f;
eye.z = 2.5f;
center.x = 0.0f; 
center.y = 0.0f;
center.z = 0.0f; 
up.x = 0.0f; 
up.y = 0.0f;
up.z = 1.0f;
sceGumLookAt( &eye, &center, &up ); // Set viewpoint matrix	


and in the main loop i do:

Code: Select all



sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumLookAt( &eye, &center, &up ); // Set viewpoint matrix	


With the Pad Control:
	if (padd & PSP_CTRL_UP) {
		angle += 0.01;
		angle_y = angle;
		angle_z = angle;
		center.z += angle_y * 2;
		orientMe(-angle_z,0);
		
	}
	if (padd & PSP_CTRL_DOWN) {
		angle -= 0.01;
		angle_y = angle;
		angle_z = angle;
		center.z += angle_y * 2;
		orientMe(-angle_z,0);
	}
	if (padd & PSP_CTRL_LEFT) {
		orientMe(camspeed,0);
	}
	if (padd & PSP_CTRL_RIGHT) {
		orientMe(-camspeed,0);
	}

	if (padd & PSP_CTRL_CIRCLE) {
		moveMeFlat(-camspeed);
	}

	if (padd & PSP_CTRL_CROSS) {
		moveMeFlat(camspeed);
	}

void orientMe(float speed, int mode) {
ScePspFVector3 vVect;
vVect.x = center.x - eye.x;
vVect.y = center.y - eye.y;
vVect.z = center.z - eye.z;
center.y = (float)(eye.y + sinf(speed)*vVect.x + cosf(speed)*vVect.y);
center.x = (float)(eye.x + cosf(speed)*vVect.x - sinf(speed)*vVect.y);
}

void moveMeFlat(float speed) {
	ScePspFVector3 vVect;
	vVect.x = center.x - eye.x;
	vVect.y = center.y - eye.y;
	vVect.z = center.z - eye.z;

	eye.x = eye.x + vVect.x * speed;
	eye.y = eye.y + vVect.y * speed;
	eye.z = eye.z + vVect.z * speed;
	center.x = center.x + vVect.x * speed;
	center.y = center.y + vVect.y * speed;
	center.z = center.z + vVect.z * speed;
}

Any help would be greatly appreciated since I am really getting frustrated :(
Post Reply