Jump to content

[1.12.2] [SOLVED] Rolling the camera around a point in the world


FredTargaryen

Recommended Posts

Hi,
This gif from a 1.7.10 mod shows the camera turning as the coaster turns. It feels like the camera is fixed onto the coaster.
It accomplished this with a coremod that inserted a GL11.rotated call at the start of orientCamera.

For some reason, trying the same thing in 1.12.2 produces this! The camera hovers above the coaster in the world regardless of its orientation.

 

I've experimented with a lot of different GL translations to replicate the first effect but it's been difficult trying to find translations that work for all camera orientations - made more difficult by those translations being relative to the screen rather than the world, so knowing where the camera should be in the world relative to the coaster is not enough.

Trying this using the CameraSetup event has the same effect as the second gif but the mouse no longer lines up with where the player is looking.


So I am hoping that anyone out there knows any of:

  • GL commands to move the camera along the world axes instead of the screen axes
  • How to convert some world coordinates to screen coordinates, so that maybe I can move the camera that way (I thought about maybe using the modelview matrix but don't know the best way to get hold of that)
  • A different method that accomplishes the original effect
  • Why the effect of added roll has changed between 1.7.10 and 1.12.2
  • The obvious answer that I've probably missed because of massive tunnel vision
  • Anything else that might help

 

Thanks for reading.

Edited by FredTargaryen
Link to comment
Share on other sites

  • 4 months later...

Well I figured it out; maybe this is helpful for 1.14.4 and beyond too.

Declare a Vec3d representing the offset in the world. This is how much the world will be translated around the camera.

The following statements transform that world offset into screen coordinates, so that no matter where the player is looking the camera moves by the same offset in the world.

   Vec3d alignedToYaw = rotateAroundVector(offsetVec, new Vec3d(0, 1, 0), player.rotationYaw * Math.PI / 180);
   Vec3d alignedToPitch = rotateAroundVector(alignedToYaw, new Vec3d(1, 0, 0), player.rotationPitch * Math.PI / 180);
   //Put rotation first, so it comes out, then turns at the point it came out to
   GL11.glRotatef(prevRotationRoll + (rotationRoll - prevRotationRoll) * f, 0.0F, 0.0F, 1.0F);
   GL11.glTranslated(alignedToPitch.x, alignedToPitch.y, -alignedToPitch.z);

If you swap the rotate and translate, this is effectively rotating your offset vector and you won't see a camera tilt.

rotateAroundVector is a function that takes one vector and returns the rotated vector using another vector as the axis.

You can implement your own or see an example implementation here.

  • Like 1
Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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