Changeset 10088 in orxonox.OLD for branches/playability/src/util/track/track.cc
- Timestamp:
- Dec 18, 2006, 1:28:49 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/playability/src/util/track/track.cc
r10085 r10088 13 13 This is anohter installment of the infamous track system. It serves for 14 14 temporary use only and is mainly a slimmed version of the old track. 15 15 16 16 The track is used to steer the spaceship. In this case the track will have 17 17 to control a PNode. The spaceship will be able to fly around this node. 18 18 The camera will always be focused on that point. 19 19 20 20 As we do this we have exactly the verticalscroller feeling we want. 21 21 22 22 main-programmer: Benjamin Knecht 23 23 */ 24 24 25 25 #include "util/loading/load_param.h" 26 27 #include "class_id_DEPRECATED.h" 26 #include "track/track.h" 27 28 #include "track/track_manager.h" 29 #include "p_node.h" 30 31 #include "debug.h" 28 32 29 33 ObjectListDefinition(Track); 30 CREATE_FACTORY(Track); 34 // CREATE_FACTORY(Track); 35 31 36 32 37 /** … … 35 40 Track::Track() 36 41 { 37 this->firstTrackElem = new TrackElement(); 38 this->firstTrackElem->ID = 1; 39 this->firstTrackElem->setName("root"); 40 41 this->currentTrackElem = firstTrackElem; 42 43 this->curveType = CURVE_BEZIER; 44 this->trackElemCount = 1; 45 46 this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL); 42 this->init(); 43 } 44 45 46 /** 47 * this is a constructor for use with the xml loading file 48 * @param root xml root element for this object 49 */ 50 Track::Track(const TiXmlElement* root) 51 { 52 this->init(); 53 } 54 55 56 /** 57 * initializes this class 58 */ 59 void Track::init() 60 { 61 // resetting all elements 62 this->firstTrackElem = NULL; 63 64 65 // make a debug track 66 this->firstTrackElem = new TrackElement(); 67 this->firstTrackElem->ID = 1; 68 this->firstTrackElem->setName("root"); 69 70 this->currentTrackElem = firstTrackElem; 71 72 this->curveType = CURVE_BEZIER; 73 this->trackElemCount = 1; 74 75 this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL); 47 76 } 48 77 … … 52 81 Track::~Track() 53 82 { 54 delete this->firstTrackElem; 55 } 83 if( this->firstTrackElem) 84 delete this->firstTrackElem; 85 } 86 56 87 57 88 void Track::loadParams(const TiXmlElement* root) … … 61 92 LoadParam_CYCLE(element, "Point", this, Track, addPoint) 62 93 .describe("Adds a new Point to the currently selected TrackElement"); 63 94 64 95 } 65 96 LOAD_PARAM_END_CYCLE(element); 66 97 } 67 98 99 100 101 /** 102 * 103 * @param x 104 * @param y 105 * @param z 106 */ 68 107 void Track::addPoint(float x, float y, float z) 69 108 { … … 71 110 } 72 111 112 113 /** 114 * 115 * @param newPoint 116 */ 73 117 void Track::addPoint(Vector newPoint) 74 118 { 75 if (this->currentTrackElem->isFresh) 76 { 77 this->setCurveType(CURVE_BEZIER, this->currentTrackElem); 78 this->currentTrackElem->isFresh = false; 79 } 80 trackElem->curve->addNode(newPoint); 81 trackElem->nodeCount++; 82 } 83 119 // if (this->currentTrackElem->isFresh) 120 // { 121 // this->setCurveType(CURVE_BEZIER, this->currentTrackElem); 122 // this->currentTrackElem->isFresh = false; 123 // } 124 // trackElem->curve->addNode(newPoint); 125 // trackElem->nodeCount++; 126 } 127 128 /** 129 * 130 */ 84 131 void Track::finalize() 85 132 { 86 for (int i = 1; i<= trackElemCount ;i++) 87 { 88 TrackElement* tmpElem = this->firstTrackElem->findByID(i); 89 if( tmpElem->childCount > 0) 90 { 91 tIterator<TrackElement>* iterator = tmpElem->children->getIterator(); 92 TrackElement* enumElem = iterator->firstElement(); 93 //TrackElement* enumElem = tmpElem->children->enumerate(); 94 while (enumElem) 95 { 96 97 // c1-continuity 98 enumElem->curve->addNode(enumElem->curve->getNode(0) + 99 ((enumElem->curve->getNode(0) - 100 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) 101 ),2); 102 enumElem->nodeCount++; 103 // c2-continuity 104 enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())- 105 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 + 106 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3); 107 enumElem->nodeCount++; 108 PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n %d-out: count: %d %f, %f, %f\n", 109 tmpElem->ID, tmpElem->nodeCount, 110 tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z, 111 enumElem->ID, enumElem->nodeCount, 112 enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z); 113 114 enumElem = iterator->nextElement(); 115 } 116 delete iterator; 117 } 118 } 133 // for (int i = 1; i<= trackElemCount ;i++) 134 // { 135 // TrackElement* tmpElem = this->firstTrackElem->findByID(i); 136 // if( tmpElem->childCount > 0) 137 // { 138 // tIterator<TrackElement>* iterator = tmpElem->children->getIterator(); 139 // TrackElement* enumElem = iterator->firstElement(); 140 // //TrackElement* enumElem = tmpElem->children->enumerate(); 141 // while (enumElem) 142 // { 143 // 144 // // c1-continuity 145 // enumElem->curve->addNode(enumElem->curve->getNode(0) + 146 // ((enumElem->curve->getNode(0) - 147 // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) 148 // ),2); 149 // enumElem->nodeCount++; 150 // // c2-continuity 151 // enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())- 152 // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 + 153 // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3); 154 // enumElem->nodeCount++; 155 // PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n %d-out: count: %d %f, %f, %f\n", 156 // tmpElem->ID, tmpElem->nodeCount, 157 // tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z, 158 // enumElem->ID, enumElem->nodeCount, 159 // enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z); 160 // 161 // enumElem = iterator->nextElement(); 162 // } 163 // delete iterator; 164 // } 165 // } 166 167 168 119 169 /*for (int i = 1; i <= trackElemCount;i++) 120 170 if (this->firstTrackElem->findByID(i)->endTime > this->maxTime) … … 135 185 void Track::tick(float dt) 136 186 { 137 PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);138 if (this->localTime <= this->firstTrackElem->duration)139 this->jumpTo(this->localTime);140 if (this->localTime <= this->maxTime)141 this->localTime += dt;142 if (this->localTime > this->currentTrackElem->endTime143 && this->currentTrackElem->children)144 {145 if (this->currentTrackElem->jumpTime != 0.0)146 this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);147 // jump to the next TrackElement and also set the history of the new Element to the old one.148 TrackElement* tmpHistoryElem = this->currentTrackElem;149 this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem));150 this->currentTrackElem->history = tmpHistoryElem;151 if (this->currentTrackElem->getName())152 {153 this->trackText->setText(this->currentTrackElem->getName());154 this->textAnimation->replay();155 }156 }157 if (this->bindSlave)158 {159 Vector tmp = this->calcPos();160 Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z));161 162 Vector v(0.0, 1.0, 0.0);163 Quaternion q(-PI/2, v);164 quat = quat * q;165 166 this->bindSlave->setAbsCoor(tmp);167 this->bindSlave->setAbsDir(quat);168 }187 // PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt); 188 // if (this->localTime <= this->firstTrackElem->duration) 189 // this->jumpTo(this->localTime); 190 // if (this->localTime <= this->maxTime) 191 // this->localTime += dt; 192 // if (this->localTime > this->currentTrackElem->endTime 193 // && this->currentTrackElem->children) 194 // { 195 // if (this->currentTrackElem->jumpTime != 0.0) 196 // this->jumpTo(this->localTime + this->currentTrackElem->jumpTime); 197 // // jump to the next TrackElement and also set the history of the new Element to the old one. 198 // TrackElement* tmpHistoryElem = this->currentTrackElem; 199 // this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem)); 200 // this->currentTrackElem->history = tmpHistoryElem; 201 // if (this->currentTrackElem->getName()) 202 // { 203 // this->trackText->setText(this->currentTrackElem->getName()); 204 // this->textAnimation->replay(); 205 // } 206 // } 207 // if (this->bindSlave) 208 // { 209 // Vector tmp = this->calcPos(); 210 // Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z)); 211 // 212 // Vector v(0.0, 1.0, 0.0); 213 // Quaternion q(-PI/2, v); 214 // quat = quat * q; 215 // 216 // this->bindSlave->setAbsCoor(tmp); 217 // this->bindSlave->setAbsDir(quat); 218 // } 169 219 } 170 220
Note: See TracChangeset
for help on using the changeset viewer.