Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm going through a book, and the example it gave me seems like is should work, but when I try and implement it, it falls short.

My Camera class takes three vectors in to generate View and Projection matrices. I'm giving it a position vector of (0,0,5), a target vector of Vector.Zero and a top vector (which way is up) of Vector.Up.

My Three vertices are placed at (0,1,0), (-1,-1,0), (1,-1,0).

It seems like it should work because the vertices are centered around the origin, and thats where I'm telling the camera to look but when I run the game, the only way to get the camera to see the vertices is to set its position to (0,0,-5) and even then the triangle is skewed. Not sure what's wrong here.

Any suggestions would be helpful.

Just to make sure I've given you guys everything (I don't think these are important as the problem seems to be related to the coordinates, not the ability of the game to draw them): I'm using a VertexBuffer and a BasicEffect.

My render code is as follows:

effect.World = Matrix.Identity;
effect.View = camera.view;
effect.Projection = camera.projection;
effect.VertexColorEnabled = true;

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
    pass.Apply();

    GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
         (PrimitiveType.TriangleStrip, verts, 0, 1);
}
share|improve this question
    
In case you are interested about the clockwise / counterclockwise thing, it’s called "Culling". You can even set it in XNA through CullMode. Also see this tutorial. –  Aufziehvogel Dec 4 '12 at 19:02
add comment

1 Answer

up vote 1 down vote accepted

The first thing which can be wrong is the vertices order. Now they are drawn counterclockwise (if we are looking from the 0,0,5 position. Try to draw them clockwise.

And that your triangle is skewed - you should post some picture. It can be caused by projection matrix. So you should also write how you create it.

share|improve this answer
    
Ok, well changing the order worked but that wasn't why it was skewed. I was defining the vertices in an array of VertexPositionColor and I was overwriting the Object at index 1. ie. vert[0] = new VertexPositionColor(variables); vert[1] = new VertexPositionColor(variables); vert[1] = new VertexPositionColor(variables); So thank you for your help, worked perfectly. –  Peteyslatts Dec 4 '12 at 21:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.