btoCylinder::btoCylinder(btoWorld *world, BulletOgreEngine *btoEngine, btScalar radius, btScalar height, const btTransform &transform, const btScalar density) : btCylinder(world, radius, height, transform, density) { this->btoEngine = btoEngine; // New entity btoCylinder::mNumEntitiesInstanced++; // Create Ogre Entity entity = btoEngine->getOgreEngine()->getOgreSceneManager()->createEntity( "CylinderEntity_" + StringConverter::toString(btoCylinder::mNumEntitiesInstanced), "Barrel.mesh"); // Material entity->setMaterialName("GeneCraft/RockWall"); entity->setCastShadows(true); // Attach node = btoEngine->getOgreEngine()->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode(); // Scale AxisAlignedBox boundingB = entity->getBoundingBox(); // we need the bounding box of the box to be able to set the size of the Bullet-box Vector3 sizeBB = boundingB.getSize(); sizeBB /= 2.0f; // only the half needed sizeBB *= 0.95f; // Bullet margin is a bit bigger so we need a smaller size (Bullet 2.76 Physics SDK Manual page 18) Vector3 ogreSize(radius*2,height,radius*2); Vector3 scale = ogreSize / boundingB.getSize(); node->scale(scale); // the cube is too big for us sizeBB *= scale; // don't forget to scale down the Bullet-box too }
void btoCylinder::setSize(btScalar radius, btScalar height) { btoCylinder::setSize(radius,height); // Scale AxisAlignedBox boundingB = entity->getBoundingBox(); // we need the bounding box of the box to be able to set the size of the Bullet-box Vector3 sizeBB = boundingB.getSize(); sizeBB /= 2.0f; // only the half needed sizeBB *= 0.95f; // Bullet margin is a bit bigger so we need a smaller size (Bullet 2.76 Physics SDK Manual page 18) Vector3 ogreSize(radius*2,height,radius*2); Vector3 scale = ogreSize / boundingB.getSize(); node->scale(scale); // the cube is too big for us }
void RenderBoxScene::updateViewport() { if (mCanvas->getWidth() <= 1 || mCanvas->getHeight() <= 1) return; if (mEntity != nullptr && mCamera != nullptr) { mCamera->setAspectRatio((float)mCanvas->getWidth() / (float)mCanvas->getHeight()); AxisAlignedBox box; const Vector3& dpos = mEntity->getParentSceneNode()->_getDerivedPosition(); box.merge(mEntity->getBoundingBox().getMinimum() + dpos); box.merge(mEntity->getBoundingBox().getMaximum() + dpos); if (box.isNull()) return; Vector3 vec = box.getSize(); float width = sqrt(vec.x * vec.x + vec.z * vec.z), height = vec.y; float len2 = width / mCamera->getAspectRatio(), len1 = height; if (len1 < len2) len1 = len2; len1 /= 0.86; // [sqrt(3)/2] for 60 degrees field of view Vector3 pos = box.getCenter(); pos.z += vec.z / 2 + len1 + 1/* min dist*/; pos += Vector3(0, height * 0.9f/* pitch*/, len1 * 0.1f); pos *= 0.85f; //* closer Vector3 look = Vector3(0, box.getCenter().y * 0.8f, 0); mCameraNode->setPosition(pos); mCameraNode->lookAt(look, Node::TS_WORLD); } }
//------------------------------------------------------------------------------------- bool OBTutorial2::processUnbufferedInput(const Ogre::FrameEvent& evt) { static float mToggle = 0; if (mToggle>0) mToggle -= evt.timeSinceLastFrame; // create and throw a box if 'B' is pressed if(mKeyboard->isKeyDown(OIS::KC_B) && mToggle <=0) { Vector3 size = Vector3::ZERO; // size of the box // starting position of the box Vector3 position = (mCamera->getDerivedPosition() + mCamera->getDerivedDirection().normalisedCopy() * 10); // create an ordinary, Ogre mesh with texture Entity *entity = mSceneMgr->createEntity( "Box" + StringConverter::toString(mNumEntitiesInstanced), "cube.mesh"); entity->setCastShadows(true); createBoxShape(entity, position, false); // we need the bounding box of the box to be able to set the size of the Bullet-box AxisAlignedBox boundingB = entity->getBoundingBox(); size = boundingB.getSize(); size /= 2.0f; // only the half needed size *= 1.00f; // Bullet margin is a bit bigger so we need a smaller size // (Bullet 2.76 Physics SDK Manual page 18) entity->setMaterialName("Examples/BumpyMetal"); SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); node->attachObject(entity); node->scale(0.05f, 0.05f, 0.05f); // the cube is too big for us size *= 0.05f; // don't forget to scale down the Bullet-box too // after that create the Bullet shape with the calculated size /*OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size); // and the Bullet rigid body OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody( "defaultBoxRigid" + StringConverter::toString(mNumEntitiesInstanced), mWorld); defaultBody->setShape( node, sceneBoxShape, 0.6f, // dynamic body restitution 0.6f, // dynamic body friction 1.0f, // dynamic bodymass position, // starting position of the box Quaternion(0,0,0,1));// orientation of the box mNumEntitiesInstanced++; defaultBody->setLinearVelocity( mCamera->getDerivedDirection().normalisedCopy() * Ogre::Math::RangeRandom(0.7f,20.0f) ); // shooting speed // push the created objects to the dequese mShapes.push_back(sceneBoxShape); mBodies.push_back(defaultBody); **/ mToggle = 0.5; } return true; }
void SurveyMapManager::init() { AxisAlignedBox aab = App::GetSimTerrain()->getTerrainCollisionAAB(); Vector3 terrain_size = App::GetSimTerrain()->getMaxTerrainSize(); bool use_aab = App::GetSimTerrain()->isFlat() && std::min(aab.getSize().x, aab.getSize().z) > 50.0f; if (terrain_size.isZeroLength() || use_aab && (aab.getSize().length() < terrain_size.length())) { terrain_size = aab.getSize(); terrain_size.y = aab.getMaximum().y; Vector3 offset = aab.getCenter() - terrain_size / 2; mMapCenterOffset = Vector2(offset.x, offset.z); } mTerrainSize = Vector2(terrain_size.x, terrain_size.z); mPlayerPosition = mTerrainSize / 2; mMapCenter = mTerrainSize / 2; mMapSize = mTerrainSize; ConfigOptionMap ropts = App::GetOgreSubsystem()->GetOgreRoot()->getRenderSystem()->getConfigOptions(); int resolution = StringConverter::parseInt(StringUtil::split(ropts["Video Mode"].currentValue, " x ")[0], 1024); int fsaa = StringConverter::parseInt(ropts["FSAA"].currentValue, 0); int res = std::pow(2, std::floor(std::log2(resolution))); mMapTextureCreatorStatic = std::unique_ptr<SurveyMapTextureCreator>(new SurveyMapTextureCreator(terrain_size.y)); mMapTextureCreatorStatic->init(res, fsaa); mMapTextureCreatorStatic->update(mMapCenter + mMapCenterOffset, mMapSize); // TODO: Find out how to zoom into the static texture instead mMapTextureCreatorDynamic = std::unique_ptr<SurveyMapTextureCreator>(new SurveyMapTextureCreator(terrain_size.y)); mMapTextureCreatorDynamic->init(res / 4, fsaa); mMapTextureCreatorDynamic->update(mMapCenter + mMapCenterOffset, mMapSize); mMapTexture->eventMouseSetFocus += MyGUI::newDelegate(this, &SurveyMapManager::setFocus); mMapTexture->eventMouseLostFocus += MyGUI::newDelegate(this, &SurveyMapManager::lostFocus); mMapTexture->eventMouseMove += MyGUI::newDelegate(this, &SurveyMapManager::mouseMove); mMapTexture->eventMouseButtonPressed += MyGUI::newDelegate(this, &SurveyMapManager::mousePressed); mCursorEntity = createMapEntity("other"); mCursorEntity->setVisibility(false); mCursorEntity->setCaption(_L("Teleport")); }
/** Returns true is the box will fit in a child. */ bool Octree::_isTwiceSize( const AxisAlignedBox &box ) const { // infinite boxes never fit in a child - always root node if (box.isInfinite()) return false; Vector3 halfMBoxSize = mBox.getHalfSize(); Vector3 boxSize = box.getSize(); return ((boxSize.x <= halfMBoxSize.x) && (boxSize.y <= halfMBoxSize.y) && (boxSize.z <= halfMBoxSize.z)); }
Extrusion::Extrusion(Vector3 pos, Vector3 size, Vector3 axis, float extrusionTravel, hkpWorld * world, SceneManager * sceneMgr): mWorld(world), mSceneMgr(sceneMgr) { hkVector4 halfSize(size.x * 0.5f, size.y * 0.5, size.z * 0.5); hkpBoxShape * shape = new hkpBoxShape(halfSize, 0); hkpRigidBodyCinfo info; info.m_shape = shape; info.m_mass = 800.0f; hkpInertiaTensorComputer::setShapeVolumeMassProperties(shape, info.m_mass, info); info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; info.m_position.set(pos.x, pos.y, pos.z); mBody = new hkpRigidBody(info); mWorld->addEntity(mBody); shape->removeReference(); hkpRigidBodyCinfo anchorInfo; anchorInfo.m_motionType = hkpMotion::MOTION_FIXED; anchorInfo.m_position = hkVector4(pos.x + (20.0f * axis.x), pos.y, pos.z + (20.0f * axis.z)); anchorInfo.m_shape = new hkpSphereShape(0.1f); hkpRigidBody * anchor = new hkpRigidBody(anchorInfo); mWorld->addEntity(anchor); // Setup prismatic constraint hkVector4 a(axis.x, axis.y, axis.z); hkpPrismaticConstraintData * prismatic = new hkpPrismaticConstraintData(); prismatic->setMaxLinearLimit(extrusionTravel); prismatic->setMinLinearLimit(0.0f); prismatic->setInWorldSpace(mBody->getTransform(), anchor->getTransform(), hkVector4(pos.x, pos.y, pos.z), a); hkpConstraintInstance * prismaticConstraint = new hkpConstraintInstance(mBody, anchor, prismatic); mWorld->addConstraint(prismaticConstraint); prismaticConstraint->removeReference(); prismatic->removeReference(); // Ogre char entityName[] = "000ExtrusionEntity"; entityName[0] += numExtrusions; mMesh = mSceneMgr->createEntity(entityName, "cube.mesh"); AxisAlignedBox aab = mMesh->getBoundingBox(); mMesh->setMaterialName("Examples/CubeDefault"); Vector3 meshSize = aab.getSize(); Vector3 scaling = size / meshSize; char nodeName[] = "000ExtrusionNode"; nodeName[0] += numExtrusions; mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(nodeName); mNode->setPosition(pos.x, pos.y, pos.z); mNode->setScale(scaling); mNode->attachObject(mMesh); numExtrusions++; }
/** Returns true is the box will fit in a child. */ bool PagingLandScapeOctree::_isTwiceCullSize(const AxisAlignedBox &box) const { // infinite boxes never fit in a child - always root node if (box.isInfinite()) return false; const Vector3 &boxSize = box.getSize(); return(boxSize.x <= mCullHalfSize.x) && (boxSize.y <= mCullHalfSize.y) && (boxSize.z <= mCullHalfSize.z) ; }
Actor::Actor(const Ogre::String& name) { _strName = name; _AnimSpeed = 1.0; _pCurAnim = 0; _bPaused = false; _bShowAxes = false; _bShowBone = false; _bShowBoundingBox = false; _axesBoneTagPoint = 0; //the body _pBodyEntity = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(_strName, _strName); _pBodySceneNode = OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode(_strName); _pBodySceneNode->attachObject(_pBodyEntity); //the body axes String axesName = _strName + "_" + "axes"; _axesEntity = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(axesName, "axes.mesh"); SceneNode* pAxesNode = _pBodySceneNode->createChildSceneNode(axesName); pAxesNode->attachObject(_axesEntity); _axesEntity->setVisible(_bShowAxes); //the bone axes axesName = _strName + "_Bone_" + "axes"; _axesBoneEntity = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(axesName, "axes.mesh"); AxisAlignedBox aabb = _pBodyEntity->getBoundingBox(); _vInitCenter = aabb.getCenter(); _fVolumeSize = aabb.getSize().length(); _scaleAxes = _fVolumeSize * 0.01; //for Axes mesh size is about 13, i want the axes to be 1/10 of the mesh pAxesNode->setScale(_scaleAxes, _scaleAxes, _scaleAxes); AddBoneVisualizer(); OgreFramework::getSingletonPtr()->AddActor(this); }
//Constructor EnvironmentObject::EnvironmentObject(PGFrameListener* frameListener, OgreBulletDynamics::DynamicsWorld *mWorld, int mNumEntitiesInstanced, SceneManager* mSceneMgr, std::string object[24]) { //Initialise variables mName = object[0]; mMesh = object[1]; mPosition = Vector3(atof(object[2].c_str()), atof(object[3].c_str()), atof(object[4].c_str())); mOrientation = Quaternion(atof(object[5].c_str()), atof(object[6].c_str()), atof(object[7].c_str()), atof(object[8].c_str())); mScale = Vector3(atof(object[9].c_str()), atof(object[10].c_str()), atof(object[11].c_str())); mRestitution = atof(object[12].c_str()); mFriction = atof(object[13].c_str()); mMass = atof(object[14].c_str()); mAnimated = atoi(object[15].c_str()); mXMovement = atof(object[16].c_str()); mYMovement = atof(object[17].c_str()); mZMovement = atof(object[18].c_str()); mSpeed = atof(object[19].c_str());; mRotationX = atof(object[20].c_str()); mRotationY = atof(object[21].c_str()); mRotationZ = atof(object[22].c_str()); mBillBoard = atoi(object[23].c_str()); //Initially targets haven't been hit counted = false; //Generate new Ogre entity Entity* entity = mSceneMgr->createEntity(mName + StringConverter::toString(mNumEntitiesInstanced), mMesh); //Create bounding box for entity AxisAlignedBox boundingB = entity->getBoundingBox(); Vector3 size = boundingB.getSize() * mScale; size /= 2.0f; size *= 0.97f; //Attach entity to a scene node so it can be displayed in the environment SceneNode* objectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); objectNode->attachObject(entity); objectNode->setScale(mScale); //Generate a new rigidbody for the object mBody = new OgreBulletDynamics::RigidBody(mName + StringConverter::toString(mNumEntitiesInstanced), mWorld); //Different objects require different collision shapes if(mName == "Target") { OgreBulletCollisions::CylinderCollisionShape* ccs = new OgreBulletCollisions::CylinderCollisionShape(size, Ogre::Vector3(0,0,1)); mBody->setShape(objectNode, ccs, mRestitution, mFriction, mMass, mPosition, mOrientation); mBody->setDebugDisplayEnabled(true); mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); } else if(mName == "Palm") { OgreBulletCollisions::StaticMeshToShapeConverter* acs = new OgreBulletCollisions::StaticMeshToShapeConverter(entity); OgreBulletCollisions::TriangleMeshCollisionShape* ccs = acs->createTrimesh(); OgreBulletCollisions::CollisionShape* finalCollisionShape = (OgreBulletCollisions::CollisionShape*) ccs; Ogre::Vector3 scale = objectNode->getScale(); btVector3 scale2(scale.x, scale.y, scale.z); finalCollisionShape->getBulletShape()->setLocalScaling(scale2); mBody->setShape(objectNode, (OgreBulletCollisions::CollisionShape*) ccs, mRestitution, mFriction, mMass, mPosition, mOrientation); mBody->getBulletRigidBody()->setFriction(0.5f); palmAnimation = entity->getAnimationState("my_animation"); } else if(mName == "GoldCoconut") { float biggestSize = 0; if (size.x > biggestSize) biggestSize = size.x; if (size.y > biggestSize) biggestSize = size.y; if (size.z > biggestSize) biggestSize = size.z; entity->setMaterialName("GoldCoconut"); OgreBulletCollisions::CollisionShape *sceneSphereShape = new OgreBulletCollisions::SphereCollisionShape(biggestSize); mBody->setShape(objectNode, sceneSphereShape, mRestitution, mFriction, mMass, mPosition, mOrientation); mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); } else { if (mName=="Orange" ||mName=="Blue" || mName=="Red" || mName=="Block") { mMass=50; } if (mName == "Orange") entity->setMaterialName("Orange"); else if (mName == "Blue") entity->setMaterialName("Blue"); else if (mName == "Red") entity->setMaterialName("Red"); OgreBulletCollisions::BoxCollisionShape* sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size); mBody->setShape(objectNode, sceneBoxShape, mRestitution, mFriction, mMass, mPosition, mOrientation); mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); } mBody->setCastShadows(true); //Add a billboard for scores if necessary if(mBillBoard != 0) { mText = new MovableText("targetText" + StringConverter::toString(mNumEntitiesInstanced), "100", "000_@KaiTi_33", 17.0f); mText->setTextAlignment(MovableText::H_CENTER, MovableText::V_ABOVE); // Center horizontally and display above the node //Create scene node for bill board and attach text to it mBillNode = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild()); mBillNode->attachObject(mText); mBillNode->setPosition(mPosition.x, mPosition.y + 50, mPosition.z); mBillNode->setVisible(false); //Set animation to off initially mTextAnim = 0; mTextBool = false; mTextPos = mBody->getCenterOfMassPosition(); } else { mText = NULL; mBillNode = NULL; mTextAnim = NULL; mTextBool = NULL; mTextPos = NULL; } }