Hello!
I am developing a first person shooter using LWJGL. Currently, for my “view gun” I am doing the following:
public ModelMatrix getViewModelMatrix(Camera camera) {
//Rotate hand/gun to cameras rotation, and draw
float rx = 0;
float ry = (float)Math.toDegrees(camera.getPitch()) + 90f;
float rz = (float)-Math.toDegrees(camera.getYaw()) + 90f;
ModelMatrix matrix = new ModelMatrix();
matrix.matrix_add_translation(camera.getX(), camera.getY(), camera.getZ());
matrix.matrix_add_rotation_z(rz);
matrix.matrix_add_rotation_y(ry);
matrix.matrix_add_rotation_x(rx);
return matrix;
}
And this works! With this matrix setup I can draw my gun exactly where the camera is.
However, I want to add a rotate effect: I want to rotate the gun by the cameras delta yaw. This is quite easy to do, I created a “yawSpeed” variable, and when the mouse moves in the X direction, I add to the speed; I also have a friction to return it to 0.
This works, however the origin of the model is at 0, 0, 0. If you look at the picture above, it pivots the gun at the axis origin around the players head.
I want to change the origin axis to about where the gun is, so when the gun rotates it isn’t moving around the cameras position, but instead rotating around the guns position.
TL:DR
I want to draw my gun at the same position visually, but change the point where it rotates.
Any ideas?