public void Render(List <GameObject> terrains) { foreach (GameObject terrain in terrains) { var terrainComponent = terrain.GetComponent <Terrain>(); PrepareTerrain(terrainComponent); LoadModelMatrix(terrain); if (WireFrame.IsEnabled()) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } GL.DrawElements(BeginMode.Triangles, terrainComponent.model.vertexCount, DrawElementsType.UnsignedInt, 0); if (WireFrame.IsEnabled()) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } UnbindTexturedModel(); } }
public void Render(Dictionary <TexturedModel, List <GameObject> > entities) { foreach (TexturedModel model in entities.Keys) { entities.TryGetValue(model, out List <GameObject> batch); PrepareTexturedModel(model); foreach (GameObject entity in batch) { PrepareInstance(entity); if (WireFrame.IsEnabled()) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } GL.DrawElements(BeginMode.Triangles, model.rawModel.vertexCount, DrawElementsType.UnsignedInt, 0); if (WireFrame.IsEnabled()) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } } UnbindTexturedModel(); } }
private void Update(object sender, GameUpdatedEventArgs args) { if (!Focused) { return; } DebugScreenTexts(); if (Input.GetKeyDown(Key.Escape) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.Back)) { Exit(); } if (Input.GetKeyDown(Key.F) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadDown)) { FrameRate.Enable(!FrameRate.IsEnabled()); } if (Input.GetKeyDown(Key.Z) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadUp)) { WireFrame.Enable(!WireFrame.IsEnabled()); } if (Input.GetKeyDown(Key.Q) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadLeft)) { ProfilerScreen.enabled = !ProfilerScreen.enabled; text1.enabled = !text1.enabled; text2.enabled = !text2.enabled; } if (Input.GetKeyDown(Key.G) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.Start)) { Gaming = !Gaming; } if (Input.GetKeyDown(Key.V) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadRight)) { if (VSync == VSyncMode.Off) { VSync = VSyncMode.On; } else { VSync = VSyncMode.Off; } } if (Input.GetKeyDown(Key.L) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.LeftShoulder)) { Input.LockCursor(!Input.GetLockCursor()); Input.ShowCursor(!Input.GetCursorVisibility()); CameraFollowMouse = !CameraFollowMouse; if (Input.GetLockCursor()) { Input.SetMousePositionScreenCenter(0, 0); } } if (!Gaming) { const float cameraSpeed = 20.0f; if (Input.GetKey(Key.Space)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.ShiftLeft)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButton(Buttons.A)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButton(Buttons.B)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.A)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.D)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime * ControllerManager.GetController(0).GetAxis(Controller.Axis.HorizontalLeft); } if (Input.GetKey(Key.W)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.S)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime * ControllerManager.GetController(0).GetAxis(Controller.Axis.VerticalLeft); } if (CameraFollowMouse) { Vector2 delta = Input.GetMouseDelta(); var sensitivity = Camera.Sensitivity; if (ControllerManager.ControllerExists(0)) { var newDelta = ControllerManager.GetController(0).GetAxis(3, 4); if (Math.Abs(newDelta.X) + Math.Abs(newDelta.Y) > 0) { delta = newDelta; sensitivity = 100 * args.DeltaTime; } } if (Input.GetLockCursor()) { Input.SetMousePositionScreenCenter(0, 0); } MainCamera.gameObject.transform.Rotate(-delta.Y * sensitivity, -delta.X * sensitivity, 0); MainCamera.gameObject.transform.rotation = new Vector3(Math.Clamp(MainCamera.gameObject.transform.rotation.X, -89f, 89f), MainCamera.gameObject.transform.rotation.Y, MainCamera.gameObject.transform.rotation.Z); } } else { const float movementSpeed = 10.0f; var movement = Vector3.Zero; if (ControllerManager.ControllerExists(0)) { movement.Z = ControllerManager.GetController(0).GetAxis(Controller.Axis.VerticalLeft); } if (Input.GetKey(Key.W)) { movement.Z += 1; } if (Input.GetKey(Key.S)) { movement.Z -= 1; } if (ControllerManager.ControllerExists(0)) { movement.X = -ControllerManager.GetController(0).GetAxis(Controller.Axis.HorizontalLeft); } if (Input.GetKey(Key.A)) { movement.X += 1; } if (Input.GetKey(Key.D)) { movement.X -= 1; } if (CameraFollowMouse) { Vector2 delta = Input.GetMouseDelta(); if (ControllerManager.ControllerExists(0)) { var newDelta = ControllerManager.GetController(0).GetAxis(2, 3); if (Math.Abs(newDelta.X) > 0) { delta = newDelta; } } if (Input.GetLockCursor()) { Input.SetMousePositionScreenCenter(0, 0); } // if (delta.X < 0) MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Right * 10 * args.DeltaTime; // if (delta.X > 0) MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Right * 10 * args.DeltaTime; // MainCamera.gameObject.transform.LookAt(player.transform.position); } else { if (movement.Z != 0 || movement.X != 0) { var camForward = MainCamera.gameObject.transform.Front; camForward.Y = 0; camForward.Normalize(); var camRight = MainCamera.gameObject.transform.Right; camRight.Y = 0; camRight.Normalize(); if (!Targeting) { var direction = player.transform.position + (camForward * -movement.Z + camRight * movement.X).Normalized(); player.transform.RotateTowardsTarget(direction, args.DeltaTime * 5, 270); } else { player.transform.RotateTowardsTarget(target.transform.position, 1, 90); } var movementVector = new Vector3(((camForward * -movement.Z + camRight * movement.X) * movementSpeed * args.DeltaTime).X, 0, ((camForward * -movement.Z + camRight * movement.X) * movementSpeed * args.DeltaTime).Z); player.transform.position -= movementVector; } var pos = player.transform.position; MainCamera.gameObject.transform.rotation = new Vector3(-15f, -180, MainCamera.gameObject.transform.rotation.Z); MainCamera.gameObject.transform.position = new Vector3(pos.X, pos.Y + 6, pos.Z - 7); } } }
private void Update(object sender, GameUpdatedEventArgs args) { if (!Focused) { return; } DebugScreenTexts(); if (lockToMouseObject != null) { if (Input.GetMouseButtonDown(MouseButton.Right)) { var component = lockToMouseObject.GetComponent <RaycastTarget>(); component.focused = false; component.onLoseFocus(); lockToMouseObject = null; return; } if (!Input.GetKey(Key.R)) { var mult = 5.25f; if (Input.GetKey(Key.Up)) { lockToMouseObject.transform.position += lockToMouseObject.transform.Up * args.DeltaTime * mult; } if (Input.GetKey(Key.Down)) { lockToMouseObject.transform.position -= lockToMouseObject.transform.Up * args.DeltaTime * mult; } if (Input.GetKey(Key.Left)) { lockToMouseObject.transform.position -= lockToMouseObject.transform.Right * args.DeltaTime * mult; } if (Input.GetKey(Key.Right)) { lockToMouseObject.transform.position += lockToMouseObject.transform.Right * args.DeltaTime * mult; } if (Input.GetKey(Key.ControlRight)) { lockToMouseObject.transform.position -= lockToMouseObject.transform.Front * args.DeltaTime * mult; } if (Input.GetKey(Key.ShiftRight)) { lockToMouseObject.transform.position += lockToMouseObject.transform.Front * args.DeltaTime * mult; } } else { var mult = 20; if (Input.GetKey(Key.Up)) { lockToMouseObject.transform.Rotate(lockToMouseObject.transform.Up * args.DeltaTime * mult); } if (Input.GetKey(Key.Down)) { lockToMouseObject.transform.Rotate(-lockToMouseObject.transform.Up * args.DeltaTime * mult); } if (Input.GetKey(Key.Left)) { lockToMouseObject.transform.Rotate(-lockToMouseObject.transform.Right * args.DeltaTime * mult); } if (Input.GetKey(Key.Right)) { lockToMouseObject.transform.Rotate(lockToMouseObject.transform.Right * args.DeltaTime * mult); } if (Input.GetKey(Key.ControlRight)) { lockToMouseObject.transform.Rotate(-lockToMouseObject.transform.Front * args.DeltaTime * mult); } if (Input.GetKey(Key.ShiftRight)) { lockToMouseObject.transform.Rotate(lockToMouseObject.transform.Front * args.DeltaTime * mult); } } } if (Input.GetKeyDown(Key.Escape) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.Back)) { Exit(); } if (Input.GetKeyDown(Key.F) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadDown)) { FrameRate.Enable(!FrameRate.IsEnabled()); } if (Input.GetKeyDown(Key.Z) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadUp)) { WireFrame.Enable(!WireFrame.IsEnabled()); } if (Input.GetKeyDown(Key.Q) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadLeft)) { ProfilerScreen.enabled = !ProfilerScreen.enabled; text1.enabled = !text1.enabled; text2.enabled = !text2.enabled; } if (Input.GetKeyDown(Key.V) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.DPadRight)) { if (VSync == VSyncMode.Off) { VSync = VSyncMode.On; } else { VSync = VSyncMode.Off; } } if (Input.GetKeyDown(Key.L) || ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButtonDown(Buttons.LeftShoulder)) { Input.LockCursor(!Input.GetLockCursor()); Input.ShowCursor(!Input.GetCursorVisibility()); CameraFollowMouse = !CameraFollowMouse; if (Input.GetLockCursor()) { Input.SetMousePositionScreenCenter(0, 0); } } const float cameraSpeed = 5; if (Input.GetKey(Key.Space)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.ShiftLeft)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButton(Buttons.A)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0) && ControllerManager.GetController(0).GetButton(Buttons.B)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Up * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.A)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.D)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Right * cameraSpeed * args.DeltaTime * ControllerManager.GetController(0).GetAxis(Controller.Axis.HorizontalLeft); } if (Input.GetKey(Key.W)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime; } if (Input.GetKey(Key.S)) { MainCamera.gameObject.transform.position -= MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime; } if (ControllerManager.ControllerExists(0)) { MainCamera.gameObject.transform.position += MainCamera.gameObject.transform.Front * cameraSpeed * args.DeltaTime * ControllerManager.GetController(0).GetAxis(Controller.Axis.VerticalLeft); } if (CameraFollowMouse) { Vector2 delta = Input.GetMouseDelta(); var sensitivity = Camera.Sensitivity; if (ControllerManager.ControllerExists(0)) { var newDelta = ControllerManager.GetController(0).GetAxis(3, 4); if (Math.Abs(newDelta.X) + Math.Abs(newDelta.Y) > 0) { delta = newDelta; sensitivity = 100 * args.DeltaTime; } } if (Input.GetLockCursor()) { Input.SetMousePositionScreenCenter(0, 0); } MainCamera.gameObject.transform.Rotate(-delta.Y * sensitivity, -delta.X * sensitivity, 0); MainCamera.gameObject.transform.rotation = new Vector3(Math.Clamp(MainCamera.gameObject.transform.rotation.X, -89f, 89f), MainCamera.gameObject.transform.rotation.Y, MainCamera.gameObject.transform.rotation.Z); } }