Jump to content

  • Log In with Google      Sign In   
  • Create Account

Xna 3d coordinates problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 destructivArts   Members   -  Reputation: 205

Like
0Likes
Like

Posted 04 December 2012 - 11:28 AM

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);
}

-------------------------------------
"Other than that, I have no opinion."
My Blog - Check it Out

Sponsor:

#2 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

Posted 04 December 2012 - 11:36 AM

Here's a quick test: put the camera back where it was and swap the order of the second and third vertex. If it shows up, you were culling the triangle due to winding order (which tells the GPU which way a polygon is "facing").

As for the skew, how are you defining your view and projection matrices?

Edited by BCullis, 04 December 2012 - 11:36 AM.

Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#3 destructivArts   Members   -  Reputation: 205

Like
0Likes
Like

Posted 04 December 2012 - 03:54 PM

Changing the order worked but it still is skewed.

My view matrix is:
view = Matrix.CreateLookAt(pos, target, up);
and the Projection matrix is
view = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height, 1, 100);

Edit:
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

Edited by destructivArts, 04 December 2012 - 03:59 PM.

-------------------------------------
"Other than that, I have no opinion."
My Blog - Check it Out




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS