Ejemplo n.º 1
0
void AnimCtrlPlayerCharacter::updateAimRotation(Ogre::Radian angleHorizontal, Ogre::Radian angleVertical, unsigned long timeSinceLastFrame)
{
	// This is freaking important! Must be in seconds and an Ogre::Real
	Ogre::Real secSinceLastFrame = (Ogre::Real) timeSinceLastFrame / 1000.f;

	// Set manual frame position
	// ---------------------------------------
	
	float prevValue = animPipeline->getAnimManualTimePos(	"aim" );
	float maxValue = animPipeline->getAnimLength(			"aim" );

	float aimFrame = interpolateAiming( angleHorizontal.valueDegrees(), 360.f, prevValue, maxValue, 3500.f, secSinceLastFrame );

	animPipeline->setAnimManualTimePos( "aim",		aimFrame );
	animPipeline->setAnimManualTimePos( "aimUp",	aimFrame );
	animPipeline->setAnimManualTimePos( "aimDown",	aimFrame );

	// Set blend value
	// ---------------------------------------

	// Modify Angle; animated only from 45° (up) to -45° (down)
	float aimBlend = angleVertical.valueDegrees() - 45.f;
	aimBlend = std::max( 0.f, aimBlend );
	aimBlend = std::min( 90.f, aimBlend );

	prevValue = getFlagValue( "aim_vertical2", 0 ) +
				getFlagValue( "aim_vertical3", 0 );

	aimBlend = interpolateAiming( aimBlend, 90.f, prevValue, 2.f, 2000.f, secSinceLastFrame );

	// Split up blend value from 0 to 1 into three blend values for the LERP tree
	float aimBlendTrees	= (aimBlend > 1.f) ? 1.f : 0.f;			setFlagValue( "aim_vertical1", aimBlendTrees );
	float aimBlend2		= std::min( 1.f, aimBlend );			setFlagValue( "aim_vertical2", aimBlend2 );
	float aimBlend3		= std::max( 1.f, aimBlend ) - 1.f;		setFlagValue( "aim_vertical3", aimBlend3 );
}
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());
}
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());
}
Ejemplo n.º 4
0
			inline void moveCamera() {
				camera_->rotate(AngleVector(-rotY_.valueDegrees(), rotX_.valueDegrees(), 0.0));
				
				camera_->translate(camera_->getOrientation().yawOrientation * translateVector_);
				
				const double maxPitch = 60.0;
				
				AngleVector rotation = camera_->getRotation();
				const double pitch = rotation.pitch;
				
				// Limit the pitch.
				if(fabs(pitch) > maxPitch) {
					rotation.pitch = (pitch > 0.0) ? maxPitch : -maxPitch;
					camera_->setRotation(rotation);
				}
			}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
// Returns volume for the right ear.
// If the sound is directly to the right, that channel gets 254 of intensity.
// If the sound is directly in front of us, each channel gets 254/2 of intensity.
int SoundManager::calcPanning(Ogre::Camera* mCamera, Ogre::Vector3 soundPosition) {
    Ogre::Vector3 camDirection = mCamera->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
    Ogre::Vector3 soundDir = soundPosition - mCamera->getPosition();
    soundDir.normalise();
    // Retrieve the angle made between the sound position and the camera's direction,
    // which should be pointing forwards.
    Ogre::Quaternion q = camDirection.getRotationTo(soundDir);
    Ogre::Radian radians = q.getYaw();

    // anything left of the camera returns positive degrees
    float degrees = radians.valueDegrees();

    int leftIntensity;
    int rightIntensity;

    // from 0 to -179 it's the right ear.
    if(degrees <= 0) {
      //std::cout << "degrees " << degrees << std::endl;
      degrees *= -1;
      if(degrees > 90)
          degrees = 90 - (degrees - 90); // if 91, we subtract 1 and go back to 89
      // Intensity can never be 255 because then the effect cancels out.
      int intensity = (degrees / 90.0) * 254/2 + 254/2;
      //std::cout << "intensity " << intensity << std::endl;
      rightIntensity = intensity;
      leftIntensity = 255 - (rightIntensity);
    }
    // from 0 to 179 it's the left ear.
    else {
      if(degrees > 90)
          degrees = 90 - (degrees - 90); 
      int intensity = (degrees / 90) * 254/2 + 254/2;
      //std::cout << "intensity " << intensity << std::endl;
      leftIntensity = intensity;
      rightIntensity = 254 - (leftIntensity);
    }
    return rightIntensity;
}
Ejemplo n.º 9
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);
	}
Ejemplo n.º 10
0
Ogre::Vector3 LuaScriptUtilities::QuaternionToRotationDegrees(
    const Ogre::Quaternion& quaternion)
{
    Ogre::Vector3 angles;

    Ogre::Radian xAngle;
    Ogre::Radian yAngle;
    Ogre::Radian zAngle;

    Ogre::Matrix3 rotation;
    quaternion.ToRotationMatrix(rotation);
    rotation.ToEulerAnglesXYZ(xAngle, yAngle, zAngle);

    angles.x = xAngle.valueDegrees();
    angles.y = yAngle.valueDegrees();
    angles.z = zAngle.valueDegrees();

    return angles;
}
Ejemplo n.º 11
0
 static float sgn(Ogre::Radian a)
 {
     if(a.valueRadians() > 0)
         return 1.0;
     return -1.0;
 }
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
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));
	}
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
void OGRERendererRacer::update() {

    mpVehicle = mpApp->mRacer;

    const cml::vector3d& pos = mpVehicle->mPos;

    mVehicleNode->setPosition(pos[0], pos[1], pos[2]);

    Ogre::Quaternion q;

    const quat& orientation = mpVehicle->getOrientation();

    q.w = orientation.as_vector()[0];
    q.x = orientation.as_vector()[1];
    q.y = orientation.as_vector()[2];
    q.z = orientation.as_vector()[3];

    if (q != mOrientation) {

        Ogre::Quaternion transition = q * mOrientation.Inverse();

        Ogre::Radian a;
        Ogre::Vector3 v;

        transition.ToAngleAxis(a, v);

        if (a.valueDegrees() > 0.1) {

            Ogre::Quaternion t2;

            // TODO 3: Make rotation speed configurable
            t2.FromAngleAxis(a * 0.05, v);

            mOrientation = t2 * mOrientation;
        } else {
            mOrientation = q;
        }
    }

    //################# BEGIN Construct Sideward thrust roll quaternion ################

//	cml::vector3f velDirSidewardComponent = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity) * mpVehicle->mDirLeft;

    if (mpVehicle->mAddThrustLeft || mpVehicle->mAddThrustRight) {
        mRollAngle = -mpVehicle->mThrustSideward * 500;
    } else {
        mRollAngle *= 0.98;
    }

    float dot = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity);
    mRollAngle = -dot * 50;

    Ogre::Quaternion qSidewardThrustRoll(Ogre::Degree(mRollAngle), Ogre::Vector3(0, 0, -1));

    cml::vector3f g = mpVehicle->getGravity();

    cml::vector3f velDirGravityComponent = cml::dot(g, mpVehicle->mVelocity) * g;

    dot = cml::dot(velDirGravityComponent, g);

    if (velDirGravityComponent.length() > 0.000001) {
        mPitchAngle = -cml::sign(dot) * velDirGravityComponent.length() * 500000;
    } else {

        if (mpVehicle->mAddThrustForward && mPitchAngle > -7) {
            mPitchAngle -= 0.1;
        } else {
            mPitchAngle *= 0.95;
        }
    }

    Ogre::Quaternion qForwardThrustPitch(Ogre::Degree(mPitchAngle), Ogre::Vector3(1, 0, 0));

    //################# END Construct Sideward thrust roll quaternion ################

    bool mSidewardThrustRollCamera = false;

    if (mSidewardThrustRollCamera) {
        // Roll both vehicle and camera:
        mVehicleNode->setOrientation(q * qSidewardThrustRoll * qForwardThrustPitch);
    } else {
        // Roll only the vehicle, not the camera:
        mVehicleNode->setOrientation(mOrientation);
        mVehicleMeshNode->setOrientation(qSidewardThrustRoll * qForwardThrustPitch);
    }

    //############# BEGIN Update engine particle emitters ####################

    // TODO 1: Reimplement

    bool emit = (mpVehicle->mGameState == 0) && mpVehicle->mThrustForward > 0;

    mEngineFlameParticleSystem->setEmitting(emit);
    mEngineSmokeParticleSystem->setEmitting(emit);

    Ogre::ParticleEmitter* emitter = mEngineFlameParticleSystem->getEmitter(0);
    emitter->setParticleVelocity(mpVehicle->mThrustForward * 6000);
    emitter->setEmissionRate(mpVehicle->mThrustForward * 10000);

    emitter = mEngineSmokeParticleSystem->getEmitter(0);
    emitter->setEmissionRate(mpVehicle->mThrustForward * 7000);

    //############# END Update engine particle emitters ####################
}