public SmoothCamera(String pName, SceneManager pSceneManager, MovingObject pTarget, Int32 pFramesBehind)
            : base(pName, pSceneManager)
        {
            Node = pSceneManager.RootSceneNode.CreateChildSceneNode();
            Node.Position = cameraOffset;
            Node.AttachObject(this);

            x = new List<double>(pFramesBehind);
            y = new List<double>(pFramesBehind);
            dx = new List<double>(pFramesBehind);
            dy = new List<double>(pFramesBehind);
            framesBehind = Math.Max(1, pFramesBehind);
            target = pTarget;

            for (var i = 0; i < pFramesBehind; i++)
            {
                x.Add(pTarget.Position.x);
                y.Add(pTarget.Position.y);
                dx.Add(0);
                dy.Add(0);
            }

            x.Insert(0, pTarget.Position.x);
            y.Insert(0, pTarget.Position.y);
            dx.Insert(0, pTarget.Velocity.x);
            dy.Insert(0, pTarget.Velocity.y);

            isYawFixed = true;
            FixedYawAxis = Vector3.UnitZ;
            Near = 5;
            AutoAspectRatio = true;
        }
        public MultiLights(SceneManager pSceneManager, SceneNode pCamNode, MovingObject pPlayerShip, Int32 pNumberOfLights)
        {
            oldCamLightColor = CamLightColor = new ColorEx(0.13f, 0.1f, 0.05f);
            PlayerLightColor = ColorEx.White;
            camLights = new List<Light>(pNumberOfLights);

            innerLights = (Int32)Math.Round(pNumberOfLights / 3.0f, MidpointRounding.AwayFromZero);
            outerLights = pNumberOfLights - innerLights;

            // create the playership's light.
            playerLight = pSceneManager.CreateLight("playerSpotLight");
            playerLight.Type = LightType.Spotlight;
            playerLight.Diffuse = PlayerLightColor;
            playerLight.Specular = ColorEx.White;
            playerLight.SetSpotlightRange(0.0f, 120.0f);
            playerLight.Direction = Vector3.NegativeUnitZ;

            playerLightNode = pPlayerShip.Node.CreateChildSceneNode();
            playerLightNode.AttachObject(playerLight);
            playerLightNode.Position = new Vector3(0, 0, 0);
            playerLightNode.SetDirection(new Vector3(1, 0, 0), TransformSpace.Local);

            // create the camera spotlights around the camera's direction.
            camInnerLightNode = pCamNode.CreateChildSceneNode();
            camInnerLightNode.Position = new Vector3(0, 0, 0);
            camOuterLightNode = pCamNode.CreateChildSceneNode();
            camOuterLightNode.Position = new Vector3(0, 0, 0);

            for (var i = 0; i < innerLights; i++)
            {
                var light = pSceneManager.CreateLight("camInnerLight " + (i + 1));
                light.Type = LightType.Spotlight;
                light.Diffuse = CamLightColor;
                light.Specular = ColorEx.White;
                light.SetSpotlightRange(0.0f, 25.0f);
                light.Direction = Quaternion.FromAngleAxis(360.0 * i / innerLights * Constants.DegreesToRadians, Vector3.UnitZ) *
                    Quaternion.FromAngleAxis(10.0 * Constants.DegreesToRadians, Vector3.UnitX) *
                    Vector3.NegativeUnitZ;

                camLights.Add(light);
                camInnerLightNode.AttachObject(light);
            }
            for (var i = 0; i < outerLights; i++)
            {
                var light = pSceneManager.CreateLight("camOuterLight " + (i + 1));
                light.Type = LightType.Spotlight;
                light.Diffuse = CamLightColor;
                light.Specular = ColorEx.White;
                light.SetSpotlightRange(0.0f, 25.0f);
                light.Direction = Quaternion.FromAngleAxis(360.0 * i / outerLights * Constants.DegreesToRadians, Vector3.UnitZ) *
                    Quaternion.FromAngleAxis(20.0 * Constants.DegreesToRadians, Vector3.UnitX) *
                    Vector3.NegativeUnitZ;

                camLights.Add(light);
                camOuterLightNode.AttachObject(light);
            }
        }
        public override void Loop(MovingObject pShip)
        {
            if (Targets.Count == 0)
                Targets.Add(new Vector3((Methods.Random.NextDouble() - 0.5) * World.Instance.Arena.Width, (Methods.Random.NextDouble() - 0.5) * World.Instance.Arena.Height, 0));

            InputStates.Clear();
            //InputStates.Fire = Methods.Random.Next(128) == 0; // Temporary random fire.

            InputStates.Add(MoveToNextTarget(pShip));
            InputStates.DetectPresses();
        }
        public static Trail NewTrail(MovingObject pObjectToFollow, Single pMaxWidth, ColorEx pColor)
        {
            if (freeTrails.Count == 0)
            {
                return new Trail(pObjectToFollow, pMaxWidth, pColor);
            }

            var trail = freeTrails.Dequeue();
            trail.Relaunch(pObjectToFollow, pMaxWidth, pColor);
            return trail;
        }
        public override void Loop(MovingObject pShip)
        {
            InputStates.Up = InputStates.GetKey(Keys.Up);
            InputStates.Down = InputStates.GetKey(Keys.Down);
            InputStates.Left = InputStates.GetKey(Keys.Left);
            InputStates.Right = InputStates.GetKey(Keys.Right);
            InputStates.Fire = InputStates.GetKey(Keys.C);
            InputStates.Secondary = InputStates.GetKey(Keys.X);
            InputStates.Upgrade = InputStates.GetKey(Keys.Z);

            InputStates.DetectPresses();
        }
Exemple #6
0
        public Trail(MovingObject pObjectToFollow, Single pMaxWidth, ColorEx pColor)
        {
            LoopResultStates = new LoopResultStates();

            Chain = new BillboardChain(Methods.GenerateUniqueID.ToString(CultureInfo.InvariantCulture));
            Chain.Material.SetSceneBlending(SceneBlendType.Replace);
            Chain.Material.DepthCheck = false;
            Chain.Material.DepthWrite = false;
            Chain.NumberOfChains = 1;
            Chain.IsVisible = false;
            World.Instance.SceneManager.RootSceneNode.AttachObject(Chain);

            Relaunch(pObjectToFollow, pMaxWidth, pColor);
        }
        protected InputStates MoveToNextTarget(MovingObject pShip)
        {
            temporaryAdditionInputState.Clear();

            if (Targets.Count <= 0) return temporaryAdditionInputState;

            var nextTarget = Targets[0];
            var vectorToTarget = Methods.ToVector2(nextTarget - pShip.Position); // Direction to target.
            var vectorToFacing = Methods.ToVector2(pShip.Velocity + 4 * Methods.AngleToVector(pShip.Angle * Constants.DegreesToRadians)); // Ship's velocity plus a little bit of it's rotation.
            var vectorAlong = Methods.Projection(vectorToFacing, vectorToTarget); // The part of the facing vector that is in line with the target (how close we are to pointing to the target).
            var vectorAside = vectorToTarget - vectorAlong; // The part of the facing vector that is looking to the side of the target (how close we are to looking 90 degrees away from the target).

            if (vectorAside.Length < vectorAlong.Length * 2 && vectorToTarget.Dot(vectorToFacing) > 0) // Generally facing target.
                temporaryAdditionInputState.Up = true;
            if (vectorAside.Length * 8 > vectorAlong.Length || vectorToTarget.Dot(vectorToFacing) < 0) // Accurately facing target.
                if (vectorToFacing.Perpendicular.Dot(vectorToTarget) < 0) // Target is to the left.
                    temporaryAdditionInputState.Left = true;
                else
                    temporaryAdditionInputState.Right = true;
            if ((nextTarget - pShip.Position).Length < (Targets.Count > 1 ? 32 : 16)) // Are we there yet? More lenient if there are more waypoints to come.
                Targets.RemoveAt(0);

            return temporaryAdditionInputState;
        }
        public InputStates InputStates = new InputStates(); // keys pressed after every Loop().

        #endregion Fields

        #region Methods

        public abstract void Loop(MovingObject pShip);
Exemple #9
0
        public void Relaunch(MovingObject pObjectToFollow, Single pMaxWidth, ColorEx pColor)
        {
            objectToFollow = pObjectToFollow;
            maxwidth = pMaxWidth;
            color = pColor;
            trailState = TrailState.Growing;
            elementList.Clear();
            elementPositions.Clear();
            elementsToDestroy = Chain.MaxChainElements = 4;

            AddHead();
        }