I did everything that is required but I can't make the code work.
Here is the requirements:
In the windows main.cpp (in the while loop of Win Main and right before the first if statement), add something similar to the following to detect a right arrow key press:
if (KEY_DOWN(VK_RIGHT)) {
ObjVelX =. . .; //Add you own code to update the object’s horizontal velocity
//so that when the right key is pressed the velocity increases
//i.e. it goes faster and faster
}
Add similar code for the left arrow key.
Add the following code after the ShowWindow in WinMain to remove keyboard focus so the arrow keys will not control the slider controls:
SetFocus(NULL);
1 2 3 4 5 6 7 8
//Here is what I got for that in the main.cpp//
if (KEY_DOWN(VK_RIGHT))
{
ObjVelX += (50*20/1000);}
if (KEY_DOWN(VK_LEFT))
{
ObjVelX += (50*20/1000);}
Here is step 2: Create a timer event
The program should calculate the new position of the object for the subsequent frames and update the OpenGL output. Use the windows timer so that each frame is about 20/1000= 1/50th of a second.
A windows timer can be created in WinMain just before the while message loop using the SetTimer function:
SetTimer(HDialog, 1, 20, NULL); //20 milliseconds
This will generate a WM_TIMER message that can be handled by the WndProc function. Each time the timer goes off, update the object's position.
Add a case for the timer event in the DialogProc() function, in main.cpp:
case WM_TIMER:
ObjPosX =. . . //add code to position based on formula
//xnew = xold + dt*velocity
//Be sure to use the same time as set up in SetTimer:
//dt=20.0/1000.0
break;
1 2 3 4 5 6 7 8 9 10
///Here is what I have for that for the main.cpp///
case WM_TIMER:
ObjPosX = ObjPosX + 20.0/1000.0 * ObjVelX;
char str[32];
sprintf(str, "%s", <%.2f %.2f %.2f>", "Name goes here", ObjPosX, 0.0F, 0.0F);
SetWindowText(HDialog, str);
SetFocus(NULL);
break;
Here is the last step in the CGfxOpenGL.cpp :
Modify the sphere’s glTranslatef function in CGfxOpenGL.cpp to draw the single sphere in the proper new (updated) position
For example,
glTranslatef(ObjPosX, 0, 0);[/
//Here is the CGfxOpenGL.cpp for teh last step//
// undo the previous floor transform
glTranslatef(ObjPosX, 0, 0);////last step////////////////////////////////////////
// draw some spheres
glColor3f(1, 0, 0); //color blue
gluSphere(quadric, 1.0f, 20, 20); // has radius 1