Quaterion
A quaternion can be understood as a rotation axis vector and a rotation angle. Note: This is not a point rotating around an axis, but a vector rotating around an axis. What you get after rotation is also a vector. Therefore, if you want to calculate the coordinates of a point P rotated by an angle around a fixed axis, you first need to fix a point S on the axis, and connect SP to form a vector. Use the quaternion to calculate the rotated vector, and add the coordinates of point S to get the rotated coordinates.
Example: Calculate the coordinates of a point rotated by a certain angle around a certain axis
static function RotateAroundPoint(point : Vector3, pivot : Vector3, angle : Quaternion) : Vector3
{
var finalPos : Vector3 = point – pivot;
//Center the point around the origin
finalPos = angle * finalPos;
//Rotate the point.
finalPos += pivot;
//Move the point back to its original offset.
return finalPos;
}//
unity3d video tutorial
var newPos = SomeClass.RotateAroundPoint(Vector3.forward, Vector3.zero, Quaternion.Euler(0, 90, 0) );
Debug. Log(newPos);
//Prints (1, 0, 0) or is it (-1, 0, 0 )? Something like 2.html
Quaternions Other URLs
http://hi.baidu.com/czx_main/blog/item/71468e3690f438390a55a992.html
http://oulehui.blog.163.com/blog/static/796146982011273184592/
http://www.cnblogs.com/softimagewht/archive/2010/11/16.html
Generally speaking, there is no concept of clockwise or counterclockwise in three-dimensional space. The distinction between clockwise and counterclockwise is only when we have identified a direction of sight. Most quaternions stipulate that, when viewed from the opposite direction of the rotation axis, counterclockwise angles are positive. For example, if your rotation axis is in the positive direction of the z-axis (for example, the axis protruding from the screen), then when I look at the screen (that is, the opposite direction of the z-axis), the angle of counterclockwise rotation is positive, and the angle of clockwise rotation is negative. . This is mostly the case unless the quaternion you’re using makes a special provision.
2, Gimbal Lock and EulerAngle
Gimbal Lock video: http://www.cnblogs.com/mavaL/articles/1860354.html
2011-03-24
Transform
1, .transform.forward The direction of the z-axis of the object in the world coordinate system, as shown in the figure below
transform.forward = (1,0,0) and Vector3.forward indicates the direction of the z-axis of the world coordinate system, namely: (0,0,1)
unity3d forum Test example:
transform.Translate(transform.forward*Time.deltaTime);//
The object will move (1,0,0) units per second relative to its own coordinate system, that is: move down.
transform.Translate(Vector3.forward*Time.deltaTime);//
The object will move (0,0,1) units per second relative to its own coordinate system, that is: move to the right.
2, transform. Rotate (eulerAngles : Vector3, relativeTo : Space = Space. Self)
Note that the rotation of eulerAngle is sequential. In Unity, the rotation is in the order of z-x-y.
3, transform.RoateAround (point : Vector3, axis : Vector3, angle : float)
It can realize the rotation of one object around another object. Example:
transform.RotateAround(_target.transform.position,Vector3.up,Time.deltaTime*_speed);// Rotate around the _target object, the rotation axis is the y axis
(Vector3.up, Time.deltaTime*_speed);//Rotate around the y axis, pay attention to the distinction:
transform.RotateAround(transform.up, Time.deltaTime*_speed);
4, function TransformDirection (direction: Vector3) : Vector3
//Convert local coordinates to world coordinates, for example:
Vector3 vecRet = transform.TransformDirection(Vector3.right);//Transform the (1,0,0) point in the local coordinate system to a point in the world coordinate system. The value of vecRet is (0,0,-1). This value is equivalent to the value of transform.right,
5. InverseTransformDirection(Vector3.right) returns (0,0,-1), as shown in the figure below:
Example:
relativePosition = cameraTransform.InverseTransformDirection(transform.position – cameraTransform.position);
6, transform. TransformPoint(2,0,0);//
Let’s say that if you hold your right arm straight out to the side, the local-space coordinate (2, 0, 0) is at the tips of your fingers. No matter where you go or how you orient yourself, as Long as you keep your arm straight out, the tips of your fingers will still be at exactly the same location in local space.
However, as you move and re-orient yourself, the world-space position of the tips of your fingers is constantly changing. This is what TransformPoint() does; it takes the local-space coordinate ((2, 0, 0) in this case) and converts it to a world-space coordinate based on the current transform for the object (the object being you in our example).
Example: Create a _target object at a distance of 2 units to the right of the current object.
Instantiate(_target, transform.TransformPoint(Vector3.right*2), transform.rotation);
.InverseTransformPoint() converts world coordinates toThe points under � are transformed into points in the relative coordinate system. For example, the coordinates of the object displayed on the Inspector panel are points in the world coordinate system. If this function is called, the return value is (0,0,0)
transform.InverseTransformPoint(new Vector3(2630.192f, 763.5179f,1161.068f));
7, static function FromToRotation (fromDirection : Vector3, toDirection : Vector3)
Rotate the fromDirection direction of the object to the toDirection direction, for example: rotate the direction (1,0,1) of the angle bisector of the object x and z to the direction of the z-axis of the century coordinate system.
public Vector3 _fromDir;
public Vector3 _toDir;
Quaternion q = Quaternion. identity;
q.SetFromToRotation(_fromDir, _toDir);
//Equivalent to q = Quaternion.FromToRotation(_fromDir, _toDir);
transform. rotation = q;
print(transform. right. ToString());
spin front
after rotation
8, Quaternion.()
Create a rotation so that the z-axis faces the view and the y-axis faces up. Its function is the same as that of LookRotation
9, Quaternion. AngleAxis(angle : float, axis:Vector3)
Create a rotation which rotates angle degrees around axis
Create a rotation around the axis rotation angle degrees, for example:
transform.rotation = Quaternion.AngleAxis(30.0f, Vector3.up);//Set the rotation angle of the object to 30 degrees around the Y axis. Regardless of the object’s previous rotation, the final rotation is the one set by the code above. as the picture shows:
Forward
after rotation
10, Quaternion. Angle()
Calculates the angle between two rotations. Same as Vector3.Angle(a : Quaternion, b : Quaternion).
Reference website: http://www.cnblogs.com/softimagewht/archive/2010/11/16.html
11, Unity3D uses a left-handed coordinate system, namely: Z-axis direction), hold to the right (X-axis direction),
The direction of the thumb is the Y-axis direction.