# need some vertices explinations?

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i know the below code draws a triangle in 3d space, but i dont know how it gets the co-ordinates for each corner of the triangle. can anyone explain the numbers that are needed to create each vertex.i mean , how does the computer know what (0.0f,1.0f,1.0f) are, as i dont understand. thanks CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[3]; verts[0].SetPosition(new Vector3(0.0f,1.0f,1.0f)); verts[0].Color = Color.Red.ToArgb(); verts[1].SetPosition(new Vector3(-1.0f,-1.0f,1.0f)); verts[1].Color = Color.Blue.ToArgb(); verts[2].SetPosition(new Vector3(1.0f,-1.0f,1.0f)); verts[2].Color = Color.Green.ToArgb();

##### Share on other sites
The numbers are coordinates in 3D space, X Y Z triplets. Depending on the world axis these represent values in the left, up and forwards direction, or some other arrangement of these. When you specify the camera position and view, you are placing yourself in this 3D space so all the vertices will appear farther/closer depending on their positions.

Take a looks at the OpenGL / Direct3D tranformation pipeline (camera, projection) and at some tutorials about basics in 3D.

##### Share on other sites
the center of the triangle is 0,0,0. does that mean that each corner is 1 from the center? what metrics are theese co-ordinates in ( centimetres, pixels etc)

##### Share on other sites
Quote:
 Original post by fguihenthe center of the triangle is 0,0,0. does that mean that each corner is 1 from the center? what metrics are theese co-ordinates in ( centimetres, pixels etc)

No the corners are not 1 from the center. To get the distance in 3D between two points (vertices) you use the formula:

distance = sqrt( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 )

Where x1, y1, z1 are the coordinates of one point and x2,y2,z2 of the other.

So the distance between the center and the vertices is square root of 2.

Now for the units: the measurements in 3d have no units, they could be anything depending on the relative sizes of the objects in your scene:

supposing you have a man and a wall, if the man is 2 meters in height and the wall is 2.5 meters in height the sizes in 3D space could be any multiple of those values. for example: 1 and 1.25, 0.5 and 62.5 or 2000 and 2500. Just make sure you have nice ratios so things look good. If you want to use pixels then you have to setup a special projection matrix (search for orthographic projections and you'll find some explanations), but this is a more indepth topic.

##### Share on other sites
i still dont know how, from the values provided, the computer knows where to draw the lines that make up the triangle.sorry

##### Share on other sites
It knows because it takes the 3d coordinates given and, by using matrices, transforms them into screen space (pixels on the screen).

The 3d coordinate is first multiplied with the world matrix which converts the point to a position in world space.
This new coordinate is then multiplied with the view matrix which represents the camera's position and orientation within the scene, to give a new coordinate in camera space.
Finally, the camera space coordinate is multiplied by the projection matrix which projects the camera space 3d coordinate to a position on a 2d plane (the screen).

If you are using OpenGL, the world and view matrices are combined in one matrix known as the 'modelview' matrix.

##### Share on other sites
if the points are not co ordinates, how do you know exactly where you are placing something on the screen? is it just an educated guess, or just where it looks good or what?like, the point (-1,0,1), how do you work out where on the screen that will be? i suppose it all depends on camera position and other such variables

##### Share on other sites
Quote:
 Original post by fguihenif the points are not co ordinates,

The points are coords, but they're in a seperate coordinate space from your screen. In this case they're in world coords, which is an independant 'space' in which things in your game world live.

Quote:
 how do you know exactly where you are placing something on the screen? is it just an educated guess, or just where it looks good or what?like, the point (-1,0,1), how do you work out where on the screen that will be? i suppose it all depends on camera position and other such variables

If you want to find the exact 2d position, you need to transform your vertices into screen coords. That typically involves multiplying by your model & camera & projection matrices. If you're using OpenGL or DX then this will be done for you.

Usually you choose your 3d world coords to model the thing you're after (like a box or person) then position your camera to get a suitable angle. Of course, once you've made your 3d points once you can change the camera and generate the different views automajically.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46