#include #include "bounceDCS.h" /************************************************************************/ /* Performer type data */ pfType *bounceDCS::classType_ = NULL; void bounceDCS::init(void) { if (classType_ == NULL) { pfDCS::init(); /* Initialize the parent class */ classType_ = new pfType(pfDCS::getClassType(), "bounceDCS"); /* Create the new pfType for this class, based on the parent class's type */ } } /************************************************************************/ bounceDCS::bounceDCS(void) { setType(classType_); /* set the Performer type of this instance */ position_.set(0,0,0); velocity_.set(0,0,0); gravity_ = 10.0f; prevTime_ = -1.0f; } void bounceDCS::setPosition(float x,float y,float z) { position_.set(x,y,z); } void bounceDCS::setVelocity(float x,float y,float z) { velocity_.set(x,y,z); } void bounceDCS::setGravity(float g) { gravity_ = g; } int bounceDCS::app(pfTraverser *trav) { float dt; dt = pfGetTime() - prevTime_; if (dt < 1.0f) { position_ += velocity_ * dt; if (position_[2] < 0.0f) { if (velocity_[2] < 0.0f) velocity_[2] *= -1.0f; } else velocity_[2] -= gravity_ * dt; } setTrans(position_[0],position_[1],position_[2]); prevTime_ = pfGetTime(); return pfDCS::app(trav); } int bounceDCS::needsApp(void) { return TRUE; }