- Main Page
- Classes
- Files

- Search for |

# CollisionGroup.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      CollisionGroup.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    00021 ***************************/
    00022
    00025
    00026 #ifndef CollisionGroup_H
    00027 #define CollisionGroup_H
    00028
    00029
    00030 #include "H3DNetworkingUtils/Config.h"
    00031 #include <H3D/X3DChildNode.h>
    00032 #include <H3D/Node.h>
    00033 #include <H3D/MFString.h>
    00034 #include "H3DNetworkingUtils/CollisionGeometry.h"
    00035 #include "H3DNetworkingUtils/CollisionSphere.h"
    00036 #include "H3DNetworkingUtils/CollisionSphereHierarchy.h"
    00037 //#include "CollidableLine.h"
    00038
    00039 namespace H3DNetworkingUtils {
    00040
    00062
    00063 class H3D_NETWORKING_UTILS_DLL_SPEC CollisionGroup : public H3D::X3DChildNode {
    00064
    00065 public:
    00066
    00067    typedef H3D::TypedMFNode<H3D::X3DChildNode> MFChild;
    00068
    00069    CollisionGroup();
    00070   static H3D::H3DNodeDatabase database;
    00071
    00076   auto_ptr<MFChild> collidingChildrenA;
    00077
    00082   auto_ptr<MFChild> collidingChildrenB;
    00083
    00088   auto_ptr<H3D::MFString> userMsg;
    00089
    00090   virtual void traverseSG(H3D::TraverseInfo & ti);
    00091
    00092 protected:
    00093    static int lineSphereIntersection( const H3D::Vec3f &lineOrigin,
    00094              const H3D::Vec3f &lineGradient,
    00095              const H3D::Vec3f &sphereCentre,
    00096              H3D::H3DFloat sphereRadius,
    00097              H3D::Vec3f &soln1,
    00098              H3D::Vec3f &soln2 );
    00099
    00100
    00101   void detectCollision( H3D::X3DChildNode*, H3D::X3DChildNode* );
    00102   // performs collisions between a chain and a dynamic
    00103
    00104   void detectCollision( CollidableDynamic*, CollidableDynamic* );
    00105   // performs collisions between two CollidableDynamics
    00106
    00107   void detectCollision( CollisionGeometry*, CollidableDynamic* );
    00108   void detectCollision( CollidableDynamic*, CollisionGeometry* );
    00109
    00110   // performs collisions between two geometries
    00111   void detectCollision( CollisionGeometry*, CollisionGeometry* );
    00112   void detectCollision( CollisionSphere*, CollisionSphere* );
    00113   void detectCollision( CollisionSphere*, CollisionSphereHierarchy* );
    00114   void detectCollision( CollisionSphereHierarchy*, CollisionSphere* );
    00115   void detectCollision( CollisionSphereHierarchy*,
    00116       CollisionSphereHierarchy* );
    00117
    00118
    00119   // checkIntersection is an overloaded function which checks for
    00120   // intersections between two geometries.
    00121   bool checkIntersection( CollisionSphere*, CollisionSphere*, H3D::Vec3f & penetration_dir,
    00122      H3D::H3DFloat & penetration_mag, H3D::Vec3f & global_contact_point );
    00123
    00124    virtual void doFirstCollideMessage(CollidableDynamic * coll_A, CollidableDynamic * coll_B,
    00125                                       const H3D::Vec3f & penetration_vec);
    00126    // Provide a mesage describing how to moigve objects so that they won't start in a collision state.
    00127
    00128 private:
    00129   bool first_collide;
    00130   int check_seg_num;
    00131   bool collision_found;
    00132 };
    00133
    00134
    00135 inline H3D::Rotation inverse( const H3D::Rotation &rot )
    00136 {
    00137   return H3D::Rotation( rot.axis, -rot.angle );
    00138 }
    00139
    00140 inline H3D::Matrix3f transpose( H3D::Matrix3f mat )
    00141 {
    00142   H3D::Matrix3f ret;
    00143   int i;
    00144   int j;
    00145
    00146   for ( i = 0; i < 3; i ++ ) {
    00147     for ( j = 0; j < 3; j ++ ) {
    00148       ret[i][j] = mat[j][i];
    00149     }
    00150   }
    00151
    00152   return ret;
    00153 }
    00154
    00155 }
    00156
    00157 #endif