NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPlaneGround.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
27 //This Module
28 #include "tgPlaneGround.h"
29 
30 //Bullet Physics
31 #include "BulletCollision/CollisionShapes/btBoxShape.h"
32 #include "BulletDynamics/Dynamics/btRigidBody.h"
33 #include "LinearMath/btDefaultMotionState.h"
34 #include "LinearMath/btTransform.h"
35 
36 // The C++ Standard Library
37 #include <cassert>
38 
39 tgPlaneGround::Config::Config( btVector3 normalVector,
40  btScalar friction,
41  btScalar restitution,
42  btVector3 origin) :
43 m_normalVector(normalVector),
44 m_friction(friction),
45 m_restitution(restitution),
46 m_origin(origin)
47 {
48  assert((m_friction >= 0.0) && (m_friction <= 1.0));
49  assert((m_restitution >= 0.0) && (m_restitution <= 1.0));
50 }
51 
53 m_config(Config())
54 {
55  // @todo make constructor aux to avoid repeated code
56  pGroundShape = new btStaticPlaneShape(m_config.m_normalVector,0);
57 
58 }
59 
61 m_config(config)
62 {
63  pGroundShape = new btStaticPlaneShape(m_config.m_normalVector,0);
64 }
65 
66 
68 {
69  btTransform groundTransform;
70  groundTransform.setIdentity();
71  groundTransform.setOrigin(m_config.m_origin);
72 
73  btQuaternion orientation;
74  orientation.setEuler(0,0,0);
75 // orientation.setEuler(m_config.m_eulerAngles[0], // Yaw
76 // m_config.m_eulerAngles[1], // Pitch
77 // m_config.m_eulerAngles[2]); // Roll
78  groundTransform.setRotation(orientation);
79 
80  // Using motionstate is recommended
81  // It provides interpolation capabilities, and only synchronizes 'active' objects
82  btDefaultMotionState* const pMotionState =
83  new btDefaultMotionState(groundTransform);
84 
85  const btVector3 localInertia(0, 0, 0);
86 
87 // btRigidBody::btRigidBodyConstructionInfo const rbInfo(mass, pMotionState, pGroundShape, localInertia);
88 
89  btRigidBody* const pGroundBody=new btRigidBody(0.0,pMotionState,pGroundShape,localInertia);
90  pGroundBody->setFriction(m_config.m_friction);
91  pGroundBody->setRestitution(m_config.m_restitution);
92 
93 // btRigidBody* const pGroundBody = new btRigidBody(rbInfo);
94 
95  return pGroundBody;
96 }
97 
Contains the definition of class tgPlaneGround.
virtual btRigidBody * getGroundRigidBody() const