private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (!mParticleSystem.HasActiveParticles) { Owner.Despawn(); } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { Quaternion rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(mAngularVelocity * e.GameTime.ElapsedGameTime.TotalSeconds)); mTransform.Orientation = rotation * mTransform.Orientation; mTransform.Orientation.Normalize(); }
private void PostPhysicsUpdateHandler(object sender, UpdateStepEventArgs e) { Value += (float)(e.GameTime.ElapsedGameTime.TotalSeconds) * RegenerationRate; if (Value > 1.0f) { Value = 1.0f; } }
private void UpdateCompleteHandler(object sender, UpdateStepEventArgs e) { // If there are any particles waiting in the newly added queue, // we'd better upload them to the GPU ready for drawing. if (mFirstNewParticleIndex != mParticleData.FirstFreeParticleIndex) { AddNewParticlesToVertexBuffer(); } }
private void DespawnStepHandler(object sender, UpdateStepEventArgs e) { OnActorDespawning(EventArgs.Empty); foreach (ActorComponent component in mComponents.Values) { component.Release(); } GameResources.ActorManager.DespawnStep -= DespawnStepHandler; }
// Looks at DesiredMovementState and movement values and conveys the appropiate state to the animation controller. // Also commits the Controller movement and orientation input values. private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { CommitOrientationAndMovement(); if (mState != ControllerState.InputDisabled) { if (mAnimationStateMachine != null) { if (Controller.SupportFinder.HasSupport) { Vector2 horizontalMovement = BepuConverter.Convert(Controller.HorizontalMotionConstraint.MovementDirection) * Controller.HorizontalMotionConstraint.SpeedScale; if ((DesiredMovementActions & MovementActions.Jumping) > 0) { mAnimationStateMachine.DesiredStateName = JUMPING_SN; } else if (DesiredMovementActions.HasFlag(MovementActions.Boosting) && mState == ControllerState.Neutral && mBooster != null && mBooster.BoostReady) { mAnimationStateMachine.DesiredStateName = BOOSTING_SN; } else if ((DesiredMovementActions & MovementActions.Crouching) > 0) { if (horizontalMovement.LengthSquared() > 0.0f) { mAnimationStateMachine.HorizontalMovement = horizontalMovement; mAnimationStateMachine.DesiredStateName = CROUCHMOVING_SN; } else { mAnimationStateMachine.DesiredStateName = CROUCHING_SN; } } else if (horizontalMovement.LengthSquared() > 0.0f) { mAnimationStateMachine.HorizontalMovement = horizontalMovement; mAnimationStateMachine.DesiredStateName = MOVING_SN; } else { mAnimationStateMachine.DesiredStateName = STANDING_SN; } } else { mAnimationStateMachine.DesiredStateName = FALLING_SN; } } } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (mBipedControl.State == BipedControllerComponent.ControllerState.Boosting && mBoostTime < MinDuration) { // Keep boost on. mBipedControl.DesiredMovementActions |= BipedControllerComponent.MovementActions.Boosting; } else if (BoostTimeRemaining <= 0.0f) { // Force boost off. mBipedControl.DesiredMovementActions &= ~BipedControllerComponent.MovementActions.Boosting; } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (mTargetActorId == Actor.INVALID_ACTOR_ID) { if (!mParticleSystem.HasActiveParticles) { Owner.Despawn(); } return; } // Work out how much time has passed since the previous update. float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds); Vector3 newPosition = GetPosition(); if (elapsedTime > 0) { // Work out how fast we are moving. Vector3 velocity = (newPosition - mPreviousPosition) / elapsedTime; // If we had any time left over that we didn't use during the // previous update, add that to the current elapsed time. float timeToSpend = mTimeLeftOver + elapsedTime; // Counter for looping over the time interval. float currentTime = -mTimeLeftOver; // Create particles as long as we have a big enough time interval. while (timeToSpend > mTimeBetweenParticles) { currentTime += mTimeBetweenParticles; timeToSpend -= mTimeBetweenParticles; // Work out the optimal position for this particle. This will produce // evenly spaced particles regardless of the object speed, particle // creation frequency, or game update rate. float mu = currentTime / elapsedTime; Vector3 position = Vector3.Lerp(mPreviousPosition, newPosition, mu); // Create the particle. mParticleSystem.AddParticle(position, velocity); } // Store any time we didn't use, so it can be part of the next update. mTimeLeftOver = timeToSpend; } mPreviousPosition = newPosition; }
private void PostPhysicsUpdateHandler(object sender, UpdateStepEventArgs e) { float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds); if (mBipedControl.State == BipedControllerComponent.ControllerState.Boosting) { mBoostTime += elapsedTime; BoostTimeRemaining -= elapsedTime; } else if (BoostTimeRemaining < MaxDuration) { BoostTimeRemaining += elapsedTime; } }
// Checks the animation state for control events and passes them on to the Controller. private void PostAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (mAnimationStateMachine != null) { if (mAnimationStateMachine.CurrentState.Name == CROUCHING_SN || mAnimationStateMachine.CurrentState.Name == CROUCHMOVING_SN) { Controller.StanceManager.DesiredStance = Stance.Crouching; } else { Controller.StanceManager.DesiredStance = Stance.Standing; } if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Jump)) { Controller.Jump(); } if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Boost)) { OnStateChanged(ControllerState.Boosting); } } else // Just let the events happen immediately: { if (Controller.SupportFinder.HasSupport) { if ((DesiredMovementActions & MovementActions.Jumping) > 0) { Controller.Jump(); } if (DesiredMovementActions.HasFlag(MovementActions.Boosting) && mState == ControllerState.Neutral && mBooster != null && mBooster.BoostReady) { OnStateChanged(ControllerState.Boosting); } } } if (mState == ControllerState.Boosting && !(DesiredMovementActions.HasFlag(MovementActions.Boosting))) { OnStateChanged(ControllerState.Neutral); } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mTimeAlive += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); float lifeMeasure = mTimeAlive * mSpeed; if (lifeMeasure > 335.0f) { Owner.Despawn(); } else if (lifeMeasure > 285.0f) { TransformComponent tc = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); tc.Scale = MathHelper.Lerp(mOrigScale, 0.01f, (lifeMeasure - 285.0f) / 50.0f); } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mTimeAlive += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); float lifeMeasure = mTimeAlive * mSpeed; if (lifeMeasure > 435.0f) { Owner.Despawn(); } else if (lifeMeasure > 285.0f) { DynamicCollisionComponent collisionComponent = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics); collisionComponent.Entity.IsAffectedByGravity = true; } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mCurrentTime += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); RetireActiveParticles(); FreeRetiredParticles(); // If we let our timer go on increasing for ever, it would eventually // run out of floating point precision, at which point the particles // would render incorrectly. An easy way to prevent this is to notice // that the time value doesn't matter when no particles are being drawn, // so we can reset it back to zero any time the active queue is empty. if (mParticleData.FirstActiveParticleIndex == mParticleData.FirstFreeParticleIndex) { mCurrentTime = 0; } if (mFirstRetiredParticleIndex == mParticleData.FirstActiveParticleIndex) { mDrawCounter = 0; } }
public void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { // Make a copy of the master window list, to avoid confusion if // the process of updating one window adds or removes others. mWindowsToUpdate.Clear(); foreach (UIWindow window in mWindows) { mWindowsToUpdate.Add(window); } // These flags are initialized for the topmost window: bool coveredByOtherWindow = false; bool isCoveringUnderlyingWindows = false; // Loop as long as there are screens waiting to be updated. while (mWindowsToUpdate.Count > 0) { // Pop the topmost screen off the waiting list. UIWindow window = mWindowsToUpdate[mWindowsToUpdate.Count - 1]; mWindowsToUpdate.RemoveAt(mWindowsToUpdate.Count - 1); if (window.WindowState == ScreenState.TransitionOn || window.WindowState == ScreenState.Active) { // If this is an active non-popup, inform any subsequent // windows that they are covered by it. isCoveringUnderlyingWindows = !window.IsPopup; } // Update the screen. window.Update(e.GameTime, coveredByOtherWindow); // Update flags for next screen: coveredByOtherWindow |= isCoveringUnderlyingWindows; } }
private void AnimationUpdateHandler(object sender, UpdateStepEventArgs e) { AnimationStateMachine.Update(e.GameTime); }
public void ImpactHandler(object sender, UpdateStepEventArgs e) { GameResources.ActorManager.PostPhysicsUpdateStep -= ImpactHandler; // TODO: P2: Some boooom sound effects... TransformComponent myXForm = Owner.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); // Do a sphere cast to get actors in the blast radius List <RayCastResult> inRangeActors = new List <RayCastResult>(); SphereShape blastZone = new SphereShape(mBlastRadius); RigidTransform blastPosition = new RigidTransform(BepuConverter.Convert(myXForm.Translation)); BEPUutilities.Vector3 bepuZero = BEPUutilities.Vector3.Zero; GameResources.ActorManager.SimSpace.ConvexCast(blastZone, ref blastPosition, ref bepuZero, inRangeActors); RayCastDistanceComparer rcdc = new RayCastDistanceComparer(); for (int a = 0; a < inRangeActors.Count; ++a) { EntityCollidable inRangeEntityCollidable = inRangeActors[a].HitObject as EntityCollidable; if (inRangeEntityCollidable != null && inRangeEntityCollidable.Entity != null && inRangeEntityCollidable.Entity.Tag != null) { Actor blastedActor = GameResources.ActorManager.GetActorById((int)(inRangeEntityCollidable.Entity.Tag)); IDamagable actorDamage = blastedActor.GetBehaviorThatImplementsType <IDamagable>(); DynamicCollisionComponent actorCollidable = blastedActor.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics); BepuVec3 blastToActorCenter = actorCollidable.Entity.Position - blastPosition.Position; BepuRay loeRay = new BepuRay(blastPosition.Position, blastToActorCenter); bool hasCover = false; float distance = mBlastRadius; if (actorDamage != null || (actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver)))) { List <RayCastResult> loeResults = new List <RayCastResult>(); GameResources.ActorManager.SimSpace.RayCast(loeRay, mBlastRadius, loeResults); loeResults.Sort(rcdc); for (int c = 0; c < loeResults.Count; ++c) { EntityCollidable possibleCover = loeResults[c].HitObject as EntityCollidable; if (possibleCover != null && possibleCover.Entity == inRangeEntityCollidable.Entity) { // Hit distance = loeResults[c].HitData.T; break; } Terrain possibleCoverTerrain = loeResults[c].HitObject as Terrain; if (possibleCoverTerrain != null) { hasCover = true; break; } if (possibleCover != null && possibleCover.Entity != null && !possibleCover.Entity.IsDynamic) { hasCover = true; break; } } } if (!hasCover && actorDamage != null) { actorDamage.TakeDamage((int)(MathHelper.Lerp(1.0f, 0.25f, distance / mBlastRadius) * mDamage)); } if (!hasCover && actorCollidable != null && actorCollidable.IsDynamic && !(actorCollidable.Entity.CollisionInformation.CollisionRules.Personal.HasFlag(BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver))) { blastToActorCenter.Normalize(); blastToActorCenter = blastToActorCenter * 1200; // Math.Min(5000.0f / (distance + 1.0f)); actorCollidable.Entity.ApplyLinearImpulse(ref blastToActorCenter); if (!actorCollidable.Entity.ActivityInformation.IsActive) { actorCollidable.Entity.ActivityInformation.Activate(); } } } } DynamicCollisionComponent dcc = Owner.GetComponent <DynamicCollisionComponent>(ActorComponent.ComponentType.Physics); Vector3 myVelocity = BepuConverter.Convert(dcc.Entity.LinearVelocity); Actor fireball = GameResources.ActorManager.SpawnTemplate("ExplosionFire"); TransformComponent fireXForm = fireball.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); fireXForm.Translation = myXForm.Translation; ExplosionFire fireBehavior = fireball.GetBehavior <ExplosionFire>(); fireBehavior.Emit(myVelocity); Actor smoke = GameResources.ActorManager.SpawnTemplate("ExplosionSmoke"); TransformComponent smokeXForm = smoke.GetComponent <TransformComponent>(ActorComponent.ComponentType.Transform); smokeXForm.Translation = myXForm.Translation; ExplosionSmoke smokeBehavior = smoke.GetBehavior <ExplosionSmoke>(); smokeBehavior.Emit(myVelocity); Owner.Despawn(); }
public void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mController.Update((float)(e.GameTime.ElapsedGameTime.TotalSeconds)); mTransformComponent.Transform = mController.Transform; }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds); Actor avatar = GameResources.ActorManager.GetActorById(ActorId); BipedControllerComponent bipedControl = avatar.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); // Update the camera. Vector3 desiredCameraPosition; if (mInputMode == InputMode.Aloof) { Matrix cameraRotation = Matrix.CreateFromYawPitchRoll(mMmoCameraDesc.Yaw, mMmoCameraDesc.Pitch, 0.0f); BepuRay boomRay = new BepuRay(mAvatarBepuEntity.Position, BepuConverter.Convert(cameraRotation.Backward)); RayCastResult result; GameResources.ActorManager.SimSpace.RayCast(boomRay, mMmoCameraDesc.Distance, CameraClipFilter, out result); desiredCameraPosition = result.HitObject != null? BepuConverter.Convert(BEPUutilities.Vector3.Lerp(result.HitData.Location, mAvatarBepuEntity.Position, 0.05f)) : BepuConverter.Convert(mAvatarBepuEntity.Position) + mMmoCameraDesc.Distance * cameraRotation.Backward; } else if (mInputMode == InputMode.Aiming) { Matrix viewRotation = Matrix.CreateWorld(Vector3.Zero, BepuConverter.Convert( bipedControl.Controller.ViewDirection), Vector3.Up); desiredCameraPosition = BepuConverter.Convert(mAvatarBepuEntity.Position) + Vector3.Transform( mAimingCameraOffset, viewRotation); } else { desiredCameraPosition = mCamera.Transform.Translation; } Vector3 newCameraPosition = desiredCameraPosition; Vector3 desiredCameraDirection; if (mInputMode == InputMode.Aloof) { desiredCameraDirection = BepuConverter.Convert(mAvatarBepuEntity.Position) - newCameraPosition; } else if (mInputMode == InputMode.Aiming) { desiredCameraDirection = BepuConverter.Convert(bipedControl.Controller.ViewDirection); } else { desiredCameraDirection = mCamera.Transform.Forward; } desiredCameraDirection.Normalize(); Vector3 newCameraDirection = desiredCameraDirection; if (mCameraSmoothingEngaged) { Vector3 positionDelta = desiredCameraPosition - mCamera.Transform.Translation; Quaternion directionDelta = SpaceUtils.GetSweptQuaternion(mCamera.Transform.Forward, desiredCameraDirection); const float POSITION_DELTA_THRESHHOLD = 4.0f; const float DIRECTION_DELTA_THRESHHOLD = MathHelper.Pi / 16.0f; float positionDeltaLength = positionDelta.Length(); float directionDeltaAngle = (float)(SpaceUtils.GetQuaternionAngle(directionDelta)); float fractionComplete = Math.Min(POSITION_DELTA_THRESHHOLD / positionDeltaLength, DIRECTION_DELTA_THRESHHOLD / directionDeltaAngle); if (fractionComplete < 1.0f) { newCameraPosition = Vector3.Lerp(mCamera.Transform.Translation, desiredCameraPosition, fractionComplete); Quaternion smoothedCamRotation = Quaternion.Slerp(Quaternion.Identity, directionDelta, fractionComplete); newCameraDirection = Vector3.Transform(mCamera.Transform.Forward, smoothedCamRotation); } } else { mCameraSmoothingEngaged = true; } mCamera.Transform = Matrix.CreateWorld(newCameraPosition, newCameraDirection, Vector3.Up); }
// Checks the animation state for control events and passes them on to the Controller. private void PostAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (mAnimationStateMachine != null) { if (mAnimationStateMachine.CurrentState.Name == CROUCHING_SN || mAnimationStateMachine.CurrentState.Name == CROUCHMOVING_SN) { Controller.StanceManager.DesiredStance = Stance.Crouching; } else { Controller.StanceManager.DesiredStance = Stance.Standing; } if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Jump)) Controller.Jump(); if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Boost)) OnStateChanged(ControllerState.Boosting); } else // Just let the events happen immediately: { if (Controller.SupportFinder.HasSupport) { if ((DesiredMovementActions & MovementActions.Jumping) > 0) Controller.Jump(); if (DesiredMovementActions.HasFlag(MovementActions.Boosting) && mState == ControllerState.Neutral && mBooster != null && mBooster.BoostReady) { OnStateChanged(ControllerState.Boosting); } } } if (mState == ControllerState.Boosting && !(DesiredMovementActions.HasFlag(MovementActions.Boosting))) { OnStateChanged(ControllerState.Neutral); } }
private void ProcessAIStepHandler(object sender, UpdateStepEventArgs e) { // Check FOV, add any new foes to memory. And update existing ones. We may also have gained new memories by other means. // Get players and mobs in field of vision: List <RayCastResult> actorsInView = new List <RayCastResult>(); ConeShape visionCone = new ConeShape(VisionDistance, VisionDistance); BipedControllerComponent bcc = Owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); RigidTransform tipOverCone = new RigidTransform(BepuVec3.Forward * VisionDistance * 0.75f, BepuQuaternion.CreateFromAxisAngle(BepuVec3.Right, MathHelper.PiOver2)); RigidTransform eyeLevelAndFacing = new RigidTransform(bcc.Controller.Body.Position - bcc.Controller.Down * bcc.Controller.Body.Height * 0.45f, BepuConverter.Convert(SpaceUtils.GetOrientation(BepuConverter.Convert(bcc.Controller.ViewDirection), Vector3.Up))); RigidTransform visionConeTransform; RigidTransform.Transform(ref tipOverCone, ref eyeLevelAndFacing, out visionConeTransform); BepuVec3 noSweep = BepuVec3.Zero; ViewInterestFilter filter = new ViewInterestFilter(bcc.Controller.Body.CollisionInformation); GameResources.ActorManager.SimSpace.ConvexCast(visionCone, ref visionConeTransform, ref noSweep, filter.Test, actorsInView); for (int a = 0; a < actorsInView.Count; ++a) { // Does this actor warrant an addition to be made to our memory? // If so, check for LOS and recheck range. If those tests pass, modify the memory. EntityCollidable otherEntityCollidable = actorsInView[a].HitObject as EntityCollidable; // We can jump to the Id in the Tag property because we know the filter has validated this. int actorId = (int)(otherEntityCollidable.Entity.Tag); Actor viewedActor = GameResources.ActorManager.GetActorById(actorId); BipedControllerComponent viewedActorBcc = viewedActor.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); BepuVec3 toSubject = viewedActorBcc.Controller.Body.Position - eyeLevelAndFacing.Position; // Check range: if (toSubject.LengthSquared() <= VisionDistance * VisionDistance) { BepuRay losRay = new BepuRay(eyeLevelAndFacing.Position, toSubject); RayCastResult losResult; LOSFilter losFilter = new LOSFilter(bcc.Controller.Body.CollisionInformation, otherEntityCollidable); GameResources.ActorManager.SimSpace.RayCast(losRay, VisionDistance, losFilter.Test, out losResult); EntityCollidable losEC = losResult.HitObject as EntityCollidable; // Test for LOS: if (losEC != null && losEC.Entity != null && losEC.Entity.Tag != null && (int)(losEC.Entity.Tag) == actorId) { // The viewed actor is either a player(foe) or a mob(ally). if (GameResources.ActorManager.IsPlayer(actorId)) { mMemory.SpotFoe(actorId); } else { IAgentStateManager agent = viewedActor.GetBehaviorThatImplementsType <IAgentStateManager>(); if (agent != null && agent.HasProperty(AgentPropertyName.ActiveOpponent)) { int mobFoe = agent.GetProperty <int>(AgentPropertyName.ActiveOpponent); mMemory.SenseFoe(mobFoe); } } } } } // Evaluate current threats and select one to engage: int enemyId = mMemory.GetLargestThreat(); if (enemyId != Actor.INVALID_ACTOR_ID) { if (mAgentProperties.ContainsKey(AgentPropertyName.ActiveOpponent)) { if ((int)(mAgentProperties[AgentPropertyName.ActiveOpponent]) != enemyId) { mAgentProperties[AgentPropertyName.ActiveOpponent] = enemyId; } } else { mAgentProperties.Add(AgentPropertyName.ActiveOpponent, enemyId); } } else { if (mAgentProperties.ContainsKey(AgentPropertyName.ActiveOpponent)) { mAgentProperties.Remove(AgentPropertyName.ActiveOpponent); } } TimeInState += e.GameTime.ElapsedGameTime; CurrentState.Update(mSteering, Owner, this); Vector2 locomotion = mSteering.ComputeForce(Owner); if (locomotion.LengthSquared() == 0.0f) { bcc.OrientationChange = Quaternion.Identity; bcc.HorizontalMovement = Vector2.Zero; } else { bcc.OrientationChange = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(Math.Atan2(-locomotion.X, locomotion.Y))); bcc.HorizontalMovement = locomotion.Length() * Vector2.UnitY; } mMemory.Fade(e.GameTime); }
private void AnimationUpdateHandler(object sender, UpdateStepEventArgs e) { SkinClipPlayer.Update(e.GameTime.ElapsedGameTime, true); }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mParticleSystem.AddParticle(mTransform.Translation, Vector3.Zero); }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mCurrentTime += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); RetireActiveParticles(); FreeRetiredParticles(); // If we let our timer go on increasing for ever, it would eventually // run out of floating point precision, at which point the particles // would render incorrectly. An easy way to prevent this is to notice // that the time value doesn't matter when no particles are being drawn, // so we can reset it back to zero any time the active queue is empty. if (mParticleData.FirstActiveParticleIndex == mParticleData.FirstFreeParticleIndex) mCurrentTime = 0; if (mFirstRetiredParticleIndex == mParticleData.FirstActiveParticleIndex) mDrawCounter = 0; }
private void PostPhysicsUpdateHandler(object sender, UpdateStepEventArgs e) { Value += (float)(e.GameTime.ElapsedGameTime.TotalSeconds) * RegenerationRate; if (Value > 1.0f) Value = 1.0f; }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mCurrentTime += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); }
protected virtual void PostPhysicsUpdateHandler(object sender, UpdateStepEventArgs e) { mTransformComponent.PhysicsUpdate(mPosition, mOrientation); }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { mTimeAlive += (float)(e.GameTime.ElapsedGameTime.TotalSeconds); float lifeMeasure = mTimeAlive * mSpeed; if (lifeMeasure > 335.0f) { Owner.Despawn(); } else if (lifeMeasure > 285.0f) { TransformComponent tc = Owner.GetComponent<TransformComponent>(ActorComponent.ComponentType.Transform); tc.Scale = MathHelper.Lerp(mOrigScale, 0.01f, (lifeMeasure - 285.0f) / 50.0f); } }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (mTargetActorId == Actor.INVALID_ACTOR_ID) { if (!mParticleSystem.HasActiveParticles) Owner.Despawn(); return; } // Work out how much time has passed since the previous update. float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds); Vector3 newPosition = GetPosition(); if (elapsedTime > 0) { // Work out how fast we are moving. Vector3 velocity = (newPosition - mPreviousPosition) / elapsedTime; // If we had any time left over that we didn't use during the // previous update, add that to the current elapsed time. float timeToSpend = mTimeLeftOver + elapsedTime; // Counter for looping over the time interval. float currentTime = -mTimeLeftOver; // Create particles as long as we have a big enough time interval. while (timeToSpend > mTimeBetweenParticles) { currentTime += mTimeBetweenParticles; timeToSpend -= mTimeBetweenParticles; // Work out the optimal position for this particle. This will produce // evenly spaced particles regardless of the object speed, particle // creation frequency, or game update rate. float mu = currentTime / elapsedTime; Vector3 position = Vector3.Lerp(mPreviousPosition, newPosition, mu); // Create the particle. mParticleSystem.AddParticle(position, velocity); } // Store any time we didn't use, so it can be part of the next update. mTimeLeftOver = timeToSpend; } mPreviousPosition = newPosition; }
public virtual void PreAnimationUpdate(object sender, UpdateStepEventArgs e) { TimeInState += e.GameTime.ElapsedGameTime; CurrentState.Update(e.GameTime, this, CurrentOperation); }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { float elapsedTime = (float)(e.GameTime.ElapsedGameTime.TotalSeconds); Actor avatar = GameResources.ActorManager.GetActorById(ActorId); BipedControllerComponent bipedControl = avatar.GetComponent<BipedControllerComponent>(ActorComponent.ComponentType.Control); // Update the camera. Vector3 desiredCameraPosition; if (mInputMode == InputMode.Aloof) { Matrix cameraRotation = Matrix.CreateFromYawPitchRoll(mMmoCameraDesc.Yaw, mMmoCameraDesc.Pitch, 0.0f); BepuRay boomRay = new BepuRay(mAvatarBepuEntity.Position, BepuConverter.Convert(cameraRotation.Backward)); RayCastResult result; GameResources.ActorManager.SimSpace.RayCast(boomRay, mMmoCameraDesc.Distance, CameraClipFilter, out result); desiredCameraPosition = result.HitObject != null ? BepuConverter.Convert(BEPUutilities.Vector3.Lerp(result.HitData.Location, mAvatarBepuEntity.Position, 0.05f)) : BepuConverter.Convert(mAvatarBepuEntity.Position) + mMmoCameraDesc.Distance * cameraRotation.Backward; } else if (mInputMode == InputMode.Aiming) { Matrix viewRotation = Matrix.CreateWorld(Vector3.Zero, BepuConverter.Convert( bipedControl.Controller.ViewDirection), Vector3.Up); desiredCameraPosition = BepuConverter.Convert(mAvatarBepuEntity.Position) + Vector3.Transform( mAimingCameraOffset, viewRotation); } else { desiredCameraPosition = mCamera.Transform.Translation; } Vector3 newCameraPosition = desiredCameraPosition; Vector3 desiredCameraDirection; if (mInputMode == InputMode.Aloof) { desiredCameraDirection = BepuConverter.Convert(mAvatarBepuEntity.Position) - newCameraPosition; } else if (mInputMode == InputMode.Aiming) { desiredCameraDirection = BepuConverter.Convert(bipedControl.Controller.ViewDirection); } else { desiredCameraDirection = mCamera.Transform.Forward; } desiredCameraDirection.Normalize(); Vector3 newCameraDirection = desiredCameraDirection; if (mCameraSmoothingEngaged) { Vector3 positionDelta = desiredCameraPosition - mCamera.Transform.Translation; Quaternion directionDelta = SpaceUtils.GetSweptQuaternion(mCamera.Transform.Forward, desiredCameraDirection); const float POSITION_DELTA_THRESHHOLD = 4.0f; const float DIRECTION_DELTA_THRESHHOLD = MathHelper.Pi / 16.0f; float positionDeltaLength = positionDelta.Length(); float directionDeltaAngle = (float)(SpaceUtils.GetQuaternionAngle(directionDelta)); float fractionComplete = Math.Min(POSITION_DELTA_THRESHHOLD / positionDeltaLength, DIRECTION_DELTA_THRESHHOLD / directionDeltaAngle); if (fractionComplete < 1.0f) { newCameraPosition = Vector3.Lerp(mCamera.Transform.Translation, desiredCameraPosition, fractionComplete); Quaternion smoothedCamRotation = Quaternion.Slerp(Quaternion.Identity, directionDelta, fractionComplete); newCameraDirection = Vector3.Transform(mCamera.Transform.Forward, smoothedCamRotation); } } else { mCameraSmoothingEngaged = true; } mCamera.Transform = Matrix.CreateWorld(newCameraPosition, newCameraDirection, Vector3.Up); }
private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e) { if (!mParticleSystem.HasActiveParticles) Owner.Despawn(); }