#### Archived

This topic is now archived and is closed to further replies.

# Camera problems

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am having camera problems. When I try to turn left and right my camera just kind of doubles back on itself. I guess one of the biggest problems is that I didn't write most of the camera code invloved. Here is a download link for an executable and the source for the relevant code
void CCamera::SetViewByMouse()
{
POINT mousePos;
int middleX = 320  >> 1;   //TODO replace with function to get current resolution
int middleY = 240 >> 1;
float angleX = 0.0f;
float angleY = 0.0f;
static float currentRotX = 0.0f;

GetCursorPos(&mousePos);

if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return;

SetCursorPos(middleX, middleY);

angleX = (float)( (middleX - mousePos.x) ) / 50.0f;
angleY = (float)( (middleY - mousePos.y) ) / 50.0f;

//currentRotX -= angleX;
currentRotX += angleY;

if(currentRotX > 1.0f)
currentRotX = 1.0f;
else if(currentRotX < -1.0f)
currentRotX = -1.0f;
else
{
CVector3 vAxis = CrossProduct(vView - vPosition, vUpVector);
vAxis = Normalize(vAxis);

// Rotate around our perpendicular axis and along the y-axis
RotateView(angleY, vAxis.x, vAxis.y, vAxis.z);
RotateView(angleX, 0, 1, 0);
}
}

void CCamera::RotateView(float fAngle, float rx, float ry, float rz)
{
quaternion temp, quat_view, result;

temp.x = rx * sin(fAngle/2);
temp.y = ry * sin(fAngle/2);
temp.z = rz * sin(fAngle/2);
temp.w = cos(fAngle/2);

quat_view.x = vView.x;
quat_view.y = vView.y;
quat_view.z = vView.z;
quat_view.w = 0;

result = mult(mult(temp, quat_view), conjugate(temp));

vView.x = result.x;
vView.y = result.y;
vView.z = result.z;
}


Edit: if you run the executable press l to turn off lighting, it's not working right now. [edited by - griffenjam on October 8, 2003 3:05:32 PM]

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007629
• ### Who's Online (See full list)

There are no registered users currently online

×