In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Unity how to achieve any angle around any axis rotation vector, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
There is a requirement in the game, that is, a rectangle or Cube rotates at any angle around a certain point. Now give the following algorithm.
Public static Vector3 RotateRound (Vector3 position, Vector3 center, Vector3 axis, float angle) {Vector3 point = Quaternion.AngleAxis (angle, axis) * (position-center); Vector3 resultVec3 = center + point; return resultVec3;}
Test case
Using UnityEngine;using System.Collections; public class RotateTest: MonoBehaviour {public LineRenderer line1; public LineRenderer line2; public float angle = 30f; private Vector3 v0; private Vector3 v1; private Vector3 v2; private Vector3 v3; private Vector3 v4; private Vector3 vCenter; void Start () {v0 = new Vector3; v1 = new Vector3 (1f, 0f, 3f); v2 = new Vector3 (4f, 0f, 6f); v3 = new Vector3 (6f, 0f, 4f); vCenter = new Vector3 (2f, 0f, 2f) } / / Use this for initialization void Update () {line1.SetVertexCount (5); line1.SetPosition (0quotient v0); line1.SetPosition (1scorev1); line1.SetPosition (2pencev2); line1.SetPosition (3scorev3); line1.SetPosition (4Powerv0); line2.SetVertexCount (5); Vector3 v01 = MathUtils.RotateRound (v0, vCenter, Vector3.up, angle); Vector3 v11 = MathUtils.RotateRound (v1, vCenter, Vector3.up, angle); Vector3 v21 = MathUtils.RotateRound (v2, vCenter, Vector3.up, angle) Vector3 v31 = MathUtils.RotateRound (v3, vCenter, Vector3.up, angle); Vector3 v41 = MathUtils.RotateRound (v4, vCenter, Vector3.up, angle); line2.SetPosition (0, v01); line2.SetPosition (1, v11); line2.SetPosition (2, v21); line2.SetPosition (3, v31); line2.SetPosition (4, v01);}}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.