~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srBody/wheel.cpp

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//! Specialized body class.
 
2
 
 
3
/*!
 
4
 * Predefined body class. Ready to use in a RobotActor.
 
5
 * This body represents the wheels of the robot.
 
6
 *
 
7
 * @author Lutz Winkler
 
8
 *
 
9
 */
 
10
 
 
11
#include <srBody/wheel.h>
 
12
 
 
13
namespace srCore {
 
14
 
 
15
// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
 
16
#define SCALE_3DS                       0.2                             //0.2
 
17
#define WHEEL_SIZE                      SCALE_3DS
 
18
#define WHEEL_MASS                      0.01
 
19
#define WHEEL_RADIUS                    0.5 * SCALE_3DS //4.5
 
20
#define WHEEL_LENGTH                    1 * SCALE_3DS   //2
 
21
 
 
22
using namespace srCore;
 
23
 
 
24
//! Constructor
 
25
/*! @param id a 16bit id, used to set the colliding bit parameter.
 
26
 *      @param x, y, z the position of the hinge in the world coordinate system.
 
27
 *  @param heading, pitch, roll the orientation of the axis of the hinge in the world coordinate system.
 
28
 *  @param Scene the scene in which the body should be placed.
 
29
 *
 
30
 */
 
31
Wheel::Wheel(   RobotActorBase* robot,
 
32
                                float x, float y, float z,
 
33
                                float heading, float pitch, float roll)
 
34
 
 
35
 
 
36
 
 
37
 
 
38
{
 
39
 
 
40
        // initializing. parameters: name, id (of the robot), position, orientation and the scene
 
41
        // needs to be done first
 
42
        this->init("wheel", robot, x, y, z, heading, pitch, roll);
 
43
 
 
44
        // loading 3ds model
 
45
        char file[50];
 
46
 
 
47
        sprintf(file, "%s/StaticMeshes/wheel.3ds", SimulationUtils::getStageProjectPath().c_str());
 
48
        //sprintf(file, "%s/StaticMeshes/barrel.ive", SimulationUtils::getStageProjectPath().c_str());
 
49
 
 
50
        LoadFile(file, false);
 
51
 
 
52
        // scaling the model
 
53
        SetScale(osg::Vec3(WHEEL_SIZE, WHEEL_SIZE, WHEEL_SIZE));
 
54
 
 
55
 
 
56
        // our Object just needs a mass now ...
 
57
        this->setMass(WHEEL_MASS, WHEEL_RADIUS, WHEEL_LENGTH);
 
58
 
 
59
        // defining the collision box
 
60
        this->setCollisionCylinder(WHEEL_RADIUS, WHEEL_LENGTH);
 
61
 
 
62
        // ... and then, it is ready to place it in the scene
 
63
        this->addToScene();
 
64
 
 
65
        // to check if the collision geometry fits to the model:
 
66
        this->renderCollisionGeometry(true);
 
67
        this->colorCollisionShape(osg::Vec4(255,0,0,0));
 
68
//      this->colorBody(osg::Vec4(1,0,0,0));
 
69
 
 
70
        // need to be set to let the wheels rotate
 
71
    dBodySetFiniteRotationMode(GetBodyID(), 1);
 
72
 
 
73
    setCollisionBits(2);
 
74
}
 
75
 
 
76
Wheel::~Wheel()
 
77
{
 
78
}
 
79
 
 
80
}