random_racer/src/BuggyFunCar.cpp

Go to the documentation of this file.
00001 #include "ResourceManager.h"
00002 #include "BuggyFunCar.h"
00003 #include "random_utils/LogManager.h"
00004 #include "vrsode/PhysicsManager.h"
00005 #include "vrsode/CylinderShape.h"
00006 #include "vrsode/SphereShape.h"
00007 
00008 #include <vrs/box.h>
00009 #include <vrs/color.h>
00010 #include <vrs/torus.h>
00011 #include <vrs/vector.h>
00012 #include <vrs/scaling.h>
00013 #include <vrs/opengl/shapematerialgl.h>
00014 #include <vrs/translation.h>
00015 #include <vrs/io/threedsreader.h>
00016 
00017 
00018 using namespace vrsode;
00019 
00020 namespace random_racer
00021 {
00022 
00023 BuggyFunCar::BuggyFunCar(VRS::SO<VRS::SceneThing> p_parent) : Car(p_parent)
00024 {
00025     m_springLengthFront = 0.2;
00026     m_springLengthRear = 0.2;
00027     m_springPowerFront = 31;
00028     m_springPowerRear = 27;
00029     m_springSpeedFront = 1.4;
00030     m_springSpeedRear = 1.4;
00031     m_wheelSizeFront = 0.3;
00032     m_wheelSizeRear = 0.4;
00033     m_wheelMass = 0.01;
00034     m_bodyMass = 8.0;
00035     m_debugNodes = false;
00036     m_wheelMu = dInfinity;
00037 
00038     m_carMaxSpeed = 30;
00039     m_carPower = 35;
00040 
00041     m_chassisOffset         = VRS::Vector( -0.55, 1.2,  0.0);
00042 
00043     m_wheelOffsetFL         = VRS::Vector( 2.45, 1.0, -1.5);
00044     m_wheelOffsetFR         = VRS::Vector( 2.45, 1.0,  1.5);
00045     m_wheelOffsetRL         = VRS::Vector(-2.1, 1.0, -1.8);
00046     m_wheelOffsetRR         = VRS::Vector(-2.1, 1.0,  1.8);
00047 
00048     m_suspensionOffsetFL    = VRS::Vector( 2.1, 1.0, -0.5);
00049     m_suspensionOffsetFR    = VRS::Vector( 2.1, 1.0,  0.5);
00050     m_suspensionOffsetRL    = VRS::Vector(-2.1, 1.0, -0.5);
00051     m_suspensionOffsetRR    = VRS::Vector(-2.1, 1.0,  0.5);
00052 
00053     m_steerOffsetFL         = VRS::Vector( 2.3, 1.0, -0.5);
00054     m_steerOffsetFR         = VRS::Vector( 2.3, 1.0,  0.5);
00055 
00056 
00057     // Load the 3DS model
00058     VRS::SO<VRS::SceneThing> tmp;
00059     VRS::SO<VRS::SceneThing> modelRootThing =
00060             ResourceManager::get()->load3ds("model/model.3ds");
00061 
00062     if(!modelRootThing)
00063         std::cerr << "ERROR: cannot load mesh" << std::endl;
00064 
00065     VRS::SO<VRS::SceneThing> body;
00066     
00067     VRS::SO<VRS::SceneThing> radLV;
00068     VRS::SO<VRS::SceneThing> radRV;
00069     VRS::SO<VRS::SceneThing> radLH;
00070     VRS::SO<VRS::SceneThing> radRH;
00071     
00072     VRS::SO<VRS::SceneThing> federLV;
00073     VRS::SO<VRS::SceneThing> federRV;
00074     VRS::SO<VRS::SceneThing> federLH;
00075     VRS::SO<VRS::SceneThing> federRH;
00076     
00077     VRS::SO<VRS::SceneThing> achseLV;
00078     VRS::SO<VRS::SceneThing> achseRV;
00079     VRS::SO<VRS::SceneThing> achseLH;
00080     VRS::SO<VRS::SceneThing> achseRH;
00081     
00082     VRS::SO<VRS::SceneThing> federInnenLV;
00083     VRS::SO<VRS::SceneThing> federInnenRV;
00084     VRS::SO<VRS::SceneThing> federInnenLH;
00085     VRS::SO<VRS::SceneThing> federInnenRH;
00086     
00087     
00088     // Restructure the SceneGraph
00089     // chassis
00090     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00091     tmp = (VRS::SceneThing*)tmp->object(9);
00092     tmp = (VRS::SceneThing*)tmp->object(1);
00093     body = tmp;
00094     
00095     // wheels
00096     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00097     tmp = (VRS::SceneThing*)tmp->object(6);
00098     tmp = (VRS::SceneThing*)tmp->object(2);
00099     radLH = tmp;
00100     
00101     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00102     tmp = (VRS::SceneThing*)tmp->object(7);
00103     tmp = (VRS::SceneThing*)tmp->object(2);
00104     radRV = tmp;
00105     
00106     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00107     tmp = (VRS::SceneThing*)tmp->object(8);
00108     tmp = (VRS::SceneThing*)tmp->object(2);
00109     radLV = tmp;
00110     
00111     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00112     tmp = (VRS::SceneThing*)tmp->object(5);
00113     tmp = (VRS::SceneThing*)tmp->object(2);
00114     tmp = (VRS::SceneThing*)tmp->object(2);
00115     tmp = (VRS::SceneThing*)tmp->object(2);
00116     radRH = tmp;
00117     
00118     // springs
00119     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00120     tmp = (VRS::SceneThing*)tmp->object(2);
00121     tmp = (VRS::SceneThing*)tmp->object(2);
00122     federLV = tmp;
00123     
00124     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00125     tmp = (VRS::SceneThing*)tmp->object(12);
00126     tmp = (VRS::SceneThing*)tmp->object(1);
00127     federRV = tmp;
00128     
00129     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00130     tmp = (VRS::SceneThing*)tmp->object(14);
00131     tmp = (VRS::SceneThing*)tmp->object(2);
00132     federLH = tmp;
00133     
00134     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00135     tmp = (VRS::SceneThing*)tmp->object(17);
00136     tmp = (VRS::SceneThing*)tmp->object(1);
00137     federRH = tmp;
00138     
00139     // axis
00140     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00141     tmp = (VRS::SceneThing*)tmp->object(4);
00142     tmp = (VRS::SceneThing*)tmp->object(2);
00143     achseLV = tmp;
00144     
00145     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00146     tmp = (VRS::SceneThing*)tmp->object(10);
00147     tmp = (VRS::SceneThing*)tmp->object(2);
00148     achseRV = tmp;
00149     
00150     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00151     tmp = (VRS::SceneThing*)tmp->object(13);
00152     tmp = (VRS::SceneThing*)tmp->object(2);
00153     achseRH = tmp;
00154     
00155     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00156     tmp = (VRS::SceneThing*)tmp->object(18);
00157     tmp = (VRS::SceneThing*)tmp->object(2);
00158     achseLH = tmp;
00159     
00160     // inside springs
00161     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00162     tmp = (VRS::SceneThing*)tmp->object(3);
00163     tmp = (VRS::SceneThing*)tmp->object(2);
00164     federInnenLV = tmp;
00165     
00166     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00167     tmp = (VRS::SceneThing*)tmp->object(11);
00168     tmp = (VRS::SceneThing*)tmp->object(1);
00169     federInnenRV = tmp;
00170     
00171     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00172     tmp = (VRS::SceneThing*)tmp->object(15);
00173     tmp = (VRS::SceneThing*)tmp->object(2);
00174     federInnenLH = tmp;
00175     
00176     tmp = (VRS::SceneThing*)modelRootThing->object(1);
00177     tmp = (VRS::SceneThing*)tmp->object(16);
00178     tmp = (VRS::SceneThing*)tmp->object(1);
00179     federInnenRH = tmp;
00180 
00181     m_rootNode = new VRS::SceneThing(p_parent);
00182     m_rootNode ->append(new VRS::ShapeMaterialGL(
00183             VRS::Color(0.1, 0.1, 0.1), VRS::Color(0.1, 0.1, 0.1)));
00184 
00185     VRS::SO<VRS::SceneThing> st;
00186 
00187     // chassis body
00188     st = new VRS::SceneThing(m_rootNode);
00189     m_chassis = new PhysicsBody(st, new SphereShape(VRS::Bounds(
00190             VRS::Vector(-0.2, -0.2, -0.2), VRS::Vector(0.2, 0.2, 0.2))), true);
00191     m_chassis->setDebugNode(m_debugNodes);
00192     
00193     st->append(new VRS::Scaling(0.005, 0.005, 0.005));
00194     st->append(body);
00195     
00196     // spring scene things
00197     VRS::SO<VRS::SceneThing> federLVSceneThing = new VRS::SceneThing(st);
00198     federLVSceneThing->append(federLV);
00199     VRS::SO<VRS::SceneThing> federRVSceneThing = new VRS::SceneThing(st);
00200     federRVSceneThing->append(federRV);
00201     VRS::SO<VRS::SceneThing> federLHSceneThing = new VRS::SceneThing(st);
00202     federLHSceneThing->append(federLH);
00203     VRS::SO<VRS::SceneThing> federRHSceneThing = new VRS::SceneThing(st);
00204     federRHSceneThing->append(federRH);
00205     
00206     // axis scene things  
00207     VRS::SO<VRS::SceneThing> axisLVSceneThing = new VRS::SceneThing(st);
00208     achseLV->prepend(new VRS::Translation(VRS::Vector(180,-10,-590)));
00209     axisLVSceneThing->append(achseLV);
00210     VRS::SO<VRS::SceneThing> axisRVSceneThing = new VRS::SceneThing(st);
00211     achseRV->prepend(new VRS::Translation(VRS::Vector(-180,-10,-590)));
00212     axisRVSceneThing->append(achseRV);
00213     VRS::SO<VRS::SceneThing> axisLHSceneThing = new VRS::SceneThing(st);
00214     achseLH->prepend(new VRS::Translation(VRS::Vector(180,-30,230)));
00215     axisLHSceneThing->append(achseLH);
00216     VRS::SO<VRS::SceneThing> axisRHSceneThing = new VRS::SceneThing(st);
00217     achseRH->prepend(new VRS::Translation(VRS::Vector(-180,-30,230)));
00218     axisRHSceneThing->append(achseRH);
00219     
00220     // inside spring scene things
00221     VRS::SO<VRS::SceneThing> infederLVSceneThing = new VRS::SceneThing(st);
00222     infederLVSceneThing->append(federInnenLV);
00223     VRS::SO<VRS::SceneThing> infederRVSceneThing = new VRS::SceneThing(st);
00224     infederRVSceneThing->append(federInnenRV);
00225     VRS::SO<VRS::SceneThing> infederLHSceneThing = new VRS::SceneThing(st);
00226     infederLHSceneThing->append(federInnenLH);
00227     VRS::SO<VRS::SceneThing> infederRHSceneThing = new VRS::SceneThing(st);
00228     infederRHSceneThing->append(federInnenRH);
00229 
00230     // wheel body front left
00231     st = new VRS::SceneThing(m_rootNode);
00232     st->append(new VRS::Scaling(0.004, 0.004, 0.004));
00233     st->append(radLV);
00234 
00235     VRS::SO<Shape> wheelShapeFL = 
00236         new CylinderShape(VRS::Vector(0,1,0),1,m_wheelSizeFront*2.0);
00237     m_wheelFL = new PhysicsBody(st, wheelShapeFL, true);
00238     m_wheelFL->setDebugNode(m_debugNodes);
00239     m_wheelFL->surface()->setMu(m_wheelMu);
00240 
00241     // suspension body front left
00242     st = new VRS::SceneThing(m_rootNode);
00243     m_suspensionFL = new PhysicsBody(st, CS_None);
00244     m_suspensionFL->setDebugNode(m_debugNodes);
00245 
00246     // steering body front left
00247     st = new VRS::SceneThing(m_rootNode);
00248     m_steerFL = new PhysicsBody(st, CS_None);
00249     m_steerFL->setDebugNode(m_debugNodes);
00250 
00251     // wheel body front right
00252     st = new VRS::SceneThing(m_rootNode);
00253     st->append(new VRS::Scaling(0.004, 0.004, 0.004));
00254     st->append(radRV);
00255     VRS::SO<Shape> wheelShapeFR = 
00256         new CylinderShape(VRS::Vector(0,1,0),1,m_wheelSizeFront*2.0);
00257     m_wheelFR = new PhysicsBody(st, wheelShapeFR, true);
00258     m_wheelFR->setDebugNode(m_debugNodes);
00259     m_wheelFR->surface()->setMu(m_wheelMu);
00260 
00261     // suspension body front right
00262     st = new VRS::SceneThing(m_rootNode);
00263     m_suspensionFR = new PhysicsBody(st, CS_None);
00264     m_suspensionFR->setDebugNode(m_debugNodes);
00265 
00266     // steering body front right
00267     st = new VRS::SceneThing(m_rootNode);
00268     m_steerFR = new PhysicsBody(st, CS_None);
00269     m_steerFR->setDebugNode(m_debugNodes);
00270 
00271     // wheel body rear left
00272     st = new VRS::SceneThing(m_rootNode);
00273     st->append(new VRS::Scaling(0.004, 0.004, 0.004));
00274     st->append(radLH);
00275     VRS::SO<Shape> wheelShapeRL = 
00276         new CylinderShape(VRS::Vector(0,1,0),1,m_wheelSizeRear*2.0);
00277     m_wheelRL = new PhysicsBody(st, wheelShapeRL, true);
00278     m_wheelRL->setDebugNode(m_debugNodes);
00279     m_wheelRL->surface()->setMu(m_wheelMu);
00280 
00281     // suspension body rear left
00282     st = new VRS::SceneThing(m_rootNode);
00283     m_suspensionRL = new PhysicsBody(st, CS_None);
00284     m_suspensionRL->setDebugNode(m_debugNodes);
00285 
00286     // wheel body rear right
00287     st = new VRS::SceneThing(m_rootNode);
00288     st->append(new VRS::Scaling(0.004, 0.004, 0.004));
00289     st->append(radRH);
00290     VRS::SO<Shape> wheelShapeRR = 
00291         new CylinderShape(VRS::Vector(0,1,0),1,m_wheelSizeRear*2.0);
00292     m_wheelRR = new PhysicsBody(st, wheelShapeRR, true);
00293     m_wheelRR->setDebugNode(m_debugNodes);
00294     m_wheelRR->surface()->setMu(m_wheelMu);
00295 
00296     // suspension body rear right
00297     st = new VRS::SceneThing(m_rootNode);
00298     m_suspensionRR = new PhysicsBody(st, CS_None);
00299     m_suspensionRR->setDebugNode(m_debugNodes);
00300 
00301     // // rotate wheels to position
00302     m_wheelFL->setRotation(1,0,0,-90);
00303     m_wheelFR->setRotation(1,0,0,90);
00304     m_wheelRL->setRotation(1,0,0,-90);
00305     m_wheelRR->setRotation(1,0,0,90);
00306 
00307     // position chassis bodies
00308     m_chassis->setPosition(m_chassisOffset);
00309     m_chassis->setRotation(0,1,0,-90);
00310 
00311     // position wheel bodies
00312     m_wheelFL->setPosition(m_wheelOffsetFL);
00313     m_wheelFR->setPosition(m_wheelOffsetFR);
00314     m_wheelRL->setPosition(m_wheelOffsetRL);
00315     m_wheelRR->setPosition(m_wheelOffsetRR);
00316 
00317     // position steer bodies
00318     m_steerFL->setPosition(m_steerOffsetFL);
00319     m_steerFR->setPosition(m_steerOffsetFR);
00320 
00321     // position suspension bodies
00322     m_suspensionFL->setPosition(m_suspensionOffsetFL);
00323     m_suspensionFR->setPosition(m_suspensionOffsetFR);
00324     m_suspensionRL->setPosition(m_suspensionOffsetRL);
00325     m_suspensionRR->setPosition(m_suspensionOffsetRR);
00326 
00327     // joints
00328     // front left
00329     // connect wheel and steering
00330     m_axisFL = new PhysicsJointHinge(m_wheelFL, m_steerFL,
00331                              VRS::Vector( 2.45, 1.0,-1.5),
00332                              VRS::Vector(0,0,1));
00333 
00334     // connect steering and suspension
00335     m_steerControlFL =new PhysicsJointHinge(m_steerFL, m_suspensionFL,
00336                              VRS::Vector( 2.1, 0.7, -1.8),
00337                              VRS::Vector(0,1,0));
00338 
00339     // connect suspension and chassis
00340     m_springFL = new PhysicsJointSlider(m_chassis, m_suspensionFL,
00341                              VRS::Vector(0,1,0));
00342 
00343     // front right
00344     // connect wheel and steering
00345     m_axisFR = new PhysicsJointHinge(m_wheelFR, m_steerFR,
00346                              VRS::Vector( 2.45, 1.0, 1.5),
00347                              VRS::Vector(0,0,1));
00348 
00349 
00350     // connect steering and suspension
00351     m_steerControlFR = new PhysicsJointHinge(m_steerFR, m_suspensionFR,
00352                              VRS::Vector( 2.1, 0.7, 1.8),
00353                              VRS::Vector(0,1,0));
00354 
00355 
00356     // connect suspension and chassis
00357     m_springFR = new PhysicsJointSlider(m_chassis, m_suspensionFR,
00358                              VRS::Vector(0,1,0));
00359 
00360     // rear left
00361     // connect wheel and suspension
00362     m_axisRL = new PhysicsJointHinge(m_suspensionRL, m_wheelRL,
00363                              VRS::Vector(-2.1, 1.0,-1.8),
00364                              VRS::Vector(0,0,1));
00365 
00366     // connect suspension and chassis
00367     m_springRL = new PhysicsJointSlider(m_chassis, m_suspensionRL,
00368                              VRS::Vector(0,1,0));
00369 
00370     // rear right
00371     // connect wheel and suspension
00372     m_axisRR = new PhysicsJointHinge(m_suspensionRR, m_wheelRR,
00373                              VRS::Vector(-2.1, 1.0, 1.8),
00374                              VRS::Vector(0,0,1));
00375 
00376     // connect suspension and chassis
00377     m_springRR = new PhysicsJointSlider(m_chassis, m_suspensionRR,
00378                              VRS::Vector(0,1,0));
00379 
00380     // high speed rotation mode
00381     m_wheelFL->setHighSpeedRotationAxis(VRS::Vector(0,0,1));
00382     m_wheelFR->setHighSpeedRotationAxis(VRS::Vector(0,0,1));
00383     m_wheelRL->setHighSpeedRotationAxis(VRS::Vector(0,0,1));
00384     m_wheelRR->setHighSpeedRotationAxis(VRS::Vector(0,0,1));
00385 
00386     m_wheelFL->setHighSpeedRotationMode(true);
00387     m_wheelFR->setHighSpeedRotationMode(true);
00388     m_wheelRL->setHighSpeedRotationMode(true);
00389     m_wheelRR->setHighSpeedRotationMode(true);
00390 
00391     // set masses
00392     m_chassis->setMass(m_bodyMass, VRS::Vector(0,-30,0));
00393     m_wheelFL->setMass(m_wheelMass);
00394     m_wheelFR->setMass(m_wheelMass);
00395     m_wheelRL->setMass(m_wheelMass);
00396     m_wheelRR->setMass(m_wheelMass);
00397 
00398     // configure suspension springs
00399     m_springFL->setHighStop(0.0);
00400     m_springFL->setLowStop(-m_springLengthFront);
00401     m_springFL->setMotorVelocity(m_springSpeedFront);
00402     m_springFL->setMotorMaxForce(m_springPowerFront);
00403 
00404     m_springFR->setHighStop(0.0);
00405     m_springFR->setLowStop(-m_springLengthFront);
00406     m_springFR->setMotorVelocity(m_springSpeedFront);
00407     m_springFR->setMotorMaxForce(m_springPowerFront);
00408 
00409     m_springRL->setHighStop(0.0);
00410     m_springRL->setLowStop(-m_springLengthRear);
00411     m_springRL->setMotorVelocity(m_springSpeedRear);
00412     m_springRL->setMotorMaxForce(m_springPowerRear);
00413 
00414     m_springRR->setHighStop(0.0);
00415     m_springRR->setLowStop(-m_springLengthRear);
00416     m_springRR->setMotorVelocity(m_springSpeedRear);
00417     m_springRR->setMotorMaxForce(m_springPowerRear);
00418 
00419     // configure steering
00420     m_steerControlFL->setHighStop(0.0);
00421     m_steerControlFL->setLowStop(0.0);
00422     m_steerControlFR->setHighStop(0.0);
00423     m_steerControlFR->setLowStop(0.0);
00424 
00425     // This is our Camera Hook
00426     st = new VRS::SceneThing(m_rootNode);
00427     m_hook = new PhysicsBody(st, new SphereShape(
00428         VRS::Bounds(VRS::Vector(0.1,0.1,0.1), VRS::Vector(0.1,0.1,0.1))), true);
00429     m_hook->setPosition(m_chassisOffset + VRS::Vector(0,0,0));
00430     m_hook->surface()->setGhostMode(true);
00431 
00432     m_hook->setRotation(VRS::Vector(0,1,0), 0);
00433     
00434     m_hookJoint = new PhysicsJointSlider(
00435         m_chassis, m_hook, VRS::Vector(0,1,0));
00436 
00437     m_hookJoint->setHighStop(0.0);
00438     m_hookJoint->setLowStop(0.0);
00439 
00440 
00441     m_chassis->setAutoDisableMode(false);
00442 
00443     m_wheelFL->setAutoDisableMode(false);
00444     m_wheelFR->setAutoDisableMode(false);
00445     m_wheelRL->setAutoDisableMode(false);
00446     m_wheelRR->setAutoDisableMode(false);
00447 
00448     m_suspensionFL->setAutoDisableMode(false);
00449     m_suspensionFR->setAutoDisableMode(false);
00450     m_suspensionRL->setAutoDisableMode(false);
00451     m_suspensionRR->setAutoDisableMode(false);
00452 
00453     m_steerFL->setAutoDisableMode(false);
00454     m_steerFR->setAutoDisableMode(false);
00455 
00456 
00457     enableAllBodies();
00458 }
00459 
00460 BuggyFunCar::~BuggyFunCar()
00461 {
00462     // TODO: cleanup
00463 }
00464 
00465 void
00466 BuggyFunCar::accelerate(double p_amount)
00467 {
00468     enableAllBodies();
00469 
00470     if(p_amount)
00471     {
00472         m_axisRL->setMotorVelocity(m_carMaxSpeed * p_amount);
00473         m_axisRR->setMotorVelocity(m_carMaxSpeed * p_amount);
00474         m_axisRL->setMotorMaxForce(m_carPower);
00475         m_axisRR->setMotorMaxForce(m_carPower);
00476     }
00477     else
00478     {
00479         m_axisRL->setMotorVelocity(m_carMaxSpeed);
00480         m_axisRR->setMotorVelocity(m_carMaxSpeed);
00481         m_axisRL->setMotorMaxForce(0);
00482         m_axisRR->setMotorMaxForce(0);
00483     }
00484 }
00485 
00486 void
00487 BuggyFunCar::steer(double p_amount)
00488 {
00489     enableAllBodies();
00490     m_steerControlFL->setHighStop(0.55 * p_amount);
00491     m_steerControlFL->setLowStop(0.55 * p_amount);
00492     m_steerControlFR->setHighStop(0.55 * p_amount);
00493     m_steerControlFR->setLowStop(0.55 * p_amount);
00494 }
00495 
00496 void
00497 BuggyFunCar::nitro(double p_amount)
00498 {
00499     enableAllBodies();
00500     m_chassis->addRelativeForceAtRelativePosition(
00501             VRS::Vector(0,0,350 * -p_amount),
00502             VRS::Vector(0,0,-2));
00503 }
00504 
00505 void
00506 BuggyFunCar::handBreak(double p_enable)
00507 {
00508     enableAllBodies();
00509     if(p_enable == 1.0)
00510     {
00511         m_axisFL->setMotorVelocity(0);
00512         m_axisFR->setMotorVelocity(0);
00513         m_axisFL->setMotorMaxForce(15);
00514         m_axisFR->setMotorMaxForce(15);
00515         m_axisRL->setMotorVelocity(0);
00516         m_axisRR->setMotorVelocity(0);
00517         m_axisRL->setMotorMaxForce(200);
00518         m_axisRR->setMotorMaxForce(200);
00519     }
00520     else
00521     {
00522         m_axisFL->setMotorVelocity(100);
00523         m_axisFR->setMotorVelocity(100);
00524         m_axisFL->setMotorMaxForce(0);
00525         m_axisFR->setMotorMaxForce(0);
00526         m_axisRL->setMotorVelocity(100);
00527         m_axisRR->setMotorVelocity(100);
00528         m_axisRL->setMotorMaxForce(0);
00529         m_axisRR->setMotorMaxForce(0);
00530     }
00531 }
00532 
00533 VRS::SO<VRS::SceneThing>
00534 BuggyFunCar::sceneThing()
00535 {
00536     return m_chassis->sceneThing();
00537 }
00538 
00539 void
00540 BuggyFunCar::attachCamera(VRS::SO<VRS::Camera> p_camera)
00541 {
00542 
00543 }
00544 
00545 void
00546 BuggyFunCar::enableAllBodies()
00547 {
00548      m_chassis->setEnabled(true);
00549 
00550      m_wheelFL->setEnabled(true);
00551      m_wheelFR->setEnabled(true);
00552      m_wheelRL->setEnabled(true);
00553      m_wheelRR->setEnabled(true);
00554 
00555      m_suspensionFL->setEnabled(true);
00556      m_suspensionFR->setEnabled(true);
00557      m_suspensionRL->setEnabled(true);
00558      m_suspensionRR->setEnabled(true);
00559 
00560      m_steerFL->setEnabled(true);
00561      m_steerFR->setEnabled(true);
00562 
00563      m_hook->setEnabled(true);
00564 }
00565 
00566 void
00567 BuggyFunCar::setPosition(VRS::Vector p_position)
00568 {
00569     // position chassis bodies
00570     m_chassis->setPosition(m_chassisOffset + p_position);
00571     m_chassis->setLinearVelocity(VRS::Vector(0,0,0));
00572     m_chassis->setAngularVelocity(VRS::Vector(0,0,0));
00573 
00574     // position wheel bodies
00575     m_wheelFL->setPosition(m_wheelOffsetFL + p_position);
00576     m_wheelFR->setPosition(m_wheelOffsetFR + p_position);
00577     m_wheelRL->setPosition(m_wheelOffsetRL + p_position);
00578     m_wheelRR->setPosition(m_wheelOffsetRR + p_position);
00579     m_wheelFL->setLinearVelocity(VRS::Vector(0,0,0));
00580     m_wheelFR->setLinearVelocity(VRS::Vector(0,0,0));
00581     m_wheelRL->setLinearVelocity(VRS::Vector(0,0,0));
00582     m_wheelRR->setLinearVelocity(VRS::Vector(0,0,0));
00583     m_wheelFL->setAngularVelocity(VRS::Vector(0,0,0));
00584     m_wheelFR->setAngularVelocity(VRS::Vector(0,0,0));
00585     m_wheelRL->setAngularVelocity(VRS::Vector(0,0,0));
00586     m_wheelRR->setAngularVelocity(VRS::Vector(0,0,0));
00587 
00588     // position steer bodies
00589     m_steerFL->setPosition(m_steerOffsetFL + p_position);
00590     m_steerFR->setPosition(m_steerOffsetFR + p_position);
00591     m_steerFL->setLinearVelocity(VRS::Vector(0,0,0));
00592     m_steerFR->setLinearVelocity(VRS::Vector(0,0,0));
00593     m_steerFL->setAngularVelocity(VRS::Vector(0,0,0));
00594     m_steerFR->setAngularVelocity(VRS::Vector(0,0,0));
00595 
00596     // position suspension bodies
00597     m_suspensionFL->setPosition(m_suspensionOffsetFL + p_position);
00598     m_suspensionFR->setPosition(m_suspensionOffsetFR + p_position);
00599     m_suspensionRL->setPosition(m_suspensionOffsetRL + p_position);
00600     m_suspensionRR->setPosition(m_suspensionOffsetRR + p_position);
00601     m_suspensionFL->setLinearVelocity(VRS::Vector(0,0,0));
00602     m_suspensionFR->setLinearVelocity(VRS::Vector(0,0,0));
00603     m_suspensionRL->setLinearVelocity(VRS::Vector(0,0,0));
00604     m_suspensionRR->setLinearVelocity(VRS::Vector(0,0,0));
00605     m_suspensionFL->setAngularVelocity(VRS::Vector(0,0,0));
00606     m_suspensionFR->setAngularVelocity(VRS::Vector(0,0,0));
00607     m_suspensionRL->setAngularVelocity(VRS::Vector(0,0,0));
00608     m_suspensionRR->setAngularVelocity(VRS::Vector(0,0,0));
00609 }
00610 
00611 void
00612 BuggyFunCar::setPosition(double p_x, double p_y, double p_z)
00613 {
00614     setPosition(VRS::Vector(p_x, p_y, p_z));
00615 }
00616 
00617 VRS::Vector
00618 BuggyFunCar::position()
00619 {
00620 //     return m_chassis->position() - m_chassisOffset;
00621     return m_chassis->translationNode()->getTranslate();
00622 }
00623 
00624 } // namespace vrsode

Generated on Fri May 11 21:01:57 2007 for Random Racer by  doxygen 1.5.1