public override void Update(GameTime gameTime, IActor actor) { Actor3D parentActor = actor as Actor3D; DrawnActor3D targetDrawnActor = this.TargetActor as DrawnActor3D; if (targetDrawnActor != null) { if (this.bFirstUpdate) { //set the initial position of the camera parentActor.Transform.Translation = railParameters.MidPoint; this.bFirstUpdate = false; } //get look vector to target Vector3 cameraToTarget = MathUtility.GetNormalizedObjectToTargetVector(parentActor.Transform, targetDrawnActor.Transform); cameraToTarget = MathUtility.Round(cameraToTarget, 3); //round to prevent floating-point precision errors across updates //new position for camera if it is positioned between start and the end points of the rail Vector3 projectedCameraPosition = parentActor.Transform.Translation + Vector3.Dot(cameraToTarget, railParameters.Look) * railParameters.Look; // gameTime.ElapsedGameTime.Milliseconds; //removed gameTime multiplier - was causing camera judder when object close to camera projectedCameraPosition = MathUtility.Round(projectedCameraPosition, 3); //round to prevent floating-point precision errors across updates //do not allow the camera to move outside the rail if (railParameters.InsideRail(projectedCameraPosition)) { parentActor.Transform.Translation = projectedCameraPosition; } //set the camera to look at the object parentActor.Transform.Look = cameraToTarget; } }
public override void Update(GameTime gameTime, IActor actor) { Actor3D parentActor = actor as Actor3D; DrawnActor3D targetDrawnActor = this.TargetActor as DrawnActor3D; if (this.bFirstUpdate) { //set the initial position of the camera parentActor.Transform3D.Translation = railParameters.MidPoint; this.bFirstUpdate = false; } //get look vector to target Vector3 cameraToTarget = MathUtility.GetNormalizedObjectToTargetVector(parentActor.Transform3D, targetDrawnActor.Transform3D); //new position for camera if it is positioned between start and the end points of the rail Vector3 projectedCameraPosition = parentActor.Transform3D.Translation + Vector3.Dot(cameraToTarget, railParameters.Look) * railParameters.Look * gameTime.ElapsedGameTime.Milliseconds; //do not allow the camera to move outside the rail if (railParameters.InsideRail(projectedCameraPosition)) { parentActor.Transform3D.Translation = projectedCameraPosition; } //set the camera to look at the object parentActor.Transform3D.Look = cameraToTarget; //set the camera to look at the target object parentActor.Transform3D.Look = Vector3.Lerp(this.oldCameraToTarget, cameraToTarget, lerpSpeed); //store old values for lerp this.oldCameraToTarget = cameraToTarget; }
public override void Update(GameTime gameTime, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; if (bUpdated) { game.GraphicsDevice.SetRenderTarget(this.textRenderTarget); game.GraphicsDevice.Clear(this.backgroundColor); game.SpriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, null, DepthStencilState.Default, null); game.SpriteBatch.DrawString(font, this.text, Vector2.Zero, textColor); game.SpriteBatch.End(); game.GraphicsDevice.SetRenderTarget(null); //set texture in drawn object if (parentActor is TexturedPrimitiveObject) //its either a billboard, a simple textured primitive, or a model { (parentActor as TexturedPrimitiveObject).Texture = this.textRenderTarget; } else { (parentActor as ModelObject).Texture = this.textRenderTarget; } //set to false to prevent repeat each update bUpdated = false; } }
public void Add(DrawnActor3D actor) { if (actor.GetAlpha() == 1) { this.opaqueDrawList.Add(actor); } else { this.transparentDrawList.Add(actor); } }
private void EventDispatcher_RemoveActorChanged(EventData eventData) { if (eventData.EventType == EventActionType.OnRemoveActor) { DrawnActor3D actor = eventData.Sender as DrawnActor3D; if (actor != null) { this.Remove(actor); } } }
public void Add(DrawnActor3D actor) { if (actor.EffectParameters.Alpha < 1) { this.transparentList.Add(actor); } else { this.opaqueList.Add(actor); } }
//calls the DrawObject() based on underlying object type private void DrawActor(GameTime gameTime, DrawnActor3D actor, Camera3D activeCamera) { //was the drawn enum value set? if ((actor.StatusType & StatusType.Drawn) == StatusType.Drawn) { if (actor is ModelObject) { DrawObject(gameTime, actor as ModelObject, activeCamera); } //we will add additional else...if statements here to render other object types (e.g model, animated, billboard etc) } }
private void SetTexture(Texture2D texture, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; if (parentActor is TexturedPrimitiveObject) //its either a billboard, a simple textured primitive, or a model { (parentActor as TexturedPrimitiveObject).Texture = texture; } else { (parentActor as ModelObject).Texture = texture; } }
public override void Update(GameTime gameTime, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; if (parentActor != null) { //accumulate elapsed time - note we are not formally resetting this time if the controller becomes inactive - we should mirror the approach used for the UI sine controllers. this.totalElapsedTime += gameTime.ElapsedGameTime.Milliseconds; //sine wave in the range 0 -> max amplitude float lerpFactor = MathUtility.SineLerpByElapsedTime(this.TrigonometricParameters, this.totalElapsedTime); parentActor.EffectParameters.DiffuseColor = MathUtility.Lerp(this.startColor, this.endColor, lerpFactor); } }
//calls the DrawObject() based on underlying object type private void DrawActor(GameTime gameTime, DrawnActor3D actor, Camera3D activeCamera) { //was the drawn enum value set? if ((actor.StatusType & StatusType.Drawn) == StatusType.Drawn) { ModelObject modelObject = actor as ModelObject; //if the typecast using "as" worked then proceed if (modelObject != null) { modelObject.Draw(gameTime, activeCamera); } } }
public override bool Equals(object obj) { DrawnActor3D other = obj as DrawnActor3D; if (other == null) { return(false); } else if (this == other) { return(true); } return(this.effectParameters.Equals(other.EffectParameters) && this.Alpha.Equals(other.Alpha) && base.Equals(obj)); }
public override void Update(GameTime gameTime, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; //makes the object spin upwards and fade away after its alpha is lower than a threshold value parentActor.Transform.RotateAroundYBy(this.rotationRate); parentActor.Transform.TranslateBy(this.translationRate * gameTime.ElapsedGameTime.Milliseconds); parentActor.Transform.ScaleBy(this.scaleRate); parentActor.EffectParameters.Alpha += this.alphaDecayRate; //if alpha less than some threshold value then remove if (parentActor.EffectParameters.Alpha < this.alphaDecayThreshold) { EventDispatcher.Publish(new EventData(parentActor, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove)); } }
public override void Update(GameTime gameTime, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; //set the texture if the parent is valid if (parentActor != null) { if (videoState == VideoState.Playing) { parentActor.EffectParameters.Texture = videoPlayer.GetTexture(); } else if (videoState == VideoState.Stopped) { parentActor.EffectParameters.Texture = startTexture; } } }
public new object Clone() { IActor actor = new DrawnActor3D("clone - " + ID, //deep this.ActorType, //deep (Transform3D)this.Transform.Clone(), //deep - calls the clone for Transform3D explicitly this.EffectParameters.GetDeepCopy(), //hybrid - shallow (texture and effect) and deep (all other fields) this.StatusType); //deep - a simple numeric type if (this.ControllerList != null) { //clone each of the (behavioural) controllers foreach (IController controller in this.ControllerList) { actor.AttachController((IController)controller.Clone()); } } return(actor); }
private void EventDispatcher_OpacityChanged(EventData eventData) { DrawnActor3D actor = eventData.Sender as DrawnActor3D; if (actor != null) { if (eventData.EventType == EventActionType.OnOpaqueToTransparent) { //remove from opaque and add to transparent this.opaqueDrawList.Remove(actor); this.transparentDrawList.Add(actor); } else if (eventData.EventType == EventActionType.OnTransparentToOpaque) { //remove from transparent and add to opaque this.transparentDrawList.Remove(actor); this.opaqueDrawList.Add(actor); } } }
public DrawnActor3D Find(Predicate <DrawnActor3D> predicate) { DrawnActor3D drawnActor = null; //look in opaque drawnActor = this.opaqueDrawList.Find(predicate); if (drawnActor != null) { return(drawnActor); } //look in transparent drawnActor = this.transparentDrawList.Find(predicate); if (drawnActor != null) { return(drawnActor); } return(null); }
public override void Update(GameTime gameTime, IActor actor) { DrawnActor3D parentActor = actor as DrawnActor3D; if (parentActor != null) { float time = (float)gameTime.TotalGameTime.TotalSeconds; time %= 360; //0 - > 359 degrees float lerpFactor = (float)Math.Sin(MathHelper.ToRadians( this.lerpSpeed * time)); lerpFactor *= 0.5f; //scale to 0->1 lerpFactor += 0.5f; parentActor.Color = MathUtility.Lerp(this.startColor, this.endColor, lerpFactor); } }
//call when we want to remove a drawn object from the scene public void Remove(DrawnActor3D actor) { this.removeList.Add(actor); }