/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2006 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: This is anohter installment of the infamous track system. It serves for temporary use only and is mainly a slimmed version of the old track. The track is used to steer the spaceship. In this case the track will have to control a PNode. The spaceship will be able to fly around this node. The camera will always be focused on that point. As we do this we have exactly the verticalscroller feeling we want. main-programmer: Benjamin Knecht */ #include "util/loading/load_param.h" #include "track/track.h" #include "track/track_manager.h" #include "p_node.h" #include "debug.h" ObjectListDefinition(Track); // CREATE_FACTORY(Track); /** * standard constructor */ Track::Track() { this->init(); } /** * this is a constructor for use with the xml loading file * @param root xml root element for this object */ Track::Track(const TiXmlElement* root) { this->init(); } /** * initializes this class */ void Track::init() { // resetting all elements this->firstTrackElem = NULL; // make a debug track this->firstTrackElem = new TrackElement(); this->firstTrackElem->ID = 1; this->firstTrackElem->setName("root"); this->currentTrackElem = firstTrackElem; this->curveType = CURVE_BEZIER; this->trackElemCount = 1; this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL); } /** * standard destructor */ Track::~Track() { if( this->firstTrackElem) delete this->firstTrackElem; } void Track::loadParams(const TiXmlElement* root) { LOAD_PARAM_START_CYCLE(root, element); { LoadParam_CYCLE(element, "Point", this, Track, addPoint) .describe("Adds a new Point to the currently selected TrackElement"); } LOAD_PARAM_END_CYCLE(element); } /** * * @param x * @param y * @param z */ void Track::addPoint(float x, float y, float z) { this->addPoint(Vector (x,y,z)); } /** * * @param newPoint */ void Track::addPoint(Vector newPoint) { // if (this->currentTrackElem->isFresh) // { // this->setCurveType(CURVE_BEZIER, this->currentTrackElem); // this->currentTrackElem->isFresh = false; // } // trackElem->curve->addNode(newPoint); // trackElem->nodeCount++; } /** * */ void Track::finalize() { // for (int i = 1; i<= trackElemCount ;i++) // { // TrackElement* tmpElem = this->firstTrackElem->findByID(i); // if( tmpElem->childCount > 0) // { // tIterator* iterator = tmpElem->children->getIterator(); // TrackElement* enumElem = iterator->firstElement(); // //TrackElement* enumElem = tmpElem->children->enumerate(); // while (enumElem) // { // // // c1-continuity // enumElem->curve->addNode(enumElem->curve->getNode(0) + // ((enumElem->curve->getNode(0) - // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) // ),2); // enumElem->nodeCount++; // // c2-continuity // enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())- // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 + // tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3); // enumElem->nodeCount++; // PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n %d-out: count: %d %f, %f, %f\n", // tmpElem->ID, tmpElem->nodeCount, // tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z, // enumElem->ID, enumElem->nodeCount, // enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z); // // enumElem = iterator->nextElement(); // } // delete iterator; // } // } /*for (int i = 1; i <= trackElemCount;i++) if (this->firstTrackElem->findByID(i)->endTime > this->maxTime) this->maxTime = this->firstTrackElem->findByID(i)->endTime; // very bad implemented :/ */ } Vector TrackManager::calcPos() const { return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration); } Vector TrackManager::calcDir() const { return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration); } void Track::tick(float dt) { // PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt); // if (this->localTime <= this->firstTrackElem->duration) // this->jumpTo(this->localTime); // if (this->localTime <= this->maxTime) // this->localTime += dt; // if (this->localTime > this->currentTrackElem->endTime // && this->currentTrackElem->children) // { // if (this->currentTrackElem->jumpTime != 0.0) // this->jumpTo(this->localTime + this->currentTrackElem->jumpTime); // // jump to the next TrackElement and also set the history of the new Element to the old one. // TrackElement* tmpHistoryElem = this->currentTrackElem; // this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem)); // this->currentTrackElem->history = tmpHistoryElem; // if (this->currentTrackElem->getName()) // { // this->trackText->setText(this->currentTrackElem->getName()); // this->textAnimation->replay(); // } // } // if (this->bindSlave) // { // Vector tmp = this->calcPos(); // 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)); // // Vector v(0.0, 1.0, 0.0); // Quaternion q(-PI/2, v); // quat = quat * q; // // this->bindSlave->setAbsCoor(tmp); // this->bindSlave->setAbsDir(quat); // } } /** * @returns the main TrackNode */ PNode* TrackManager::getTrackNode() { return this->trackNode; }