Jump to content

How to rotate OBJ around specific point always?


Recommended Posts

Posted (edited)

I previously asked this question and I was told to translate, rotate, then translate back. After many hours of debugging trying to understand what was going wrong, I have come to the conclusion that it doesn't work like that. When one rotates using GlStateManager.rotate, all the axes of the OBJ rotate as well. In other words, the final translation will translate in reference to the rotated axis, making it impossible to translate to it's previous position. For example:

 

// Move in the x axis 0.5 (works fine)
GlStateManager.translate(0.5, 0, 0)
// Rotate around the z axis, 45 degrees (code breaks. the object rotates as intended, but all the axes get rotated as well)
GlStateManager.rotate(45f, 0f, 0f, 1f)
// Return the object to its previous position (Doesn't work, translates the object diagonally because the axes changed)
GlStateManager.translate(-0.5, 0, 0)

 

How would one rotate the OBJ without the OBJ axes being rotated?

Edited by ctbe
typo
Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thanks for the answer, but I give up. I think no one has ever managed to do a custom chest in minecraft. If they did, they had a thorough understanding of what opengl is doing. I don't.

 

I'll make my chest a simple static block. No animation or anything.

Posted
8 minutes ago, ctbe said:

I think no one has ever managed to do a custom chest in minecraft.

Cough:

http://mod-minecraft.net/iron-chests-mod/

 

In order to rotate around a point you need to translate to the origin by that point's offset from the origin, then rotate, then translate back.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

It's okay guys. I appreciate the intention on helping :), but I'm really leaving it since this has been eating me for too long. If anyone asks me to add animation to my chests for when the lid opens and close I'll just tell them I don't know how to do it as I don't understand the GL. Don't worry :). Here is an illustration in 2D of what I meant in my first post that is happening with the gl calls.

 

Spoiler

yIGVfs.png

 

In step 3, all the axes of reference get rotated. Meaning that any translation in the x axis afterwards, will be diagonal. This is 2D, but in minecraft, all 3 axes of reference get rotated together with  the object (x, y, z).

Posted
2 minutes ago, Elix_x said:

So I grabbed the first link on google for what I knew existed. 9.9

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, ctbe said:

In step 3, all the axes of reference get rotated. Meaning that any translation in the x axis afterwards, will be diagonal. This is 2D, but in minecraft, all 3 axes of reference get rotated together with  the object (x, y, z).

This is the definition of matrices. Understanding matrices will definitely help you solve this. I recommend watching this:

Linear transformations and matrices | Essence of linear algebra, chapter 3*

Spoiler

 

 

As for how to rotate around an axis, in 3D, you can look at how utility method is implemented in JOML:

https://github.com/JOML-CI/JOML/blob/c312304fefbe757e3d37cba866f5742b3448a85c/src/org/joml/Matrix4f.java#L11379

 

This is generic use case, but now i have to correct you. What you put in the "What is happening" is not correct. Because in both translation, rotation and scaling, coordinates do "the same" what the model does (it is actually the opposite - model does whatever you do to the coordinate system).

That said, the transformations you apply further down in the stack, actually apply to the already transformed coordinates as a whole, so

multiplication_order.jpg

 

  • Like 1
Posted (edited)

Why thanks for the references and explanation.

 

I know I said I'm leaving it, but just to show my whole problem, here is the rendering result of my code and the code itself that makes the linked video.

 

Lid Rotation: https://vgy.me/EvxpWl


Chest Body Rotation (how I wanted the lid to rotate): https://vgy.me/NOOLZg


Code... (This code is quite a bit so don't worry if you don't look at it. I'm opting for going static.)

  1. TileEntity (TileEntitySimpleChest.kt)
  2. Block properties
  3. Block (BlockSimpleChest.kt)
  4. TileEntitySpecialRenderer (TileEntitySimpleChestRenderer.kt)
  5. Blockstate JSON (blocksimplechest.json)
  6. Chest Model (simple_chest.obj)
  7. Chest MTL (simple_chest.mtl)
  8. Lid Model (simple_chest_lid.obj)
  9. Lid MTL (simple_chest_lid.mtl)


This was an extension of the tutorial: https://wiki.mcjty.eu/modding/index.php/Render_Block_TESR_/_OBJ-1.12  but I changed a lot of it to fit my purposes. Though the rendering code is pretty much a copy paste.

 

No amount of transformation fixes the problem for me. The problem must be me and I could never identify what I was doing wrong. The code I provided here renders the first video only. The chest body rotation happens if one uses false for the IS_CHEST_LID property in the TileEntitySpecialRenderer... in case you wonder how I shifted from rotating the lid to rotate the chest body in the second video.

Edited by ctbe
Better formatting
Posted

Just as Draco said, you have to translate the lid such that it's origin is world origin, rotate, then translate it back.

Notice GlStateManager.translate(x, y, z) in the beginning of the method. This method translates tile entity in the world view space. Now the origin (0,0,0) is "actually" the XYZ of the tile entity, AKA you're working in local coordinates - coordinates relative to the origin of tile/model. So you have to translate the lid by it's local model coordinates to local origin and back. Ex: GL.trans(-lidModelCoords).rot(rot).trans(lidModelCoords).

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.