ODEPlaneShape.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 #ifndef ODEPLANESHAPE_HH 00018 #define ODEPLANESHAPE_HH 00019 00020 #include "physics/PlaneShape.hh" 00021 #include "physics/ode/ODEPhysics.hh" 00022 00023 namespace gazebo 00024 { 00025 namespace physics 00026 { 00029 00032 00034 class ODEPlaneShape : public PlaneShape 00035 { 00036 public: ODEPlaneShape(CollisionPtr parent) : PlaneShape(parent) {} 00037 public: virtual ~ODEPlaneShape() {} 00038 00040 public: void CreatePlane() 00041 { 00042 PlaneShape::CreatePlane(); 00043 ODECollisionPtr oParent; 00044 oParent = 00045 boost::shared_dynamic_cast<ODECollision>(this->collisionParent); 00046 00047 double altitude = 0; 00048 00049 math::Vector3 n = this->GetNormal(); 00050 if (oParent->GetCollisionId() == NULL) 00051 oParent->SetCollision(dCreatePlane(oParent->GetSpaceId(), 00052 n.x, n.y, n.z, altitude), false); 00053 else 00054 dGeomPlaneSetParams(oParent->GetCollisionId(), 00055 n.x, n.y, n.z, altitude); 00056 } 00057 00059 public: void SetAltitude(const math::Vector3 &pos) 00060 { 00061 PlaneShape::SetAltitude(pos); 00062 ODECollisionPtr odeParent; 00063 odeParent = boost::shared_dynamic_cast<ODECollision>(this->collisionParent); 00064 00065 dVector4 vec4; 00066 00067 dGeomPlaneGetParams(odeParent->GetCollisionId(), vec4); 00068 00069 // Compute "altitude": scalar product of position and normal 00070 vec4[3] = vec4[0] * pos.x + vec4[1] * pos.y + vec4[2] * pos.z; 00071 00072 dGeomPlaneSetParams(odeParent->GetCollisionId(), vec4[0], vec4[1], 00073 vec4[2], vec4[3]); 00074 } 00075 }; 00078 } 00079 } 00080 #endif

1.7.5.1