Hello forum,
I’m am very new to this forum and this is my first post. I’m sorry for my English, it could be a bit wrong sometimes but i’ll try my best.
Now the actual question:
In my 3d game I have a model of a gun. Like in almost every shooter you have a gun in the bottom-right corner of the screen, independently of the point you’re looking at. I want this in my game to and I’ve already managed to turn the model as it should and it is in the correct position for turning left and right. The only problem is now, that I can’t manage it for looking up and down, the gun stays in the wrong spot.
Here is some of my code:
float z = (float) ((Math.sin(Math.toRadians(cam.getRY() + 90 * 2))) / -1 + (Math.sin(Math.toRadians(cam.getRY() + 90 * 1))) * -2);
float x = (float) ((Math.cos(Math.toRadians(cam.getRY() + 90 * 2))) / -1 + (Math.cos(Math.toRadians(cam.getRY() + 90 * 1))) * -2);
glTranslatef(-cam.getX() + x, -cam.getY() - 1, -cam.getZ() + z);
glRotatef(-cam.getRY() - 90, 0, 1, 0);
glRotatef(cam.getRX(), 0, 0, 1);
glScalef(0.05f, 0.05f, 0.05f);
glCallList(model);
I hope someone can help me!