Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, 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:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution 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.
    The name of the author may not 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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Data */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define t0              0.5773502691896257645091487805019F
/* #define fPhi4           6.4721359549995793928183473374626F */
/* #define fRadiusRatio    1.7013016167040798643630809941259F */
#define f2              0.5257311121191336060256690848475F
#define f3              0.8506508083520399321815404970625F




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Data                                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- TETRAHEDRON ----------------------------------------------------------------------------------------------------------------------------------------------------- */

C_TgUINT16 KTgGM_CUBE_INDEX[36] =
{
    0,1,2, 1,3,2, 4,6,5, 5,6,7, 0,5,1, 0,4,5, 2,7,6, 2,3,7, 0,6,4, 0,2,6, 1,7,3, 1,5,7
};

C_TgFLOAT32 KTgGM_CUBE_VERTEX[24] =
{
    -0.5f,-0.5f,-0.5f, -0.5f,-0.5f, 0.5f, -0.5f, 0.5f,-0.5f, -0.5f, 0.5f, 0.5f, 0.5f,-0.5f,-0.5f, 0.5f,-0.5f, 0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f, 0.5f,
};


/* ---- TETRAHEDRON ----------------------------------------------------------------------------------------------------------------------------------------------------- */

C_TgUINT16 KTgGM_TETRAHEDRON_INDEX[12] =
{
       0,3,6,     0,9,3,       6,3,9,      9,0,6
};

C_TgFLOAT32 KTgGM_TETRAHEDRON_VERTEX[12] =
{
    t0,t0,t0,-t0,-t0,t0,-t0,t0,-t0,t0,-t0,-t0
};


/* ---- OCTOGON --------------------------------------------------------------------------------------------------------------------------------------------------------- */

C_TgUINT16 KTgGM_OCTOGON_INDEX[24] =
{
      0,12,6,     6,12,3,     3,12,9,     9,12,0,     0,6,15,     6,3,15,     3,9,15,     9,0,15
};

C_TgFLOAT32 KTgGM_OCTOGON_VERTEX[24] =
{
    1.f,0.f,0.f,-1.f,0.f,0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,1.f,0.f,0.f,-1.f
};


/* ---- ICOSAHEDRON ----------------------------------------------------------------------------------------------------------------------------------------------------- */

C_TgUINT16 KTgGM_ICOSAHEDRON_INDEX[60] =
{
     4, 8, 7,     4, 7, 9,     5, 6,11,     5,10, 6,     0, 4, 3,     0, 3, 5,     2, 7, 1,     2, 1, 6,     8, 0,11,     8,11, 1,
     9,10, 3,     9, 2,10,     8, 4, 0,    11, 0, 5,     4, 9, 3,     5, 3,10,     7, 8, 1,     6, 1,11,     7, 2, 9,     6,10, 2
};

C_TgFLOAT32 KTgGM_ICOSAHEDRON_VERTEX[96] =
{
     f3,  f2,  0.0F, 1.0F,           f3, f2, 0.0F, 0.0F,
    -f3,  f2,  0.0F, 1.0F,          -f3, f2, 0.0F, 0.0F,
    -f3, -f2,  0.0F, 1.0F,          -f3,-f2, 0.0F, 0.0F,
     f3, -f2,  0.0F, 1.0F,           f3,-f2, 0.0F, 0.0F,

     f2,  0.0F,  f3, 1.0F,            f2, 0.0F, f3, 0.0F,
     f2,  0.0F, -f3, 1.0F,            f2, 0.0F,-f3, 0.0F,
    -f2,  0.0F, -f3, 1.0F,           -f2, 0.0F,-f3, 0.0F,
    -f2,  0.0F,  f3, 1.0F,           -f2, 0.0F, f3, 0.0F,

     0.0F,  f3,  f2, 1.0F,            0.0F, f3, f2, 0.0F,
     0.0F, -f3,  f2, 1.0F,            0.0F,-f3, f2, 0.0F,
     0.0F, -f3, -f2, 1.0F,            0.0F,-f3,-f2, 0.0F,
     0.0F,  f3, -f2, 1.0F,            0.0F, f3,-f2, 0.0F,
};


/* ---- ICOSAHEDRON_HEMI ------------------------------------------------------------------------------------------------------------------------------------------------ */

C_TgUINT16 KTgGM_ICOSAHEDRON_HEMI_INDEX[108] =
{
     /* Positive Cap */
      2, 6, 5, /* 0,P,0,*/
      3, 4, 7, /* 0,0,P,*/
      6, 0, 7, /* P,P,P,*/
      6, 7, 1, /* P,P,P,*/
      6, 2, 0, /* P,0,P,*/
      7, 0, 3, /* P,P,0,*/
      5, 6, 1, /* 0,P,P,*/
      4, 1, 7, /* 0,P,P,*/
      2, 8, 0,
      8, 3, 0,
      4, 9, 1,
      9, 5, 1,

     /* Negative Cap */
     12,15,16, /* 0,0,N,*/
     13,17,14, /* 0,N,0,*/
     16,17,11, /* N,N,N,*/
     16,10,17, /* N,N,N,*/
     12,16,11, /* 0,N,N,*/
     13,11,17, /* 0,N,N,*/
     15,10,16, /* 0,N,N,*/
     14,17,10, /* 0,N,N*/
     13,18,11,
     18,12,11,
     15,19,10,
     19,14,10,

     /* Tube Section */
      2,12, 8,
      8,12,18,
      8,18, 3,
      3,18,13,
      3,13, 4,
      4,13,14,
      4,14, 9,
      9,14,19,
      9,19, 5,
      5,19,15,
      5,15, 2,
      2,15,12,
};


C_TgFLOAT32 KTgGM_ICOSAHEDRON_HEMI_VERTEX[160] =
{
     /* Positive Cap */
     f3,     f2, 0.0F, 1.0F,       f3,   f2,   0.0F, 0.0F,
    -f3,     f2, 0.0F, 1.0F,      -f3,   f2,   0.0F, 0.0F,
     f2,   0.0F,   f3, 1.0F,       f2,   0.0F, f3,   0.0F,
     f2,   0.0F,  -f3, 1.0F,       f2,   0.0F,-f3,   0.0F,
    -f2,   0.0F,  -f3, 1.0F,      -f2,   0.0F,-f3,   0.0F,
    -f2,   0.0F,   f3, 1.0F,      -f2,   0.0F, f3,   0.0F,
     0.0F,   f3,   f2, 1.0F,       0.0F, f3,   f2,   0.0F,
     0.0F,   f3,  -f2, 1.0F,       0.0F, f3,  -f2,   0.0F,
     0.5F, 0.0F, 0.0F, 1.0F,       1.0F, 0.0F, 0.0F, 0.0F,
    -0.5F, 0.0F, 0.0F, 1.0F,      -1.0F, 0.0F, 0.0F, 0.0F,

     /* Negative Cap */
    -f3,   -f2,  0.0F, 1.0F,      -f3,  -f2,   0.0F,  0.0F,
     f3,   -f2,  0.0F, 1.0F,       f3,  -f2,   0.0F,  0.0F,
     f2,   0.0F,   f3, 1.0F,       f2,   0.0F, f3,    0.0F,
     f2,   0.0F,  -f3, 1.0F,       f2,   0.0F,-f3,    0.0F,
    -f2,   0.0F,  -f3, 1.0F,      -f2,   0.0F,-f3,    0.0F,
    -f2,   0.0F,   f3, 1.0F,      -f2,   0.0F, f3,    0.0F,
     0.0F,  -f3,   f2, 1.0F,       0.0F,-f3,   f2,    0.0F,
     0.0F,  -f3,  -f2, 1.0F,       0.0F,-f3,  -f2,    0.0F,
     0.5F, 0.0F, 0.0F, 1.0F,       1.0F, 0.0F, 0.0F,  0.0F,
    -0.5F, 0.0F, 0.0F, 1.0F,      -1.0F, 0.0F, 0.0F,  0.0F,
};




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

/* ---- tgGM_Primitive_To_String ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_TgCHAR tgGM_Primitive_To_String( C_ETgPRIMITIVE enPM )
{
    switch (enPM)
    {
        case ETgPRIMITIVE_UNKNOWN:
        case ETgPRIMITIVE_MAX:
        default: return(TgT("UNKNOWN"));

        case ETgPOINT: return(TgT("POINT"));
        case ETgPARTICLE: return(TgT("PARTICLE"));

        case ETgLINE: return(TgT("LINE"));
        case ETgRAY: return(TgT("RAY"));
        case ETgSEGMENT: return(TgT("SEGMENT"));

        case ETgRECTANGLE2D: return(TgT("RECTANGLE2D"));
        case ETgELLIPSE2D: return(TgT("ELLIPSE2D"));

        case ETgCIRCLE: return(TgT("CIRCLE"));
        case ETgDISK: return(TgT("DISK"));
        case ETgELLIPSE: return(TgT("ELLIPSE"));
        case ETgPARALLELOGRAM: return(TgT("PARALLELOGRAM"));
        case ETgPLANE: return(TgT("PLANE"));
        case ETgRECTANGLE: return(TgT("RECTANGLE"));
        case ETgPTRI: return(TgT("PTRI"));
        case ETgETRI: return(TgT("ETRI"));
        case ETgCTRI: return(TgT("CTRI"));
        case ETgSTRI: return(TgT("STRI"));

        case ETgBOXAA: return(TgT("BOXAA"));
        case ETgBOX: return(TgT("BOX"));
        case ETgCAPSULE: return(TgT("CAPSULE"));
        case ETgCONE: return( TgT("CONE") );
        case ETgCYLINDER: return(TgT("CYLINDER"));
        case ETgFRUSTRUM: return( TgT("FRUSTRUM") );
        case ETgMESH_SIMPLE: return(TgT("MESH_SIMPLE"));
        case ETgMESH_BVT: return(TgT("MESH_BVT"));
        case ETgMESH_BA: return(TgT("MESH_BA"));
        case ETgSPHERE: return(TgT("SPHERE"));
        case ETgTETRAHEDRON: return( TgT("TETRAHEDRON") );
        case ETgTORUS: return(TgT("TORUS"));
        case ETgTUBE: return(TgT("TUBE"));
    };
}


/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define PCU_TYPE TgFLOAT32 * __restrict const
#define TYPE TgFLOAT32
#define MKL(A) A##F
#define F(A) A##_F32
#define M34(A) A##_F32_34

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define V(A) A##_F32_04

#include "TgS Common - Geometry 3D - Box.c_inc"
#include "TgS Common - Geometry 3D - Circle.c_inc"
#include "TgS Common - Geometry 3D - Cylinder.c_inc"
#include "TgS Common - Geometry 3D - Disk.c_inc"
#include "TgS Common - Geometry 3D - Ellipse.c_inc"
#include "TgS Common - Geometry 3D - Mesh [BA].c_inc"
#include "TgS Common - Geometry 3D - Mesh [Simple].c_inc"
#include "TgS Common - Geometry 3D - Particle.c_inc"
#include "TgS Common - Geometry 3D - Torus.c_inc"
#include "TgS Common - Geometry 3D - Triangle [Collision].c_inc"
#include "TgS Common - Geometry 3D - Triangle [Edge].c_inc"
#include "TgS Common - Geometry 3D - Triangle [Point].c_inc"

#define FI(A) A##_VL_F32_04
#include "TgS Common - Geometry 3D - Mesh [Utility].c_inc"
#undef FI
#define FI(A) A##_IL_F32_04
#include "TgS Common - Geometry 3D - Mesh [Utility].c_inc"
#undef FI

#undef V

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#undef M34
#undef F
#undef MKL
#undef TYPE
#undef PCU_TYPE

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define PCU_TYPE TgFLOAT64 * __restrict const
#define TYPE TgFLOAT64
#define MKL(A) A
#define F(A) A##_F64
#define M34(A) A##_F64_34

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define V(A) A##_F64_04

#include "TgS Common - Geometry 3D - Box.c_inc"
#include "TgS Common - Geometry 3D - Circle.c_inc"
#include "TgS Common - Geometry 3D - Cylinder.c_inc"
#include "TgS Common - Geometry 3D - Disk.c_inc"
#include "TgS Common - Geometry 3D - Ellipse.c_inc"
#include "TgS Common - Geometry 3D - Mesh [BA].c_inc"
#include "TgS Common - Geometry 3D - Mesh [Simple].c_inc"
#include "TgS Common - Geometry 3D - Particle.c_inc"
#include "TgS Common - Geometry 3D - Torus.c_inc"
#include "TgS Common - Geometry 3D - Triangle [Collision].c_inc"
#include "TgS Common - Geometry 3D - Triangle [Edge].c_inc"
#include "TgS Common - Geometry 3D - Triangle [Point].c_inc"

#define FI(A) A##_VL_F64_04
#include "TgS Common - Geometry 3D - Mesh [Utility].c_inc"
#undef FI
#define FI(A) A##_IL_F64_04
#include "TgS Common - Geometry 3D - Mesh [Utility].c_inc"
#undef FI

#undef V

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#undef M34
#undef F
#undef MKL
#undef TYPE
#undef PCU_TYPE

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */