[Teleus-cvs] teleus/src/obj cube.cpp,1.9,1.10 cube.hpp,1.6,1.7 object.cpp,1.10,1.11 object.hpp,1.8,1
Status: Inactive
Brought to you by:
spiffgq
|
From: Daniel R. <sp...@us...> - 2004-05-25 23:10:11
|
Update of /cvsroot/teleus/teleus/src/obj In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17475/src/obj Modified Files: cube.cpp cube.hpp object.cpp object.hpp ship.cpp ship.hpp Log Message: Modified these classes to rely on math::Mass to update physics and such. Index: object.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/object.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** object.hpp 25 Feb 2004 02:23:26 -0000 1.8 --- object.hpp 25 May 2004 23:10:00 -0000 1.9 *************** *** 40,47 **** using math::Vector3d; ! using math::PointMass; using math::Quaternion; ! class Object : public PointMass { friend class gfx::Camera; --- 40,47 ---- using math::Vector3d; ! using math::Mass; using math::Quaternion; ! class Object : public Mass { friend class gfx::Camera; *************** *** 49,52 **** --- 49,54 ---- protected: + #if 0 + // Delegated to Mass class. float mWidth; float mHeight; *************** *** 63,66 **** --- 65,69 ---- Quaternion mRotation; + #endif public: *************** *** 70,73 **** --- 73,78 ---- virtual void updatePhysics (double timeInc); + + #if 0 void setBoundingBox (float height, float width, float length); void setBoundingSphere (float radius); *************** *** 87,90 **** --- 92,96 ---- void setOri (const Vector3d&); void setRot (const Quaternion&); + #endif }; Index: object.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/object.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** object.cpp 25 Feb 2004 06:34:00 -0000 1.10 --- object.cpp 25 May 2004 23:10:00 -0000 1.11 *************** *** 30,34 **** #include "math/vector.hpp" #include "object.hpp" ! #include "debug.hpp" --- 30,34 ---- #include "math/vector.hpp" #include "object.hpp" ! #include "util/debugrecord.hpp" #include "debug.hpp" *************** *** 48,52 **** */ Object::Object () ! : PointMass () { //DEBUG_PRINT ("Creating object\n"); --- 48,52 ---- */ Object::Object () ! : Mass () { //DEBUG_PRINT ("Creating object\n"); *************** *** 62,65 **** --- 62,66 ---- Object::~Object (){} + #if 0 /** * \brief Changes the size of this object. *************** *** 85,88 **** --- 86,90 ---- } + /** * \brief Changes the bounding sphere radius *************** *** 99,102 **** --- 101,105 ---- mRadius = radius; } + #endif /** *************** *** 115,118 **** --- 118,124 ---- void Object::updatePhysics (double timeInc){ + Mass::updatePhysics(timeInc); + + #if 0 // Rotate the object mRotation *= Quaternion::getVector4d ( *************** *** 127,130 **** --- 133,137 ---- mForwardVector = mRotation.directionVector(); mForwardVector.normalize(); + #endif #if 0 *************** *** 142,145 **** --- 149,153 ---- #endif + #if 0 // Update rotation: for (int i = 0; i < 3; ++i){ *************** *** 151,157 **** --- 159,167 ---- } } + #endif } + #if 0 /** * \brief Returns the speed of this object. *************** *** 278,281 **** --- 288,292 ---- mRotation = newRot; } + #endif /** *************** *** 296,299 **** --- 307,311 ---- */ + #if 0 /** * \var float Object::mWidth *************** *** 353,356 **** --- 365,370 ---- */ + #endif + } // END NAMESPACE obj } // END NAMESPACE teleus Index: cube.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/cube.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** cube.hpp 25 Feb 2004 02:23:26 -0000 1.6 --- cube.hpp 25 May 2004 23:10:00 -0000 1.7 *************** *** 29,32 **** --- 29,33 ---- #include "object.hpp" + #include "ship.hpp" #include "gfx/gfx.hpp" #include "gfx/color.hpp" *************** *** 35,39 **** namespace obj { ! class Cube : public Object { protected: --- 36,40 ---- namespace obj { ! class Cube : public Ship { protected: Index: cube.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/cube.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** cube.cpp 11 Mar 2004 03:20:42 -0000 1.9 --- cube.cpp 25 May 2004 23:10:00 -0000 1.10 *************** *** 46,49 **** --- 46,50 ---- */ Cube::Cube (float width, float length, float depth) + : Ship () { // ok, these were bad choices for names :) *************** *** 51,54 **** --- 52,56 ---- mHeight = length; mLength = depth; + mRadius = math::boundingSphere(width, length, depth); } *************** *** 73,86 **** void Cube::updatePhysics (double timeInc){ ! // Update rotation ! Object::updatePhysics(timeInc); ! // Update position ! PointMass::updatePhysics(timeInc); ! // Reverse velocity if we get too far away from the origin. ! if (mPosition.length() > 10000.0){ ! mVelocity = -mVelocity; } } --- 75,100 ---- void Cube::updatePhysics (double timeInc){ ! //resetForces(); ! // If we are greater than 1000 units away from the center, ! // we'll apply a centripetal force. Just for fun. ! /* ! if (mPosition.lengthSquared() > 1000000.0){ ! // The force points to the origin ! Vector3d force = -mPosition.normalized(); ! ! // The force's strength depends on how far from the ! // maximum radius the Cube is. As the cube returns ! // to the appropriate spot, the force will diminish. ! force *= (mPosition.length() - 1000.0) * 100.0; ! ! // The force is world oriented. Add it to the total ! //forces acting on this body. ! addForceWorld(force, mPosition); } + */ + + Ship::updatePhysics(timeInc); } *************** *** 117,121 **** Cube * Cube::getRandomCube (){ ! math::Random rand; gfx::Color3f color; --- 131,135 ---- Cube * Cube::getRandomCube (){ ! static math::Random rand(747393); gfx::Color3f color; *************** *** 125,128 **** --- 139,143 ---- math::Vector3d velocity; math::Vector3d rotVel; + math::Vector3d moi; double mass; *************** *** 141,145 **** dimensions.z = rand.floatNumber (10.0f, 100.0f); ! const double MAX_POSITION = 4000.0f; position.x = rand.floatNumber (-MAX_POSITION, MAX_POSITION); position.y = rand.floatNumber (-MAX_POSITION, MAX_POSITION); --- 156,160 ---- dimensions.z = rand.floatNumber (10.0f, 100.0f); ! const double MAX_POSITION = 900.0f; position.x = rand.floatNumber (-MAX_POSITION, MAX_POSITION); position.y = rand.floatNumber (-MAX_POSITION, MAX_POSITION); *************** *** 156,171 **** velocity.z = 0.0; //math::randFloat(0.0f, 100.0f); #else ! velocity.x = rand.floatNumber (0.0f, 100.0f); ! velocity.y = rand.floatNumber (0.0f, 100.0f); ! velocity.z = rand.floatNumber (0.0f, 100.0f); #endif ! rotVel.x = rand.floatNumber (0.0f, 1.0f); ! rotVel.y = rand.floatNumber (0.0f, 1.0f); ! rotVel.z = rand.floatNumber (0.0f, 1.0f); mass = (dimensions.x * dimensions.y * dimensions.z) / 10.0f; radius = dimensions.length(); // Assign the generated properties --- 171,191 ---- velocity.z = 0.0; //math::randFloat(0.0f, 100.0f); #else ! velocity.x = rand.floatNumber (-100.0f, 100.0f); ! velocity.y = rand.floatNumber (-100.0f, 100.0f); ! velocity.z = rand.floatNumber (-100.0f, 100.0f); #endif ! rotVel.x = 0.0; // rand.floatNumber (0.0f, 1.0f); ! rotVel.y = 0.0; // rand.floatNumber (0.0f, 1.0f); ! rotVel.z = 0.0; // rand.floatNumber (0.0f, 1.0f); mass = (dimensions.x * dimensions.y * dimensions.z) / 10.0f; radius = dimensions.length(); + // TODO: Verify the following line. I'm pretty sure that + // the object is sitting facing down the +z axis, with +y + // up and +x to the left. + moi = math::rectanglePrismMOI(mass, dimensions.z, dimensions.x, dimensions.y); + // Assign the generated properties *************** *** 177,183 **** c->mColor = color; c->mPosition = c->mLastPosition = position; ! c->mRotation = math::Vector4d::getVector4d (angle, orientation.x, orientation.y, orientation.z); c->mVelocity = velocity; ! c->mRotationalVelocity = rotVel; return c; --- 197,204 ---- c->mColor = color; c->mPosition = c->mLastPosition = position; ! //c->mRotation = math::Vector4d::getVector4d (angle, orientation.x, orientation.y, orientation.z); c->mVelocity = velocity; ! //c->mAngVelocity = rotVel; ! c->setInertia(moi.x, moi.y, moi.z); return c; Index: ship.hpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/ship.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ship.hpp 25 Feb 2004 02:23:26 -0000 1.6 --- ship.hpp 25 May 2004 23:10:00 -0000 1.7 *************** *** 25,29 **** */ ! #ifndef TELEUS_SHIP_HEADER #define TELEUS_SHIP_OBJECT_HEADER 1 --- 25,29 ---- */ ! #ifndef TELEUS_SHIP_OBJECT_HEADER #define TELEUS_SHIP_OBJECT_HEADER 1 Index: ship.cpp =================================================================== RCS file: /cvsroot/teleus/teleus/src/obj/ship.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ship.cpp 25 Feb 2004 02:23:26 -0000 1.8 --- ship.cpp 25 May 2004 23:10:00 -0000 1.9 *************** *** 29,32 **** --- 29,33 ---- #include "math/vector.hpp" #include "math/physics.hpp" + #include "util/debugrecord.hpp" #include "debug.hpp" *************** *** 187,197 **** void Ship::killVelocity (){ ! mVelocity.x = 0.0f; ! mVelocity.y = 0.0f; ! mVelocity.z = 0.0f; - mRotationalVelocity.x = 0.0f; - mRotationalVelocity.y = 0.0f; - mRotationalVelocity.z = 0.0f; } --- 188,197 ---- void Ship::killVelocity (){ ! debugrecord::printf("Kill Velocity\n"); ! ! resetForces(); ! mAngVelocity.zero(); ! mVelocity.zero(); } *************** *** 210,213 **** --- 210,214 ---- void Ship::updatePhysics (double timeInc){ + #if 0 // TODO: Replace these constants with variables so different *************** *** 326,330 **** --- 327,399 ---- mRotationalVelocity.r = mRotationalVelocity.r + (rollAcceleration * timeInc); + #endif + + // TODO: Replace these constants with variables so different + // ships can have different thuster force. + const float MAX_FORWARD_FORCE = 10000.0; // newtons + const float MAX_ROTATIONAL_FORCE = 200.0; // newtons + + // Create force for the main engine + Vector3d mainEngineThrustForce (0.0, 0.0, 1.0); + Vector3d mainEngineThrustLoc (0.0, 0.0, -10.0); + mainEngineThrustForce *= MAX_FORWARD_FORCE * mForwardThrust; + addForceBody(mainEngineThrustForce, mainEngineThrustLoc); + + // Create force for the RCS thrusters + Vector3d RCSThrustForce; + Vector3d RCSThrustLoc; + + // YAW + RCSThrustForce.x = MAX_ROTATIONAL_FORCE * mYawThrust; + RCSThrustLoc.z = 10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + RCSThrustForce.zero(); + RCSThrustLoc.zero(); + + RCSThrustForce.x = -(MAX_ROTATIONAL_FORCE * mYawThrust); + RCSThrustLoc.z = -10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + RCSThrustForce.zero(); + RCSThrustLoc.zero(); + + + // PITCH + RCSThrustForce.y = MAX_ROTATIONAL_FORCE * mPitchThrust; + RCSThrustLoc.z = 10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + RCSThrustForce.zero(); + RCSThrustLoc.zero(); + + RCSThrustForce.y = -(MAX_ROTATIONAL_FORCE * mPitchThrust); + RCSThrustLoc.z = -10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + RCSThrustForce.zero(); + RCSThrustLoc.zero(); + + // ROLL + RCSThrustForce.y = MAX_ROTATIONAL_FORCE * mRollThrust; + RCSThrustLoc.x = 10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + RCSThrustForce.zero(); + RCSThrustLoc.zero(); + + RCSThrustForce.y = -(MAX_ROTATIONAL_FORCE * mRollThrust); + RCSThrustLoc.x = -10.0; + addForceBody(RCSThrustForce, RCSThrustLoc); + + + /* + // A temporary centripetal force, just for fun. + + Vector3d gravVec = -mPosition.normalized(); + gravVec *= 900.0; + addForceWorld (gravVec, mPosition); + */ Object::updatePhysics (timeInc); |