I almost got it but just need to refine it.

Okay I just need a little assistance with my code. I have made a few adjustments to what is needed. Here is what I need to do
In the windows main loop (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
}





Here is what I have for that:
1
2
3
4
5
6
if (KEY_DOWN(VK_RIGHT))  
{ 
ObjVelX += (50*20/1000);} 
if (KEY_DOWN(VK_LEFT)) 
{  
ObjVelX += (50*20/1000);}///// 





Step 2: Make 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:





Here is what I have for that:
1
2
3
4
5
6
7
8
9
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;
 






Was there a question somewhere?
The code you've posted seems alright, except that there should be -= on line 6 in the first piece of code and that you,e missed a " on line 5 in the second one...
Topic archived. No new replies allowed.