~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srBody/kitBody1.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/kitBody1.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
  KITBody1::KITBody1(   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("KITBody1", 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/KITcollBody.3ds", SimulationUtils::getStageProjectPath().c_str());
 
52
                          else
 
53
                            sprintf(file, "%s/StaticMeshes/KITcollBody1.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,COLLISION_SIDE*25));
 
58
                          
 
59
//                        printf ("done \n");
 
60
                          
 
61
                          // scaling the model
 
62
                          this->setScale(SCALE_3DS,SCALE_3DS,SCALE_3DS);
 
63
                          // defining the collision box
 
64
                          this->setCollisionBox(COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
 
65
                          
 
66
                          // our Object just needs a mass now ...
 
67
                          this->setMass(BODY_MASS, COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
 
68
                          
 
69
                          this->GetOSGNode()->setNodeMask(SimulationUtils::geometryDetailsNodeMask);
 
70
                          
 
71
                          dtCore::Object* collModel = new dtCore::Object();
 
72
                          dtCore::Transform xform;
 
73
                          
 
74
                          switch (SimulationUtils::getCollisionGeometryDetails()) {
 
75
                            
 
76
                            case 0: //sprintf(file, "%s/StaticMeshes/KITcollBodySquare1.3ds",   SimulationUtils::getStageProjectPath().c_str()); break;
 
77
                            case 1: //sprintf(file, "%s/StaticMeshes/KITcollBodyPolygone1.3ds", SimulationUtils::getStageProjectPath().c_str()); break;
 
78
                            case 2: sprintf(file, "%s/StaticMeshes/KITcollBody.3ds",    SimulationUtils::getStageProjectPath().c_str()); break;
 
79
                            case 15: sprintf(file, "%s/StaticMeshes/newKITBody1.3ds",   SimulationUtils::getStageProjectPath().c_str()); break;
 
80
                            
 
81
                          }
 
82
                          
 
83
                          collModel->LoadFile(file);
 
84
                         
 
85
                          
 
86
                          collModel->SetScale(osg::Vec3(0.021,0.021,0.021));//this->GetScale());
 
87
                          
 
88
                          osg::StateSet* stateset;
 
89
                          collModel->GetOSGNode()->setNodeMask(SimulationUtils::collisionNodeMask);
 
90
                          stateset = collModel->GetOSGNode()->getOrCreateStateSet();
 
91
                          osg::Material * mm = dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
 
92
                          if (!mm)
 
93
                          {
 
94
                            mm = new osg::Material;
 
95
                          }
 
96
                          mm->setAlpha(osg::Material::FRONT, 0.2);
 
97
                          mm->setAmbient(osg::Material::FRONT, osg::Vec4(0,0,0,0));
 
98
                          stateset->setAttributeAndModes( mm, osg::StateAttribute::OVERRIDE |
 
99
                          osg::StateAttribute::ON);
 
100
                          stateset->setMode(GL_BLEND,   osg::StateAttribute::OVERRIDE |
 
101
                          osg::StateAttribute::ON );
 
102
                          stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE |
 
103
                          osg::StateAttribute::ON );
 
104
                          stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
 
105
                          
 
106
                          
 
107
                          
 
108
                          this->renderCollisionGeometry(true);
 
109
                          
 
110
                          this->SetCollisionMesh(collModel->GetOSGNode());
 
111
                          
 
112
                          this->AddChild(collModel);
 
113
                          
 
114
                          this->setCollisionModel(collModel->GetOSGNode());
 
115
                          
 
116
                          
 
117
                          // to check if the collision geometry fits to the model:
 
118
                          // this->renderCollisionGeometry();
 
119
                          
 
120
                          // ... and then, it is ready to place it in the scene
 
121
                          this->addToScene();
 
122
                          
 
123
                        }
 
124
                        
 
125
                        
 
126
                        KITBody1::~KITBody1()
 
127
                        {
 
128
                        }
 
129
                        
 
130
}