Ejemplo n.º 1
0
bool gkMouseSensor::rayTest(void)
{
	// cannot test no movable data,
	if (m_type == MOUSE_MOUSE_OVER && (m_object->getType() == GK_OBJECT || m_object->getType() == GK_SKELETON))
		return false;


	GK_ASSERT(m_object);
	gkCamera* cam = m_object->getOwner()->getMainCamera();
	Ogre::Camera* oc = cam->getCamera();


	gkMouse* mse = gkWindowSystem::getSingleton().getMouse();

	gkScalar ncx = mse->position.x / mse->winsize.x;
	gkScalar ncy = mse->position.y / mse->winsize.y;


	Ogre::Ray dest;
	oc->getCameraToViewportRay(ncx, ncy, &dest);

	if (m_rayQuery == 0)
	{
		Ogre::SceneManager* mgr = m_object->getOwner()->getManager();
		m_rayQuery = mgr->createRayQuery(dest);
	}
	else m_rayQuery->setRay(dest);


	// do the test
	Ogre::RaySceneQueryResult& res = m_rayQuery->execute();

	bool result = false;
	for (Ogre::RaySceneQueryResult::iterator it = res.begin(); it != res.end(); ++it)
	{
		Ogre::RaySceneQueryResultEntry ent = (*it);

		if (ent.movable == oc)
			continue;


		if (ent.movable)
		{
			if (m_type == MOUSE_MOUSE_OVER)
			{
				if (ent.movable == m_object->getMovable())
				{
					result = true;
					break;
				}
			}
			else
			{
				result = true;
				break;
			}
		}
	}
	return result;
}
Ejemplo n.º 2
0
CombatSystem::CombatSystem(EntitySystem& ents, Ogre::SceneManager& scene, GridSystem& grid)
	: entities_{ents}, ray_query_{*scene.createRayQuery(Ogre::Ray{})},
	  grid_{grid}, ray_caster_{scene}, run_away_queue_{}
{
	ray_query_.setSortByDistance(true);
	ray_query_.setQueryMask((int)ENTITY_TYPE::WALL || (int)ENTITY_TYPE::BUILDING);
}
Ejemplo n.º 3
0
void MainCamera::createRayQueries(Ogre::SceneManager& sceneManager)
{
	unsigned long queryMask = Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK;
	queryMask |= MousePicker::CM_AVATAR;
	queryMask |= MousePicker::CM_ENTITY;
	queryMask |= MousePicker::CM_NATURE;
	queryMask |= MousePicker::CM_UNDEFINED;
// 	queryMask |= Ogre::RSQ_FirstTerrain;

	mCameraRaySceneQuery = sceneManager.createRayQuery( Ogre::Ray(), queryMask);
	mCameraRaySceneQuery->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);
	mCameraRaySceneQuery->setSortByDistance(true);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
void MainCamera::createRayQueries(Ogre::SceneManager& sceneManager)
{
	mCameraRaySceneQuery = sceneManager.createRayQuery(Ogre::Ray(), 0);
	mCameraRaySceneQuery->setWorldFragmentType(Ogre::SceneQuery::WFT_SINGLE_INTERSECTION);
	mCameraRaySceneQuery->setSortByDistance(true);
}