xbdev - software development
Friday February 23, 2024
home | contact | Support


The Maths of 3D

You can't have 3D without a little maths...


Collision Reaction

by bkenwright@xbdev.net



So you know you have a collision!...and you also know which triangle it is that your colliding with...so what do you do?  Well let me take you through a few possible sollutions.


<1> Stop

Upon colliding with the object, just have the character stop!...simple but effective.


<2> Slide in the triangles parallel plane.








//                                                                    //

//                       Collision Reaction                           //

//                                                                    //



D3DXVECTOR3 GetNormal( D3DXVECTOR3 vTriangle[] )


      D3DXVECTOR3 vA = D3DXVECTOR3(p1[0],p1[1],p1[2]);

      D3DXVECTOR3 vB = D3DXVECTOR3(p2[0],p2[1],p2[2]);

      D3DXVECTOR3 vC = D3DXVECTOR3(p3[0],p3[1],p3[2]);


      D3DXVECTOR3 v1, v2;

      v1 = vB-vA;

      v2 = vC-vA;


      D3DXVECTOR3 vN;

      D3DXVec3Cross(&vN, &v1, &v2);


      D3DXVec3Normalize(&vN, &vN);


      return vN;



D3DXVECTOR3 CollisionReaction( D3DXVECTOR3 vDirection, D3DXVECTOR3 vTriangle[] )


      D3DXVECTOR3 vNormal = GetNormal( vTriangle );


      D3DXVec3Normalize(&vDirection, &vDirection);


      float f = D3DXVec3Dot( &vNormal, &vDirection );


      D3DXVECTOR3 vUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);


      D3DXVECTOR3 vWallDirection;

      D3DXVec3Cross(&vWallDirection, &vNormal, &vUp);


      D3DXVec3Normalize(&vWallDirection, &vWallDirection);


      float fSpeed = 1.0f;


      D3DXVECTOR3 vNewDir = fSpeed * f * vWallDirection;


      return vNewDir;


Advert (Support Website)

Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.