本文整理汇总了C#中Plane.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Plane.Normalize方法的具体用法?C# Plane.Normalize怎么用?C# Plane.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane
的用法示例。
在下文中一共展示了Plane.Normalize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NormalizeTest
public void NormalizeTest()
{
Plane p1 = Plane.Normalize(new Plane(2.2f, 3.3f, -1.1f, -2.2f));
Plane r1 = new Plane(0.5345225f, 0.8017837f, -0.2672612f, -0.5345225f);
Plane plane = new Plane(-1.33f, 0f, 2.25f, 1.77f);
Plane p2 = new Plane();
Plane.Normalize(ref plane, out p2);
Plane r2 = new Plane(-0.5088582f, 0f, 0.8608503f, 0.6772023f);
Plane p3 = new Plane(0.5f, 1f, 2.25f, 3.3334f);
Plane r3 = new Plane(0.1990075f, 0.3980149f, 0.8955336f, 1.326743f);
p3.Normalize();
Assert.AreEqual(TestHelper.Approximate(r1), TestHelper.Approximate(p1), "#1");
Assert.AreEqual(TestHelper.Approximate(r2), TestHelper.Approximate(p2), "#2");
Assert.AreEqual(TestHelper.Approximate(r3), TestHelper.Approximate(p3), "#3");
}
示例2: SetBoundingCorners
/// <summary>
/// Update the bounding corners of the surface corners of this 3D cuboid with specific corners.
/// </summary>
/// <param name="vBottomLeft">What the space understands as the bottom left corner of the surface.</param>
/// <param name="vBottomRight">What the space understands as the bottom right corner of the surface.</param>
/// <param name="vTopLeft">What the space understands as the top left corner of the surface.</param>
/// <param name="vTopRight">What the space understands as the top right corner of the surface.</param>
public void SetBoundingCorners(Vector3 vBottomLeft, Vector3 vBottomRight, Vector3 vTopLeft, Vector3 vTopRight)
{
// Extrapolation distance.
float fDistance = -(fSurfaceZOffset + fHeight);
// Set the corners.
Vector3 BL = vBottomLeft;
Vector3 BR = vBottomRight;
Vector3 TL = vTopLeft;
Vector3 TR = vTopRight;
// Query all the points in a given region.
if (this.RelativeSurface == null)
throw new Exception("Setting the bounding corners requires a surface.");
// Slow (use all data within the surface region to compute the plane).
// SurfacePlane = Surface.KinectProcessor.ImageCoordinatesToBestFitPlane(this.RelativeSurface.KinectSpace);
// Fast (just use corners to compute the plane.
SurfacePlane = Utilities.RatcliffPlane.ComputeBestFit(new Vector3[] { vBottomLeft, vBottomRight, vTopLeft, vTopRight });
SurfacePlane.Normalize();
// Check the plane is facing upwards.
if (SurfacePlane.Normal.Z < 0)
{
SurfacePlane *= -1;
//SurfacePlane = new Plane(SurfacePlane.Normal, SurfacePlane.D * -1);
}
// Extrapolate the cube based on the normal of the plane.
Vector3 BLZ = BL + (SurfacePlane.Normal * fDistance);
Vector3 BRZ = BR + (SurfacePlane.Normal * fDistance);
Vector3 TLZ = TL + (SurfacePlane.Normal * fDistance);
Vector3 TRZ = TR + (SurfacePlane.Normal * fDistance);
// Create a scaling matrix to transform values between 0 and 1 reative to the display.
var mScale = Matrix.Scaling(
1f / Vector3.Distance(BL, BR),
1f / Vector3.Distance(BL, TL),
1f / Vector3.Distance(BL, BLZ));
// Create a transformation matrix (and inverse) which allows going to and from surface space.
Transform = Matrix.LookAtRH(BL, BL + (SurfacePlane.Normal * 100f), Vector3.Normalize(TL - BL)) * mScale;
Inverse = Matrix.Invert(Transform);
// top back .. clockwise windings ..
// TR------TRz
// /| /| - Back Plane <= (BL, TL, TLz, BLz)
// TL-+----TLz| - Front Plane <= (BR, TR, TRz, BRz)
// close | BR----|-BRz far
// |/ |/ - Top Plane <= (TL, TR, TRz, TLz)
// BL------BLz - Bottom Plane <= (BL, BR, BRz, BLz)
// bottom
// - Close Plane <= (BL, TL, TR, BR)
// font - Far Plane <= (BLz, TLz, TRz, BRz)
//
Back = new Plane(BL, TL, TLZ);
Front = new Plane(BR, TR, TRZ);
Top = new Plane(TL, TR, TRZ);
Bottom = new Plane(BL, BR, BRZ);
Close = new Plane(BL, TL, TR);
Far = new Plane(BLZ, TLZ, TRZ);
}
示例3: ComputePickingDelta
private Vector3 ComputePickingDelta(EngineContext engineContext, Vector3 axis1, Vector3 axis2, ref Matrix viewProj, Vector3 pickingGizmoOrigin, Vector3 pickingObjectOrigin, Vector2 delta)
{
// Build plane along which object will move
var plane = new Plane(pickingGizmoOrigin, pickingGizmoOrigin + axis1, pickingGizmoOrigin + axis2);
plane.Normalize();
// Position difference in screen space to move one unit
var pickingStartTranslationScreenSpace = Vector3.TransformCoordinate(pickingGizmoOrigin, viewProj);
// Build mouse picking ray
var mouseDelta = new Vector3(delta.X / engineContext.RenderContext.Width * 2.0f,
-delta.Y / engineContext.RenderContext.Height * 2.0f,
0.0f);
var mousePickingPosition = pickingStartTranslationScreenSpace + mouseDelta;
var invViewProj = Matrix.Invert(viewProj);
mousePickingPosition.Z = 0.0f;
var picking1 = Vector3.TransformCoordinate(mousePickingPosition, invViewProj);
mousePickingPosition.Z = 0.1f;
var picking2 = Vector3.TransformCoordinate(mousePickingPosition, invViewProj);
// Intersect moving plane with mouse picking ray
var ray = new Ray(picking1, Vector3.Normalize(picking2 - picking1));
Vector3 pickingDelta;
plane.Intersects(ref ray, out pickingDelta);
// Project result along movement axis
pickingDelta = Vector3.Dot(axis1, pickingDelta - pickingGizmoOrigin) * axis1;
return pickingDelta;
}
示例4: Initialize
public void Initialize()
{
float size = GetNodeSize();
float x = this.Location.X;
float z = this.Location.Y;
float xWhole = x + size;
float zWhole = z + size;
float zHalf = z + size / 2;
float xHalf = x + size / 2;
float heightXZWhole = this.ParentTree.GetHeight(x, zWhole);
float heightXWholeZWhole = this.ParentTree.GetHeight(xWhole, zWhole);
float heightXWholeZ = this.ParentTree.GetHeight(xWhole, z); ;
float heightXZ = this.ParentTree.GetHeight(x, z);
//normal of the current quad
Vector3 normal = //Vector3.Multiply(
new Plane(
new Vector3(x, heightXZWhole, zWhole),
new Vector3(xWhole, heightXWholeZ, z),
new Vector3(x, heightXZ, z)).Normal
*
new Plane(
new Vector3(x, heightXZWhole, zWhole),
new Vector3(xWhole, heightXWholeZWhole, zWhole),
new Vector3(xWhole, heightXWholeZ, z)).Normal
;
normal.Normalize();
//tangent of the current quad
Vector3 tangent = new Vector3(x, heightXZWhole, zWhole) - new Vector3(xWhole, heightXWholeZWhole, zWhole);
tangent.Normalize();
//binormal of the current quad
Vector3 binormal = Vector3.Cross(tangent, normal);
//first compute the 4 egdes of the current square
//here we know all : position and height.
{
if (this.Parent != null)
{
//if we have a parent maybe we can use its vertices
switch (this.Position)
{
case NodeChild.NorthWest:
this.NorthWestVertex = this.Parent.NorthWestVertex;
this.NorthEastVertex = this.Parent.NorthVertex;
this.SouthEastVertex = this.Parent.CenterVertex;
this.SouthWestVertex = this.Parent.WestVertex;
break;
case NodeChild.NorthEast:
this.NorthWestVertex = this.Parent.NorthVertex;
this.NorthEastVertex = this.Parent.NorthEastVertex;
this.SouthWestVertex = this.Parent.CenterVertex;
this.SouthEastVertex = this.Parent.EastVertex;
break;
case NodeChild.SouthWest:
this.NorthWestVertex = this.Parent.WestVertex;
this.NorthEastVertex = this.Parent.CenterVertex;
this.SouthWestVertex = this.Parent.SouthWestVertex;
this.SouthEastVertex = this.Parent.SouthVertex;
break;
case NodeChild.SouthEast:
this.NorthWestVertex = this.Parent.CenterVertex;
this.NorthEastVertex = this.Parent.EastVertex;
this.SouthWestVertex = this.Parent.SouthVertex;
this.SouthEastVertex = this.Parent.SouthEastVertex;
break;
default:
break;
}
//only the sides can be new
this.CenterVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, zHalf), zHalf), normal, GetTextureCoordinates(xHalf, zHalf), tangent, binormal));
this.WestVertex = (this.WestNeighbor != null ? this.WestNeighbor.EastVertex : new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(x, this.ParentTree.GetHeight(x, zHalf), zHalf), normal, GetTextureCoordinates(x, zHalf), tangent, binormal)));
this.NorthVertex = (this.NorthNeighbor != null ? this.NorthNeighbor.SouthVertex : new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, zWhole), zWhole), normal, GetTextureCoordinates(xHalf, zWhole), tangent, binormal)));
this.EastVertex = (this.EastNeighbor != null ? this.EastNeighbor.WestVertex : new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(xWhole, this.ParentTree.GetHeight(xWhole, zHalf), zHalf), normal, GetTextureCoordinates(xWhole, zHalf), tangent, binormal)));
this.SouthVertex = (this.SouthNeighbor != null ? this.SouthNeighbor.NorthVertex : new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, z), z), normal, GetTextureCoordinates(xHalf, z), tangent, binormal)));
}
else //this occurs only on depth = 0
{
Vector3 northWest = new Vector3(x, heightXZWhole, zWhole);
Vector3 northEast = new Vector3(xWhole, heightXWholeZWhole, zWhole);
Vector3 southEast = new Vector3(xWhole, heightXWholeZ, z);
Vector3 southWest = new Vector3(x, heightXZ, z);
Vector3 west = new Vector3(x, this.ParentTree.GetHeight(x, zHalf), zHalf);
Vector3 north = new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, zWhole), zWhole);
Vector3 east = new Vector3(xWhole, this.ParentTree.GetHeight(xWhole, zHalf), zHalf);
Vector3 south = new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, z), z);
this.NorthWestVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(northWest, normal, GetTextureCoordinates(x, zWhole), tangent, binormal));
this.NorthEastVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(northEast, normal, GetTextureCoordinates(xWhole, zWhole), tangent, binormal));
this.SouthEastVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(southEast, normal, GetTextureCoordinates(xWhole, z), tangent, binormal));
this.SouthWestVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(southWest, normal, GetTextureCoordinates(x, z), tangent, binormal));
this.CenterVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(new Vector3(xHalf, this.ParentTree.GetHeight(xHalf, zHalf), zHalf), normal, GetTextureCoordinates(xHalf, zHalf), tangent, binormal));
this.WestVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(west, normal, GetTextureCoordinates(x, zHalf), tangent, binormal));
this.NorthVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(north, normal, GetTextureCoordinates(xHalf, zWhole), tangent, binormal));
this.EastVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(east, normal, GetTextureCoordinates(xWhole, zHalf), tangent, binormal));
this.SouthVertex = new TerrainVertex(new VertexPositionNormalTextureTangentBinormal(south, normal, GetTextureCoordinates(xHalf, z), tangent, binormal));
}
//.........这里部分代码省略.........
示例5: DrawReflection
private void DrawReflection(float aspectRatio, out Matrix reflectionViewProjection)
{
// Set target to reflection and clear it
GraphicsDevice.SetRenderTarget(0, this.waterReflection);
GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.CornflowerBlue, 1f, 0);
const float waterHeight = 24f;
// Get a virtual camera position
Vector3 reflectionCamPosition = new Vector3
{
X = cameraPosition.X,
Y = waterHeight - (cameraPosition.Y - waterHeight),
Z = cameraPosition.Z
};
// Reflect the current cameraDirection around the water plane
Vector3 reflectedDir = Vector3.Reflect(Vector3.Normalize(cameraFront), Vector3.Up);
Vector3 reflectionCamTarget = default(Vector3);
reflectionCamTarget.X = reflectionCamPosition.X + reflectedDir.X;
reflectionCamTarget.Y = reflectionCamPosition.Y + reflectedDir.Y;
reflectionCamTarget.Z = reflectionCamPosition.Z + reflectedDir.Z;
// Generate view and projection matrices using virtual position, target and a field of view of 90 degrees
Matrix reflectionView = Matrix.CreateLookAt(reflectionCamPosition, reflectionCamTarget, Vector3.Up);
Matrix reflectionProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, aspectRatio, 0.1f, 10000f);
// Output combioned reflection view and projection matrices
reflectionViewProjection = reflectionView * reflectionProjection;
// Create a normalized world space clip plane representing the water
Plane reflectionClipPlane = new Plane(Vector3.Up, -waterHeight);
reflectionClipPlane.Normalize();
// Transform the world space clip plane into clip space
Plane reflectionClipPlaneWaterSpace;
Plane.Transform(ref reflectionClipPlane, ref reflectionViewProjection, out reflectionClipPlaneWaterSpace);
// Set the clip plane on the hardware device
GraphicsDevice.ClipPlanes[0].Plane = reflectionClipPlaneWaterSpace;
GraphicsDevice.ClipPlanes[0].IsEnabled = true;
this.Sky.Draw(reflectionView, reflectionProjection);
// Draw the terrain with our reflection view and projection
this.DrawTerrain(null, ref reflectionView, ref reflectionProjection);
// Make sure to unset to the clip plane, else further drawing will be spoilt
GraphicsDevice.ClipPlanes[0].IsEnabled = false;
}
示例6: GetPlane
public Plane GetPlane()
{
if(_pointCount < 3)
{
return new Plane();
}
Vector3 center = this.Center;
Vector3 v = new Vector3(_points[0, 0], _points[0, 1], _points[0, 2]);
Vector3 v1 = v - center;
Vector3 v2 = new Vector3(_points[1, 0], _points[1, 1], _points[1, 2]) - center;
Plane plane = new Plane();
plane.Normal = Vector3.Cross(v2, v1);
plane.Normalize();
Vector3 tmp = plane.Normal * v;
plane.D = tmp.X + tmp.Y + tmp.Z;
return plane;
}