@mgulde wrote:
Dear all, I have come encountered this problem a few times now without ever solving it. So maybe you can help me understand where the actual issue lies:
I have a very simple 3D project and would like to just display a single triangle with the
BasicEffect
class and a customVertexDeclaration
. However, when using an orthographic projection, the triangle becomes invisible as soon as I am looking from above. A tiny offset solves the problem.The VertexDeclaration is as follows:
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration( new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), new VertexElement(sizeof(float) * 6, VertexElementFormat.Color, VertexElementUsage.Color, 0) );
My display vectors are:
View = Matrix.CreateLookAt(Position, Target, Vector3.Up); Projection = Matrix.CreateOrthographic(Settings.ScreenWidth, Settings.ScreenHeight, Settings.NearPlane, Settings.FarPlane);
with
Position = (0, 10, 0)
andTarget = (0, 0, 0)
.The "Model" / triangle is defined as
VX.Add(new VertexPositionNormalColor(new Vector3(0, 0, 0), new Vector3(0, 1, 0), Color.DarkOrange)); VX.Add(new VertexPositionNormalColor(new Vector3(100, 0, 0), new Vector3(0, 1, 0), Color.DarkOrange)); VX.Add(new VertexPositionNormalColor(new Vector3(0, 0, 100), new Vector3(0, 1, 0), Color.DarkOrange));
The drawing routine is
// effect
Eff.World = Matrix.Identity;
Eff.Projection = Cam.Projection;
Eff.View = Cam.View;
Eff.VertexColorEnabled = true;// draw
foreach (EffectPass pass in Eff.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(VB);
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, VX.Count);
}The result is invisible. Only by adding a tiny tilt in the camera angle I can see the triangle as planned:
Position = (0, 10, 0.1f)
.Any ideas?
Posts: 10
Participants: 4