opal-commits Mailing List for Open Physics Abstraction Layer (Page 17)
Status: Inactive
Brought to you by:
tylerstreeter
You can subscribe to this list here.
| 2005 |
Jan
|
Feb
(162) |
Mar
(134) |
Apr
(113) |
May
(13) |
Jun
(60) |
Jul
(18) |
Aug
(25) |
Sep
|
Oct
(2) |
Nov
(35) |
Dec
(76) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
(3) |
Apr
(8) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
|
Feb
(1) |
Mar
(12) |
Apr
(16) |
May
(2) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
(3) |
Oct
|
Nov
|
Dec
(3) |
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(15) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:52
|
Update of /cvsroot/opal/opal/samples/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854/samples/src Modified Files: BaseOpalApp.h ExampleApplication.h PhysicalCamera.h TemplateApp.cpp Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: PhysicalCamera.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/PhysicalCamera.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PhysicalCamera.h 3 Apr 2005 00:11:42 -0000 1.1 --- PhysicalCamera.h 4 Apr 2005 13:09:10 -0000 1.2 *************** *** 43,52 **** mGraspingSensor = sim->createRaycastSensor(); mGraspedObject = NULL; ! mGraspPos.set(0, 0, -5); ! mMaxReach = 8; mEyeHeight = eyeHeight; - //mGraspOffset.makeIdentity(); - // Setup OPAL Solid, if necessary. if (isPhysical) --- 43,50 ---- mGraspingSensor = sim->createRaycastSensor(); mGraspedObject = NULL; ! mGraspOffset.set(0, 0, -5); ! mMaxReach = 100; mEyeHeight = eyeHeight; // Setup OPAL Solid, if necessary. if (isPhysical) *************** *** 92,134 **** void update(opal::real dt) { - if (!mIsPhysical && !mGraspedObject) - { - return; - } - - // Keep solid upright by resetting its orientation. Thus the - // camera Solid's orientation is always the same. - opal::Point3r p = mSolid->getPosition(); - opal::Matrix44r m; - m.translate(p[0], p[1], p[2]); - mSolid->setTransform(m); - - // Set the Ogre camera's position. It must be at the same position - // as the OPAL Solid. - mOgreCamera->setPosition((Ogre::Real)p[0], (Ogre::Real)p[1], - (Ogre::Real)p[2]); - - // Update the ray casting Sensor's ray. - Ogre::Vector3 camForward = mOgreCamera->getDirection(); - if (0 != camForward.squaredLength()) - { - camForward.normalise(); - } - opal::Vec3r rayDir(camForward[0], camForward[1], camForward[2]); if (mIsPhysical) { ! // The ray's origin will be updated automatically since it is ! // attached to the camera's Solid. Its direction should be set ! // manually here because we constantly reset the camera's ! // orientation. ! opal::Rayr r(opal::Point3r(), rayDir); ! mGraspingSensor->setRay(r); ! } ! else ! { ! // The ray should start at the camera's position and fire ! // straight forward into the scene. ! opal::Rayr r(p, rayDir); ! mGraspingSensor->setRay(r); } --- 90,106 ---- void update(opal::real dt) { if (mIsPhysical) { ! // Keep solid upright by resetting its orientation. Thus the ! // camera Solid's orientation is always the same. ! opal::Point3r p = mSolid->getPosition(); ! opal::Matrix44r m; ! m.translate(p[0], p[1], p[2]); ! mSolid->setTransform(m); ! ! // Set the Ogre camera's position. It must be at the same ! // position as the OPAL Solid. ! mOgreCamera->setPosition((Ogre::Real)p[0], (Ogre::Real)p[1], ! (Ogre::Real)p[2]); } *************** *** 139,164 **** mGraspedObject->setSleeping(false); ! // TODO: use 3 vecs for motor, not transform ! ! // Get the camera's transform. ! opal::Matrix44r camTransform; ! getOpalMatFromOgreCam(camTransform); ! ! // Set the desired transform for the grasped object. ! //mGraspingMotor->setDesiredTransform(camTransform * mGraspOffset); ! mGraspingMotor->setDesiredTransform(camTransform); ! ! // Since the Ogre camera's matrix doesn't include position, now ! // set the desired position. ! if (SHORT_RANGE_GRASP_MODE == mGraspMode) ! { ! // mGraspPos is a local offset from the camera. ! mGraspingMotor->setDesiredPosition(camTransform * mGraspPos); ! } ! else if (LONG_RANGE_GRASP_MODE == mGraspMode) ! { ! // mGraspPos is the global desired pos. ! mGraspingMotor->setDesiredPosition(mGraspPos); ! } // Drop object if it gets too far away. --- 111,117 ---- mGraspedObject->setSleeping(false); ! // Set the Motor's global desired position for the Solid ! // (at its attach position). ! mGraspingMotor->setDesiredPosition(getGraspGlobalPos()); // Drop object if it gets too far away. *************** *** 274,278 **** // position relative to the camera as the grasp offset. ! opal::RaycastResult result = mGraspingSensor->fireRay(mMaxReach); if (result.solid && !result.solid->isStatic()) --- 227,260 ---- // position relative to the camera as the grasp offset. ! // First update the ray casting Sensor's ray. ! Ogre::Vector3 camForward = mOgreCamera->getDirection(); ! if (0 != camForward.squaredLength()) ! { ! camForward.normalise(); ! } ! opal::Vec3r rayDir(camForward[0], camForward[1], ! camForward[2]); ! if (mIsPhysical) ! { ! // The ray's origin will be updated automatically since ! // it is attached to the camera's Solid. Its direction ! // should be set manually here because we constantly ! // reset the camera's orientation. ! opal::Rayr r(opal::Point3r(), rayDir); ! mGraspingSensor->setRay(r); ! } ! else ! { ! // The ray should start at the camera's position and fire ! // straight forward into the scene. ! Ogre::Vector3 ogreCamPos = mOgreCamera->getPosition(); ! opal::Rayr r(opal::Point3r(ogreCamPos[0], ogreCamPos[1], ! ogreCamPos[2]), rayDir); ! mGraspingSensor->setRay(r); ! } ! ! // Fire the ray. ! opal::RaycastResult result = ! mGraspingSensor->fireRay(mMaxReach); if (result.solid && !result.solid->isStatic()) *************** *** 284,292 **** opal::SpringMotorData data; data.solid = result.solid; ! data.mode = opal::LINEAR_AND_ANGULAR_MODE; ! data.linearKd = 15; ! data.linearKs = 250; ! data.angularKd = 1; ! data.angularKs = 5; // Desired position/orientation will be updated in the // "update" function. --- 266,272 ---- opal::SpringMotorData data; data.solid = result.solid; ! data.mode = opal::LINEAR_MODE; ! data.linearKd = 3; ! data.linearKs = 50; // Desired position/orientation will be updated in the // "update" function. *************** *** 296,327 **** if (LONG_RANGE_GRASP_MODE == mGraspMode) { ! mGraspPos = result.intersection; } - - // TODO: try just passing in the matrix and let OPAL calc these three vecs - //Ogre::Vector3 f = mOgreCamera->getDirection(); - //Ogre::Vector3 u = mOgreCamera->getUp(); - //Ogre::Vector3 r = mOgreCamera->getRight(); - //opal::Vec3r forward(f[0], f[1], f[2]); - //opal::Vec3r up(u[0], u[1], u[2]); - //opal::Vec3r right(r[0], r[1], r[2]); - //mGraspingMotor->setDesiredOrientation( forward, up, right ); - - //Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix(); - ////ogreMat.setScale(Ogre::Vector3(1,1,1)); - //opal::Matrix44r camTransform(ogreMat[0][0], ogreMat[1][0], ogreMat[2][0], ogreMat[3][0], - // ogreMat[0][1], ogreMat[1][1], ogreMat[2][1], ogreMat[3][1], - // ogreMat[0][2], ogreMat[1][2], ogreMat[2][2], ogreMat[3][2], - // ogreMat[0][3], ogreMat[1][3], ogreMat[2][3], ogreMat[3][3]); - - //// setup grasp offset transform - //camTransform.fastInvert(); - //mGraspOffset = mGraspedObject->getTransform() * camTransform; - // - //// set desired transform - //mGraspingMotor->setDesiredTransform(mGraspedObject->getTransform()); - - //// since the previous matrix doesn't include position, now set the desired position - //mGraspingMotor->setDesiredPos(calcGraspPos()); } } --- 276,281 ---- if (LONG_RANGE_GRASP_MODE == mGraspMode) { ! mGraspOffset.set(0, 0, -result.distance); } } } *************** *** 341,344 **** --- 295,311 ---- } + /// Returns true if the camera is grasping an object. + bool isGrasping() + { + if (mGraspedObject) + { + return true; + } + else + { + return false; + } + } + /// Adjust the camera's pitch by adding an angle to its yaw /// relative to its current yaw. *************** *** 377,397 **** /// Sets the desired position for grasped objects, represented as a /// local offset from the camera's transform. This only applies ! /// in the short-range grasp mode. ! void setGraspOffset(const opal::Point3r& offset) { if (SHORT_RANGE_GRASP_MODE == mGraspMode) { ! mGraspPos = offset; } } ! /// Returns the desired position for grasped objects. In short ! /// range mode this is a local offset from the camera's transform. ! /// In long range mode this is the global desired position. ! const opal::Point3r& getGraspPos()const { ! return mGraspPos; } /// Sets the maximum reach distance used for grasping. void setMaxReach(opal::real r) --- 344,403 ---- /// Sets the desired position for grasped objects, represented as a /// local offset from the camera's transform. This only applies ! /// in the short-range grasp mode. In long-range grasp mode the ! /// offset is calculated automatically based on a ray cast ! /// into the scene. ! void setGraspOffset(const opal::Vec3r& offset) { if (SHORT_RANGE_GRASP_MODE == mGraspMode) { ! mGraspOffset = offset; } } ! /// Returns the desired position for grasped objects relative to ! /// the camera. ! const opal::Vec3r& getGraspOffset()const { ! return mGraspOffset; } + /// Returns the position of the grasping spring's attach point + /// on the grasped object in global coordinates. This is only + /// meaningful when an object is being grasped. + opal::Point3r getAttachGlobalPos()const + { + return mGraspingMotor->getGlobalAttachPoint(); + } + + /// Returns the desired position for grasped objects in global + /// coordinates. + opal::Point3r getGraspGlobalPos()const + { + Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix().inverse(); + //Ogre::Vector3 camPos = mOgreCamera->getPosition(); + Ogre::Vector3 graspOffset(mGraspOffset[0], mGraspOffset[1], + mGraspOffset[2]); + + // Transform the offset vector to global space. + graspOffset = ogreMat * graspOffset; + + return opal::Point3r(graspOffset[0], graspOffset[1], + graspOffset[2]); + } + + //opal::Point3r getGlobalPosFromLocalOffset(opal::Vec3r localOffset) + //{ + // Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix().inverse(); + // //Ogre::Vector3 camPos = mOgreCamera->getPosition(); + // Ogre::Vector3 offset(localOffset[0], localOffset[1], + // localOffset[2]); + + // // Transform the offset vector to global space. + // offset = ogreMat * offset; + + // // Combine the camera position with the local offset vector. + // return opal::Point3r(offset[0], offset[1], offset[2]); + //} + /// Sets the maximum reach distance used for grasping. void setMaxReach(opal::real r) *************** *** 411,424 **** //opal::Matrix44r mGraspOffset; ! void getOpalMatFromOgreCam(opal::Matrix44r& mat) ! { ! // Make an OPAL matrix copy of the Ogre camera's transform. ! Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix(); ! mat.set( ! ogreMat[0][0], ogreMat[1][0], ogreMat[2][0], ogreMat[3][0], ! ogreMat[0][1], ogreMat[1][1], ogreMat[2][1], ogreMat[3][1], ! ogreMat[0][2], ogreMat[1][2], ogreMat[2][2], ogreMat[3][2], ! ogreMat[0][3], ogreMat[1][3], ogreMat[2][3], ogreMat[3][3]); ! } /// True if the camera uses physics. --- 417,430 ---- //opal::Matrix44r mGraspOffset; ! //void getOpalMatFromOgreCam(opal::Matrix44r& mat) ! //{ ! // // Make an OPAL matrix copy of the Ogre camera's transform. ! // Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix(); ! // mat.set( ! // ogreMat[0][0], ogreMat[1][0], ogreMat[2][0], ogreMat[3][0], ! // ogreMat[0][1], ogreMat[1][1], ogreMat[2][1], ogreMat[3][1], ! // ogreMat[0][2], ogreMat[1][2], ogreMat[2][2], ogreMat[3][2], ! // ogreMat[0][3], ogreMat[1][3], ogreMat[2][3], ogreMat[3][3]); ! //} /// True if the camera uses physics. *************** *** 447,453 **** opal::Solid* mGraspedObject; ! /// The desired position for grasped objects. Has different ! /// meanings depending on the grasp mode. ! opal::Point3r mGraspPos; /// When the camera attempts to grasp an object by casting a ray, --- 453,458 ---- opal::Solid* mGraspedObject; ! /// The desired position for grasped objects in global coordinates. ! opal::Vec3r mGraspOffset; /// When the camera attempts to grasp an object by casting a ray, Index: TemplateApp.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/src/TemplateApp.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TemplateApp.cpp 3 Apr 2005 00:11:42 -0000 1.4 --- TemplateApp.cpp 4 Apr 2005 13:09:10 -0000 1.5 *************** *** 188,201 **** // Use the relative mouse motion to rotate the camera. mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->yawRelative(rotX.valueDegrees()); ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(1)) { ! // The right mouse button is down. } else { ! // The right mouse button is up. } --- 188,201 ---- // Use the relative mouse motion to rotate the camera. mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->pitchRelative(rotX.valueDegrees()); ! // Check mouse button states. ! if (true == mInputDevice->getMouseButton(0)) { ! // The left mouse button is down. } else { ! // The left mouse button is up. } Index: ExampleApplication.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/ExampleApplication.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExampleApplication.h 3 Apr 2005 00:11:42 -0000 1.3 --- ExampleApplication.h 4 Apr 2005 13:09:10 -0000 1.4 *************** *** 71,74 **** --- 71,75 ---- // These internal methods package up the stages in the startup process /** Sets up the application - returns false if the user chooses to abandon configuration. */ + // This function was modifed for the Opal sample apps. virtual bool setup(void) { *************** *** 82,85 **** --- 83,87 ---- chooseSceneManager(); createCamera(); + createPhysicalCamera(); createViewports(); *************** *** 140,143 **** --- 142,148 ---- } + // This function was added for the Opal sample apps. + virtual void createPhysicalCamera() = 0; + // This function was modifed for the Opal sample apps. virtual void createFrameListener() Index: BaseOpalApp.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/BaseOpalApp.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BaseOpalApp.h 3 Apr 2005 00:11:42 -0000 1.4 --- BaseOpalApp.h 4 Apr 2005 13:09:09 -0000 1.5 *************** *** 6,9 **** --- 6,10 ---- #include "PhysicalEntity.h" #include "PhysicalCamera.h" + #include "OgreLine.h" #include <opal/opal.h> *************** *** 18,23 **** mSimulator = opal::createSimulator(); mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); ! // Create the physical camera later after the ExampleApplication ! // has created its Ogre camera. mPaused = false; mNamelessObjectCount = 0; --- 19,25 ---- mSimulator = opal::createSimulator(); mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); ! // The physical camera gets created later after the ! // ExampleApplication has created its Ogre camera. ! mPhysicalCamera = NULL; mPaused = false; mNamelessObjectCount = 0; *************** *** 27,53 **** { delete mPhysicalCamera; ! ! while (!mPhysicalEntityList.empty()) ! { ! delete mPhysicalEntityList.back(); ! mPhysicalEntityList.pop_back(); ! } ! ! // Every pointer in the mPhysicalEntityMap is a duplicate of ! // a pointer in mPhysicalEntityList, so we don't need to ! // delete the memory they point to. ! mPhysicalEntityMap.clear(); mSimulator->destroy(); } protected: ! /// Register the frame listener with the Ogre root so it will ! /// call the listener at the appropriate time. ! virtual void createFrameListener() { - // TODO: move this somewhere else... mPhysicalCamera = new PhysicalCamera(mSimulator, ExampleApplication::mCamera, false); ExampleFrameListener::init(ExampleApplication::mWindow, ExampleApplication::mCamera); --- 29,49 ---- { delete mPhysicalCamera; ! destroyAllPhysicalEntities(); mSimulator->destroy(); } protected: ! /// Create a PhysicalCamera that uses the ExampleApplication's ! /// Ogre camera. ! virtual void createPhysicalCamera() { mPhysicalCamera = new PhysicalCamera(mSimulator, ExampleApplication::mCamera, false); + } + /// Register the frame listener with the Ogre root so it will + /// call the listener at the appropriate time. + virtual void createFrameListener() + { ExampleFrameListener::init(ExampleApplication::mWindow, ExampleApplication::mCamera); *************** *** 97,100 **** --- 93,99 ---- } + // Update the PhysicalCamera. + mPhysicalCamera->update(dt); + // Notify the application about the new frame. appFrameStarted((opal::real)dt); *************** *** 247,251 **** } - // Now remove the Solid. for(size_t i = 0; i<mPhysicalEntityList.size(); ++i) { --- 246,249 ---- *************** *** 286,289 **** --- 284,305 ---- } + /// Destroys all of the PhysicalEntities. + void destroyAllPhysicalEntities() + { + // TODO: fix this (and maybe destroyPhysicalEntity) since + // they break things when called in the middle of the app. + while (!mPhysicalEntityList.empty()) + { + destroyPhysicalEntity(mPhysicalEntityList.back()); + //delete mPhysicalEntityList.back(); + //mPhysicalEntityList.pop_back(); + } + + // Every pointer in the mPhysicalEntityMap is a duplicate of + // a pointer in mPhysicalEntityList, so we don't need to + // delete the memory they point to. + mPhysicalEntityMap.clear(); + } + /// Returns false if we should break out of the main loop. bool handleInput(Ogre::Real dt) |
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:51
|
Update of /cvsroot/opal/opal/src/ODE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854/src/ODE Modified Files: ODESolid.cpp ODESolid.h Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: ODESolid.h =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESolid.h,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** ODESolid.h 23 Mar 2005 07:54:35 -0000 1.66 --- ODESolid.h 4 Apr 2005 13:09:11 -0000 1.67 *************** *** 121,128 **** //virtual void OPAL_CALL setFastRotationAxis(Vec3r axis); - /// Returns the Solid's mass. This will return 0 if the Solid - /// is static. virtual real OPAL_CALL getMass()const; virtual void OPAL_CALL internal_updateOPALTransform(); --- 121,128 ---- //virtual void OPAL_CALL setFastRotationAxis(Vec3r axis); virtual real OPAL_CALL getMass()const; + virtual Matrix44r OPAL_CALL getInertiaTensor()const; + virtual void OPAL_CALL internal_updateOPALTransform(); Index: ODESolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESolid.cpp,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** ODESolid.cpp 3 Apr 2005 00:11:42 -0000 1.80 --- ODESolid.cpp 4 Apr 2005 13:09:10 -0000 1.81 *************** *** 840,843 **** --- 840,865 ---- } + Matrix44r ODESolid::getInertiaTensor()const + { + Matrix44r m; + + if (mData.isStatic) + { + return m; + } + else + { + dMass mass; + dBodyGetMass(mBodyID, &mass); + m.set( + mass.I[0], mass.I[1], mass.I[2], 0, + mass.I[4], mass.I[5], mass.I[6], 0, + mass.I[8], mass.I[9], mass.I[10], 0, + 0, 0, 0, 1); + + return m; + } + } + void ODESolid::setupNewGeom(GeomData* newGeom) { |
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:48
|
Update of /cvsroot/opal/opal/samples/playpen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854/samples/playpen Modified Files: main.cpp Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: main.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/main.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.cpp 3 Apr 2005 00:11:41 -0000 1.4 --- main.cpp 4 Apr 2005 13:09:09 -0000 1.5 *************** *** 38,41 **** --- 38,45 ---- /// Point where new objects are created. opal::Point3r mCreationPoint; + + /// A visual line that represents the PhysicalCamera's grasping + /// spring. + opalSamples::OgreLine* mGraspingSpringLine; }; *************** *** 45,48 **** --- 49,53 ---- mUseShadows = true; mCreationPoint.set(0, 30, 0); + mGraspingSpringLine = NULL; } *************** *** 82,85 **** --- 87,103 ---- mSceneMgr->setSkyBox(true, "Skyboxes/Gray", 5000); + // Create the visual line used to represent the PhysicalCamera's + // grasping spring. Just create two points for now that will + // be updated later. + mGraspingSpringLine = + new opalSamples::OgreLine(); + mGraspingSpringLine->addPoint(0, 0, 0); + mGraspingSpringLine->addPoint(0, 0, 0); + mGraspingSpringLine->update(); + SceneNode* lineNode = + mSceneMgr->getRootSceneNode()->createChildSceneNode("graspLine"); + lineNode->attachObject(mGraspingSpringLine); + mGraspingSpringLine->setVisible(false); + //// Create a physical ground plane. //mSimulator->createPlane(0, 1, 0, 0); *************** *** 117,120 **** --- 135,168 ---- // Do per-frame application specific things here. + // Update the grasping spring line. + if (mPhysicalCamera->isGrasping()) + { + // Update the first point using the desired position. + opal::Point3r graspPos = + mPhysicalCamera->getGraspGlobalPos(); + Ogre::Vector3 point(graspPos[0], graspPos[1], graspPos[2]); + mGraspingSpringLine->setPoint(0, point); + + // Update the second point using the spring's attach point. + opal::Point3r attachPos = mPhysicalCamera->getAttachGlobalPos(); + point[0] = attachPos[0]; + point[1] = attachPos[1]; + point[2] = attachPos[2]; + mGraspingSpringLine->setPoint(1, point); + mGraspingSpringLine->update(); + + if (mGraspingSpringLine->isVisible() == false) + { + mGraspingSpringLine->setVisible(true); + } + } + else + { + if (mGraspingSpringLine->isVisible() == true) + { + mGraspingSpringLine->setVisible(false); + } + } + // Return true to continue looping. return true; *************** *** 139,158 **** } ! // Testing... ! if(mInputDevice->isKeyDown(KC_F)) { ! opalSamples::PhysicalEntity* pe = getPhysicalEntity("object0"); ! if (pe) ! { ! opal::Solid* s = pe->getSolid(); ! if (s) ! { ! opal::Force f; ! f.type = opal::GLOBAL_TORQUE; ! f.duration = (opal::real)0.05; ! f.vec.set(5, 5, 5); ! s->addForce(f); ! } ! } } --- 187,194 ---- } ! // Reset the scene. ! if(mInputDevice->isKeyDown(KC_R)) { ! destroyAllPhysicalEntities(); } *************** *** 163,167 **** if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(0.5, 0.5, 0.5); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); --- 199,203 ---- if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(1, 1, 1); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); *************** *** 178,182 **** if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 0.25; opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); --- 214,218 ---- if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 0.5; opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); *************** *** 193,197 **** if(mInputDevice->isKeyDown(KC_3) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(3, 3, 3); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); --- 229,233 ---- if(mInputDevice->isKeyDown(KC_3) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(4, 4, 4); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); *************** *** 208,216 **** if(mInputDevice->isKeyDown(KC_4) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 1.5; opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); opal::SphereShapeData data; data.radius = radius; s->addShape(data); createPhysicalEntitySphere("", "Plastic/Blue", radius, s); --- 244,253 ---- if(mInputDevice->isKeyDown(KC_4) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 1.68; // testing opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); opal::SphereShapeData data; data.radius = radius; + data.material.density = 1; // testing s->addShape(data); createPhysicalEntitySphere("", "Plastic/Blue", radius, s); *************** *** 253,257 **** if(mInputDevice->isKeyDown(KC_7) && mTimeUntilNextToggle <= 0) { ! createWall(10, 10, opal::Vec3r(2, 0.5, 1)); // Reset the timer for toggle keys. --- 290,294 ---- if(mInputDevice->isKeyDown(KC_7) && mTimeUntilNextToggle <= 0) { ! createWall(6, 8, opal::Vec3r(2, 1, 1)); // Reset the timer for toggle keys. *************** *** 262,266 **** if(mInputDevice->isKeyDown(KC_8) && mTimeUntilNextToggle <= 0) { ! createTower(3, 3, 6, opal::Vec3r(2, 1, 1)); // Reset the timer for toggle keys. --- 299,303 ---- if(mInputDevice->isKeyDown(KC_8) && mTimeUntilNextToggle <= 0) { ! createTower(2, 2, 20, opal::Vec3r(2, 1, 1)); // Reset the timer for toggle keys. *************** *** 268,271 **** --- 305,356 ---- } + //// testing + //if(mInputDevice->isKeyDown(KC_9) && mTimeUntilNextToggle <= 0) + //{ + // opal::Blueprint ragdollBP; + // opal::loadFile(ragdollBP, "SwitcherSceneOpal.xml"); + // opal::Matrix44r offset; + // offset.translate(0, 2, 0); + // offset.rotate(-90, 1, 0, 0); + + // // Instantiate the Blueprint. + // opal::BlueprintInstance instance; + // mSimulator->instantiateBlueprint(instance, ragdollBP, offset, 10); + + // unsigned int i=0; + // for (i=0; i<instance.getNumSolids(); ++i) + // { + // opal::Solid* s = instance.getSolid(i); + // const opal::SolidData& data = s->getData(); + // unsigned int j=0; + // for (j=0; j<data.getNumShapes(); ++j) + // { + // opal::ShapeData* shapeData = data.getShapeData(j); + + // switch(shapeData->getType()) + // { + // case opal::BOX_SHAPE: + // { + // opal::Vec3r dim = ((opal::BoxShapeData*)shapeData)->dimensions; + // Ogre::Vector3 boxDim(dim[0], dim[1], dim[2]); + // createPhysicalEntityBox("", "Plastic/Gray", boxDim, s); + // break; + // } + // case opal::SPHERE_SHAPE: + // { + // opal::real r = ((opal::SphereShapeData*)shapeData)->radius; + // createPhysicalEntitySphere("", "Plastic/Gray", r, s); + // break; + // } + // default: + // assert(false); + // } + // } + // } + + // // Reset the timer for toggle keys. + // mTimeUntilNextToggle = 0.5; + //} + // The following code updates the camera's position. opal::Vec3r cameraDir; *************** *** 366,379 **** // Use the relative mouse motion to rotate the camera. mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->yawRelative(rotX.valueDegrees()); ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(1)) { ! // The right mouse button is down. } else { ! // The right mouse button is up. } --- 451,466 ---- // Use the relative mouse motion to rotate the camera. mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->pitchRelative(rotX.valueDegrees()); ! // Check mouse button states. ! if (true == mInputDevice->getMouseButton(0)) { ! // The left mouse button is down. ! mPhysicalCamera->grasp(); } else { ! // The left mouse button is up. ! mPhysicalCamera->release(); } *************** *** 405,411 **** opal::BoxShapeData boxData; boxData.dimensions = boxDim; s->addShape(boxData); Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); ! createPhysicalEntityBox("", "Plastic/Red", boxDimensions, s); } } --- 492,499 ---- opal::BoxShapeData boxData; boxData.dimensions = boxDim; + boxData.material.friction = 0.001; // testing s->addShape(boxData); Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); ! createPhysicalEntityBox("", "Plastic/Orange", boxDimensions, s); } } *************** *** 457,485 **** } ! for (unsigned int l=0; l<length; ++l) ! { ! for (unsigned int h=0; h<height; ++h) ! { ! opal::real offset = 0; ! if (h % 2 == 0) ! { ! offset = (opal::real)0.5 * boxDim[0]; ! } ! opal::Matrix44r blockTransform = wallBaseTransform; ! blockTransform.translate(l * boxDim[0] + ! 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + ! offset, h * boxDim[1] + 0.5 * boxDim[1], 0); ! opal::Solid* s = mSimulator->createSolid(); ! s->setTransform(blockTransform); ! //s->setSleeping(true); ! opal::BoxShapeData boxData; ! boxData.dimensions = boxDim; ! s->addShape(boxData); ! Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); ! createPhysicalEntityBox("", "Plastic/Red", boxDimensions, s); ! } ! } } } --- 545,575 ---- } ! createWall(length, height, boxDim, wallBaseTransform); ! //for (unsigned int l=0; l<length; ++l) ! //{ ! // for (unsigned int h=0; h<height; ++h) ! // { ! // opal::real offset = 0; ! // if (h % 2 == 0) ! // { ! // offset = (opal::real)0.5 * boxDim[0]; ! // } ! // opal::Matrix44r blockTransform = wallBaseTransform; ! // blockTransform.translate(l * boxDim[0] + ! // 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + ! // offset, h * boxDim[1] + 0.5 * boxDim[1], 0); ! ! // opal::Solid* s = mSimulator->createSolid(); ! // s->setTransform(blockTransform); ! // s->setSleeping(true); ! // opal::BoxShapeData boxData; ! // boxData.dimensions = boxDim; ! // s->addShape(boxData); ! // Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); ! // createPhysicalEntityBox("", "Plastic/Red", boxDimensions, s); ! // } ! //} } } |
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:47
|
Update of /cvsroot/opal/opal/samples/data/materials In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854/samples/data/materials Modified Files: basic.material Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: basic.material =================================================================== RCS file: /cvsroot/opal/opal/samples/data/materials/basic.material,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** basic.material 1 Apr 2005 23:13:48 -0000 1.2 --- basic.material 4 Apr 2005 13:09:08 -0000 1.3 *************** *** 31,34 **** --- 31,50 ---- } + material Plastic/Orange + { + receive_shadows on + + technique + { + pass + { + ambient 1 0.4 0 + diffuse 1 0.4 0 + specular 0.2 0.2 0.2 50 + emissive 0 0 0 + } + } + } + material Plastic/Gray { |
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:23
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854/src Modified Files: Solid.h SpringMotor.cpp Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: SpringMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/SpringMotor.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SpringMotor.cpp 30 Mar 2005 23:26:23 -0000 1.12 --- SpringMotor.cpp 4 Apr 2005 13:09:12 -0000 1.13 *************** *** 91,95 **** LINEAR_AND_ANGULAR_MODE == mData.mode) { ! Vec3r error = mData.desiredPos - mData.solid->getPosition(); Force f; f.singleStep = true; --- 91,95 ---- LINEAR_AND_ANGULAR_MODE == mData.mode) { ! Vec3r error = mData.desiredPos - getGlobalAttachPoint(); Force f; f.singleStep = true; *************** *** 98,101 **** --- 98,104 ---- f.vec = mData.linearKs * error - mData.linearKd * mData.solid->getGlobalLinearVel(); + + // Scale the force vector by the Solid's mass. + f.vec *= mData.solid->getMass(); mData.solid->addForce(f); } *************** *** 154,162 **** rightError *= -rangle; ! // average the vectors into one Vec3r errorAxis = (forwardError + upError + rightError) * globals::OPAL_ONE_THIRD; ! // use the error vector to calculate torque Force f; f.singleStep = true; --- 157,165 ---- rightError *= -rangle; ! // Average the vectors into one. Vec3r errorAxis = (forwardError + upError + rightError) * globals::OPAL_ONE_THIRD; ! // Use the error vector to calculate torque. Force f; f.singleStep = true; *************** *** 164,167 **** --- 167,173 ---- f.vec = mData.angularKs * errorAxis - mData.angularKd * mData.solid->getGlobalAngularVel(); + + // Scale the torque vector by the Solid's intertia tensor. + f.vec = mData.solid->getInertiaTensor() * f.vec; mData.solid->addForce(f); } *************** *** 189,196 **** } ! // Convert the global point to an offset from the Solid's transform. ! Vec3r relVec = p - mData.solid->getPosition(); ! Point3r relPos(relVec[0], relVec[1], relVec[2]); ! mData.attachOffset = mData.solid->getTransform() * relPos; } --- 195,203 ---- } ! // Convert the global point to a local point offset from the Solid's ! // transform. ! Matrix44r inv; ! fastInverse(inv, mData.solid->getTransform()); ! mData.attachOffset = inv * p; } Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** Solid.h 23 Mar 2005 07:54:34 -0000 1.85 --- Solid.h 4 Apr 2005 13:09:11 -0000 1.86 *************** *** 210,213 **** --- 210,217 ---- virtual real OPAL_CALL getMass()const = 0; + /// Returns the Solid's inertia tensor as a 4x4 matrix. This will + /// be the identity matrix if the Solid is static. + virtual Matrix44r OPAL_CALL getInertiaTensor()const = 0; + /// Update the OPAL transform using the physics engine transform. virtual void OPAL_CALL internal_updateOPALTransform() = 0; |
|
From: tylerstreeter <tyl...@us...> - 2005-04-04 13:09:23
|
Update of /cvsroot/opal/opal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1854 Modified Files: todo.txt Log Message: made the SpringMotor depend on the Solid's mass and inertia tensor; fixed bugs in SpringMotor; added to playpen sample app Index: todo.txt =================================================================== RCS file: /cvsroot/opal/opal/todo.txt,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** todo.txt 3 Apr 2005 00:11:44 -0000 1.67 --- todo.txt 4 Apr 2005 13:09:12 -0000 1.68 *************** *** 28,31 **** --- 28,33 ---- * move samples to a separate module? + * within 'samples', make an 'ogre' directory? + * add 'sleeping' user prop to max exporter *************** *** 49,52 **** --- 51,57 ---- - do the same for trimeshes? + * check places where we don't have to iterate over every object + - have a list of solids that have forces applied and only update those per time step + * make trimeshes work - test basic functionality |
|
From: tylerstreeter <tyl...@us...> - 2005-04-03 00:11:53
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12604/src Modified Files: RaycastSensor.cpp RaycastSensor.h Solid.cpp Log Message: minor changes to opal src; added more to playpen sample app Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Solid.cpp 29 Mar 2005 03:05:46 -0000 1.31 --- Solid.cpp 3 Apr 2005 00:11:44 -0000 1.32 *************** *** 181,278 **** } - //void Solid::addLocalForce(const Vec3r& force, real duration) - //{ - // Force f; - // f.type = LOCAL_FORCE; - // f.timeLeft = duration; - // f.vec = force; - // mForceList.push_back(f); - //} - - //void Solid::addGlobalForce(const Vec3r& force, real duration) - //{ - // Force f; - // f.type = GLOBAL_FORCE; - // f.timeLeft = duration; - // f.vec = force; - // mForceList.push_back(f); - //} - - //void Solid::addLocalForceAtLocalPos(const Vec3r& force, - // const Point3r& pos, real duration) - //{ - // Force f; - // f.type = LOCAL_FORCE_AT_LOCAL_POS; - // f.timeLeft = duration; - // f.vec = force; - // f.pos = pos; - // mForceList.push_back(f); - //} - - //void Solid::addLocalForceAtGlobalPos(const Vec3r& force, - // const Point3r& pos, real duration) - //{ - // Force f; - // f.type = LOCAL_FORCE_AT_GLOBAL_POS; - // f.timeLeft = duration; - // f.vec = force; - // f.pos = pos; - // mForceList.push_back(f); - //} - - //void Solid::addGlobalForceAtLocalPos(const Vec3r& force, - // const Point3r& pos, real duration) - //{ - // Force f; - // f.type = GLOBAL_FORCE_AT_LOCAL_POS; - // f.timeLeft = duration; - // f.vec = force; - // f.pos = pos; - // mForceList.push_back(f); - //} - - //void Solid::addGlobalForceAtGlobalPos(const Vec3r& force, - // const Point3r& pos, real duration) - //{ - // Force f; - // f.type = GLOBAL_FORCE_AT_GLOBAL_POS; - // f.timeLeft = duration; - // f.vec = force; - // f.pos = pos; - // mForceList.push_back(f); - //} - - //void Solid::addLocalTorque(const Vec3r& axis, real duration) - //{ - // Force f; - // f.type = LOCAL_TORQUE; - // f.timeLeft = duration; - // f.vec = axis; - // mForceList.push_back(f); - //} - - //void Solid::addGlobalTorque(const Vec3r& axis, real duration) - //{ - // Force f; - // f.type = GLOBAL_TORQUE; - // f.timeLeft = duration; - // f.vec = axis; - // mForceList.push_back(f); - //} - - //void Solid::addLocalTorque(real amount, Vec3r axis, real duration) - //{ - // axis.normalize(); - // axis *= amount; - // addLocalTorque(axis, duration); - //} - - //void Solid::addGlobalTorque(real amount, Vec3r axis, real duration) - //{ - // axis.normalize(); - // axis *= amount; - // addGlobalTorque(axis, duration); - //} - void Solid::internal_applyForces(real stepSize) { --- 181,184 ---- *************** *** 349,367 **** //{ //} - - //BodyState Solid::getState()const - //{ - // BodyState s; - // s.transform = getTransform(); - // s.globalAngularVel = getGlobalAngularVel(); - // s.globalLinearVel = getGlobalLinearVel(); - // return s; - //} - - //void Solid::setState(const BodyState & s) - //{ - // setTransform(s.transform); - // setGlobalAngularVel(s.globalAngularVel); - // setGlobalLinearVel(s.globalLinearVel); - //} } --- 255,257 ---- Index: RaycastSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RaycastSensor.cpp 30 Mar 2005 23:26:22 -0000 1.9 --- RaycastSensor.cpp 3 Apr 2005 00:11:43 -0000 1.10 *************** *** 102,106 **** } ! void RaycastSensor::setRay(Rayr r) { mData.ray = r; --- 102,106 ---- } ! void RaycastSensor::setRay(const Rayr& r) { mData.ray = r; Index: RaycastSensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RaycastSensor.h 23 Mar 2005 04:04:30 -0000 1.6 --- RaycastSensor.h 3 Apr 2005 00:11:44 -0000 1.7 *************** *** 120,124 **** /// Sets the Sensor's ray. ! virtual void OPAL_CALL setRay(Rayr r); /// Returns the Sensor's ray. --- 120,124 ---- /// Sets the Sensor's ray. ! virtual void OPAL_CALL setRay(const Rayr& r); /// Returns the Sensor's ray. |
|
From: tylerstreeter <tyl...@us...> - 2005-04-03 00:11:53
|
Update of /cvsroot/opal/opal/samples/playpen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12604/samples/playpen Modified Files: main.cpp playpen.vcproj Log Message: minor changes to opal src; added more to playpen sample app Index: main.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/main.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 1 Apr 2005 23:13:49 -0000 1.3 --- main.cpp 3 Apr 2005 00:11:41 -0000 1.4 *************** *** 22,32 **** /// Builds a wall of boxes centered at the origin. void createWall(unsigned int length, unsigned height, ! opal::Vec3r boxDim, ! opal::Matrix44r baseTransform = opal::Matrix44r()); ! /// Builds a tower of boxes centered at the origin. ! void createTower(unsigned int length, unsigned int width, ! unsigned height, opal::Vec3r boxDim, ! opal::Matrix44r baseTransform = opal::Matrix44r()); private: --- 22,34 ---- /// Builds a wall of boxes centered at the origin. void createWall(unsigned int length, unsigned height, ! const opal::Vec3r& boxDim, ! const opal::Matrix44r& baseTransform = opal::Matrix44r()); ! /// Builds a tower of boxes centered at the origin. For best ! /// results, make box length = 2 * box width to helps the ! /// corners line up correctly. ! void createTower(unsigned int width, unsigned int depth, ! unsigned height, const opal::Vec3r& boxDim, ! const opal::Matrix44r& baseTransform = opal::Matrix44r()); private: *************** *** 42,46 **** { mUseShadows = true; ! mCreationPoint.set(0, 20, 0); } --- 44,48 ---- { mUseShadows = true; ! mCreationPoint.set(0, 30, 0); } *************** *** 74,80 **** // Setup the initial camera position. ! ExampleApplication::mCamera->setPosition( ! Ogre::Vector3(0, 30, 50)); ! ExampleApplication::mCamera->lookAt(0, 0, 0); // Create a skybox. --- 76,81 ---- // Setup the initial camera position. ! mPhysicalCamera->setPosition(opal::Point3r(0, 30, 50)); ! mPhysicalCamera->lookAt(opal::Point3r(0, 0, 0)); // Create a skybox. *************** *** 162,166 **** if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(1, 1, 1); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); --- 163,167 ---- if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(0.5, 0.5, 0.5); opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); *************** *** 177,181 **** if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 0.5; opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); --- 178,182 ---- if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) { ! Ogre::Real radius = 0.25; opal::Solid* s = mSimulator->createSolid(); s->setPosition(mCreationPoint); *************** *** 189,194 **** } ! // Create a large box. ! if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) { Ogre::Vector3 boxDim(3, 3, 3); --- 190,195 ---- } ! // Create a medium box. ! if(mInputDevice->isKeyDown(KC_3) && mTimeUntilNextToggle <= 0) { Ogre::Vector3 boxDim(3, 3, 3); *************** *** 204,209 **** } ! // Create a large sphere. ! if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) { Ogre::Real radius = 1.5; --- 205,210 ---- } ! // Create a medium sphere. ! if(mInputDevice->isKeyDown(KC_4) && mTimeUntilNextToggle <= 0) { Ogre::Real radius = 1.5; *************** *** 219,226 **** } ! // Create a wall. if(mInputDevice->isKeyDown(KC_5) && mTimeUntilNextToggle <= 0) { ! createWall(5, 5, opal::Vec3r(2, 1, 1)); // Reset the timer for toggle keys. --- 220,266 ---- } ! // Create a large box. if(mInputDevice->isKeyDown(KC_5) && mTimeUntilNextToggle <= 0) { ! Ogre::Vector3 boxDim(16, 16, 16); ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::BoxShapeData data; ! data.dimensions.set(boxDim[0], boxDim[1], boxDim[2]); ! s->addShape(data); ! createPhysicalEntityBox("", "Plastic/Red", boxDim, s); ! ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! ! // Create a large sphere. ! if(mInputDevice->isKeyDown(KC_6) && mTimeUntilNextToggle <= 0) ! { ! Ogre::Real radius = 8; ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::SphereShapeData data; ! data.radius = radius; ! s->addShape(data); ! createPhysicalEntitySphere("", "Plastic/Blue", radius, s); ! ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! ! // Create a wall. ! if(mInputDevice->isKeyDown(KC_7) && mTimeUntilNextToggle <= 0) ! { ! createWall(10, 10, opal::Vec3r(2, 0.5, 1)); ! ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! ! // Create a tower. ! if(mInputDevice->isKeyDown(KC_8) && mTimeUntilNextToggle <= 0) ! { ! createTower(3, 3, 6, opal::Vec3r(2, 1, 1)); // Reset the timer for toggle keys. *************** *** 229,233 **** // The following code updates the camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; bool cameraMoved = false; --- 269,273 ---- // The following code updates the camera's position. ! opal::Vec3r cameraDir; bool cameraMoved = false; *************** *** 236,240 **** { // Move camera left. ! cameraDir.x -= (dt * mMoveSpeed); cameraMoved = true; } --- 276,280 ---- { // Move camera left. ! cameraDir[0] -= (dt * mMoveSpeed); cameraMoved = true; } *************** *** 244,248 **** { // Move camera right. ! cameraDir.x += (dt * mMoveSpeed); cameraMoved = true; } --- 284,288 ---- { // Move camera right. ! cameraDir[0] += (dt * mMoveSpeed); cameraMoved = true; } *************** *** 252,256 **** { // Move camera forward. ! cameraDir.z -= (dt * mMoveSpeed); cameraMoved = true; } --- 292,296 ---- { // Move camera forward. ! cameraDir[2] -= (dt * mMoveSpeed); cameraMoved = true; } *************** *** 260,264 **** { // Move camera backward. ! cameraDir.z += (dt * mMoveSpeed); cameraMoved = true; } --- 300,304 ---- { // Move camera backward. ! cameraDir[2] += (dt * mMoveSpeed); cameraMoved = true; } *************** *** 270,274 **** // Use the camera dir vector to translate the camera. ! ExampleApplication::mCamera->moveRelative(cameraDir); // Toggle shadows. --- 310,314 ---- // Use the camera dir vector to translate the camera. ! mPhysicalCamera->moveRelative(cameraDir); // Toggle shadows. *************** *** 290,295 **** } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) { mStatsOn = !mStatsOn; --- 330,335 ---- } ! // Toggle GUI. ! if (mInputDevice->isKeyDown(KC_G) && mTimeUntilNextToggle <= 0) { mStatsOn = !mStatsOn; *************** *** 321,326 **** // the last poll. This data can be used to rotate the camera // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Radian rotY(-mInputDevice->getMouseRelativeX() * mRotateSpeed); ! Ogre::Radian rotX(-mInputDevice->getMouseRelativeY() * mRotateSpeed); // The following code checks the mouse button state. --- 361,370 ---- // the last poll. This data can be used to rotate the camera // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Degree rotY = -mInputDevice->getMouseRelativeX() * mRotateSpeed; ! Ogre::Degree rotX = -mInputDevice->getMouseRelativeY() * mRotateSpeed; ! ! // Use the relative mouse motion to rotate the camera. ! mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->yawRelative(rotX.valueDegrees()); // The following code checks the mouse button state. *************** *** 328,335 **** { // The right mouse button is down. - - // Use the relative mouse motion to rotate the camera. - ExampleApplication::mCamera->yaw(rotY); - ExampleApplication::mCamera->pitch(rotX); } else --- 372,375 ---- *************** *** 343,350 **** void PlaypenApp::createWall(unsigned int length, unsigned height, ! opal::Vec3r boxDim, opal::Matrix44r baseTransform) { - opal::Matrix44r tempTransform; - for (unsigned int l=0; l<length; ++l) { --- 383,388 ---- void PlaypenApp::createWall(unsigned int length, unsigned height, ! const opal::Vec3r& boxDim, const opal::Matrix44r& baseTransform) { for (unsigned int l=0; l<length; ++l) { *************** *** 357,367 **** } ! tempTransform = baseTransform; ! tempTransform.translate(l * boxDim[0] + 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + offset, h * boxDim[1] + 0.5 * boxDim[1], 0); opal::Solid* s = mSimulator->createSolid(); ! s->setTransform(tempTransform); //s->setSleeping(true); opal::BoxShapeData boxData; --- 395,405 ---- } ! opal::Matrix44r blockTransform = baseTransform; ! blockTransform.translate(l * boxDim[0] + 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + offset, h * boxDim[1] + 0.5 * boxDim[1], 0); opal::Solid* s = mSimulator->createSolid(); ! s->setTransform(blockTransform); //s->setSleeping(true); opal::BoxShapeData boxData; *************** *** 374,381 **** } ! void PlaypenApp::createTower(unsigned int length, unsigned int width, ! unsigned height, opal::Vec3r boxDim, opal::Matrix44r baseTransform) { } } --- 412,486 ---- } ! void PlaypenApp::createTower(unsigned int width, unsigned int depth, ! unsigned height, const opal::Vec3r& boxDim, ! const opal::Matrix44r& baseTransform) { + for (unsigned int wall=0; wall<4; ++wall) + { + opal::Matrix44r wallBaseTransform = baseTransform; + opal::real length = 0; + + switch(wall) + { + case 0: + length = width; + wallBaseTransform.translate( + -(opal::real)0.25 * boxDim[0], 0, + -(opal::real)0.5 * depth * boxDim[0]); + break; + case 1: + length = width; + wallBaseTransform.translate( + (opal::real)0.25 * boxDim[0], 0, + (opal::real)0.5 * depth * boxDim[0]); + wallBaseTransform.rotate(180, 0, 1, 0); + break; + case 2: + length = depth; + wallBaseTransform.translate( + -(opal::real)0.5 * width * boxDim[0], 0, 0); + wallBaseTransform.rotate(90, 0, 1, 0); + wallBaseTransform.translate( + -(opal::real)0.25 * boxDim[0], 0, 0); + break; + case 3: + length = depth; + wallBaseTransform.translate( + (opal::real)0.5 * width * boxDim[0], 0, 0); + wallBaseTransform.rotate(-90, 0, 1, 0); + wallBaseTransform.translate( + -(opal::real)0.25 * boxDim[0], 0, 0); + break; + default: + assert(false); + break; + } + + for (unsigned int l=0; l<length; ++l) + { + for (unsigned int h=0; h<height; ++h) + { + opal::real offset = 0; + if (h % 2 == 0) + { + offset = (opal::real)0.5 * boxDim[0]; + } + + opal::Matrix44r blockTransform = wallBaseTransform; + blockTransform.translate(l * boxDim[0] + + 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + + offset, h * boxDim[1] + 0.5 * boxDim[1], 0); + opal::Solid* s = mSimulator->createSolid(); + s->setTransform(blockTransform); + //s->setSleeping(true); + opal::BoxShapeData boxData; + boxData.dimensions = boxDim; + s->addShape(boxData); + Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); + createPhysicalEntityBox("", "Plastic/Red", boxDimensions, s); + } + } + } } } Index: playpen.vcproj =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/playpen.vcproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** playpen.vcproj 1 Apr 2005 23:13:49 -0000 1.2 --- playpen.vcproj 3 Apr 2005 00:11:41 -0000 1.3 *************** *** 33,36 **** --- 33,37 ---- <Tool Name="VCLinkerTool" + AdditionalOptions="/STACK:20000000" AdditionalDependencies="ogremain_d.lib opal-ode_d.lib" OutputFile="../win32bin/debug/playpen.exe" *************** *** 84,87 **** --- 85,89 ---- <Tool Name="VCLinkerTool" + AdditionalOptions="/STACK:10000000" AdditionalDependencies="ogremain.lib opal-ode.lib" OutputFile="../win32bin/release/playpen.exe" |
|
From: tylerstreeter <tyl...@us...> - 2005-04-03 00:11:53
|
Update of /cvsroot/opal/opal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12604 Modified Files: todo.txt Log Message: minor changes to opal src; added more to playpen sample app Index: todo.txt =================================================================== RCS file: /cvsroot/opal/opal/todo.txt,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** todo.txt 1 Apr 2005 23:13:50 -0000 1.66 --- todo.txt 3 Apr 2005 00:11:44 -0000 1.67 *************** *** 26,29 **** --- 26,31 ---- * comment math functions + * move samples to a separate module? + * add 'sleeping' user prop to max exporter *************** *** 43,46 **** --- 45,52 ---- ================= + * remove plane from shapes; just make it a special object? + - it isn't really something you would store in a blueprint + - do the same for trimeshes? + * make trimeshes work - test basic functionality |
|
From: tylerstreeter <tyl...@us...> - 2005-04-03 00:11:52
|
Update of /cvsroot/opal/opal/samples/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12604/samples/src Modified Files: BaseOpalApp.h ExampleApplication.h TemplateApp.cpp Added Files: PhysicalCamera.h PhysicalEntity.h Log Message: minor changes to opal src; added more to playpen sample app --- NEW FILE: PhysicalCamera.h --- #ifndef OPAL_SAMPLES_PHYSICAL_CAMERA_H #define OPAL_SAMPLES_PHYSICAL_CAMERA_H #include <opal/opal.h> namespace opalSamples { //const opal::real graspDistanceScalar = (opal::real)5; //const opal::real maxReachScalar = (opal::real)8; /// Define how object grasping is handled. enum GraspMode { /// Grasped objects stay the same distance from the camera as /// when they were initially grasped. LONG_RANGE_GRASP_MODE, /// Grasped objects are pulled close to the camera. Better for /// first-person perspective. SHORT_RANGE_GRASP_MODE }; /// A camera class that enables an Ogre Camera to be physical by /// using an OPAL Solid. The physical aspect can also be disabled, /// allowing the camera to move freely through objects and not be /// affected by gravity. When the physics option is used, the /// physical shape of the camera is a stack of two sphere, like a /// snowman. class PhysicalCamera { public: /// Note: eye height and Solid radius are only used when the /// physics option is enabled. PhysicalCamera(opal::Simulator* sim, Ogre::Camera* cam, bool isPhysical, opal::real eyeHeight=2) { mIsPhysical = isPhysical; mGraspMode = LONG_RANGE_GRASP_MODE; mSimulator = sim; mSolid = NULL; mOgreCamera = cam; mGraspingMotor = sim->createSpringMotor(); mGraspingSensor = sim->createRaycastSensor(); mGraspedObject = NULL; mGraspPos.set(0, 0, -5); mMaxReach = 8; mEyeHeight = eyeHeight; //mGraspOffset.makeIdentity(); // Setup OPAL Solid, if necessary. if (isPhysical) { mSolid = sim->createSolid(); mSolid->setPosition(0, eyeHeight, 0); // Keep the camera Solid from falling asleep. mSolid->setSleepiness(0); // Make the spheres' radii 1/4 * eye height. opal::real radius = eyeHeight * (opal::real)0.25; // Add a sphere at the eye/Solid position. opal::SphereShapeData sphereData; sphereData.radius = radius; mSolid->addShape(sphereData); // Add another sphere down below. sphereData.offset.translate(0, -3 * radius, 0); mSolid->addShape(sphereData); // Attach the ray Sensor to the Solid. opal::RaycastSensorData raySensorData; raySensorData.solid = mSolid; mGraspingSensor->init(raySensorData); } } ~PhysicalCamera() { if (mIsPhysical) { assert(mSimulator && mGraspingMotor); mSimulator->destroySolid(mSolid); } mSimulator->destroyMotor(mGraspingMotor); mSimulator->destroySensor(mGraspingSensor); } /// Gives the camera a chance to update things regularly. void update(opal::real dt) { if (!mIsPhysical && !mGraspedObject) { return; } // Keep solid upright by resetting its orientation. Thus the // camera Solid's orientation is always the same. opal::Point3r p = mSolid->getPosition(); opal::Matrix44r m; m.translate(p[0], p[1], p[2]); mSolid->setTransform(m); // Set the Ogre camera's position. It must be at the same position // as the OPAL Solid. mOgreCamera->setPosition((Ogre::Real)p[0], (Ogre::Real)p[1], (Ogre::Real)p[2]); // Update the ray casting Sensor's ray. Ogre::Vector3 camForward = mOgreCamera->getDirection(); if (0 != camForward.squaredLength()) { camForward.normalise(); } opal::Vec3r rayDir(camForward[0], camForward[1], camForward[2]); if (mIsPhysical) { // The ray's origin will be updated automatically since it is // attached to the camera's Solid. Its direction should be set // manually here because we constantly reset the camera's // orientation. opal::Rayr r(opal::Point3r(), rayDir); mGraspingSensor->setRay(r); } else { // The ray should start at the camera's position and fire // straight forward into the scene. opal::Rayr r(p, rayDir); mGraspingSensor->setRay(r); } // Handle the grasped object if one exists. if (mGraspedObject) { // Keep the object awake. mGraspedObject->setSleeping(false); // TODO: use 3 vecs for motor, not transform // Get the camera's transform. opal::Matrix44r camTransform; getOpalMatFromOgreCam(camTransform); // Set the desired transform for the grasped object. //mGraspingMotor->setDesiredTransform(camTransform * mGraspOffset); mGraspingMotor->setDesiredTransform(camTransform); // Since the Ogre camera's matrix doesn't include position, now // set the desired position. if (SHORT_RANGE_GRASP_MODE == mGraspMode) { // mGraspPos is a local offset from the camera. mGraspingMotor->setDesiredPosition(camTransform * mGraspPos); } else if (LONG_RANGE_GRASP_MODE == mGraspMode) { // mGraspPos is the global desired pos. mGraspingMotor->setDesiredPosition(mGraspPos); } // Drop object if it gets too far away. if (opal::distance(getPosition(), mGraspedObject->getPosition()) > mMaxReach) { release(); } } } /// Returns a pointer to the Ogre Camera. Ogre::Camera* getOgreCamera()const { return mOgreCamera; } /// Sets the position of the camera in global coordinates. This /// refers to the camera's eye position. void setPosition(const opal::Point3r& pos) { if (mIsPhysical) { assert(mSolid); mSolid->setPosition(pos); } else { mOgreCamera->setPosition(pos[0], pos[1], pos[2]); } } /// Returns the position of the camera in global coordinates. This /// refers to the camera's eye position. opal::Point3r getPosition()const { Ogre::Vector3 ogreCamPos = mOgreCamera->getPosition(); return opal::Point3r(ogreCamPos[0], ogreCamPos[1], ogreCamPos[2]); } /// Orients the camera look at the given point. void lookAt(opal::Point3r point) { mOgreCamera->lookAt(point[0], point[1], point[2]); } /// Moves the camera according to the given direction vector /// relative to its current transform. This works differently /// depending on whether the camera is physical. void moveRelative(const opal::Vec3r& dir) { if (mIsPhysical) { assert(mSolid); // TODO... //// don't let the camera fly ////if (mSolid->getPosition()[1] > mEyeHeight + 0.0001) ////{ //// dir = DONT_MOVE; ////} //Ogre::Vector3 vec; //switch(dir) //{ // case DONT_MOVE: // vec = Ogre::Vector3::ZERO; // break; // case MOVE_LEFT: // vec = -(mOgreCamera->getRight()); // break; // case MOVE_RIGHT: // vec = mOgreCamera->getRight(); // break; // case MOVE_FORWARD: // vec = mOgreCamera->getDirection(); // break; // case MOVE_BACK: // vec = -(mOgreCamera->getDirection()); // break; //} //// Don't let the camera fly. //if (vec[1] > 0) //{ // vec[1] = 0; //} //vec.normalise(); //opal::Vec3r v(vec[0], vec[1], vec[2]); //v *= 3; //mSolid->setGlobalLinearVel(v); } else { Ogre::Vector3 ogreVec(dir[0], dir[1], dir[2]); mOgreCamera->moveRelative(ogreVec); } } /// Attempts to grasp an object by firing a ray into the scene /// directly in front of the camera and choosing the closest /// intersected object, if any. void grasp() { if (!mGraspedObject) { // Fire a ray into the scene to find an object to grasp. If // an object is found, attach it to the grasping Motor and, // if using long range grasping mode, store the intersection // position relative to the camera as the grasp offset. opal::RaycastResult result = mGraspingSensor->fireRay(mMaxReach); if (result.solid && !result.solid->isStatic()) { // Store the grasped object. mGraspedObject = result.solid; // Initialize the grasping Motor with the new data. opal::SpringMotorData data; data.solid = result.solid; data.mode = opal::LINEAR_AND_ANGULAR_MODE; data.linearKd = 15; data.linearKs = 250; data.angularKd = 1; data.angularKs = 5; // Desired position/orientation will be updated in the // "update" function. mGraspingMotor->init(data); mGraspingMotor->setGlobalAttachPoint(result.intersection); if (LONG_RANGE_GRASP_MODE == mGraspMode) { mGraspPos = result.intersection; } // TODO: try just passing in the matrix and let OPAL calc these three vecs //Ogre::Vector3 f = mOgreCamera->getDirection(); //Ogre::Vector3 u = mOgreCamera->getUp(); //Ogre::Vector3 r = mOgreCamera->getRight(); //opal::Vec3r forward(f[0], f[1], f[2]); //opal::Vec3r up(u[0], u[1], u[2]); //opal::Vec3r right(r[0], r[1], r[2]); //mGraspingMotor->setDesiredOrientation( forward, up, right ); //Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix(); ////ogreMat.setScale(Ogre::Vector3(1,1,1)); //opal::Matrix44r camTransform(ogreMat[0][0], ogreMat[1][0], ogreMat[2][0], ogreMat[3][0], // ogreMat[0][1], ogreMat[1][1], ogreMat[2][1], ogreMat[3][1], // ogreMat[0][2], ogreMat[1][2], ogreMat[2][2], ogreMat[3][2], // ogreMat[0][3], ogreMat[1][3], ogreMat[2][3], ogreMat[3][3]); //// setup grasp offset transform //camTransform.fastInvert(); //mGraspOffset = mGraspedObject->getTransform() * camTransform; // //// set desired transform //mGraspingMotor->setDesiredTransform(mGraspedObject->getTransform()); //// since the previous matrix doesn't include position, now set the desired position //mGraspingMotor->setDesiredPos(calcGraspPos()); } } } /// Releases any grasped objects. void release() { if (mGraspedObject) { // Make sure the object is awake before releasing it so it // doesn't float in midair. mGraspedObject->setSleeping(false); mGraspedObject = NULL; mGraspingMotor->setEnabled(false); } } /// Adjust the camera's pitch by adding an angle to its yaw /// relative to its current yaw. void yawRelative(opal::real degrees) { // Update the Ogre camera. mOgreCamera->yaw(Ogre::Radian(Ogre::Degree(degrees))); } /// Adjust the camera's pitch by adding an angle to its pitch /// relative to its current pitch. void pitchRelative(opal::real degrees) { // Update the Ogre camera. mOgreCamera->pitch(Ogre::Radian(Ogre::Degree(degrees))); } /// Returns true if the camera uses physics. bool isPhysical()const { return mIsPhysical; } /// Sets how object grasping is handled. void setGraspMode(GraspMode mode) { mGraspMode = mode; } /// Returns the grasp mode being used. GraspMode getGraspMode()const { return mGraspMode; } /// Sets the desired position for grasped objects, represented as a /// local offset from the camera's transform. This only applies /// in the short-range grasp mode. void setGraspOffset(const opal::Point3r& offset) { if (SHORT_RANGE_GRASP_MODE == mGraspMode) { mGraspPos = offset; } } /// Returns the desired position for grasped objects. In short /// range mode this is a local offset from the camera's transform. /// In long range mode this is the global desired position. const opal::Point3r& getGraspPos()const { return mGraspPos; } /// Sets the maximum reach distance used for grasping. void setMaxReach(opal::real r) { mMaxReach = r; } /// Returns the maximum reach distance used for grasping. opal::real getMaxReach()const { return mMaxReach; } private: // Old stuff... //opal::Point3r calcGraspPos(); //opal::Matrix44r mGraspOffset; void getOpalMatFromOgreCam(opal::Matrix44r& mat) { // Make an OPAL matrix copy of the Ogre camera's transform. Ogre::Matrix4 ogreMat = mOgreCamera->getViewMatrix(); mat.set( ogreMat[0][0], ogreMat[1][0], ogreMat[2][0], ogreMat[3][0], ogreMat[0][1], ogreMat[1][1], ogreMat[2][1], ogreMat[3][1], ogreMat[0][2], ogreMat[1][2], ogreMat[2][2], ogreMat[3][2], ogreMat[0][3], ogreMat[1][3], ogreMat[2][3], ogreMat[3][3]); } /// True if the camera uses physics. bool mIsPhysical; /// Determines how object grasping is handled. GraspMode mGraspMode; /// Pointer to the OPAL Simulator. opal::Simulator* mSimulator; /// Pointer to the OPAL Solid. opal::Solid* mSolid; /// Pointer to the Ogre camera. Ogre::Camera* mOgreCamera; /// The OPAL ray casting Sensor used to find objects to grasp. opal::RaycastSensor* mGraspingSensor; /// The OPAL Motor used to hold grasped objects in a desired /// position and orientation. opal::SpringMotor* mGraspingMotor; /// Pointer to the currently grasped object, if one exists. opal::Solid* mGraspedObject; /// The desired position for grasped objects. Has different /// meanings depending on the grasp mode. opal::Point3r mGraspPos; /// When the camera attempts to grasp an object by casting a ray, /// this is the length of the ray. It determines how far away /// objects can be and still be grasped. opal::real mMaxReach; /// The distance between the ground and the camera viewpoint. opal::real mEyeHeight; }; } #endif Index: TemplateApp.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/src/TemplateApp.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TemplateApp.cpp 1 Apr 2005 23:13:50 -0000 1.3 --- TemplateApp.cpp 3 Apr 2005 00:11:42 -0000 1.4 *************** *** 58,64 **** // Setup the initial camera position. ! ExampleApplication::mCamera->setPosition( ! Ogre::Vector3(0, 30, 50)); ! ExampleApplication::mCamera->lookAt(0, 0, 0); // Load models, create physical objects, etc. here. --- 58,63 ---- // Setup the initial camera position. ! mPhysicalCamera->setPosition(Ogre::Vector3(0, 30, 50)); ! mPhysicalCamera->lookAt(0, 0, 0); // Load models, create physical objects, etc. here. *************** *** 92,96 **** // The following code updates the camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; bool cameraMoved = false; --- 91,95 ---- // The following code updates the camera's position. ! opal::Vec3r cameraDir; bool cameraMoved = false; *************** *** 99,103 **** { // Move camera left. ! cameraDir.x -= (dt * 5); cameraMoved = true; } --- 98,102 ---- { // Move camera left. ! cameraDir[0] -= (dt * mMoveSpeed); cameraMoved = true; } *************** *** 107,111 **** { // Move camera right. ! cameraDir.x += (dt * 5); cameraMoved = true; } --- 106,110 ---- { // Move camera right. ! cameraDir[0] += (dt * mMoveSpeed); cameraMoved = true; } *************** *** 115,119 **** { // Move camera forward. ! cameraDir.z -= (dt * 5); cameraMoved = true; } --- 114,118 ---- { // Move camera forward. ! cameraDir[2] -= (dt * mMoveSpeed); cameraMoved = true; } *************** *** 123,127 **** { // Move camera backward. ! cameraDir.z += (dt * 5); cameraMoved = true; } --- 122,126 ---- { // Move camera backward. ! cameraDir[2] += (dt * mMoveSpeed); cameraMoved = true; } *************** *** 133,137 **** // Use the camera dir vector to translate the camera. ! ExampleApplication::mCamera->moveRelative(cameraDir); // Toggle shadows. --- 132,136 ---- // Use the camera dir vector to translate the camera. ! mPhysicalCamera->moveRelative(cameraDir); // Toggle shadows. *************** *** 153,158 **** } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) { mStatsOn = !mStatsOn; --- 152,157 ---- } ! // Toggle GUI. ! if (mInputDevice->isKeyDown(KC_G) && mTimeUntilNextToggle <= 0) { mStatsOn = !mStatsOn; *************** *** 184,189 **** // the last poll. This data can be used to rotate the camera // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Radian rotX(-mInputDevice->getMouseRelativeX() * mRotateSpeed); ! Ogre::Radian rotY(-mInputDevice->getMouseRelativeY() * mRotateSpeed); // The following code checks the mouse button state. --- 183,192 ---- // the last poll. This data can be used to rotate the camera // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Degree rotY = -mInputDevice->getMouseRelativeX() * mRotateSpeed; ! Ogre::Degree rotX = -mInputDevice->getMouseRelativeY() * mRotateSpeed; ! ! // Use the relative mouse motion to rotate the camera. ! mPhysicalCamera->yawRelative(rotY.valueDegrees()); ! mPhysicalCamera->yawRelative(rotX.valueDegrees()); // The following code checks the mouse button state. *************** *** 191,198 **** { // The right mouse button is down. - - // Use the relative mouse motion to rotate the camera. - ExampleApplication::mCamera->yaw(rotY); - ExampleApplication::mCamera->pitch(rotX); } else --- 194,197 ---- Index: ExampleApplication.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/ExampleApplication.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ExampleApplication.h 31 Mar 2005 08:47:02 -0000 1.2 --- ExampleApplication.h 3 Apr 2005 00:11:42 -0000 1.3 *************** *** 27,31 **** ! using namespace Ogre; /** Base class which manages the standard startup of an Ogre application. --- 27,31 ---- ! //using namespace Ogre; /** Base class which manages the standard startup of an Ogre application. --- NEW FILE: PhysicalEntity.h --- #ifndef OPAL_SAMPLES_PHYSICAL_ENTITY_H #define OPAL_SAMPLES_PHYSICAL_ENTITY_H #include <opal/opal.h> namespace opalSamples { class PhysicalEntity { public: /// PhysicalEntities should not be instantiated directly. Instead, /// use the BaseOpalApp function for creating PhysicalEntities. PhysicalEntity(const std::string& name, Ogre::SceneNode* node, opal::Solid* s) { mName = name; mSceneNode = node; mSolid = s; } virtual ~PhysicalEntity() { // The OPAL Solid and Ogre SceneNode should be destroyed // externally, not here. } /// Updates the Ogre SceneNode transform from the OPAL /// Solid's transform. virtual void update(opal::real dt) { if (NULL == mSolid || NULL == mSceneNode) { return; } opal::Point3r pos = mSolid->getPosition(); opal::Quaternion quat = mSolid->getQuaternion(); mSceneNode->setPosition((Ogre::Real)pos[0], (Ogre::Real)pos[1], (Ogre::Real)pos[2]); quat.normalize(); mSceneNode->setOrientation((Ogre::Real)quat[0], (Ogre::Real)quat[1], (Ogre::Real)quat[2], (Ogre::Real)quat[3]); } /// Returns the PhysicalEntity's name. const std::string& getName()const { return mName; } /// Returns a pointer to the Ogre SceneNode. Ogre::SceneNode* getSceneNode()const { return mSceneNode; } /// Returns a pointer to the OPAL Solid. opal::Solid* getSolid()const { return mSolid; } protected: /// The PhysicalEntity's name. std::string mName; /// Pointer to the OPAL Solid. opal::Solid* mSolid; /// Pointer to the Ogre SceneNode. Ogre::SceneNode* mSceneNode; private: }; } #endif Index: BaseOpalApp.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/BaseOpalApp.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BaseOpalApp.h 1 Apr 2005 23:13:50 -0000 1.3 --- BaseOpalApp.h 3 Apr 2005 00:11:42 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- #include "ExampleFrameListener.h" #include "PhysicalEntity.h" + #include "PhysicalCamera.h" #include <opal/opal.h> *************** *** 17,20 **** --- 18,23 ---- mSimulator = opal::createSimulator(); mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); + // Create the physical camera later after the ExampleApplication + // has created its Ogre camera. mPaused = false; mNamelessObjectCount = 0; *************** *** 23,26 **** --- 26,31 ---- ~BaseOpalApp() { + delete mPhysicalCamera; + while (!mPhysicalEntityList.empty()) { *************** *** 41,44 **** --- 46,53 ---- virtual void createFrameListener() { + // TODO: move this somewhere else... + mPhysicalCamera = new PhysicalCamera(mSimulator, + ExampleApplication::mCamera, false); + ExampleFrameListener::init(ExampleApplication::mWindow, ExampleApplication::mCamera); *************** *** 315,318 **** --- 324,330 ---- opal::Simulator* mSimulator; + /// Pointer to the PhysicalCamera. + PhysicalCamera* mPhysicalCamera; + /// True when the physics simulation is paused. bool mPaused; |
|
From: tylerstreeter <tyl...@us...> - 2005-04-03 00:11:51
|
Update of /cvsroot/opal/opal/src/ODE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12604/src/ODE Modified Files: ODESolid.cpp Log Message: minor changes to opal src; added more to playpen sample app Index: ODESolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESolid.cpp,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** ODESolid.cpp 31 Mar 2005 08:47:02 -0000 1.79 --- ODESolid.cpp 3 Apr 2005 00:11:42 -0000 1.80 *************** *** 81,85 **** dGeomDestroy(mGeomDataList[i]->transformID); } ! #ifdef OPAL_USE_MESH if (0 != mGeomDataList[i]->trimeshDataID) --- 81,85 ---- dGeomDestroy(mGeomDataList[i]->transformID); } ! #ifdef OPAL_USE_MESH if (0 != mGeomDataList[i]->trimeshDataID) *************** *** 91,94 **** --- 91,95 ---- } #endif + // Destroy the ODE geom. dGeomDestroy(mGeomDataList[i]->geomID); *************** *** 247,252 **** if (0 != (*iter)->transformID) { ! // this geom uses a transform, so apply the new space only ! // to the transform geom dSpaceRemove((*iter)->spaceID, (*iter)->transformID); dSpaceAdd(mSpaceID, (*iter)->transformID); --- 248,253 ---- if (0 != (*iter)->transformID) { ! // This geom uses a transform, so apply the new space only ! // to the transform geom. dSpaceRemove((*iter)->spaceID, (*iter)->transformID); dSpaceAdd(mSpaceID, (*iter)->transformID); *************** *** 254,258 **** else { ! // normal geom with no transform dSpaceRemove((*iter)->spaceID, (*iter)->geomID); dSpaceAdd(mSpaceID, (*iter)->geomID); --- 255,259 ---- else { ! // Normal geom with no transform. dSpaceRemove((*iter)->spaceID, (*iter)->geomID); dSpaceAdd(mSpaceID, (*iter)->geomID); |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:16
|
Update of /cvsroot/opal/opal/samples/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340/samples/src Modified Files: BaseOpalApp.h ExampleFrameListener.h TemplateApp.cpp Log Message: added stuff to the playpen sample app Index: TemplateApp.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/src/TemplateApp.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TemplateApp.cpp 31 Mar 2005 08:47:02 -0000 1.2 --- TemplateApp.cpp 1 Apr 2005 23:13:50 -0000 1.3 *************** *** 7,178 **** { public: ! MyApp() ! : BaseOpalApp() ! { ! mUseShadows = true; ! } ! ~MyApp() ! {} protected: ! virtual void createScene() ! { ! // Setup shadows. ! if (mUseShadows) ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! // Set the ambient light level. ! mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); ! // Create a light source. ! Ogre::Light* light = mSceneMgr->createLight("light0"); ! light->setType(Ogre::Light::LT_POINT); ! light->setPosition(-80.0, 30.0, -10.0); ! // Load models, create physical objects, etc. here. ! } ! virtual bool appFrameStarted(opal::real dt) ! { ! // Do per-frame application specific things here. ! // Return true to continue looping. ! return true; ! } ! virtual bool processUnbufferedKeyInput(Ogre::Real dt) ! { ! // Check if we should quit looping. ! if(mInputDevice->isKeyDown(KC_ESCAPE) ! || mInputDevice->isKeyDown(KC_Q)) ! { ! return false; ! } ! // Check if we should pause physics. ! if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) ! { ! mPaused = !mPaused; ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // The following code can be used to update a camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; ! bool cameraMoved = false; ! if (mInputDevice->isKeyDown(KC_LEFT)) ! { ! // Move camera left. ! cameraDir.x -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_RIGHT)) ! { ! // Move camera right. ! cameraDir.x += (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_UP)) ! { ! // Move camera forward. ! cameraDir.z -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_DOWN)) ! { ! // Move camera backward. ! cameraDir.z += (dt * 5); ! cameraMoved = true; ! } ! if (!cameraMoved) ! { ! // Slow physical camera motion if necessary. ! } ! // Here, use the camera dir vector to affect the camera. ! // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_S) && mTimeUntilNextToggle <= 0) ! { ! mUseShadows = !mUseShadows; ! if (mUseShadows) ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) ! { ! mStatsOn = !mStatsOn; ! showDebugOverlay(mStatsOn); ! mTimeUntilNextToggle = 1; ! } ! // Handy screenshot saving procedure. ! if (mInputDevice->isKeyDown(KC_SYSRQ) ! && mTimeUntilNextToggle <= 0) ! { ! char tmp[20]; ! sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); ! ExampleApplication::mWindow->writeContentsToFile(tmp); ! ExampleApplication::mWindow->setDebugText(String("Wrote ") ! + tmp); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Return true to continue looping. ! return true; } ! virtual bool processUnbufferedMouseInput(Ogre::Real dt) { ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(0)) { ! // The left mouse button is down. } else { ! // The left mouse button is up. } ! // The following code checks how far the mouse has move since ! // the last poll. This data can be used to rotate the camera ! // around its X and Y axes (yaw and pitch, respectively). ! Ogre::Real rotX = -mInputDevice->getMouseRelativeX(); ! Ogre::Real rotY = -mInputDevice->getMouseRelativeY(); ! // Return true to continue looping. ! return true; } ! private: ! /// Used to toggle shadows on and off. ! bool mUseShadows; ! }; } --- 7,207 ---- { public: ! MyApp(); ! ~MyApp(); protected: ! virtual void createScene(); ! virtual bool appFrameStarted(opal::real dt); ! virtual bool processUnbufferedKeyInput(Ogre::Real dt); ! virtual bool processUnbufferedMouseInput(Ogre::Real dt); ! private: ! /// Used to toggle shadows on and off. ! bool mUseShadows; ! }; ! MyApp::MyApp() ! : BaseOpalApp() ! { ! mUseShadows = true; ! } ! ~MyApp::MyApp() ! { ! } ! void MyApp::createScene() ! { ! // Setup shadows. ! if (mUseShadows) ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! // Set the ambient light level. ! mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); ! // Create a light source. ! Ogre::Light* light = mSceneMgr->createLight("light0"); ! light->setType(Ogre::Light::LT_POINT); ! light->setDiffuseColour(1.0, 1.0, 1.0); ! light->setSpecularColour(1.0, 1.0, 1.0); ! light->setPosition(100.0, 300.0, 100.0); ! // Setup the initial camera position. ! ExampleApplication::mCamera->setPosition( ! Ogre::Vector3(0, 30, 50)); ! ExampleApplication::mCamera->lookAt(0, 0, 0); ! // Load models, create physical objects, etc. here. ! } ! bool MyApp::appFrameStarted(opal::real dt) ! { ! // Do per-frame application specific things here. ! // Return true to continue looping. ! return true; ! } ! bool MyApp::processUnbufferedKeyInput(Ogre::Real dt) ! { ! // Check if we should quit looping. ! if(mInputDevice->isKeyDown(KC_ESCAPE) ! || mInputDevice->isKeyDown(KC_Q)) ! { ! return false; ! } ! // Check if we should pause physics. ! if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) ! { ! mPaused = !mPaused; ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // The following code updates the camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; ! bool cameraMoved = false; ! if (mInputDevice->isKeyDown(KC_LEFT) ! || mInputDevice->isKeyDown(KC_A)) ! { ! // Move camera left. ! cameraDir.x -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_RIGHT) ! || mInputDevice->isKeyDown(KC_D)) ! { ! // Move camera right. ! cameraDir.x += (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_UP) ! || mInputDevice->isKeyDown(KC_W)) ! { ! // Move camera forward. ! cameraDir.z -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_DOWN) ! || mInputDevice->isKeyDown(KC_S)) ! { ! // Move camera backward. ! cameraDir.z += (dt * 5); ! cameraMoved = true; ! } ! if (!cameraMoved) ! { ! // Slow physical camera motion if necessary. } ! // Use the camera dir vector to translate the camera. ! ExampleApplication::mCamera->moveRelative(cameraDir); ! ! // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) { ! mUseShadows = !mUseShadows; ! ! if (mUseShadows) { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); } else { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); } ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) ! { ! mStatsOn = !mStatsOn; ! showDebugOverlay(mStatsOn); ! mTimeUntilNextToggle = 1; } ! // Handy screenshot saving procedure. ! if (mInputDevice->isKeyDown(KC_SYSRQ) ! && mTimeUntilNextToggle <= 0) ! { ! char tmp[20]; ! sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); ! ExampleApplication::mWindow->writeContentsToFile(tmp); ! ExampleApplication::mWindow->setDebugText(String("Wrote ") ! + tmp); ! ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! ! // Return true to continue looping. ! return true; ! } ! ! bool MyApp::processUnbufferedMouseInput(Ogre::Real dt) ! { ! // The following code checks how far the mouse has move since ! // the last poll. This data can be used to rotate the camera ! // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Radian rotX(-mInputDevice->getMouseRelativeX() * mRotateSpeed); ! Ogre::Radian rotY(-mInputDevice->getMouseRelativeY() * mRotateSpeed); ! ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(1)) ! { ! // The right mouse button is down. ! ! // Use the relative mouse motion to rotate the camera. ! ExampleApplication::mCamera->yaw(rotY); ! ExampleApplication::mCamera->pitch(rotX); ! } ! else ! { ! // The right mouse button is up. ! } ! ! // Return true to continue looping. ! return true; ! } } Index: ExampleFrameListener.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/ExampleFrameListener.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ExampleFrameListener.h 31 Mar 2005 08:47:02 -0000 1.2 --- ExampleFrameListener.h 1 Apr 2005 23:13:50 -0000 1.3 *************** *** 128,133 **** mUseBufferedInputMouse = useBufferedInputMouse; mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse; ! mRotateSpeed = 36; ! mMoveSpeed = 100; if (mInputTypeSwitchingOn) --- 128,133 ---- mUseBufferedInputMouse = useBufferedInputMouse; mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse; ! mRotateSpeed = 0.1; ! mMoveSpeed = 40; if (mInputTypeSwitchingOn) Index: BaseOpalApp.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/BaseOpalApp.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BaseOpalApp.h 31 Mar 2005 08:47:02 -0000 1.2 --- BaseOpalApp.h 1 Apr 2005 23:13:50 -0000 1.3 *************** *** 18,28 **** mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); mPaused = false; } ~BaseOpalApp() { ! mSimulator->destroy(); ! mPhysicalEntityList.clear(); mPhysicalEntityMap.clear(); } --- 18,37 ---- mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); mPaused = false; + mNamelessObjectCount = 0; } ~BaseOpalApp() { ! while (!mPhysicalEntityList.empty()) ! { ! delete mPhysicalEntityList.back(); ! mPhysicalEntityList.pop_back(); ! } ! ! // Every pointer in the mPhysicalEntityMap is a duplicate of ! // a pointer in mPhysicalEntityList, so we don't need to ! // delete the memory they point to. mPhysicalEntityMap.clear(); + mSimulator->destroy(); } *************** *** 87,91 **** /// Creates and returns a pointer to a PhysicalEntity. Takes /// the name of the new PhysicalEntity, the Ogre Entity, and a ! /// pointer to an OPAL Solid. PhysicalEntity* createPhysicalEntity(const std::string& name, Ogre::Entity* e, opal::Solid* s) --- 96,101 ---- /// Creates and returns a pointer to a PhysicalEntity. Takes /// the name of the new PhysicalEntity, the Ogre Entity, and a ! /// pointer to an OPAL Solid. The name must be unique; unique ! /// names will be automatically generated for empty name strings. PhysicalEntity* createPhysicalEntity(const std::string& name, Ogre::Entity* e, opal::Solid* s) *************** *** 96,102 **** } // Create an Ogre SceneNode. Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! createChildSceneNode(name); // Attach the Entity to the SceneNode. --- 106,122 ---- } + std::string nameStr = name; + if (nameStr.empty()) + { + // Make a unique name. + char newName[20]; + sprintf(newName, "object%d", mNamelessObjectCount); + mNamelessObjectCount++; + nameStr = newName; + } + // Create an Ogre SceneNode. Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! createChildSceneNode(nameStr); // Attach the Entity to the SceneNode. *************** *** 104,108 **** // Create a new Physical Entity. ! PhysicalEntity* pe = new PhysicalEntity(name, sn, s); // Store the pointer in the PhysicalEntity list. --- 124,128 ---- // Create a new Physical Entity. ! PhysicalEntity* pe = new PhysicalEntity(nameStr, sn, s); // Store the pointer in the PhysicalEntity list. *************** *** 113,119 **** if (!name.empty()) { ! mPhysicalEntityMap[name] = pe; } return pe; } --- 133,204 ---- if (!name.empty()) { ! mPhysicalEntityMap[nameStr] = pe; ! } ! ! return pe; ! } ! ! /// Creates a PhysicalEntity drawn as a box. The OPAL Solid can ! /// be any shape, however. This is useful for prototyping scenes ! /// when you don't have a specific visual mesh to use. The name ! /// must be unique; unique names will be automatically generated ! /// for empty name strings. ! PhysicalEntity* createPhysicalEntityBox(const std::string& name, ! const std::string& materialName, Ogre::Vector3 dimensions, ! opal::Solid* s) ! { ! PhysicalEntity* pe = NULL; ! ! std::string nameStr = name; ! if (nameStr.empty()) ! { ! // Make a unique name. ! char newName[20]; ! sprintf(newName, "object%d", mNamelessObjectCount); ! mNamelessObjectCount++; ! nameStr = newName; ! } ! ! // This mesh must be stored as a box with dimensions 1x1x1. ! Entity* e = mSceneMgr->createEntity(nameStr, "cube.mesh"); ! e->setMaterialName(materialName); ! pe = createPhysicalEntity(nameStr, e, s); ! ! // Scale the mesh according to the given dimensions. ! e->getParentSceneNode()->scale(dimensions[0], dimensions[1], ! dimensions[2]); ! ! return pe; ! } ! ! /// Creates a PhysicalEntity drawn as a sphere. The OPAL Solid can ! /// be any shape, however. This is useful for prototyping scenes ! /// when you don't have a specific visual mesh to use. The name ! /// must be unique; unique names will be automatically generated ! /// for empty name strings. ! PhysicalEntity* createPhysicalEntitySphere(const std::string& name, ! const std::string& materialName, Ogre::Real radius, ! opal::Solid* s) ! { ! PhysicalEntity* pe = NULL; ! ! std::string nameStr = name; ! if (nameStr.empty()) ! { ! // Make a unique name. ! char newName[20]; ! sprintf(newName, "object%d", mNamelessObjectCount); ! mNamelessObjectCount++; ! nameStr = newName; } + // This mesh must be stored as a sphere with radius 1. + Entity* e = mSceneMgr->createEntity(nameStr, "sphere.mesh"); + e->setMaterialName(materialName); + pe = createPhysicalEntity(nameStr, e, s); + + // Scale the mesh according to the given dimensions. + e->getParentSceneNode()->scale(radius, radius, radius); + return pe; } *************** *** 233,236 **** --- 318,324 ---- bool mPaused; + /// A counter used to generate unique object names. + unsigned int mNamelessObjectCount; + /// Map of named PhysicalEntities. This is just used to find a /// PhysicalEntity by name. |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:16
|
Update of /cvsroot/opal/opal/samples/simple_objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340/samples/simple_objects Modified Files: main.cpp simple_objects.vcproj Log Message: added stuff to the playpen sample app Index: main.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/simple_objects/main.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** main.cpp 30 Mar 2005 23:26:21 -0000 1.28 --- main.cpp 1 Apr 2005 23:13:49 -0000 1.29 *************** *** 29,34 **** //float gMousePosWorld[2]; bool gMouseButtonsPressed[2]; ! const float gRotateSpeed = 3; ! const float gZoomSpeed = 3; opal::Simulator* gSimulator=NULL; std::vector<Base3DObject*> gObjects; --- 29,34 ---- //float gMousePosWorld[2]; bool gMouseButtonsPressed[2]; ! const float gRotateSpeed = 1; ! const float gZoomSpeed = 1; opal::Simulator* gSimulator=NULL; std::vector<Base3DObject*> gObjects; *************** *** 94,108 **** // Create and setup a Solid for the ground. ! gGround = gSimulator->createSolid(); ! gGround->setStatic(true); ! ! // Add a plane Shape to the Solid. ! opal::PlaneShapeData planeData; ! planeData.material = gGroundMaterial; ! planeData.abcd[0] = gGroundParams[0]; ! planeData.abcd[1] = gGroundParams[1]; ! planeData.abcd[2] = gGroundParams[2]; ! planeData.abcd[3] = gGroundParams[3]; ! gGround->addShape(planeData); // Create the objects used for picking. --- 94,99 ---- // Create and setup a Solid for the ground. ! gGround = gSimulator->createPlane(gGroundParams[0], gGroundParams[1], ! gGroundParams[2], gGroundParams[3], gGroundMaterial); // Create the objects used for picking. *************** *** 147,151 **** // Load the ragdoll Blueprint. ! opal::loadFile(gRagdollBP, "ragdoll.xml"); InitSDL(); --- 138,143 ---- // Load the ragdoll Blueprint. ! //opal::loadFile(gRagdollBP, "ragdoll.xml"); ! opal::loadFile(gRagdollBP, "SwitcherSceneOpal.xml"); InitSDL(); *************** *** 169,178 **** opal::Matrix44r offset; offset.translate(0, 2, 0); // Instantiate the Blueprint. opal::BlueprintInstance instance; ! gSimulator->instantiateBlueprint(instance, gRagdollBP, offset); ! int i=0; for (i=0; i<instance.getNumSolids(); ++i) { --- 161,171 ---- opal::Matrix44r offset; offset.translate(0, 2, 0); + offset.rotate(-90, 1, 0, 0); // Instantiate the Blueprint. opal::BlueprintInstance instance; ! gSimulator->instantiateBlueprint(instance, gRagdollBP, offset, 10); ! unsigned int i=0; for (i=0; i<instance.getNumSolids(); ++i) { *************** *** 220,224 **** { const opal::SolidData& data = s->getData(); ! int i=0; for (i=0; i<data.getNumShapes(); ++i) { --- 213,217 ---- { const opal::SolidData& data = s->getData(); ! unsigned int i=0; for (i=0; i<data.getNumShapes(); ++i) { *************** *** 500,507 **** break; case SDLK_a: ! gCameraZoom -= gZoomSpeed; break; case SDLK_z: ! gCameraZoom += gZoomSpeed; break; case SDLK_ESCAPE: //fall through --- 493,500 ---- break; case SDLK_a: ! gCameraZoom += gZoomSpeed; break; case SDLK_z: ! gCameraZoom -= gZoomSpeed; break; case SDLK_ESCAPE: //fall through *************** *** 836,840 **** void drawPickingSpring() ! { if (!gPickingSpring->isEnabled()) { --- 829,833 ---- void drawPickingSpring() ! {return; if (!gPickingSpring->isEnabled()) { Index: simple_objects.vcproj =================================================================== RCS file: /cvsroot/opal/opal/samples/simple_objects/simple_objects.vcproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** simple_objects.vcproj 1 Mar 2005 05:04:20 -0000 1.10 --- simple_objects.vcproj 1 Apr 2005 23:13:50 -0000 1.11 *************** *** 33,36 **** --- 33,37 ---- <Tool Name="VCLinkerTool" + AdditionalOptions="/STACK:10000000" AdditionalDependencies="opengl32.lib glu32.lib SDL.lib SDLmain.lib opal-ode_d.lib" OutputFile="$(OutDir)/simple_objects.exe" *************** *** 84,87 **** --- 85,89 ---- <Tool Name="VCLinkerTool" + AdditionalOptions="/STACK:10000000" AdditionalDependencies="opengl32.lib glu32.lib SDL.lib SDLmain.lib opal-ode.lib" OutputFile="$(OutDir)/simple_objects.exe" |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:16
|
Update of /cvsroot/opal/opal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340 Modified Files: todo.txt Log Message: added stuff to the playpen sample app Index: todo.txt =================================================================== RCS file: /cvsroot/opal/opal/todo.txt,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** todo.txt 31 Mar 2005 08:47:20 -0000 1.65 --- todo.txt 1 Apr 2005 23:13:50 -0000 1.66 *************** *** 26,31 **** --- 26,35 ---- * comment math functions + * add 'sleeping' user prop to max exporter + * rename 'vc7' to 'vc71' + * stop supporting vc6? + * finish web todo for 0.3.0 |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:01
|
Update of /cvsroot/opal/opal/samples/playpen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340/samples/playpen Modified Files: main.cpp playpen.vcproj Log Message: added stuff to the playpen sample app Index: main.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/main.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.cpp 31 Mar 2005 08:47:02 -0000 1.2 --- main.cpp 1 Apr 2005 23:13:49 -0000 1.3 *************** *** 7,241 **** { public: ! PlaypenApp() ! : BaseOpalApp() ! { ! mUseShadows = true; ! } ! ~PlaypenApp() ! {} protected: ! virtual void createScene() { ! // Setup shadows. ! if (mUseShadows) ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! //mSceneMgr->showBoundingBoxes(true); ! // Set the ambient light level. ! mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); ! // Create a light source. ! Ogre::Light* light = mSceneMgr->createLight("light0"); ! light->setType(Ogre::Light::LT_POINT); ! light->setPosition(80.0, 100.0, 30.0); ! // Create a skybox ! mSceneMgr->setSkyBox(true, "FlatGray", 5000); ! // Move the camera back a little. ! ExampleApplication::mCamera->moveRelative( ! Ogre::Vector3(0, 0, 10)); ! // Create a physical ground plane. ! mSimulator->createPlane(0, 1, 0, -2); ! // Create a visual ground plane. ! Ogre::Plane plane(Ogre::Vector3(0, 0, -1), 0); ! Ogre::MeshManager::getSingleton().createPlane("plane", "General", ! plane, 200, 200, 10, 10); ! Entity* e = mSceneMgr->createEntity("ground plane", "plane"); ! Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! createChildSceneNode("ground plane"); ! sn->attachObject(e); ! Ogre::Radian angle(Ogre::Degree(90)); ! sn->rotate(Ogre::Vector3(1, 0, 0), angle); ! sn->translate(0, -2, 0); ! // Load models, create physical objects, etc. here. ! e = mSceneMgr->createEntity("cube", "cube.mesh"); ! opal::Solid* s = mSimulator->createSolid(); ! //opal::SphereShapeData sphereData; ! //sphereData.radius = e->getBoundingRadius(); ! //s->addShape(sphereData); ! Ogre::AxisAlignedBox aabb = e->getBoundingBox(); ! Ogre::Vector3 aabbMin = aabb.getMinimum(); ! Ogre::Vector3 aabbMax = aabb.getMaximum(); ! opal::BoxShapeData boxData; ! boxData.dimensions.set(aabbMax[0] - aabbMin[0], ! aabbMax[1] - aabbMin[1], aabbMax[2] - aabbMin[2]); ! s->addShape(boxData); ! opalSamples::PhysicalEntity* pe = createPhysicalEntity("cube", ! e, s); ! // Testing... ! //Ogre::Real r = e->getBoundingRadius(); ! //e->getParentSceneNode()->scale(0.1, 0.1, 0.1); ! //r = e->getBoundingRadius(); } ! virtual bool appFrameStarted(opal::real dt) { ! // Do per-frame application specific things here. ! // Return true to continue looping. ! return true; } ! virtual bool processUnbufferedKeyInput(Ogre::Real dt) { ! // Check if we should quit looping. ! if(mInputDevice->isKeyDown(KC_ESCAPE) ! || mInputDevice->isKeyDown(KC_Q)) { ! return false; } ! // Check if we should pause physics. ! if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) ! { ! mPaused = !mPaused; ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Testing... ! if(mInputDevice->isKeyDown(KC_F)) ! { ! opalSamples::PhysicalEntity* pe = getPhysicalEntity("cube"); ! if (pe) ! { ! opal::Solid* s = pe->getSolid(); ! if (s) ! { ! opal::Force f; ! f.type = opal::GLOBAL_TORQUE; ! f.duration = (opal::real)0.05; ! f.vec.set(5, 5, 5); ! s->addForce(f); ! } ! } ! } ! // The following code can be used to update a camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; ! bool cameraMoved = false; ! if (mInputDevice->isKeyDown(KC_LEFT)) ! { ! // Move camera left. ! cameraDir.x -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_RIGHT)) ! { ! // Move camera right. ! cameraDir.x += (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_UP)) ! { ! // Move camera forward. ! cameraDir.z -= (dt * 5); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_DOWN)) ! { ! // Move camera backward. ! cameraDir.z += (dt * 5); ! cameraMoved = true; ! } ! if (!cameraMoved) ! { ! // Slow physical camera motion if necessary. ! } ! // Here, use the camera dir vector to affect the camera. ! ExampleApplication::mCamera->moveRelative(cameraDir); ! // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_S) && mTimeUntilNextToggle <= 0) ! { ! mUseShadows = !mUseShadows; ! if (mUseShadows) ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) ! { ! mStatsOn = !mStatsOn; ! showDebugOverlay(mStatsOn); ! mTimeUntilNextToggle = 1; ! } ! // Handy screenshot saving procedure. ! if (mInputDevice->isKeyDown(KC_SYSRQ) ! && mTimeUntilNextToggle <= 0) ! { ! char tmp[20]; ! sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); ! ExampleApplication::mWindow->writeContentsToFile(tmp); ! ExampleApplication::mWindow->setDebugText(String("Wrote ") ! + tmp); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Return true to continue looping. ! return true; } ! virtual bool processUnbufferedMouseInput(Ogre::Real dt) { ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(0)) { ! // The left mouse button is down. } else { ! // The left mouse button is up. } ! // The following code checks how far the mouse has move since ! // the last poll. This data can be used to rotate the camera ! // around its X and Y axes (yaw and pitch, respectively). ! Ogre::Real rotX = -mInputDevice->getMouseRelativeX(); ! Ogre::Real rotY = -mInputDevice->getMouseRelativeY(); ! // Return true to continue looping. ! return true; } ! private: ! /// Used to toggle shadows on and off. ! bool mUseShadows; ! }; } --- 7,382 ---- { public: ! PlaypenApp(); ! ~PlaypenApp(); protected: ! virtual void createScene(); ! ! virtual bool appFrameStarted(opal::real dt); ! ! virtual bool processUnbufferedKeyInput(Ogre::Real dt); ! ! virtual bool processUnbufferedMouseInput(Ogre::Real dt); ! ! /// Builds a wall of boxes centered at the origin. ! void createWall(unsigned int length, unsigned height, ! opal::Vec3r boxDim, ! opal::Matrix44r baseTransform = opal::Matrix44r()); ! ! /// Builds a tower of boxes centered at the origin. ! void createTower(unsigned int length, unsigned int width, ! unsigned height, opal::Vec3r boxDim, ! opal::Matrix44r baseTransform = opal::Matrix44r()); ! ! private: ! /// Used to toggle shadows on and off. ! bool mUseShadows; ! ! /// Point where new objects are created. ! opal::Point3r mCreationPoint; ! }; ! ! PlaypenApp::PlaypenApp() ! : BaseOpalApp() ! { ! mUseShadows = true; ! mCreationPoint.set(0, 20, 0); ! } ! ! PlaypenApp::~PlaypenApp() ! { ! } ! ! void PlaypenApp::createScene() ! { ! // Setup shadows. ! if (mUseShadows) { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); ! } ! else ! { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); ! } ! //mSceneMgr->showBoundingBoxes(true); ! // Set the ambient light level. ! mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); ! // Create a light source. ! Ogre::Light* light = mSceneMgr->createLight("light0"); ! light->setType(Ogre::Light::LT_POINT); ! light->setDiffuseColour(1.0, 1.0, 1.0); ! light->setSpecularColour(1.0, 1.0, 1.0); ! light->setPosition(100.0, 300.0, 100.0); ! // Setup the initial camera position. ! ExampleApplication::mCamera->setPosition( ! Ogre::Vector3(0, 30, 50)); ! ExampleApplication::mCamera->lookAt(0, 0, 0); ! // Create a skybox. ! mSceneMgr->setSkyBox(true, "Skyboxes/Gray", 5000); ! //// Create a physical ground plane. ! //mSimulator->createPlane(0, 1, 0, 0); ! //// Create a visual ground plane. ! //Ogre::Plane plane(Ogre::Vector3(0, 0, -1), 0); ! //Ogre::MeshManager::getSingleton().createPlane("plane", "General", ! // plane, 3000, 3000, 10, 10); ! //Entity* e = mSceneMgr->createEntity("ground plane", "plane"); ! //e->setMaterialName("Flat/Gray"); ! //Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! // createChildSceneNode("ground plane"); ! //sn->attachObject(e); ! //Ogre::Radian angle(Ogre::Degree(90)); ! //sn->rotate(Ogre::Vector3(1, 0, 0), angle); ! // Create a static box for a ground plane. ! Ogre::Vector3 groundDim(100, 8, 100); ! opal::Solid* s = mSimulator->createSolid(); ! s->setStatic(true); ! s->setPosition(0, -4, 0); ! opal::BoxShapeData data; ! data.dimensions.set(groundDim[0], groundDim[1], groundDim[2]); ! s->addShape(data); ! createPhysicalEntityBox("ground", "Plastic/Gray", groundDim, s); ! // Make a crosshairs for picking. ! ! // Load models, create physical objects, etc. here. ! } ! ! bool PlaypenApp::appFrameStarted(opal::real dt) ! { ! // Do per-frame application specific things here. ! ! // Return true to continue looping. ! return true; ! } ! ! bool PlaypenApp::processUnbufferedKeyInput(Ogre::Real dt) ! { ! // Check if we should quit looping. ! if(mInputDevice->isKeyDown(KC_ESCAPE) ! || mInputDevice->isKeyDown(KC_Q)) ! { ! return false; } ! // Check if we should pause physics. ! if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) { ! mPaused = !mPaused; ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; } ! // Testing... ! if(mInputDevice->isKeyDown(KC_F)) { ! opalSamples::PhysicalEntity* pe = getPhysicalEntity("object0"); ! if (pe) { ! opal::Solid* s = pe->getSolid(); ! if (s) ! { ! opal::Force f; ! f.type = opal::GLOBAL_TORQUE; ! f.duration = (opal::real)0.05; ! f.vec.set(5, 5, 5); ! s->addForce(f); ! } } + } ! // Create various types of objects when the number keys are ! // pressed. ! // Create a small box. ! if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) ! { ! Ogre::Vector3 boxDim(1, 1, 1); ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::BoxShapeData data; ! data.dimensions.set(boxDim[0], boxDim[1], boxDim[2]); ! s->addShape(data); ! createPhysicalEntityBox("", "Plastic/Red", boxDim, s); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! // Create a small sphere. ! if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) ! { ! Ogre::Real radius = 0.5; ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::SphereShapeData data; ! data.radius = radius; ! s->addShape(data); ! createPhysicalEntitySphere("", "Plastic/Blue", radius, s); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! // Create a large box. ! if(mInputDevice->isKeyDown(KC_1) && mTimeUntilNextToggle <= 0) ! { ! Ogre::Vector3 boxDim(3, 3, 3); ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::BoxShapeData data; ! data.dimensions.set(boxDim[0], boxDim[1], boxDim[2]); ! s->addShape(data); ! createPhysicalEntityBox("", "Plastic/Red", boxDim, s); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! // Create a large sphere. ! if(mInputDevice->isKeyDown(KC_2) && mTimeUntilNextToggle <= 0) ! { ! Ogre::Real radius = 1.5; ! opal::Solid* s = mSimulator->createSolid(); ! s->setPosition(mCreationPoint); ! opal::SphereShapeData data; ! data.radius = radius; ! s->addShape(data); ! createPhysicalEntitySphere("", "Plastic/Blue", radius, s); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! // Create a wall. ! if(mInputDevice->isKeyDown(KC_5) && mTimeUntilNextToggle <= 0) ! { ! createWall(5, 5, opal::Vec3r(2, 1, 1)); ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.3; ! } ! // The following code updates the camera's position. ! Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; ! bool cameraMoved = false; ! if (mInputDevice->isKeyDown(KC_LEFT) ! || mInputDevice->isKeyDown(KC_A)) ! { ! // Move camera left. ! cameraDir.x -= (dt * mMoveSpeed); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_RIGHT) ! || mInputDevice->isKeyDown(KC_D)) ! { ! // Move camera right. ! cameraDir.x += (dt * mMoveSpeed); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_UP) ! || mInputDevice->isKeyDown(KC_W)) ! { ! // Move camera forward. ! cameraDir.z -= (dt * mMoveSpeed); ! cameraMoved = true; ! } ! if (mInputDevice->isKeyDown(KC_DOWN) ! || mInputDevice->isKeyDown(KC_S)) ! { ! // Move camera backward. ! cameraDir.z += (dt * mMoveSpeed); ! cameraMoved = true; ! } ! if (!cameraMoved) ! { ! // Slow physical camera motion if necessary. } ! // Use the camera dir vector to translate the camera. ! ExampleApplication::mCamera->moveRelative(cameraDir); ! ! // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) { ! mUseShadows = !mUseShadows; ! ! if (mUseShadows) { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); } else { ! mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); } ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! // Toggle HUD. ! if (mInputDevice->isKeyDown(KC_H) && mTimeUntilNextToggle <= 0) ! { ! mStatsOn = !mStatsOn; ! showDebugOverlay(mStatsOn); ! mTimeUntilNextToggle = 1; } ! // Handy screenshot saving procedure. ! if (mInputDevice->isKeyDown(KC_SYSRQ) ! && mTimeUntilNextToggle <= 0) ! { ! char tmp[20]; ! sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); ! ExampleApplication::mWindow->writeContentsToFile(tmp); ! ExampleApplication::mWindow->setDebugText(String("Wrote ") ! + tmp); ! ! // Reset the timer for toggle keys. ! mTimeUntilNextToggle = 0.5; ! } ! ! // Return true to continue looping. ! return true; ! } ! ! bool PlaypenApp::processUnbufferedMouseInput(Ogre::Real dt) ! { ! // The following code checks how far the mouse has move since ! // the last poll. This data can be used to rotate the camera ! // around its X and Y axes (pitch and yaw, respectively). ! Ogre::Radian rotY(-mInputDevice->getMouseRelativeX() * mRotateSpeed); ! Ogre::Radian rotX(-mInputDevice->getMouseRelativeY() * mRotateSpeed); ! ! // The following code checks the mouse button state. ! if (true == mInputDevice->getMouseButton(1)) ! { ! // The right mouse button is down. ! ! // Use the relative mouse motion to rotate the camera. ! ExampleApplication::mCamera->yaw(rotY); ! ExampleApplication::mCamera->pitch(rotX); ! } ! else ! { ! // The right mouse button is up. ! } ! ! // Return true to continue looping. ! return true; ! } ! ! void PlaypenApp::createWall(unsigned int length, unsigned height, ! opal::Vec3r boxDim, opal::Matrix44r baseTransform) ! { ! opal::Matrix44r tempTransform; ! ! for (unsigned int l=0; l<length; ++l) ! { ! for (unsigned int h=0; h<height; ++h) ! { ! opal::real offset = 0; ! if (h % 2 == 0) ! { ! offset = (opal::real)0.5 * boxDim[0]; ! } ! ! tempTransform = baseTransform; ! tempTransform.translate(l * boxDim[0] + ! 0.5 * boxDim[0] - 0.5 * length * boxDim[0] + ! offset, h * boxDim[1] + 0.5 * boxDim[1], 0); ! ! opal::Solid* s = mSimulator->createSolid(); ! s->setTransform(tempTransform); ! //s->setSleeping(true); ! opal::BoxShapeData boxData; ! boxData.dimensions = boxDim; ! s->addShape(boxData); ! Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]); ! createPhysicalEntityBox("", "Plastic/Red", boxDimensions, s); ! } ! } ! } ! ! void PlaypenApp::createTower(unsigned int length, unsigned int width, ! unsigned height, opal::Vec3r boxDim, opal::Matrix44r baseTransform) ! { ! ! } } Index: playpen.vcproj =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/playpen.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** playpen.vcproj 30 Mar 2005 23:26:24 -0000 1.1 --- playpen.vcproj 1 Apr 2005 23:13:49 -0000 1.2 *************** *** 34,38 **** Name="VCLinkerTool" AdditionalDependencies="ogremain_d.lib opal-ode_d.lib" ! OutputFile="$(OutDir)/playpen.exe" LinkIncremental="2" AdditionalLibraryDirectories="" --- 34,38 ---- Name="VCLinkerTool" AdditionalDependencies="ogremain_d.lib opal-ode_d.lib" ! OutputFile="../win32bin/debug/playpen.exe" LinkIncremental="2" AdditionalLibraryDirectories="" *************** *** 85,89 **** Name="VCLinkerTool" AdditionalDependencies="ogremain.lib opal-ode.lib" ! OutputFile="$(OutDir)/playpen.exe" LinkIncremental="1" AdditionalLibraryDirectories="" --- 85,89 ---- Name="VCLinkerTool" AdditionalDependencies="ogremain.lib opal-ode.lib" ! OutputFile="../win32bin/release/playpen.exe" LinkIncremental="1" AdditionalLibraryDirectories="" |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:00
|
Update of /cvsroot/opal/opal/samples/data/materials In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340/samples/data/materials Modified Files: basic.material skyboxes.material Log Message: added stuff to the playpen sample app Index: basic.material =================================================================== RCS file: /cvsroot/opal/opal/samples/data/materials/basic.material,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** basic.material 31 Mar 2005 08:47:20 -0000 1.1 --- basic.material 1 Apr 2005 23:13:48 -0000 1.2 *************** *** 1,15 **** material Plastic/Red { ! receive_shadows on ! technique ! { ! pass ! { ! ambient 0.000000 0.000000 0.000000 ! diffuse 0.9 0.0 0.0 ! specular 0.500000 0.500000 0.500000 50.000000 ! emissive 0.000000 0.000000 0.000000 ! } ! } } --- 1,47 ---- material Plastic/Red { ! receive_shadows on ! ! technique ! { ! pass ! { ! ambient 1 0 0 ! diffuse 1 0 0 ! specular 0.2 0.2 0.2 50 ! emissive 0 0 0 ! } ! } ! } ! ! material Plastic/Blue ! { ! receive_shadows on ! ! technique ! { ! pass ! { ! ambient 0 0 1 ! diffuse 0 0 1 ! specular 0.2 0.2 0.2 50 ! emissive 0 0 0 ! } ! } } + material Plastic/Gray + { + receive_shadows on + + technique + { + pass + { + ambient 0.5 0.5 0.5 + diffuse 0.5 0.5 0.5 + specular 0.2 0.2 0.2 50 + emissive 0 0 0 + } + } + } Index: skyboxes.material =================================================================== RCS file: /cvsroot/opal/opal/samples/data/materials/skyboxes.material,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** skyboxes.material 31 Mar 2005 08:47:20 -0000 1.1 --- skyboxes.material 1 Apr 2005 23:13:48 -0000 1.2 *************** *** 1,3 **** ! material FlatGray { technique --- 1,3 ---- ! material Skyboxes/Gray { technique |
|
From: tylerstreeter <tyl...@us...> - 2005-04-01 23:14:00
|
Update of /cvsroot/opal/opal/samples/data/models In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30340/samples/data/models Modified Files: cube.mesh Log Message: added stuff to the playpen sample app Index: cube.mesh =================================================================== RCS file: /cvsroot/opal/opal/samples/data/models/cube.mesh,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsTIOQW6 and /tmp/cvsLnpEyU differ |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:58
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/src Modified Files: Blueprint.cpp Blueprint.h BlueprintInstance.cpp BlueprintInstance.h CapsuleShapeData.h Defines.h Simulator.cpp Simulator.h SolidData.cpp SolidData.h Log Message: added some helper functions to Simulator; added data for ogre sample apps Index: SolidData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SolidData.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SolidData.h 11 Mar 2005 05:31:56 -0000 1.7 --- SolidData.h 31 Mar 2005 08:47:02 -0000 1.8 *************** *** 50,54 **** /// Returns the number of Shapes in this SolidData. ! OPAL_DECL virtual int OPAL_CALL getNumShapes()const; /// Returns a pointer to the ShapeData at the given index. --- 50,54 ---- /// Returns the number of Shapes in this SolidData. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumShapes()const; /// Returns a pointer to the ShapeData at the given index. Index: CapsuleShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/CapsuleShapeData.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CapsuleShapeData.h 11 Mar 2005 05:31:56 -0000 1.5 --- CapsuleShapeData.h 31 Mar 2005 08:47:02 -0000 1.6 *************** *** 34,38 **** namespace opal { ! /// A data structure describing a capsule Shape. class CapsuleShapeData : public ShapeData { --- 34,39 ---- namespace opal { ! /// A data structure describing a capsule Shape. Capsules start out ! /// aligned along their local Z axis. class CapsuleShapeData : public ShapeData { *************** *** 71,75 **** real radius; ! /// The capsule's length. real length; --- 72,76 ---- real radius; ! /// The capsule's length, not including the round caps. real length; Index: Defines.h =================================================================== RCS file: /cvsroot/opal/opal/src/Defines.h,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** Defines.h 30 Mar 2005 23:26:22 -0000 1.70 --- Defines.h 31 Mar 2005 08:47:02 -0000 1.71 *************** *** 299,303 **** namespace shape { ! const Material material = opal::globals::woodMaterial; const unsigned int contactGroup = 0; const Vec3r boxDimensions = Vec3r(1, 1, 1); --- 299,303 ---- namespace shape { ! const Material material = globals::woodMaterial; const unsigned int contactGroup = 0; const Vec3r boxDimensions = Vec3r(1, 1, 1); Index: Blueprint.h =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Blueprint.h 26 Feb 2005 10:22:23 -0000 1.24 --- Blueprint.h 31 Mar 2005 08:47:02 -0000 1.25 *************** *** 80,93 **** /// Returns the number of SolidData objects. ! OPAL_DECL virtual int OPAL_CALL getNumSolids()const; /// Returns the number of JointData objects. ! OPAL_DECL virtual int OPAL_CALL getNumJoints()const; /// Returns the number of MotorData objects. ! OPAL_DECL virtual int OPAL_CALL getNumMotors()const; /// Returns the number of SensorData objects. ! OPAL_DECL virtual int OPAL_CALL getNumSensors()const; /// Returns a pointer to the SolidData at the given index. --- 80,93 ---- /// Returns the number of SolidData objects. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumSolids()const; /// Returns the number of JointData objects. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumJoints()const; /// Returns the number of MotorData objects. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumMotors()const; /// Returns the number of SensorData objects. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumSensors()const; /// Returns a pointer to the SolidData at the given index. Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Blueprint.cpp 29 Mar 2005 03:05:46 -0000 1.21 --- Blueprint.cpp 31 Mar 2005 08:47:02 -0000 1.22 *************** *** 377,396 **** } ! int Blueprint::getNumSolids()const { return (int)(mSolidList.size()); } ! int Blueprint::getNumJoints()const { return (int)(mJointList.size()); } ! int Blueprint::getNumMotors()const { return (int)(mMotorList.size()); } ! int Blueprint::getNumSensors()const { return (int)(mSensorList.size()); --- 377,396 ---- } ! unsigned int Blueprint::getNumSolids()const { return (int)(mSolidList.size()); } ! unsigned int Blueprint::getNumJoints()const { return (int)(mJointList.size()); } ! unsigned int Blueprint::getNumMotors()const { return (int)(mMotorList.size()); } ! unsigned int Blueprint::getNumSensors()const { return (int)(mSensorList.size()); Index: BlueprintInstance.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintInstance.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BlueprintInstance.h 3 Mar 2005 04:39:55 -0000 1.3 --- BlueprintInstance.h 31 Mar 2005 08:47:02 -0000 1.4 *************** *** 71,84 **** /// Returns the number of Solids in this BlueprintInstance. ! OPAL_DECL virtual int OPAL_CALL getNumSolids()const; /// Returns the number of Joints in this BlueprintInstance. ! OPAL_DECL virtual int OPAL_CALL getNumJoints()const; /// Returns the number of Motors in this BlueprintInstance. ! OPAL_DECL virtual int OPAL_CALL getNumMotors()const; /// Returns the number of Sensors in this BlueprintInstance. ! OPAL_DECL virtual int OPAL_CALL getNumSensors()const; /// Finds a Solid by index and returns its pointer. --- 71,84 ---- /// Returns the number of Solids in this BlueprintInstance. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumSolids()const; /// Returns the number of Joints in this BlueprintInstance. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumJoints()const; /// Returns the number of Motors in this BlueprintInstance. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumMotors()const; /// Returns the number of Sensors in this BlueprintInstance. ! OPAL_DECL virtual unsigned int OPAL_CALL getNumSensors()const; /// Finds a Solid by index and returns its pointer. Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** Simulator.cpp 30 Mar 2005 23:26:22 -0000 1.54 --- Simulator.cpp 31 Mar 2005 08:47:02 -0000 1.55 *************** *** 306,310 **** std::vector<Solid*> solidList; std::vector<Joint*> jointList; ! int i; // Create all Solids in the Blueprint. --- 306,310 ---- std::vector<Solid*> solidList; std::vector<Joint*> jointList; ! unsigned int i; // Create all Solids in the Blueprint. *************** *** 331,335 **** // Scale the Solid's Shape's offsets and dimensions. ! int i=0; for (i=0; i<sd.getNumShapes(); ++i) { --- 331,335 ---- // Scale the Solid's Shape's offsets and dimensions. ! unsigned int i=0; for (i=0; i<sd.getNumShapes(); ++i) { *************** *** 737,740 **** --- 737,771 ---- } + Solid* Simulator::createPlane(real a, real b, real c, real d, + const Material& m) + { + // Create the plane's Solid and make it static. + Solid* plane = createSolid(); + plane->setStatic(true); + + // Setup the plane's Shape data. + opal::PlaneShapeData planeData; + planeData.material = m; + planeData.abcd[0] = a; + planeData.abcd[1] = b; + planeData.abcd[2] = c; + planeData.abcd[3] = d; + + // Add the Shape to the Solid. + plane->addShape(planeData); + + return plane; + } + + unsigned int Simulator::getNumSolids()const + { + return (unsigned int)(mSolidList.size()); + } + + Solid* Simulator::getSolid(unsigned int i)const + { + return mSolidList.at(i); + } + void Simulator::destroySolid(Solid* s) { *************** *** 752,760 **** } - //const std::vector<Solid*>& Simulator::getSolids()const - //{ - // return mSolidList; - //} - void Simulator::destroyJoint(Joint* j) { --- 783,786 ---- Index: BlueprintInstance.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintInstance.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BlueprintInstance.cpp 3 Mar 2005 04:39:55 -0000 1.3 --- BlueprintInstance.cpp 31 Mar 2005 08:47:02 -0000 1.4 *************** *** 107,126 **** } ! int BlueprintInstance::getNumSolids()const { return (int)(mSolidList.size()); } ! int BlueprintInstance::getNumJoints()const { return (int)(mJointList.size()); } ! int BlueprintInstance::getNumMotors()const { return (int)(mMotorList.size()); } ! int BlueprintInstance::getNumSensors()const { return (int)(mSensorList.size()); --- 107,126 ---- } ! unsigned int BlueprintInstance::getNumSolids()const { return (int)(mSolidList.size()); } ! unsigned int BlueprintInstance::getNumJoints()const { return (int)(mJointList.size()); } ! unsigned int BlueprintInstance::getNumMotors()const { return (int)(mMotorList.size()); } ! unsigned int BlueprintInstance::getNumSensors()const { return (int)(mSensorList.size()); Index: SolidData.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/SolidData.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SolidData.cpp 5 Mar 2005 21:26:24 -0000 1.3 --- SolidData.cpp 31 Mar 2005 08:47:02 -0000 1.4 *************** *** 103,109 **** } ! int SolidData::getNumShapes()const { ! return (int)(mShapes.size()); } --- 103,109 ---- } ! unsigned int SolidData::getNumShapes()const { ! return (unsigned int)(mShapes.size()); } Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** Simulator.h 30 Mar 2005 23:26:22 -0000 1.92 --- Simulator.h 31 Mar 2005 08:47:02 -0000 1.93 *************** *** 168,171 **** --- 168,181 ---- virtual Solid* OPAL_CALL createSolid() = 0; + /// Helper function for creating a static Solid with a Plane Shape. + virtual Solid* OPAL_CALL createPlane(real a, real b, real c, real d, + const Material& m = defaults::shape::material); + + /// Returns the number of Solids in the Simulator. + virtual unsigned int OPAL_CALL getNumSolids()const; + + /// Returns a pointer to the Solid at the given index. + virtual Solid* OPAL_CALL getSolid(unsigned int i)const; + /// Immediately destroys the given Solid. All Joints, Motors, and /// Sensors that depend on this Solid will be automatically *************** *** 176,182 **** virtual void OPAL_CALL destroyAllSolids(); - /// Returns all Solids in the Simulator. - //virtual const std::vector<Solid*>& OPAL_CALL getSolids()const; - // JOINTS --- 186,189 ---- |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:41
|
Update of /cvsroot/opal/opal/samples/playpen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/samples/playpen Modified Files: main.cpp Log Message: added some helper functions to Simulator; added data for ogre sample apps Index: main.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/playpen/main.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.cpp 30 Mar 2005 23:26:24 -0000 1.1 --- main.cpp 31 Mar 2005 08:47:02 -0000 1.2 *************** *** 4,8 **** namespace playpen { ! class PlaypenApp : public BaseOpalApp { public: --- 4,8 ---- namespace playpen { ! class PlaypenApp : public opalSamples::BaseOpalApp { public: *************** *** 29,32 **** --- 29,34 ---- } + //mSceneMgr->showBoundingBoxes(true); + // Set the ambient light level. mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); *************** *** 35,41 **** Ogre::Light* light = mSceneMgr->createLight("light0"); light->setType(Ogre::Light::LT_POINT); ! light->setPosition(-80.0, 30.0, -10.0); // Load models, create physical objects, etc. here. } --- 37,85 ---- Ogre::Light* light = mSceneMgr->createLight("light0"); light->setType(Ogre::Light::LT_POINT); ! light->setPosition(80.0, 100.0, 30.0); ! ! // Create a skybox ! mSceneMgr->setSkyBox(true, "FlatGray", 5000); ! ! // Move the camera back a little. ! ExampleApplication::mCamera->moveRelative( ! Ogre::Vector3(0, 0, 10)); ! ! // Create a physical ground plane. ! mSimulator->createPlane(0, 1, 0, -2); ! ! // Create a visual ground plane. ! Ogre::Plane plane(Ogre::Vector3(0, 0, -1), 0); ! Ogre::MeshManager::getSingleton().createPlane("plane", "General", ! plane, 200, 200, 10, 10); ! Entity* e = mSceneMgr->createEntity("ground plane", "plane"); ! Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! createChildSceneNode("ground plane"); ! sn->attachObject(e); ! Ogre::Radian angle(Ogre::Degree(90)); ! sn->rotate(Ogre::Vector3(1, 0, 0), angle); ! sn->translate(0, -2, 0); // Load models, create physical objects, etc. here. + + e = mSceneMgr->createEntity("cube", "cube.mesh"); + opal::Solid* s = mSimulator->createSolid(); + //opal::SphereShapeData sphereData; + //sphereData.radius = e->getBoundingRadius(); + //s->addShape(sphereData); + Ogre::AxisAlignedBox aabb = e->getBoundingBox(); + Ogre::Vector3 aabbMin = aabb.getMinimum(); + Ogre::Vector3 aabbMax = aabb.getMaximum(); + opal::BoxShapeData boxData; + boxData.dimensions.set(aabbMax[0] - aabbMin[0], + aabbMax[1] - aabbMin[1], aabbMax[2] - aabbMin[2]); + s->addShape(boxData); + opalSamples::PhysicalEntity* pe = createPhysicalEntity("cube", + e, s); + + // Testing... + //Ogre::Real r = e->getBoundingRadius(); + //e->getParentSceneNode()->scale(0.1, 0.1, 0.1); + //r = e->getBoundingRadius(); } *************** *** 57,84 **** } // The following code can be used to update a camera's position. if (mInputDevice->isKeyDown(KC_LEFT)) { // Move camera left. } ! else if (mInputDevice->isKeyDown(KC_RIGHT)) { // Move camera right. } ! else if (mInputDevice->isKeyDown(KC_UP)) { // Move camera forward. } ! else if (mInputDevice->isKeyDown(KC_DOWN)) { // Move camera backward. } ! else { ! // Stop camera motion if necessary. } // Toggle shadows. ! if( mInputDevice->isKeyDown(KC_S)) { mUseShadows = !mUseShadows; --- 101,173 ---- } + // Check if we should pause physics. + if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) + { + mPaused = !mPaused; + + // Reset the timer for toggle keys. + mTimeUntilNextToggle = 0.5; + } + + // Testing... + if(mInputDevice->isKeyDown(KC_F)) + { + opalSamples::PhysicalEntity* pe = getPhysicalEntity("cube"); + if (pe) + { + opal::Solid* s = pe->getSolid(); + if (s) + { + opal::Force f; + f.type = opal::GLOBAL_TORQUE; + f.duration = (opal::real)0.05; + f.vec.set(5, 5, 5); + s->addForce(f); + } + } + } + // The following code can be used to update a camera's position. + Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; + bool cameraMoved = false; + if (mInputDevice->isKeyDown(KC_LEFT)) { // Move camera left. + cameraDir.x -= (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_RIGHT)) { // Move camera right. + cameraDir.x += (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_UP)) { // Move camera forward. + cameraDir.z -= (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_DOWN)) { // Move camera backward. + cameraDir.z += (dt * 5); + cameraMoved = true; } ! ! if (!cameraMoved) { ! // Slow physical camera motion if necessary. } + // Here, use the camera dir vector to affect the camera. + ExampleApplication::mCamera->moveRelative(cameraDir); + // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_S) && mTimeUntilNextToggle <= 0) { mUseShadows = !mUseShadows; *************** *** 93,98 **** } ! // Set this to keep from handling the key press ! // continually while it is down. mTimeUntilNextToggle = 0.5; } --- 182,186 ---- } ! // Reset the timer for toggle keys. mTimeUntilNextToggle = 0.5; } *************** *** 116,121 **** + tmp); ! // Set this to keep from handling the key press ! // continually while it is down. mTimeUntilNextToggle = 0.5; } --- 204,208 ---- + tmp); ! // Reset the timer for toggle keys. mTimeUntilNextToggle = 0.5; } |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:41
|
Update of /cvsroot/opal/opal/samples/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/samples/src Modified Files: BaseOpalApp.h ExampleApplication.h ExampleFrameListener.h TemplateApp.cpp Log Message: added some helper functions to Simulator; added data for ogre sample apps Index: TemplateApp.cpp =================================================================== RCS file: /cvsroot/opal/opal/samples/src/TemplateApp.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TemplateApp.cpp 30 Mar 2005 23:26:25 -0000 1.1 --- TemplateApp.cpp 31 Mar 2005 08:47:02 -0000 1.2 *************** *** 4,8 **** namespace myAppNamespace { ! class MyApp : public BaseOpalApp { public: --- 4,8 ---- namespace myAppNamespace { ! class MyApp : public opalSamples::BaseOpalApp { public: *************** *** 57,84 **** } // The following code can be used to update a camera's position. if (mInputDevice->isKeyDown(KC_LEFT)) { // Move camera left. } ! else if (mInputDevice->isKeyDown(KC_RIGHT)) { // Move camera right. } ! else if (mInputDevice->isKeyDown(KC_UP)) { // Move camera forward. } ! else if (mInputDevice->isKeyDown(KC_DOWN)) { // Move camera backward. } ! else { ! // Stop camera motion if necessary. } // Toggle shadows. ! if( mInputDevice->isKeyDown(KC_S)) { mUseShadows = !mUseShadows; --- 57,110 ---- } + // Check if we should pause physics. + if(mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) + { + mPaused = !mPaused; + + // Reset the timer for toggle keys. + mTimeUntilNextToggle = 0.5; + } + // The following code can be used to update a camera's position. + Ogre::Vector3 cameraDir = Ogre::Vector3::ZERO; + bool cameraMoved = false; + if (mInputDevice->isKeyDown(KC_LEFT)) { // Move camera left. + cameraDir.x -= (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_RIGHT)) { // Move camera right. + cameraDir.x += (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_UP)) { // Move camera forward. + cameraDir.z -= (dt * 5); + cameraMoved = true; } ! ! if (mInputDevice->isKeyDown(KC_DOWN)) { // Move camera backward. + cameraDir.z += (dt * 5); + cameraMoved = true; } ! ! if (!cameraMoved) { ! // Slow physical camera motion if necessary. } + // Here, use the camera dir vector to affect the camera. + // Toggle shadows. ! if(mInputDevice->isKeyDown(KC_S) && mTimeUntilNextToggle <= 0) { mUseShadows = !mUseShadows; *************** *** 93,98 **** } ! // Set this to keep from handling the key press ! // continually while it is down. mTimeUntilNextToggle = 0.5; } --- 119,123 ---- } ! // Reset the timer for toggle keys. mTimeUntilNextToggle = 0.5; } *************** *** 116,121 **** + tmp); ! // Set this to keep from handling the key press ! // continually while it is down. mTimeUntilNextToggle = 0.5; } --- 141,145 ---- + tmp); ! // Reset the timer for toggle keys. mTimeUntilNextToggle = 0.5; } Index: ExampleApplication.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/ExampleApplication.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExampleApplication.h 30 Mar 2005 23:26:25 -0000 1.1 --- ExampleApplication.h 31 Mar 2005 08:47:02 -0000 1.2 *************** *** 124,127 **** --- 124,129 ---- mSceneMgr = mRoot->getSceneManager(ST_GENERIC); } + + // This function was modifed for the Opal sample apps. virtual void createCamera(void) { *************** *** 129,138 **** mCamera = mSceneMgr->createCamera("PlayerCam"); ! // Position it at 500 in Z direction ! mCamera->setPosition(Vector3(0,0,500)); // Look back along -Z mCamera->lookAt(Vector3(0,0,-300)); - mCamera->setNearClipDistance(5); } --- 131,141 ---- mCamera = mSceneMgr->createCamera("PlayerCam"); ! // Position it at the origin. ! mCamera->setPosition(Vector3(0, 0, 0)); ! // Look back along -Z mCamera->lookAt(Vector3(0,0,-300)); + mCamera->setNearClipDistance(0.5); } Index: ExampleFrameListener.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/ExampleFrameListener.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExampleFrameListener.h 30 Mar 2005 23:26:25 -0000 1.1 --- ExampleFrameListener.h 31 Mar 2005 08:47:02 -0000 1.2 *************** *** 95,99 **** // your app from BaseOpalApp, you should be fine. ExampleFrameListener() ! {} // Takes a RenderWindow because it uses that to determine input context. --- 95,121 ---- // your app from BaseOpalApp, you should be fine. ExampleFrameListener() ! { ! mDebugOverlay = NULL; ! mUseBufferedInputKeys = false; ! mUseBufferedInputMouse = false; ! mInputTypeSwitchingOn = false; ! mRotateSpeed = 36; ! mMoveSpeed = 100; ! ! mEventProcessor = NULL; ! mInputDevice = NULL; ! ! mCamera = NULL; ! mWindow = NULL; ! mStatsOn = true; ! mNumScreenShots = 0; ! mTimeUntilNextToggle = 0; ! mSceneDetailIndex = 0; ! mMoveScale = 0.0f; ! mRotScale = 0.0f; ! mTranslateVector = Vector3::ZERO; ! mAniso = 1; ! mFiltering = TFO_BILINEAR; ! } // Takes a RenderWindow because it uses that to determine input context. *************** *** 142,146 **** { if (mInputTypeSwitchingOn) - { delete mEventProcessor; --- 164,167 ---- *************** *** 148,152 **** else { ! PlatformManager::getSingleton().destroyInputReader( mInputDevice ); } } --- 169,173 ---- else { ! PlatformManager::getSingleton().destroyInputReader(mInputDevice); } } Index: BaseOpalApp.h =================================================================== RCS file: /cvsroot/opal/opal/samples/src/BaseOpalApp.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BaseOpalApp.h 30 Mar 2005 23:26:24 -0000 1.1 --- BaseOpalApp.h 31 Mar 2005 08:47:02 -0000 1.2 *************** *** 1,110 **** ! #ifndef BASE_OPAL_APP_H ! #define BASE_OPAL_APP_H #include "ExampleApplication.h" #include "ExampleFrameListener.h" #include <opal/opal.h> ! class BaseOpalApp : public ExampleApplication, public ExampleFrameListener { ! public: ! BaseOpalApp() ! : ExampleApplication(), ExampleFrameListener() { ! mSimulator = opal::createSimulator(); ! } ! ~BaseOpalApp() ! { ! mSimulator->destroy(); ! } ! protected: ! /// Register the frame listener with the Ogre root so it will ! /// call the listener at the appropriate time. ! virtual void createFrameListener() ! { ! ExampleFrameListener::init(ExampleApplication::mWindow, ! ExampleApplication::mCamera); ! mRoot->addFrameListener(this); ! } ! /// Initial scene setup function. Create and position lights, load ! /// models, create a camera, etc. ! virtual void createScene() = 0; ! /// Called once per frame after input and physics have been updated. ! /// This is a place for applications to do application-specific updates ! /// per frame. It takes the dt since the last frame as a parameter. ! /// This should return false if we should break out of the main loop. ! virtual bool appFrameStarted(opal::real dt) = 0; ! /// Called at the start of each frame. Calculate dt since the last ! /// frame, update input, update physics, etc. Returns false if we ! /// should break out of the main loop. Applications should not override ! /// this; instead, they should override 'appFrameStarted'. ! virtual bool frameStarted(const FrameEvent& evt) ! { ! if(ExampleApplication::mWindow->isClosed()) { ! return false; ! } ! Ogre::Real dt = evt.timeSinceLastFrame; ! if (false == handleInput(dt)) ! { ! return false; ! } ! // Simulate physics. ! mSimulator->simulate(dt); ! // Notify the application about the new frame. ! appFrameStarted((opal::real)dt); ! return true; ! } ! /// Returns false if we should break out of the main loop. ! bool handleInput(Ogre::Real dt) ! { ! // This variable can be used to keep keys from repeating too fast. ! if (mTimeUntilNextToggle >= 0) { ! mTimeUntilNextToggle -= dt; } ! // Acquire data from input devices. ! mInputDevice->capture(); ! // Handle keyboard input. ! if (processUnbufferedKeyInput(dt) == false) { ! return false; } ! // Handle mouse input. ! if (processUnbufferedMouseInput(dt) == false) { ! return false; } ! return true; ! } ! /// Process keyboard input here. Returns false if we should break out ! /// of the main loop. ! virtual bool processUnbufferedKeyInput(Ogre::Real dt) = 0; ! /// Process mouse input here. Returns false if we should break out of ! /// the main loop. ! virtual bool processUnbufferedMouseInput(Ogre::Real dt) = 0; ! /// Pointer to the OPAL Simulator. ! opal::Simulator* mSimulator; ! private: ! }; #endif --- 1,246 ---- ! #ifndef OPAL_SAMPLES_BASE_OPAL_APP_H ! #define OPAL_SAMPLES_BASE_OPAL_APP_H #include "ExampleApplication.h" #include "ExampleFrameListener.h" + #include "PhysicalEntity.h" #include <opal/opal.h> ! namespace opalSamples { ! class BaseOpalApp : public ExampleApplication, public ExampleFrameListener { ! public: ! BaseOpalApp() ! : ExampleApplication(), ExampleFrameListener() ! { ! mSimulator = opal::createSimulator(); ! mSimulator->setGravity(opal::Vec3r(0, (opal::real)-9.81, 0)); ! mPaused = false; ! } ! ~BaseOpalApp() ! { ! mSimulator->destroy(); ! mPhysicalEntityList.clear(); ! mPhysicalEntityMap.clear(); ! } ! protected: ! /// Register the frame listener with the Ogre root so it will ! /// call the listener at the appropriate time. ! virtual void createFrameListener() ! { ! ExampleFrameListener::init(ExampleApplication::mWindow, ! ExampleApplication::mCamera); ! mRoot->addFrameListener(this); ! } ! /// Initial scene setup function. Create and position lights, load ! /// models, create a camera, etc. ! virtual void createScene() = 0; ! /// Called once per frame after input and physics have been updated. ! /// This is a place for applications to do application-specific ! /// updates per frame. It takes the dt since the last frame as a ! /// parameter. This should return false if we should break out of ! /// the main loop. ! virtual bool appFrameStarted(opal::real dt) = 0; ! /// Called at the start of each frame. Calculate dt since the last ! /// frame, update input, update physics, etc. Returns false if we ! /// should break out of the main loop. Applications should not ! /// override this; instead, they should override 'appFrameStarted'. ! virtual bool frameStarted(const FrameEvent& evt) { ! if(ExampleApplication::mWindow->isClosed()) ! { ! return false; ! } ! Ogre::Real dt = evt.timeSinceLastFrame; ! if (false == handleInput(dt)) ! { ! return false; ! } ! if (!mPaused) ! { ! // Simulate physics. ! mSimulator->simulate(dt); ! } ! // Update the PhysicalEntities. ! size_t size = mPhysicalEntityList.size(); ! for(size_t i = 0; i<size; ++i) ! { ! mPhysicalEntityList.at(i)->update(dt); ! } ! // Notify the application about the new frame. ! appFrameStarted((opal::real)dt); ! return true; ! } ! ! /// Creates and returns a pointer to a PhysicalEntity. Takes ! /// the name of the new PhysicalEntity, the Ogre Entity, and a ! /// pointer to an OPAL Solid. ! PhysicalEntity* createPhysicalEntity(const std::string& name, ! Ogre::Entity* e, opal::Solid* s) { ! if (!s) ! { ! return NULL; ! } ! ! // Create an Ogre SceneNode. ! Ogre::SceneNode* sn = mSceneMgr->getRootSceneNode()-> ! createChildSceneNode(name); ! ! // Attach the Entity to the SceneNode. ! sn->attachObject(e); ! ! // Create a new Physical Entity. ! PhysicalEntity* pe = new PhysicalEntity(name, sn, s); ! ! // Store the pointer in the PhysicalEntity list. ! mPhysicalEntityList.push_back(pe); ! ! // If the name is not empty, also store the pointer in the ! // map of named PhysicalEntities. ! if (!name.empty()) ! { ! mPhysicalEntityMap[name] = pe; ! } ! ! return pe; } ! /// Finds a PhysicalEntity pointer by name. Returns NULL if the ! /// PhysicalEntity could not be found. ! PhysicalEntity* getPhysicalEntity(const std::string& name)const ! { ! std::map<std::string, PhysicalEntity*>::const_iterator iter = ! mPhysicalEntityMap.find(name); ! if (mPhysicalEntityMap.end() == iter) ! { ! // The named PhysicalEntity could not be found in the map. ! return NULL; ! } ! else ! { ! return (*iter).second; ! } ! } ! ! /// Destroys the given PhysicalEntity. ! void destroyPhysicalEntity(PhysicalEntity* pe) { ! if (!pe) ! { ! return; ! } ! ! // If the PhysicalEntity has a name, remove it from the ! // PhysicalEntity map. ! std::string name = pe->getName(); ! if (!name.empty()) ! { ! mPhysicalEntityMap.erase(name); ! } ! ! // Now remove the Solid. ! for(size_t i = 0; i<mPhysicalEntityList.size(); ++i) ! { ! if(mPhysicalEntityList[i] == pe) ! { ! // Destroy the PhysicalEntity's OPAL Solid. ! mSimulator->destroySolid(pe->getSolid()); ! ! // Destroy the PhysicalEntity's Ogre SceneNode. ! Ogre::SceneNode* sn = pe->getSceneNode(); ! ! // Detach and destroy all objects from the SceneNode. ! while(sn->numAttachedObjects() > 0) ! { ! MovableObject* thisObject = ! sn->detachObject(static_cast<unsigned short>(0)); ! delete thisObject; ! } ! ! // Destroy the SceneNodes all of its children. ! sn->removeAndDestroyAllChildren(); ! mSceneMgr->getRootSceneNode()->removeAndDestroyChild( ! sn->getName()); ! ! // Delete the PhysicalEntity. ! delete pe; ! ! // Copy the last element over this one and pop the last ! // one off, removing it from the PhysicalEntity list. ! mPhysicalEntityList[i] = mPhysicalEntityList.back(); ! mPhysicalEntityList.pop_back(); ! ! // Return early since we've already found the desired ! // element. ! return; ! } ! } } ! /// Returns false if we should break out of the main loop. ! bool handleInput(Ogre::Real dt) { ! // This variable can be used to keep keys from repeating too fast. ! if (mTimeUntilNextToggle >= 0) ! { ! mTimeUntilNextToggle -= dt; ! } ! ! // Acquire data from input devices. ! mInputDevice->capture(); ! ! // Handle keyboard input. ! if (processUnbufferedKeyInput(dt) == false) ! { ! return false; ! } ! ! // Handle mouse input. ! if (processUnbufferedMouseInput(dt) == false) ! { ! return false; ! } ! ! return true; } ! /// Process keyboard input here. Returns false if we should break out ! /// of the main loop. ! virtual bool processUnbufferedKeyInput(Ogre::Real dt) = 0; ! /// Process mouse input here. Returns false if we should break out of ! /// the main loop. ! virtual bool processUnbufferedMouseInput(Ogre::Real dt) = 0; ! /// Pointer to the OPAL Simulator. ! opal::Simulator* mSimulator; ! /// True when the physics simulation is paused. ! bool mPaused; ! /// Map of named PhysicalEntities. This is just used to find a ! /// PhysicalEntity by name. ! std::vector<PhysicalEntity*> mPhysicalEntityList; ! ! /// Map of named PhysicalEntities. ! std::map<std::string, PhysicalEntity*> mPhysicalEntityMap; ! ! private: ! }; ! } #endif |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:30
|
Update of /cvsroot/opal/opal/samples/data/textures In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/samples/data/textures Added Files: gray_bk.jpg gray_dn.jpg gray_fr.jpg gray_lf.jpg gray_rt.jpg gray_up.jpg Log Message: added some helper functions to Simulator; added data for ogre sample apps --- NEW FILE: gray_bk.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: gray_up.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: gray_lf.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: gray_fr.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: gray_rt.jpg --- (This appears to be a binary file; contents omitted.) --- NEW FILE: gray_dn.jpg --- (This appears to be a binary file; contents omitted.) |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:30
|
Update of /cvsroot/opal/opal/src/ODE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/src/ODE Modified Files: ODESolid.cpp Log Message: added some helper functions to Simulator; added data for ogre sample apps Index: ODESolid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ODE/ODESolid.cpp,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** ODESolid.cpp 23 Mar 2005 07:54:34 -0000 1.78 --- ODESolid.cpp 31 Mar 2005 08:47:02 -0000 1.79 *************** *** 117,121 **** // Add the new Shapes. ! for (int i=0; i<data.getNumShapes(); ++i) { addShape(*(data.getShapeData(i))); --- 117,121 ---- // Add the new Shapes. ! for (unsigned int i=0; i<data.getNumShapes(); ++i) { addShape(*(data.getShapeData(i))); *************** *** 537,544 **** // The "direction" parameter orients the mass along one of the ! // body's local axes; x=1, y=2, z=3. TODO: This might be weird ! // if this capsule is not oriented along one of the body's axes. ! // Maybe have a default value in the Simulator that the user can ! // change. dMassSetCappedCylinder(&newMass, (dReal)data.material.density, 3, (dReal)capsuleData.radius, (dReal)capsuleData.length); --- 537,543 ---- // The "direction" parameter orients the mass along one of the ! // body's local axes; x=1, y=2, z=3. This axis MUST ! // correspond with the axis along which the capsule is ! // initially aligned, which is the capsule's local Z axis. dMassSetCappedCylinder(&newMass, (dReal)data.material.density, 3, (dReal)capsuleData.radius, (dReal)capsuleData.length); |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:30
|
Update of /cvsroot/opal/opal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811 Modified Files: todo.txt Log Message: added some helper functions to Simulator; added data for ogre sample apps Index: todo.txt =================================================================== RCS file: /cvsroot/opal/opal/todo.txt,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** todo.txt 30 Mar 2005 23:26:21 -0000 1.64 --- todo.txt 31 Mar 2005 08:47:20 -0000 1.65 *************** *** 20,23 **** --- 20,24 ---- - clean up old ones OR make new ones - add license to all source files + - add instructions for making your own opal-ogre app * build (and distribute) with ode dll? *************** *** 25,28 **** --- 26,31 ---- * comment math functions + * rename 'vc7' to 'vc71' + * finish web todo for 0.3.0 |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:29
|
Update of /cvsroot/opal/opal/samples/data/models In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/samples/data/models Added Files: cube.mesh Log Message: added some helper functions to Simulator; added data for ogre sample apps --- NEW FILE: cube.mesh --- (This appears to be a binary file; contents omitted.) |
|
From: tylerstreeter <tyl...@us...> - 2005-03-31 08:47:29
|
Update of /cvsroot/opal/opal/samples/data/materials In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17811/samples/data/materials Added Files: basic.material skyboxes.material Log Message: added some helper functions to Simulator; added data for ogre sample apps --- NEW FILE: basic.material --- material Plastic/Red { receive_shadows on technique { pass { ambient 0.000000 0.000000 0.000000 diffuse 0.9 0.0 0.0 specular 0.500000 0.500000 0.500000 50.000000 emissive 0.000000 0.000000 0.000000 } } } --- NEW FILE: skyboxes.material --- material FlatGray { technique { pass { lighting off depth_write off texture_unit { cubic_texture gray_fr.jpg gray_bk.jpg gray_lf.jpg gray_rt.jpg gray_up.jpg gray_dn.jpg separateUV tex_address_mode clamp } } } } |