//-----------------------------------------------------------------------
	void EntityRenderer::_updateRenderQueue(Ogre::RenderQueue* queue, ParticlePool* pool)
	{
		// Always perform this one
		ParticleRenderer::_updateRenderQueue(queue, pool);

		if (!mVisible)
			return;

		// Fast check to determine whether there are visual particles
		if (pool->isEmpty(Particle::PT_VISUAL))
			return;

		VisualParticle* particle = static_cast<VisualParticle*>(pool->getFirst(Particle::PT_VISUAL));
		while (!pool->end(Particle::PT_VISUAL))
		{
			if (particle)
			{
				if (!particle->visualData && !mVisualData.empty())
				{
					particle->visualData = mVisualData.back();
					mVisualData.pop_back();
				}

				if (particle->visualData)
				{
					Ogre::SceneNode* node = (static_cast<EntityRendererVisualData*>(particle->visualData))->node;
					if (node)
					{
						node->_setDerivedPosition(particle->position);

						if (mEntityOrientationType == ENT_ORIENTED_SHAPE)
						{
							// Use the orientation of the particle itself
							node->setOrientation(particle->orientation);
						}
						else if (mEntityOrientationType == ENT_ORIENTED_SELF)
						{
							// Rotate towards the direction
							node->setOrientation(Vector3::UNIT_X.getRotationTo(particle->direction));
						}
						else if (mEntityOrientationType == ENT_ORIENTED_SELF_MIRRORED)
						{
							// Rotate towards the negative direction
							node->setOrientation(Vector3::UNIT_X.getRotationTo(-particle->direction));
						}

						node->setVisible(true);
						node->setScale(particle->width / mBoxWidth, particle->height / mBoxHeight, particle->depth / mBoxDepth);
						if (mZRotated)
						{
							_rotateTexture(particle, static_cast<Ogre::Entity*>(node->getAttachedObject(0))); // We know for sure there is only one and it is an Entity*
						}
					}
				}
			}
			particle = static_cast<VisualParticle*>(pool->getNext(Particle::PT_VISUAL));
		}
	}
void GPUSurfApplication::createWebcamPlane(Real _distanceFromCamera)
{
	// Create a prefab plane dedicated to display video
    Vector2 videoDim = mVideo->getDimensions();
	float videoAspectRatio = videoDim.x / videoDim.y;

	float planeHeight = 2 * _distanceFromCamera * Ogre::Math::Tan(Degree(26.53)*0.5);
	float planeWidth = planeHeight * videoAspectRatio;

    Plane p(Vector3::UNIT_Z, 0.0);
	MeshManager::getSingleton().createPlane("VerticalPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, p , planeWidth, planeHeight, 1, 1, true, 1, 1, 1, Vector3::UNIT_Y);
	Entity* planeEntity = mSceneMgr->createEntity("VideoPlane", "VerticalPlane"); 
	planeEntity->setMaterialName("WebcamVideoMaterial");
	planeEntity->setRenderQueueGroup(RENDER_QUEUE_WORLD_GEOMETRY_1);

	// Create a node for the plane, inserts it in the scene
	Ogre::SceneNode* node = mCameraNode->createChildSceneNode("planeNode");
	node->attachObject(planeEntity);

    // Update position    
	Vector3 planePos = mCamera->getPosition() + mCamera->getDirection() * _distanceFromCamera;
	node->setPosition(planePos);

	// Update orientation
	node->setOrientation(mCamera->getOrientation());
}
Beispiel #3
0
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;
}
Beispiel #4
0
void OgreARAppLogic::createCameraPlane(int width, int height, Ogre::Real _distanceFromCamera)
{
	// Create a prefab plane dedicated to display video
	float videoAspectRatio = width / (float) height;

	float planeHeight = 2 * _distanceFromCamera * Ogre::Math::Tan(Degree(26)*0.5); //FOVy webcam = 26° (intrinsic param)
	float planeWidth = planeHeight * videoAspectRatio;

	Plane p(Vector3::UNIT_Z, 0.0);
	MeshManager::getSingleton().createPlane("VerticalPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, p , planeWidth, planeHeight, 1, 1, true, 1, 1, 1, Vector3::UNIT_Y);
	Entity* planeEntity = mSceneMgr->createEntity("VideoPlane", "VerticalPlane"); 
	planeEntity->setMaterialName("CameraMaterial");
	planeEntity->setRenderQueueGroup(RENDER_QUEUE_WORLD_GEOMETRY_1);

	// Create a node for the plane, inserts it in the scene
	Ogre::SceneNode* node = mCameraNode->createChildSceneNode("planeNode");
	node->attachObject(planeEntity);

	// Update position    
	Vector3 planePos = mCamera->getPosition() + mCamera->getDirection() * _distanceFromCamera;
	node->setPosition(planePos);

	// Update orientation
	node->setOrientation(mCamera->getOrientation());
}
Ogre::SceneNode* AWGraphics::SceneDirector::createPlane(float x, float y, float z)
{
    Ogre::Plane plane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);

    // Initialize a ground entity for later use
    Ogre::MeshManager::getSingleton().createPlane(
        "ground",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        plane,
        1500, 1500, 20, 20,
        true,
        1, 5, 5,
        Ogre::Vector3::UNIT_Z);

    //Ogre::MeshManager::getSingleton().createPlane()

    Ogre::Entity* groundEntity = mSceneMgr->createEntity("ground");
    groundEntity->setMaterialName("Rockwall");
    groundEntity->setCastShadows(false);

    Ogre::SceneNode* ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    ogreNode->attachObject(groundEntity);
    ogreNode->setPosition(x, y, z);
    ogreNode->setOrientation(Ogre::Quaternion::IDENTITY); // hope this is  a good reference

    return ogreNode;
}
void OBTutorial2::createBoxShape(Ogre::Entity* entity, Ogre::Vector3 position, bool bStatic)
{

   Ogre::SceneNode *node = entity->getParentSceneNode();
   Vector3 size = node->_getDerivedScale()*entity->getBoundingBox().getHalfSize();
   float mass =  bStatic ? 0.0f : 1.0f;
   srand( (unsigned)time( NULL ) );

   node->setPosition(position);
   node->setOrientation(Quaternion(Degree(Ogre::Math::RangeRandom(0.0,60.0)), Vector3::UNIT_Y));

   btBoxShape *sceneBoxShape = new btBoxShape(toBulletVector(size)); // konvertovat vektor size

   // and the Bullet rigid body
   MyMotionState * defaultMotionState = new MyMotionState(btTransform(btQuaternion(btScalar(0),btScalar(0),btScalar(0),btScalar(1))), node);
   btRigidBody *defaultBody = new btRigidBody(btScalar(1), defaultMotionState, sceneBoxShape);
  /* defaultBody->setShape(node, 
						sceneBoxShape, 
						0.6f,                             // dynamic body restitution
		                0.6f,                             // dynamic body friction
		                mass,                             // dynamic bodymass
		                node->_getDerivedPosition(),      // starting position of the box
		                node->_getDerivedOrientation());  // orientation of the box**/
	mShapes.push_back(sceneBoxShape);
	mBodies.push_back(defaultBody);
	mNumEntitiesInstanced++;				
}
Beispiel #7
0
bool BallApp::frameStarted(const Ogre::FrameEvent &evt) {
  bool result = BaseApplication::frameStarted(evt);
  if (mPhysics != NULL) {
    btDiscreteDynamicsWorld* world = mPhysics->getDynamicsWorld();
    world->stepSimulation(1.0f/60.0f);

    btAlignedObjectArray<btCollisionObject*> objs = world->getCollisionObjectArray();
    for (int i = 0; i < objs.size(); i++) {
      btCollisionObject *obj = objs[i];
      btRigidBody *body = btRigidBody::upcast(obj);
      
      if (body && body->getMotionState()) {
        btTransform trans;
        body->getMotionState()->getWorldTransform(trans);
        
        void *userPointer = body->getUserPointer();
        if (userPointer) {
          btQuaternion orientation = trans.getRotation();
          Ogre::SceneNode *sceneNode = static_cast<Ogre::SceneNode *>(userPointer);
          sceneNode->setPosition(Ogre::Vector3(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()));
          sceneNode->setOrientation(Ogre::Quaternion(orientation.getW(), orientation.getX(), orientation.getY(), orientation.getZ()));
        }
      }
    }
  }

  return result;
}
Beispiel #8
0
void Actors::insertBegin(const MWWorld::Ptr &ptr)
{
    Ogre::SceneNode* cellnode;
    CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(ptr.getCell());
    if(celliter != mCellSceneNodes.end())
        cellnode = celliter->second;
    else
    {
        //Create the scenenode and put it in the map
        cellnode = mRootNode->createChildSceneNode();
        mCellSceneNodes[ptr.getCell()] = cellnode;
    }

    Ogre::SceneNode* insert = cellnode->createChildSceneNode();
    const float *f = ptr.getRefData().getPosition().pos;
    insert->setPosition(f[0], f[1], f[2]);
    insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale);

    // Convert MW rotation to a quaternion:
    f = ptr.getCellRef().mPos.rot;

    // Rotate around X axis
    Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X);

    // Rotate around Y axis
    Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y);

    // Rotate around Z axis
    Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z);

    // Rotates first around z, then y, then x
    insert->setOrientation(xr*yr*zr);
    ptr.getRefData().setBaseNode(insert);
}
Beispiel #9
0
bool Game::update( float deltaSec ) {
	m_pDynamicsWorld->stepSimulation(deltaSec);
	btCollisionObjectArray objArray = m_pDynamicsWorld->getCollisionObjectArray();
	for( int i = 0; i < objArray.size(); i++ ) {
		btCollisionObject* obj = objArray[i];
		btRigidBody* body = btRigidBody::upcast(obj);

		if( body && body->getMotionState() ) {
			btTransform trans;
			body->getMotionState()->getWorldTransform(trans);

			void* userPointer = body->getUserPointer();
			if( userPointer ) {
				btQuaternion orientation = trans.getRotation();
				Ogre::SceneNode* sceneNode = static_cast<Ogre::SceneNode*>(userPointer);
				sceneNode->setPosition(Ogre::Vector3(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()));
				sceneNode->setOrientation(Ogre::Quaternion(orientation.getW(), orientation.getX(), orientation.getY(), orientation.getZ()));
			}
		}
	}

//	m_pPlayerSceneNode->translate(m_PlayerVelocity * deltaSec );
//	Ogre::Vector3 src = m_pPlayerSceneNode->getOrientation() * Ogre::Vector3::UNIT_X;
//	Ogre::Quaternion quat = src.getRotationTo(m_PlayerVelocity);
//	m_pPlayerSceneNode->rotate(quat);

	return true;
}//Game::update
Beispiel #10
0
Ogre::SceneNode *VLogicModel::_createLocatorSceneNode(const Ogre::Vector3 &pos, const Ogre::Quaternion &ori)
{
    static VUINT32 count = 0;
    Ogre::StringUtil::StrStreamType str;
    str<<"Locator_"<<std::setw(5)<<std::setfill('0')<<count++<<std::ends;
    Ogre::SceneNode *locatorNode = mModelMainNode->createChildSceneNode(str.str());
    locatorNode->translate(pos);
    locatorNode->setOrientation(ori);
    return locatorNode;
}
Beispiel #11
0
void DrawToolOGRE::multMatrix(float* glTransform)
{
    Ogre::Matrix4 t( glTransform[0], glTransform[1], glTransform[2], glTransform[3],
            glTransform[4], glTransform[5], glTransform[6], glTransform[7],
            glTransform[8], glTransform[9], glTransform[10], glTransform[11],
            glTransform[12], glTransform[13], glTransform[14], glTransform[15]);
    t = t.transpose();
    Ogre::SceneNode* currentSceneNode = sceneNodeStack.top();
    currentSceneNode->setOrientation(t.extractQuaternion());
    currentSceneNode->setPosition(t.getTrans());
}
//--------------------------------------------------------------------------------------
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);


}
 void SparseOccupancyGridArrayDisplay::processMessage(
   const jsk_recognition_msgs::SparseOccupancyGridArray::ConstPtr& msg)
 {
   allocateCloudsAndNodes(msg->grids.size()); // not enough
   for (size_t i = 0; i < msg->grids.size(); i++) {
     Ogre::SceneNode* node = nodes_[i];
     rviz::PointCloud* cloud = clouds_[i];
     const jsk_recognition_msgs::SparseOccupancyGrid grid = msg->grids[i];
     Ogre::Vector3 position;
     Ogre::Quaternion quaternion;
     if(!context_->getFrameManager()->transform(grid.header, grid.origin_pose,
                                                position,
                                                quaternion)) {
       ROS_ERROR( "Error transforming pose '%s' from frame '%s' to frame '%s'",
                  qPrintable( getName() ), grid.header.frame_id.c_str(),
                  qPrintable( fixed_frame_ ));
       return;                 // return?
     }
     node->setPosition(position);
     node->setOrientation(quaternion);
     cloud->setDimensions(grid.resolution, grid.resolution, 0.0);
     std::vector<rviz::PointCloud::Point> points;
     for (size_t ci = 0; ci < grid.columns.size(); ci++) {
       const jsk_recognition_msgs::SparseOccupancyGridColumn column = grid.columns[ci];
       const int column_index = column.column_index;
       for (size_t ri = 0; ri < column.cells.size(); ri++) {
         const jsk_recognition_msgs::SparseOccupancyGridCell cell = column.cells[ri];
         const int row_index = cell.row_index;
         rviz::PointCloud::Point point;
         if (!axis_color_) {
           QColor color = gridColor(cell.value);
           Ogre::ColourValue ogre_color = rviz::qtToOgre(color);
           point.color = ogre_color;
         }
         else {
           QColor color = axisColor(quaternion, Ogre::Vector3(1, 0, 0));
           Ogre::ColourValue ogre_color = rviz::qtToOgre(color);
           point.color = ogre_color;
         }
         point.position.x = grid.resolution * (column_index + 0.5);
         point.position.y = grid.resolution * (row_index + 0.5);
         point.position.z = 0.0;
         
         points.push_back(point);
       }
     }
     cloud->clear();
     cloud->setAlpha(alpha_);
     if (!points.empty()) {
       cloud->addPoints(&points.front(), points.size());
     }
   }
   context_->queueRender();
 }
void  OgreWidget::constraintZ(bool value)
{
  Ogre::SceneNode * node = m_sceneManager->getSceneNode("grid");

  m_constraintedZ = value;
  if (value)
    {
      node->setOrientation(1, 1, 0, 0);
      update();
    }
}
Beispiel #15
0
void OgreVehicle::updateVehicle(const AllVehicleInfoOgre& allv)
{
	//INITLOG;
	//PRINTLOG(allv.vepos.y);
	Ogre::SceneNode* pNode = (Ogre::SceneNode*)(mNode->getChild("Body" + mNode->getName()));
	pNode->setOrientation(allv.verot);
	mNode->setPosition(allv.vepos - mParNode->getWorldPosition());

	if (allv.campos != Ogre::Vector3(0, 0, 0))
	{
		Ogre::SceneNode* pCamNode = (Ogre::SceneNode*)(mNode->getChild("Cam" + mNode->getName()));

		pCamNode->setOrientation(allv.camrot);
		pCamNode->setPosition(allv.campos);
	}
	
	mWheels[0]->updateWheel(allv.angle0);
	mWheels[1]->updateWheel(allv.angle1);
	mWheels[2]->updateWheel(allv.angle2);
	mWheels[3]->updateWheel(allv.angle3);
}
Beispiel #16
0
void VLogicModel::_updateLocatorPos()
{
    for (VLocatorMap::iterator itr = mLocators.begin(); itr != mLocators.end(); ++itr)
    {
        VLocatorValue &tempValue = itr->second;

        // 只更新创建出来的(已经使用的)locator node
        if (tempValue.mLocatorNode != VNULL)
        {
            if (!tempValue.mBoneName.empty())
            {
                Ogre::Bone *bone = VNULL;
                try
                {
                    bone = mSkeleton->getBone(tempValue.mBoneName);
                }
                catch (const Ogre::Exception &e)
                {
                    Ogre::LogManager::getSingleton().logMessage("LogicModel::_updateLocatorPos " + mName + e.getDescription());
                    continue;
                }

                assert(bone != VNULL);

                Ogre::SceneNode *locatorNode = tempValue.mLocatorNode;
                assert(locatorNode != VNULL);

                locatorNode->setPosition(bone->_getDerivedPosition());
                locatorNode->setOrientation(bone->_getDerivedOrientation());

                if (tempValue.mTranslateFirst)
                {
                    // 先平移,再旋转
                    locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL);
                    locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL);
                }
                else
                {
                    // 先旋转,再平移
                    locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL);
                    locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL);
                }
            }
        }
    }

    if (mLocators.size() != 0)
    {
        mModelMainNode->_update(true, false);
    }
}
Beispiel #17
0
void GraphicsImpl::addNode(const boost::shared_ptr<ObjectToCreate>& object)
{
	Ogre::Entity* ent;
	Ogre::SceneNode* node;
	//Dout << "Creating object with specification: " + object.specification;
	ent = sceneMgr->createEntity(ObjectRegistry::Instance().getNameForID(object->node.ID) + boost::lexical_cast<std::string>(object->node.ID), object->specification);

	node = sceneMgr->getRootSceneNode()->createChildSceneNode();
	node->attachObject(ent);
	node->setPosition(object->node.pos);
	node->setOrientation(object->node.orient);
	node->setScale(object->scale);
	nodes[object->node.ID] = node;
}
Beispiel #18
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);
	}
}
/*! アセットファイルの読み込みを行う
@param[in] sceneMgr
@param[in] assetFileName
@param[in] assetName
*/
Ogre::SceneNode* AssetLoader::createChildSceneNodeWithTransform(Ogre::SceneNode* scnNode, const aiNode* ainode)
{	
	Ogre::SceneNode *node = scnNode->createChildSceneNode(getFullPathName(ainode)); //std::string(ainode->mName.data)+"_Node");

	aiVector3D scl;
	aiQuaternion rot;
	aiVector3D pos;

	ainode->mTransformation.Decompose(scl, rot, pos);
	node->setOrientation(rot.w, rot.x, rot.y, rot.z);
	node->setPosition(pos.x, pos.y, pos.z);
	node->setScale(scl.x, scl.y, scl.z);

	return node;
}
Beispiel #20
0
void ModelRenderer::repositionSceneNode()
{
	if (mModel) {
		Ogre::SceneNode* node = mTexture->getRenderContext()->getSceneNode();
		if (node) {
			node->setOrientation(mDefaultRotation);
			node->rotate(mModel->getDefinition()->getRotation());

			//translate the scale node according to the translate defined in the model
			node->setPosition(mDefaultTranslation);
			node->translate(mModel->getDefinition()->getTranslate());

		}
	}
}
Beispiel #21
0
 void Camera::attachTo(const MWWorld::Ptr &ptr)
 {
     mTrackingPtr = ptr;
     Ogre::SceneNode *node = mTrackingPtr.getRefData().getBaseNode()->createChildSceneNode(Ogre::Vector3(0.0f, 0.0f, mHeight));
     if(mCameraNode)
     {
         node->setOrientation(mCameraNode->getOrientation());
         node->setPosition(mCameraNode->getPosition());
         node->setScale(mCameraNode->getScale());
         mCameraNode->getCreator()->destroySceneNode(mCameraNode);
     }
     mCameraNode = node;
     if(!mCamera->isAttached())
         mCameraNode->attachObject(mCamera);
 }
//We're not sure whether return a reference to a vector is such a great idea. 
void
    CinematicManager::createPerspectiveCamera(Ogre::Real windowW, Ogre::Real windowH, const Ogre::Vector3 &initialPos,
    const Ogre::Quaternion &initialOrient, Control* control)
{
    Ogre::Camera* cam = _scnMgr->createCamera(PERSP_CAM_NAME + Ogre::StringConverter::toString(_camCurId));
    cam->setNearClipDistance(1.0f);
    cam->setFarClipDistance(400.0f);
    cam->setPosition(0.0f, 0.0f, 0.0f);
    cam->setAspectRatio(windowW / windowH);
    Ogre::SceneNode* defaultNode = _scnMgr->createSceneNode();
    defaultNode->setPosition(initialPos); //It's in local space.
    defaultNode->setOrientation(initialOrient);
    defaultNode->attachObject(cam);
    _camsVec.push_back(new ZCameraInfo(_camsVec.size(), "PERSPECTIVE", cam->getName(), control, cam));
}
bool VehicleRenderable::loadSceneNodes(TinyXml::TiXmlElement* ele)
{
	TinyXml::TiXmlElement* nodeEle = ele->FirstChildElement("node");
	while (nodeEle)
	{
		Ogre::String name = getAttrib(nodeEle, "name");
		Ogre::SceneNode* node = NULL;

		if (name.empty())
			node = mAttachNode->createChildSceneNode();
		else
			node = mAttachNode->createChildSceneNode(name);

		mSceneNodes.push_back(node);

		Ogre::LogManager::getSingleton().
			logMessage("VehicleRenderable : parsing <" + name + "> node...");

		//process position
		TinyXml::TiXmlElement* pos = nodeEle->FirstChildElement("position");
		node->setPosition(parseVector3(pos));
		node->setInitialState();

		//process scale
		TinyXml::TiXmlElement* scale = nodeEle->FirstChildElement("scale");
		node->setScale(parseVector3(scale));
		node->setInitialState();

		//process rotate
		TinyXml::TiXmlElement* rotate = nodeEle->FirstChildElement("rotation");
		node->setOrientation(parseQuaternion(rotate));
		node->setInitialState();

		//process entities
		TinyXml::TiXmlElement* entity = nodeEle->FirstChildElement("entity");
		while (entity)
		{
			if (!loadEntity(entity, node))
				return false;

			entity = entity->NextSiblingElement("entity");
		}

		nodeEle = nodeEle->NextSiblingElement("node");
	}

	return true;
}
Beispiel #24
0
// Fix for Simon in regards to animation mesh's orientation 
void Player::setAnimation(DynamicObject *p)
{

	// makes a child node of parent node 
	Ogre::SceneNode *childNode = mPlayerObject->mSceneNode->createChildSceneNode("child");
	childNode->flipVisibility(true); // makes this entire thing visible since parent node is invisible

	for (Ogre::String name : p->meshNames) {
		Ogre::Entity *newEnt = mSceneManager->createEntity(name);
		//mEntity->setCastShadows(true);
		childNode->attachObject(newEnt);
		childNode->setPosition(0, -125, 0);
		childNode->setOrientation(Ogre::Quaternion(0, 0, 1, -1)); // does the rotation 
		childNode->roll(Ogre::Radian(Ogre::Math::PI)); // fixes it so player's back faces us 
	}
}
Beispiel #25
0
void gkPhysicsController::setTransform(const btTransform& worldTrans)
{
	GK_ASSERT(m_object && m_object->isInstanced());


	const gkQuaternion& rot = gkMathUtils::get(worldTrans.getRotation());
	const gkVector3& loc = gkMathUtils::get(worldTrans.getOrigin());

	// apply to the node and sync state next update

	Ogre::SceneNode* node = m_object->getNode();

	node->setOrientation(rot);
	node->setPosition(loc);

	m_object->notifyUpdate();
}
void
    CinematicManager::createOrthoCamera(Ogre::Real windowW, Ogre::Real windowH, const Ogre::Vector3 &initialPos,
    const Ogre::Quaternion &initialOrient, Control* control)
{
    Ogre::Camera* cam = _scnMgr->createCamera(ORTHO_CAM_NAME + Ogre::StringConverter::toString(_camCurId));
    cam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    cam->setOrthoWindow(100, 50);
    cam->setNearClipDistance(1);
    cam->setPosition(0.0f, 0.0f,  0.0f);
    //cam->setFarClipDistance(100.0f);
    cam->setFOVy(Ogre::Radian(Ogre::Math::PI / 2.0f));
    Ogre::SceneNode* defaultNode = _scnMgr->createSceneNode();
    defaultNode->setPosition(initialPos);
    defaultNode->setOrientation(initialOrient);
    defaultNode->attachObject(cam);
    _camsVec.push_back(new ZCameraInfo(_camsVec.size(), "ORTHOGRAPHIC", cam->getName(), control, cam));
}
void
dmz::RenderModuleCoreOgreBasic::update_object_orientation (
      const UUID &Identity,
      const Handle ObjectHandle,
      const Handle AttributeHandle,
      const Matrix &Value,
      const Matrix *PreviousValue) {

   if (AttributeHandle == _defaultAttributeHandle) {

      Ogre::SceneNode *node = _dynamicObjectTable.lookup (ObjectHandle);

      if (node) {

         node->setOrientation (to_ogre_quaternion (Value));
      }
   }
}
Beispiel #28
0
void ModelRenderer::repositionSceneNode()
{
	if (mModel) {
		Ogre::SceneNode* node = mTexture->getRenderContext()->getSceneNode();
		if (node) {
			node->setOrientation(Ogre::Quaternion::IDENTITY);
			//rotate node to fit with WF space
			//perhaps this is something to put in the model spec instead?
			// 			node->rotate(Ogre::Vector3::UNIT_Y,(Ogre::Degree)90);
			node->rotate(mModel->getRotation());

			//translate the scale node according to the translate defined in the model
			node->setPosition(Ogre::Vector3::ZERO);
			node->translate(mModel->getDefinition()->getTranslate());

		}
	}
}
Beispiel #29
0
void GraphicsImpl::updatePositions()
{
	{
		boost::mutex::scoped_lock lock(modifyNodesMutex);

		while (!nodesToAdd.empty()) {
			addNode(nodesToAdd.back());
			nodesToAdd.pop_back();
		}

		while (!nodesToRemove.empty()) {
			removeNode(nodesToRemove.back());
			nodesToRemove.pop_back();
		}

		while (!terrainToCreate.empty()) {
			Terrain terrain = terrainToCreate.back();

			Ogre::Entity* ent;
			Ogre::SceneNode* node;
			Dout << "Creating terrain with specification: " + terrain.specification;
			ent = sceneMgr->createEntity(ObjectRegistry::Instance().getNameForID(terrain.node.ID) + boost::lexical_cast<std::string>(terrain.node.ID), terrain.specification);

			node = sceneMgr->getRootSceneNode()->createChildSceneNode();
			node->attachObject(ent);
			node->setPosition(terrain.node.pos);
			ent->setMaterialName("Simple/BeachStones");
			node->setOrientation(terrain.node.orient);
			node->setScale(terrain.scale);
			nodes[terrain.node.ID] = node;

			terrainToCreate.pop_back();

		}
	}

	if (!frontWorld->nodes.empty()) {
		for (std::vector< OgreNewt::Node* >::iterator iter = frontWorld->nodes.begin(); iter != frontWorld->nodes.end(); ++iter) {
			nodes[(*iter)->ID]->setOrientation((*iter)->orient);
			nodes[(*iter)->ID]->setPosition((*iter)->pos);
		}
	}
}
Beispiel #30
0
//std::vector<btRigidBody *> Objects; // Storing the physics objects that need to be
//WHERE btDiscreteDynamicsWorld *World
void Application::UpdatePhysics(unsigned int DeltaTime)
{
    // This is where the physics library does it's calculations based on the time since last frame.
    // Incorporating the time since last frame (DeltaTime) should give us smooth movement
    dynamicsWorld->stepSimulation(DeltaTime * 0.001f, 60);

    btRigidBody *TObject;

    // For each of the rigid body objects in our world (stored in the vector)
    //for(std::vector<btRigidBody *>::iterator it = Objects.begin(); it != Objects.end(); ++it)
    //THIS IS REPLACED WITH

//		for (int i = 0; i< this->physicsEngine->getCollisionObjectCount(); i++) {
    for (int i=0; i=dynamicsWorld->getNumCollisionObjects(); i++) {
        // Get the SceneNode using the pointer we saved when we created the objects

        //Ogre::SceneNode *node = static_cast<Ogre::SceneNode *>((*it)->getUserPointer());

        //TObject = *it;
        //replaced with
        //btCollisionObject* obj = this->physicsEngine->getDynamicsWorld()->getCollisionObjectArray()[i];
        btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
        btRigidBody* TObject = btRigidBody::upcast(obj);

        void *userPointer = TObject->getUserPointer();

        if (userPointer) {
            // Get the calculated position from the rigidbody object
            // and set the position of the rendered object
            btVector3 Point = TObject->getCenterOfMassPosition();
            Ogre::SceneNode *node = static_cast<Ogre::SceneNode *>(userPointer);
            node->setPosition(Ogre::Vector3((float)Point[0], (float)Point[1], (float)Point[2]));

            // Get the Orientation of the rigidbody as a bullet Quaternion
            // Convert it to an Ogre quaternion
            btQuaternion btq = TObject->getOrientation();
            Ogre::Quaternion quart = Ogre::Quaternion(btq.w(),btq.x(),btq.y(),btq.z());

            // Set the orientation of the rendered Object
            node->setOrientation(quart);
        }
    }
}