Ejemplo n.º 1
0
	void MapPresenter::initializeScene(const QRectF& rect,
			const Ogre::ColourValue& bkcolor, 
			const Ogre::Vector3& eye_pos,
			const Ogre::Vector3& target_pos)
	{
		if (!view_->renderWindow())
			return;
		OgreContext* pOgreContext = WorkspaceRoot::instance()->ogreContext();
		scene_ = pOgreContext->createScene("MainRenderScene");

		//----------------------------------scene rendering test-------------------
		// Setup animation default
		Ogre::Animation::setDefaultInterpolationMode(Ogre::Animation::IM_LINEAR);
		Ogre::Animation::setDefaultRotationInterpolationMode(Ogre::Animation::RIM_LINEAR);

		// Set ambient light
		scene_->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 1));

		//create camera
		active_camera_ = scene_->createCamera("MainRenderScene.Camera");

		//initialise camera man
		camera_man_= new SdkCameraMan(active_camera_);
		camera_man_->setStyle(OgreBites::CS_ORBIT);

		// Position it at 500 in Z direction
		active_camera_->setPosition(eye_pos);
		// Look back along -Z
		active_camera_->lookAt(target_pos);
		//camera->setPolygonMode(Ogre::PM_WIREFRAME);

		//set aspect ratio determine left and right
		active_camera_->setAspectRatio(rect.width() / rect.height());
		//set fovy determine top and bottom
		float near_distance = 10;
		float far_distance = 10000;
		float fov = 2 * ::atan(rect.height() * 0.5F / near_distance);
		//camera->setFOVy(Ogre::Radian(fov));
		//set near and far distance
		active_camera_->setNearClipDistance(near_distance);
		active_camera_->setFarClipDistance(far_distance);

		//add viewport
		Ogre::RenderWindow* pRenderWindow = view_->renderWindow();
		Viewport* vp = pRenderWindow->addViewport(active_camera_);
		vp->setBackgroundColour(bkcolor);

		//------------------------------rendering test---------------------
		// Create the robot scene
		Entity* robotEntity = scene_->createEntity("robot", "robot.mesh");

		// Add entity to the scene node
		// Place and rotate to face the Z direction
		Vector3 robotLoc(1500, 1480, 0);
		Quaternion robotRot(Degree(-90), Vector3(0, 1, 0));

		scene_->getRootSceneNode()->createChildSceneNode(robotLoc, robotRot)->attachObject(robotEntity);

		/*AnimationState* robotWalkState = robotEntity->getAnimationState("Walk");
		robotWalkState->setEnabled(true);*/

		// Create the ninja entity
		Entity *ent = scene_->createEntity("ninja", "ninja.mesh");

		// Add entity to the scene node
		// Place and rotate to face the Z direction
		Vector3 ninjaLoc(1460, 1470, 0);
		Quaternion ninjaRot(Degree(180), Vector3(0, 1, 0));

		SceneNode *ninjaNode = scene_->getRootSceneNode()->createChildSceneNode(ninjaLoc, ninjaRot);
		ninjaNode->scale(0.5, 0.5, 0.5);        // He's twice as big as our robot...
		ninjaNode->attachObject(ent);

		/*AnimationState* ninjaWalkState = ent->getAnimationState("Walk");
		ninjaWalkState->setEnabled(true);*/

		// Give it a little ambience with lights
		Ogre::Light* l;
		l = scene_->createLight("BlueLight");
		l->setPosition(1500,1500,100);
		l->setDiffuseColour(0.5, 0.5, 1.0);

		l = scene_->createLight("GreenLight");
		l->setPosition(1460,1450,-100);
		l->setDiffuseColour(0.5, 1.0, 0.5);
		camera_man_->setTarget(ninjaNode);
		//---------------------------------------------rendering test-------------------------

		view_->sceneLoaded();
	}
Ejemplo n.º 2
0
bool NavigationDefault::execute(int rid, Position FinalPos, Position &TargetPos)
{
    Vector2D currentLoc = robotLoc(rid,true);
    Vector2D nearestOBS;
    bool foundNearest = false;
    //for oppROBOTS
    for(int i=0; i < PLAYERS_MAX_NUM ;i++)
    {
        if(!_wm->oppRobot[i].isValid)
            continue;
        Vector2D rbTemp = _wm->oppRobot[i].pos.loc;
        if(intersectOBS(rbTemp,currentLoc,FinalPos.loc))
        {
            if(!foundNearest)
            {
                nearestOBS = rbTemp;
                foundNearest = true;
            }
            else if (currentLoc.dist2(rbTemp) <= currentLoc.dist2(nearestOBS) )
            {
                nearestOBS = rbTemp;
            }
        }
    }
    //for ourROBOT
    for(int i=0; i < PLAYERS_MAX_NUM ; i++)
    {
        if(!_wm->oppRobot[i].isValid)
            continue;
        if(i==rid)
            continue;
        Vector2D rbTemp = _wm->ourRobot[i].pos.loc;
        if(intersectOBS(rbTemp,currentLoc,FinalPos.loc))
        {
            if(!foundNearest)
            {
                nearestOBS = rbTemp;
                foundNearest = true;
            }
            else if (currentLoc.dist2(rbTemp) <= currentLoc.dist2(nearestOBS) )
            {
                nearestOBS = rbTemp;
            }
        }
    }
    //check ball
    if(_wm->ball.isValid)
    {
        Vector2D balltmp = _wm->ball.pos.loc;
        if(intersectOBS(balltmp,currentLoc,FinalPos.loc)){
            if(!foundNearest)
            {
                nearestOBS = balltmp;
                foundNearest = true;
            }
            else if (currentLoc.dist2(balltmp) <= currentLoc.dist2(nearestOBS) )
            {
                nearestOBS = balltmp;
            }
        }
    }
    if(!foundNearest)
        TargetPos = FinalPos;
    else {
        Line2D interline(currentLoc,nearestOBS);
        Circle2D obs(nearestOBS,300);
        Vector2D res1,res2;
        obs.intersection(interline.perpendicular(nearestOBS),&res1,&res2);
        if(FinalPos.loc.dist2(res1) <= FinalPos.loc.dist2(res2))
        {
            FinalPos.loc = res1;
            TargetPos = FinalPos;
        }else
        {
            FinalPos.loc = res2;
            TargetPos = FinalPos;
        }
    }
    return true;
}