00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU Lesser General Public License as published by * 00007 * the Free Software Foundation; either version 2.1 of the License, or (at * 00008 * your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00013 * for more details. * 00014 * * 00015 * You should have received a copy of the GNU Lesser General Public License * 00016 * along with this library; if not, write to the Free Software Foundation, * 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00018 ******************************************************************************* 00019 * SOFA :: Modules * 00020 * * 00021 * Authors: The SOFA Team and external contributors (see Authors.txt) * 00022 * * 00023 * Contact information: contact@sofa-framework.org * 00024 ******************************************************************************/ 00025 #ifndef SOFA_COMPONENT_COLLISION_RAYCONTACT_H 00026 #define SOFA_COMPONENT_COLLISION_RAYCONTACT_H 00027 00028 #include <sofa/core/componentmodel/collision/Contact.h> 00029 #include <sofa/helper/Factory.h> 00030 00031 namespace sofa 00032 { 00033 00034 namespace component 00035 { 00036 00037 namespace collision 00038 { 00039 00040 using namespace sofa::defaulttype; 00041 00042 class RayModel; 00043 00044 class BaseRayContact : public core::componentmodel::collision::Contact 00045 { 00046 public: 00047 typedef RayModel CollisionModel1; 00048 00049 protected: 00050 CollisionModel1* model1; 00051 sofa::helper::vector<core::componentmodel::collision::DetectionOutput*> collisions; 00052 00053 public: 00054 BaseRayContact(CollisionModel1* model1, core::componentmodel::collision::Intersection* instersectionMethod); 00055 00056 ~BaseRayContact(); 00057 00058 const sofa::helper::vector<core::componentmodel::collision::DetectionOutput*>& getDetectionOutputs() const { return collisions; } 00059 00060 void createResponse(core::objectmodel::BaseContext* /*group*/) 00061 { 00062 } 00063 00064 void removeResponse() 00065 { 00066 } 00067 }; 00068 00069 template<class CM2> 00070 class RayContact : public BaseRayContact 00071 { 00072 public: 00073 typedef RayModel CollisionModel1; 00074 typedef CM2 CollisionModel2; 00075 typedef core::componentmodel::collision::Intersection Intersection; 00076 typedef core::componentmodel::collision::TDetectionOutputVector<CollisionModel1, CollisionModel2> OutputVector; 00077 protected: 00078 CollisionModel2* model2; 00079 core::objectmodel::BaseContext* parent; 00080 public: 00081 RayContact(CollisionModel1* model1, CollisionModel2* model2, Intersection* intersectionMethod) 00082 : BaseRayContact(model1, intersectionMethod), model2(model2) 00083 { 00084 } 00085 00086 void setDetectionOutputs(core::componentmodel::collision::DetectionOutputVector* outputs) 00087 { 00088 OutputVector* o = static_cast<OutputVector*>(outputs); 00089 //collisions = outputs; 00090 collisions.resize(o->size()); 00091 for (unsigned int i=0; i< o->size(); ++i) 00092 collisions[i] = &(*o)[i]; 00093 } 00094 00095 std::pair<core::CollisionModel*,core::CollisionModel*> getCollisionModels() { return std::make_pair(model1,model2); } 00096 }; 00097 00098 } // namespace collision 00099 00100 } // namespace component 00101 00102 } // namespace sofa 00103 00104 #endif
1.5.7.1