/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 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: main-programmer: Patrick Boenzli co-programmer: ... */ #include "p_node.h" using namespace std; /** \brief standard constructor \todo this constructor is not jet implemented - do it */ PNode::PNode () { this->children = new tList(); this->bCoorChanged = true; this->bDirChanged = true; } /** \brief standard deconstructor \todo this deconstructor is not jet implemented - do it */ PNode::~PNode () { this->children->destroy(); delete this->children; } /** \brief get relative coordinates \returns relative coordinates to its parent */ Vector PNode::getRelCoor () { Vector r = this->relCoordinate; /* return a copy, so it can't be modified */ return r; } /** \brief set relative coordinates \param relative coordinates to its parent it is very importand, that you use this function, if you want to update the relCoordinates. If you don't use this, the PNode won't recognize, that something has changed and won't update the children Nodes. */ void PNode::setRelCoor (Vector relCoord) {} /** \brief get absolute coordinates \returns absolute coordinates from (0,0,0) */ Vector PNode::getAbsCoor () {} /** \brief get relative coordinates \returns relative coordinates to its parent it is very importand, that you use this function, if you want to update the absCoordinates. If you don't use this, the PNode won't recognize, that something has changed and won't update the children Nodes. */ void PNode::setAbsCoor (Vector absCoord) {} /** \brief shift coordinate (abs and rel) \param shift vector this function shifts the current coordinates about the vector shift. this is usefull because from some place else you can: PNode* someNode = ...; Vector objectMovement = calculateShift(); someNode->shiftCoor(objectMovement); elsewhere you would have to: PNode* someNode = ...; Vector objectMovement = calculateShift(); Vector currentCoor = someNode->getRelCoor(); Vector newCoor = currentCoor + objectMovement; someNode->setRelCoor(newCoor); yea right... shorter... */ void PNode::shiftCoor (Vector shift) {} /** \brief get relative direction \returns relative direction to its parent */ Quaternion PNode::getRelDir () {} /** \brief set relative direction \param relative direction to its parent it is very importand, that you use this function, if you want to update the relDirection. If you don't use this, the PNode won't recognize, that something has changed and won't update the children Nodes. */ void PNode::setRelDir (Quaternion relDir) {} /** \brief gets the absolute direction (0,0,1) \returns absolute coordinates */ Quaternion PNode::getAbsDir () {} /** \brief sets the absolute direction (0,0,1) \param absolute coordinates it is very importand, that you use this function, if you want to update the absDirection. If you don't use this, the PNode won't recognize, that something has changed and won't update the children Nodes. */ void PNode::setAbsDir (Quaternion absDir) {} /** \brief shift coordinate (abs and rel) \param shift vector this function shifts the current coordinates about the vector shift. this is usefull because from some place else you can: PNode* someNode = ...; Quaternion objectMovement = calculateShift(); someNode->shiftCoor(objectMovement); elsewhere you would have to: PNode* someNode = ...; Quaternion objectMovement = calculateShift(); Quaternion currentCoor = someNode->getRelCoor(); Quaternion newCoor = currentCoor + objectMovement; someNode->setRelCoor(newCoor); yea right... shorter... */ void PNode::shiftDir (Quaternion shift) {} /** \brief adds a child and makes this node to a parent \param child reference use this to add a child to this node. */ void PNode::addChild (PNode* pNode) { this->addChild(pNode, DEFAULT_MODE); } /** \brief adds a child and makes this node to a parent \param child reference \param on which changes the child should also change ist state use this to add a child to this node. */ void PNode::addChild (PNode* pNode, parentingMode mode) { pNode->mode = mode; this->children->add (pNode); } /** /brief removes a child from the node */ void PNode::removeChild (PNode* pNode) { this->children->remove (pNode); } /** \brief sets the parent of this PNode */ void PNode::setParent (PNode* parent) { this->parent = parent; } /** \brief updates the absCoordinate/absDirection this is used to go through the parent-tree to update all the absolute coordinates and directions. this update should be done by the engine, so you don't have to worry, normaly... */ void PNode::update(long timeStamp) { if(this->parent == NULL) printf("PNode::upate(long timeStamp) - parent is NULL..."); if( this->bCoorChanged && this->timeStamp != DataTank::timeStamp) { /* update the current absCoordinate */ this->absCoordinate = parent->getAbsCoor () + this->relCoordinate; } if( this->bDirChanged && this->timeStamp != DataTank::timeStamp) { /* update the current absDirection - remember * means rotation around sth.*/ this->absDirection = parent->getAbsDir () * this->relDirection; } PNode* pn = this->children->enumerate(); while( pn != NULL) { pn->update(timeStamp); pn = this->children->nextElement(); } this->timeStamp = timeStamp; this->bCoorChanged = false; this->bDirChanged = false; }