public Vector4 Rotate4D(Vector4 v, Rotation4D r) { Matrix4x4 rotMat = Matrix4x4.identity; { // xy float sin = Mathf.Sin(rotation.xy * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.xy * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(cos, sin, 0, 0), new Vector4(-sin, cos, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1)); rotMat = m * rotMat; } { // yz float sin = Mathf.Sin(rotation.yz * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.yz * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, cos, sin, 0), new Vector4(0, sin, -cos, 0), new Vector4(0, 0, 0, 1)); rotMat = m * rotMat; } { // xz float sin = Mathf.Sin(rotation.zx * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.zx * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(cos, 0, -sin, 0), new Vector4(0, 1, 0, 0), new Vector4(sin, 0, cos, 0), new Vector4(0, 0, 0, 1)); rotMat = m * rotMat; } { // xw float sin = Mathf.Sin(rotation.xw * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.xw * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(cos, 0, 0, -sin), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(sin, 0, 0, cos)); rotMat = m * rotMat; } { // yw float sin = Mathf.Sin(rotation.yw * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.yw * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, cos, 0, -sin), new Vector4(0, 0, 1, 0), new Vector4(0, sin, 0, cos)); rotMat = m * rotMat; } { // zw float sin = Mathf.Sin(rotation.zw * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation.zw * Mathf.Deg2Rad); Matrix4x4 m = new Matrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, cos, -sin), new Vector4(0, 0, sin, cos)); rotMat = m * rotMat; } return(rotMat * v); }
// Start is called before the first frame update void Start() { visualVerteces = new Vector4[shapeVerteces.Length]; shapeVerteces.CopyTo(visualVerteces, 0); rotation = new Rotation4D(); }
} // TODO change back to local private void _SetLocalRotation(Rotation4D r) { transform.eulerAngles = r.ToEuler3D(); rot_w = r.ToEulerW(); } // the same