Never mind! I continued writing my code and the bug disappeared!
For some reason, when I move to mouse on the X axis, the program only realizes it when I have moved the mouse over some amount of pixels, rather than just one. Even stranger, it works fine on the Y axis.
My loop:
while (!bQuit)
{
/* check for messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
/* OpenGL animation code goes here */
GetCursorPos(&mouse);
ScreenToClient(hwnd,&mouse);
ScreenToClient(hwnd,&coord);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0,0);
glRotatef(camxrot,1.0f,0.0f,0.0f);
glRotatef(camyrot,0.0f,1.0f,0.0f);
glTranslatef(xpos,ypos,zpos);
/*glBegin(GL_TRIANGLES);
glColor3f(0.5f, 1.0f, 0.5f); glVertex3f(myTri1.point1.x,myTri1.point1.y,myTri1.point1.z);
glColor3f(1.0f, 0.5f, 0.5f); glVertex3f(myTri1.point2.x,myTri1.point2.y,myTri1.point2.z);
glColor3f(0.5f, 0.5f, 1.0f); glVertex3f(myTri1.point3.x,myTri1.point3.y,myTri1.point3.z);
glColor3f(1.0f, 0.5f, 0.5f); glVertex3f(myTri.point1.x,myTri.point1.y,myTri.point1.z);
glColor3f(0.5f, 1.0f, 0.5f); glVertex3f(myTri.point2.x,myTri.point2.y,myTri.point2.z);
glColor3f(0.5f, 0.5f, 1.0f); glVertex3f(myTri.point3.x,myTri.point3.y,myTri.point3.z);
glColor3f(1.0f, 0.5f, 0.5f); glVertex3f(myTri2.point1.x,myTri2.point1.y,myTri2.point1.z);
glColor3f(0.5f, 1.0f, 0.5f); glVertex3f(myTri2.point2.x,myTri2.point2.y,myTri2.point2.z);
glColor3f(0.5f, 0.5f, 1.0f); glVertex3f(myTri2.point3.x,myTri2.point3.y,myTri2.point3.z);
glEnd();*/
glBegin(GL_LINES);
renderGrids();
glEnd();
glBegin(GL_TRIANGLES);
render(&myBod);
glEnd();
glPopMatrix();
SwapBuffers(hDC);
if(GetKeyState('W') & 0x80 && GetKeyState(VK_SHIFT) & 0x80)
{
xpos += -sin(camyrot*M_PI/180.0f)/5.0f;
ypos += sin(camxrot*M_PI/180.0f)/5.0f;
zpos += cos(camyrot*M_PI/180.0f)/5.0f;
}
if(GetKeyState('W') & 0x80)
{
xpos += -sin(camyrot*M_PI/180.0f)/15.0f;
ypos += sin(camxrot*M_PI/180.0f)/15.0f;
zpos += cos(camyrot*M_PI/180.0f)/15.0f;
}
if(GetKeyState('S') & 0x80)
{
xpos += sin(camyrot*M_PI/180.0f)/15.0f;
ypos += -sin(camxrot*M_PI/180.0f)/15.0f;
zpos += -cos(camyrot*M_PI/180.0f)/15.0f;
}
if(GetKeyState('A') & 0x80)
{
xpos += sin((camyrot+90)*M_PI/180.0f)/15.0f;
ypos += -sin((camxrot)*M_PI/180.0f)/15.0f;
zpos += -cos((camyrot+90)*M_PI/180.0f)/15.0f;
}
if(GetKeyState('D') & 0x80)
{
xpos += sin((camyrot-90)*M_PI/180.0f)/15.0f;
ypos += -sin((camxrot)*M_PI/180.0f)/15.0f;
zpos += -cos((camyrot-90)*M_PI/180.0f)/15.0f;
}
if(GetKeyState('P') & 0x80 && ppress != 1)
{
ppress = 1;
struct Triangle tri = cTriangleRaw(-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
addTriangle(&myBod,tri);
}
if(!GetKeyState('P') & 0x80 && ppress == 1)
{
ppress = 0;
}
if(mouse.y != mouselast.y)
{
camxrot += (mouse.y - mouselast.y)/2.0f;
}
if(mouse.x != mouselast.x)
{
camyrot += (mouse.x - mouselast.x)/2.0f;
}
SetCursorPos(500.0f,500.0f);
GetCursorPos(&mouselast);
ScreenToClient(hwnd,&mouselast);
Sleep (1);
}
}
And the executable from this is here: Link
The triangle struct and body struct are made by me, a triangle contains three points and a body contains triangles.