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
  On 9/17/2017 at 5:47 PM, ctbe said:

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

Expand  

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.

 

  Reveal hidden contents

 

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
  On 9/17/2017 at 7:41 PM, Elix_x said:
Expand  

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
  On 9/17/2017 at 7:43 PM, 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).

Expand  

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*

  Reveal hidden contents

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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