Thread: Comparing Matrices (D3D9)

  1. #1
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002

    Comparing Matrices (D3D9)

    hey, just a stupid question, im new to D3D, previously just ben coding 2D games using Dx7 and the GDI but i decided id make the change to 3D, im reading through a D3D book and im at the part of handling transformations and translations allowing roatation and movement of primitives using matrices. now logicaly i thought, hey if matrices hold position data then surely comparing matrices could tell me if two primitives are coliding or not, so i skimmed the book looking to see if it had any info on collision and to my annoyance not a thing on collision detection in the whole book..
    can any 1 point me in the right direction?
    You can stop change as easily as u can drink the sea with a fork

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Collision detection actually has nothing at all to do with matrices in regards to meshes. All you do is make bounding spheres/boxes around the meshes you want to check and use a simple geometry formula to calculate if the spheres or boxes collide. Here's a basic sphere collision detection function written in C++:

    BOOL CheckSphereCollision( float XCenter1, float YCenter1, float ZCenter1, float Radius1,
                                                  float XCenter2, float YCenter2, float ZCenter2, float Radius2 )
        float XDifference, YDifference, ZDifference, Distance;
        XDifference  =  (float)fabs(XCenter2 - XCenter1);
        YDifference  =  (float)fabs(YCenter2 - YCenter1);
        ZDifference  =  (float)fabs(ZCenter2 - ZCenter1);
        Distance  =  (float)sqrt(XDifference*XDifference+YDifference*YDifference+ZDifference*ZDifference);
        if( Distance <=  (Radius1+Radius2))
            return TRUE;  //  INTERSECTION HAPPENED
        return FALSE;  // NO INTERSECTION
    Conclusion: is packed and packed full of information about everything. Use it to your advantage.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:

  3. #3
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    wow didnt think it'd be as simple, and i guess for some more complex objects u can use multiple spheres / boxes and do a collision check for each one, btw that code u posted is interesting, im used to doing inequality checks (with 2D) without mathematical computation so my collision sub in 2D is normaly more hectic than that, thanks it helped alot
    You can stop change as easily as u can drink the sea with a fork

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C simple Matrices
    By Cyberman86 in forum C Programming
    Replies: 3
    Last Post: 05-07-2009, 05:20 PM
  2. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  3. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  4. comparing two matrices or double values
    By collymitch in forum C Programming
    Replies: 4
    Last Post: 04-17-2005, 08:16 AM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM