private void UpdateParent(GameTime gameTime, Actor3D parentActor, Actor3D targetActor) { if (targetActor != null) { //rotate the target look around the target right to get a vector pointing away from the target at a specified elevation Vector3 cameraToTarget = Vector3.Transform(-targetActor.Transform.Look, Matrix.CreateFromAxisAngle(-targetActor.Transform.Right, MathHelper.ToRadians(this.elevationAngle))); //normalize to give unit length, otherwise distance from camera to target will vary over time cameraToTarget.Normalize(); //set the position of the camera to be a set distance from target and at certain elevation angle parentActor.Transform.Translation = Vector3.Lerp(this.oldTranslation, cameraToTarget * this.distance + targetActor.Transform.Translation, this.translationLerpSpeed * gameTime.ElapsedGameTime.Milliseconds); //set the camera to look at the target object parentActor.Transform.Look = Vector3.Lerp(this.oldCameraToTarget, cameraToTarget, this.lookLerpSpeed * gameTime.ElapsedGameTime.Milliseconds); //store old values for lerp this.oldTranslation = parentActor.Transform.Translation; this.oldCameraToTarget = -cameraToTarget; } }
//when setting up the level loader we create these mappings to say what to do when we find a particular pixel color public void AddColorActor3DPair(Color color, Actor3D actor) { if (!this.colorToActorDictionary.ContainsKey(color.ToVector3())) { this.colorToActorDictionary.Add(color.ToVector3(), actor); } }
private void HandleKeyboardInput(GameTime gameTime, Actor3D parent) { Vector3 moveVector = Vector3.Zero; if (this.keyboardManager.IsKeyDown(moveKeys[0])) { moveVector = parent.Transform3D.Look * this.moveSpeed; } else if (this.keyboardManager.IsKeyDown(moveKeys[1])) { moveVector = -1 * parent.Transform3D.Look * this.moveSpeed; } if (this.keyboardManager.IsKeyDown(moveKeys[2])) { moveVector -= parent.Transform3D.Right * this.strafeSpeed; } else if (this.keyboardManager.IsKeyDown(moveKeys[3])) { moveVector += parent.Transform3D.Right * this.strafeSpeed; } //constrain movement in Y-axis moveVector.Y = 0; parent.Transform3D.TranslateBy(moveVector * gameTime.ElapsedGameTime.Milliseconds); }
private void DrawObjectByType(GameTime gameTime, Actor3D actor) { //was the drawn enum value set? if ((actor.StatusType & StatusType.Drawn) == StatusType.Drawn) { if (actor is AnimatedPlayerObject) { DrawObject(gameTime, actor as AnimatedPlayerObject); } else if (actor is ModelObject) { DrawObject(gameTime, actor as ModelObject); } else if (actor is BillboardPrimitiveObject) { DrawObject(gameTime, actor as BillboardPrimitiveObject); } else if (actor is TexturedPrimitiveObject) { DrawObject(gameTime, actor as TexturedPrimitiveObject); } else if (actor is PrimitiveObject) { DrawObject(gameTime, actor as PrimitiveObject); } DrawCollisionSkin(actor); } }
public override void HandleMouseInput(GameTime gameTime, Actor3D parentActor) { Vector2 mouseDelta = Vector2.Zero; mouseDelta = -game.MouseManager.GetDeltaFromCentre();//game.ScreenCentre); mouseDelta *= gameTime.ElapsedGameTime.Milliseconds; mouseDelta *= this.RotationSpeed; //if (parentActor.Transform3D.Look.Y >= 0.9f) //{ // if (mouseDelta.Y < 0) // { // mouseDelta.Y += mouseDelta.Y * gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed; // } //} //else if (parentActor.Transform3D.Look.Y <= -0.9f) //{ // if (mouseDelta.Y > 0) // { // mouseDelta.Y += mouseDelta.Y * gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed; // } //} parentActor.Transform3D.RotateBy(new Vector3(mouseDelta.X, mouseDelta.Y, 0)); }
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; } }
//returns a reference to a new actor based on the current pixel color and the if...else logic of this method - see MyLevelLoader::GetActorFromPixelColor() private Actor3D GetActor3DFromColor(Vector3 colorAsVector3, Vector3 position) { Actor3D clonedActor = this.colorToActorDictionary[colorAsVector3].Clone() as Actor3D; clonedActor.Transform.Translation = position; return(clonedActor); }
public void Update(GameTime gameTime, IActor actor) { Actor3D parent = actor as Actor3D; if (parent != null) { if (this.keyboardManager.IsKeyDown(Keys.W)) { parent.Transform3D.TranslateBy(parent.Transform3D.Look * this.moveSpeed); } else if (this.keyboardManager.IsKeyDown(Keys.S)) { parent.Transform3D.TranslateBy(parent.Transform3D.Look * -this.moveSpeed); } //ASD if (this.keyboardManager.IsKeyDown(Keys.A)) { parent.Transform3D.TranslateBy(parent.Transform3D.Right * -this.strafeSpeed); } else if (this.keyboardManager.IsKeyDown(Keys.D)) { parent.Transform3D.TranslateBy(parent.Transform3D.Right * this.strafeSpeed); } Vector2 mouseDelta = this.mouseManager.GetDeltaFromCentre(new Vector2(512, 384)); mouseDelta *= this.rotationSpeed * gameTime.ElapsedGameTime.Milliseconds; if (mouseDelta.Length() != 0) { parent.Transform3D.RotateBy(new Vector3(-1 * mouseDelta, 0)); } } }
private void HandleCameraFollow(GameTime gameTime, Actor3D parent) { //Offest the objects position to where the camera should be Vector3 parentPos = parent.Transform3D.Translation; parentPos.Y += GConstants.PlayerCamOffsetY; parentPos.Z += GConstants.PlayerCamOffsetZ; //subtract objects position from camera position to get the distance parentPos -= camera3D.Transform3D.Translation; //Wait for the player to be slightly out of position before moving camera if (cameraMoveConstraint || parentPos.Length() > 70) { cameraMoveConstraint = true; //Offset the position before adding so it will take several updates to move to the objects position (This make the camera move smoothly) parentPos *= 0.01f; camera3D.Transform3D.Translation += parentPos; if (parentPos.Length() <= 0.2) { cameraMoveConstraint = false; } } }
/// <summary> /// Checks what tile is directly underneath the player and performs an action based on it. /// This is called directly after the player's move has finished. /// </summary> private void CheckGround() { Actor3D newGround = CheckCollisionAfterTranslation(-Vector3.UnitY) as Actor3D; if (newGround == null) { //No ground detected --> player dies (Water tiles have no collision, so water will kill the player too) EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new [] { new TranslationTween(this, 200, new Vector3(0, -2, 0), true, actor3D => Die()) })); return; } //Correcting the X and Y position of the player Transform3D groundTransform = newGround.Transform3D; Vector3 position = new Vector3(groundTransform.Translation.X, Transform3D.Translation.Y, groundTransform.Translation.Z); Transform3D.Translation = position; if (newGround.ActorType == ActorType.WaterPlatform) { Vector3 platformTrans = (newGround as Actor3D).Transform3D.Translation; Transform3D.Translation = new Vector3(platformTrans.X, Transform3D.Translation.Y, platformTrans.Z); EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAddChild, new [] { newGround as Actor3D, this })); } //Update the ground ground = newGround; }
public override void HandleKeyboardInput(GameTime gameTime, Actor3D parentActor) { if (this.ManagerParameters.KeyboardManager.IsKeyDown(this.MoveKeys[0])) { Vector3 moveDirection = gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform.Look; moveDirection = moveDirection * new Vector3(1, 0, 1); parentActor.Transform.TranslateBy(moveDirection); } else if (this.ManagerParameters.KeyboardManager.IsKeyDown(this.MoveKeys[1])) { Vector3 moveDirection = -gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform.Look; moveDirection = moveDirection * new Vector3(1, 0, 1); parentActor.Transform.TranslateBy(moveDirection); } if (this.ManagerParameters.KeyboardManager.IsKeyDown(this.MoveKeys[2])) { parentActor.Transform.TranslateBy(-gameTime.ElapsedGameTime.Milliseconds * this.StrafeSpeed * parentActor.Transform.Right); } else if (this.ManagerParameters.KeyboardManager.IsKeyDown(this.MoveKeys[3])) { parentActor.Transform.TranslateBy(gameTime.ElapsedGameTime.Milliseconds * this.StrafeSpeed * parentActor.Transform.Right); } }
private void CheckCollisions(GameTime gameTime) { Ray mouseRay = this.managerParameters.MouseManager.GetMouseRay(this.managerParameters.CameraManager.ActiveCamera); foreach (Actor3D actor in this.managerParameters.ObjectManager.OpaqueDrawList) { collidee = CheckCollision(gameTime, actor, mouseRay); if (collidee != null) { HandleResponse(gameTime, collidee); break; //if we collide then break and handle collision } } foreach (Actor3D actor in this.managerParameters.ObjectManager.TransparentDrawList) { collidee = CheckCollision(gameTime, actor, mouseRay); if (collidee != null) { HandleResponse(gameTime, collidee); break; //if we collide then break and handle collision } } //we're not over anything if (collidee == null) { //notify listeners that we're no longer picking object[] additionalParameters = { NoObjectSelectedText }; EventDispatcher.Publish(new EventData(EventActionType.OnNonePicked, EventCategoryType.ObjectPicking, additionalParameters)); } }
//test for collision against a specific object private Actor CheckCollisionWithActor(GameTime gameTime, Actor3D actor3D) { //dont test for collision against yourself - remember the player is in the object manager list too! if (this != actor3D) { if (actor3D is CollidablePrimitiveObject) { CollidablePrimitiveObject collidableObject = actor3D as CollidablePrimitiveObject; if (this.CollisionPrimitive.Intersects(collidableObject.CollisionPrimitive, this.Transform.TranslateIncrement)) { return(collidableObject); } } else if (actor3D is SimpleZoneObject) { SimpleZoneObject zoneObject = actor3D as SimpleZoneObject; if (this.CollisionPrimitive.Intersects(zoneObject.CollisionPrimitive, this.Transform.TranslateIncrement)) { return(zoneObject); } } } return(null); }
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 HandleKeyboardInput(GameTime gameTime, Actor3D parentActor) { if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveForward])) { parentActor.Transform3D.TranslateIncrement = gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform3D.Look; } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveBackward])) { parentActor.Transform3D.TranslateIncrement += -gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform3D.Look; } if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexStrafeLeft])) { parentActor.Transform3D.TranslateIncrement += -gameTime.ElapsedGameTime.Milliseconds * this.StrafeSpeed * parentActor.Transform3D.Right; } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexStrafeRight])) { parentActor.Transform3D.TranslateIncrement += gameTime.ElapsedGameTime.Milliseconds * this.StrafeSpeed * parentActor.Transform3D.Right; } if (parentActor.Transform3D.TranslateIncrement != Vector3.Zero) { parentActor.Transform3D.TranslateBy(parentActor.Transform3D.TranslateIncrement); parentActor.Transform3D.TranslateIncrement = Vector3.Zero; } }
public override void HandleMouseInput(GameTime gameTime, Actor3D parentActor) { //code from the group that made Crime Rush if ((parentActor != null) && (parentActor != null)) { Camera3D camera = parentActor as Camera3D; Vector2 mouseDelta = game.MouseManager.GetDeltaFromPosition(game.ScreenCentre); if (mouseDelta.X >= 480 || mouseDelta.X <= -480) { game.MouseManager.SetPosition(new Vector2(game.ScreenCentre.X, Mouse.GetState().Y)); } if (Mouse.GetState().Y >= 483) { mouseDelta.Y = 99; game.MouseManager.SetPosition(new Vector2(Mouse.GetState().X, 483f)); } else if (Mouse.GetState().Y <= 285) { mouseDelta.Y = -100; game.MouseManager.SetPosition(new Vector2(Mouse.GetState().X, 285)); } mouseDelta *= gameTime.ElapsedGameTime.Milliseconds; mouseDelta *= 0.047f; //this.Transform3D.RotateBy(new Vector3(-mouseDelta, 0)); parentActor.Transform3D.RotateBy(new Vector3(-mouseDelta, 0)); } }
private Actor3D CheckCollision(GameTime gameTime, Actor3D actor, Ray mouseRay) { if (actor is CollidablePrimitiveObject) { collisionPrimitive = (actor as CollidablePrimitiveObject).CollisionPrimitive; if (collisionPrimitive.Intersects(mouseRay)) { return(actor); } } else if (actor is SimpleZoneObject) { collisionPrimitive = (actor as SimpleZoneObject).CollisionPrimitive; if (collisionPrimitive.Intersects(mouseRay)) { return(actor); } } else //PrimitiveObject - uses basic BoundingSphere created for camera frustum culling { float?result = mouseRay.Intersects(actor.BoundingSphere); if (result != null) { return(actor); } } return(null); }
public override void HandleKeyboardInput(GameTime gameTime, Actor3D parentActor) { if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveForward])) { parentActor.Transform3D.TranslateIncrement = gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform3D.Look; } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveBackward])) { parentActor.Transform3D.TranslateIncrement += -gameTime.ElapsedGameTime.Milliseconds * this.MoveSpeed * parentActor.Transform3D.Look; } if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexRotateLeft])) { parentActor.Transform3D.RotateAroundYBy(gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed); } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexRotateRight])) { parentActor.Transform3D.RotateAroundYBy(-gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed); } //prevent movement up or down //parentActor.Transform3D.TranslateIncrementY = 0; if (parentActor.Transform3D.TranslateIncrement != Vector3.Zero) { parentActor.Transform3D.TranslateBy(parentActor.Transform3D.TranslateIncrement); parentActor.Transform3D.TranslateIncrement = Vector3.Zero; } }
public override void HandleGamePadInput(GameTime gameTime, Actor3D parentActor) { //only override this method if we want to use the gamepad //if (this.gamePadManager.IsButtonPressed(PlayerIndex.One, Buttons.RightTrigger)) //{ // //do something.... //} }
private void UpdateTrack(GameTime gameTime, Actor3D parentActor) { this.elapsedTimeInMs += gameTime.ElapsedGameTime.Milliseconds; this.transform3DCurve.Evalulate(elapsedTimeInMs, this.curveEvaluationPrecision, out translation, out look, out up); parentActor.Transform.Translation = translation; parentActor.Transform.Look = look; parentActor.Transform.Up = up; }
public new object Clone() { IActor actor = new Actor3D("clone - " + ID, //deep this.ActorType, //deep (Transform3D)this.transform.Clone()); //deep return(actor); }
public override void Update(GameTime gameTime, IActor actor) { Actor3D parentActor = actor as Actor3D; HandleMouseInput(gameTime, parentActor); HandleKeyboardInput(gameTime, parentActor); base.Update(gameTime, actor); }
public override void HandleMouseInput(GameTime gameTime, Actor3D parentActor) { Vector2 mouseDelta = game.MouseManager.GetDeltaFromCentre(); mouseDelta *= gameTime.ElapsedGameTime.Milliseconds; mouseDelta *= this.RotationSpeed; parentActor.Transform3D.RotateBy(new Vector3(-mouseDelta, 0)); }
public override void Update(GameTime gameTime, IActor actor) { Actor3D parentActor = actor as Actor3D; Actor3D targetActor = this.TargetActor as Actor3D; UpdateFromScrollWheel(gameTime); UpdateParent(gameTime, parentActor, targetActor); }
public void Update(GameTime gameTime, IActor actor) { Actor3D parent = actor as Actor3D; if (parent != null) { HandleInput(gameTime, parent); HandleCameraFollow(gameTime, parent); } }
public override void Update(GameTime gameTime, IActor actor) { Actor3D parentActor = actor as Actor3D; if (parentActor != null) { parentActor.Transform.RotateBy(this.rotation * count * gameTime.ElapsedGameTime.Milliseconds); count++; } }
public override void Update(GameTime gameTime, IActor actor) { Actor3D parent = actor as Actor3D; if (parent != null) { HandleKeyboardInput(gameTime, parent); HandleMouseInput(gameTime, parent); } }
public override void HandleKeyboardInput(GameTime gameTime, Actor3D parentActor) { if ((parentActor != null) && (parentActor != null)) { //jump if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveJump])) { this.playerObject.CharacterBody.DoJump(AppData.CameraJumpHeight); } //crouch else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveCrouch])) { this.playerObject.CharacterBody.IsCrouching = !this.playerObject.CharacterBody.IsCrouching; } //forward/backward if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveForward])) { Vector3 restrictedLook = parentActor.Transform3D.Look; restrictedLook.Y = 0; this.playerObject.CharacterBody.Velocity += restrictedLook * this.MoveSpeed * gameTime.ElapsedGameTime.Milliseconds; } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexMoveBackward])) { Vector3 restrictedLook = parentActor.Transform3D.Look; restrictedLook.Y = 0; this.playerObject.CharacterBody.Velocity -= restrictedLook * this.MoveSpeed * gameTime.ElapsedGameTime.Milliseconds; } else //decelerate to zero when not pressed { this.playerObject.CharacterBody.DesiredVelocity = Vector3.Zero; } //strafe left/right if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexRotateLeft])) { Vector3 restrictedRight = parentActor.Transform3D.Right; restrictedRight.Y = 0; this.playerObject.CharacterBody.Velocity -= restrictedRight * gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed; } else if (game.KeyboardManager.IsKeyDown(this.MoveKeys[AppData.IndexRotateRight])) { Vector3 restrictedRight = parentActor.Transform3D.Right; restrictedRight.Y = 0; this.playerObject.CharacterBody.Velocity += restrictedRight * gameTime.ElapsedGameTime.Milliseconds * this.RotationSpeed; } else //decelerate to zero when not pressed { this.playerObject.CharacterBody.DesiredVelocity = Vector3.Zero; } //update the camera position to reflect the collision skin position parentActor.Transform3D.Translation = this.playerObject.CharacterBody.Position; } }
public void Add(Actor3D actor) { if (actor.GetAlpha() == 1) { this.opaqueDrawList.Add(actor); } else { this.transparentDrawList.Add(actor); } }
private void HandleMouseInput(GameTime gameTime, Actor3D parent) { Vector2 mouseDelta = this.mouseManager.GetDeltaFromCentre(new Vector2(512, 384)); mouseDelta *= this.rotationSpeed * gameTime.ElapsedGameTime.Milliseconds; if (mouseDelta.Length() != 0) { parent.Transform3D.RotateBy(new Vector3(-1 * mouseDelta, 0)); } }