コード例 #1
0
VEHA::RotationVector OgrePointSpecification::getLocalRotation() const
{
	Ogre::Quaternion q=_node->getOrientation();
	Ogre::Vector3 v;
	Ogre::Radian a;
	q.ToAngleAxis(a,v);
	return VEHA::RotationVector((double)v.x,(double)v.y,(double)v.z,(double)a.valueRadians());
}
コード例 #2
0
void GameObject::yaw(const Ogre::Radian radians)
{
    if (node)
        node->yaw(radians);
    btTransform t = body->getCenterOfMassTransform();
    t.setRotation(btQuaternion(0, 1, 0, radians.valueRadians()));
    body->setCenterOfMassTransform(t);
}
コード例 #3
0
void Character::yaw(const Ogre::Radian radians)
{
  if (node)
      node->yaw(radians);
  btTransform t = body->getCenterOfMassTransform();
  t.setRotation(btQuaternion(0, 1, 0, radians.valueRadians()));
  body->setCenterOfMassTransform(t);
  changes = changes | (1 << ROTATION_CHANGE);
}
コード例 #4
0
VEHA::RotationVector OgrePointSpecification::getGlobalRotation() const
{
	Ogre::Quaternion q=_node->getOrientation();
	if(_parent)
		q=shared_dynamic_cast<OgrePointSpecification>(_parent)->_node->convertLocalToWorldOrientation(q);
	Ogre::Vector3 v;
	Ogre::Radian a;
	q.ToAngleAxis(a,v);
	return VEHA::RotationVector((double)v.x,(double)v.y,(double)v.z,(double)a.valueRadians());
}
コード例 #5
0
ファイル: gkSteering.cpp プロジェクト: Ali-il/gamekit
gkRadian gkSteering::getAngle(const gkVector3& from, const gkVector3& to)
{
	Ogre::Vector3 from1 = getProjectionOnPlane(from, m_steerAxis);

	Ogre::Vector3 to1 = getProjectionOnPlane(to, m_steerAxis);

	Ogre::Quaternion q = from1.getRotationTo(to1);

	Ogre::Radian angle;
	Ogre::Vector3 rAxis;

	q.ToAngleAxis(angle, rAxis);

	rAxis = angle.valueRadians() * (rAxis * m_steerAxis);

	angle = rAxis.x + rAxis.y + rAxis.z;

	return angle;
}
コード例 #6
0
	void CCameraFeedbackNotifier::calculateEnemyPosition(Vector3 vPosEnemy) { 
		//Obtengo la posición del enemigo
		Ogre::Vector3 vEnemyPos = vPosEnemy;
		//Obtengo mi posición (entidad a la que han dañado)
		Ogre::Vector3 vMyPos = this->_entity->getPosition();

		//Obtengo el vector en el que estoy mirando, y me quedo sólo en el plano horizontal (quitando la altura)
		Vector3 vMyDirVision = _entity->getOrientation()*Vector3::NEGATIVE_UNIT_Z;
		vMyDirVision = Vector3(vMyDirVision.x,0,vMyDirVision.z);
		//Obtengo el vector desde el enemigo a mi posición; y me quedo sólo con el plano horizontal (quitando la altura)
		Vector3 vEnemyDirVision = vPosEnemy - vMyPos;
		vEnemyDirVision = Vector3(vEnemyDirVision.x, 0, vEnemyDirVision.z);

		//Ángulo entre ambos vectores
		Ogre::Radian rad = vMyDirVision.angleBetween(vEnemyDirVision);
		//Convierto los radianes a float porque en el mensaje mando float
		float fRadianes = (float)rad.valueRadians();

		//Cambio de sistema de coordenadas para tener la posición del enemigo respecto 
		//al jugador. Antonio el crack matemático! ^^
		Matrix4 mat;
		mat.makeTransform(_entity->getPosition(),Vector3::UNIT_SCALE,_entity->getOrientation());
		mat.inverse();
		Vector3 vec = mat * vPosEnemy; //este vector es la posicion del enemigo respecto a mi
		if (vec.x > 0) 
		{
			//El enemigo está a la derecha, así que tengo que multiplicar
			//por -1 para que se oriente bien la flecha de daño
			fRadianes *= -1.0f;
		}

		//Mando el mensaje
		std::shared_ptr<Logic::CMessageImpact> impact = std::make_shared<Logic::CMessageImpact>();
		impact->setDirectionImpact(fRadianes);							 
		_entity->emitMessage(impact);
	}
コード例 #7
0
ファイル: pathfinding.hpp プロジェクト: 0xmono/openmw
 static float sgn(Ogre::Radian a)
 {
     if(a.valueRadians() > 0)
         return 1.0;
     return -1.0;
 }
コード例 #8
0
ファイル: FieldPlayer.cpp プロジェクト: LiuJack/FootballAI
void FieldPlayer::onUpdate(double time_diff)
{
	this->mIsUpdatingAfterChange = (time_diff == 0);

	mStateMachine->onUpdate();

	// Update here
	mSteeringBehaviors->calculateDrivingForce();

	// Apply a small rotation 
	Ogre::Quaternion rotation = getRotation();
	Ogre::Vector3 current_velocity = getVelocity();
	Ogre::Vector3 current_heading = rotation * Ogre::Vector3(0, 0, 1);

	float velocity_magnitude = current_velocity.length();
	Ogre::Vector3 driving_force = mSteeringBehaviors->getSteeringForce();


	btTransform trans = mPhysicsBody->getRigidBody()->getWorldTransform();
	btMotionState* motion = mPhysicsBody->getRigidBody()->getMotionState();

	if (driving_force.length() > EPS)
	{
		Ogre::Radian angle = current_heading.getRotationTo(driving_force).getYaw();

		if (angle > Ogre::Radian(mTurnRate))
			angle = Ogre::Radian(mTurnRate);

		if (angle < Ogre::Radian(-mTurnRate))
			angle = Ogre::Radian(-mTurnRate);

		float accumulate_force = current_heading.dotProduct(driving_force);

		// If at the same line
		if (fabs(angle.valueRadians()) < 1e-3 && accumulate_force < 0)
			angle = mTurnRate;

        rotation = rotation * Ogre::Quaternion(angle, Ogre::Vector3(0, 1, 0));

		trans.setRotation(BtOgre::Convert::toBullet(rotation));

		velocity_magnitude += accumulate_force;
		
		if (velocity_magnitude < 0)
			velocity_magnitude = 0;
	} 
	else 
	{
		velocity_magnitude *= 0.8;
	}

	// Is at target
	if (mIsTurnningAroundAtTarget != Ogre::Radian(0))
	{
		rotation = rotation * Ogre::Quaternion(mIsTurnningAroundAtTarget, Ogre::Vector3(0, 1, 0));
		trans.setRotation(BtOgre::Convert::toBullet(rotation));
	}

	if (velocity_magnitude > mMaxSpeed)
		velocity_magnitude = mMaxSpeed;

	// About animation
	if (velocity_magnitude < 1e-6)
		mMesh->stopAnimation();
	else
		mMesh->playAnimation();

	// Set velocity 
	mVelocity = rotation * Ogre::Vector3(0, 0, velocity_magnitude);

	trans.setOrigin(trans.getOrigin() + BtOgre::Convert::toBullet(mVelocity) * 0.02);
	motion->setWorldTransform(trans);

	mIsTurnningAroundAtTarget = Ogre::Radian(0);

	setDebugText(getStateMachine()->getNameOfCurrentState());
	//setDebugText(dt::Utils::toString(getSteering()->getTarget()));
	//DEBUG_MODE_BEGIN
	//setDebugText(dt::Utils::toString(getSteering()->getSteeringForce()));
	//DEBUG_MODE_END

	dt::Node::onUpdate(time_diff);
}
コード例 #9
0
ファイル: Turret.cpp プロジェクト: Senchy/RWM_Solo_Final
void Turret::Update()
{
	
	bool PlayerInRoom = false;
	DynamicObject::Update();
	hkpWorldRayCastOutput	OutPut;
	hkpWorldRayCastInput	Ray;
	Player* theplayer = 0;
	Ogre::Vector3 RayDirection = (mPlayerPos - mPosition).normalisedCopy();
	Ray.m_from = hkVector4(mPosition.x + (RayDirection.x * 25)
						,mPosition.y + (RayDirection.y * 25)
						,mPosition.z + (RayDirection.z * 25));
    Ray.m_to = hkVector4(mPlayerPos.x, mPlayerPos.y, mPlayerPos.z);
	mPhysicsManager->GetPhysicsWorld()->castRay(Ray,OutPut);
	if(OutPut.hasHit())
	{
		const hkpCollidable* col = OutPut.m_rootCollidable;
		hkpRigidBody* body = hkpGetRigidBody(col);
		theplayer = dynamic_cast<Player*> ((BaseObject *)body->getUserData());
		if(theplayer != 0)
		{
			PlayerInRoom = true;
		}
		else
		{
			mPlayerInSight = false;
			mKillTimer = 0;
		}
	}
	Ogre::Vector3 NewDir = Ogre::Vector3(RayDirection.x,0,RayDirection.z);
	NewDir.normalise();
	Ogre::Radian angle = NewDir.angleBetween(ObjectNode->getOrientation() * Ogre::Vector3::UNIT_X);
	if(PlayerInRoom || !mPlayerInSight)
	{
		if(angle.valueDegrees() < 20 || angle.valueDegrees() > -20)
		{
			mPlayerInSight = true;
		}
	}
	if(mPlayerInSight)
	{
		mRotateValue += angle.valueRadians();
		Body->setRotation(hkQuaternion(hkVector4(0,1,0),mRotateValue));
		mKillTimer++;
		if(mKillTimer > 800)
		{
			mShutdown = true;
			//theplayer->OnDeath();
		}
	}
	else
	{
		if(mRotateValue < -2)
		{
			mChangeInRotation = 0.001;
		}
		else if (mRotateValue > 2)
		{
			mChangeInRotation = -0.001;
		}
		mRotateValue += mChangeInRotation;
		Body->setRotation(hkQuaternion(hkVector4(0,1,0),mRotateValue));
	}
}
コード例 #10
0
bool
    GraphicsController::onUpdate(const Ogre::Real dt)
{
    using namespace Ogre;

    //pass int he Skylight SH coefficients
    //Compute theta and phi and get turbulence
    Vector3 xyz;

    Ogre::Quaternion quat(Ogre::Radian(_radianOffset * dt), Ogre::Vector3::UNIT_Z) ;
    _lightDir = quat * _lightDir;
    _lightDir.normalise();
    xyz = -_lightDir;


    Ogre::Radian theta = Math::ACos(xyz.y);
    Ogre::Radian phi = Math::ATan2(xyz.x, xyz.z);

    const Ogre::String shr("SHC_R_");
    const Ogre::String shg("SHC_G_");
    const Ogre::String shb("SHC_B_");

    //was 4.5
    Real turbulence = 3.0;

	Real ltDist = 500.0;
    if(xyz.y >= 0.0f)
    {
		light->setDirection(-xyz);

		CalculatePreethamSH(theta.valueRadians(),phi.valueRadians(),turbulence, NUM_OF_BANDS, true, _SHC_R, _SHC_G, _SHC_B, 1.0f);
        //CalculateSunSH(theta.valueRadians(), phi.valueRadians(), turbulence, NUM_OF_BANDS, _SHC_R, _SHC_G, _SHC_B, 1.0f);

		Ogre::MaterialPtr matPtr = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("PRJZ/DirectionLightBuffer"));
		Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);

		const Ogre::Matrix4& viewMat = _cam->getViewMatrix(true);
		Ogre::Vector4 xyz4(xyz.x, xyz.y, xyz.z, 0.0f);

		xyz4 = viewMat * xyz4;
		
		if(pass->getVertexProgramParameters()->_findNamedConstantDefinition("dirLightWorld"))
			pass->getVertexProgramParameters()->setNamedConstant("dirLightWorld", xyz4);

    }
    else
    {
        Ogre::Vector3 moonxyz = xyz * -1;

		light->setDirection(-moonxyz);

		Ogre::Radian theta = Math::ACos(moonxyz.y);
        Ogre::Radian phi = Math::ATan2(moonxyz.x, moonxyz.z);

        CalculatePreethamSH(theta.valueRadians(),phi.valueRadians(),turbulence, NUM_OF_BANDS, true, _SHC_R, _SHC_G, _SHC_B, 1.0f);
        //CalculateSunSH(theta.valueRadians(), phi.valueRadians(), turbulence, NUM_OF_BANDS, _SHC_R, _SHC_G, _SHC_B, 1.0f);

		const Ogre::Matrix4& viewMat = _cam->getViewMatrix(true);
		Ogre::Vector4 xyz4(moonxyz.x, moonxyz.y, moonxyz.z, 0.0f);

		xyz4 = viewMat * xyz4;
		
		Ogre::MaterialPtr matPtr = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("PRJZ/DirectionLightBuffer"));
		Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);
		if(pass->getVertexProgramParameters()->_findNamedConstantDefinition("dirLightWorld"))
			pass->getVertexProgramParameters()->setNamedConstant("dirLightWorld", xyz4);

    }

    std::vector<Ogre::String> materialNames;
    materialNames.push_back("PRJZ/Minecraft");
    materialNames.push_back("PRJZ/MinecraftCharacter");
	materialNames.push_back("PRJZ/Minecraft2");
    materialNames.push_back("preview_diffusenormalspecular");
	materialNames.push_back("preview2_diffusenormalspecular");
	materialNames.push_back("preview3_diffusenormalspecular");
	materialNames.push_back("preview_cubemap");
	materialNames.push_back("PRJZ/HWBasic");

	size_t idx = 0;

#define FULL_BAND 1
    for(size_t i=0; i < 9; ++i)
    {
        String namer = shr+StringConverter::toString(idx);
        String nameg = shg+StringConverter::toString(idx);
        String nameb = shb+StringConverter::toString(idx);

        _setSHParameterMultipleMaterials(i, namer, nameg, nameb, materialNames);
        idx++;
    }

#if FULL_BAND
        //Skip band 4th band (or 3rd degree).
        for(size_t i=16; i < 25; ++i)
        {
            String namer = shr+StringConverter::toString(idx);
            String nameg = shg+StringConverter::toString(idx);
            String nameb = shb+StringConverter::toString(idx);
            _setSHParameterMultipleMaterials(i, namer, nameg, nameb, materialNames);
            idx++;
        }
#endif

		materialNames.push_back("PRJZ/DirectionLightBuffer");

		for(const Ogre::String &materialName : materialNames)
        //for(auto iter = materialNames.cbegin(); iter != materialNames.cend(); ++iter)
        {
              Ogre::MaterialPtr matPtr = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName));
              Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);
              if(pass->getFragmentProgramParameters()->_findNamedConstantDefinition("uLightY"))
                pass->getFragmentProgramParameters()->setNamedConstant("uLightY", xyz.y);
        }

    return true;
}