I'm trying to adapt some code from a site to my code, to see how this works, but it isnt working. The code is supposed to control the view with the screen, and move the cursor back to the middle. It moves the cursor to the middle, but the view vector stays the same. When compiled, it only comes up with two warnings:
test.cpp 311: angleZ is assigned a value that is never used in function SetViewByMouse.
test.cpp 310: angleY is assigned a value that is never used in function SetViewByMouse.
These are the functions to move the mouse:
Code:
void SetViewByMouse() {
POINT mousePos;
Vector3D m_vPosition(posx, posy, posz);
int middleX = 400;
int middleY = 300;
float angleY = 0.0f; //line 310
float angleZ = 0.0f; //line 311
float currentRotX = 0.0f;
GetCursorPos(&mousePos);
if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return;
SetCursorPos(middleX, middleY);
angleY = (float)( (middleX - mousePos.x) ) / 1000.0f;
angleZ = (float)( (middleY - mousePos.y) ) / 1000.0f;
static float lastRotX = 0.0f;
lastRotX = currentRotX;
currentRotX += angleZ;
if(currentRotX > 1.0f) {
currentRotX = 1.0f;
if(lastRotX != 1.0f) {
Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
vAxis = vAxis.normalize();
RotateView( 1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
}
} else if(currentRotX < -1.0f) {
currentRotX = -1.0f;
if(lastRotX != -1.0f) {
Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
vAxis = vAxis.normalize();
RotateView( -1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
}
} else {
Vector3D vAxis = m_vUpVector.crossProduct(m_vView - m_vPosition);
vAxis = vAxis.normalize();
RotateView(angleZ, vAxis.x, vAxis.y, vAxis.z);
}
RotateView(angleY, 0, 1, 0);
}
void RotateView(float angle, float x, float y, float z) {
Vector3D m_vPosition(posx, posy, posz);
Vector3D vNewView;
Vector3D vView = m_vView - m_vPosition;
float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);
vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;
vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;
vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;
vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;
vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;
vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;
vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;
vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;
vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;
m_vView = m_vPosition + vNewView;
}
Hope you can help, thanks !