Original Post
I am trying to add mouse movement to my camera class, but when I got to do the rotation, it automaticly puts me in the sky. I use the NeHe basecode for the Win32 accessing. When it gets to the code to access the rendering loop, i have it call layout(). From layout I have the scences all setup based on time, and each scene has its own init() and draw() functions. I want to add mouse rotation to my opening scene, opening.cpp, but after setting the parameters and compiling, the screen zeros in on the sky, all blue. Does it matter I am getting the mouse position outside the Win32 access file. I set my width and height accordingly (640, 480).
main.cpp
********
int WINAPI WinMain(...)
...
layout(hDC);
...
*********
layout.cpp
*********
void layout(HDC hDC)
{
...
drawOpening();
...
***********
opening.cpp
***********
int screenHeight = 480;
int screenWidth = 640;
drawOpening()
{
...
GetInput();
...
drawscene
...
}
void GetInput()
{
int h = screenHeight >> 1;
int w = screenWidth >> 1;
POINT mousePos;
GetCursorPos(&mousPos);
camera.RotateMouse(mousePos,x, mousePos.y, w, h);
}
******
camera.cpp
******
void Camera::RotateMouse(int mousePosX, int mousePosY, int midX, int midY)
{
float yDirection = 0.0f; // Direction angel
float yRotation = 0.0f; // Rotation angle
// If mouse position is at origin, no rotation needed
if((mousePosX == midX) && (mousePosY == midY)) return;
// Get direction
yDirection = (float)((midX - mousePosX)) / 1000.0f;
yRotation = (float)((midY - mousePosY)) / 1000.0f;
// Keeps camera from rotating too far
currentRotationAngle -= yRotation;
// Keeps camera from going too high
if(currentRotationAngle > 1.0f)
{
currentRotationAngle = 1.0f;
return;
}
// Keeps camera from going too low
if(currentRotationAngle < -1.0f)
{
currentRotationAngle = -1.0f;
return;
}
float xAxis = 0, yAxis = 0, zAxis = 0;
float xDir = 0, yDir = 0, zDir = 0;
// Get direction of the view
xDir = xView - xPos;
yDir = yView - yPos;
zDir = zView = zPos;
// Normalize
float len = 1 / (float)sqrt(xAxis * xAxis + yAxis * yAxis + zAxis * zAxis);
xAxis *= len;
yAxis *= len;
zAxis *= len;
// Rotate the camera
RotateCamera(yRotation, xAxis, yAxis, zAxis);
RotateCamera(yDirection, 0.0f,1.0f,0.0f);
}
I think I got everything. All help is appreciated.
Thanks,
Dimebag