I am making my own first person shooter 3D engine. I am stuck with shooting. I know that I have somehow change my screen coordinates to world coordinates, am I right? This just involves matrixes and I cant do the math, not yet atleast.
More accurately, I have aiming cross at center of the screen and I want to shoot ray to there from players position and if it collides with something it could at this point just print something. All I think I need is to know how to do the conversion from x = WIDTH/2 y = HEIGHT/2 to my world coordinates. Atleast this is what I think I need for now.
There's propably topics around this and I quickly searched but did'nt find anything I could use. Or how to implement it in my code.
My camera is set up like this:
glRotatef(rx, 1, 0, 0); glRotatef(ry, 0, 1, 0); glRotatef(rz, 0, 0, 1); glTranslatef(x, y, z);
and OPENGL initialized like this:
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect, near, far); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST);
and I am trying to draw ammo like this:
glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3f(origin.x, origin.y, origin.z); glColor3f(0, 1, 0); glVertex3f(direction.x, direction.y, direction.z); glEnd();
Problem is just that I dont know what are those origin and direction coordinates or how to calculate those.