Jump to content

Custom Sky Renderer Using Quaternion to Rotate One Vector to Another


Floydman

Recommended Posts

This is a follow-up to a question I asked earlier on Discord but didn't get resolved: I am working on a custom sky renderer, and my goal is to be able to take 2 vectors, one representing the in-game y-axis and the other pointing toward the object I want to render, generate a quaternion that rotates the first to become the second, and give that quaternion to the MatrixStack to render the object in the correct place. When I brought it up before, I was a little unsure of my vector math, but I have now verified that when using my quaternion to rotate the first vector, it perfectly (or almost perfectly since I'm dealing in floats) rotates to become the second vector. (I've even put together a Mathematica workbook that shows all the vectors behaving like they should.) However, when giving this quaternion to the MatrixStack, I still get very odd behavior. (For example, even with no orbital or axial tilt, the sun renders a very odd path instead of it's normal vanilla circle.) So what I'm thinking is that I must be messing up the rendering code, even though I basically copied how Minecraft renders its sky objects.

Here are the two classes I am using (one for vector math and the other for rendering): https://gist.github.com/TheFloydman/3443e0b888dd04f2770a785080e8b76d

I am aware there are simpler ways to render a stationary sun around which the Minecraft planet is orbiting, but I'm using this as a simple situation to prepare for something more complex, like a planet or comet is is orbiting the sun. If I can describe an object's current position with a vector, I want to be able to render it correctly.

Edit: Adding an animation to demonstrate what should be happening. The black vector is the current rotation of the observer, red is the position of the observer, green is the position of another orbiting planet, and blue is the vector generated when I transform the black rotation vector with the quaternion I generate. This view is from overhear, but the orbital inclinations of each planet is 7 degrees, and the observer's planet is tilted 23 degrees. As you can see, no matter where the black observer rotation and green other planet vectors are pointed, the blue vector always points from the observer's planet to the other planet.

fyJEC.gif

Edited by Floydman
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.