本文整理汇总了C#中Plane类的典型用法代码示例。如果您正苦于以下问题:C# Plane类的具体用法?C# Plane怎么用?C# Plane使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Plane类属于命名空间,在下文中一共展示了Plane类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetVanishingPoint
// =============================================================================
// METHODS STATIC --------------------------------------------------------------
public static void SetVanishingPoint( Camera cam, float offset, ClientCameraScreen screen )
{
Transform t = cam.transform;
NearPlane plane = new NearPlane();
Vector3 nearCenter = t.position + t.forward*cam.nearClipPlane;
Plane nearPlane = new Plane ( -t.forward, nearCenter );
float distance = 0f;
Vector3 direction;
Ray ray;
Vector3 screenTL = t.TransformPoint ( new Vector3 ( ( -screen.Width/2.0f ) + offset, screen.Height/2.0f, screen.Distance ) );
direction = ( screenTL - t.position ).normalized;
ray = new Ray ( t.position, direction );
nearPlane.Raycast ( ray, out distance );
Vector3 nearTL = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );
Vector3 screenBR = t.TransformPoint ( new Vector3 ( ( screen.Width/2.0f ) + offset, -screen.Height/2.0f, screen.Distance ) );
direction = ( screenBR - t.position ).normalized;
ray = new Ray ( t.position, direction );
nearPlane.Raycast ( ray, out distance );
Vector3 nearBR = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );
plane.left = nearTL.x;
plane.top = nearTL.y;
plane.right = nearBR.x;
plane.bottom = nearBR.y;
plane.near = cam.nearClipPlane;
plane.far = cam.farClipPlane;
cam.projectionMatrix = PerspectiveOffCenter ( plane );
}
示例2: DoClick
private void DoClick(object sender, ClickedEventArgs e)
{
if (this.teleportOnClick)
{
float y = this.reference.position.y;
Plane plane = new Plane(Vector3.up, -y);
Ray ray = new Ray(base.transform.position, base.transform.forward);
bool flag = false;
float d = 0f;
if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
{
TerrainCollider component = Terrain.activeTerrain.GetComponent<TerrainCollider>();
RaycastHit raycastHit;
flag = component.Raycast(ray, out raycastHit, 1000f);
d = raycastHit.distance;
}
else if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
{
RaycastHit raycastHit2;
Physics.Raycast(ray, out raycastHit2);
d = raycastHit2.distance;
}
else
{
flag = plane.Raycast(ray, out d);
}
if (flag)
{
Vector3 position = ray.origin + ray.direction * d - new Vector3(this.reference.GetChild(0).localPosition.x, 0f, this.reference.GetChild(0).localPosition.z);
this.reference.position = position;
}
}
}
示例3: CreateThroughBox
/// <summary>
/// Extends a plane into a plane surface so that the latter goes through a bounding box.
/// </summary>
/// <param name="plane">An original plane value.</param>
/// <param name="box">A box to use for extension boundary.</param>
/// <returns>A new plane surface on success, or null on error.</returns>
/// <example>
/// <code source='examples\vbnet\ex_splitbrepwithplane.vb' lang='vbnet'/>
/// <code source='examples\cs\ex_splitbrepwithplane.cs' lang='cs'/>
/// <code source='examples\py\ex_splitbrepwithplane.py' lang='py'/>
/// </example>
public static PlaneSurface CreateThroughBox(Plane plane, BoundingBox box)
{
IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox2(ref plane, ref box);
if (IntPtr.Zero == ptr)
return null;
return new PlaneSurface(ptr, null);
}
示例4: Update
void Update () {
// Movement input
Vector3 moveInput = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
Vector3 moveVelocity = moveInput.normalized * moveSpeed;
controller.Move (moveVelocity);
// Look input
Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
Plane groundPlane = new Plane (Vector3.up, Vector3.up * gunController.GunHeight);
float rayDistance;
if (groundPlane.Raycast(ray,out rayDistance)) {
Vector3 point = ray.GetPoint(rayDistance);
//Debug.DrawLine(ray.origin,point,Color.red);
controller.LookAt(point);
crosshairs.transform.position = point;
crosshairs.DetectTargets(ray);
if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1) {
gunController.Aim(point);
}
}
// Weapon input
if (Input.GetMouseButton(0)) {
gunController.OnTriggerHold();
}
if (Input.GetMouseButtonUp(0)) {
gunController.OnTriggerRelease();
}
if (Input.GetKeyDown (KeyCode.R)) {
gunController.Reload();
}
}
示例5: Update
void Update()
{
var plane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hit;
if (plane.Raycast(ray, out hit))
{
var aimDirection = Vector3.Normalize(ray.GetPoint(hit) - transform.position);
var targetRotation = Quaternion.LookRotation(aimDirection);
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 360 * Time.deltaTime);
if (Input.GetMouseButtonDown(0))
bulletPrefab.Spawn(gun.position, gun.rotation);
}
if (Input.GetKeyDown(KeyCode.Space))
{
bulletPrefab.DestroyPooled();
}
if (Input.GetKeyDown(KeyCode.Z))
{
bulletPrefab.DestroyAll();
}
}
示例6: BuildDecalForObject
public static void BuildDecalForObject(DecalGenerator generator, Transform decal, Transform affectedObject)
{
Mesh affectedMesh = affectedObject.GetComponent<MeshFilter>().sharedMesh;
if (affectedMesh == null) return;
float maxAngle = generator.maxAngle;
Plane right = new Plane(Vector3.right, Vector3.right / 2f);
Plane left = new Plane(-Vector3.right, -Vector3.right / 2f);
Plane top = new Plane(Vector3.up, Vector3.up / 2f);
Plane bottom = new Plane(-Vector3.up, -Vector3.up / 2f);
Plane front = new Plane(Vector3.forward, Vector3.forward / 2f);
Plane back = new Plane(-Vector3.forward, -Vector3.forward / 2f);
Vector3[] vertices = affectedMesh.vertices;
int[] triangles = affectedMesh.triangles;
int startVertexCount = bufVertices.Count;
Matrix4x4 matrix = decal.worldToLocalMatrix * affectedObject.transform.localToWorldMatrix;
for (int i = 0; i < triangles.Length; i += 3)
{
int i1 = triangles[i];
int i2 = triangles[i + 1];
int i3 = triangles[i + 2];
Vector3 v1 = matrix.MultiplyPoint(vertices[i1]);
Vector3 v2 = matrix.MultiplyPoint(vertices[i2]);
Vector3 v3 = matrix.MultiplyPoint(vertices[i3]);
Vector3 side1 = v2 - v1;
Vector3 side2 = v3 - v1;
Vector3 normal = Vector3.Cross(side1, side2).normalized;
if (Vector3.Angle(-Vector3.forward, normal) >= maxAngle) continue;
DecalPolygon poly = new DecalPolygon(v1, v2, v3);
poly = DecalPolygon.ClipPolygon(poly, right);
if (poly == null) continue;
poly = DecalPolygon.ClipPolygon(poly, left);
if (poly == null) continue;
poly = DecalPolygon.ClipPolygon(poly, top);
if (poly == null) continue;
poly = DecalPolygon.ClipPolygon(poly, bottom);
if (poly == null) continue;
poly = DecalPolygon.ClipPolygon(poly, front);
if (poly == null) continue;
poly = DecalPolygon.ClipPolygon(poly, back);
if (poly == null) continue;
AddPolygon(poly, normal);
}
GenerateTexCoords(startVertexCount, generator.sprite);
}
示例7: ProjectScreenPointOnDragPlane
// converts a screen-space position to a world-space position constrained to the current drag plane type
// returns false if it was unable to get a valid world-space position
public bool ProjectScreenPointOnDragPlane( Vector3 refPos, Vector2 screenPos, out Vector3 worldPos )
{
worldPos = refPos;
if( DragPlaneCollider )
{
Ray ray = RaycastCamera.ScreenPointToRay( screenPos );
RaycastHit hit;
if( !DragPlaneCollider.Raycast( ray, out hit, float.MaxValue ) )
return false;
worldPos = hit.point + DragPlaneOffset * hit.normal;
}
else // DragPlaneType.Camera
{
Transform camTransform = RaycastCamera.transform;
// create a plane passing through refPos and facing toward the camera
Plane plane = new Plane( -camTransform.forward, refPos );
Ray ray = RaycastCamera.ScreenPointToRay( screenPos );
float t = 0;
if( !plane.Raycast( ray, out t ) )
return false;
worldPos = ray.GetPoint( t );
}
return true;
}
示例8: TestPlaneConstructor
public static void TestPlaneConstructor()
{
PlaneAttributes atts = new PlaneAttributes("badger50", 1, 5, 3, 7, 2000);
Plane p = new Plane("acas-1200-badger50", atts);
//A plane should have anything assigned to it in the constructor reflected in it immediately.
p.attributes.maxHeight.ShouldBe(2000);
p.attributes.planeModelGUID.ShouldBe("badger50");
p.attributes.planeHeight.ShouldBe(3);
p.attributes.planeWidth.ShouldBe(5);
p.attributes.planeLength.ShouldBe(7);
p.attributes.planeClass.ShouldBe(1);
//A new plane should have no position data within it.
p.GetPositionCount().ShouldBe(0);
//A new plane with no position data should have a 'zero' velocity
p.IsClass(p.attributes.planeClass).ShouldBe(true);
Vector3d vel = p.GetVelocity();
vel.x.ShouldBe(0, .01);
vel.y.ShouldBe(0, .01);
vel.z.ShouldBe(0, .01);
//Getting position from a newly constructed plane (with no position data)
//should cause a NotSupportedException
Exception ex = null;
try {
Vector3d pos = p.GetPosition();
} catch (Exception e) {
ex = e;
}
ex.ShouldNotBeNull();
ex.GetType().ShouldBe(typeof(NotSupportedException));
}
示例9: Caminar
void Caminar()
{
// Da seguimiento a la distancia entre este gameObject y posicionDestino.
distanciaDestino = Vector3.Distance(posicionDestino, esteTransform.position);
// Mueve al jugador si el click izquierdo del mouse fue clickeado.
if (Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0) {
Plane planoJugador = new Plane(Vector3.up, esteTransform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
float longitudRayo = 0.0f;
// Obtenemos la longitud del rayo.
if (planoJugador.Raycast(ray, out longitudRayo)) {
posicionDestino = ray.GetPoint(longitudRayo); // Coordenada destino
Quaternion rotacionDestino = Quaternion.LookRotation(posicionDestino - transform.position);
esteTransform.rotation = rotacionDestino;
}
}
// Evita que el codigo se ejecute si no es necesario.
if(distanciaDestino > .5f){
esteTransform.position = Vector3.MoveTowards(esteTransform.position, posicionDestino, velocidad * Time.deltaTime);
}
}
示例10: AttachMirrorPlane
void AttachMirrorPlane(BabylonTexture babylonTexture, NovaObject novaObject)
{
// Mirror plane
int f1, f2, f3;
if (novaObject.Is32bits)
{
f1 = novaObject.Indices32[2];
f2 = novaObject.Indices32[1];
f3 = novaObject.Indices32[0];
}
else
{
f1 = novaObject.Indices[2];
f2 = novaObject.Indices[1];
f3 = novaObject.Indices[0];
}
Vector3 a = novaObject.PositionOnlyVertices[f1];
Vector3 b = novaObject.PositionOnlyVertices[f2];
Vector3 c = novaObject.PositionOnlyVertices[f3];
var mainPlane = new Plane(a, b, c);
Matrix matrix = Matrix.Invert(novaObject.WorldMatrix);
matrix = Matrix.Transpose(matrix);
Plane plane = Plane.Transform(mainPlane, matrix);
babylonTexture.mirrorPlane = new[] { plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D };
}
示例11: MustFlipCurve
/// <summary>
/// Checks if curve is flipped to a plane.
/// </summary>
/// <param name="plane">
/// The plane.
/// </param>
/// <param name="curve">
/// The curve.
/// </param>
/// <returns>
/// True if the curve is flipped to the plane, false otherwise.
/// </returns>
public static bool MustFlipCurve(Plane plane, Curve curve)
{
XYZ xVector = null;
XYZ yVector = null;
if (curve is Arc)
{
Arc arc = curve as Arc;
xVector = arc.XDirection;
yVector = arc.YDirection;
}
else if (curve is Ellipse)
{
Ellipse ellipse = curve as Ellipse;
xVector = ellipse.XDirection;
yVector = ellipse.YDirection;
}
else
return false;
List<double> realListX = ConvertVectorToLocalCoordinates(plane, xVector);
List<double> realListY = ConvertVectorToLocalCoordinates(plane, yVector);
double dot = realListY[0] * (-realListX[1]) + realListY[1] * (realListX[0]);
if (dot < -MathUtil.Eps())
return true;
return false;
}
示例12: Update
void Update()
{
// Movement Input
Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
Vector3 moveVelocity = moveInput.normalized * moveSpeed;
pc.Move(moveVelocity);
// Look/Aim Input
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayDist;
if(groundPlane.Raycast(ray, out rayDist))
{
Vector3 point = ray.GetPoint(rayDist);
Debug.DrawLine(ray.origin, point, Color.red);
pc.LookAt(point);
}
// Shooting Input
if(Input.GetMouseButton(0))
{
gc.Shoot();
}
}
示例13: Frustum
public Frustum()
{
for (var planeIndex = 0; planeIndex < _planes.Length; planeIndex++)
{
_planes[planeIndex] = new Plane();
}
}
示例14: OnMouseMove
public void OnMouseMove( dfControl control, dfMouseEventArgs args )
{
if( animating || !dragging )
return;
this.momentum = ( momentum + args.MoveDelta.Scale( 1, -1 ) ) * 0.5f;
args.Use();
if( args.Buttons.IsSet( dfMouseButtons.Left ) )
{
var ray = args.Ray;
var distance = 0f;
var direction = Camera.main.transform.TransformDirection( Vector3.back );
var plane = new Plane( direction, lastPosition );
plane.Raycast( ray, out distance );
var pos = ( ray.origin + ray.direction * distance ).Quantize( control.PixelsToUnits() );
var offset = pos - lastPosition;
var transformPos = ( control.transform.position + offset ).Quantize( control.PixelsToUnits() );
control.transform.position = transformPos;
lastPosition = pos;
}
}
示例15: RobotCellUR
internal RobotCellUR(string name, RobotArm robot, IO io, Plane basePlane, Mesh environment) : base(name, Manufacturers.UR, io, basePlane, environment)
{
this.Robot = robot as RobotUR;
this.DisplayMesh = new Mesh();
DisplayMesh.Append(robot.DisplayMesh);
this.DisplayMesh.Transform(this.BasePlane.ToTransform());
}