PDA

View Full Version : help with my camera func

ShinGouki
05-08-2003, 06:22 PM
Hi sorry this is a repost but i really need help, and no one in beginners is replying to me.

Ive tried creating a simple camera movement function, for rotation i just change the look at vector. for movement ive tried working out the current vector from the pos vector to the look at vector, but for some reason when i go into different quadrants sometimes forward makes me go back, and all kinds of strange things happen...
///////Camera Functions////////////////////////////////////////////
void rotateFunc() ////Rotation vectors ........
{
vView[0]=vPosition[0]+(10*sin(cameraAngle)); //vector for rotating in circular motion
vView[2]=vPosition[2]+(10*cos(cameraAngle));
}

void throttleFunc()
{

vPosition[0]+=(cameraVector[0]*zoom); //function for calculating look vector and travelling along it
vPosition[1]+=(cameraVector[1]*zoom); //
vPosition[2]+=(cameraVector[2]*zoom);

vView[0]+=(cameraVector[0]*zoom);
vView[1]+=(cameraVector[1]*zoom);
vView[2]+=(cameraVector[2]*zoom);
}

////////Function for the looking mode setup etc and actual camera location............
void camera()
{

static float vectorLength=0;

vectorLength= (vView[0]-vPosition[0]) + (vView[1]-vPosition[1]) + (vView[2]-vPosition[2]);

cameraVector[0] = (vView[0]-vPosition[0])/vectorLength;
cameraVector[1] = (vView[1]-vPosition[1])/vectorLength;
cameraVector[2] = (vView[2]-vPosition[2])/vectorLength;

glMatrixMode(GL_PROJECTION);

rotateFunc();

// Define a perspective view volume - this creates a projection matrix
// and multiples it onto the top of the projection matrix stack
gluPerspective(45.0, ASPECT_RATIO, 1.0, 6000.0); //field of view, aspect ratio, near plane, far plane

gluLookAt(vPosition[0], vPosition[1], vPosition[2], //posx,y,z,
vView[0], vView[1], vView[2], //viewx.y.z
0.0, 1.0, 0.0);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black background
throttleFunc();
}
Here are all the functions im using. Anywone who can tell me where im going wrong or if you have any easy alternatives to what ime doing then please let me know. I also need a way of resizeing this so that when the window size is changed the camera changes with it.