예제 #1
0
bool BaselinePattern::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id)
{
    Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
    Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
    
    query->setSortByDistance(true);
    Ogre::RaySceneQueryResult result = query->execute();
    
    //Handle Selection
    if (stage->selected == NULL) {
        if (result.size() > 0 && result[0].movable != NULL) {
            for (int i = 0; i < stage->poppies.size(); ++i)
                if ( stage->poppies[i]->hasEntity( (Ogre::Entity*)result[0].movable ) ) {
                    stage->poppies[i]->setColor(getRandomPotColor());
                    stage->selected = stage->poppies[i];
                    stage->poppies[i]->deactivateJump();
                    //soundPickUp->play();
                }
            
            for (int i = 0; i < stage->pots.size(); ++i)
                if (stage->pots[i]->hasEntity( (Ogre::Entity*)result[0].movable) )
                    stage->pots[i]->setColor(getRandomPotColor());
        }
    }
    
    return true;
}
예제 #2
0
파일: Camera.cpp 프로젝트: Pured/CSCI356
bool DemoApp::quickSelect()
{
	// Create RaySceneQuery
	Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(static_cast<float>(mMouse->getMouseState().X.abs)/mMouse->getMouseState().width, static_cast<float>(mMouse->getMouseState().Y.abs)/mMouse->getMouseState().height);

	Ogre::RaySceneQuery * mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());

	// Set ray
	mRaySceneQuery->setRay(mouseRay);

	mRaySceneQuery->setQueryTypeMask(Ogre::SceneManager::ENTITY_TYPE_MASK);
			
	mRaySceneQuery->setSortByDistance(true);

	// Ray-cast and get first hit
	Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
	Ogre::RaySceneQueryResult::iterator itr = result.begin();

	if((itr != result.end() && itr->movable))
	{
		
		//Get hit location
		Ogre::String name = itr->movable->getName();
		bool found=false;
		if(name=="Box")
		{
			itr++;
			name = itr->movable->getName();
		}

		for(int i=0;i<TANK_LIMIT;i++)
		{
			if(name=="Tank"+std::to_string(i))
			{
				tanks.at(i).selected=true;
				if(tanks.at(i).mSelectionCircle->getParentSceneNode()!=tanks.at(i).tankNode)
					tanks.at(i).tankNode->attachObject(tanks.at(i).mSelectionCircle);
				if(tanks.at(i).mHealthBar->getParentSceneNode()!=tanks.at(i).tankNode)
					tanks.at(i).tankNode->attachObject(tanks.at(i).mHealthBar);
				found=true;	
				tanks.at(i).path2->setVisible(true);
			}
			else if(controlPressed==false)
			{
				tanks.at(i).selected=false;
				if(tanks.at(i).mSelectionCircle->getParentSceneNode()==tanks.at(i).tankNode)
					tanks.at(i).tankNode->detachObject(tanks.at(i).mSelectionCircle);
				if(tanks.at(i).mHealthBar->getParentSceneNode()==tanks.at(i).tankNode)
					tanks.at(i).tankNode->detachObject(tanks.at(i).mHealthBar);
				tanks.at(i).path2->setVisible(false);
			}
		}
		if(found==false)
			return false;
		else return true;
	}
	return false;
}
예제 #3
0
std::pair<DetectionResult, DetectionIterator&> ViewDetection::detectObjects() {
	//Ogre::ResourceGroupManager::getSingletonPtr();
	//Ogre::OverlayManager* mg = Ogre::OverlayManager::getSingletonPtr();
	//Ogre::Overlay* ov = mg->getByName("TestScriptOverlay");

	Ogre::RaySceneQuery* rayQuery = viewManager->createRayQuery(*detection);
	rayQuery->setSortByDistance(true);

	DetectionResult result = rayQuery->execute();
	DetectionIterator& endOfResult = filterObjects(result);

	return std::make_pair(result, endOfResult);
}
예제 #4
0
void Game::CheckAndRespawnPlayers()
{
	// When A Player is dead, he is simply invisible
	for (std::vector<RenderableChar*>::iterator ite = local_players.begin(); ite != local_players.end(); ++ite) {
		if ( (*ite)->getCharState() == RenderableChar::SPAWNING ) {
			std::cout << "I should respawn!" << std::endl;
			(*ite)->resetVelX();
			(*ite)->resetVelY();
			(*ite)->setCharState(RenderableChar::IDLE);
			
			bool free = false;
			Ogre::RaySceneQuery* msq;
			float x;
			float y;
			int c = 0;
			
			// Here, we look for a position in the level which is collision free
			// TODO: IN NARROW LEVELS, THIS CAN LEAD TO INFINITE LOOPS!
			do {
				if (c > 20) {
					x = 10.0f;
					y = 10.0f;
					free = true;
				}
				x = Ogre::Math::RangeRandom(myLevel->getObjectSide(), myLevel->getObjectSide() * (myLevel->getWidth() -1));
				y = Ogre::Math::RangeRandom(myLevel->getObjectSide(), myLevel->getObjectSide() * (myLevel->getHeight()));	
				
				std::cout << "GENX: " << x << " --- GENY: " << y << std::endl;

				msq = OgreFW::getSingletonPtr()->m_pSceneMgr->createRayQuery(Ogre::Ray(Ogre::Vector3(x, y, 0.0f), Ogre::Vector3::UNIT_Y));
				msq->setSortByDistance(true, 3);
				//Ogre::RaySceneQuery	msq->setRay(Ogre::Ray( ( (*ite)->getWorldPosition() + Ogre::Vector3(0.0f, (*ite)->getAABB().getHalfSize().y, 0.0f) ), Ogre::Vector3::UNIT_Y ));
				Ogre::RaySceneQueryResult& result = msq->execute();
			
				for (Ogre::RaySceneQueryResult::iterator itr = result.begin(); itr != result.end(); ++itr) {
					if ( itr->distance >= (*ite)->getAABB().getSize().x ){
						free = true;
						break;
					}
				}
				c++;
			} while (free != true);
			(*ite)->SetPosition(Ogre::Vector3(x, y + 0.1, 0.0f));
			(*ite)->setVisible(true);
			msq->clearResults();
		}
	}
}
예제 #5
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
RenderingCanvas::querySceneNodes(Math::Real _x, Math::Real _y, I_SceneNodeVisitor& _visitor)
{
    Ogre::Camera& camera = m_pCurrentCamera->getOgreCamera();
    Ogre::Vector3 position;
    if( camera.getParentSceneNode() )
    {
        position = camera.getParentSceneNode()->_getDerivedPosition();
    }
    else
    {
        position = camera.getDerivedPosition();
    }

    Ogre::RaySceneQuery* pSceneQuery =
        m_pSceneManager->createRayQuery(camera.getCameraToViewportRay(_x, _y));
    pSceneQuery->setSortByDistance(true);

    Ogre::RaySceneQueryResult::const_iterator iter;
    const Ogre::RaySceneQueryResult& queryResult = pSceneQuery->execute();

    _visitor.begin();
    for(iter = queryResult.begin(); iter != queryResult.end(); iter++)
    {
        const Ogre::RaySceneQueryResultEntry& result = *iter;

        // Check to see if this is a scene node.
        if (result.movable != NULL)
        {
            Ogre::SceneNode *pNode = dynamic_cast<Ogre::SceneNode*>(result.movable->getParentSceneNode());
            if (pNode)
            {
                if (!pNode->getUserAny().isEmpty())
                {
                    SceneNode* pRawSceneNode = Ogre::any_cast<SceneNode*>(pNode->getUserAny());

                    I_SceneNodeVisitor::pSceneNode_type pSceneNode(pRawSceneNode->getSelfReference().lock());

                    _visitor.visit(pSceneNode);
                }
            }
        }
    }
    _visitor.end();

    delete pSceneQuery;
}
예제 #6
0
bool BaselinePattern::mouseMoved(const OIS::MouseEvent &evt)
{
    Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
    Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
    
    query->setSortByDistance(true);
    Ogre::RaySceneQueryResult result = query->execute();
    
    if (stage->selected && stage->selected->getType() == Selectable::TYPE_POPPY)
        for (int i = 0; i < result.size(); ++i)
            if (stage->ground->hasEntity( (Entity*)result[i].movable )) {
                Poppy* toMove = (Poppy*)stage->selected;
                Vector3 hoverPos = ray * result[i].distance;
                hoverPos.y = poppyRadius;
                toMove->setPosition(hoverPos);
            }
    return true;
}
예제 #7
0
bool BaselinePattern::mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id)
{
    Ogre::Ray ray = OgreFramework::getSingletonPtr()->getCursorRay();
    Ogre::RaySceneQuery* query = OgreFramework::getSingletonPtr()->m_pSceneMgr->createRayQuery(ray);
    
    query->setSortByDistance(true);
    Ogre::RaySceneQueryResult result = query->execute();
    
    if (stage->selected != NULL && stage->selected->getType() == Selectable::TYPE_POPPY && result.size() > 0) {
        Poppy* old = (Poppy*)stage->selected;
        stage->selected = NULL;
        Vector3 placeDest = ray * result[0].distance;
        placeDest.y = poppyRadius;
        old->setPosition(placeDest);
        old->activateJump();
    }
    
    return true;
}
예제 #8
0
void QOgreWindow::mouseReleaseEvent(QMouseEvent *e)
{
    if (camMan) camMan->injectMouseUp(*e);

    QPoint pos = e->pos();
    Ogre::Ray mouseRay = oCam->getCameraToViewportRay(
                (Ogre::Real)pos.x() / oWin->getWidth(),
                (Ogre::Real)pos.y() / oWin->getHeight());
    Ogre::RaySceneQuery* sceneQuery = oSceneMgr->createRayQuery(mouseRay);
    sceneQuery->setSortByDistance(true);
    Ogre::RaySceneQueryResult vResult = sceneQuery->execute();

    for (size_t ui = 0; ui < vResult.size(); ui++)
    {
        if (vResult[ui].movable)
        {
            if (vResult[ui].movable->getMovableType().compare("Entity") == 0)
            {
                emit entitySelected((Ogre::Entity*)vResult[ui].movable);
            }
        }
    }
    oSceneMgr->destroyQuery(sceneQuery);
}
예제 #9
0
void Tank::update(const float& deltaTime, std::vector<PowerUpSpawn*> mPowerUpSpawns){
	
	//this check must be first
	if (!isAlive())
	{
		deathTimer -= deltaTime;

		if (deathTimer <= 0.f)
		{
			deathTimer = 0.f;
			resetAll();
			
			std::random_device rd;
			std::mt19937 random(rd());

			if (tankSide == 1)
			{
				std::uniform_real_distribution<double> randomGen1(1, 5);
				int tempNumber = randomGen1(random);
				std::uniform_real_distribution<double> randomGen2(0, 36);
				int tempNumber2 = (36 * (int)randomGen2(random)) + (int)tempNumber;

				Ogre::Vector3 position = pathFindingGraph->getPosition(tempNumber2);

				mTankBodyNode->setPosition(position);
			} else if(tankSide == 2){
				std::uniform_real_distribution<double> randomGen1(31, 35);
				int tempNumber = randomGen1(random);
				std::uniform_real_distribution<double> randomGen2(0, 36);
				int tempNumber2 = (36 * (int)randomGen2(random)) + (int)tempNumber;
				
				Ogre::Vector3 position = pathFindingGraph->getPosition(tempNumber2);

				mTankBodyNode->setPosition(position);
			}
			mTankBodyNode->setVisible(true);
			setSelected(false);
		}
	}

	//Check for tank powerups
	sphereSceneTime += deltaTime;
	if(sphereSceneTime > 0.2)
	{
		sphereSceneTime = 0;

		Ogre::Vector3 tankCenter = mTankBodyNode->getPosition();
		int location;
		bool found = false;

		for(int i = 0; i < mPowerUpSpawns.size(); i++)
		{
			Ogre::Vector3 powerUpLocation = mPowerUpSpawns[i]->spawnNode->getPosition();
			if(tankCenter.squaredDistance(powerUpLocation) < 5625) //squaredDistance is better
			{
				found = true;
				location = i;
			}
		}
		if (found)
		{
			if(mPowerUpSpawns[location]->getIsPowerUp())
			{
				char tempType = mPowerUpSpawns[location]->pickupPowerUp(mSceneMgr);

				printf("Got Powerup %c\n", tempType);

				switch(tempType)
				{
					case ('H'): //health
					{
						hp += 0.1f;
						if (hp > 1.0f)
						{
							hp = 1.0f;
						}
						printf("Got Health\n");

						//update healthbar
						float healthBarAdjuster = (1.0 - hp) / 2;
						mHealthBarBB->setTexcoordRect(0.0 + healthBarAdjuster, 0.0, 0.5 + healthBarAdjuster, 1.0);
					}
					break;
					case ('R'): //fire rate
					{
						fireRate = 1.f;
						powerUpDurationR = 6.f;
					}
					break;
					case ('S'): //speed
					{
						mRotSpd = 75.0f;
						ms = 100.f;
						mMoveSpd = 100.f;
						powerUpDurationS = 6.f;
					}
					break;
					case ('P'): //damage
					{
						dmg = 30.f;
						powerUpDurationP = 6.f;
					}
					break;
					default:
						printf("Unknown Powerup\n");
					break;
				}
			}
			currentState = WANDER;
			resetWander();
			wanderAStar();
		}
	}

	decrementPowerups(deltaTime);

	//weapontimer
	weaponTimer += deltaTime;

	//seek powerups
	/*
	Ogre::Real distancePowerUp = 0;
	int powerUpNo = 0;
	bool firstTimeDistanceCheck = true;
	for(int i = 0; i < mPowerUpSpawns.size(); i++)
	{
		if(mPowerUpSpawns[i]->getIsPowerUp())
		{
			Ogre::Real tempDistancePowerUp = mTankBodyNode->getPosition().distance(mPowerUpSpawns[i]->getPowerLocation());

			if(firstTimeDistanceCheck)
			{
				firstTimeDistanceCheck = false;
				distancePowerUp = tempDistancePowerUp;
			}
			if(tempDistancePowerUp < distancePowerUp)
			{
				distancePowerUp = tempDistancePowerUp;
				powerUpNo = i;
			}
		}
	}*/
	/*
	if(distancePowerUp < 500 && distancePowerUp > 0 && currentState != POSSESSED)
	{
		if(mPowerUpSpawns[powerUpNo]->getIsPowerUp())
		{
			if(currentState != SEEK)
			{
				currentState = SEEK;
				seekTarget = mPowerUpSpawns[powerUpNo]->getPowerLocation();
				seekAStar();
			}
			
		}
		else 
			currentState = WANDER;
		
	}*/
	
	//check if the user is like somewhere and stopped ocassionally 
	if (currentState != POSSESSED)
	{
		checkPosition += deltaTime;
		if(checkPosition > 3)
		{
			if(mTankBodyNode->getPosition().x == previousLocation.x)
			{
				if(mTankBodyNode->getPosition().z == previousLocation.z)
				{
					checkWhereAt();
				}
			}
			checkPosition = 0;
			previousLocation = mTankBodyNode->getPosition();
		}
	
		checkOrientation += deltaTime;
		if(checkOrientation > 15)
		{
			if(currentState != A_STAR)
			{
				if(!orientationEquals(initBodyOrientation, mTankBodyNode->getOrientation()))
				{
					mTankBodyNode->setOrientation(initBodyOrientation);
				}
				if(!orientationEquals(initBarrelOrientation, mTankBarrelNode->getOrientation()))
				{
					mTankBarrelNode->setOrientation(initBarrelOrientation);
				}
				if(!orientationEquals(initTurretOrientation, mTankTurretNode->getOrientation()))
				{
					mTankTurretNode->setOrientation(initTurretOrientation);
				}
			}
			checkOrientation = 0;
		}
	}

	//no movement for body yet

	//A_STAR, SEEK, WANDER, ESCAPE, STOP
	switch(currentState)
	{
		case A_STAR:
			//initiate astar
			if(tankStarted == false)
			{
				tankStarted = true;
				aStar(tankSide); //creates the path to get out of there
			}
			else
			{
				aStarMovement(deltaTime);
			}
		break;
		case FIRE:
		{
			Ogre::Vector3 targetPosition = getPredictPos(target);
			targetPosition.y = 16.f;

			Ogre::Degree angle = getShootingAngle(targetPosition);

			mTankTurretNode->lookAt(targetPosition, Ogre::Node::TransformSpace::TS_WORLD, Ogre::Vector3::NEGATIVE_UNIT_X);
			//barrelDegree = angle;
			if (weaponTimer > 4)
			{
				tnkMgr->createProjectile(mTankBodyNode->getPosition(), mTankTurretNode->_getDerivedOrientation(), angle, shootingVelocity, dmg);
				weaponTimer = 0;
			}
			if (target->hp <= 0 || mTankBodyNode->getPosition().distance(target->getPosition()) > 600 )
				currentState = WANDER;
		}
		case WANDER:
			//wander(deltaTime);
			wanderMovement(deltaTime);
			break;
	
		case SEEK:
			//seek(mPowerUpSpawns[powerUpNo]->getPowerLocation(), deltaTime);

			//seek(Ogre::Vector3::ZERO, deltaTime);
			//seekMovement(deltaTime);
		break;
		case ESCAPE:
			
		break;
		case STOP:
		
		break;

		case POSSESSED: {
			Ogre::Vector3 rayDest;

			if (mMove < 0)
				rayDest = mTankBodyNode->getOrientation() * Ogre::Vector3(-1,0,0);
			else if (mMove > 0)
				rayDest = mTankBodyNode->getOrientation() * Ogre::Vector3(1,0,0);


			//THIS IS WHERE THE TANK IS MOVED WHEN PROCESSING

			//if (rayDest != NULL)
			{
				Ogre::Ray shootToCheckWall = Ogre::Ray(mTankBodyNode->getPosition(), rayDest);

				Ogre::RaySceneQuery* mRaySceneQuery = mSceneMgr->createRayQuery(shootToCheckWall, Ogre::SceneManager::ENTITY_TYPE_MASK);
				mRaySceneQuery->setSortByDistance(true);

				// Ray-cast and get first hit
				Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
				Ogre::RaySceneQueryResult::iterator itr = result.begin();

				bool hit = false;
				for (itr = result.begin(); itr != result.end(); itr++) 
				{
					
					std::string x = itr->movable->getName();
					printf("Check %s \n", x.c_str());

					if (x[0] == 'C' && itr->distance < 10)
					{
						printf("Too close to %s: %f \n", x.c_str(), (float)itr->distance);
						hit = true;
					}
				}

				if(hit == false)
				{
				
					mTankBodyNode->translate(mMove * deltaTime * mMoveSpd, 0, 0, Ogre::Node::TransformSpace::TS_LOCAL);
				}
			}		

			mTankBodyNode->yaw(Ogre::Degree(bodyRotate * deltaTime * mRotSpd));

			// Rotate the tank turret
			mTankTurretNode->yaw(Ogre::Degree(turretRotation * deltaTime * mRotSpd * 1.5));

			turretDegree += turretRotation;

			//to move barrel change barrelRotation
			float barrelChange = barrelRotation * deltaTime * mRotSpd;
			barrelDegree += barrelChange;

			if(barrelDegree > 30)
				barrelDegree = 30;
			else if(barrelDegree < 0)
				barrelDegree = 0;
			else
				mTankBarrelNode->roll(Ogre::Degree(-barrelChange));				
		}

		break;
	}

	Ogre::Vector3 setpos = mTankBodyNode->getPosition();
	setpos.y = 13.f;
	mTankBodyNode->setPosition(setpos);

}
예제 #10
0
bool Player::Update(InputManager* input,
					PhysicsManager* physics,
					EWSManager* ews,
					const OgreTransform& transform)
{
	if(input->isCFGKeyPressed(InputManager::ENVWARNSYS))
	{
		placeEWS(ews,physics,transform);
	}

	cGunData* gun = nullptr;

	if(_equippables[_curEquippable].equip->getIsWeapon())
	{
		gun = static_cast<cGunData*>(_equippables[_curEquippable].equip);
	}

	if(gun != nullptr)
	{	
		bool movkey = false;
		movkey = (input->isCFGKeyPressed(InputManager::FORWARD) || 
			      input->isCFGKeyPressed(InputManager::BACKWARD)||
				  input->isCFGKeyPressed(InputManager::RIGHT) ||
				  input->isCFGKeyPressed(InputManager::LEFT));

		if(input->isMBPressed(OIS::MB_Left))
		{
			//shoot gun
			//std::cout << "MB_Left pressed..." << std::endl;
			gun->fire();
			//check for collisions with enemies if first time through
			if(gun->shouldDamage())
			{
				Ogre::SceneManager* scene = _equipNode->getCreator();
				Ogre::Vector3 dir = transform.direction;
				Ogre::Ray ray(transform.position,dir);

				Ogre::RaySceneQuery* rayQuery = scene->createRayQuery(ray);
				rayQuery->setSortByDistance(true);

				Ogre::RaySceneQueryResult results = rayQuery->execute();

				auto shot =  [this,gun] (Ogre::RaySceneQueryResultEntry& entry) 
				{
					if(entry.movable != nullptr)
					{
						std::string name = entry.movable->getName().substr(3,std::string::npos);
						LevelData::BaseEntity* ent = LuaManager::getSingleton().getEntity(name);
						if(ent != nullptr && (ent->getType() == LevelData::NPC || ent->getType() == LevelData::ENEMY))
						{
							_damageInterface->registerShotAtEnemy(gun->getGunshotData(),name);
						}
					}
				};
				std::for_each(results.begin(),results.end(),shot);

				scene->destroyQuery(rayQuery);
			}
		}
		else
		{
			gun->setFiring(false);
		}

		if(input->isCFGKeyPressed(InputManager::RELOAD))
		{
			gun->reload();
		}

		if(movkey)
		{
			gun->setMoving(true);
		}
		else
		{
			if(gun->isMoving())
			{
				gun->setMoving(false);
			}
		}
	}

	if(_damageInterface != nullptr)
	{
		//this clears out the added-up damage in the interface.
		_health -= static_cast<int>(_damageInterface->getTotalDamagePlayer());
	}

	return true;
}
예제 #11
0
void NPCCharacter::_actionLook(const Ogre::Vector3& target)
{
	Ogre::Bone* headBone;
	std::string n = _node->getName();
	Ogre::Skeleton* skel = static_cast<Ogre::Entity*>(_movableObject)->getSkeleton();
	headBone = skel->getBone("Bip01_Head");

	headBone->setManuallyControlled(true);
	headBone->setInheritOrientation(true);
	int nAnim = skel->getNumAnimations();

	//have to do this to allow the head to turn properly.
	for(int i = 0; i < nAnim; ++i)
	{
		skel->getAnimation(i)->destroyNodeTrack(headBone->getHandle());
	}

	Ogre::Vector3 test = headBone->_getDerivedPosition() * CHARACTER_SCALE_FACTOR + _node->getPosition();
	Ogre::Vector3 dir = target - test;
	Ogre::Quaternion nodeRot,boneRot;
	Ogre::Euler boneEuler; boneEuler.setDirection(dir,true,false);
	/*boneRot = _node->convertLocalToWorldOrientation(_node->getOrientation()) * headBone->_getDerivedOrientation();
	Ogre::Vector3 boneTest = boneRot * Ogre::Vector3::UNIT_Z;*/
	//Ogre::Vector3 boneTest = headBone->getOrientation() * Ogre::Vector3::UNIT_Z;

	//turns the direction vector into a 2D normalized vector on the X/Z axis.
	dir.y = 0;
	dir.normalise();

	//All of this ray query stuff is to make sure that the AI can "see" the target before attempting to look at it.
	Ogre::SceneManager* scene = _node->getCreator();
	Ogre::Ray ray(headBone->_getDerivedPosition() * CHARACTER_SCALE_FACTOR + _node->getPosition(),dir);

	Ogre::RaySceneQuery* query = scene->createRayQuery(ray);
	query->setSortByDistance(true);
	query->setQueryMask(CHARACTER_MASK | SCENERY_MASK);

	Ogre::RaySceneQueryResult results = query->execute();

	bool withinView = false;
	if(results.size() == 0)
	{
		withinView = true;
	}
	else
	{
		if(results.begin()->movable->getParentNode()->getName() == getName())
		{
			if(results.size() == 1)
			{
				withinView = true;
			}
		}
		
		if(!withinView && results.size() > 1 && std::next(results.begin())->distance > test.distance(target))
		{
			withinView = true;
		}
	}

	scene->destroyQuery(query);

	if(withinView)
	{
		Ogre::Euler node;
		Ogre::Euler t = headOrientation.getRotationTo(dir);
		t.limitYaw(Ogre::Radian(3.0));
		t.limitPitch(Ogre::Radian(0.0));

		headOrientation = headOrientation + t;
		headOrientation.limitYaw(Ogre::Degree(100));
		headOrientation.limitPitch(Ogre::Degree(60));

		headBone->setOrientation(headOrientation);

		/*headBone->rotate(boneTest.getRotationTo(dir),Ogre::Node::TS_WORLD);

		Ogre::Quaternion boneRotation = _node->convertLocalToWorldOrientation(_node->getOrientation()) * headBone->_getDerivedOrientation() * (Ogre::Quaternion(Ogre::Degree(180),Ogre::Vector3::UNIT_Y));
		Ogre::Quaternion nodeRotation = _node->_getDerivedOrientation();
		Ogre::Quaternion diff = nodeRotation.Inverse() * boneRotation;*/
	}

	_isActFinished = true;
}