当前位置: 首页>>代码示例>>C#>>正文


C# Vector4.Normalize方法代码示例

本文整理汇总了C#中UnityEngine.Vector4.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector4.Normalize方法的具体用法?C# Vector4.Normalize怎么用?C# Vector4.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Vector4的用法示例。


在下文中一共展示了Vector4.Normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SplitTriangle

 protected void SplitTriangle(FastHull topHull, FastHull bottomHull, int[] oldToNewVertexMap, Vector3 pointOnPlane, Vector3 planeNormal, int top, int cw, int ccw, out Vector3 cwIntersection, out Vector3 ccwIntersection)
 {
     Vector3 v0 = vertices[top];
     Vector3 v1 = vertices[cw];
     Vector3 v2 = vertices[ccw];
     
     // Intersect the top-cw edge with the plane
     float cwDenominator = Vector3.Dot(v1 - v0, planeNormal);
     float cwScalar = Mathf.Clamp01(Vector3.Dot(pointOnPlane - v0, planeNormal) / cwDenominator);
     
     // Intersect the top-ccw edge with the plane
     float ccwDenominator = Vector3.Dot(v2 - v0, planeNormal);
     float ccwScalar = Mathf.Clamp01(Vector3.Dot(pointOnPlane - v0, planeNormal) / ccwDenominator);
     
     // Interpolate vertex positions
     Vector3 cwVertex = new Vector3();
     
     cwVertex.x = v0.x + (v1.x - v0.x) * cwScalar;
     cwVertex.y = v0.y + (v1.y - v0.y) * cwScalar;
     cwVertex.z = v0.z + (v1.z - v0.z) * cwScalar;
     
     Vector3 ccwVertex = new Vector3();
     
     ccwVertex.x = v0.x + (v2.x - v0.x) * ccwScalar;
     ccwVertex.y = v0.y + (v2.y - v0.y) * ccwScalar;
     ccwVertex.z = v0.z + (v2.z - v0.z) * ccwScalar;
     
     // Create top triangle
     int cwA = topHull.vertices.Count;
     topHull.vertices.Add(cwVertex);
     
     int ccwA = topHull.vertices.Count;
     topHull.vertices.Add(ccwVertex);
     
     topHull.indices.Add(oldToNewVertexMap[top]);
     topHull.indices.Add(cwA);
     topHull.indices.Add(ccwA);
     
     // Create bottom triangles
     int cwB = bottomHull.vertices.Count;
     bottomHull.vertices.Add(cwVertex);
     
     int ccwB = bottomHull.vertices.Count;
     bottomHull.vertices.Add(ccwVertex);
     
     bottomHull.indices.Add(oldToNewVertexMap[cw]);
     bottomHull.indices.Add(oldToNewVertexMap[ccw]);
     bottomHull.indices.Add(ccwB);
     
     bottomHull.indices.Add(oldToNewVertexMap[cw]);
     bottomHull.indices.Add(ccwB);
     bottomHull.indices.Add(cwB);
     
     // Interpolate normals
     if (normals != null)
     {
         Vector3 n0 = normals[top];
         Vector3 n1 = normals[cw];
         Vector3 n2 = normals[ccw];
         
         Vector3 cwNormal = new Vector3();
         
         cwNormal.x = n0.x + (n1.x - n0.x) * cwScalar;
         cwNormal.y = n0.y + (n1.y - n0.y) * cwScalar;
         cwNormal.z = n0.z + (n1.z - n0.z) * cwScalar;
         
         cwNormal.Normalize();
         
         Vector3 ccwNormal = new Vector3();
         
         ccwNormal.x = n0.x + (n2.x - n0.x) * ccwScalar;
         ccwNormal.y = n0.y + (n2.y - n0.y) * ccwScalar;
         ccwNormal.z = n0.z + (n2.z - n0.z) * ccwScalar;
         
         ccwNormal.Normalize();
         
         // Add vertex property
         topHull.normals.Add(cwNormal);
         topHull.normals.Add(ccwNormal);
         
         bottomHull.normals.Add(cwNormal);
         bottomHull.normals.Add(ccwNormal);
     }
     
     // Interpolate colors
     if (colors != null)
     {
         Color32 c0 = colors[top];
         Color32 c1 = colors[cw];
         Color32 c2 = colors[ccw];
         
         Color32 cwColor = Color32.Lerp(c0, c1, cwScalar);
         Color32 ccwColor = Color32.Lerp(c0, c2, ccwScalar);
         
         // Add vertex property
         topHull.colors.Add(cwColor);
         topHull.colors.Add(ccwColor);
         
         bottomHull.colors.Add(cwColor);
         bottomHull.colors.Add(ccwColor);
//.........这里部分代码省略.........
开发者ID:turbosheep,项目名称:ThriveVR,代码行数:101,代码来源:FastHull.cs

示例2: SplitTriangle

 protected void SplitTriangle(LegacyHull topHull, LegacyHull bottomHull, Edge topEdge0, Edge topEdge1, Edge topCutEdge, Edge bottomEdge0, Edge bottomEdge1, Edge bottomCutEdge, Edge bottomEdge2, int vertex0, int vertex1, int vertex2, float scalar0, float scalar1, int[] oldToNewVertex)
 {
     Vector3 n0 = normals[vertex0];
     Vector3 n1 = normals[vertex1];
     Vector3 n2 = normals[vertex2];
     
     Vector4 t0 = tangents[vertex0];
     Vector4 t1 = tangents[vertex1];
     Vector4 t2 = tangents[vertex2];
     
     Vector2 uv0 = uvs[vertex0];
     Vector2 uv1 = uvs[vertex1];
     Vector2 uv2 = uvs[vertex2];
     
     // Calculate the cut vertex data by interpolating original triangle values
     Vector3 cutNormal0 = new Vector3();
     
     cutNormal0.x = n0.x + (n1.x - n0.x) * scalar0;
     cutNormal0.y = n0.y + (n1.y - n0.y) * scalar0;
     cutNormal0.z = n0.z + (n1.z - n0.z) * scalar0;
     
     cutNormal0.Normalize();
     
     Vector3 cutNormal1 = new Vector3();
     
     cutNormal1.x = n1.x + (n2.x - n1.x) * scalar1;
     cutNormal1.y = n1.y + (n2.y - n1.y) * scalar1;
     cutNormal1.z = n1.z + (n2.z - n1.z) * scalar1;
     
     cutNormal1.Normalize();
     
     Vector4 cutTangent0 = new Vector4();
     
     cutTangent0.x = t0.x + (t1.x - t0.x) * scalar0;
     cutTangent0.y = t0.y + (t1.y - t0.y) * scalar0;
     cutTangent0.z = t0.z + (t1.z - t0.z) * scalar0;
     
     cutTangent0.Normalize();
     cutTangent0.w = t0.w;
     
     Vector4 cutTangent1 = new Vector4();
     
     cutTangent1.x = t1.x + (t2.x - t1.x) * scalar1;
     cutTangent1.y = t1.y + (t2.y - t1.y) * scalar1;
     cutTangent1.z = t1.z + (t2.z - t1.z) * scalar1;
     
     cutTangent1.Normalize();
     cutTangent1.w = t1.w;
     
     Vector2 cutUv0 = new Vector2();
     
     cutUv0.x = uv0.x + (uv1.x - uv0.x) * scalar0;
     cutUv0.y = uv0.y + (uv1.y - uv0.y) * scalar0;
     
     Vector2 cutUv1 = new Vector2();
     
     cutUv1.x = uv1.x + (uv2.x - uv1.x) * scalar1;
     cutUv1.y = uv1.y + (uv2.y - uv1.y) * scalar1;
     
     // Add the cut vertices to the hulls
     int topCutVertex0, topCutVertex1;
     
     topHull.AddVertex(topEdge0.point0.position, cutNormal0, cutTangent0, cutUv0, topEdge0.point0, out topCutVertex0);
     
     topHull.AddVertex(topEdge1.point0.position, cutNormal1, cutTangent1, cutUv1, topEdge1.point0, out topCutVertex1);
     
     int bottomCutVertex0, bottomCutVertex1;
     
     bottomHull.AddVertex(bottomEdge0.point0.position, cutNormal0, cutTangent0, cutUv0, bottomEdge0.point0, out bottomCutVertex0);
     
     bottomHull.AddVertex(bottomEdge1.point0.position, cutNormal1, cutTangent1, cutUv1, bottomEdge1.point0, out bottomCutVertex1);
     
     // Create the top of the original triangle
     Triangle topTriangle = new Triangle(topCutVertex0, oldToNewVertex[vertex1], topCutVertex1, topEdge0.point0, topEdge0.point1, topEdge1.point0, topEdge0, topEdge1, topCutEdge);
     
     topHull.triangles.Add(topTriangle);
     
     // Create the bottom of the original triangle
     Edge bottomCrossEdge = new Edge(bottomEdge0.point1, bottomEdge1.point0);
     
     Triangle bottomTriangle0 = new Triangle(oldToNewVertex[vertex0], bottomCutVertex0, bottomCutVertex1, bottomEdge0.point1, bottomEdge0.point0, bottomEdge1.point0, bottomEdge0, bottomCutEdge, bottomCrossEdge);
     Triangle bottomTriangle1 = new Triangle(oldToNewVertex[vertex0], bottomCutVertex1, oldToNewVertex[vertex2], bottomEdge0.point1, bottomEdge1.point0, bottomEdge1.point1, bottomCrossEdge, bottomEdge1, bottomEdge2);
     
     bottomHull.edges.Add(bottomCrossEdge);
     bottomHull.triangles.Add(bottomTriangle0);
     bottomHull.triangles.Add(bottomTriangle1);
 }
开发者ID:turbosheep,项目名称:ThriveVR,代码行数:87,代码来源:LegacyHull.cs


注:本文中的UnityEngine.Vector4.Normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。