[Opal-commits] opal/samples/src BaseOpalApp.h,1.4,1.5 ExampleApplication.h,1.3,1.4 PhysicalCamera.h,
Status: Inactive
Brought to you by:
tylerstreeter
|
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) |