public override void UpdateFrame(IGameInputDriver input, double time)
        {
            Application.DoEvents();

            // Move camera
            if (input.GetMouse(OpenTK.Input.MouseButton.Right))
            {
                this.pan  -= input.MouseMovement.X;
                this.tilt -= input.MouseMovement.Y;
                this.tilt  = MathHelper.Clamp(this.tilt, -89, 89);
            }

            this.camera.Eye = this.camera.Target - 8.0f * this.GetCameraDirection();
        }
Example #2
0
 public void UpdateFrame(IGameInputDriver input, double time)
 {
     // TODO: Implement nicer interpolation
     this.CurrentPosition = Vector3.Lerp(this.CurrentPosition, this.SetpointPosition, 0.2f);
     this.CurrentBodyRotation = 0.8f * this.CurrentBodyRotation + 0.2f * this.SetpointBodyRotation;
 }
Example #3
0
        public void UpdateFrame(IGameInputDriver input, double time)
        {
            this.camera.Pan -= 0.5f * input.MouseMovement.X;
            this.camera.Tilt -= 0.5f * input.MouseMovement.Y;

            this.camera.Pan %= 360.0f;
            this.camera.Tilt = MathHelper.Clamp(this.camera.Tilt, -80, 80);

            Vector3 forward = Vector3.Zero;

            forward.X = 1.0f * (float)(Math.Sin(MathHelper.DegreesToRadians(this.camera.Pan)));
            forward.Y = 0.0f;
            forward.Z = 1.0f * (float)(Math.Cos(MathHelper.DegreesToRadians(this.camera.Pan)));

            Vector3 right = Vector3.Cross(forward, Vector3.UnitY);

            Vector3 move = Vector3.Zero;
            if (input.GetButton(Key.W)) move += forward;
            if (input.GetButton(Key.S)) move -= forward;
            if (input.GetButton(Key.D)) move += right;
            if (input.GetButton(Key.A)) move -= right;

            this.WalkSpeed = 10.0f * move.Jitter();

            if (input.GetButtonDown(Key.Space))
            {
                RaycastCallback callback = (b, n, f) =>
                {
                    return b.IsStatic;
                };
                RigidBody body;
                JVector normal;
                float friction;

                if (this.world.CollisionSystem.Raycast(
                    this.Position,
                    new JVector(0, -1, 0),
                    callback,
                    out body,
                    out normal,
                    out friction))
                {
                    if (friction < 0.9f)
                    {
                        this.AddForce(new JVector(0, 200, 0));
                        Console.WriteLine("{0} {1} {2}", body, normal, friction);
                    }
                }
            }

            var origin = this.camera.GetEye();
            var direction = this.camera.GetForward();

            if (input.GetMouseDown(MouseButton.Left))
            {
                this.Tool?.PrimaryUse(origin, direction);
            }

            if (input.GetMouseDown(MouseButton.Right))
            {
                this.Tool?.SecondaryUse(origin, direction);
            }
        }
Example #4
0
        public override void UpdateFrame(IGameInputDriver input, double time)
        {
            this.fps        = (int)(1.0f / time);
            this.totalTime += time;

            this.network.Dispatch();

            foreach (var proxy in this.proxies)
            {
                proxy.Value.UpdateFrame(input, time);
            }

            if (input.GetButtonDown(Key.Q))
            {
                this.currentTool = (this.currentTool + 1) % this.tools.Count;
            }

            if (this.player != null)
            {
                this.player.Tool = this.tools[this.currentTool].Item2;
                this.player.UpdateFrame(input, time);

                var previous = this.selectedDetail;
                this.selectedDetail = null;
                this.visibleDetails.Clear();

                var from = this.player.Eye;
                foreach (var detail in this.world.Details)
                {
                    // Ignore all details without interactions.
                    // How stupid was I when i forgot this?
                    if (detail.Interactions.Count == 0)
                    {
                        continue;
                    }

                    // Check for visibility with trace
                    var to  = detail.WorldPosition;
                    var dir = (to - from).Normalized();

                    var hit = this.world.Trace(from.Jitter(), dir.Jitter(), TraceOptions.IgnoreDynamic);

                    if ((hit != null) && ((hit.Body?.Tag as DetailObject) != detail))
                    {
                        continue;
                    }

                    var dist = (detail.WorldPosition - from).Length;
                    if (dist > 3.5f)                     // TODO: Implement settings value
                    {
                        continue;
                    }

                    var center = this.player.Camera.WorldToScreen(detail.WorldPosition, this.Aspect);
                    if ((center.X < -0.6) || (center.X > 0.6))
                    {
                        continue;
                    }

                    /*
                     * Maybe opt in this later, but it should decrease usability of doors.
                     * if ((center.Y < -1.0) || (center.Y > 1.0))
                     * continue;
                     */

                    this.visibleDetails.Add(detail);


                    if (this.selectedDetail != null)
                    {
                        var currentCenter = this.player.Camera.WorldToScreen(this.selectedDetail.WorldPosition, this.Aspect).Xy.Length;

                        if (currentCenter < center.Xy.Length)
                        {
                            continue;
                        }
                    }
                    this.selectedDetail = detail;
                }
                this.visibleDetails.Remove(this.selectedDetail);

                // Reset interaction on change
                if (previous != this.selectedDetail)
                {
                    this.selectedDetailInteraction = 0;
                }

                if (this.selectedDetail != null)
                {
                    // Detail interaction selection with moues wheel.
                    int c = this.selectedDetail.Interactions.Count;
                    if (c > 1)
                    {
                        if (input.MouseWheel > 0)
                        {
                            this.selectedDetailInteraction -= 1;
                        }
                        if (input.MouseWheel < 0)
                        {
                            this.selectedDetailInteraction += 1;
                        }

                        while (this.selectedDetailInteraction < 0)
                        {
                            this.selectedDetailInteraction += c;
                        }
                        while (this.selectedDetailInteraction >= c)
                        {
                            this.selectedDetailInteraction -= c;
                        }
                    }

                    // Detail interaction with Key.E
                    if (input.GetButtonDown(Key.E))
                    {
                        if (this.selectedDetail.Interactions.Count > 0)
                        {
                            this.Server.TriggerInteraction(
                                this.selectedDetail,
                                this.selectedDetail.Interactions[this.selectedDetailInteraction]);
                        }
                    }
                }
            }
            lock (typeof(World))
            {
                this.world.Step((float)time, true);
            }

            this.networkUpdateCounter++;
            if (this.networkUpdateCounter > 5)
            {
                this.sender.SetPlayer(this.player.FeetPosition, this.player.BodyRotation);
                this.networkUpdateCounter = 0;
            }
        }
        public override void UpdateFrame(IGameInputDriver input, double time)
        {
            Application.DoEvents();

            // Move camera
            if (input.GetMouse(OpenTK.Input.MouseButton.Right))
            {
                this.pan -= input.MouseMovement.X;
                this.tilt -= input.MouseMovement.Y;
                this.tilt = MathHelper.Clamp(this.tilt, -89, 89);
            }

            this.camera.Eye = this.camera.Target - 8.0f * this.GetCameraDirection();
        }
Example #6
0
 public virtual void UpdateFrame(IGameInputDriver input, double time)
 {
 }
Example #7
0
 public void UpdateFrame(IGameInputDriver input, double time)
 {
     // TODO: Implement nicer interpolation
     this.CurrentPosition     = Vector3.Lerp(this.CurrentPosition, this.SetpointPosition, 0.2f);
     this.CurrentBodyRotation = 0.8f * this.CurrentBodyRotation + 0.2f * this.SetpointBodyRotation;
 }
Example #8
0
 public virtual void UpdateFrame(IGameInputDriver input, double time)
 {
 }
Example #9
0
		public override void UpdateFrame(IGameInputDriver input, double time)
		{
			this.fps = (int)(1.0f / time);
			this.totalTime += time;

			this.network.Dispatch();

			foreach (var proxy in this.proxies)
				proxy.Value.UpdateFrame(input, time);

			if (input.GetButtonDown(Key.Q))
			{
				this.currentTool = (this.currentTool + 1) % this.tools.Count;
			}

			if (this.player != null)
			{
				this.player.Tool = this.tools[this.currentTool].Item2;
				this.player.UpdateFrame(input, time);

				var previous = this.selectedDetail;
				this.selectedDetail = null;
				this.visibleDetails.Clear();

				var from = this.player.Eye;
				foreach (var detail in this.world.Details)
				{
					// Ignore all details without interactions.
					// How stupid was I when i forgot this?
					if (detail.Interactions.Count == 0)
						continue;

					// Check for visibility with trace
					var to = detail.WorldPosition;
					var dir = (to - from).Normalized();

					var hit = this.world.Trace(from.Jitter(), dir.Jitter(), TraceOptions.IgnoreDynamic);

					if ((hit != null) && ((hit.Body?.Tag as DetailObject) != detail))
						continue;

					var dist = (detail.WorldPosition - from).Length;
					if (dist > 3.5f) // TODO: Implement settings value
						continue;

					var center = this.player.Camera.WorldToScreen(detail.WorldPosition, this.Aspect);
					if ((center.X < -0.6) || (center.X > 0.6))
						continue;
					/*
					Maybe opt in this later, but it should decrease usability of doors.
					if ((center.Y < -1.0) || (center.Y > 1.0))
                        continue;
					*/

					this.visibleDetails.Add(detail);


					if (this.selectedDetail != null)
					{
						var currentCenter = this.player.Camera.WorldToScreen(this.selectedDetail.WorldPosition, this.Aspect).Xy.Length;

						if (currentCenter < center.Xy.Length)
							continue;
					}
					this.selectedDetail = detail;
				}
				this.visibleDetails.Remove(this.selectedDetail);

				// Reset interaction on change
				if (previous != this.selectedDetail)
					this.selectedDetailInteraction = 0;

				if (this.selectedDetail != null)
				{

					// Detail interaction selection with moues wheel.
					int c = this.selectedDetail.Interactions.Count;
					if (c > 1)
					{
						if (input.MouseWheel > 0)
							this.selectedDetailInteraction -= 1;
						if (input.MouseWheel < 0)
							this.selectedDetailInteraction += 1;

						while (this.selectedDetailInteraction < 0)
							this.selectedDetailInteraction += c;
						while (this.selectedDetailInteraction >= c)
							this.selectedDetailInteraction -= c;
					}

					// Detail interaction with Key.E
					if (input.GetButtonDown(Key.E))
					{
						if (this.selectedDetail.Interactions.Count > 0)
						{
							this.Server.TriggerInteraction(
								this.selectedDetail,
								this.selectedDetail.Interactions[this.selectedDetailInteraction]);
						}
					}
				}

			}
			lock (typeof(World))
			{
				this.world.Step((float)time, true);
			}

			this.networkUpdateCounter++;
			if (this.networkUpdateCounter > 5)
			{
				this.sender.SetPlayer(this.player.FeetPosition, this.player.BodyRotation);
				this.networkUpdateCounter = 0;
			}
		}
Example #10
0
        public void UpdateFrame(IGameInputDriver input, double time)
        {
            this.camera.Pan  -= 0.5f * input.MouseMovement.X;
            this.camera.Tilt -= 0.5f * input.MouseMovement.Y;

            this.camera.Pan %= 360.0f;
            this.camera.Tilt = MathHelper.Clamp(this.camera.Tilt, -80, 80);

            Vector3 forward = Vector3.Zero;

            forward.X = 1.0f * (float)(Math.Sin(MathHelper.DegreesToRadians(this.camera.Pan)));
            forward.Y = 0.0f;
            forward.Z = 1.0f * (float)(Math.Cos(MathHelper.DegreesToRadians(this.camera.Pan)));

            Vector3 right = Vector3.Cross(forward, Vector3.UnitY);

            Vector3 move = Vector3.Zero;

            if (input.GetButton(Key.W))
            {
                move += forward;
            }
            if (input.GetButton(Key.S))
            {
                move -= forward;
            }
            if (input.GetButton(Key.D))
            {
                move += right;
            }
            if (input.GetButton(Key.A))
            {
                move -= right;
            }

            this.WalkSpeed = 10.0f * move.Jitter();

            if (input.GetButtonDown(Key.Space))
            {
                RaycastCallback callback = (b, n, f) =>
                {
                    return(b.IsStatic);
                };
                RigidBody body;
                JVector   normal;
                float     friction;

                if (this.world.CollisionSystem.Raycast(
                        this.Position,
                        new JVector(0, -1, 0),
                        callback,
                        out body,
                        out normal,
                        out friction))
                {
                    if (friction < 0.9f)
                    {
                        this.AddForce(new JVector(0, 200, 0));
                        Console.WriteLine("{0} {1} {2}", body, normal, friction);
                    }
                }
            }

            var origin    = this.camera.GetEye();
            var direction = this.camera.GetForward();

            if (input.GetMouseDown(MouseButton.Left))
            {
                this.Tool?.PrimaryUse(origin, direction);
            }

            if (input.GetMouseDown(MouseButton.Right))
            {
                this.Tool?.SecondaryUse(origin, direction);
            }
        }