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 ); }
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); } }
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; }
// 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; }
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)); } }
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 #################### }