Exemple #1
0
void Actor::ShowCertainBone(const Ogre::String& strBone)
{
	if (!_bShowBone)
	{
		return;
	}

	SkeletonInstance* pSkeletonInstance = _pBodyEntity->getSkeleton();

	if (!pSkeletonInstance)
	{
		return;
	}

	Bone* pBone = pSkeletonInstance->getBone(strBone);
	if (!pBone)
	{
		return;
	}

	if (_axesBoneTagPoint)
		_pBodyEntity->detachObjectFromBone(_axesBoneEntity);

	_axesBoneTagPoint = _pBodyEntity->attachObjectToBone(pBone->getName(), _axesBoneEntity);
	_axesBoneTagPoint->setScale(_scaleAxes, _scaleAxes, _scaleAxes);

	//OgreFramework::getSingleton().m_pLog->logMessage(strBone);
}
void AIHandlerBattleSphere::init()
{
	time = 0;

	hasTarget = false;
	guardPos = aiComp->object->position;
	desiredHeading = Vector3::NEGATIVE_UNIT_Z;
	angularVelocity = btVector3(0, 0, 0);

	fireDelay = 0;
	shotsUntilReload = BATTLE_SPHERE_SHOTS_UNTIL_RELOAD;

	// Get the physics component and disable deactivation on the rigid body
	ComponentPhysics* physComp;
	aiComp->object->sendGetMessage(COMPMSG_GET_PHYSICS_COMPONENT, &physComp);
	aiComp->rigidBody->setActivationState(DISABLE_DEACTIVATION);

	// Initialize class to find neighbours
	neighbours = new AIGetNeighbours(BATTLE_SPHERE_NEIGHBOUR_RADIUS, aiComp->object, OBJTAG_BULLET);

	// Initialize movement controller
	movementController = new AIMovementController(BATTLE_SPHERE_MAX_FORCE, BATTLE_SPHERE_MAX_SPEED, physComp, neighbours);
	movementController->setNoProgressTimeout(BATTLE_SPHERE_NO_PROGRESS_TIMEOUT);
	movementController->arriveDeceleration = BATTLE_SPHERE_ARRIVE_DECELERATION;
	movementController->weightArrive = BATTLE_SPHERE_WEIGHT_ARRIVE;
	movementController->weightWallAvoidance = BATTLE_SPHERE_WEIGHT_WALL_AVOIDANCE;
	movementController->weightSeparation = BATTLE_SPHERE_WEIGHT_SEPARATION;

	// Start with "guard" state
	stateMachine = new AIStateMachine<AIHandlerBattleSphere>(this);
	stateMachine->changeState(new AIStateBattleSphereGuard());

	// Initialize perception
	perception = new AIPerception(OBJTAG_AGENT, BATTLE_SPHERE_VIEW_RANGE, Degree(BATTLE_SPHERE_FIELD_OF_VIEW), BATTLE_SPHERE_MEMORY_SPAN, aiComp->object);
	perceptionTimer = new JitteredIntervalTimer(1.0f / 3.0f);
	
	// Check if the mesh has a "Fly" animation
	ComponentMesh* mesh = aiComp->object->mesh;
	if (mesh)
	{
		SkeletonInstance* sk = mesh->entity->getSkeleton();

		// Set all bones to "manually controlled"
		if (sk)
		{
			for (int b = 0; b < (int)sk->getNumBones(); ++b)
				sk->getBone(b)->setManuallyControlled(true);

			// TODO: move the hasAnim variable(s) into the template, initialize them upon creation of first instance
			hasAnimFly = sk->hasAnimation(animStringFly);
		}
	}
}
Exemple #3
0
void Actor::AddBoneVisualizer()
{
	SkeletonInstance* pSkeletonInstance = _pBodyEntity->getSkeleton();

	if (!pSkeletonInstance)
	{
		return;
	}

	Skeleton::BoneIterator it = pSkeletonInstance->getBoneIterator();
	while (it.hasMoreElements())
	{
		Bone* pBone = it.getNext();

		Bone::ChildNodeIterator cit = pBone->getChildIterator();
		int iCount = 0;
		while (cit.hasMoreElements())
		{
			Node* pChild = cit.getNext();
			iCount++;

			String strName = pBone->getName() + "_" + pChild->getName();
			Ogre::Entity* ent = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(strName, "bone.mesh");
			TagPoint* pTag	= _pBodyEntity->attachObjectToBone(pBone->getName(), ent);

			ent->setVisible(_bShowBone);

			_Entitys.push_back(ent);

			_BoneVisuals[pTag] = pChild;
		}

		if (iCount == 0)
		{
			Ogre::Entity* ent = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(pBone->getName(), "bone.mesh");
			TagPoint* pTag	= _pBodyEntity->attachObjectToBone(pBone->getName(), ent);

			ent->setVisible(_bShowBone);

			_Entitys.push_back(ent);

			_BoneVisuals[pTag] = 0;
		}
	}

	_UpdateBoneVisualizer();
}
void AIHandlerBattleSphere::logicUpdate()
{
	time += LOGIC_TIME_STEP;

	// Calculate the current view direction (for perception and for calculating the angularVelocity)
	btQuaternion btCurQuat = aiComp->rigidBody->getOrientation();
	Quaternion curQuat = Quaternion(btCurQuat.w(), btCurQuat.x(), btCurQuat.y(), btCurQuat.z());
	Vector3 curHeading = curQuat * Vector3::NEGATIVE_UNIT_Z;

	// Update neighbours
	neighbours->update(aiComp->object->position);

	// Update vision
	perception->updateTime(LOGIC_TIME_STEP);
	if (perceptionTimer->isReady(LOGIC_TIME_STEP))
	{
		perception->updateVision(curHeading);
		perception->updateNeighbours(neighbours);
		doTargetSelection();
		notifyNeighboursOfPerceptedAgents();
	}

	// Update firing variables
	fireDelay -= LOGIC_TIME_STEP;
	if (fireDelay < BATTLE_SPHERE_FIRE_DELAY - BATTLE_SPHERE_RELOAD_TIME)
		shotsUntilReload = BATTLE_SPHERE_SHOTS_UNTIL_RELOAD;

	// Update state machine
	stateMachine->update(LOGIC_TIME_STEP);

	// Update movement controller
	movementController->calculateVelocity(LOGIC_TIME_STEP);

	// Adjust the heading if the agent is moving
	if (movementController->velocity.squaredLength() > MOVING_THRESHOLD)
		desiredHeading = movementController->velocity.normalisedCopy();

	// Calculate the angularVelocity for the heading
	Quaternion destQuat = curHeading.getRotationTo(desiredHeading, Vector3::UNIT_Y);
	float destYaw = destQuat.getYaw(true).valueDegrees();
	float destPitch = destQuat.getPitch(true).valueDegrees();
	float destRoll = destQuat.getRoll(true).valueDegrees();

	angularVelocity = btVector3(destPitch / 20, destYaw / 20, destRoll / 20);

	// Update velocities
	posUpdate(0);
	
	// Update animation
	ComponentMesh* mesh = aiComp->object->mesh;
	if (hasAnimFly && mesh)
	{
		SkeletonInstance* sk = mesh->entity->getSkeleton();
		if (sk)
		{
			sk->reset(true);
	
			Animation* anim = sk->getAnimation(animStringFly);
			anim->apply(sk, time);
		}
	}
}