I'm working on this graphics application (DirectX Direct3D Ratained-Mode). My goal at this point is to make it possible to use the numeric keypad keys to move the "camera" around the scene and to retate the "camera" as needed.
First, I added to the WindowProc() function to have it read the numeric keypad keys via a switch case method.
First, I tried to declare (near the top of the program outside of any function blocks) nine variables to store the x, y, z vectors for the camera frame position rotation and vertical orientation. Then, in the switch case, I tried to adjust these variables according to which numpad key ( 0-9 ) was pressed.
switch(msg)
{
case WM_KEYDOWN:
{
switch(wparam)
{
VK_NUMPAD4:
campos_x = campos_X - 0.1;
break;
}
}
Please bear in mind that this code segment is only one
out of nine cases I attempted to program. Assuming that global variables could be read by any function, I then placed the following lines in the function that sets the positions of the frames.
lpCamera->SetPosition(lpScene, D3DVAL(campos_x), D3DVAL(campos_y),
D3DVAL(campos_z));
lpCamera->SetOrientation(lpScene, D3DVAL(camrot_x),
D3DVAL(camrot_y), D3DVAL(camrot_z), D3DVAL(camvrt_x),
D3DVAL(camvrt_y, camvrt_z));
Now, assuming that the campos, camrot, and camvrt variables are truly global, this method should have worked, but it didn't.
My second attempted method was trying to define a global variable (again, near the top of the program outside any functions) named "keyindex" which was supposed to be assigned an integer value corrosponding to which numpad key ( 0-9 ) was pressed.
I added the appropriate code to the same switch-case statements in the WindowProc() and added some statements in the SetPositions function to adjust the nine camera movement variables mentioned above according to the value of keyindex. However, this method, too, failed.
My third attempted method was to try to globally define and then use a pointer (*p_keyindex) to point to the keyvalue. No good.
My fourth attempted method was to try to define a character variable and use it. Again, no good.
My fifth attempted method was to try to "tap" into the message queue and have the message copied into a MSG structure named keypress and go from there, having the SetPosition function then read the values in that keypress structure. No success here, either.
My sixth attempted method was to try to add the keyindex and/or keypress MSG structure member or two to the function prototype and the function definition to show that these were supposed to be passed among these functions from one to the other as appropriate. No dice.
In desparation, I also added memset calls to the InitApp function to initialize these global variables and the structure.
So far, I've spent three to four days and nights trying to figure out and/or research in the documentation a way out of this difficulty.
Bottom line? Unless I'm missing something, one would think that if a variable(s) is(are) defined globally, they are supposed to be able to be used and updated anywhere in the file in which they appear after their declaration. And you're supposed to be able to "see" and use the values regardless of what function your program is in at any given time.
I tested to see if the keys were being read by placine a call to the CleanUp() function which releases all objects and variables and causes the application to terminate. In each tested case, this worked. So, the keys DO appear to be being scanned okay.
Also, I deliberately set the index variable to a value in the SetPositions() function to see if the adjustments would work there. Again, success to some degree. Having eliminated these two steps, the only one left is the middle step, "copying" the value called for from the WindowProc function to the SetPositions() function so as to be able to move the camera with the keypad keys.
This is maddening to me because (at least from my perspective and unless I'm missing something) global variables are supposed to be visible in the file.
Thank you very much in advance for any help you may be able to offer.
Mike
PS. Also, I'm not sure (and this may have some bearing on what I'm trying to do) whether the program cycles through the whole program for every frame update or whether it starts at Winmain(), then calls InitApp, and then cyles through the various rendering functions over and over again until the application is shut down.
Also, I'm not sure if DirectInput is the answer. This particular version of DirectInput appears to be only for joystick input.
By the way, I'm using Microsoft's Developer Studio '97 Visual C++ 5.0 development environment.
Thanks again.