GX Camera Issues

Post Reply
mv2112
Posts: 4
Joined: Wed Sep 01, 2010 3:22 am

GX Camera Issues

Post by mv2112 » Wed Jun 22, 2011 5:33 am

Im trying to make a FPS type view in GX and iv got it working except for 1 small problem. Im trying to rotate the camera:

Code: Select all

   angle2+=d;//New Viewing angle
	float y=cam[0].y+sin(DegToRad(angle2)); //Get New Y From the New View Angle and add it to the cameras position
	cam[2].y=y; //set the View Y to the generated Y ^^ //guVector cam[3]
	guMtxIdentity(m);
	guLookAt(m, &cam[0], &cam[1], &cam[2]); //reload camera
Basicly it just takes an angle, calculates a y chord for the view vector and loads it into the view matrix (m). This works perfectly except for when you go all the way up or down. I think this is because im not updating the Up vector. Would i just inverse the slope of the line between the view point and camera location and add/subtract it to the up vector? Much help would be appreciated. And also, i have one last question: I've tried to use translations and rotations on the view matrix but they seem to have no effect. Are you not able to use the regular transformation functions on view matrices?

Thanks
mv2112

ccfreak2k
Posts: 14
Joined: Sat Mar 06, 2010 1:11 pm

Re: GX Camera Issues

Post by ccfreak2k » Wed Jun 22, 2011 1:01 pm

I actually have this kind of view implemented to some extent in the lesson 10 code of the "neheGX" examples. Specifically, this section will be relevant:

Code: Select all

f32 lookupdown; // Vertical angle, 0 is straight ahead
if (lookupdown > 90)  lookupdown = 90.0F;
if (lookupdown < -90) lookupdown = -90.0F;
Kind of simple, but it works. If you instead want the camera to flip around when the user goes past these two "ends", you can simply add/subtract 180 on each of the angles to get the camera to quickly spin around, but the user might find this disorienting.

EDIT: Someone on IRC suggests:

Code: Select all

cam[2].x = cam[0].x + cos(yaw)cos(pitch);
cam[2].y = cam[0].y + sin(pitch);
cam[2].z = cam[0].z + sin(yaw)cos(pitch);
Said someone also adds: "...pitch also modifies x and z, not just y."

Use whichever works best for you.

mv2112
Posts: 4
Joined: Wed Sep 01, 2010 3:22 am

Re: GX Camera Issues

Post by mv2112 » Wed Jun 22, 2011 9:11 pm

ccfreak2k wrote:

Code: Select all

f32 lookupdown; // Vertical angle, 0 is straight ahead
if (lookupdown > 90)  lookupdown = 90.0F;
if (lookupdown < -90) lookupdown = -90.0F;
Works Perfectly! Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests