00001 #include "TrackPhysicalObject.h"
00002 #include "Application.h"
00003 #include "Visitor.h"
00004
00005 int TrackPhysicalObject::s_nextID = 0;
00006
00007 void TrackPhysicalObject::setID()
00008 {
00009 m_ID = s_nextID;
00010 ++s_nextID;
00011 }
00012
00013 TrackPhysicalObject::TrackPhysicalObject(int _val, Ogre::Vector3 _pos, Track* _track) : GameObject()
00014 {
00015 setID();
00016 setName("TrackPhysicalObject" + Ogre::StringConverter::toString(getID()));
00017 m_type = 5;
00018 m_nextSec = 0;
00019 m_prevSec = 0;
00020 m_groundManual = 0;
00021 m_leftManual = 0;
00022 m_rightManual = 0;
00023 m_entity = 0;
00024 m_leftEnt = 0;
00025 m_rightEnt = 0;
00026 m_contactCheck = false;
00027 m_staticGeom = false;
00028
00029 setPointID(_val);
00030 setTrack(_track);
00031 m_staticGeom = 0;
00032 m_friction = 50.0f;
00033 Ogre::SceneNode* sceneNode = _track->getSceneNode()->createChildSceneNode(m_name + "SceneNode");
00034 setSceneNode(sceneNode);
00035
00036
00037
00038 Ogre::ManualObject* trackManual;
00039
00040 trackManual = Application::getSingleton()->getViewerManager()->createManualObject(m_name + "Manual");
00041
00042
00043 trackManual->setDynamic(true);
00044
00045
00046 sceneNode->attachObject(trackManual);
00047
00048
00049 setGroundManual(trackManual);
00050
00051
00052
00053 for (int i = 0; i < getTrack()->getInterpSteps(); ++i)
00054 {
00055 #ifdef TRACK_USE_LINES
00056 trackManual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
00057
00058 trackManual->position(Ogre::Vector3(1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00059 trackManual->position(Ogre::Vector3(-1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00060 #endif
00061 #define TRACK_USE_POLYS
00062 #ifdef TRACK_USE_POLYS
00063 trackManual->begin("track", Ogre::RenderOperation::OT_TRIANGLE_LIST);
00064
00065 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00066 trackManual->textureCoord(0.5,0);
00067 trackManual->normal(0, 1, 0);
00068 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00069 trackManual->textureCoord(0.5,1);
00070 trackManual->normal(0, 1, 0);
00071 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00072 trackManual->textureCoord(0,0);
00073 trackManual->normal(0, 1, 0);
00074 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00075 trackManual->textureCoord(0,1);
00076 trackManual->normal(0, 1, 0);
00077 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00078 trackManual->textureCoord(1,0);
00079 trackManual->normal(0, 1, 0);
00080 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00081 trackManual->textureCoord(1,1);
00082 trackManual->normal(0, 1, 0);
00083
00084 trackManual->index(0);
00085 trackManual->index(1);
00086 trackManual->index(2);
00087
00088 trackManual->index(1);
00089 trackManual->index(3);
00090 trackManual->index(2);
00091
00092 trackManual->index(0);
00093 trackManual->index(4);
00094 trackManual->index(1);
00095
00096 trackManual->index(1);
00097 trackManual->index(4);
00098 trackManual->index(5);
00099 #endif
00100 trackManual->end();
00101 }
00102
00103 trackManual = Application::getSingleton()->getViewerManager()->createManualObject(m_name + "LeftManual");
00104
00105
00106 trackManual->setDynamic(true);
00107
00108
00109 sceneNode->attachObject(trackManual);
00110
00111
00112 setLeftManual(trackManual);
00113
00114 for (int i = 0; i < getTrack()->getInterpSteps(); ++i)
00115 {
00116 #ifdef TRACK_USE_LINES
00117 trackManual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
00118
00119 trackManual->position(Ogre::Vector3(1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00120 trackManual->position(Ogre::Vector3(-1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00121 #endif
00122 #define TRACK_USE_POLYS
00123 #ifdef TRACK_USE_POLYS
00124 trackManual->begin("trackSideBarrier", Ogre::RenderOperation::OT_TRIANGLE_LIST);
00125
00126 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00127 trackManual->textureCoord(0,0);
00128 trackManual->normal(1, 0, 0);
00129 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00130 trackManual->textureCoord(0,100.0);
00131 trackManual->normal(1, 0, 0);
00132 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00133 trackManual->textureCoord(5.0,0);
00134 trackManual->normal(1, 0, 0);
00135 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00136 trackManual->textureCoord(100.0,100.0);
00137 trackManual->normal(1, 0, 0);
00138
00139 trackManual->index(0);
00140 trackManual->index(1);
00141 trackManual->index(2);
00142
00143 trackManual->index(1);
00144 trackManual->index(3);
00145 trackManual->index(2);
00146
00147 #endif
00148 trackManual->end();
00149 }
00150
00151 trackManual = Application::getSingleton()->getViewerManager()->createManualObject(m_name + "RightManual");
00152
00153
00154 trackManual->setDynamic(true);
00155
00156
00157 sceneNode->attachObject(trackManual);
00158
00159
00160 setRightManual(trackManual);
00161
00162 for (int i = 0; i < getTrack()->getInterpSteps(); ++i)
00163 {
00164 #ifdef TRACK_USE_LINES
00165 trackManual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
00166
00167 trackManual->position(Ogre::Vector3(1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00168 trackManual->position(Ogre::Vector3(-1.0,0.0,i * getTrack()->getInterpAmount() + getTrack()->getInterpSteps()));
00169 #endif
00170 #define TRACK_USE_POLYS
00171 #ifdef TRACK_USE_POLYS
00172 trackManual->begin("trackSideBarrier", Ogre::RenderOperation::OT_TRIANGLE_LIST);
00173
00174 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00175 trackManual->textureCoord(0,0);
00176 trackManual->normal(-1, 0, 0);
00177 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00178 trackManual->textureCoord(0,1);
00179 trackManual->normal(-1, 0, 0);
00180 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00181 trackManual->textureCoord(1,0);
00182 trackManual->normal(-1, 0, 0);
00183 trackManual->position(Ogre::Vector3(0.0,0.0,0.0));
00184 trackManual->textureCoord(1,1);
00185 trackManual->normal(-1, 0, 0);
00186
00187 trackManual->index(0);
00188 trackManual->index(1);
00189 trackManual->index(2);
00190
00191 trackManual->index(1);
00192 trackManual->index(3);
00193 trackManual->index(2);
00194
00195 #endif
00196 trackManual->end();
00197 }
00198
00199 setAny();
00200
00201 setLastDirection(Ogre::Vector3::UNIT_X);
00202 setLastUp(Ogre::Vector3::UNIT_Y);
00203 setLastCross(Ogre::Vector3::UNIT_Z);
00204
00205 setFirstDirection(Ogre::Vector3::UNIT_X);
00206 setFirstUp(Ogre::Vector3::UNIT_Y);
00207 setFirstCross(Ogre::Vector3::NEGATIVE_UNIT_Z);
00208
00209 sceneNode->setPosition(_pos);
00210 Application::getSingleton()->getObjectManager()->addObject(this);
00211 }
00212
00213 TrackPhysicalObject::~TrackPhysicalObject()
00214 {
00215 if (getGroundManual() != 0) getSceneNode()->detachObject(getGroundManual());
00216 if (getGroundManual() != 0) Application::getSingleton()->getViewerManager()->destroyManualObject(getGroundManual());
00217
00218 if (getLeftManual() != 0) getSceneNode()->detachObject(getLeftManual());
00219 if (getLeftManual() != 0) Application::getSingleton()->getViewerManager()->destroyManualObject(getLeftManual());
00220
00221 if (getRightManual() != 0) getSceneNode()->detachObject(getRightManual());
00222 if (getRightManual() != 0) Application::getSingleton()->getViewerManager()->destroyManualObject(getRightManual());
00223 }
00224
00225 Track* TrackPhysicalObject::getTrack() const
00226 {
00227 return m_track;
00228 }
00229
00230 void TrackPhysicalObject::setTrack(Track* _val)
00231 {
00232 m_track = _val;
00233 }
00234
00235 void TrackPhysicalObject::resetCurrent()
00236 {
00237 getSceneNode()->resetToInitialState();
00238 m_nextSec = 0;
00239 m_prevSec = 0;
00240 }
00241
00242 void TrackPhysicalObject::rebuildSegment()
00243 {
00244
00245
00246
00247
00248
00249
00250 Ogre::SimpleSpline* equalisedSpline = getTrack()->getSplineEqualised();
00251
00252
00253 Ogre::Real interpAmount = getTrack()->getInterpAmount();
00254
00255
00256
00257
00258
00259
00260
00261
00262 Ogre::Vector3 startPoint = getSceneNode()->convertWorldToLocalPosition(getTrack()->getSplineEqualised()->getPoint(getPointID()));
00263 Ogre::Vector3 endPoint = getSceneNode()->convertWorldToLocalPosition(getTrack()->getSplineEqualised()->interpolate(getPointID(),(0.1f)));
00264 Ogre::Vector3 nextEndPoint;
00265
00266 Ogre::Vector3 upVector;
00267 Ogre::Vector3 currentTrackDirection = getFirstDirection();
00268 Ogre::Vector3 nextTrackDirection;
00269 Ogre::Vector3 startCross = getFirstCross();
00270 Ogre::Vector3 endCross;
00271
00272 Ogre::Quaternion upRotation;
00273
00274 Ogre::Quaternion direcRotation;
00275
00276
00277 m_upVectors.clear();
00278 for (Ogre::Real i = 0.0f; i < 1.0f; i += interpAmount)
00279 {
00280
00281
00282
00283
00284 if (i < 0.9)
00285 {
00286 nextEndPoint = getSceneNode()->convertWorldToLocalPosition(getTrack()->getSplineEqualised()->interpolate(getPointID(),(i + 0.2f)));
00287 }
00288 else
00289 {
00290 nextEndPoint = getSceneNode()->convertWorldToLocalPosition(getTrack()->getSplineEqualised()->interpolate(getNextSec()->getPointID(),(0.1f)));
00291 }
00292
00293 nextTrackDirection = nextEndPoint - endPoint;
00294
00295 if (i >= 0.9)
00296 {
00297 getNextSec()->setFirstDirection(nextTrackDirection.normalisedCopy());
00298 }
00299
00300 nextTrackDirection.normalise();
00301
00302 Ogre::Radian roll = Ogre::Radian(((getTrackAvRotation().valueRadians() * (1.0 - i)) + (getNextSec()->getTrackAvRotation().valueRadians() * (0.0 + i))));
00303
00304
00305 upRotation = Ogre::Quaternion(roll, Ogre::Vector3::UNIT_Z);
00306
00307
00308 Ogre::Radian pitch = currentTrackDirection.angleBetween(nextTrackDirection);
00309 direcRotation = Ogre::Quaternion(pitch, Ogre::Vector3::UNIT_X);
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 upVector = Ogre::Vector3::UNIT_Y;
00322 upVector = upRotation * upVector;
00323 upVector = direcRotation * upVector;
00324 upVector.normalise();
00325
00326 endCross = upVector.crossProduct(nextTrackDirection);
00327
00328
00329 m_upVectors.push_back(upVector);
00330
00331 endCross.normalise();
00332 if (i >= 0.9)
00333 {
00334 getNextSec()->setFirstCross(endCross);
00335 }
00336
00337 Ogre::Vector3 startLeft = startPoint + (startCross * getTrack()->getTrackWidth());
00338 Ogre::Vector3 endLeft = endPoint + (endCross * getTrack()->getTrackWidth());
00339
00340 Ogre::Vector3 startRight = startPoint + (startCross * -getTrack()->getTrackWidth());
00341 Ogre::Vector3 endRight = endPoint + (endCross * -getTrack()->getTrackWidth());
00342
00343 Ogre::Vector3 startDrawingPoint = startPoint;
00344 Ogre::Vector3 endDrawingPoint = endPoint;
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 int manualNum = (int)(i * (Ogre::Real)getTrack()->getInterpSteps());
00363 getGroundManual()->beginUpdate(manualNum);
00364
00365 #ifdef TRACK_USE_LINES
00366 getManual()->position(startLeft);
00367 getManual()->position(startRight);
00368 #endif
00369 #ifdef TRACK_USE_POLYS
00370
00371 getGroundManual()->position(startDrawingPoint);
00372 getGroundManual()->textureCoord(0,0.5);
00373 getGroundManual()->normal(upVector);
00374 getGroundManual()->position(endDrawingPoint);
00375 getGroundManual()->textureCoord(1,0.5);
00376 getGroundManual()->normal(upVector);
00377 getGroundManual()->position(startLeft);
00378 getGroundManual()->textureCoord(0,0);
00379 getGroundManual()->normal(upVector);
00380 getGroundManual()->position(endLeft);
00381 getGroundManual()->textureCoord(1,0);
00382 getGroundManual()->normal(upVector);
00383 getGroundManual()->position(startRight);
00384 getGroundManual()->textureCoord(0,1);
00385 getGroundManual()->normal(upVector);
00386 getGroundManual()->position(endRight);
00387 getGroundManual()->textureCoord(1,1);
00388 getGroundManual()->normal(upVector);
00389
00390 getGroundManual()->index(0);
00391 getGroundManual()->index(1);
00392 getGroundManual()->index(2);
00393
00394 getGroundManual()->index(1);
00395 getGroundManual()->index(3);
00396 getGroundManual()->index(2);
00397
00398 getGroundManual()->index(0);
00399 getGroundManual()->index(4);
00400 getGroundManual()->index(1);
00401
00402 getGroundManual()->index(1);
00403 getGroundManual()->index(4);
00404 getGroundManual()->index(5);
00405 #endif
00406
00407 getGroundManual()->end();
00408
00409 getLeftManual()->beginUpdate(manualNum);
00410
00411 #ifdef TRACK_USE_LINES
00412 getManual()->position(startLeft);
00413 getManual()->position(startRight);
00414 #endif
00415 #ifdef TRACK_USE_POLYS
00416
00417 getLeftManual()->position(startLeft);
00418 getLeftManual()->textureCoord(0,0);
00419 getLeftManual()->normal(startCross);
00420 getLeftManual()->position(endLeft);
00421 getLeftManual()->textureCoord(0,1);
00422 getLeftManual()->normal(endCross);
00423 getLeftManual()->position(startLeft + Ogre::Vector3::UNIT_Y * 100);
00424 getLeftManual()->textureCoord(1,0);
00425 getLeftManual()->normal(startCross);
00426 getLeftManual()->position(endLeft + Ogre::Vector3::UNIT_Y * 100);
00427 getLeftManual()->textureCoord(1,1);
00428 getLeftManual()->normal(endCross);
00429
00430 getLeftManual()->index(0);
00431 getLeftManual()->index(1);
00432 getLeftManual()->index(2);
00433
00434 getLeftManual()->index(1);
00435 getLeftManual()->index(3);
00436 getLeftManual()->index(2);
00437
00438 #endif
00439
00440 getLeftManual()->end();
00441
00442 getRightManual()->beginUpdate(manualNum);
00443
00444 #ifdef TRACK_USE_LINES
00445 getManual()->position(startRight);
00446 getManual()->position(startRight);
00447 #endif
00448 #ifdef TRACK_USE_POLYS
00449
00450 getRightManual()->position(startRight);
00451 getRightManual()->textureCoord(0,0);
00452 getRightManual()->normal(-startCross);
00453
00454 getRightManual()->position(endRight);
00455 getRightManual()->textureCoord(0,1);
00456 getRightManual()->normal(-endCross);
00457
00458 getRightManual()->position(startRight + Ogre::Vector3::UNIT_Y * 100);
00459 getRightManual()->textureCoord(1,0);
00460 getRightManual()->normal(-startCross);
00461
00462 getRightManual()->position(endRight + Ogre::Vector3::UNIT_Y * 100);
00463 getRightManual()->textureCoord(1,1);
00464 getRightManual()->normal(-endCross);
00465
00466 getRightManual()->index(2);
00467 getRightManual()->index(1);
00468 getRightManual()->index(0);
00469
00470 getRightManual()->index(2);
00471 getRightManual()->index(3);
00472 getRightManual()->index(1);
00473
00474 #endif
00475
00476 getRightManual()->end();
00477
00478
00479 startPoint = endPoint;
00480 endPoint = nextEndPoint;
00481 currentTrackDirection = nextTrackDirection;
00482 startCross = endCross;
00483 }
00484
00485 }
00486
00487 void TrackPhysicalObject::calcAvRotation()
00488 {
00489
00490
00491 Ogre::Radian rotation;
00492 Ogre::Vector3 upVector = Ogre::Vector3::UNIT_Y;
00493
00494
00495 Ogre::Vector3 direction = getTrackAvDirection().normalisedCopy();
00496 Ogre::Vector3 prevDirection = getPrevSec()->getTrackAvDirection().normalisedCopy();
00497
00498
00499 rotation = prevDirection.angleBetween(direction);
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 rotation = rotation * 0.5f;
00510
00511
00512 if (rotation.valueRadians() > 0.1) rotation = Ogre::Radian(0.1);
00513
00514 if (rotation.valueRadians() < 1e-6f) rotation = Ogre::Radian(0.0);
00515
00516
00517 if (rotation.valueRadians() > 0.0)
00518 {
00519 if (direction.z < prevDirection.z)
00520 {
00521 if (direction.x > prevDirection.x)
00522 {
00523
00524
00525 rotation = rotation * -1.0;
00526 }
00527 }
00528 else
00529 {
00530 if (direction.x > prevDirection.x)
00531 {
00532
00533
00534 rotation = rotation * -1.0;
00535 }
00536 }
00537
00538 Ogre::Quaternion upRotation = Ogre::Quaternion(rotation, Ogre::Vector3::UNIT_Z);
00539
00540
00541
00542
00543
00544 upVector = upRotation * upVector;
00545 }
00546
00547
00548
00549 setTrackAvRotation(rotation);
00550
00551
00552 Ogre::Vector3 cross = Ogre::Vector3::UNIT_Z.crossProduct(upVector);
00553
00554
00555 cross.normalise();
00556
00557
00558 setTrackAvUp(upVector);
00559 setTrackAvCross(cross);
00560
00561
00562 Ogre::ManualObject* yLine;
00563
00564 yLine = Application::getSingleton()->getViewerManager()->createManualObject(m_name + "Y");
00565
00566 getSceneNode()->attachObject(yLine);
00567
00568
00569
00570 yLine->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
00571 yLine->position(upVector);
00572 yLine->position(upVector * 10.0f);
00573 yLine->end();
00574
00575 }
00576
00577 void TrackPhysicalObject::setTrackAvRotation(const Ogre::Radian &_val)
00578 {
00579 m_trackAvRotation = _val;
00580 }
00581
00582 Ogre::Radian TrackPhysicalObject::getTrackAvRotation() const
00583 {
00584 return m_trackAvRotation;
00585 }
00586
00587
00588 void TrackPhysicalObject::setTrackAvDirection(const Ogre::Vector3 &_val)
00589 {
00590 m_trackAvDirection = _val;
00591 }
00592
00593 Ogre::Vector3 TrackPhysicalObject::getTrackAvDirection() const
00594 {
00595 return m_trackAvDirection;
00596 }
00597
00598 void TrackPhysicalObject::setTrackAvCross(const Ogre::Vector3 &_val)
00599 {
00600 m_trackAvCross = _val;
00601 }
00602
00603 Ogre::Vector3 TrackPhysicalObject::getTrackAvCross() const
00604 {
00605 return m_trackAvCross;
00606 }
00607
00608 void TrackPhysicalObject::setTrackAvUp(const Ogre::Vector3 &_val)
00609 {
00610 m_trackAvUp = _val;
00611 }
00612
00613 Ogre::Vector3 TrackPhysicalObject::getTrackAvUp() const
00614 {
00615 return m_trackAvUp;
00616 }
00617
00618 void TrackPhysicalObject::setLastDirection(const Ogre::Vector3 &_val)
00619 {
00620 m_lastDirection = _val;
00621 }
00622
00623 Ogre::Vector3 TrackPhysicalObject::getLastDirection() const
00624 {
00625 return m_lastDirection;
00626 }
00627
00628 void TrackPhysicalObject::setLastCross(const Ogre::Vector3 &_val)
00629 {
00630 m_lastCross = _val;
00631 }
00632
00633 Ogre::Vector3 TrackPhysicalObject::getLastCross() const
00634 {
00635 return m_lastCross;
00636 }
00637
00638 void TrackPhysicalObject::setLastUp(const Ogre::Vector3 &_val)
00639 {
00640 m_lastUp = _val;
00641 }
00642
00643 Ogre::Vector3 TrackPhysicalObject::getLastUp() const
00644 {
00645 return m_lastUp;
00646 }
00647
00648 void TrackPhysicalObject::setFirstDirection(const Ogre::Vector3 &_val)
00649 {
00650 m_firstDirection = _val;
00651 }
00652
00653 Ogre::Vector3 TrackPhysicalObject::getFirstDirection() const
00654 {
00655 return m_firstDirection;
00656 }
00657
00658 void TrackPhysicalObject::setFirstCross(const Ogre::Vector3 &_val)
00659 {
00660 m_firstCross = _val;
00661 }
00662
00663 Ogre::Vector3 TrackPhysicalObject::getFirstCross() const
00664 {
00665 return m_firstCross;
00666 }
00667
00668 void TrackPhysicalObject::setFirstUp(const Ogre::Vector3 &_val)
00669 {
00670 m_firstUp = _val;
00671 }
00672
00673 Ogre::Vector3 TrackPhysicalObject::getFirstUp() const
00674 {
00675 return m_firstUp;
00676 }
00677
00678 void TrackPhysicalObject::setPrevSec(TrackPhysicalObject* _val)
00679 {
00680 m_prevSec = _val;
00681 if (m_prevSec != 0 && m_prevSec->getNextSec() != this) m_prevSec->setNextSec(this);
00682 }
00683
00684 TrackPhysicalObject* TrackPhysicalObject::getPrevSec()
00685 {
00686 return m_prevSec;
00687 }
00688
00689 void TrackPhysicalObject::setNextSec(TrackPhysicalObject* _val)
00690 {
00691 m_nextSec = _val;
00692 if (m_nextSec != 0 && m_nextSec->getPrevSec() != this) m_nextSec->setPrevSec(this);
00693 }
00694
00695 TrackPhysicalObject* TrackPhysicalObject::getNextSec()
00696 {
00697 return m_nextSec;
00698 }
00699
00700 Ogre::Real TrackPhysicalObject::getTrackWidth() const
00701 {
00702 return getTrack()->getTrackWidth();
00703 }
00704
00705 int TrackPhysicalObject::getPointID() const
00706 {
00707 return m_pointID;
00708 }
00709
00710 void TrackPhysicalObject::setPointID(const int &_val)
00711 {
00712 m_pointID = _val;
00713 }
00714
00715 Ogre::ManualObject* TrackPhysicalObject::getGroundManual() const
00716 {
00717 return m_groundManual;
00718 }
00719
00720 void TrackPhysicalObject::setGroundManual(Ogre::ManualObject* _val)
00721 {
00722 m_groundManual = _val;
00723 }
00724
00725 Ogre::ManualObject* TrackPhysicalObject::getLeftManual() const
00726 {
00727 return m_leftManual;
00728 }
00729
00730 void TrackPhysicalObject::setLeftManual(Ogre::ManualObject* _val)
00731 {
00732 m_leftManual = _val;
00733 }
00734
00735 Ogre::ManualObject* TrackPhysicalObject::getRightManual() const
00736 {
00737 return m_rightManual;
00738 }
00739
00740 void TrackPhysicalObject::setRightManual(Ogre::ManualObject* _val)
00741 {
00742 m_rightManual = _val;
00743 }
00744
00745 void TrackPhysicalObject::createPhysicalMesh()
00746 {
00747 if (m_leftManual != 0)
00748 {
00749 m_physicalLeft = m_leftManual->convertToMesh(getName() + "LeftMesh");
00750 m_leftEnt = Application::getSingleton()->getViewerManager()->createEntity(m_name + "Left", m_physicalLeft->getName());
00751
00752 getSceneNode()->detachObject(getLeftManual());
00753 Application::getSingleton()->getViewerManager()->destroyManualObject(getLeftManual());
00754
00755 m_leftManual = 0;
00756
00757 getSceneNode()->attachObject(m_leftEnt);
00758 }
00759
00760 if (m_rightManual != 0)
00761 {
00762 m_physicalRight = m_rightManual->convertToMesh(getName() + "RightMesh");
00763 m_rightEnt = Application::getSingleton()->getViewerManager()->createEntity(m_name + "Right", m_physicalRight->getName());
00764
00765 getSceneNode()->detachObject(getRightManual());
00766 Application::getSingleton()->getViewerManager()->destroyManualObject(getRightManual());
00767
00768 m_rightManual = 0;
00769
00770 getSceneNode()->attachObject(m_rightEnt);
00771 }
00772
00773 if (m_groundManual != 0)
00774 {
00775 m_physicalMesh = m_groundManual->convertToMesh(getName() + "trackMesh");
00776 Ogre::Entity* ent = Application::getSingleton()->getViewerManager()->createEntity(m_name, m_physicalMesh->getName());
00777
00778 getSceneNode()->detachObject(getGroundManual());
00779 Application::getSingleton()->getViewerManager()->destroyManualObject(getGroundManual());
00780
00781 m_groundManual = 0;
00782
00783 setEntity(ent);
00784 }
00785
00786
00787
00788 Visitor* visitor = new Visitor();
00789
00790 m_entity->visitRenderables(visitor);
00791 m_leftEnt->visitRenderables(visitor);
00792 m_rightEnt->visitRenderables(visitor);
00793
00794 m_staticGeom = Application::getSingleton()->getViewerManager()->createStaticGeometry(getName() + "staticGeometry");
00795 m_staticGeom->addSceneNode(getSceneNode());
00796 m_staticGeom->visitRenderables(visitor);
00797
00798 delete visitor;
00799
00800 m_staticGeom->build();
00801 setMass(0.0f);
00802 makePhysical();
00803
00804
00805
00806 getSceneNode()->getParentSceneNode()->removeAndDestroyChild(getSceneNode()->getName());
00807 if (m_entity != 0)
00808 {
00809 Application::getSingleton()->getViewerManager()->destroyEntity(m_entity);
00810 m_entity = 0;
00811 }
00812
00813 if (m_leftEnt != 0)
00814 {
00815 Application::getSingleton()->getViewerManager()->destroyEntity(m_leftEnt);
00816 m_leftEnt = 0;
00817 }
00818
00819 if (m_rightEnt != 0)
00820 {
00821 Application::getSingleton()->getViewerManager()->destroyEntity(m_rightEnt);
00822 m_rightEnt = 0;
00823 }
00824 }
00825
00826 bool TrackPhysicalObject::makePhysical()
00827 {
00828 bool ret = false;
00829
00830 if (m_leftEnt != 0)
00831 {
00832 Ogre::Vector3 physicalSize = Ogre::Vector3::ZERO;
00833 Ogre::AxisAlignedBox boundingBox = m_leftEnt->getBoundingBox();
00834
00835
00836 m_collisionShape = Application::getSingleton()->getPhysicsManager()->createCollisionShape(m_leftEnt);
00837
00838
00839 m_rigidBody = Application::getSingleton()->getPhysicsManager()->createRigidBody(getName() + "LeftRigidBody");
00840
00841 Ogre::Vector3 pos = getSceneNode()->getPosition();
00842 Ogre::Quaternion quat = getSceneNode()->getOrientation();
00843 m_rigidBody->setShape(getSceneNode(),m_collisionShape,m_restitution,m_friction,m_mass,pos,quat);
00844
00845 Application::getSingleton()->getPhysicsManager()->addPair(m_rigidBody,m_collisionShape);
00846
00847 m_rigidBody->getBulletRigidBody()->setUserPointer((void*)this);
00848
00849 ret = true;
00850 }
00851
00852 if (m_rightEnt != 0)
00853 {
00854 Ogre::Vector3 physicalSize = Ogre::Vector3::ZERO;
00855 Ogre::AxisAlignedBox boundingBox = m_rightEnt->getBoundingBox();
00856
00857
00858 m_collisionShape = Application::getSingleton()->getPhysicsManager()->createCollisionShape(m_rightEnt);
00859
00860
00861 m_rigidBody = Application::getSingleton()->getPhysicsManager()->createRigidBody(getName() + "RightRigidBody");
00862
00863 Ogre::Vector3 pos = getSceneNode()->getPosition();
00864 Ogre::Quaternion quat = getSceneNode()->getOrientation();
00865 m_rigidBody->setShape(getSceneNode(),m_collisionShape,m_restitution,m_friction,m_mass,pos,quat);
00866
00867 Application::getSingleton()->getPhysicsManager()->addPair(m_rigidBody,m_collisionShape);
00868
00869 m_rigidBody->getBulletRigidBody()->setUserPointer((void*)this);
00870
00871 ret = true;
00872 }
00873
00874 if (getEntity() != 0)
00875 {
00876 Ogre::Vector3 physicalSize = Ogre::Vector3::ZERO;
00877 Ogre::AxisAlignedBox boundingBox = getEntity()->getBoundingBox();
00878
00879
00880 m_collisionShape = Application::getSingleton()->getPhysicsManager()->createCollisionShape(getEntity());
00881
00882
00883 m_rigidBody = Application::getSingleton()->getPhysicsManager()->createRigidBody(getName() + "rigidBody");
00884
00885 Ogre::Vector3 pos = getSceneNode()->getPosition();
00886 Ogre::Quaternion quat = getSceneNode()->getOrientation();
00887 m_rigidBody->setShape(getSceneNode(),m_collisionShape,m_restitution,m_friction,m_mass,pos,quat);
00888
00889 Application::getSingleton()->getPhysicsManager()->addPair(m_rigidBody,m_collisionShape);
00890
00891 m_rigidBody->getBulletRigidBody()->setUserPointer((void*)this);
00892
00893 ret = true;
00894 }
00895
00896 return ret;
00897 }
00898
00899 void TrackPhysicalObject::setAny()
00900 {
00901 if (m_entity != 0) m_entity->setUserAny(Ogre::Any(this));
00902 if (m_groundManual != 0) m_groundManual->setUserAny(Ogre::Any(this));
00903 if (m_leftManual != 0) m_leftManual->setUserAny(Ogre::Any(this));
00904 if (m_rightManual != 0) m_rightManual->setUserAny(Ogre::Any(this));
00905 if (m_sceneNode != 0) m_sceneNode->setUserAny(Ogre::Any(this));
00906 }
00907
00908 Ogre::MeshPtr TrackPhysicalObject::getPhysicalMesh()
00909 {
00910 return m_physicalMesh;
00911 }
00912
00913 Ogre::StaticGeometry* TrackPhysicalObject::getStaticGeometry()
00914 {
00915 return m_staticGeom;
00916 }
00917
00918 void TrackPhysicalObject::tellTrackOfContact()
00919 {
00920 if (m_contactCheck == false)
00921 {
00922 m_track->informOfContact(this);
00923 m_contactCheck = true;
00924 }
00925 }
00926
00927 void TrackPhysicalObject::resetContactCheck()
00928 {
00929 m_contactCheck = false;
00930 }