Unity3d-Mathematical Correlation

Source: Internet
Author: User

1. Transform. Rotation: rotation of the object in the world coordinate system; transform. localrotation: rotation of the object in the Local Coordinate System of the parent object. The two variables are of four types.

(1) Get the angle-axis representation of the current rotation of the game object

Transform. Rotation. toangleaxis (angle, axis );

(2) return to zero. The coordinate axes of the local coordinate system are parallel to those of the world coordinate system.

Transform. Rotation = Quaternion. identity;

(3) orientation the object to the target

Relativepos = target. Position-transform. position;

Rotation = Quaternion. lookrotation (relativepos );

Transform. Rotation = rotation;

(4) moving an object from a smooth difference to can be used to simulate the effect of the camera's transition from object A to object B.

Transform. Rotation = Quaternion. slerp (from. rotation, To. rotation, time. deltatime * speed)

2. Coordinate System: common coordinate systems include the world coordinate system, local coordinate system, camera coordinate system, and screen coordinate system. Transform. transformpoint can be used to convert coordinate points from a local coordinate system to a world coordinate system, transform. inversetransformpoint can convert coordinate points from the world coordinate system to the local coordinate system; transform. transformdirection and transform. inversetransformdirection converts vectors between the world coordinate system and the local coordinate system. For example, convert the object location to the coordinates in the camera coordinate system:

Cam = camera. Main. Transform;

Camerarelative = cam. inversetransformpoint (transform. position)

If (camerarelative. z> 0)

Debug. Log ("the object is in front of camera ");

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.