In orthographic mode( flat 2D ), the shooting is pretty straight forward. Shoot as in from a gun and in first person view perspective.
And in 3D, you gotta use rotating code like
CODE
//Turn left or right calculation
x = sin(angle);
z = -cos(angle);
//Applying camera change to screen
glLoadIdentity();
gluLookAt(camX,camY,camZ,
camX+x,camY+y,camZ+z,
0.0,1.0,0.0f);
But how in the world do you make the bullet object spawn from where you're standing and make it move forward like in every fps game?
I've come up with a few ideas that aren't working out. One was to use SDL and OpenGL then blit a bullethole texture in the center of the screen. That sounds really complicated and probably not the correct way, I think!
The real way would maybe figure out the trigonometry of the bullet object then move it in a straight line in whatever direction the camera is facing. Again, I'm assuming the basic of how it might be done.
Currently, the sphere I spawn when pressing Space would appear at wherever I stand, then float along towards the negative side of Z-axis. It moves away and appears where I am so that's good. But if I turn away, it'd spawn at the side of me, instead of in front. What do I need to think about to get the object to always appear in front and then fly away in that same direction?
This is all the "forward-action" trig code I have:
CODE
void movesObjectOrCameraForward()
{
camX = camX + (x)*0.9;
camZ = camZ + (z)*0.9;
glLoadIdentity();
gluLookAt(camX,camY,camZ,
camX+x,camY+y,camZ+z,
0.0,1.0,0.0f);
}