Below is my code that lets me to move the camera forward it works fine but i always want to know if I’m writing code in a efficient way..
void keyboard (unsigned char key, int x, int y) {
if (key=='w')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad))* 3 ;//move forward and initialise speed
zpos -= float(cos(yrotrad))* 3 ;
ypos -= float(sin(xrotrad))* 3 ;
}
OK this question just came to my head: Does anyone know any good OpenGL collision tutorials online.. if yes would be more than grateful if u share..
Thanks for reading my question
I think your solution is pretty good. I’ve used similar solutions to that problem in the past. I would combine the / 180 and the multiply by PI into a constant.
define PI_OVER_180 (3.141459f / 180f)
This should guarantee you don’t have to perform that calculation every time if the constant expression is performed by the preprocessor or compiler.