Hi, this is my first time posting on here so sorry for everything that I'm gonna do wrong in advance
I am currently trying to render custom models using OpenGL. Now I have a mesh which follows the player, but as soon as I go into third person the position of the mesh isn't correct anymore because OpenGL translates from the viewport and not the actual player "eyes" position where the viewport is located in first person (as far as I know).
Now my question is, how do I compensate for the offset? Is there a way to get the actual viewport position in relation to the player "eyes" or is there a more elegant solution which I just don't know about. Or maybe 2am is too late for my brain to work properly.
Sorry if I ask stupid questions but I just got back into Forge yesterday which is why I'm not quite familiar with all the new stuff.
All help is appreciated, thanks in advance :"
@SubscribeEvent
public void RenderWorldLastEvent(RenderWorldLastEvent event)
{
float partialTicks = event.getPartialTicks();
ClientPlayerEntity playerEntity = Minecraft.getInstance().player;
double x = playerEntity.lastTickPosX + (playerEntity.posX - playerEntity.lastTickPosX) * partialTicks;
double y = playerEntity.lastTickPosY + (playerEntity.posY - playerEntity.lastTickPosY) * partialTicks;
double z = playerEntity.lastTickPosZ + (playerEntity.posZ - playerEntity.lastTickPosZ) * partialTicks;
GlStateManager.pushMatrix();
GlStateManager.translated(-0.5 d, -playerEntity.getEyeHeight(), -0.5 d);
GlStateManager.disableCull();
GlStateManager.disableDepthTest();
GlStateManager.disableTexture();
GlStateManager.color4f(1, 1, 1, 1);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder wr = tessellator.getBuffer();
wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
wr.pos(0, 0, 0).endVertex();
wr.pos(1, 0, 0).endVertex();
wr.pos(1, 0, 1).endVertex();
wr.pos(0, 0, 1).endVertex();
wr.pos(0, 1, 0).endVertex();
wr.pos(1, 1, 0).endVertex();
wr.pos(1, 1, 1).endVertex();
wr.pos(0, 1, 1).endVertex();
tessellator.draw();
GlStateManager.enableCull();
GlStateManager.enableDepthTest();
GlStateManager.enableTexture();
GlStateManager.popMatrix();
}