00001 /* 00002 * physics.cpp 00003 * 00004 * Created on: Dec 19, 2011 00005 * Author: sushil 00006 */ 00007 #include <assert.h> 00008 00009 #include <OgreVector3.h> 00010 00011 #include <physics.h> 00012 #include <ent.h> 00013 #include <utils.h> 00014 #include "DEBUG.h" 00015 00016 void FastEcslent::Physics2D1::init(){ 00017 entity->desiredSpeed = entity->speed; 00018 entity->desiredHeading = entity->heading; 00019 } 00020 00021 void FastEcslent::Physics2D1::doHelmsman(double dtime){ 00022 00023 if (kInvalidFloat == entity->desiredSpeed || kInvalidFloat == entity->desiredHeading) 00024 return; 00025 //speed 00026 timeScaledAcceleration = entity->maxAcceleration * dtime; 00027 entity->speed += clamp(entity->desiredSpeed - entity->speed, -timeScaledAcceleration, +timeScaledAcceleration); 00028 cosYaw = cos(-entity->heading); 00029 sinYaw = sin(-entity->heading); 00030 entity->vel = Ogre::Vector3(entity->speed * cosYaw, 0.0f, entity->speed * sinYaw); 00031 entity->pos = entity->pos + (entity->vel * dtime); 00032 00033 //heading 00034 this->timeScaledRotationalSpeed = entity->maxRotationalSpeed * dtime; 00035 //rotate only if you are moving at > 0.5 00036 if(entity->speed > 0.5f){ 00037 angleDiff = differenceBetweenAngles(entity->desiredHeading, entity->heading); 00038 dHeading = clamp(angleDiff, -timeScaledRotationalSpeed, +timeScaledRotationalSpeed); 00039 entity->heading += dHeading; 00040 } 00041 00042 DEBUG(std::cout << "Speed: " << entity->speed << ", Heading: " << entity->heading << std::endl;) 00043 } 00044 00045 00046 void FastEcslent::Physics2D1::tick(double dtime){ 00047 doHelmsman(dtime); 00048 }