本文整理汇总了C#中UnityEngine.Plane.GetDistanceToPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Plane.GetDistanceToPoint方法的具体用法?C# Plane.GetDistanceToPoint怎么用?C# Plane.GetDistanceToPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Plane
的用法示例。
在下文中一共展示了Plane.GetDistanceToPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Side
// Check on which Side this Face lie (given the Input Plane)
public EPlaneSide Side( Plane inPlane )
{
//
int numBack = 0, numFront = 0, numPlanar = 0;
for( int i = 0; i < vertices.Length; ++i )
{
float dist = inPlane.GetDistanceToPoint( vertices[i] );
// FIXME: do this work right??
if( dist > GlobalSettings.Epsilonf )
numFront++;
else if( dist < -GlobalSettings.Epsilonf )
numBack++;
else
{
numPlanar++;
numFront++;
numBack++;
}
}
if( numPlanar == vertices.Length )
return EPlaneSide.Side_Planar;
if( numFront == vertices.Length )
return EPlaneSide.Side_Front;
if( numBack == vertices.Length )
return EPlaneSide.Side_Back;
return EPlaneSide.Side_Split;
}
示例2: CalculateDownEdge
void CalculateDownEdge()
{
RaycastHit hit;
//for(float i=-colliderHeight/2; i<=colliderHeight/2; i+=colliderHeight/raysNumber)
for(float i=-rayCastRangeX/2; i<=rayCastRangeX/2; i+=rayCastRangeX/raysNumber)
{
Ray down = new Ray(transform.position+Vector3.right*i, _traceDirectionDown);
if(Physics.Raycast(down, out hit) && hit.transform.name!="Rocket")
{
Plane newPlane = new Plane(-_traceDirectionDown, hit.point-_traceDirectionDown*_currentHeight);
if(newPlane.GetDistanceToPoint(transform.position+_traceDirectionDown*_currentHeight)<
edges.downPlane.GetDistanceToPoint(transform.position+_traceDirectionDown*_currentHeight))
//&& Vector3.Dot(hit.normal, _traceDirectionDown) < _edgeAngleFactor)
{
edges.downPlane = new Plane(hit.normal, hit.point+hit.normal*_currentHeight);
edges.downHit = hit;
}
if(Vector3.Distance(transform.position, hit.point)<_currentHeight+0.2f)
{
obstacleInfo.obstacleOnBottom = true;
}
if(drawGizmos) Debug.DrawLine(transform.position+Vector3.right*i,hit.point,_downDebugColor);
}
}
}
示例3: CameraToPlaneProjection
/// <summary>
/// Projects a screen point to a plane from a camera's point of view.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="camera">The camera.</param>
/// <param name="projectionPlane">Projection plane.</param>
/// <returns>Projected point on the plane in World coordinates.</returns>
public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
{
var distance = 0f;
var ray = camera.ScreenPointToRay(position);
var result = projectionPlane.Raycast(ray, out distance);
if (!result && Mathf.Approximately(distance, 0f)) return -projectionPlane.normal * projectionPlane.GetDistanceToPoint(Vector3.zero); // perpendicular to the screen
return ray.origin + ray.direction * distance;
}
示例4: ScreenToPlaneProjection
/// <summary>
/// Projects a screen point to a plane using parallel projection.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="projectionPlane">Projection plane.</param>
/// <returns>Projected point on the plane in World coordinates.</returns>
public static Vector3 ScreenToPlaneProjection(Vector2 position, Plane projectionPlane)
{
var distance = 0f;
var ray = new Ray(position, Vector3.forward);
var result = projectionPlane.Raycast(ray, out distance);
if (!result && Mathf.Approximately(distance, 0f)) return -projectionPlane.normal * projectionPlane.GetDistanceToPoint(Vector3.zero); // perpendicular to the screen
return ray.origin + new Vector3(0, 0, distance);
}
示例5: GetWorldPerScreenPixel
public float GetWorldPerScreenPixel(Vector3 worldPoint)
{
Camera cam = Camera.mainCamera;
if (cam == null)
return 0;
Plane nearPlane = new Plane(cam.transform.forward, cam.transform.position);
float dist = nearPlane.GetDistanceToPoint(worldPoint);
float sample = 100;
return Vector3.Distance(cam.ScreenToWorldPoint(new Vector3(Screen.width/2, Screen.height/2-sample/2, dist)), cam.ScreenToWorldPoint(new Vector3(Screen.width/2, Screen.height/2+sample/2, dist))) / sample;
}
示例6: LateUpdate
void LateUpdate()
{
float v = scale * Settings.marker_scale;
if (Settings.marker_autoscale) {
var cam = EditorCamera.Instance;
var plane = new Plane (cam.transform.forward, cam.transform.position);
float dist = plane.GetDistanceToPoint (transform.position);
v *= Mathf.Clamp (dist_c * dist, 0f, 1f);
}
transform.localScale = Vector3.one * v;
}
示例7: Update
void Update() {
Plane plane = new Plane(transform.up, transform.position);
for (int i = 0; i < LockedObjects.Length; i++) {
float currentDistance = plane.GetDistanceToPoint(LockedObjects[i].position);
Vector3 currentoffset = transform.up * currentDistance;
Vector3 offset = transform.up * MaxDistance;
Debug.DrawLine(LockedObjects[i].position, LockedObjects[i].position - offset);
LockedObjects[i].position = LockedObjects[i].position - currentoffset + offset;
Vector3 centerOffset = LockedObjects[i].position - transform.position;
centerOffset = Vector3.ClampMagnitude(centerOffset, MaxRadialDistance);
LockedObjects[i].position = transform.position + centerOffset;
}
}
示例8: ClassifyPoint
public static Classification ClassifyPoint(Vector3 point, Plane plane, float e)
{
float distance = plane.GetDistanceToPoint(point);
if (distance < -e)
{
return Classification.BACK;
}
else if (distance > e)
{
return Classification.FRONT;
}
else
{
return Classification.COINCIDING;
}
}
示例9: ClassifyPoints
public static Classification ClassifyPoints(Vector3[] points, Plane plane, out Classification[] classes, float e)
{
uint numpos = 0;
uint numneg = 0;
classes = new Classification[3];
for(int i = 0; i < points.Length; i++)
{
float distance = plane.GetDistanceToPoint(points[i]);
if (distance < -e)
{
classes[i] = Classification.BACK;
numneg++;
}
else if (distance > e)
{
classes[i] = Classification.FRONT;
numpos++;
}
else
{
classes[i] = Classification.COINCIDING;
}
}
if (numpos > 0 && numneg == 0)
{
return Classification.FRONT;
}
else if (numpos == 0 && numneg > 0)
{
return Classification.BACK;
}
else if (numpos > 0 && numneg > 0)
{
return Classification.STRADDLE;
}
else
{
return Classification.COINCIDING;
}
}
示例10: Update
void Update() {
Plane plane = new Plane(transform.up, transform.position);
for (int i = 0; i < LockedObjects.Count; i++) {
float currentDistance = plane.GetDistanceToPoint(LockedObjects[i].position);
if (currentDistance < 0) {
Vector3 planarOffset = Vector3.ProjectOnPlane(LockedObjects[i].position, transform.up) -
Vector3.ProjectOnPlane(transform.position, transform.up);
if (!RestrictWhileOutsideCircle && planarOffset.magnitude > MaxRadialDistance) {
Debug.DrawRay(transform.position, planarOffset);
continue;
}
Vector3 currentoffset = transform.up * currentDistance;
Vector3 offset = transform.up * MaxDistance;
Debug.DrawLine(LockedObjects[i].position, LockedObjects[i].position - offset);
LockedObjects[i].position = LockedObjects[i].position - currentoffset + offset;
Vector3 centerOffset = LockedObjects[i].position - transform.position;
centerOffset = Vector3.ClampMagnitude(centerOffset, MaxRadialDistance);
LockedObjects[i].position = transform.position + centerOffset;
}
}
}
示例11: OnBrushApply
public override void OnBrushApply(z_BrushTarget target, z_BrushSettings settings)
{
Vector3[] vertices = target.editableObject.vertices;
Vector3 v, t, avg, dirVec = direction.ToVector3();
Plane plane = new Plane(Vector3.up, Vector3.zero);
foreach(KeyValuePair<int, float> weight in target.weights)
{
if(weight.Value < .0001f || (ignoreNonManifoldIndices && nonManifoldIndices.Contains(weight.Key)))
continue;
v = vertices[weight.Key];
if(direction == z_Direction.Normal && relax)
avg = z_Math.Average(cached_vertices, neighborLookup[weight.Key]);
else
avg = z_Math.WeightedAverage(cached_vertices, neighborLookup[weight.Key], target.weights);
if(direction != z_Direction.Normal || !relax)
{
if(direction == z_Direction.Normal)
dirVec = z_Math.WeightedAverage(cached_normals, neighborLookup[weight.Key], target.weights).normalized;
plane.SetNormalAndPosition(dirVec, avg);
avg = v - dirVec * plane.GetDistanceToPoint(v);
}
t = Vector3.Lerp(v, avg, weight.Value);
vertices[weight.Key] = v + (t-v) * settings.strength * SMOOTH_STRENGTH_MODIFIER;
}
target.editableObject.mesh.vertices = vertices;
if(tempComponent != null)
tempComponent.OnVerticesMoved();
base.OnBrushApply(target, settings);
}
示例12: SetCamera
/// <summary>
/// Sets the camera to use when calculating
/// a pixel-perfect character size.
/// </summary>
/// <param name="c"></param>
public void SetCamera(Camera c)
{
if (c == null || !m_started)
return;
float dist;
Plane nearPlane = new Plane(c.transform.forward, c.transform.position);
if (!Application.isPlaying)
{
// If the screenSize has never been initialized,
// or if this is a different camera, get what
// values we can get, otherwise just keep the
// values we got during our last run:
#if !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9)
if ((screenSize.x == 0 || c != renderCamera) && c.pixelHeight > 100)
#endif
{
screenSize.x = c.pixelWidth;
screenSize.y = c.pixelHeight;
}
if (screenSize.x == 0)
return;
renderCamera = c;
if (screenPlacer != null)
screenPlacer.SetCamera(renderCamera);
// Determine the world distance between two vertical
// screen pixels for this camera:
dist = nearPlane.GetDistanceToPoint(transform.position);
worldUnitsPerScreenPixel = Vector3.Distance(c.ScreenToWorldPoint(new Vector3(0, 1, dist)), c.ScreenToWorldPoint(new Vector3(0, 0, dist)));
if(!hideAtStart)
CalcSize();
return;
}
screenSize.x = c.pixelWidth;
screenSize.y = c.pixelHeight;
renderCamera = c;
if (screenPlacer != null)
screenPlacer.SetCamera(renderCamera);
// Determine the world distance between two vertical
// screen pixels for this camera:
dist = nearPlane.GetDistanceToPoint(transform.position);
worldUnitsPerScreenPixel = Vector3.Distance(c.ScreenToWorldPoint(new Vector3(0, 1, dist)), c.ScreenToWorldPoint(new Vector3(0, 0, dist)));
CalcSize();
}
示例13: OnWizardCreate
// Let's do this thing!:
void OnWizardCreate()
{
float worldUnitsPerScreenPixel;
int skipped = 0; // How many sprites had to be skipped because they were prefabs?
if (disablePixelPerfect)
disablePixelPerfect = EditorUtility.DisplayDialog("Are you sure?", "Are you sure you wish to disable pixel-perfect on all selected sprites?", "Yes", "No");
// Get our desired sprites:
FindSprites();
if (renderCamera.isOrthoGraphic)
{
// Use orthographic logic:
worldUnitsPerScreenPixel = (renderCamera.orthographicSize * 2f) / targetScreenHeight;
// Now set their sizes:
for (int i = 0; i < sprites.Count; ++i)
{
SpriteRoot sprite = sprites[i];
Vector2 pxSize = sprite.GetDefaultPixelSize(AssetDatabase.GUIDToAssetPath, AssetDatabase.LoadAssetAtPath);
if (disablePixelPerfect)
sprite.pixelPerfect = false;
if (sprite.spriteMesh == null)
{
sprite.width = pxSize.x * worldUnitsPerScreenPixel;
sprite.height = pxSize.y * worldUnitsPerScreenPixel;
}
else
sprite.SetSize(pxSize.x * worldUnitsPerScreenPixel, pxSize.y * worldUnitsPerScreenPixel);
EditorUtility.SetDirty(sprites[i].gameObject);
}
}
else
{
// Use perspective logic:
float dist;
Plane nearPlane;
// Now set their sizes:
for (int i = 0; i < sprites.Count; ++i)
{
#if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
#if (UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
PrefabType ptype = PrefabUtility.GetPrefabType(sprites[i].gameObject);
#else
PrefabType ptype = EditorUtility.GetPrefabType(sprites[i].gameObject);
#endif
// We can't do prefabs with perspective cameras:
if (ptype == PrefabType.Prefab || ptype == PrefabType.ModelPrefab)
{
++skipped;
Debug.LogWarning("Sprite \"" + sprites[i].name + "\" skipped because it is a prefab and the selected camera is perspective. Size cannot be calculated for perspective cameras without the object actually being positioned in front of the camera.\n Either use an orthographic camera, or use an instance of the prefab in the scene instead.");
continue;
}
#endif
SpriteRoot sprite = sprites[i];
nearPlane = new Plane(renderCamera.transform.forward, renderCamera.transform.position);
Vector2 pxSize = sprite.GetDefaultPixelSize(AssetDatabase.GUIDToAssetPath, AssetDatabase.LoadAssetAtPath);
// Determine the world distance between two vertical
// screen pixels for this camera:
dist = nearPlane.GetDistanceToPoint(sprite.transform.position);
worldUnitsPerScreenPixel = Vector3.Distance(renderCamera.ScreenToWorldPoint(new Vector3(0, 1, dist)), renderCamera.ScreenToWorldPoint(new Vector3(0, 0, dist)));
if (disablePixelPerfect)
sprite.pixelPerfect = false;
if (sprite.spriteMesh == null)
{
sprite.width = pxSize.x * worldUnitsPerScreenPixel;
sprite.height = pxSize.y * worldUnitsPerScreenPixel;
}
else
sprite.SetSize(pxSize.x * worldUnitsPerScreenPixel, pxSize.y * worldUnitsPerScreenPixel);
EditorUtility.SetDirty(sprites[i].gameObject);
}
}
// See if we need to advise the user to reload the scene:
if (applyToAllPrefabs)
EditorUtility.DisplayDialog("NOTE", "You may need to reload the current scene for prefab instances to reflect your changes.", "OK");
Debug.Log( (sprites.Count - skipped) + " sprites sized.");
// Save our settings for next time:
SaveSettings();
}
示例14: GetJointPosColorOverlay
/// <summary>
/// Gets the 3d overlay position of the given joint over the color-image.
/// </summary>
/// <returns>The joint position for color overlay.</returns>
/// <param name="userId">User ID</param>
/// <param name="joint">Joint index</param>
/// <param name="camera">Camera used to visualize the 3d overlay position</param>
/// <param name="imageRect">Color image rectangle on the screen</param>
public Vector3 GetJointPosColorOverlay(Int64 userId, int joint, Camera camera, Rect imageRect)
{
if(dictUserIdToIndex.ContainsKey(userId) && camera != null)
{
int index = dictUserIdToIndex[userId];
if(index >= 0 && index < sensorData.bodyCount &&
bodyFrame.bodyData[index].bIsTracked != 0)
{
if(joint >= 0 && joint < sensorData.jointCount)
{
KinectInterop.JointData jointData = bodyFrame.bodyData[index].joint[joint];
Vector3 posJointRaw = jointData.kinectPos;
if(posJointRaw != Vector3.zero)
{
// 3d position to depth
Vector2 posDepth = MapSpacePointToDepthCoords(posJointRaw);
ushort depthValue = GetDepthForPixel((int)posDepth.x, (int)posDepth.y);
if(posDepth != Vector2.zero && depthValue > 0 && sensorData != null)
{
// depth pos to color pos
Vector2 posColor = MapDepthPointToColorCoords(posDepth, depthValue);
if(!float.IsInfinity(posColor.x) && !float.IsInfinity(posColor.y))
{
float xScaled = (float)posColor.x * imageRect.width / sensorData.colorImageWidth;
float yScaled = (float)posColor.y * imageRect.height / sensorData.colorImageHeight;
float xScreen = imageRect.x + xScaled;
//float yScreen = camera.pixelHeight - (imageRect.y + yScaled);
float yScreen = imageRect.y + imageRect.height - yScaled;
Plane cameraPlane = new Plane(camera.transform.forward, camera.transform.position);
float zDistance = cameraPlane.GetDistanceToPoint(posJointRaw);
//float zDistance = (jointData.kinectPos - camera.transform.position).magnitude;
//Vector3 vPosJoint = camera.ViewportToWorldPoint(new Vector3(xNorm, yNorm, zDistance));
Vector3 vPosJoint = camera.ScreenToWorldPoint(new Vector3(xScreen, yScreen, zDistance));
return vPosJoint;
}
}
}
}
}
}
return Vector3.zero;
}
示例15: ComputeIslandsMeshDataConnectivity
private static bool ComputeIslandsMeshDataConnectivity(FracturedObject fracturedComponent, bool bVerticesAreLocal, MeshData meshData1, MeshData meshData2)
{
float fMargin = fracturedComponent.ChunkIslandConnectionMaxDistance;
// Vertices and min/max may be in local space. We want distance checks to be in world space
Vector3 v3Min1 = meshData1.v3Min; if(bVerticesAreLocal) v3Min1 = Vector3.Scale(v3Min1, meshData1.v3Scale);
Vector3 v3Max1 = meshData1.v3Max; if(bVerticesAreLocal) v3Max1 = Vector3.Scale(v3Max1, meshData1.v3Scale);
Vector3 v3Min2 = meshData2.v3Min; if(bVerticesAreLocal) v3Min2 = Vector3.Scale(v3Min2, meshData2.v3Scale);
Vector3 v3Max2 = meshData2.v3Max; if(bVerticesAreLocal) v3Max2 = Vector3.Scale(v3Max2, meshData2.v3Scale);
if((v3Min1.x > (v3Max2.x + fMargin)) || (v3Min1.y > (v3Max2.y + fMargin)) || (v3Min1.z > (v3Max2.z + fMargin)))
{
return false;
}
if((v3Min2.x > (v3Max1.x + fMargin)) || (v3Min2.y > (v3Max1.y + fMargin)) || (v3Min2.z > (v3Max1.z + fMargin)))
{
return false;
}
bool bConnected = false;
float fDistPlaneMax = fracturedComponent.ChunkIslandConnectionMaxDistance;
for(int nSubMesh1 = 0; nSubMesh1 < meshData1.aaIndices.Length; nSubMesh1++)
{
for(int nFace1 = 0; nFace1 < meshData1.aaIndices[nSubMesh1].Length / 3; nFace1++)
{
Vector3 v1 = meshData1.aVertexData[meshData1.aaIndices[nSubMesh1][nFace1 * 3 + 0]].v3Vertex;
Vector3 v2 = meshData1.aVertexData[meshData1.aaIndices[nSubMesh1][nFace1 * 3 + 1]].v3Vertex;
Vector3 v3 = meshData1.aVertexData[meshData1.aaIndices[nSubMesh1][nFace1 * 3 + 2]].v3Vertex;
if(bVerticesAreLocal)
{
v1 = Vector3.Scale(v1, meshData1.v3Scale);
v2 = Vector3.Scale(v2, meshData1.v3Scale);
v3 = Vector3.Scale(v3, meshData1.v3Scale);
}
Vector3 v3Forward = -Vector3.Cross(v2 - v1, v3 - v1);
float fArea1 = v3Forward.magnitude;
if(fArea1 < Parameters.EPSILONCROSSPRODUCT)
{
continue;
}
Quaternion qFace = Quaternion.LookRotation(v3Forward.normalized, (v2 - v1).normalized);
Matrix4x4 mtxToFace = Matrix4x4.TRS(v1, qFace, Vector3.one).inverse;
Plane planeFace1 = new Plane(v1, v2, v3);
for(int nSubMesh2 = 0; nSubMesh2 < meshData2.aaIndices.Length; nSubMesh2++)
{
for(int nFace2 = 0; nFace2 < meshData2.aaIndices[nSubMesh2].Length / 3; nFace2++)
{
Vector3 v3Other1 = meshData2.aVertexData[meshData2.aaIndices[nSubMesh2][nFace2 * 3 + 0]].v3Vertex;
Vector3 v3Other2 = meshData2.aVertexData[meshData2.aaIndices[nSubMesh2][nFace2 * 3 + 1]].v3Vertex;
Vector3 v3Other3 = meshData2.aVertexData[meshData2.aaIndices[nSubMesh2][nFace2 * 3 + 2]].v3Vertex;
if(bVerticesAreLocal)
{
v3Other1 = Vector3.Scale(v3Other1, meshData2.v3Scale);
v3Other2 = Vector3.Scale(v3Other2, meshData2.v3Scale);
v3Other3 = Vector3.Scale(v3Other3, meshData2.v3Scale);
}
// Compute distance from face1 to face2
float fDist1 = Mathf.Abs(planeFace1.GetDistanceToPoint(v3Other1)); if(fDist1 > fDistPlaneMax) continue;
float fDist2 = Mathf.Abs(planeFace1.GetDistanceToPoint(v3Other2)); if(fDist2 > fDistPlaneMax) continue;
float fDist3 = Mathf.Abs(planeFace1.GetDistanceToPoint(v3Other3)); if(fDist3 > fDistPlaneMax) continue;
// See if they intersect in 2D (face 1 local coordinates)
Vector3 v3OtherCenterLocal = (v3Other1 + v3Other2 + v3Other3) / 3.0f;
v3OtherCenterLocal = mtxToFace.MultiplyPoint3x4(v3OtherCenterLocal);
Vector3 v3Local1 = mtxToFace.MultiplyPoint3x4(v1);
Vector3 v3Local2 = mtxToFace.MultiplyPoint3x4(v2);
Vector3 v3Local3 = mtxToFace.MultiplyPoint3x4(v3);
Vector3 v3Edge2 = v3Local3 - v3Local2;
Vector3 v3Edge3 = v3Local1 - v3Local3;
bool bFaceConnected = false;
// Test the center
if(v3OtherCenterLocal.x >= 0.0f)
{
if(Vector3.Cross(v3Edge2, v3OtherCenterLocal - v3Local2).z <= 0.0f)
{
if(Vector3.Cross(v3Edge3, v3OtherCenterLocal - v3Local3).z <= 0.0f)
{
bFaceConnected = true;
}
}
}
if(bFaceConnected == false)
//.........这里部分代码省略.........