~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srBody/kitScrew.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 front part of the robot.
 
6
 *
 
7
 * @author Lutz Winkler
 
8
 *
 
9
 */
 
10
 
 
11
#include <srBody/kitScrew.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.02
 
17
 
 
18
#define COLLISION_SIDE                  (64*SCALE_3DS)                                  //60            // cm
 
19
#define COLLISION_LENGTH                (64*SCALE_3DS)                                  //85
 
20
 
 
21
// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
 
22
#define BODY_LENGTH                     1.7                                     // equals 85 mm
 
23
#define BODY_HEIGHT                     1.2
 
24
#define BODY_WIDTH                      1.2
 
25
#define BODY_MASS                       0.3                                     //0.13
 
26
 
 
27
using namespace srCore;
 
28
 
 
29
//! Constructor
 
30
/*! @param id a 16bit id, used to set the colliding bit parameter.
 
31
 *      @param x, y, z the position of the hinge in the world coordinate system.
 
32
 *  @param heading, pitch, roll the orientation of the axis of the hinge in the world coordinate system.
 
33
 *  @param Scene the scene in which the body should be placed.
 
34
 *
 
35
 */
 
36
KITScrew::KITScrew(     RobotActorBase* robot,
 
37
                        float x, float y, float z,
 
38
                        float heading, float pitch, float roll)
 
39
 
 
40
{
 
41
 
 
42
        // initializing. parameters: name, id (of the robot), position, orientation and the scene
 
43
        // needs to be done first
 
44
        // todo: at the moment scene needs to be given to each element, although we only have one scene
 
45
        this->init("KITScrew", robot, x, y, z, heading, pitch, roll);
 
46
 
 
47
        // loading 3ds model
 
48
        char file[250];
 
49
 
 
50
        if (SimulationUtils::getDetailedGraphics())
 
51
                sprintf(file, "%s/StaticMeshes/newKITScrew.3ds", SimulationUtils::getStageProjectPath().c_str());
 
52
        else
 
53
                sprintf(file, "%s/StaticMeshes/symbrionDummy.3ds", SimulationUtils::getStageProjectPath().c_str());  //use this model in case of a bad graphics card
 
54
 
 
55
        printf ("loading file %s ...\n", file);
 
56
        LoadFile(file);
 
57
        SetModelTranslation(osg::Vec3(0,0,0));
 
58
 
 
59
        printf ("done \n");
 
60
 
 
61
        // scaling the model
 
62
        this->setScale(SCALE_3DS,SCALE_3DS,SCALE_3DS);
 
63
 
 
64
        // defining the collision box
 
65
        this->setCollisionBox(COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
 
66
 
 
67
        // our Object just needs a mass now ...
 
68
        this->setMass(BODY_MASS, COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
 
69
 
 
70
        dtCore::Object* collModel = new dtCore::Object();
 
71
 
 
72
        dtCore::Transform xform;
 
73
        sprintf(file, "%s/StaticMeshes/screwCollModel.3ds",     SimulationUtils::getStageProjectPath().c_str());
 
74
 
 
75
        collModel->LoadFile(file);
 
76
        collModel->SetScale(this->GetScale());
 
77
        SetCollisionCategoryBits(UNSIGNED_BIT(2));
 
78
        SetCollisionCollideBits(UNSIGNED_BIT(1));                        
 
79
        SetCollisionMesh(collModel->GetOSGNode());
 
80
        
 
81
        osg::StateSet* stateset;
 
82
        stateset = collModel->GetOSGNode()->getOrCreateStateSet();
 
83
        osg::Material * mm = dynamic_cast<osg::Material*>(stateset->getAttribute
 
84
        (osg::StateAttribute::MATERIAL));
 
85
        if (!mm)
 
86
        {
 
87
          mm = new osg::Material;
 
88
        }
 
89
        mm->setAlpha(osg::Material::FRONT, 0.2);
 
90
        mm->setAmbient(osg::Material::FRONT, osg::Vec4(0,0,0,0));
 
91
        stateset->setAttributeAndModes( mm, osg::StateAttribute::OVERRIDE |
 
92
        osg::StateAttribute::ON);
 
93
        stateset->setMode(GL_BLEND,   osg::StateAttribute::OVERRIDE |
 
94
        osg::StateAttribute::ON );
 
95
        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE |
 
96
        osg::StateAttribute::ON );
 
97
        stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
 
98
        
 
99
        
 
100
        
 
101
        this->renderCollisionGeometry(false);
 
102
        
 
103
        this->SetCollisionMesh(collModel->GetOSGNode());
 
104
        
 
105
        this->AddChild(collModel);
 
106
        
 
107
        this->setCollisionModel(collModel->GetOSGNode());
 
108
  
 
109
        
 
110
 
 
111
        // to check if the collision geometry fits to the model:
 
112
        // this->renderCollisionGeometry();
 
113
 
 
114
        // ... and then, it is ready to place it in the scene
 
115
        this->addToScene();
 
116
        
 
117
}
 
118
 
 
119
 
 
120
KITScrew::~KITScrew()
 
121
{
 
122
}
 
123
 
 
124
}