[Opal-commits] opal/samples/playpen main.cpp,1.1,1.2
Status: Inactive
Brought to you by:
tylerstreeter
|
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; } |