GMU:Tutorials/Networking/Controlling Objects in Unity with The Captury: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 9: Line 9:
At first we should understand some concepts.There are three ways to represent rotation that is rotation matrix, quaternion and Euler, theCaputry uses rotation matrix, Unity uses  Quaternion and  Euler. This tutorial focus on  Rotation matrix, Quaternion.<br>
At first we should understand some concepts.There are three ways to represent rotation that is rotation matrix, quaternion and Euler, theCaputry uses rotation matrix, Unity uses  Quaternion and  Euler. This tutorial focus on  Rotation matrix, Quaternion.<br>


*4×4 Rotation matrix<br>
4×4 Rotation matrix<br>
TheCaputry uses it to represent rotation. Unity had only provided a 4 × 4 matrix class Matrix4x4, it contains transform T, rotation R and scaling information. You can refer to [https://en.wikipedia.org/wiki/Rotation_matrix].<br>
TheCaputry uses it to represent rotation. Unity had only provided a 4 × 4 matrix class Matrix4x4, it contains transform T, rotation R and scaling information. You can refer to [https://en.wikipedia.org/wiki/Rotation_matrix].<br>
   
   
Line 18: Line 18:
2.  It will increase the amount of calculation when doing multiplication operation and resultin some waste of space and time;
2.  It will increase the amount of calculation when doing multiplication operation and resultin some waste of space and time;


*Quaternion<br>
Quaternion<br>
Quaternions are used to represent rotations. Mostly you can use Quaternion AngleAxis(float angle, Vector3 axis) to create a quaternion.Unity internally uses Quaternions to represent all rotations. you can refer to:[https://docs.unity3d.com/ScriptReference/Quaternion.html]<br>
Quaternions are used to represent rotations. Mostly you can use Quaternion AngleAxis(float angle, Vector3 axis) to create a quaternion.Unity internally uses Quaternions to represent all rotations. you can refer to:[https://docs.unity3d.com/ScriptReference/Quaternion.html]<br>


Line 32: Line 32:
We might need to convert rotation matrix to quaternion depend on your project needs after we get data from theCaptury in matrix format.There i present two ways to convert there two.
We might need to convert rotation matrix to quaternion depend on your project needs after we get data from theCaptury in matrix format.There i present two ways to convert there two.


*Convert quaternion to 4×4 Rotation matrix.<br>
Convert quaternion to 4×4 Rotation matrix.<br>
  <source lang="csharp">
  <source lang="csharp">
Quaternion q = Quaternion.LookRotation(new Vector3(0,0.5,1));   
Quaternion q = Quaternion.LookRotation(new Vector3(0,0.5,1));   
Line 39: Line 39:
</source>
</source>


*Convert  4×4 Rotation matrix to quaternion.<br>
Convert  4×4 Rotation matrix to quaternion.<br>
  <source lang="csharp">
  <source lang="csharp">
Matrix4x4 rot = new Matrix4x4();   
Matrix4x4 rot = new Matrix4x4();   
Line 48: Line 48:
</source>
</source>


*Other conversion
Other conversion
[http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm Euler to Quaternion]<br>
[http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm Euler to Quaternion]<br>
[http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm Quaternion To Euler]<br>
[http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm Quaternion To Euler]<br>
Line 55: Line 55:


== Cover the OSC syntax and how to get nodes as matrix / vector, absolute and relative ==
== Cover the OSC syntax and how to get nodes as matrix / vector, absolute and relative ==
Cover the OSC syntax and get nodes as matrix / vector<br>
Cover the OSC syntax and get nodes as matrix / vector<br>
With OSC you can subscribe to the following:
With OSC you can subscribe to the following:
1. subscribe to a bone position,rotation as vector in world coordinates for positions:<br>
1. subscribe to a bone position,rotation as vector in world coordinates for positions:<br>
Line 80: Line 80:
<br style=“clear:both”>
<br style=“clear:both”>


*You can use transform.localPosition to get position of the transform relative to the parent transform.
You can use transform.localPosition to get position of the transform relative to the parent transform.


== How to create objects in Unity and arrange them so they represent the nodes ==
== How to create objects in Unity and arrange them so they represent the nodes ==
Line 117: Line 117:
</source>
</source>


4.  Video
4.  [https://www.youtube.com/watch?v=VVhXqrPgMJ0&feature=youtu.be Video]