本文整理汇总了C#中UnityEngine.Plane.Set3Points方法的典型用法代码示例。如果您正苦于以下问题:C# Plane.Set3Points方法的具体用法?C# Plane.Set3Points怎么用?C# Plane.Set3Points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Plane
的用法示例。
在下文中一共展示了Plane.Set3Points方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: init
protected void init(){
for (int i=0; i<normals.Count; i++) {
avgNormal+=normals[i];
}
avgNormal /= normals.Count;
plane = new Plane ();
plane.Set3Points (positions[0],positions[1],positions[2]);
bounds = MeshUtils.createBounds (positions/*, avgNormal, centerPos, true*/);
extendedBounds = new Bounds (bounds.center, bounds.size + MeshUtils.MAX_ROUND_ERROR);
}
示例2: DoesLaserCrossesMesh
public bool DoesLaserCrossesMesh()
{
if (!_isEmitting)
{
return false;
}
Vector3 capsuleNormal = _tr.up;
Vector3 capsuleOrigin = _tr.position - capsuleNormal * _length;
float capsuleRadius = 0.01f;
Mesh bakedMesh = new Mesh();
_pokeball._content._skinnedMesh.BakeMesh(bakedMesh);
Vector3[] vertex = new Vector3[3];
Vector3[] vertexWorldPosition = new Vector3[3];
Vector3 planeCenter, planeNormal, projection, projectionOnPlane, directionToPlaneCenter, finalPoint, lastCross, cross;
int[] triangles = bakedMesh.triangles;
Vector3[] vertices = bakedMesh.vertices;
Ray ray = new Ray(capsuleOrigin, capsuleNormal);
float distance;
Plane plane = new Plane();
//while(triangleId < triangles.Length - 3)
{
_verticesToDraw.Clear();
// Checking a single triangle.
for (int i = 0; i < triangles.Length - 3; i += 3)
{
/// Steps to check the collision between an length capsule (which is also a cylinder) and a triangle:
/// 1) calculate the projection of the point on the triangle plane.
/// 2) bring the point on the plane closer to the center of the triangle by the smallest value between the radius of the capsule and the distance between the projected point and the center of the triangle.
/// 3) use the final point to check the cross product between one edge of the triangle and the vector between the first point of the edge and the final point. If all the dot products between the 3 cross products are of the same sign, then the final point lies within the triangle.
/// 4) you now have confirmed the collision between the triangle and the infinite length capsule!
vertex[0] = vertices[triangles[i]];
vertex[1] = vertices[triangles[i + 1]];
vertex[2] = vertices[triangles[i + 2]];
// The coordinates of the vertices we find in the mesh are relative to the mesh pivot. So we make sure all coordinates are in the same referential which is world coordinates.
// Are the mesh relative coordinates affected by the scale of the Pokemon? Yes, they are. No need to convert them.
for (int x = 0; x < 3; x++)
{
vertexWorldPosition[x] = _pokeball._content.transform.position + _pokeball._content.transform.rotation * vertex[x];
}
plane.Set3Points(vertices[triangles[i]], vertices[triangles[i + 1]], vertices[triangles[i + 2]]);
plane.Raycast(ray, out distance);
/*planeCenter = (vertexWorldPosition[0] + vertexWorldPosition[1] + vertexWorldPosition[2]) / 3f;
planeNormal = Vector3.Cross((vertexWorldPosition[1] - vertexWorldPosition[0]), (vertexWorldPosition[2] - vertexWorldPosition[1])).normalized;
// Finding the orthogonal projection of the capsule onto the plane.
projection = Vector3.Project((planeCenter - capsuleOrigin), planeNormal);
*/
// If the projection and the capsule normal go the opposite way, that means the plane is behind the ray so we stop the calculations for this triangle.
//if (Vector3.Dot(projection, capsuleNormal) < 0)
if (distance < 0)
{
continue;
}
// We calculate the projection of the capsule onto the plane.
//projectionOnPlane = capsuleOrigin + projection;
projectionOnPlane = capsuleOrigin + capsuleNormal * distance;
_verticesToDraw.Add(projectionOnPlane);
// Actually when I said the capsule had an infinite length, I lied. We can give it a length thanks to the following condition:
//if ((projectionOnPlane - capsuleOrigin).magnitude > _length)
//{
// continue;
//}
// We now move the point towards the center of the triangle in order to take into account the radius of the capsule.
//directionToPlaneCenter = planeCenter - projectionOnPlane;
//finalPoint = projectionOnPlane + directionToPlaneCenter * Mathf.Min(capsuleRadius, directionToPlaneCenter.magnitude);
finalPoint = projectionOnPlane;
// Now we check if the final point is within the triangle by comparing some cross products.
lastCross = Vector3.zero;
bool finalPointIsInside = true;
for (int j = 0; j < 3; j++)
{
cross = Vector3.Cross((vertexWorldPosition[(j + 1) % 3] - vertexWorldPosition[j]), (vertexWorldPosition[(j + 2) % 3] - vertexWorldPosition[(j + 1) % 3]));
lastCross = Vector3.Cross((vertexWorldPosition[(j + 1) % 3] - vertexWorldPosition[j]), (finalPoint - vertexWorldPosition[j])); // A virer.
if (Vector3.Dot(lastCross, cross) <= 0)
{
finalPointIsInside = false;
break;
}
//if (j > 0 && Vector3.Dot(lastCross, cross) < 0)
//{
// finalPointIsInside = false;
// break;
//}
//lastCross = cross;
//.........这里部分代码省略.........