Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Jerdak · Feb 14, 2010 at 10:09 PM · transformquaternionorientationmocap

Manual Quaternions

For some reason I can't seem to wrap my head around this problem. Basically I have a series of quaternion orientations being supplied to Unity3D from an external program. The orientations are being pulled from a mocap system I'm using.

The orientations I get from the system are relative to a single global coordinate system. So they aren't related to any sort of parent transform.

The problem that I'm having is that I can't figure out where to supply my transformations. Because they aren't cumulative (IE, each orientation I get is the actual orientation and not the change since the last one) I can't use the update methods supplied.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by bruceb · Feb 15, 2010 at 03:45 PM

Here is the snippet of code that will give the localRotation of a child relative to its parent if you have the 2 world rotations.

childObj.transform.localRotation = Quaternion.Inverse(childObj.transform.parent.rotation) * theChild.transform.rotation

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
avatar image
0

Answer by Jaap Kreijkamp · Feb 14, 2010 at 11:16 PM

You could convert the absolute rotation to a relative rotation by multiplying it with the inverse of the current rotation.

Comment
Add comment · Show 1 · 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 Jerdak · Feb 14, 2010 at 11:34 PM 0
Share

Hmm, I'm a touch confused. Doesn't that just subtract out the current rotation from the absolute rotation? So if I've already rotated 45 degrees about X and I tell it to rotate 90 about X it will only rotate another 45?

This is fine except for 2 things: 1.) The current rotation of my object's limb was set in 3DS $$anonymous$$ax. So the base rotation for the arm, for example, is already at Euler(5,5,0). When I rotate that by 90 around X it should be 90 + what I already have. 2.) This doesn't seem take in to account if I rotate my person in the scene.

avatar image
0

Answer by Jerdak · Feb 15, 2010 at 12:08 AM

I'll be the first to admit my understanding of all of this is tenuous at best.

The following is my solution. Visually it seems to work as I want. The part I find slightly off is the conversion of the quaternion axis by the current base orientation. I did this on a whim to see what would happen. Oh and for some reason it won't rotate about the x-axis unless I update the z value of my quaternion?

public class Keyboard : MonoBehaviour { public GameObject objArm; public GameObject pivot; private Vector3 objPosition; private Quaternion objRot; private Quaternion lastRot = Quaternion.identity;

 private float rot = 0.0f;
 private int rotDir = 1;
 public float rotationIncr = 0.1f;

 private bool updateFromParent = false;
 ///Called from MouseLook.cs to tell player controller it's base orientation is in need of update
 void UpdateRotationFromParent(){
     objArm.transform.rotation = pivot.transform.rotation;
     objRot = objArm.transform.rotation;
     updateFromParent = true;
     RotateArm(lastRot);
 }
 // Use this for initialization
 void Start () {
     Screen.showCursor = false;
     Screen.lockCursor = true;
     UpdateRotationFromParent();
 }

 // Update is called once per frame
 void Update () {
     if (Input.GetKey ("escape")) {
         Application.Quit();
     }
     UpdateArm();
 }
 void RotateArm(Quaternion q){
     float angle = 0.0f;
     Vector3 axis = Vector3.zero;

     q.ToAngleAxis(out angle, out axis);

     ///Reorient axis of rotation to current object rotation
     axis = objRot * new Vector3(axis.x,axis.y,axis.z);

     //print("Rot: " + rot + " Axis: " + axis + " Angle: " + angle + " objRot: " + objRot);
     objArm.transform.rotation = objRot;
     objArm.transform.RotateAround(pivot.transform.position,axis,angle);
 }
 void UpdateArm () {
     {    ///Update rotation to simulate movement about Z axis from 0-90
         rot += rotationIncr * (float)rotDir;
         if(rot > 90.0f || rot < 0.0f){
             rotDir *= -1;
         }
     }

     ///
     Quaternion q = Quaternion.Euler(rot,0.0f,0.0f);
     lastRot = q;
     RotateArm(q);
 }

}

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Quaternion rotation with normals bug: Only works into one direction? 1 Answer

Commands affecting rotation not working 1 Answer

Adding Rotation to a Gameobject 1 Answer

Transform a Vector by a Quaternion 1 Answer

Perpendicular Vector3 0 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