本文整理汇总了C#中BoundingFrustum.GetCorners方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingFrustum.GetCorners方法的具体用法?C# BoundingFrustum.GetCorners怎么用?C# BoundingFrustum.GetCorners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingFrustum
的用法示例。
在下文中一共展示了BoundingFrustum.GetCorners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Project
/// <summary>
/// Project a point into 2D space
/// </summary>
public static Vector2 Project(BoundingFrustum VisibleArea, Vector3 Point)
{
//Acquires the frustum of the area of the screen in view.
//Then it stores the corners of the area.
Vector3[] corners = VisibleArea.GetCorners();
Ray ray = new Ray(Point, Point - Manager.CameraFocus - Manager.CameraLocation);
float? DistanceToFar = ray.Intersects(VisibleArea.Far);
float? DistanceToNear = ray.Intersects(VisibleArea.Near);
Vector3 ScreenCoord;
if (DistanceToFar.HasValue)
{
ScreenCoord = ray.Position + ray.Direction * DistanceToFar.Value;
ScreenCoord = new Vector3(
Vector3.Dot(
Vector3.Normalize(corners[5] - corners[4])
, ScreenCoord - corners[4])
/ (corners[5] - corners[4]).Length()
, Vector3.Dot(
Vector3.Normalize(corners[7] - corners[4])
, ScreenCoord - corners[4])
/ (corners[7] - corners[4]).Length()
, 0);
}
else
{
//Make sure this is off the screen
return Vector2.One * (Manager.GameWindow.Width + Manager.GameWindow.Height);
}
return new Vector2(ScreenCoord.X * Manager.GameWindow.Width, ScreenCoord.Y * Manager.GameWindow.Height);
}
示例2: DrawWireframe
public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
Matrix cameraView, Matrix cameraProjection,
BoundingFrustum frustum, Color color)
{
// The points returned correspond to the corners of the BoundingFrustum faces that are
// perpendicular to the z-axis. The near face is the face with the larger z value, and
// the far face is the face with the smaller z value. Points 0 to 3 correspond to the
// near face in a clockwise order starting at its upper-left corner when looking toward
// the origin from the positive z direction. Points 4 to 7 correspond to the far face
// in a clockwise order starting at its upper-left corner when looking toward the
// origin from the positive z direction.
frustum.GetCorners(Corners);
FrustumVertices[6].Position = Corners[0];
FrustumVertices[7].Position = Corners[1];
FrustumVertices[5].Position = Corners[2];
FrustumVertices[4].Position = Corners[3];
FrustumVertices[2].Position = Corners[4];
FrustumVertices[3].Position = Corners[5];
FrustumVertices[1].Position = Corners[6];
FrustumVertices[0].Position = Corners[7];
primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
}
示例3: Draw
public void Draw(
ref BoundingFrustum boundingFrustum,
Effect effect,
ref Color vertexColor)
{
var coners = boundingFrustum.GetCorners();
var vertices = new VertexPositionColor[8];
for (int i = 0; i < 8; i++)
{
vertices[i].Position = coners[i];
vertices[i].Color = vertexColor;
}
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
vertices,
0,
8,
indices,
0,
primitiveCount);
}
}
示例4: UpdateFromBoundingFrustum
public void UpdateFromBoundingFrustum(BoundingFrustum sourceBoundingFrustum)
{
#region Create the lines if necessary
if (mLines.Count == 0)
{
for (int i = 0; i < NumberOfLines; i++)
{
Line line = ShapeManager.AddLine();
mLines.Add(line);
}
}
#endregion
Vector3[] corners = sourceBoundingFrustum.GetCorners();
mLines[0].SetFromAbsoluteEndpoints(corners[0], corners[1]);
mLines[1].SetFromAbsoluteEndpoints(corners[1], corners[2]);
mLines[2].SetFromAbsoluteEndpoints(corners[2], corners[3]);
mLines[3].SetFromAbsoluteEndpoints(corners[3], corners[0]);
mLines[4].SetFromAbsoluteEndpoints(corners[4], corners[5]);
mLines[5].SetFromAbsoluteEndpoints(corners[5], corners[6]);
mLines[6].SetFromAbsoluteEndpoints(corners[6], corners[7]);
mLines[7].SetFromAbsoluteEndpoints(corners[7], corners[4]);
mLines[8].SetFromAbsoluteEndpoints(corners[0], corners[4]);
mLines[9].SetFromAbsoluteEndpoints(corners[1], corners[5]);
mLines[10].SetFromAbsoluteEndpoints(corners[2], corners[6]);
mLines[11].SetFromAbsoluteEndpoints(corners[3], corners[7]);
sourceBoundingFrustum.Near.ToString();
}
示例5: Draw
/// <summary>
/// Draw a bounding frustrum representation
/// </summary>
/// <param name="frustum">Frustrum</param>
/// <param name="camera">Camera</param>
/// <param name="color">Color</param>
public static void Draw(BoundingFrustum frustum, BaseCamera camera, Color color)
{
if (effect == null)
{
effect = new BasicEffect(YnG.GraphicsDevice);
effect.VertexColorEnabled = true;
effect.LightingEnabled = false;
}
Vector3[] corners = frustum.GetCorners();
for (int i = 0; i < 8; i++)
{
vertices[i].Position = corners[i];
vertices[i].Color = color;
}
effect.View = camera.View;
effect.Projection = camera.Projection;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
YnG.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, indices.Length / 2);
}
}
示例6: Projector
public Projector()
: base()
{
const float near = 0.2f;
const float far = 2.3f;
const float scale = 1.0f / ScreenDistance * near;
projection = Matrix.CreatePerspectiveOffCenter(
scale * Skreen.Left, scale * Skreen.Right,
scale * -Skreen.Height / 2, scale * Skreen.Height / 2,
near, far);
view = Matrix.CreateTranslation(0.0f, -Skreen.Height / 2, -ScreenDistance);
// this.Width = Screen.PixelWidth;
// this.Height = Screen.PixelHeight;
// this.Left = WinScreen.AllScreens.Where(s => s != WinScreen.PrimaryScreen).First().Bounds.Left;
// this.WindowState = FormWindowState.Maximized;
// this.FormBorderStyle = FormBorderStyle.None;
var num = Skreen.PixelHeight;
var frustum = new BoundingFrustum(view * projection);
var corners = frustum.GetCorners();
var tpos = corners[4];
var tray = (corners[7] - corners[4]) / (float)num;
var bpos = corners[5];
var bray = (corners[6] - corners[5]) / (float)num;
SweptPlanes = new Plane[num];
var projectorPos = Vector3.Zero;//.Invert(this.View).Translation;
for (int i = 0; i < num; ++i)
SweptPlanes[i] = new Plane(projectorPos, tpos + (float)i * tray, bpos + (float)i * bray);
}
示例7: Unproject
/// <summary>
/// Unproject a screen coordinate into a ray
/// </summary>
public static Ray Unproject(Vector2 Point)
{
//Acquires the frustum of the area of the screen in view
//Then it stores the corners of the area
BoundingFrustum VisibleArea = new BoundingFrustum(Manager.View * Manager.Projection);
Vector3[] corners = VisibleArea.GetCorners();
Vector3 Position = new Vector3(Point, 0.0f);
Ray ray = new Ray();
//Point on the near plane of the visible area
ray.Position =
corners[0] * (1 - Position.X) * (1 - Position.Y)
+ corners[1] * Position.X * (1 - Position.Y)
+ corners[2] * Position.X * Position.Y
+ corners[3] * (1 - Position.X) * Position.Y;
Position =
corners[4] * (1 - Position.X) * (1 - Position.Y)
+ corners[5] * Position.X * (1 - Position.Y)
+ corners[6] * Position.X * Position.Y
+ corners[7] * (1 - Position.X) * Position.Y;
//Direction between the two points
ray.Direction = Vector3.Normalize(Position - ray.Position);
return ray;
}
示例8: GetFrustumExtent
/// <summary>
///
/// </summary>
/// <param name="view"></param>
/// <param name="projection"></param>
/// <param name="frustum"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
bool GetFrustumExtent ( Matrix view, Matrix projection, Rectangle viewport, BoundingFrustum frustum, out Vector4 min, out Vector4 max )
{
min = max = Vector4.Zero;
var znear = projection.M34 * projection.M43 / projection.M33;
var viewPoints = frustum.GetCorners()
.Select( p0 => Vector3.TransformCoordinate( p0, view ) )
.ToArray();
//var dr = Game.GetService<DebugRender>();
var lines = new[]{
new Line( viewPoints[0], viewPoints[1] ),
new Line( viewPoints[1], viewPoints[2] ),
new Line( viewPoints[2], viewPoints[3] ),
new Line( viewPoints[3], viewPoints[0] ),
new Line( viewPoints[4], viewPoints[5] ),
new Line( viewPoints[5], viewPoints[6] ),
new Line( viewPoints[6], viewPoints[7] ),
new Line( viewPoints[7], viewPoints[4] ),
new Line( viewPoints[0], viewPoints[4] ),
new Line( viewPoints[1], viewPoints[5] ),
new Line( viewPoints[2], viewPoints[6] ),
new Line( viewPoints[3], viewPoints[7] ),
};
lines = lines.Where( line => line.Clip(znear) ).ToArray();
if (!lines.Any()) {
return false;
}
var projPoints = new List<Vector3>();
foreach ( var line in lines ) {
projPoints.Add( Vector3.TransformCoordinate( line.A, projection ) );
projPoints.Add( Vector3.TransformCoordinate( line.B, projection ) );
}
min.X = projPoints.Min( p => p.X );
min.Y = projPoints.Max( p => p.Y );
min.Z = projPoints.Min( p => p.Z );
max.X = projPoints.Max( p => p.X );
max.Y = projPoints.Min( p => p.Y );
max.Z = projPoints.Max( p => p.Z );
min.X = ( min.X * 0.5f + 0.5f ) * viewport.Width;
min.Y = ( min.Y * -0.5f + 0.5f ) * viewport.Height;
max.X = ( max.X * 0.5f + 0.5f ) * viewport.Width;
max.Y = ( max.Y * -0.5f + 0.5f ) * viewport.Height;
return true;
}
示例9: GetCameraBoundingBox
public static BoundingBox GetCameraBoundingBox(Matrix viewTransform, Matrix projectionTransform)
{
BoundingFrustum cameraFrustum = new BoundingFrustum(Matrix.Identity);
cameraFrustum.Matrix = viewTransform * projectionTransform;
// Get the corners of the frustum
Vector3[] frustumCorners = cameraFrustum.GetCorners();
BoundingBox bounds = BoundingBox.CreateFromPoints(frustumCorners);
return bounds;
}
示例10: AddFrustum
// IMPORTANT: Bounding box you are trying to change need to have positive/negative infinite values, so initialize it with InitialBox (static member)
static public void AddFrustum(ref BoundingFrustum frustum, ref BoundingBox bb)
{
if (pts == null)
pts = new Vector3[8];
frustum.GetCorners(pts);
AddPoint(ref pts[0], ref bb);
AddPoint(ref pts[1], ref bb);
AddPoint(ref pts[2], ref bb);
AddPoint(ref pts[3], ref bb);
AddPoint(ref pts[4], ref bb);
AddPoint(ref pts[5], ref bb);
AddPoint(ref pts[6], ref bb);
AddPoint(ref pts[7], ref bb);
}
示例11: AddBoundingFrustum
public static void AddBoundingFrustum(BoundingFrustum frustum, Color color)
{
// Get a DebugShape we can use to draw the frustum
DebugShape shape = GetShapeForLines(12);
// Get the corners of the frustum
frustum.GetCorners(corners);
// Fill in the vertices for the bottom of the frustum
shape.Vertices[0] = new VertexPositionColor(corners[0], color);
shape.Vertices[1] = new VertexPositionColor(corners[1], color);
shape.Vertices[2] = new VertexPositionColor(corners[1], color);
shape.Vertices[3] = new VertexPositionColor(corners[2], color);
shape.Vertices[4] = new VertexPositionColor(corners[2], color);
shape.Vertices[5] = new VertexPositionColor(corners[3], color);
shape.Vertices[6] = new VertexPositionColor(corners[3], color);
shape.Vertices[7] = new VertexPositionColor(corners[0], color);
// Fill in the vertices for the top of the frustum
shape.Vertices[8] = new VertexPositionColor(corners[4], color);
shape.Vertices[9] = new VertexPositionColor(corners[5], color);
shape.Vertices[10] = new VertexPositionColor(corners[5], color);
shape.Vertices[11] = new VertexPositionColor(corners[6], color);
shape.Vertices[12] = new VertexPositionColor(corners[6], color);
shape.Vertices[13] = new VertexPositionColor(corners[7], color);
shape.Vertices[14] = new VertexPositionColor(corners[7], color);
shape.Vertices[15] = new VertexPositionColor(corners[4], color);
// Fill in the vertices for the vertical sides of the frustum
shape.Vertices[16] = new VertexPositionColor(corners[0], color);
shape.Vertices[17] = new VertexPositionColor(corners[4], color);
shape.Vertices[18] = new VertexPositionColor(corners[1], color);
shape.Vertices[19] = new VertexPositionColor(corners[5], color);
shape.Vertices[20] = new VertexPositionColor(corners[2], color);
shape.Vertices[21] = new VertexPositionColor(corners[6], color);
shape.Vertices[22] = new VertexPositionColor(corners[3], color);
shape.Vertices[23] = new VertexPositionColor(corners[7], color);
}
示例12: Render
public static void Render(BoundingFrustum frustum,
GraphicsDevice graphicsDevice,
Matrix view,
Matrix projection,
Color color)
{
if (_basicEffect.IsNull())
_basicEffect = new BasicEffect(graphicsDevice)
{
VertexColorEnabled = true,
LightingEnabled = false
};
var corners = frustum.GetCorners();
for (var i = 0; i < 8; i++)
{
Vertices[i].Position = corners[i];
Vertices[i].Color = color;
}
_basicEffect.View = view;
_basicEffect.Projection = projection;
foreach (var pass in _basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList,
Vertices,
0,
8,
Indices,
0,
Indices.Length/2);
}
}
示例13: DrawCamera
public void DrawCamera(RTSRenderer renderer, Rectangle scissor)
{
BoundingFrustum f = new BoundingFrustum(renderer.Camera.View * renderer.Camera.Projection);
Vector3[] corners = f.GetCorners();
for(int i = 0; i < 4; i++) {
Vector3 dir = corners[i + 4] - corners[i];
float min = dir.Length();
dir /= min;
Ray r = new Ray(corners[i], dir);
foreach(Plane p in mapPlanes) {
float? v = r.Intersects(p);
if(v != null && v.Value < min) {
min = v.Value;
}
}
corners[i + 4] = r.Position + (r.Direction * min);
}
VertexPositionColor[] verts = {
new VertexPositionColor(corners[0], CAMERA_COLOR_START),
new VertexPositionColor(corners[1], CAMERA_COLOR_START),
new VertexPositionColor(corners[3], CAMERA_COLOR_START),
new VertexPositionColor(corners[2], CAMERA_COLOR_START),
new VertexPositionColor(corners[4], CAMERA_COLOR_END),
new VertexPositionColor(corners[5], CAMERA_COLOR_END),
new VertexPositionColor(corners[7], CAMERA_COLOR_END),
new VertexPositionColor(corners[6], CAMERA_COLOR_END)
};
renderer.G.BlendState = BlendState.Additive;
renderer.G.DepthStencilState = DepthStencilState.None;
renderer.G.RasterizerState = RasterizerState.CullNone;
fxCamera.CurrentTechnique.Passes[0].Apply();
Viewport vp = renderer.G.Viewport;
renderer.G.Viewport = new Viewport(scissor);
renderer.G.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, verts, 0, 8, FRUSTUM_INDS, 0, 12);
renderer.G.Viewport = vp;
}
示例14: AddBoundingFrustum
public static void AddBoundingFrustum(BoundingFrustum frustum, Color color, float life)
{
DebugShape shape = GetShapeForLines(12, life);
frustum.GetCorners(Corners);
shape.Vertices[0] = new VertexPositionColor(Corners[0], color);
shape.Vertices[1] = new VertexPositionColor(Corners[1], color);
shape.Vertices[2] = new VertexPositionColor(Corners[1], color);
shape.Vertices[3] = new VertexPositionColor(Corners[2], color);
shape.Vertices[4] = new VertexPositionColor(Corners[2], color);
shape.Vertices[5] = new VertexPositionColor(Corners[3], color);
shape.Vertices[6] = new VertexPositionColor(Corners[3], color);
shape.Vertices[7] = new VertexPositionColor(Corners[0], color);
shape.Vertices[8] = new VertexPositionColor(Corners[4], color);
shape.Vertices[9] = new VertexPositionColor(Corners[5], color);
shape.Vertices[10] = new VertexPositionColor(Corners[5], color);
shape.Vertices[11] = new VertexPositionColor(Corners[6], color);
shape.Vertices[12] = new VertexPositionColor(Corners[6], color);
shape.Vertices[13] = new VertexPositionColor(Corners[7], color);
shape.Vertices[14] = new VertexPositionColor(Corners[7], color);
shape.Vertices[15] = new VertexPositionColor(Corners[4], color);
shape.Vertices[16] = new VertexPositionColor(Corners[0], color);
shape.Vertices[17] = new VertexPositionColor(Corners[4], color);
shape.Vertices[18] = new VertexPositionColor(Corners[1], color);
shape.Vertices[19] = new VertexPositionColor(Corners[5], color);
shape.Vertices[20] = new VertexPositionColor(Corners[2], color);
shape.Vertices[21] = new VertexPositionColor(Corners[6], color);
shape.Vertices[22] = new VertexPositionColor(Corners[3], color);
shape.Vertices[23] = new VertexPositionColor(Corners[7], color);
}
示例15: DrawWireFrustum
/// <summary>
/// Renders the outline of a bounding frustum
/// </summary>
/// <param name="frustum">Bounding frustum to render</param>
/// <param name="color">Color of the frustum lines</param>
public void DrawWireFrustum(BoundingFrustum frustum, Color color)
{
DrawWireShape(frustum.GetCorners(), cubeIndices, color);
}