Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //transformedVertices = new Vector2[newGeometryEstimate];
- transformedVertices.EnsureCapacity(newGeometryEstimate);
- // Based on the algorithm described above, this will create a matrix permitting us
- //to multiply a given vertex yielding a vertex transformed to an XY plane (where Z is
- //undefined.)
- // This algorithm cannot work if we're already in that plane. We know if we're already
- //in that plane if X and Y are both zero and Z is nonzero.
- bool canUseSimplifiedTransform = Mathf.Approximately(plane.x, 0f) && Mathf.Approximately(plane.y, 0f);
- if (!canUseSimplifiedTransform) {
- Matrix4x4 flattenTransform;
- Vector3 v1 = Vector3.forward;
- Vector3 v2 = new Vector3(plane.x, plane.y, plane.z).normalized;
- Vector3 v3 = Vector3.Cross(v1, v2).normalized;
- Vector3 v4 = Vector3.Cross(v3, v1);
- float cos = Vector3.Dot(v2, v1);
- float sin = Vector3.Dot(v2, v4);
- Matrix4x4 m1 = Matrix4x4.identity;
- m1.SetRow(0, (Vector4)v1);
- m1.SetRow(1, (Vector4)v4);
- m1.SetRow(2, (Vector4)v3);
- Matrix4x4 m1i = m1.inverse;
- Matrix4x4 m2 = Matrix4x4.identity;
- m2.SetRow(0, new Vector4(cos, sin, 0, 0));
- m2.SetRow(1, new Vector4(-sin, cos, 0, 0));
- flattenTransform = m1i * m2 * m1;
- for (int i = 0; i < newVertices.Count; i++) {
- transformedVertices.AddUnsafe((Vector2)flattenTransform.MultiplyPoint3x4(newVertices[i]));
- }
- }
- else {
- for (int i = 0; i < newVertices.Count; i++) {
- transformedVertices.AddUnsafe(new Vector2(newVertices[i].x, -newVertices[i].y));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement