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