Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Common - Geometry - Type.h_inc
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
// == Geometry ================================================================================================================== //


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Structures
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

typedef struct {
    V(TgVEC)                                    m_vUDT;
    V(TgVEC)                                    m_vDT;
    TYPE                                        m_fDT;
    TYPE                                        m_fDT_DT;
    TYPE                                        m_fInv_DT;
} V(TgDELTA);

typedef struct {
    TYPE                                        m_fX0, m_fY0; //« Upper left point.
    TYPE                                        m_fX1, m_fY1; //« Lower right point.
} V(TgRECT2D);

typedef struct {
    V(TgVEC)                                    m_vMin, m_vMax;
} V(TgBOXAA);

typedef struct {
    union {
        V(TgVEC)                                    avData[4];
        M44(TgMAT)                                  xData;
        struct {
            V(TgVEC)                                    avAxis[3]; //« The three ortho-normal axes used to define the box edges.
            V(TgVEC)                                    vOrigin; //« Origin/Centroid of the box.
        }                                           m;
    }                                           m;
    V(TgVEC)                                    m_vExtent; //« The box's length along each axis from origin to extremity.
} V(TgBOX);

typedef struct {
    union {
        V(TgVEC)                                    avData[4]; //« Full basis set
        M44(TgMAT)                                  xData;
        struct {
            V(TgVEC)                                    vU; //« [x-axis]
            V(TgVEC)                                    vNormal; //« Normal of the plane. [y-axis]
            V(TgVEC)                                    vV; //« [z-axis]
            V(TgVEC)                                    vOrigin; //« Origin of the circle in the reference frame.
        }                                           m;
    }                                           m;
    TYPE                                        m_fRadius; //« Radius of the circle.
    TYPE                                        m_fRadiusSq;//« Radius Squared of the circle.
} V(TgCIRCLE);

typedef struct {
    union {
        V(TgVEC)                                    avData[4]; //« Full basis set
        M44(TgMAT)                                  xData;
        struct {
            V(TgVEC)                                    vU; //« [x-axis]
            V(TgVEC)                                    vNormal; //« Normal of the plane. [y-axis]
            V(TgVEC)                                    vV; //« [z-axis]
            V(TgVEC)                                    vOrigin; //« Origin of the circle in the reference frame.
        }                                           m;
    }                                           m;
    TYPE                                        m_fRadius; //« Radius of the disk.
    TYPE                                        m_fRadiusSq;//« Radius Squared of the disk.
} V(TgDISK);

typedef struct {
    union {
        V(TgVEC)                                    avData[4]; //« Full basis set
        M44(TgMAT)                                  xData;
        struct {
            V(TgVEC)                                    vMajor_Axis; //« [x-axis]
            V(TgVEC)                                    vNormal; //« Normal of the plane. [y-axis]
            V(TgVEC)                                    vMinor_Axis; //« [z-axis]
            V(TgVEC)                                    vOrigin; //« Origin/Centre of the ellipse.
        }                                           m;
    }                                           m;
    TYPE                                        m_fMajor; //« Major radius.
    TYPE                                        m_fMinor; //« Minor radius.
} V(TgELLIPSE);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Origin of the line segment (start point).
    V(TgVEC)                                    m_vDirN; //« The line direction.
} V(TgLINE);


typedef struct {
    V(P_TgVEC)                                  m_pvVert_List;
    P_TgUINT16                                  m_puiIndx_List;
    TgUINT32                                    m_nuiVert;
    TgUINT32                                    m_nuiIndx;
} V(TgMESH_SIMPLE);

 typedef struct {
    V(TgMESH_SIMPLE)                            m_sMS; //« Vertex and Face Data
    V(P_TgVEC)                                  m_pvVert_DT; //« Vertex delta for a swept mesh
    V(TgBOXAA)                                  *m_psBA; //« Bounding box per face
    P_TgUINT32                                  m_puiFlags; //« Collision flags per face
    V(TgDELTA)                                  m_sDT; //« Linear displacement vector, valid only for linear sweep.
    V(TgVEC)                                    m_vCG[2]; //« Centre of gravity at sweep interval.
    ETgSWEEP_TYPE                               m_etgSweep; //« Static, Linear or Rotational test indicator.
} V(TgMESH_BA);

typedef struct {
    V(TgMESH_SIMPLE)                            m_sMS; //« Vertex and Face Data
} V(TgMESH_BVT);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Common point of two of the parallelogram's edges.
    V(TgVEC)                                    m_avEdge[2]; //« The two edge's sourced at the origin point.
    V(TgVEC)                                    m_vNormal; //« The normal for the plane defined by the two edges.
    V(TgVEC)                                    m_avEdgeNormal[2]; //« The normal of the plane defined by an edge and normal.
} V(TgPARALLELOGRAM);

typedef struct {
    V(TgVEC)                                    m_vPos; //« Initial position.
    V(TgVEC)                                    m_vVel; //« Initial velocity.
    V(TgVEC)                                    m_vAccel; //« Initial acceleration.
} V(TgPARTICLE);

typedef struct {
    V4(TgVEC)                                   m_vPlnEqN; //« Store the plane constant in the last element of the vector.
    V(TgVEC)                                    m_vNormal; //« Plane unit-normal.
    TYPE                                        m_fD; //« Plane constant.
} V(TgPLANE);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Origin of the line segment (start point).
    V(TgVEC)                                    m_vDirN; //« The line direction.
} V(TgRAY);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Common point of two of the rectangle's edges.
    V(TgVEC)                                    m_avEdge[2]; //« The two edge's sourced at the origin point.
    V(TgVEC)                                    m_vNormal; //« The normal for the plane defined by the two edges.
} V(TgRECTANGLE);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Origin of the line segment (start point).
    V(TgVEC)                                    m_vDirN; //« The line direction.
} V(TgSEGMENT);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Origin of the sphere.
    TYPE                                        m_fRadius; //« Radius of the sphere.
    TYPE                                        m_fRadiusSq; //« Radius squared of the sphere.
} V(TgSPHERE);

typedef struct {
    V(TgVEC)                                    m_vOrigin; //« Origin of the torus.
    V(TgVEC)                                    m_vNormal; //« 
    TYPE                                        m_fRI; //« Radius of the tube.
    TYPE                                        m_fRO; //« Radius of the torus path.
} V(TgTORUS);

typedef struct {
    V(TgVEC)                                    m_avPoint[3]; //« Three vertices defining the triangle
    V(TgVEC)                                    m_vNormal; //« Triangle normal, not necessarily valid.
} V(TgPTRI);

typedef struct {
    V(TgPTRI)                                   m_sPT;
    V(TgVEC)                                    m_avEdge[3]; //« Segments that terminate at the remaining two triangle vertices.
} V(TgETRI);

typedef struct {
    V(TgETRI)                                   m_sET;
    TgUINT32                                    m_bfFlags; //« Bitfield container for a collection of booleans.
} V(TgCTRI);

typedef struct {
    V(TgCTRI)                                   m_sCT;
    V(TgPLANE)                                  m_avPlane[3];
} V(TgSTRI);

typedef struct {
    // Ortho-normal definition of the reference frame of the tube.
    union {
        V(TgVEC)                                    avData[4]; //« Full basis set
        M44(TgMAT)                                  xData;
        struct {
            V(TgVEC)                                    vU_Basis0; //« Another vector to make an ortho-normal basis set
            V(TgVEC)                                    vU_HAX; //« Primary unit half-axis
            V(TgVEC)                                    vU_Basis1; //« Another vector to make an ortho-normal basis set
            V(TgVEC)                                    vOrigin; //« Mid point of the tube primary axis
        }                                           m;
    }                                           m;

    // Tube definition - centre point and the vector such that its sum and difference with the origin are the two end pointg.

    V(TgVEC)                                    m_vHAX; //« Primary half-axis of the tube

    // The line segment that forms the primary axis of the tube, enclosing both end pointg inclusively.

    V(TgSEGMENT)                                m_sAX; //« Segment from end-to-end of the tube

    // Scalar properties of the tube.

    TYPE                                        m_fExtent; //« Half-height of the tube
    TYPE                                        m_fRadius; //« Radius of the tube
    TYPE                                        m_fRadiusSq; //« Radius Squared
} V(TgTUBE);


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Type
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

TgTYPE_PREFIX( V(TgDELTA) );
TgTYPE_PREFIX( V(TgRECT2D) );
TgTYPE_PREFIX( V(TgBOXAA) );
TgTYPE_PREFIX( V(TgBOX) );
TgTYPE_PREFIX( V(TgCIRCLE) );
TgTYPE_PREFIX( V(TgDISK) );
TgTYPE_PREFIX( V(TgELLIPSE) );
TgTYPE_PREFIX( V(TgLINE) );
TgTYPE_PREFIX( V(TgMESH_SIMPLE) );
TgTYPE_PREFIX( V(TgMESH_BA) );
TgTYPE_PREFIX( V(TgMESH_BVT) );
TgTYPE_PREFIX( V(TgPARALLELOGRAM) );
TgTYPE_PREFIX( V(TgPARTICLE) );
TgTYPE_PREFIX( V(TgPLANE) );
TgTYPE_PREFIX( V(TgRAY) );
TgTYPE_PREFIX( V(TgRECTANGLE) );
TgTYPE_PREFIX( V(TgSEGMENT) );
TgTYPE_PREFIX( V(TgSPHERE) );
TgTYPE_PREFIX( V(TgTORUS) );
TgTYPE_PREFIX( V(TgPTRI) );
TgTYPE_PREFIX( V(TgETRI) );
TgTYPE_PREFIX( V(TgCTRI) );
TgTYPE_PREFIX( V(TgSTRI) );
TgTYPE_PREFIX( V(TgTUBE) );


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Public Functions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

TgINLINE TgVOID                             V(tgGM_Constructor_DT)( V(PCU_TgDELTA) );
TgINLINE TgVOID                             V(tgGM_Reset_DT)( V(PCU_TgDELTA) );
TgINLINE TgBOOL                             V(tgGM_Is_Valid_DT)( V(CPCU_TgDELTA) );
TgINLINE TgVOID                             V(tgGM_TX_DT)( V(PCU_TgDELTA), M34(CPCU_TgMAT) );
TgINLINE TgVOID                             V(tgGM_Copy_TX_DT)( V(PCU_TgDELTA), V(CPCU_TgDELTA), M34(CPCU_TgMAT) );
TgINLINE TgVOID                             V(tgGM_Set_DT)( V(PCU_TgDELTA), V(CPCU_TgVEC) );