Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
}

 

  • Author

I just managed to fix the issue. For anyone who find this post in the future, I used the following code to do it:

Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();

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.translated(x - projectedView.x - 0.5d, y - projectedView.y, z - projectedView.z - 0.5d);

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.