# Newbie 3d Maths, I'm Afraid...

• 04-05-2009
SMurf
Newbie 3d Maths, I'm Afraid...
Hello,

I'm having a go at creating an isometric tile-based graphics engine. So far I can draw maps consisting of perfectly flat tiles at different heights easily enough, but what I want to be able to do now is allow different heights to be used for the each vertex of a tile.

As a tile is a quadrilateral with 4 vertexes, how do I go about splitting that into two triangles? I know that the triangles may be on different planes. Each vertex's height is restricted to a range of -3 to +3 so the resulting shapes are not too weird.
• 04-05-2009
VirtualAce
You can either create a quad in local space as normal and then rotate it 90 degrees and set the camera angle to +45 degrees of pitch or you can make the 'tiles' as they are in local space.

Since the first method fits the pipeline I would recommend using it.

A quad in a left handed system with no strip and no indices and counter clockwise culling (IE: clockwise vertex ordering) is:

Triangle 1
0) -1,1,0,0,0
1) 1,1,0,1,0
2) -1,-1,0,1,0

Triangle 2
3) -1,-1,0,0,1
4) 1,1,0,1,1,0
5) 1,-1,0,1,1

In left handed systems right is +x, up is +y, into the screen is +z.
• 04-05-2009
SMurf
Woah! First off, I don't have the advantage of a full 3D rendering library, I'm trying to project this using 2D graphics functions only. So none of this "camera" jazz.

In my psuedo-3D coordinate system, x goes in a southeasterly direction, y goes in a northeasterly direction and z goes up.
Code:

```      |Z     -|--  /Y   --  |  -- <    |      >   --      --     ----  \X```
(Yes that's supposed to be an isometric tile)

Second, I know nothing about strips, indices or culling, so the numbers you have provided are surplus to my needs (although I think you've got too many numbers on vertex 4! Have I got the hang of it? :D).

I think there's a way that I can figure this out by turning the 4 vertices into 2 triangles in vertex order, working out the normals of each triangle and then doing something with those. If that something isn't right, then I simply shuffle the vertices into the other set of triangles (there are only 2 possible permutations).

In this vein:-
Code:

```// make vectors of the vertices of triangle 1 and determine the normal vector v1.x = tile->triangles[0].vertices[0].x - tile->triangles[0].vertices[1].x; v1.y = tile->triangles[0].vertices[0].y - tile->triangles[0].vertices[1].y; v1.z = tile->triangles[0].vertices[0].z - tile->triangles[0].vertices[1].z; v2.x = tile->triangles[0].vertices[2].x - tile->triangles[0].vertices[1].x; v2.y = tile->triangles[0].vertices[2].y - tile->triangles[0].vertices[1].y; v2.z = tile->triangles[0].vertices[2].z - tile->triangles[0].vertices[1].z; vn.x = (v1.y * v2.z) - (v1.z * v2.y); vn.y = (v1.z * v2.x) - (v1.x * v2.z); vn.z = (v1.x * v2.y) - (v1.y * v2.x);```
For a triangle that's part of a "flat" isometric tile (which you could say is facing upwards), vn.x = 0, vn.y = 0, vn.z = 1.

Is it sensible to do this with the other triangle and then do some sort of comparison to work out if they both fully represent the quadrilateral, or am I way off?

EDIT: I think that I might be doing this ALLLLL wrong!
In essence, defining a tile by only its 4 vertices gives rise to the following:-
http://www.imalarkey.org.uk/images/isotiles.png
Both of these are valid. What I want to know is how should I differentiate between them? Is there a situation where I would need one over the other?