Thread: Newbie 3d Maths, I'm Afraid...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK

    Red face Newbie 3d Maths, I'm Afraid...


    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.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    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.

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK
    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.
         -|--  /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? ).

    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:-
    // 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:-
    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?
    Last edited by SMurf; 04-05-2009 at 04:05 PM. Reason: I'm stupid :(

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 05:33 PM
  2. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  3. 3D SDK for C++ programmers
    By chand in forum Game Programming
    Replies: 2
    Last Post: 05-20-2003, 07:38 AM
  4. 3D Engines
    By Peter_D3T in forum C++ Programming
    Replies: 5
    Last Post: 06-22-2002, 03:59 PM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 10:19 AM