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