ODEPlaneShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
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 GAZEBO_PHYSICS_ODE_ODEPLANESHAPE_HH_
18 #define GAZEBO_PHYSICS_ODE_ODEPLANESHAPE_HH_
19 
22 #include "gazebo/util/system.hh"
23 
24 namespace gazebo
25 {
26  namespace physics
27  {
30 
32  class GZ_PHYSICS_VISIBLE ODEPlaneShape : public PlaneShape
33  {
36  public: explicit ODEPlaneShape(CollisionPtr _parent)
37  : PlaneShape(_parent) {}
38 
40  public: virtual ~ODEPlaneShape() {}
41 
42  // Documentation inherited
43  public: virtual void CreatePlane()
44  {
46  ODECollisionPtr oParent;
47  oParent =
48  boost::dynamic_pointer_cast<ODECollision>(this->collisionParent);
49  ignition::math::Pose3d pose = oParent->WorldPose();
50  double altitude = pose.Pos().Z();
51  ignition::math::Vector3d n = this->Normal();
52  if (oParent->GetCollisionId() == nullptr)
53  oParent->SetCollision(dCreatePlane(oParent->GetSpaceId(),
54  n.X(), n.Y(), n.Z(), altitude), false);
55  else
56  dGeomPlaneSetParams(oParent->GetCollisionId(),
57  n.X(), n.Y(), n.Z(), altitude);
58  }
59 
60  // Documentation inherited
61  public: virtual void SetAltitude(const ignition::math::Vector3d &_pos)
62  {
64  ODECollisionPtr odeParent;
65  odeParent =
66  boost::dynamic_pointer_cast<ODECollision>(this->collisionParent);
67 
68  dVector4 vec4;
69 
70  dGeomPlaneGetParams(odeParent->GetCollisionId(), vec4);
71 
72  // Compute "altitude": scalar product of position and normal
73  vec4[3] = vec4[0] * _pos.X() + vec4[1] * _pos.Y() + vec4[2] * _pos.Z();
74 
75  dGeomPlaneSetParams(odeParent->GetCollisionId(), vec4[0], vec4[1],
76  vec4[2], vec4[3]);
77  }
78  };
80  }
81 }
82 #endif
Base class for all ODE collisions.
Definition: ODECollision.hh:40
boost::shared_ptr< ODECollision > ODECollisionPtr
Definition: ODETypes.hh:39
virtual void CreatePlane()
Create the plane.
virtual void SetAltitude(const ignition::math::Vector3d &_pos)
Set the altitude of the plane.
ODEPlaneShape(CollisionPtr _parent)
Constructor.
Definition: ODEPlaneShape.hh:36
An ODE Plane shape.
Definition: ODEPlaneShape.hh:32
virtual void CreatePlane()
Create the plane.
Definition: ODEPlaneShape.hh:43
virtual const ignition::math::Pose3d & WorldPose() const
Get the absolute pose of the entity.
virtual ~ODEPlaneShape()
Destructor.
Definition: ODEPlaneShape.hh:40
virtual void SetAltitude(const ignition::math::Vector3d &_pos)
Set the altitude of the plane.
Definition: ODEPlaneShape.hh:61
Collision for an infinite plane.
Definition: PlaneShape.hh:37
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113