2x2 Matrix multiplication Template

Source: Internet
Author: User
Tags cos

Since unity has only a 4x4 matrix, today is going to do a 2x2 matrix rotation and actually forget the order. So write down as a template record.

Order:

The following is the C # code that you use to rotate it:

 Public structposition{ Public intX;  Public intY;  Public Override stringToString () {return "X:"+ X +"Y:"+Y;}}voidOnenable ()//Execute{    varPosition =NewPosition () {X =1, Y =0 }; varAnchor =NewPosition () {X =0, Y =0 }; Debug.Log ("Position:"+ position);//print position:x: 1 y:0Position = Rotation ( -, position, anchor); Debug.Log ("position rot:"+ position);//Print position rot:x: 0 y:1}position Rotation (floatRotvalue, Position Pos, Position anchor) {    varmatrix00 = Mathf.cos (Rotvalue *Mathf.deg2rad); varmatrix01 =-mathf.sin (Rotvalue *Mathf.deg2rad); varmatrix10 = Mathf.sin (Rotvalue *Mathf.deg2rad); varmatrix11 = Mathf.cos (Rotvalue *Mathf.deg2rad); varx = (float) Pos. Xanchor.    X vary = (float) Pos. Yanchor.    Y varRx = matrix00 * x + matrix01 *y; varry = matrix10 * x + matrix11 *y; X= Anchor. X +Rx; Y= Anchor. Y +ry; varIntX =mathf.roundtoint (x); varInty =mathf.roundtoint (y); return NewPosition () {X = IntX, Y =inty};}

2x2 Matrix multiplication Template

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.