Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by rajat · Aug 10, 2013 at 07:18 AM · anglesfunction update

Setting Quaternion , are Euler angles updated in the same update function?

I am setting a Quaternion in update function and i want to restrict it's rotation in Y-axis by accessing the Euler Angles. This seems to pe producing random results.

Will the Euler angles be updated when the Quaternion is set?

 void Update()
 {
 
 transforms[(int)ZigJointId.LeftHip].rotation = Quaternion.Slerp(transforms[(int)joint].rotation, newRotationLH, Time.deltaTime * RotationDamping);
 .
 .
 .
 transforms[(int)ZigJointId.LeftHip].localEulerAngles = new vector3(transforms[(int)ZigJointId.LeftHip].localEulerAngles.x,0,transforms[(int)ZigJointId.LeftHip].localEulerAngles.y);
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Aug 10, 2013 at 07:33 AM

First internally Unity stores rotations as Quaternions. So...

 transform.eulerAngles = new Vector3(25.0f, 33.0f, 10.0f);

...is equivalent to:

 transform.rotation = Quaternion.Euler(25.0f, 33.0f, 10.0f);

Second, the Euler angle representation that you pull back out of a Quaternion is not the same one you put in. That is there are multiple Euler representations for any given physical representation. For example try this code:

 transform.eulerAngles = new Vector3(180,0,0);
 Debug.Log(transform.eulerAngles);

The output is (0,180,180)...the same physical rotation in a different Euler angle representation.

So reading out a Euler angle with any expectation of a specific representation is can cause problem.

Since I don't have a solid knowledge of what you are trying to accomplish, I cannot suggest a specific fix or approach.

Comment
Add comment · Show 4 · 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
avatar image rajat · Aug 10, 2013 at 07:50 AM 0
Share

Thanks for the clear explanation! What i am trying to do is to set a rotation and restrict the rotation in the same update call.

I have a avatar whose legs gets inverted when i take data from $$anonymous$$inect, so what i am trying to do is to restrict the rotation but when i restrict the rotations other axis are also fucked up.

avatar image robertbu · Aug 10, 2013 at 09:35 AM 0
Share

I have to be able to visualize the problem to give a fix...drawings, short video, or a detailed explanation. As a guess, you could try this:

 Transform t = transforms[(int)ZigJointId.LeftHip];
 t.rotation = Quaternion.FromToRotation(t.forward, t.parent.forward) * t.rotation;

$$anonymous$$y second guess is:

 Transform t = transforms[(int)ZigJointId.LeftHip];
 Vector3 v3Aim = t.parent.forward - (Vector3.Dot(t.parent.forward, t.up) * t.up);
 t.rotation = Quaternion.FromToRotation(t.forward, v3Aim) * t.rotation; 
avatar image rajat · Aug 10, 2013 at 10:00 AM 0
Share

alt text This images shows, what the problem is:

This is the code responsible for setting up the rotation of joints, i am getting the 'orientation' from Openni SD$$anonymous$$ for kinect, intial rotations stores the rotations at the tpose of the avatar, all the joints work fine but OpenNI is not giving correct data for correct rotation of the lefthip joint:

 Quaternion newRotation = transform.rotation * orientation * initialRotations[(int)joint];
             if (mirror)
             {
                 newRotation.y = -newRotation.y;
                 newRotation.z = -newRotation.z;
             }
             transforms[(int)joint].rotation = Quaternion.Slerp(transforms[(int)joint].rotation, newRotation, Time.deltaTime * RotationDamping);
avatar image robertbu · Aug 10, 2013 at 03:26 PM 0
Share

$$anonymous$$y second guess above had something like this in $$anonymous$$d. It projects the forward of the parent object onto a plane of the child object and then rotates the child to the projected vector.

avatar image
0

Answer by Owen-Reynolds · Aug 10, 2013 at 02:54 PM

From your comment, setting individual x/y/z angles in a quaternion (newRotation) doesn't work. The problem, (as robertu mentions,) is that they all get changed around.

The trick is not to mix quats and x/y/z angles. If you have the normal x/y/z angles, you can adjust them all beforehand, then use quaternion.euler(x,y,z) at the end. Or use only quaternions -- do only quaternion multiply to change things.

But, angle math is tricky. That's why we have to use quaternions, local/worldSpace, lookAt with a free axis... . There are lots of problems, with very different solutions. I think your question is really "how do I combine these rotations, but with the middle hip rotation mirrored?"

Comment
Add comment · Show 2 · 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
avatar image rajat · Aug 10, 2013 at 06:51 PM 0
Share

Yes, you understood it correctly, but the middle hip rotation should not be mirrored as only the y angle is rotated, otherwise it works fine. Also, the left hip is inversted sometimes and sometimes it is fine. It is the problem of the tracking algorithm. So what is want to fix the rotation when the legs gets inverted.

avatar image Owen-Reynolds · Aug 11, 2013 at 02:16 AM 0
Share

The official Question you asked here is odd (the answer is that Quaternions and Updates are totally unrelated.) $$anonymous$$ight help if you re-asked, mentioning "Openni $$anonymous$$innect" (?) your code snippet and the problem. $$anonymous$$ake it easier for someone who models to find.

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.

Follow this Question

Answers Answers and Comments

15 People are following this question.

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

Related Questions

Shade Based on Normal Map World Position Angle (Updated) 1 Answer

how can i determine the angle of the face of an object relative to the world? 0 Answers

spotlights spot angle 1 Answer

Rotation around z-axis always local space and not world? Vector-axis angle projection calcuations. 0 Answers

Vector3.SignedAngle wrong direction when crossing the 0 point 1 Answer


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