#include #include "gravDCS.h" /************************************************************************/ /* Performer type data */ pfType *gravDCS::classType_ = NULL; void gravDCS::init(void) { if (classType_ == NULL) { grabberDCS::init(); /* Initialize the parent class */ classType_ = new pfType(grabberDCS::getClassType(), "gravDCS"); /* Create the new pfType for this class, based on the parent class's type */ } } /************************************************************************/ gravDCS::gravDCS(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 gravDCS::setPosition(float x,float y,float z) { position_.set(x,y,z); setTrans(x,y,z); } void gravDCS::setVelocity(float x,float y,float z) { velocity_.set(x,y,z); } void gravDCS::setGravity(float g) { gravity_ = g; } void gravDCS::grab(void) { velocity_.set(0,0,0); grabberDCS::grab(); } void gravDCS::release(void) { pfMatrix mat; pfVec3 zero; getMat(mat); zero.set(0,0,0); position_.xformPt(zero,mat); grabberDCS::release(); } int gravDCS::app(pfTraverser *trav) { if (!isGrabbed()) { float dt; dt = pfGetTime() - prevTime_; if (dt < 1.0f) { position_ += velocity_ * dt; if (position_[2] < 0.0f) { if (velocity_[2] < 0.0f) velocity_[2] *= -0.7f; } else velocity_[2] -= gravity_ * dt; } setTrans(position_[0],position_[1],position_[2]); } prevTime_ = pfGetTime(); return grabberDCS::app(trav); } int gravDCS::needsApp(void) { return TRUE; }