Exemple #1
0
void DrivingSimulatorV1::createScene1() // city
{
	// create world node
	Ogre::SceneNode* worldNode = sceneManager->getRootSceneNode()->createChildSceneNode();
	Ogre::Entity* cityWorld = sceneManager->createEntity("CityWorld.mesh");
	worldNode->scale(0.05, 0.05, 0.05);
	worldNode->attachObject(cityWorld);

	// create ETH Node
	Ogre::SceneNode* ethNode = sceneManager->getRootSceneNode()->createChildSceneNode();
	Ogre::Entity* eth = sceneManager->createEntity("ETH.mesh");
	ethNode->attachObject(eth);
	ethNode->scale(1.3, 1.3, 1.3);
	ethNode->setPosition(428, 0, 235);
	ethNode->yaw(Ogre::Degree(210));

	// create ambient light
	sceneManager->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7));

	// create sun light
	Ogre::Light* sunLight = sceneManager->createLight();
	sunLight->setType(Ogre::Light::LT_DIRECTIONAL);
	sunLight->setDirection(Ogre::Vector3(-0.5, -0.5, 0.5));
	sunLight->setDiffuseColour(Ogre::ColourValue(1, 1, 1));
	sunLight->setSpecularColour(Ogre::ColourValue(0.7, 0.7, 0.7));

	// set car to initial position and orientation
	carNode->setPosition(584, 0, 121);
	carNode->setOrientation(Ogre::Quaternion(Ogre::Degree(-4.5), Ogre::Vector3::UNIT_Y));
}
void ProjectileManager::createProjectile(const Ogre::Vector3& tankPosition, const Ogre::Quaternion& turretOrientation, 
										 const Ogre::Degree& angle, const float& velocity, const float& dmg){
	
	std::ostringstream oss;
	oss << "Projectile" << time(0) << projectiles.size() << counter++;										 
											 
	Ogre::ParticleSystem* particleSystem = mSceneMgr->createParticleSystem(oss.str(), "Examples/PurpleFountain");

	scaleBy(1.f, particleSystem);

	Ogre::SceneNode* parentParticleSn = mSceneMgr->getRootSceneNode()->createChildSceneNode();

	Ogre::SceneNode* particleSn = parentParticleSn->createChildSceneNode();

	Ogre::Vector3 start(-115.f, 10.f, 0.f);

	parentParticleSn->setPosition(tankPosition);
	particleSn->setPosition(start);

	parentParticleSn->yaw(turretOrientation.getYaw());

	particleSn->attachObject(particleSystem);

	particleSn->roll(Ogre::Degree(-90.f));

	particleSn->scale(Ogre::Vector3(0.1f));

	projectiles.insert(new Projectile(start, particleSn, angle, velocity, dmg));
}
Exemple #3
0
void createBox(std::string name, dReal x, dReal y, dReal z) {
  Ogre::Entity* e;
  e=sceneMgr_->createEntity(name.c_str(), "cube.mesh");
  Ogre::SceneNode* n;
  n=sceneMgr_->getRootSceneNode()->createChildSceneNode(name.c_str());

  n->attachObject(e); 
  n->scale(0.02, 0.02, 0.02);
  e->setMaterialName("Car/Subframe");

  dBodyID b;
  dGeomID g;
  dMass m;

  static dContact contact=boxContact();

  g = World::getSingletonPtr()->addBox(2.0, 2.0, 2.0);
  dMassSetBox (&m, 1 ,2.0, 2.0, 2.0);

  b=World::getSingletonPtr()->add(g,&m);
  
  dGeomSetData(g,(void*)&contact);

  names.push_back(name);//for updating
  geoms.push_back(g);
  dBodySetPosition (b, x, y, z);
  MyTools::byOdeToOgre(b, n);
}
Shuriken::Shuriken(Ogre::SceneManager* mSceneMgr, Ogre::SceneNode* parentNode, PhysicsEngine* bulletEngine, const Ogre::Vector3& pos, bool isTennis) :  
	graphicsEngine(mSceneMgr),
	positionNode(0),
	active(true),
	physicsEngine(bulletEngine),
	colliding(false),
	shooting(false)
{
	Ogre::Real ratio = SIZE_REGULAR_SHURIKEN;
	
	if(isTennis){
		entShuriken = mSceneMgr->createEntity(Ogre::SceneManager::PT_SPHERE);
		entShuriken->setMaterialName("Examples/TennisBall");
		ratio = ratio/100;
	} else
		entShuriken = mSceneMgr->createEntity("Shuriken.mesh");
	entShuriken->setCastShadows(true);

	positionNode = parentNode->createChildSceneNode(pos);
	Ogre::SceneNode* tempNode = positionNode->createChildSceneNode();
	tempNode->attachObject(entShuriken);
	tempNode->scale(ratio, ratio, ratio);
	
	physicsObject.setToSphere(
		SIZE_REGULAR_SHURIKEN, 
		2, 
		btQuaternion(0.2f, 0.6f, 0.1f, 1.0f).normalized(),
		btVector3(pos.x,pos.y,pos.z) 
	);
	physicsObject.setRestitution(0.99);
	physicsObject.setLinearVelocity(btVector3(0,0,0));
	physicsObject.setFriction(0.5);  
	physicsObject.setAngularVelocity(btVector3(0.2f, 0.5f, 0.2f));
	physicsEngine->addObject(&physicsObject);
}
Exemple #5
0
void createBall(std::string name, dReal x, dReal y, dReal z) {
  Ogre::Entity* e;
  e=sceneMgr_->createEntity(name.c_str(), "sphere.mesh");
  Ogre::SceneNode* n;
  n=sceneMgr_->getRootSceneNode()->createChildSceneNode(name.c_str());

  n->attachObject(e); 
  n->scale(0.03, 0.03, 0.03);
  e->setMaterialName("MyOwn/Sphere");

  dBodyID b;
  dGeomID g;
  dMass m;

  static dContact contact=ballContact();

  g = World::getSingletonPtr()->addSphere(3.0);
  dMassSetSphere (&m,1,3.0);

  b=World::getSingletonPtr()->add(g,&m);
  
  dGeomSetData(g,(void*)&contact);

  names.push_back(name);
  geoms.push_back(g);
  dBodySetPosition (b, x, y, z);
  MyTools::byOdeToOgre(b, n);
}
GameEntity* SphereFactory::make(const rapidjson::Value& jsonobj, SpaceObject*spaceobj){

  // Create the sphere
  Ogre::Entity* entity = game_manager->GetSceneManager()->createEntity(jsonobj["name"].GetString(), Ogre::SceneManager::PT_SPHERE);
  entity->setMaterialName(jsonobj["material"].GetString());

  // Create a SceneNode and attach the Entity to it
  Ogre::SceneNode *node = game_manager->GetSceneManager()->getRootSceneNode()->createChildSceneNode(jsonobj["name"].GetString());
  node->attachObject(entity);

  // Set the node's position
  Eigen::Vector3f positionVec=spaceobj->position.cast<float>();
  node->setPosition(Ogre::Vector3( static_cast<Ogre::Real*>(positionVec.data()) ));

  // Set the node's orientation
  Eigen::Vector4f attitudeVec=spaceobj->attitude.coeffs().cast<float>();
  node->setOrientation(Ogre::Quaternion(static_cast<Ogre::Real*>(attitudeVec.data()) ));

  // Scale the sphere
  node->scale( jsonobj["scale"][0u].GetDouble(), jsonobj["scale"][1u].GetDouble(),jsonobj["scale"][2u].GetDouble() );

  GameEntity*game_entity=new GameEntity(spaceobj,entity,node);
  this->game_manager->add_allocated_object(game_entity);

  return game_entity;
}
void TestGame::DrawNewCore(Logic::CoreBuiltEvnt *evnt){

	Ogre::Entity* drop= mSceneMgr->createEntity("Mesh"+evnt->building->mSysName, "BaseDropNew.mesh");
	drop->setCastShadows(true);
	const Ogre::AxisAlignedBox test =drop->getBoundingBox();
	Control::ClickHelper* helpr = 	new Control::ClickHelper(Logic::CHT_BUILDING);
	helpr->target = evnt->building;
	drop->setUserAny(Ogre::Any(helpr));
	Ogre::SceneNode *coreNode = evnt->country->mNode->createChildSceneNode();
	Ogre::Vector3 tempvect = calculateActualPointFromCenter(evnt->country->mCapital.mPosition,evnt->tile->mPosition);
	tempvect= tempvect*TILESIZE;
	coreNode->attachObject(drop);
	coreNode->translate(tempvect);
	coreNode->pitch(Ogre::Degree(90));
	coreNode->scale(0.5,0.5,0.5);
	Ogre::AnimationState* temp= drop->getAnimationState("drop");
	temp->setLoop(false);
	temp->setEnabled(true);
	mAllAnimation .insert(temp);
	Ogre::Entity* basePlane= mSceneMgr->createEntity("MeshBaseFloor"+evnt->building->mSysName, "BaseCloseLook.mesh");
	basePlane->setMaterialName("BaseCloseLook/Rockwall");

	Ogre::SceneNode *BaseDraw = evnt->country->mNode->createChildSceneNode(),*camspot;
	BaseDraw->attachObject(basePlane);
	BaseDraw->translate(2000*evnt->building->mSlot,0,0);
	camspot = BaseDraw->createChildSceneNode("CamPoint_"+evnt->building->mSysName);
	camspot->setPosition(0,45,45);
	camspot->lookAt(Ogre::Vector3(0,0,0), Ogre::Node::TS_PARENT);
	helpr = 	new Control::ClickHelper(Logic::CHT_EMPTYSPACE);
	helpr->target = evnt->building;
	basePlane->setUserAny(Ogre::Any(helpr));
}
Exemple #8
0
//-------------------------------------------------------------------------------------
void DeltaControl::createScene(void) {

    mSceneMgr->setSkyBox(true, "StormySkyBox");

    mControlCenter = new ControlCenter(mSceneMgr);

    /* *********************************************************
     * ENTITIES
     * *********************************************************/

//	Telephone* phone = new Telephone(mSceneMgr, "phone1");
//	phone->init();

    // Create entity from mesh and attach it to a scene node.
    Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    Ogre::Entity* ent = mSceneMgr->createEntity("Sinbad", "Sinbad.mesh");
    node->attachObject(ent);
    node->setPosition(0,50,0);
    node->scale(10,10,10);

    // Set animation blend mode to additive / cumulative.
    ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);

    // Get the two halves of the idle animation
    Ogre::AnimationState* baseAnim = ent->getAnimationState("IdleBase");
    Ogre::AnimationState* topAnim = ent->getAnimationState("IdleTop");

    // Enable both of them and set them to loop.
    baseAnim->setLoop(true);
    topAnim->setLoop(true);
    baseAnim->setEnabled(true);
    topAnim->setEnabled(true);

}
/* ----------------------------------------------------------------------- 
 | build bullet box shape
 | 
 | : default create 125 (5x5x5) dynamic object
   ----------------------------------------------------------------------- */
bool
buildBoxShapeArray(Ogre::SceneManager* sceneMgr, btDynamicsWorld* dynamicsWorld, btAlignedObjectArray<btCollisionShape*>& collisionShapes,
                   const btVector3& array_size, btScalar scale)
{
    btTransform startTransform;
    startTransform.setIdentity();

    btScalar mass(1.f);	
    btVector3 localInertia(0,0,0);	
    btBoxShape* colShape = new btBoxShape(btVector3(scale, scale, scale));
    btAssert(colShape);    
    colShape->calculateLocalInertia(mass,localInertia);
    collisionShapes.push_back(colShape);

    float start_x = - array_size.getX()/2;
    float start_y = array_size.getY();
    float start_z = - array_size.getZ()/2;

    int index = 0;
    for (int k=0;k<array_size.getY();k++)
    {
	    for (int i=0;i<array_size.getX();i++)
	    {
            for(int j=0;j<array_size.getZ();j++)
		    {
			    startTransform.setOrigin(scale * btVector3(
								    btScalar(2.0*i + start_x),
								    btScalar(20+2.0*k + start_y),
								    btScalar(2.0*j + start_z)));

			    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
			    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
			    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
			    btRigidBody* body = new btRigidBody(rbInfo);
                body->setContactProcessingThreshold(BT_LARGE_FLOAT);

                if (sceneMgr)
                {
                    Ogre::Entity* ent = sceneMgr->createEntity("ent_" + Ogre::StringConverter::toString(index++),"Barrel.mesh");

                    Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("node_box_" + Ogre::StringConverter::toString(index++));
                    node->attachObject(ent);
                    node->setPosition(startTransform.getOrigin().getX(), startTransform.getOrigin().getY(), startTransform.getOrigin().getZ());

                    const Ogre::AxisAlignedBox& aabb = ent->getBoundingBox();
                    const Ogre::Vector3& boxScale = (aabb.getMaximum() - aabb.getMinimum())/2.0f;
                    node->scale(scale/boxScale.x, scale/boxScale.y, scale/boxScale.z);

                    body->setUserPointer((void*)node);
                }

			    dynamicsWorld->addRigidBody(body);
		    }
	    }		
    }

    return true;
}
bool 
CGrassSticks::buildGrassSticks(Ogre::SceneManager* sceneMgr, btDynamicsWorld* dynamicsWorld, btSoftBodyWorldInfo &softBodyWorldInfo)
{    
    // create our grass mesh, and create a grass entity from it
    if (!sceneMgr->hasEntity(GRASS_MESH_NAME))
    {
	    createGrassMesh();
    } // End if

    const int		n=16;
	const int		sg=4;    
	const btScalar	sz=16;
	const btScalar	hg=4;
	const btScalar	in=1/(btScalar)(n-1);
    int             index = 0;

	for(int y=0;y<n;++y)
	{
		for(int x=0;x<n;++x)
		{
			const btVector3	org(-sz+sz*2*x*in,
				1,
				-sz+sz*2*y*in);
			btSoftBody*		psb=btSoftBodyHelpers::CreateRope(softBodyWorldInfo, org,
				org+btVector3(hg*0.001f,hg,0),
				sg,
				1);
			psb->m_cfg.kDP		=	0.005f;
			psb->m_cfg.kCHR		=	0.1f;
			for(int i=0;i<3;++i)
			{
				psb->generateBendingConstraints(2+i);
			}
			psb->setMass(1,0);
			psb->setTotalMass(0.01f);
                       
            static_cast<btSoftRigidDynamicsWorld*>(dynamicsWorld)->addSoftBody(psb);
            
            const Ogre::String& strIndex = Ogre::StringConverter::toString(index++);
            Ogre::Entity* grass = sceneMgr->createEntity("Grass" + strIndex, GRASS_MESH_NAME);
            Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("node_grass_" + strIndex
                ,Ogre::Vector3(org.getX(), org.getY(), org.getZ())
                ,Ogre::Quaternion(Ogre::Degree(0), Vector3::UNIT_Y));
            node->attachObject(grass);
            node->scale(1.0f, Ogre::Math::RangeRandom(0.85f, 1.15f), 1.0f);
            node->setVisible(true);
                                    
            psb->setUserPointer((void*)(grass->getSubEntity(0)));
		} // End for
	} // End for

    dynamicsWorld->setInternalTickCallback(&CGrassSticks::simulationTickCallback);
    
    return true;
}
void TutorialApplication::crearBorde(Ogre::Vector3 posicion, Ogre::Vector3 escala)
{
	Ogre::Entity *borde = mSceneMgr->createEntity("cube.mesh");
	borde->setMaterialName("Custom/TelaBillar");
	borde->setCastShadows(false);

	Ogre::SceneNode *nodoBorde = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	nodoBorde->setPosition(posicion);
	nodoBorde->attachObject(borde);
	nodoBorde->scale(escala);
}
//--------------------------------------------------------------------------------------
void LapTrainer::createScene(void)
{
		//Create right stick
		Ogre::Entity* StickRight = mSceneMgr->createEntity("StickRight", "instrument_stick.mesh");
		StickRight -> setCastShadows(true);
		Ogre::SceneNode* RightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RightNode", Ogre::Vector3(0,0,0),Ogre::Quaternion(1,0,0,0));
		//RightNode->setPosition(Ogre::Vector3(300, 100, 100));
		RightNode->setPosition(Ogre::Vector3(300, 500, 500));//alex
		RightNode->setOrientation(0.383022, -0.383022, 0.821394, -0.178606);//alex
		RightNode->scale( 1, 1, 1); 
		Ogre::SceneNode* child = RightNode->createChildSceneNode("MoveNodeRight");
		child->attachObject(StickRight);
		child->translate(0,0,0);


		//Create left stick
		Ogre::Entity* entPenguin2 = mSceneMgr->createEntity("StickLeft", "instrument_stick.mesh");
		entPenguin2 -> setCastShadows(true);
		Ogre::SceneNode* nodPenguin2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("LeftNode", Ogre::Vector3(0,0,0),Ogre::Quaternion(1,0,0,0));
		//nodPenguin2->setPosition(Ogre::Vector3(-300, 100, 100));
		nodPenguin2->setPosition(Ogre::Vector3(-300, 500, 500));//alex
		//nodPenguin2->setOrientation(0.821394, -0.178606, 0.383022, -0.383022);//alex //this stick is not working
		nodPenguin2->setOrientation(0.821394, -0.178606, 0.383022, -0.383022);//alex //this stick is not working
		nodPenguin2->scale( 1, 1, 1); 
		Ogre::SceneNode* child2 = nodPenguin2->createChildSceneNode("MoveNodeLeft");
		child2->attachObject(entPenguin2);
		child2->translate(0,0,0);

		Ogre::Entity* Element1 = mSceneMgr->createEntity("Element1", "exercise1.mesh");//Place your mesh here
		Element1 -> setCastShadows(true);
		Ogre::SceneNode* Element1Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Element1Node", Ogre::Vector3(0, -200, 200));//X-Y-Z
		Element1Node->scale( 400, 400, 400); 
		Element1Node->attachObject(Element1);

		Ogre::Entity* Element2 = mSceneMgr->createEntity("Element2", "Sphere002.mesh");//Place your mesh here
		Element2 -> setCastShadows(true);
		//Ogre::SceneNode* Element2Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Element2Node", Ogre::Vector3(0, 50, 100));//X-Y-Z
		Ogre::SceneNode* Element2Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Element2Node", Ogre::Vector3(0,0,0),Ogre::Quaternion(1,0,0,0));
		Element2Node->setPosition(Ogre::Vector3(300, 500, 500));
		Element2Node->setOrientation(0.383022, -0.383022, 0.821394, -0.178606);
		Element2Node->scale( 60, 60, 60); 
		Element2Node->attachObject(Element2);

		Ogre::Entity* Element3 = mSceneMgr->createEntity("Element3", "Sphere002.mesh");//Place your mesh here
		Element3 -> setCastShadows(true);
		//Ogre::SceneNode* Element2Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Element2Node", Ogre::Vector3(0, 50, 100));//X-Y-Z
		Ogre::SceneNode* Element3Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Element3Node", Ogre::Vector3(0,0,0),Ogre::Quaternion(1,0,0,0));
		Element3Node->setPosition(Ogre::Vector3(-300, 500, 500));
		Element3Node->setOrientation(0.821394, -0.178606, 0.383022, -0.383022);
		Element3Node->scale( 60, 60, 60); 
		Element3Node->attachObject(Element3);


}
Exemple #13
0
void ExteriorCellRender::scaleMesh(Ogre::Vector3 axis,  std::string sceneNodeName[], int elements)
{
    assert(mInsert);
    Ogre::SceneNode *parent = mInsert;
     //std::cout << "ELEMENTS:" << elements;
    for (int i = 0; i < elements; i++){
       if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i]))
           parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i]));
    }
       parent->scale(axis);
}
Ogre::SceneNode* MiniMapManager::addMiniMapEntity(Ogre::Vector3 *pos, const std::string &meshName)
{
	Ogre::Entity *entity = mSceneMgr->createEntity(meshName);
	Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();

	Ogre::Vector3 convertedPos = Ogre::Vector3(pos->z/ZoomRatio, -pos->x/ZoomRatio, 0);
	node->setPosition(convertedPos);
	node->attachObject(entity);
	node->scale(Scale, Scale, Scale);
	return node;
}
Exemple #15
0
int Create_Static_Object::create(Ogre::SceneManager *mainSceneMgr) {
    if (meshName.empty() ) {
        std::cout << "Whoops, what do you think you're doing? You didn't give a mesh name!" << std::endl;
        return 0;
    }

    if (meshFile.empty() ) {
        std::cout << "Well what did you expect? There's no mesh file to load!" << std::endl;
        return 0;
    }

    Ogre::SceneNode *nodeStaticObject = mainSceneMgr->getRootSceneNode()->createChildSceneNode(meshName, location, rotation);
    Ogre::Entity *entityStaticObject = mainSceneMgr->createEntity(meshName, meshFile);

    if (!materialName.empty() ){
        entityStaticObject->setMaterialName(materialName);
    }

    entityStaticObject->setCastShadows(shadow);

    nodeStaticObject->attachObject(entityStaticObject);
    nodeStaticObject->showBoundingBox(showBBox);
    nodeStaticObject->scale(scale);

    //Create the ground shape.
    BtOgre::StaticMeshToShapeConverter ogreBulletShapeConverter(entityStaticObject);
    if (bulletCollision == "sphere"){
        shapeStaticObject = ogreBulletShapeConverter.createSphere();
    } else if (bulletCollision == "box"){
        shapeStaticObject = ogreBulletShapeConverter.createBox();
        offsetLocation = entityStaticObject->getBoundingBox().getHalfSize();
        location.y = location.y - offsetLocation.y;
    } else if (bulletCollision == "trimesh"){
        shapeStaticObject = ogreBulletShapeConverter.createTrimesh();
    } else if (bulletCollision == "cylinder"){
        shapeStaticObject = ogreBulletShapeConverter.createCylinder();
    } else if (bulletCollision == "convex"){
        shapeStaticObject = ogreBulletShapeConverter.createConvex();
    }else{
        return 0;
    }

    shapeStaticObject->setLocalScaling(BtOgre::Convert::toBullet(nodeStaticObject->getScale() ) );

    //Create MotionState (no need for BtOgre here, you can use it if you want to though).
    stateStaticObject = new btDefaultMotionState(btTransform( BtOgre::Convert::toBullet(rotation),  BtOgre::Convert::toBullet(location) ) );

    //Create the Body.
    bodyStaticObject = new btRigidBody(0, stateStaticObject, shapeStaticObject, btVector3(0,0,0));
    Globals::phyWorld->addRigidBody(bodyStaticObject);

    return 1;
}
void Room::createTargetEntity(Ogre::SceneManager* mSceneMgr, Ogre::SceneNode* wallNode){
    Ogre::Entity* targetEntity = mSceneMgr->createEntity("wall");
    srand(time(NULL));
    float xvalue = ((float) rand()/RAND_MAX)*.8f-.4f;
    float zvalue = ((float) rand()/RAND_MAX)*.8f-.4f;
    xvalue = 0.0f;
    zvalue = 0.0f;
    targetEntity->setMaterialName("Examples/10PointBlock");
    Ogre::SceneNode* targetNode = wallNode->createChildSceneNode(Ogre::Vector3(xvalue*WALL_SIZE, 1, zvalue*WALL_SIZE));
    targetNode->scale(Ogre::Vector3(0.2, 0.2, 0.2));
    targetNode->attachObject(targetEntity);
}
Exemple #17
0
void DotSceneLoader::processCamera(rapidxml::xml_node<>* XMLNode,
		Ogre::SceneNode *pParent) {
	// Process attributes
	Ogre::String name = getAttrib(XMLNode, "name");
	Ogre::String id = getAttrib(XMLNode, "id");
// Ogre::Real fov = getAttribReal(XMLNode, "fov", 45);
// Ogre::Real aspectRatio = getAttribReal(XMLNode, "aspectRatio", 1.3333);
	Ogre::String projectionType = getAttrib(XMLNode, "projectionType",
			"perspective");

	// Create the camera
	Ogre::Camera *pCamera = mSceneMgr->createCamera(name);

	// Set the projection type
	if (projectionType == "perspective")
		pCamera->setProjectionType(Ogre::PT_PERSPECTIVE);
	else if (projectionType == "orthographic")
		pCamera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);

	rapidxml::xml_node<>* pElement;

	// Process clipping (?)
	pElement = XMLNode->first_node("clipping");
	if (pElement) {
		Ogre::Real nearDist = getAttribReal(pElement, "near");
		if (nearDist > 0)
		  pCamera->setNearClipDistance(nearDist);

		Ogre::Real farDist = getAttribReal(pElement, "far");
		pCamera->setFarClipDistance(farDist);
	}

	// Process position (?)
	pElement = XMLNode->first_node("position");
	if (pElement)
		pCamera->setPosition(parseVector3(pElement));

	// Process rotation (?)
	pElement = XMLNode->first_node("rotation");
	if (pElement)
		pCamera->setOrientation(parseQuaternion(pElement));

	// construct a scenenode is no parent
	if (!pParent) {
		Ogre::SceneNode* pNode = mAttachNode->createChildSceneNode(name);
		pNode->setPosition(pCamera->getPosition());
		pNode->setOrientation(pCamera->getOrientation());
		pNode->scale(1, 1, 1);
	}
}
void ScoreScreen::LoadLevel(Ogre::String levelName)
{
	ResetCamera();

	Ogre::DotSceneLoader a;
	a.parseDotScene(levelName + ".scene", "General", mSceneMgr.get());

	labels.clear();

	for (unsigned int i = 0; i < mGameClient->raceResults.size(); ++i)
	{
		//make the node
		char name[128];
		sprintf_s(name, 128, "playerResult%i", i);

		if (mSceneMgr->hasSceneNode(name))
			mSceneMgr->destroySceneNode(name);

		Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(name);

		Ogre::Entity* ent = mSceneMgr->createEntity("checkBox.mesh");

		//Make the text
		char words[128];
		sprintf_s(words, 128, "Player %i = %d:%d.%d", i + 1, mGameClient->raceResults[i].minutes, mGameClient->raceResults[i].seconds, mGameClient->raceResults[i].ms);

		Ogre::MovableText* text = new Ogre::MovableText(name, words);
		text->setTextAlignment(Ogre::MovableText::H_LEFT, Ogre::MovableText::V_CENTER);
		node->setPosition(-3, 1.5 - (i*0.6), -5);
		node->scale(1, 0.5, 1);

		std::shared_ptr<PlayerLabel> p = std::shared_ptr<PlayerLabel>(new PlayerLabel(node, ent, text));

		labels.push_back(p);
	}

	//Reset the server
	mGameClient->SendString("reset");

	//Reset the local client stuff
	mGameClient->raceComplete = false;
	mGameClient->raceResults.clear();
	mGameClient->allReady = false;
	mGameClient->allDoneLoading = false;
	mGameClient->startingIndex = 999;
	mGameClient->totalPlayers = 0;
	mGameClient->mConnectedPlayers = NULL;
	mGameClient->id = 0;
}
Exemple #19
0
Penguin::Penguin(Ogre::SceneManager* sceneMgr, std::string name) {
  Ogre::Entity* entPenguin = sceneMgr->createEntity(name, "penguin.mesh");
  mAnimationState = entPenguin->getAnimationState("amuse");
  mAnimationState->setLoop(true);
  mAnimationState->setEnabled(true);
  entPenguin->setCastShadows(true);
  Ogre::SceneNode* penguinNode = sceneMgr->getRootSceneNode()->createChildSceneNode(name, Ogre::Vector3(0,30,0));
  penguinNode->attachObject(entPenguin);
  penguinNode->scale(60 / 63.0057, 50 / 47.99059, 50 / 49.27139);
  Ogre::Camera* cam = sceneMgr->getCamera("GameCam");
  cameraNode = penguinNode->createChildSceneNode("CameraNode");
  cameraNode->attachObject(cam);

  setNode(penguinNode);
}
void  OgreWidget::initScene()
{
  Ogre::SceneNode * node = m_sceneManager->getRootSceneNode()->createChildSceneNode("grid");

  m_sceneManager->setAmbientLight(Ogre::ColourValue(1,1,1));
  m_sceneManager->getRootSceneNode()->attachObject(AxisObject::createAxis(m_sceneManager));

  Ogre::Real gridSpace = DataManager::getSingleton()->getGridSpace();

  node->attachObject(GridObject::createGrid(m_sceneManager));
  node->scale(gridSpace, gridSpace, gridSpace);
  constraintX(m_constraintedX);
  constraintY(m_constraintedY);
  constraintZ(m_constraintedZ);
  update();
}
Exemple #21
0
//-------------------------------------------------------------------------------------
void GameMain::createScene(void)
{
	createCamera();    // Camera
	createViewports(); // Viewport
	createEnvir();     // Environment: Light, Sky, etc.

	//-------------------------
	// 地平面
	Ogre::MeshManager::getSingleton().createPlane("floor", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Ogre::Plane(Ogre::Vector3::UNIT_Y, 0), 100, 100, 10, 10, true, 1, 10, 10, Ogre::Vector3::UNIT_Z);

	// create a floor entity, give it a material, and place it at the origin
	Ogre::Entity* floor = mSceneMgr->createEntity("Floor", "floor");
    floor->setMaterialName("Examples/Rockwall");
	floor->setCastShadows(false);
    mSceneMgr->getRootSceneNode()->attachObject(floor);

	//-------------------------
	// 创建障碍物分布地图
	//-------------------------
	// 创建障碍物
	/*Ogre::SceneNode * boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Entity * boxEntity = mSceneMgr->createEntity("Box","cube.mesh");
	boxEntity->setMaterialName("Examples/BumpyMetal");
	
	boxNode->attachObject( boxEntity );
	boxNode->scale( 0.01f, 0.01f, 0.01f );
	boxNode->setPosition( 0,0.5,0 );

	boxNodes.push_back( boxNode );
	boxEntitys.push_back( boxEntity );*/

	Ogre::SceneNode * ogreHeadNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Entity * ogreHeadEntity = mSceneMgr->createEntity("OgreHead","ogrehead.mesh");
	
	ogreHeadNode->attachObject( ogreHeadEntity );
	ogreHeadNode->scale( 0.02f, 0.02f, 0.02f );
	//ogreHeadNode->setPosition( 1, 0, 1 );
	ogreHeadNode->setPosition( 15, 0.5, -20 );

	boxNodes.push_back( ogreHeadNode );
	boxEntitys.push_back( ogreHeadEntity );

	//-------------------------
	// 创建角色
	mPlayer = new GamePlayer( mCamera, ogreHeadNode );
}
Exemple #22
0
void DemoKeeper::createBodies( void )
{
	// Each body needs at least one shape
	const hkVector4 halfExtents(1.0f, 0.75f, 1.0f);
	hkpShape* shape = new hkpBoxShape(halfExtents, 0 );

	// Compute the inertia tensor from the shape
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, 5.0f, massProperties);

	// Assign the rigid body properties
	hkpRigidBodyCinfo bodyInfo;
	bodyInfo.m_mass = massProperties.m_mass;
	bodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
	bodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
	bodyInfo.m_shape = shape;
	bodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;


	bodyInfo.m_friction = 0.1f;

	for(int i = 0; i < m_numBodies; i++)
	{
		bodyInfo.m_position.set( hkMath::cos(hkReal(i)) - 2.0f, i * 2.0f + 10, hkMath::sin(hkReal(i)));
		hkpRigidBody* body = new hkpRigidBody(bodyInfo);
		mWorld->addEntity(body);
		body->removeReference();

		//render it with Ogre
		Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		//scale
		boxNode->scale(2, 1.5, 2);

		//display and sync
		Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh");
		mLabMgr->setColor(ent, Ogre::Vector3(rand()/(double)RAND_MAX,rand()/(double)RAND_MAX,rand()/(double)RAND_MAX));
		HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, body,mWorld);
		boxNode->attachObject(ent);

		//register to lab manager
		mLabMgr->registerEnity( boxNode, body);
	}	
	shape->removeReference();
}
Exemple #23
0
void createPalms(Ogre::SceneManager *mSceneMgr)
{
	const int NumberOfPalms = 12;

	Ogre::SceneNode* mPalmsSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		
	for (int k = 0; k < NumberOfPalms; k++)
	{
		Ogre::Vector3 RandomPos = Ogre::Vector3(rnd_(500,2500),
			0,
			rnd_(500,2500));

		Ogre::RaySceneQuery * raySceneQuery = mSceneMgr->
			createRayQuery(Ogre::Ray(RandomPos + Ogre::Vector3(0,1000000,0), 
			Ogre::Vector3::NEGATIVE_UNIT_Y));

		Ogre::RaySceneQueryResult& qryResult = raySceneQuery->execute();
		Ogre::RaySceneQueryResult::iterator i = qryResult.begin();

		if (i != qryResult.end() && i->worldFragment)
		{
			if (i->worldFragment->singleIntersection.y>105 || i->worldFragment->singleIntersection.y<20)
			{
				k--;
				continue;
			}

			RandomPos.y = i->worldFragment->singleIntersection.y;
		}
		else
		{
			k--;
			continue;
		}

		Ogre::Entity *mPalmEnt = mSceneMgr->createEntity("Palm"+Ogre::StringConverter::toString(k), "Palm.mesh");
		Ogre::SceneNode *mPalmSN = mPalmsSceneNode->createChildSceneNode();

		mPalmSN->rotate(Ogre::Vector3(-1,0,rnd_(-0.3,0.3)), Ogre::Degree(90));
		mPalmSN->attachObject(mPalmEnt);
		Ogre::Real Scale = rnd_(50,75);
		mPalmSN->scale(Scale,Scale,Scale);
		mPalmSN->setPosition(RandomPos);
	}
}
    void createScene(void)
    {
        Ogre::Light* pLight = m_pSceneMgr->createLight();
        pLight->setPosition( 100.0f, 100.0f ,100.0f );

        Ogre::SceneNode* pHeadNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode();
        Ogre::Entity* pEntity = m_pSceneMgr->createEntity( "ogrehead", "ogrehead.mesh" );
        pHeadNode->attachObject( pEntity );
        pHeadNode->scale( 0.3, 0.3 ,0.3 );

        Ogre::Entity* pEntity2 = m_pSceneMgr->createEntity( "ogrehead2", "ogrehead.mesh" );
        Ogre::SceneNode* pNode2 = m_pSceneMgr->getRootSceneNode()->createChildSceneNode();
        pNode2->attachObject( pEntity2 );
        pNode2->setPosition( 0, 0, 20 );
        pNode2->scale( 0.3, 0.3, 0.3 );

        g_pThirdCamera = new ThirdPersonCamera( m_pCamera, pHeadNode );
        g_pThirdCamera->setup();
    }
Exemple #25
0
void Wheel::createNodesAndMesh(Utils::Xml &x) {
  Ogre::Entity *e;
  Ogre::SceneNode *n;

    n  = sceneMgr_->getRootSceneNode()->createChildSceneNode(cst.nodeName);
  cst.wheelNode = n;
  

  e = sceneMgr_->createEntity(cst.nodeName+"t", x.mustString("tire-mesh"));
  e->setMaterialName(x.mustString("tire-material"));
  e->setCastShadows(true);
  n->attachObject(e);

  e = sceneMgr_->createEntity(cst.nodeName+"h", x.mustString("hubcap-mesh"));
  e->setMaterialName(x.mustString("hubcap-material"));
  n->attachObject(e);

  n->scale(x.mustOReal("scale.x"), x.mustOReal("scale.y"), x.mustOReal("scale.z"));
}
Exemple #26
0
void Laser::Initialize(Ogre::SceneManager *sceneManager, Ogre::SceneNode* parentNode, PhysicsEngine &physicsEngine, unsigned int parentID)
{
	PhysicsEntity::Initialize(sceneManager, parentNode, physicsEngine, parentID);

	//setting our mass to 0
	bodyType = ENTITY_BODY_METAPHYSICAL;
	dynamic = false;
	mass = 0.0f;

	Ogre::Entity *laserEntity = sceneManager->createEntity("Cylinder");
	laserEntity->setMaterialName("LaserMaterial");
	Ogre::SceneNode *laserSceneNode = sceneNode->createChildSceneNode("Laser" + Ogre::StringConverter::toString(entityCount));
	laserSceneNode->attachObject(laserEntity);
	laserSceneNode->scale(0.3f, 1000.0f, 0.3f);
	laserSceneNode->pitch(Ogre::Radian(-Ogre::Math::HALF_PI));
	laserSceneNode->translate(0,0,-500.0f);

	sceneNode->setVisible(false);
}
void OgreApplication::addActor(std::shared_ptr<OgreActor> actor)
{

    try {
        Ogre::Entity* ent;
        ent = mSceneMgr->createEntity(actor->entName(), actor->meshName());
        ent->setCastShadows(actor->castShadows());

        Ogre::SceneNode *node;
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode(actor->nodeName());
        node->setPosition(toOgreVector3(actor->position()));
        node->setOrientation(toOgreQuaternion(actor->orientation()));
        node->scale(actor->scale().x(),actor->scale().y(), actor->scale().z());
        node->attachObject(ent);
    }
    catch (Ogre::ItemIdentityException e){
        std::cerr << "OgreApplication::addActor, warning: Node " << actor->nodeName() << " already exists. Actor was not added." << std::endl;
    }
}
Exemple #28
0
Ring::Ring(Ogre::String name, RingFlier* flier):flier(flier)
{
	check=true;
	ringName=name;
	position.x=(rand()%5000);
	position.z=(rand()%5000);
	position.y=(rand()%700)+flier->getTerrainHeightAt(position.x,position.z)+100.0f;

	Ogre::SceneNode* sn = flier->getSceneManager()->getRootSceneNode()->createChildSceneNode("sn"+name);
	Ogre::Entity* ring = flier->getSceneManager()->createEntity(name,"Torus.mesh");
	sn->attachObject(ring);
	sn->scale(Ogre::Vector3(015.10f,015.10f,015.10f));
	sn->setPosition(position);
	sn->setVisible(true);
	sn->setOrientation(Ogre::Quaternion(Ogre::Radian(30.0f), Ogre::Vector3::UNIT_Z));
	sn->setDirection(rand()%10,rand()%10,rand()%10,Ogre::Node::TransformSpace::TS_LOCAL,Ogre::Vector3::NEGATIVE_UNIT_Z);
	Ogre::ParticleSystem* pSysRing = flier->getSceneManager()->createParticleSystem(ringName+'p',"PEExamples/ringShimmer");
	flier->getSceneManager()->getSceneNode("sn"+ringName)->attachObject(pSysRing);
}
  void createScene()
  {
    // Create the Entity
    Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh");
    // Attach robot to scene graph
    Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot");
    //RobotNode->setPosition((Ogre::Real)-0.3, (Ogre::Real)0.2, (Ogre::Real)0);
    RobotNode->attachObject(robot);
    RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
    RobotNode->pitch(Ogre::Degree(180));
    RobotNode->yaw(Ogre::Degree(-90));

    // The animation
    // Set the good animation
    mAnimationState = robot->getAnimationState( "Idle" );
    // Start over when finished
    mAnimationState->setLoop( true );
    // Animation enabled
    mAnimationState->setEnabled( true );
  }
bool TutorialApplication::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
    if (m_mode == TrollMode) {
        const Vector3 p = m_cursorNode->getPosition();
        m_ogres.push_back(p);

        Ogre::Entity *troll = m_SceneMgr->createEntity("ogrehead.mesh");
        Vector3 bounds = troll->getBoundingBox().getSize();
        Real dim = std::max({bounds.x, bounds.y, bounds.z});
        Real scale = GRID_SPACING / dim;
        bounds = bounds * scale * 0.5f;

        Ogre::SceneNode *node = m_SceneMgr->getRootSceneNode()->createChildSceneNode();
        node->setPosition(p.x + bounds.x, p.y + bounds.y, p.z + bounds.z);
//        node->showBoundingBox(true);
        node->scale(scale, scale, scale);
        node->attachObject(troll);
    }

    return BaseApplication::mouseReleased(arg, id);
}