All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ODEPlaneShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _ODEPLANESHAPE_HH_
18 #define _ODEPLANESHAPE_HH_
19 
20 #include "physics/PlaneShape.hh"
22 
23 namespace gazebo
24 {
25  namespace physics
26  {
30 
32  class ODEPlaneShape : public PlaneShape
33  {
35  public: ODEPlaneShape(CollisionPtr _parent) : PlaneShape(_parent) {}
36 
38  public: virtual ~ODEPlaneShape() {}
39 
41  public: void CreatePlane()
42  {
44  ODECollisionPtr oParent;
45  oParent =
46  boost::shared_dynamic_cast<ODECollision>(this->collisionParent);
47 
48  double altitude = 0;
49 
50  math::Vector3 n = this->GetNormal();
51  if (oParent->GetCollisionId() == NULL)
52  oParent->SetCollision(dCreatePlane(oParent->GetSpaceId(),
53  n.x, n.y, n.z, altitude), false);
54  else
55  dGeomPlaneSetParams(oParent->GetCollisionId(),
56  n.x, n.y, n.z, altitude);
57  }
58 
60  public: void SetAltitude(const math::Vector3 &pos)
61  {
63  ODECollisionPtr odeParent;
64  odeParent =
65  boost::shared_dynamic_cast<ODECollision>(this->collisionParent);
66 
67  dVector4 vec4;
68 
69  dGeomPlaneGetParams(odeParent->GetCollisionId(), vec4);
70 
71  // Compute "altitude": scalar product of position and normal
72  vec4[3] = vec4[0] * pos.x + vec4[1] * pos.y + vec4[2] * pos.z;
73 
74  dGeomPlaneSetParams(odeParent->GetCollisionId(), vec4[0], vec4[1],
75  vec4[2], vec4[3]);
76  }
77  };
79  }
80 }
81 #endif
82 
83 
84 
85 
86 
87