Comparing Matrices (D3D9)

This is a discussion on Comparing Matrices (D3D9) within the Game Programming forums, part of the General Programming Boards category; hey, just a stupid question, im new to D3D, previously just ben coding 2D games using Dx7 and the GDI ...

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

    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?
    thanx
    You can stop change as easily as u can drink the sea with a fork

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    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++:

    Code:
    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: Google.com 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:
    sadf 

  3. #3
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    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, 06: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, 09:21 AM
  4. comparing two matrices or double values
    By collymitch in forum C Programming
    Replies: 4
    Last Post: 04-17-2005, 09:16 AM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21