# help with my camera func

hi 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=vPosition+(10sin(cameraAngle)); //vector for rotating in circular motion
vView=vPosition+(10
cos(cameraAngle));
}

void throttleFunc()
{

``````vPosition+=(cameraVector*zoom);		//function for calculating look vector and travelling along it
vPosition+=(cameraVector*zoom);		//
vPosition+=(cameraVector*zoom);

vView+=(cameraVector*zoom);
vView+=(cameraVector*zoom);
vView+=(cameraVector*zoom);
``````

}

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

``````static float vectorLength=0;

vectorLength= (vView-vPosition) + (vView-vPosition) + (vView-vPosition);

cameraVector = (vView-vPosition)/vectorLength;
cameraVector = (vView-vPosition)/vectorLength;
cameraVector = (vView-vPosition)/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,	vPosition,	vPosition,					//posx,y,z,
vView,		vView,		vView,		//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.

Originally posted by ShinGouki:
[b]hi 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=vPosition+(10sin(cameraAngle)); //vector for rotating in circular motion
vView=vPosition+(10
cos(cameraAngle));
}

void throttleFunc()
{

vPosition+=(cameraVector*zoom); //function for calculating look vector and travelling along it
vPosition+=(cameraVector*zoom); //
vPosition+=(cameraVector*zoom);

vView+=(cameraVector*zoom);
vView+=(cameraVector*zoom);
vView+=(cameraVector*zoom);
}

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

static float vectorLength=0;

vectorLength= (vView-vPosition) + (vView-vPosition) + (vView-vPosition);

cameraVector = (vView-vPosition)/vectorLength;
cameraVector = (vView-vPosition)/vectorLength;
cameraVector = (vView-vPosition)/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, vPosition, vPosition, //posx,y,z,
vView, vView, vView, //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. [/b]

Part of the problem could be your vector length as it should always be positive and yours could be negative resulting strange behavior. Vector (line) length is defined as the sqrt((x2-x1)(x2-x1) + (y2-y1)(y2-y1) + (z2-z1)(z2-z1)). Another possibility is your CameraAngle - not sure how it is calculated but sin and cos expect radians not angles so verify that they are in radians. And, I am also not sure why you are multiplying the sin and cos by 10 when you want the vector formed by view and position to be unit vector which would be achieved automatically by removing the 10 as the sin and cos are complimentary for same angle and the line will always have a length of 1.

Hope some of that helps.

thanks a lot, and thanks again you’ve helped me quite a lot this week.

The camera works great now thanks again.