// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // // Project: Talina Gaming System (TgS) (∂) // File: TgS Collision - Cylinder.cpp // Author: Andrew Aye (EMail: andrew.aye@gmail.com, Web: http://www.andrewaye.com) // Version: 3.11 // // ------------------------------------------------------------------------------------------------------------------------------ // // // Copyright: © 2002-2008, 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". // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // namespace TGS { // START TGS /////////////////////////////////////////////////////////////////////////////////////////////////////// namespace COL { // START COL /////////////////////////////////////////////////////////////////////////////////////////////////////// // ============================================================================================================================== // // Functions used internally by the system // ============================================================================================================================== // TgVOID Unit_Test_Collision_Cylinder() //« Used to confirm the instantiation of standard functions and compile time valid. { TgF4LINE tgLN0; TgF4RAY tgRY0; TgF4SEGMENT tgSG0; TgF4PLANE tgPN0; TgF4STRI tgST0; TgF4CYLINDER tgCY0; TgF4SPHERE tgSP0; TgF4BOX tgBX0; TgF4CAPSULE tgCP0; TgF4VECTOR tvRT0; TgFLOAT32 tyT0; TgBOOL bK0; TgF4CONTACT_PACKET tgPK; TgF4CLIP_LIST tgCL; TgF4AXIS_RESULT tgAxS; F_DistSq( tgCY0, tgPN0 ); F_Dist( tgCY0, tgPN0 ); F_ClosestSq( &tvRT0, &tvRT0, tgCY0, tgPN0 ); F_Closest( &tvRT0, &tvRT0, tgCY0, tgPN0 ); F_Contact_Intersect( &tyT0,&tyT0, &tvRT0,&tvRT0, tgCY0, tgLN0 ); F_Contact_Intersect( &tyT0,&tyT0, &tvRT0,&tvRT0, tgCY0, tgRY0 ); F_Contact_Intersect( &tyT0,&tyT0, &tvRT0,&tvRT0, tgCY0, tgSG0 ); F_Contact_Intersect( &tgPK, tgCY0, tgLN0 ); F_Contact_Intersect( &tgPK, tgCY0, tgRY0 ); F_Contact_Intersect( &tgPK, tgCY0, tgSG0 ); F_Contact_Penetrate( &tgPK, tgPN0, tgCY0 ); F_Contact_Penetrate( &tgPK, tgST0, tgCY0 ); F_Contact_Penetrate( &tgPK, tgSP0, tgCY0 ); F_Contact_Penetrate( &tgPK, tgBX0, tgCY0 ); F_Contact_Penetrate( &tgPK, tgCY0, tgCY0 ); F_Contact_Penetrate( &tgPK, tgCP0, tgCY0 ); F_Axis_Seperation( &tgAxS, &bK0, tgBX0, tgCY0 ); F_Axis_Seperation( &tgAxS, tgST0, tgCY0 ); F_Clip( &tyT0,&tyT0, tgCY0, tgLN0 ); F_Clip( &tyT0,&tyT0, tgCY0, tgRY0 ); F_Clip( &tyT0,&tyT0, tgCY0, tgSG0 ); F_Clip( &tgCL, tgCY0, tgLN0 ); F_Clip( &tgCL, tgCY0, tgRY0 ); F_Clip( &tgCL, tgCY0, tgSG0 ); }; // ============================================================================================================================== // //enum { KTgMAX_MSG = 1024 }; //TgCHAR g_szMsg[KTgMAX_MSG]; // //static C_TgUINT32 s_nuiTest_Cat = 0, s_nuiTest = 29; //static TgUINT32 s_uiTest_Cat = 13, s_uiTest = 0; //static TgF4CYLINDER s_tgCY0, s_tgCY1; // // //TgVOID Unit_Test_Collision_Cylinder() //{ // TgF34MATRIX tmM0, tmM1, tmM2; // // MATH::F34_EUL( &tmM0, 0.0F, 0.0F, 0.0F ); // MATH::F34_EUL( &tmM2, 0.0F, 0.0F, 0.2F ); // MATH::F34_EUL( &tmM1, 0.0F, 0.0F, 0.4F ); // // if (0 == s_uiTest_Cat) // { // static C_TgFLOAT32 fStart_Time = P::TIME::Query_Time(); // C_TgFLOAT32 fTime = P::TIME::Query_Time() - fStart_Time; // C_TgFLOAT32 fA = TGS::KF32_TWO_PI*0.1F*fTime; // C_TgFLOAT32 fH = -2.6F + 0.1F*P::FLOOR( 0.1F*fTime); // // TGS::COL::s_tgCY0.Set( tmM0, 5.0, 2.5 ); // TGS::COL::s_tgCY1.Set( tmM0, 4.0, 7.5 ); // TGS::COL::s_tgCY1.Set_Origin( MATH::F4_SET4(6.5F*TGS::P::COS(fA), fH, 6.5F*TGS::P::SIN(fA), 1.0F)); // } // else if (10 == s_uiTest_Cat) // { // switch (s_uiTest) // { // // Parallel Axis - Nested // case 0: // s_tgCY0.Set( tmM0, 5.0F, 2.5F ); // s_tgCY1.Set( tmM0, 4.0F, 7.5F ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 0.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 0 nested in Object 1, Origin Differential on Axis - Cylinder 0") ); // return; // case 1: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 0.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 1 nested in Object 0, Origin Differential on Axis - Cylinder 1") ); // return; // // // Non Parallel Axis - Nested // case 2: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM1, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 0.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 0 nested in Object 1, Origin Differential on Axis - Cylinder 0") ); // return; // case 3: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM1, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 0.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 1 nested in Object 0, Origin Differential on Axis - Cylinder 1") ); // return; // // default: // s_uiTest = 0; // return; // }; // } // else if (11 == s_uiTest_Cat) // { // switch (s_uiTest) // { // // Parallel Axis - Tangent and near-Tangential Cases // case 0: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 5.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 1: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 5.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 2: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 10.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 3: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 10.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 4: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 5.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 5: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 5.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 6: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 9.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 7: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 9.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 8: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 4.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 9: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 4.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 10: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 10.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 11: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 10.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // // Parallel Axis - Radial Cut // case 12: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 6.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Radial Cut, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 13: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 6.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Radial Cut, Origin on co-planar - Cylinder 1 Axial") ); // return; // // default: // s_uiTest = 0; // return; // }; // } // else if (12 == s_uiTest_Cat) // { // switch (s_uiTest) // { // // Parallel Axis - Tangent and near-Tangential Cases // case 0: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 5.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 1: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 5.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 2: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 10.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 3: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 10.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 4: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 5.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 5: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 5.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 6: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 9.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 7: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 9.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 8: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 4.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 9: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 4.9F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // case 10: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 10.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 11: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 10.1F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Tangential, Origin on co-planar - Cylinder 1 Axial") ); // break; // // // Parallel Axis - Radial Cut // case 12: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 6.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Radial Cut, Origin on co-planar - Cylinder 0 Axial") ); // break; // case 13: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 6.0F, 0.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, TgT("Parallel Axis - Radial Cut, Origin on co-planar - Cylinder 1 Axial") ); // break; // // default: // s_uiTest = 0; // break; // }; // } // else if (13 == s_uiTest_Cat) // { // switch (s_uiTest) // { // // Parallel Axis - Nested // case 0: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM0, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 7.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 0 nested in Object 1, Origin Differential on Axis - Axis is Cylinder 0") ); // return; // case 1: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM0, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 7.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 1 nested in Object 0, Origin Differential on Axis - Axis is Cylinder 1") ); // return; // // // Non Parallel Axis - Nested // case 2: // s_tgCY0.Set( tmM0, 5.0, 2.5 ); // s_tgCY1.Set( tmM2, 4.0, 7.5 ); // s_tgCY1.Set_Origin( MATH::F4_SET4( 7.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 0 nested in Object 1, Origin Differential on Axis - Axis is Cylinder 0") ); // return; // case 3: // s_tgCY1.Set( tmM0, 5.0, 2.5 ); // s_tgCY0.Set( tmM2, 4.0, 7.5 ); // s_tgCY0.Set_Origin( MATH::F4_SET4( 7.0F, -7.0F, 0.0F, 1.0F ) ); // STRING::Copy( g_szMsg, KTgMAX_MSG, // TgT("Parallel Axis - Object 1 nested in Object 0, Origin Differential on Axis - Axis is Cylinder 1") ); // return; // // default: // s_uiTest = 0; // return; // }; // }; //}; // ============================================================================================================================== // }; // END COL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; // END TGS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////