• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by LightAdept · Jan 06, 2013 at 09:40 AM · bugrotatejava

Techne Y Rotation Bug (Minecraft modeling program)

Ok. First time here, but im running out of options. Hope you can help!

The problem is, in the program Techne, the rotation is a little glitchy. The X Y and Z all work fine, but if you try to do anything in combination (besides X and Z) it doesnt work. After lots of testing. I've concluded this. The Y doesnt take the local rotation of the object, only its beginning rotation point. To put it simpler, If i rotate an object along the Z axis any amount of degrees, lets say 40, Then the Y still thinks its at 0, and rotates accordingly. So lets say we're looking at the object in 3D, and we're looking straight at the XY axis, so we only see one face of a cube. If we rotate that Z 40 degrees, it rotates Clockwise 40 degrees. The problem is that when rotating the Y, Instead of rotating along the new Axis, it still rotates along the origin. So it rotates perfectly.....idk how to say this, Cylindrical. Instead of rotating Up and to the left, it just rotates to the left. After comparing techne to Blender, i've found that the problem is, for some reason, the Y will only rotate along its Delta. Now, im hopeless at math, and doubt i even got far enough into math to know half this stuff. So if i used any terms wrong, please comment and ask questions, CAUSE I NEED THIS ANSWERED.

Now, the whole reason im asking this, is because we can make our models all fine and dandy, but where the bug SHOWS is in the code. We export this models into java, and the Java does the rotations CORRECTLY. So now, our models are messed up, because the Y on some blocks isnt where our modellers though it would be.

So here's my question, What would i need to do, formula wise, java wise, anything! to get that bug to become "correct". So that what we see in techne, appears in minecraft, even though the Y is bugged.

Hope i explained well enough, if you need any further explaination, please comment!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tprk77 · Feb 12, 2017 at 05:35 PM

Despite this being a super old post, I'm going to answer it because it's the fist hit on Google for "Techne rotations", etc. And I happened to run into the same issue. Just sorry I'm a few years too late.

So, the problem is that Techne is exporting the Euler angles (the X, Y, and Z angles) assuming a YZX order. What that means is, first the rotation around the Y axis is applied, then the rotation around the Z axis, then around the X axis. But Minecraft actually uses Euler angles in ZYX order. So basically the exported angles are wrong if you have any rotation around the Y axis.

To fix this, you need to convert from YZX ordered Euler angles to ZYX ordered Euler angles. This function I wrote should do the trick:

     private Vector3f ConvertEulerYzxToZyx(Vector3f eulerYzx) {
         // Create a matrix from YZX ordered Euler angles
         float a = MathHelper.cos(eulerYzx.x);
         float b = MathHelper.sin(eulerYzx.x);
         float c = MathHelper.cos(eulerYzx.y);
         float d = MathHelper.sin(eulerYzx.y);
         float e = MathHelper.cos(eulerYzx.z);
         float f = MathHelper.sin(eulerYzx.z);
         Matrix4f matrix = new Matrix4f();
         matrix.m00 = c * e;
         matrix.m01 = b * d - a * c * f;
         matrix.m02 = b * c * f + a * d;
         matrix.m10 = f;
         matrix.m11 = a * e;
         matrix.m12 = -b * e;
         matrix.m20 = -d * e;
         matrix.m21 = a * d * f + b * c;
         matrix.m22 = a * c - b * d * f;
         matrix.m33 = 1.0F;
         // Create ZYX ordered Euler angles from the matrix
         Vector3f eulerZyx = new Vector3f();
         eulerZyx.y = (float) Math.asin(MathHelper.clamp_float(-matrix.m20, -1, 1));
         if (MathHelper.abs(matrix.m20) < 0.99999) {
             eulerZyx.x = (float) Math.atan2(matrix.m21, matrix.m22);
             eulerZyx.z = (float) Math.atan2(matrix.m10, matrix.m00);
         } else {
             eulerZyx.x = 0.0F;
             eulerZyx.z = (float) Math.atan2(-matrix.m01, matrix.m11);
         }
         return eulerZyx;
     }

You can just convert the rotations as they're set:

     private void setRotationWithEulerYzx(ModelRenderer model, float x, float y, float z) {
         Vector3f eulerYzx = new Vector3f(x, y, z);
         Vector3f eulerZyx = ConvertEulerYzxToZyx(eulerYzx);
         model.rotateAngleX = eulerZyx.x;
         model.rotateAngleY = eulerZyx.y;
         model.rotateAngleZ = eulerZyx.z;
     }

Now just replace all the setRotation with setRotationWithEulerYzx, and your model will work.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity rotation bug??? or my mistake (with video) 1 Answer

How to use Unity3D physics to make a robot hand move and grab an object? 1 Answer

Changeing Camera Position 1 Answer

rotation.y gets wrong data 1 Answer

Camera rotation around player while following. 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges