Quote:Original post by 3Dgonewild
1)PI180(#define PI180 0.0174532925f) , returns this number:
stdout.txt:
*** Source Snippet Removed ***
....why?
The f on the end of the number declares it of the type float, and the standard that the C/C++ language follows defines that float only has 6 significant decimals. Because of that, printf also normally outputs float-types with 6 decimals. Luckily, printf takes precision flags that can be used to force the amount of decimals, you write it in the format string, before the f-specifier, like this:
The above results in 3 decimals being output. It's possible to output more than 6 decimals, but they might not be accurate. You can read more about printf flags on
printf at www.cplusplus.com.
I'm still trying to understand the mysterious relation between PI and 0.0174532925 [smile]
Quote:Original post by 3Dgonewild
2) How can i improve the mouse movement?
Here's the function:
*** Source Snippet Removed ***
Improving the mouse movement is a bit of a design issue (there are different more or less intuitive ways of controlling what you see), but in Quake it's basically like this:
If the horizontal mouse coordinate decreases, the camera turns left.
If the horizontal mouse coordinate increases, the camera turns right.
The same goes for the vertical movement, but limit it at +-90 degrees.
To find out how much the mouse coordinates have changed between two updates, you either can:
A. Store coordinate from each update, and subtract it from the coordinate next update.
B. Get the relative mouse movement (relative to the last update, it's actually the same value as in A).
Since you're using SDL, I think option B is easier because I've seen in the SDL documentation that the mouse event struct has relative motion data, named xrel and yrel. Take a look on the following page in the documentation:
SDL_MouseMotionEvent.
Notice that the xrel and yrel members aren't in the button struct, but in the motion struct.
Here follows an example, remember that I don't use SDL though so the code isn't tested, but it should give you the idea of how to do it.
if( EVENT.type == SDL_MOUSEMOTION ){ if (EVENT.motion.xrel < 0) { THE_CAMERA.CamLeft(); } else if (EVENT.motion.xrel > 0) { THE_CAMERA.CamRight(); }}
If you want a smoother rotation, you should also check the magnitude of xrel and compute a velocity based on it. The rotation velocity is then used to rotate/turn the camera, so you would need a velocity parameter in CamLeft/CamRight.