From e70ce181a059fe88383f1dbbc6088fe0b410189a Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Thu, 25 Apr 2024 19:14:23 -0300 Subject: [PATCH 01/73] Update respecto de la plantilla original --- .../Content/Models/tgc-logo/tgc-logo.fbx | 4 ++-- TGC.MonoGame.TP/TGCGame.cs | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/TGC.MonoGame.TP/Content/Models/tgc-logo/tgc-logo.fbx b/TGC.MonoGame.TP/Content/Models/tgc-logo/tgc-logo.fbx index c8f1e9a3d..6f066d809 100644 --- a/TGC.MonoGame.TP/Content/Models/tgc-logo/tgc-logo.fbx +++ b/TGC.MonoGame.TP/Content/Models/tgc-logo/tgc-logo.fbx @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fdbf27e227a1554da9653bee09022aa6d72978a971c6390f631e3e4c75c98cfe -size 386333 +oid sha256:af84a6d4a433db8f49c3895d534e37aacddf68b27f9611856e76a6052562fe3f +size 4751036 diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 9dc2241d4..1f006389d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -26,6 +26,10 @@ public TGCGame() { // Maneja la configuracion y la administracion del dispositivo grafico. Graphics = new GraphicsDeviceManager(this); + + Graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - 100; + Graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 100; + // Para que el juego sea pantalla completa se puede usar Graphics IsFullScreen. // Carpeta raiz donde va a estar toda la Media. Content.RootDirectory = "Content"; @@ -113,10 +117,12 @@ protected override void Update(GameTime gameTime) //Salgo del juego. Exit(); } - + // Basado en el tiempo que paso se va generando una rotacion. Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); + World = Matrix.CreateRotationY(Rotation); + base.Update(gameTime); } @@ -133,12 +139,10 @@ protected override void Draw(GameTime gameTime) Effect.Parameters["View"].SetValue(View); Effect.Parameters["Projection"].SetValue(Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - var rotationMatrix = Matrix.CreateRotationY(Rotation); foreach (var mesh in Model.Meshes) { - World = mesh.ParentBone.Transform * rotationMatrix; - Effect.Parameters["World"].SetValue(World); + Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); mesh.Draw(); } } From e615e91ef3f6995f9ee9124a01cce0ca59f3db03 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Thu, 25 Apr 2024 19:21:00 -0300 Subject: [PATCH 02/73] =?UTF-8?q?Fix=20de=20caracter=20extra=C3=B1o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 1f006389d..6a06032dc 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; From dd212ee98f1840cb65b143875679fc2ac8a6b196 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Thu, 25 Apr 2024 19:50:55 -0300 Subject: [PATCH 03/73] Agrego contenido provisto por la catedra --- TGC.MonoGame.TP/Content/Content.mgcb | 31 +++++++++++++++++++ .../Content/Models/sign/StreetSign.fbx | 3 ++ .../Content/Models/sign/textures/Sign.png | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 TGC.MonoGame.TP/Content/Models/sign/StreetSign.fbx create mode 100644 TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 0aac68293..0cbd63b8e 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -19,6 +19,37 @@ /processorParam:DebugMode=Auto /build:Effects/BasicShader.fx +#begin Models/sign/StreetSign.fbx +/importer:FbxImporter +/processor:ModelProcessor +/processorParam:ColorKeyColor=0,0,0,0 +/processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect +/processorParam:GenerateMipmaps=True +/processorParam:GenerateTangentFrames=False +/processorParam:PremultiplyTextureAlpha=True +/processorParam:PremultiplyVertexColors=True +/processorParam:ResizeTexturesToPowerOfTwo=False +/processorParam:RotationX=0 +/processorParam:RotationY=0 +/processorParam:RotationZ=0 +/processorParam:Scale=1 +/processorParam:SwapWindingOrder=False +/processorParam:TextureFormat=Compressed +/build:Models/sign/StreetSign.fbx + +#begin Models/sign/textures/Sign.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Models/sign/textures/Sign.png + #begin Models/tgc-logo/tgc-logo.fbx /importer:FbxImporter /processor:ModelProcessor diff --git a/TGC.MonoGame.TP/Content/Models/sign/StreetSign.fbx b/TGC.MonoGame.TP/Content/Models/sign/StreetSign.fbx new file mode 100644 index 000000000..abd2242ef --- /dev/null +++ b/TGC.MonoGame.TP/Content/Models/sign/StreetSign.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9686784f5cf865cc46966db96646dd045578cf963ac76ce1ecf5d83a2d7a302b +size 123564 diff --git a/TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png b/TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png new file mode 100644 index 000000000..519813bcf --- /dev/null +++ b/TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd02dd8e533bd0e49b2fb1fd08019c915c08dcaa7179b7a5b100968fd6f4dd83 +size 15308 From 818285121e3952909a819b9aaf43381514ed7d9f Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sat, 27 Apr 2024 19:17:54 -0300 Subject: [PATCH 04/73] Fix problema con Sign.png --- TGC.MonoGame.TP/Content/Content.mgcb | 2 +- TGC.MonoGame.TP/Content/Models/sign/{textures => }/Sign.png | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename TGC.MonoGame.TP/Content/Models/sign/{textures => }/Sign.png (100%) diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 0cbd63b8e..1d6b630b3 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -48,7 +48,7 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Models/sign/textures/Sign.png +/build:Models/sign/Sign.png #begin Models/tgc-logo/tgc-logo.fbx /importer:FbxImporter diff --git a/TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png b/TGC.MonoGame.TP/Content/Models/sign/Sign.png similarity index 100% rename from TGC.MonoGame.TP/Content/Models/sign/textures/Sign.png rename to TGC.MonoGame.TP/Content/Models/sign/Sign.png From 908562c097ff00da62f3e2083b28ade5320d1978 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sun, 28 Apr 2024 19:39:12 -0300 Subject: [PATCH 05/73] =?UTF-8?q?Primera=20iteraci=C3=B3n=20sobre=20una=20?= =?UTF-8?q?camara=20libre=20para=20navegar=20el=20mapa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Camera/Camera.cs | 97 ++++++ TGC.MonoGame.TP/Camera/FreeCamera.cs | 137 ++++++++ TGC.MonoGame.TP/Geometries/Arrow.cs | 177 +++++++++++ TGC.MonoGame.TP/Geometries/BezierPrimitive.cs | 181 +++++++++++ TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 93 ++++++ .../Geometries/CylinderPrimitive.cs | 106 +++++++ TGC.MonoGame.TP/Geometries/FullScreenQuad.cs | 74 +++++ .../Geometries/GeometricPrimitive.cs | 174 ++++++++++ TGC.MonoGame.TP/Geometries/SpherePrimitive.cs | 119 +++++++ TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs | 299 ++++++++++++++++++ .../Geometries/Textures/BoxPrimitive.cs | 260 +++++++++++++++ .../Geometries/Textures/QuadPrimitive.cs | 125 ++++++++ TGC.MonoGame.TP/Geometries/TorusPrimitive.cs | 78 +++++ .../Geometries/TrianglePrimitive.cs | 63 ++++ TGC.MonoGame.TP/TGCGame.cs | 58 +++- 15 files changed, 2038 insertions(+), 3 deletions(-) create mode 100644 TGC.MonoGame.TP/Camera/Camera.cs create mode 100644 TGC.MonoGame.TP/Camera/FreeCamera.cs create mode 100644 TGC.MonoGame.TP/Geometries/Arrow.cs create mode 100644 TGC.MonoGame.TP/Geometries/BezierPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CubePrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/FullScreenQuad.cs create mode 100644 TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/SpherePrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/TorusPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs diff --git a/TGC.MonoGame.TP/Camera/Camera.cs b/TGC.MonoGame.TP/Camera/Camera.cs new file mode 100644 index 000000000..6d7575ddb --- /dev/null +++ b/TGC.MonoGame.TP/Camera/Camera.cs @@ -0,0 +1,97 @@ +using Microsoft.Xna.Framework; + +namespace TGC.MonoGame.TP.Camera +{ + /// + /// The minimum behavior that a camera should have. + /// + public abstract class Camera + { + public const float DefaultFieldOfViewDegrees = MathHelper.PiOver4; + public const float DefaultNearPlaneDistance = 0.1f; + public const float DefaultFarPlaneDistance = 2000; + + public Camera(float aspectRatio, float nearPlaneDistance = DefaultNearPlaneDistance, + float farPlaneDistance = DefaultFarPlaneDistance) : this(aspectRatio, nearPlaneDistance, farPlaneDistance, + DefaultFieldOfViewDegrees) + { + } + + public Camera(float aspectRatio, float nearPlaneDistance, float farPlaneDistance, float fieldOfViewDegrees) + { + BuildProjection(aspectRatio, nearPlaneDistance, farPlaneDistance, fieldOfViewDegrees); + } + + /// + /// Aspect ratio, defined as view space width divided by height. + /// + public float AspectRatio { get; set; } + + /// + /// Distance to the far view plane. + /// + public float FarPlane { get; set; } + + /// + /// Field of view in the y direction, in radians. + /// + public float FieldOfView { get; set; } + + /// + /// Distance to the near view plane. + /// + public float NearPlane { get; set; } + + /// + /// Direction where the camera is looking. + /// + public Vector3 FrontDirection { get; set; } + + /// + /// The perspective projection matrix. + /// + public Matrix Projection { get; set; } + + /// + /// Position where the camera is located. + /// + public Vector3 Position { get; set; } + + /// + /// Represents the positive x-axis of the camera space. + /// + public Vector3 RightDirection { get; set; } + + /// + /// Vector up direction (may differ if the camera is reversed). + /// + public Vector3 UpDirection { get; set; } + + /// + /// The created view matrix. + /// + public Matrix View { get; set; } + + /// + /// Build a perspective projection matrix based on a field of view, aspect ratio, and near and far view plane + /// distances. + /// + /// The aspect ratio, defined as view space width divided by height. + /// The distance to the near view plane. + /// The distance to the far view plane. + /// The field of view in the y direction, in degrees. + public void BuildProjection(float aspectRatio, float nearPlaneDistance, float farPlaneDistance, + float fieldOfViewDegrees) + { + Projection = Matrix.CreatePerspectiveFieldOfView(fieldOfViewDegrees, aspectRatio, nearPlaneDistance, + farPlaneDistance); + } + + /// + /// Allows updating the internal state of the camera if this method is overwritten. + /// By default it does not perform any action. + /// + /// Holds the time state of a . + public abstract void Update(GameTime gameTime); + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Camera/FreeCamera.cs b/TGC.MonoGame.TP/Camera/FreeCamera.cs new file mode 100644 index 000000000..65bfba986 --- /dev/null +++ b/TGC.MonoGame.TP/Camera/FreeCamera.cs @@ -0,0 +1,137 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace TGC.MonoGame.TP.Camera +{ + internal class FreeCamera : Camera + { + private readonly bool lockMouse; + + private readonly Point screenCenter; + private bool changed; + + private Vector2 pastMousePosition; + private float pitch; + + // Angles + private float yaw = -90f; + + public FreeCamera(float aspectRatio, Vector3 position, Point screenCenter) : this(aspectRatio, position) + { + lockMouse = true; + this.screenCenter = screenCenter; + } + + public FreeCamera(float aspectRatio, Vector3 position) : base(aspectRatio) + { + Position = position; + pastMousePosition = Mouse.GetState().Position.ToVector2(); + UpdateCameraVectors(); + CalculateView(); + } + + public float MovementSpeed { get; set; } = 100f; + public float MouseSensitivity { get; set; } = 5f; + + private void CalculateView() + { + View = Matrix.CreateLookAt(Position, Position + FrontDirection, UpDirection); + } + + /// + public override void Update(GameTime gameTime) + { + var elapsedTime = (float) gameTime.ElapsedGameTime.TotalSeconds; + changed = false; + ProcessKeyboard(elapsedTime); + ProcessMouseMovement(elapsedTime); + + if (changed) + CalculateView(); + } + + private void ProcessKeyboard(float elapsedTime) + { + var keyboardState = Keyboard.GetState(); + + var currentMovementSpeed = MovementSpeed; + if (keyboardState.IsKeyDown(Keys.LeftShift)) + currentMovementSpeed *= 5f; + + if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left)) + { + Position += -RightDirection * currentMovementSpeed * elapsedTime; + changed = true; + } + + if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) + { + Position += RightDirection * currentMovementSpeed * elapsedTime; + changed = true; + } + + if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up)) + { + Position += FrontDirection * currentMovementSpeed * elapsedTime; + changed = true; + } + + if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down)) + { + Position += -FrontDirection * currentMovementSpeed * elapsedTime; + changed = true; + } + } + + private void ProcessMouseMovement(float elapsedTime) + { + var mouseState = Mouse.GetState(); + + if (mouseState.RightButton.Equals(ButtonState.Pressed)) + { + var mouseDelta = mouseState.Position.ToVector2() - pastMousePosition; + mouseDelta *= MouseSensitivity * elapsedTime; + + yaw -= mouseDelta.X; + pitch += mouseDelta.Y; + + if (pitch > 89.0f) + pitch = 89.0f; + if (pitch < -89.0f) + pitch = -89.0f; + + changed = true; + UpdateCameraVectors(); + + if (lockMouse) + { + Mouse.SetPosition(screenCenter.X, screenCenter.Y); + Mouse.SetCursor(MouseCursor.Crosshair); + } + else + { + Mouse.SetCursor(MouseCursor.Arrow); + } + } + + pastMousePosition = Mouse.GetState().Position.ToVector2(); + } + + private void UpdateCameraVectors() + { + // Calculate the new Front vector + Vector3 tempFront; + tempFront.X = MathF.Cos(MathHelper.ToRadians(yaw)) * MathF.Cos(MathHelper.ToRadians(pitch)); + tempFront.Y = MathF.Sin(MathHelper.ToRadians(pitch)); + tempFront.Z = MathF.Sin(MathHelper.ToRadians(yaw)) * MathF.Cos(MathHelper.ToRadians(pitch)); + + FrontDirection = Vector3.Normalize(tempFront); + + // Also re-calculate the Right and Up vector + // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement. + RightDirection = Vector3.Normalize(Vector3.Cross(FrontDirection, Vector3.Up)); + UpDirection = Vector3.Normalize(Vector3.Cross(RightDirection, FrontDirection)); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/Arrow.cs b/TGC.MonoGame.TP/Geometries/Arrow.cs new file mode 100644 index 000000000..c1173a695 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/Arrow.cs @@ -0,0 +1,177 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Text; + +namespace TGC.MonoGame.TP.Geometries +{ + public class Arrow + { + private readonly Vector3 ORIGINAL_DIR = Vector3.Up; + + private VertexBuffer VertexBuffer { get; set; } + + public Color BodyColor { get; set; } + + public Color HeadColor { get; set; } + + public float Thickness { get; set; } + + public Vector2 HeadSize { get; set; } + + private BasicEffect Effect { get; set; } + + public Vector3 FromPosition { get; set; } + + public Vector3 ToPosition { get; set; } + + public Arrow(GraphicsDevice device) + { + VertexBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, 54, BufferUsage.None); + + Thickness = 0.06f; + HeadSize = new Vector2(0.3f, 0.6f); + BodyColor = Color.Blue; + HeadColor = Color.LightBlue; + + Effect = new BasicEffect(device); + Effect.VertexColorEnabled = true; + Effect.TextureEnabled = false; + } + + + /// + /// Actualizar parámetros de la flecha en base a los valores configurados + /// + public void UpdateValues() + { + var vertices = new VertexPositionColor[54]; + + //Crear caja en vertical en Y con longitud igual al módulo de la recta. + var lineVec = Vector3.Subtract(FromPosition, ToPosition); + var lineLength = lineVec.Length(); + var min = new Vector3(-Thickness, 0, -Thickness); + var max = new Vector3(Thickness, lineLength, Thickness); + + // Front face + vertices[0] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); + vertices[1] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); + vertices[2] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); + vertices[3] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); + vertices[4] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); + vertices[5] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); + + // Back face (remember this is facing *away* from the camera, so vertices should be clockwise order) + vertices[6] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); + vertices[7] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); + vertices[8] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); + vertices[9] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); + vertices[10] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); + vertices[11] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); + + // Top face + vertices[12] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); + vertices[13] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); + vertices[14] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); + vertices[15] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); + vertices[16] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); + vertices[17] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); + + // Bottom face (remember this is facing *away* from the camera, so vertices should be clockwise order) + vertices[18] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); + vertices[19] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); + vertices[20] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); + vertices[21] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); + vertices[22] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); + vertices[23] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); + + // Left face + vertices[24] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); + vertices[25] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); + vertices[26] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); + vertices[27] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); + vertices[28] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); + vertices[29] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); + + // Right face (remember this is facing *away* from the camera, so vertices should be clockwise order) + vertices[30] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); + vertices[31] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); + vertices[32] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); + vertices[33] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); + vertices[34] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); + vertices[35] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); + + //Vertices del cuerpo de la flecha + var hMin = new Vector3(-HeadSize.X, lineLength, -HeadSize.X); + var hMax = new Vector3(HeadSize.X, lineLength + HeadSize.Y, HeadSize.X); + + //Bottom face + vertices[36] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); + vertices[37] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); + vertices[38] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); + vertices[39] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); + vertices[40] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); + vertices[41] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); + + //Left face + vertices[42] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); + vertices[43] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); + vertices[44] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); + + //Right face + vertices[45] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); + vertices[46] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); + vertices[47] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); + + //Back face + vertices[48] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); + vertices[49] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); + vertices[50] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); + + //Front face + vertices[51] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); + vertices[52] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); + vertices[53] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); + + //Obtener matriz de rotacion respecto del vector de la linea + lineVec.Normalize(); + var angle = MathF.Acos(Vector3.Dot(ORIGINAL_DIR, lineVec)); + var axisRotation = Vector3.Cross(ORIGINAL_DIR, lineVec); + axisRotation.Normalize(); + var t = Matrix.CreateFromAxisAngle(axisRotation, angle) * Matrix.CreateTranslation(FromPosition); + + //Transformar todos los puntos + for (var i = 0; i < vertices.Length; i++) + { + vertices[i].Position = Vector3.Transform(vertices[i].Position, t); + } + + //Cargar vertexBuffer + VertexBuffer.SetData(vertices); + } + + + public void Draw(Matrix world, Matrix view, Matrix projection) + { + Effect.World = world; + Effect.View = view; + Effect.Projection = projection; + + var graphicsDevice = Effect.GraphicsDevice; + graphicsDevice.SetVertexBuffer(VertexBuffer); + + foreach (var effectPass in Effect.CurrentTechnique.Passes) + { + effectPass.Apply(); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 18); + } + } + + public void Dispose() + { + Effect.Dispose(); + VertexBuffer.Dispose(); + } + } +} diff --git a/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs b/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs new file mode 100644 index 000000000..7f314542f --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs @@ -0,0 +1,181 @@ +#region File Description + +//----------------------------------------------------------------------------- +// BezierPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using System.Diagnostics; +using Microsoft.Xna.Framework; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Base class for primitives that are made out of cubic bezier patches (a type of curved surface). + /// This is used by the TeapotPrimitive. + /// + public abstract class BezierPrimitive : GeometricPrimitive + { + /// + /// Creates indices for a patch that is tessellated at the specified level. + /// + protected void CreatePatchIndices(int tessellation, bool isMirrored) + { + var stride = tessellation + 1; + + for (var i = 0; i < tessellation; i++) + for (var j = 0; j < tessellation; j++) + { + // Make a list of six index values (two triangles). + int[] indices = + { + i * stride + j, + (i + 1) * stride + j, + (i + 1) * stride + j + 1, + + i * stride + j, + (i + 1) * stride + j + 1, + i * stride + j + 1 + }; + + // If this patch is mirrored, reverse the indices to keep the correct winding order. + if (isMirrored) Array.Reverse(indices); + + // Create the indices. + foreach (var index in indices) AddIndex(CurrentVertex + index); + } + } + + /// + /// Creates vertices for a patch that is tessellated at the specified level. + /// + protected void CreatePatchVertices(Vector3[] patch, int tessellation, bool isMirrored) + { + Debug.Assert(patch.Length == 16); + + for (var i = 0; i <= tessellation; i++) + { + var ti = (float) i / tessellation; + + for (var j = 0; j <= tessellation; j++) + { + var tj = (float) j / tessellation; + + // Perform four horizontal bezier interpolations between the control points of this patch. + var p1 = Bezier(patch[0], patch[1], patch[2], patch[3], ti); + var p2 = Bezier(patch[4], patch[5], patch[6], patch[7], ti); + var p3 = Bezier(patch[8], patch[9], patch[10], patch[11], ti); + var p4 = Bezier(patch[12], patch[13], patch[14], patch[15], ti); + + // Perform a vertical interpolation between the results of the previous horizontal interpolations, to compute the position. + var position = Bezier(p1, p2, p3, p4, tj); + + // Perform another four bezier interpolations between the control points, but this time vertically rather than horizontally. + var q1 = Bezier(patch[0], patch[4], patch[8], patch[12], tj); + var q2 = Bezier(patch[1], patch[5], patch[9], patch[13], tj); + var q3 = Bezier(patch[2], patch[6], patch[10], patch[14], tj); + var q4 = Bezier(patch[3], patch[7], patch[11], patch[15], tj); + + // Compute vertical and horizontal tangent vectors. + var tangentA = BezierTangent(p1, p2, p3, p4, tj); + var tangentB = BezierTangent(q1, q2, q3, q4, ti); + + // Cross the two tangent vectors to compute the normal. + var normal = Vector3.Cross(tangentA, tangentB); + + if (normal.Length() > 0.0001f) + { + normal.Normalize(); + + // If this patch is mirrored, we must invert the normal. + if (isMirrored) + normal = -normal; + } + else + { + // In a tidy and well constructed bezier patch, the preceding normal computation will always work. + // But the classic teapot model is not tidy or well constructed! At the top and bottom of the teapot, + // it contains degenerate geometry where a patch has several control points in the same place, + // which causes the tangent computation to fail and produce a zero normal. + // We 'fix' these cases by just hard-coding a normal that points either straight up or straight down, + // depending on whether we are on the top or bottom of the teapot. + // This is not a robust solution for all possible degenerate bezier patches, but hey, + // it's good enough to make the teapot work correctly! + + if (position.Y > 0) + normal = Vector3.Up; + else + normal = Vector3.Down; + } + + // Create the vertex. + AddVertex(position, Color.BurlyWood, normal); + } + } + } + + /// + /// Performs a cubic bezier interpolation between four scalar control points, + /// returning the value at the specified time (t ranges 0 to 1). + /// + private static float Bezier(float p1, float p2, float p3, float p4, float t) + { + return p1 * (1 - t) * (1 - t) * (1 - t) + + p2 * 3 * t * (1 - t) * (1 - t) + + p3 * 3 * t * t * (1 - t) + + p4 * t * t * t; + } + + /// + /// Performs a cubic bezier interpolation between four Vector3 control points, + /// returning the value at the specified time (t ranges 0 to 1). + /// + private static Vector3 Bezier(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, float t) + { + var result = new Vector3(); + + result.X = Bezier(p1.X, p2.X, p3.X, p4.X, t); + result.Y = Bezier(p1.Y, p2.Y, p3.Y, p4.Y, t); + result.Z = Bezier(p1.Z, p2.Z, p3.Z, p4.Z, t); + + return result; + } + + /// + /// Computes the tangent of a cubic bezier curve at the specified time, when given four scalar control points. + /// + private static float BezierTangent(float p1, float p2, float p3, float p4, float t) + { + return p1 * (-1 + 2 * t - t * t) + + p2 * (1 - 4 * t + 3 * t * t) + + p3 * (2 * t - 3 * t * t) + + p4 * (t * t); + } + + /// + /// Computes the tangent of a cubic bezier curve at the specified time, when given four Vector3 control points. + /// This is used for calculating normals (by crossing the horizontal and vertical tangent vectors). + /// + private static Vector3 BezierTangent(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, float t) + { + var result = new Vector3(); + + result.X = BezierTangent(p1.X, p2.X, p3.X, p4.X, t); + result.Y = BezierTangent(p1.Y, p2.Y, p3.Y, p4.Y, t); + result.Z = BezierTangent(p1.Z, p2.Z, p3.Z, p4.Z, t); + + result.Normalize(); + + return result; + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs new file mode 100644 index 000000000..daa6bda3d --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -0,0 +1,93 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing cubes. + /// + public class CubePrimitive : GeometricPrimitive + { + public CubePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Color.White, + Color.White, Color.White, Color.White, Color.White) + { + } + + public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) : this(graphicsDevice, size, color, + color, color, color, color, color) + { + } + + /// + /// Constructs a new cube primitive, with the specified size. + /// + public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color1, Color color2, Color color3, + Color color4, Color color5, Color color6) + { + // A cube has six faces, each one pointing in a different direction. + Vector3[] normals = + { + // front normal + Vector3.UnitZ, + // back normal + -Vector3.UnitZ, + // right normal + Vector3.UnitX, + // left normal + -Vector3.UnitX, + // top normal + Vector3.UnitY, + // bottom normal + -Vector3.UnitY + }; + + Color[] colors = + { + color1, color2, color3, color4, color5, color6 + }; + + var i = 0; + // Create each face in turn. + foreach (var normal in normals) + { + // Get two vectors perpendicular to the face normal and to each other. + var side1 = new Vector3(normal.Y, normal.Z, normal.X); + var side2 = Vector3.Cross(normal, side1); + + // Six indices (two triangles) per face. + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 2); + AddIndex(CurrentVertex + 3); + + // Four vertices per face. + AddVertex((normal - side1 - side2) * size / 2, colors[i], normal); + AddVertex((normal - side1 + side2) * size / 2, colors[i], normal); + AddVertex((normal + side1 + side2) * size / 2, colors[i], normal); + AddVertex((normal + side1 - side2) * size / 2, colors[i], normal); + + i++; + } + + InitializePrimitive(graphicsDevice); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs b/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs new file mode 100644 index 000000000..efff9de85 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs @@ -0,0 +1,106 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CylinderPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing cylinders. + /// + public class CylinderPrimitive : GeometricPrimitive + { + /// + /// Constructs a new cylinder primitive, with the specified size and tessellation level. + /// + public CylinderPrimitive(GraphicsDevice graphicsDevice, float height = 1, float diameter = 1, + int tessellation = 32) + { + if (tessellation < 3) + throw new ArgumentOutOfRangeException(nameof(tessellation)); + + height /= 2; + + var radius = diameter / 2; + + // Create a ring of triangles around the outside of the cylinder. + for (var i = 0; i < tessellation; i++) + { + var normal = GetCircleVector(i, tessellation); + + AddVertex(normal * radius + Vector3.Up * height, Color.AliceBlue, normal); + AddVertex(normal * radius + Vector3.Down * height, Color.DarkGray, normal); + + AddIndex(i * 2); + AddIndex(i * 2 + 1); + AddIndex((i * 2 + 2) % (tessellation * 2)); + + AddIndex(i * 2 + 1); + AddIndex((i * 2 + 3) % (tessellation * 2)); + AddIndex((i * 2 + 2) % (tessellation * 2)); + } + + // Create flat triangle fan caps to seal the top and bottom. + CreateCap(tessellation, height, radius, Vector3.Up); + CreateCap(tessellation, height, radius, Vector3.Down); + + InitializePrimitive(graphicsDevice); + } + + /// + /// Helper method creates a triangle fan to close the ends of the cylinder. + /// + private void CreateCap(int tessellation, float height, float radius, Vector3 normal) + { + // Create cap indices. + for (var i = 0; i < tessellation - 2; i++) + if (normal.Y > 0) + { + AddIndex(CurrentVertex); + AddIndex(CurrentVertex + (i + 1) % tessellation); + AddIndex(CurrentVertex + (i + 2) % tessellation); + } + else + { + AddIndex(CurrentVertex); + AddIndex(CurrentVertex + (i + 2) % tessellation); + AddIndex(CurrentVertex + (i + 1) % tessellation); + } + + // Create cap vertices. + for (var i = 0; i < tessellation; i++) + { + var position = GetCircleVector(i, tessellation) * radius + normal * height; + + AddVertex(position, Color.Azure, normal); + } + } + + /// + /// Helper method computes a point on a circle. + /// + private static Vector3 GetCircleVector(int i, int tessellation) + { + var angle = i * MathHelper.TwoPi / tessellation; + + var dx = (float) Math.Cos(angle); + var dz = (float) Math.Sin(angle); + + return new Vector3(dx, 0, dz); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs b/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs new file mode 100644 index 000000000..9bef78006 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs @@ -0,0 +1,74 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TGC.MonoGame.TP.Geometries +{ + public class FullScreenQuad + { + private readonly GraphicsDevice device; + private IndexBuffer indexBuffer; + private VertexBuffer vertexBuffer; + + /// + /// Create a quad used in clip space + /// + /// Used to initialize and control the presentation of the graphics device. + public FullScreenQuad(GraphicsDevice device) + { + this.device = device; + CreateVertexBuffer(); + CreateIndexBuffer(); + } + + private void CreateVertexBuffer() + { + var vertices = new VertexPositionTexture[4]; + vertices[0].Position = new Vector3(-1f, -1f, 0f); + vertices[0].TextureCoordinate = new Vector2(0f, 1f); + vertices[1].Position = new Vector3(-1f, 1f, 0f); + vertices[1].TextureCoordinate = new Vector2(0f, 0f); + vertices[2].Position = new Vector3(1f, -1f, 0f); + vertices[2].TextureCoordinate = new Vector2(1f, 1f); + vertices[3].Position = new Vector3(1f, 1f, 0f); + vertices[3].TextureCoordinate = new Vector2(1f, 0f); + + vertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, 4, + BufferUsage.WriteOnly); + vertexBuffer.SetData(vertices); + } + + private void CreateIndexBuffer() + { + var indices = new ushort[6]; + + indices[0] = 0; + indices[1] = 1; + indices[2] = 3; + indices[3] = 0; + indices[4] = 3; + indices[5] = 2; + + indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); + indexBuffer.SetData(indices); + } + + + public void Draw(Effect effect) + { + device.SetVertexBuffer(vertexBuffer); + device.Indices = indexBuffer; + + foreach (var pass in effect.CurrentTechnique.Passes) + { + pass.Apply(); + device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2); + } + } + + public void Dispose() + { + vertexBuffer.Dispose(); + indexBuffer.Dispose(); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs new file mode 100644 index 000000000..5c87dbd0c --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -0,0 +1,174 @@ +#region File Description + +//----------------------------------------------------------------------------- +// GeometricPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Base class for simple geometric primitive models. This provides a vertex buffer, an index buffer, plus methods for + /// drawing the model. Classes for specific types of primitive (CubePrimitive, SpherePrimitive, etc.) are derived from + /// this common base, and use the AddVertex and AddIndex methods to specify their geometry. + /// + public abstract class GeometricPrimitive : IDisposable + { + #region Fields + + // During the process of constructing a primitive model, vertex and index data is stored on the CPU in these managed lists. + public List Vertices { get; } = new List(); + + public List Indices { get; } = new List(); + + // Once all the geometry has been specified, the InitializePrimitive method copies the vertex and index data into these buffers, + // which store it on the GPU ready for efficient rendering. + private VertexBuffer VertexBuffer { get; set; } + + private IndexBuffer IndexBuffer { get; set; } + public BasicEffect Effect { get; set; } + + #endregion Fields + + #region Initialization + + /// + /// Adds a new vertex to the primitive model. This should only be called during the initialization process, before + /// InitializePrimitive. + /// + protected void AddVertex(Vector3 position, Color color, Vector3 normal) + { + Vertices.Add(new VertexPositionColorNormal(position, color, normal)); + } + + /// + /// Adds a new index to the primitive model. This should only be called during the initialization process, before + /// InitializePrimitive. + /// + protected void AddIndex(int index) + { + if (index > ushort.MaxValue) + throw new ArgumentOutOfRangeException(nameof(index)); + + Indices.Add((ushort) index); + } + + /// + /// Queries the index of the current vertex. This starts at zero, and increments every time AddVertex is called. + /// + protected int CurrentVertex => Vertices.Count; + + /// + /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index + /// data into GPU format buffers, ready for efficient rendering. + /// + protected void InitializePrimitive(GraphicsDevice graphicsDevice) + { + // Create a vertex declaration, describing the format of our vertex data. + + // Create a vertex buffer, and copy our vertex data into it. + VertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColorNormal), Vertices.Count, + BufferUsage.None); + VertexBuffer.SetData(Vertices.ToArray()); + + // Create an index buffer, and copy our index data into it. + IndexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), Indices.Count, BufferUsage.None); + + IndexBuffer.SetData(Indices.ToArray()); + + // Create a BasicEffect, which will be used to render the primitive. + Effect = new BasicEffect(graphicsDevice); + Effect.VertexColorEnabled = true; + Effect.EnableDefaultLighting(); + } + + /// + /// Finalizer. + /// + ~GeometricPrimitive() + { + Dispose(false); + } + + /// + /// Frees resources used by this object. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Frees resources used by this object. + /// + protected virtual void Dispose(bool disposing) + { + if (!disposing) return; + VertexBuffer?.Dispose(); + IndexBuffer?.Dispose(); + Effect?.Dispose(); + } + + #endregion Initialization + + #region Draw + + /// + /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the + /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all + /// states are set to sensible values before you call it. + /// + /// Used to set and query effects, and to choose techniques. + public void Draw(Effect effect) + { + var graphicsDevice = effect.GraphicsDevice; + + // Set our vertex declaration, vertex buffer, and index buffer. + graphicsDevice.SetVertexBuffer(VertexBuffer); + + graphicsDevice.Indices = IndexBuffer; + + foreach (var effectPass in effect.CurrentTechnique.Passes) + { + effectPass.Apply(); + + var primitiveCount = Indices.Count / 3; + + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, primitiveCount); + } + } + + /// + /// Draw the box. + /// + /// The world matrix for this box. + /// The view matrix, normally from the camera. + /// The projection matrix, normally from the application. + public void Draw(Matrix world, Matrix view, Matrix projection) + { + // Set BasicEffect parameters. + Effect.World = world; + Effect.View = view; + Effect.Projection = projection; + + // Draw the model, using BasicEffect. + Draw(Effect); + } + + #endregion Draw + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs new file mode 100644 index 000000000..9d4e8bc93 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs @@ -0,0 +1,119 @@ +#region File Description + +//----------------------------------------------------------------------------- +// SpherePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing spheres. + /// + public class SpherePrimitive : GeometricPrimitive + { + /// + /// Constructs a new sphere primitive, with the specified size, tessellation level and white color. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Diameter of the sphere. + /// The number of times the surface triangles are subdivided. + public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter = 1, int tessellation = 16) : this( + graphicsDevice, diameter, tessellation, Color.White) + { + } + + /// + /// Constructs a new sphere primitive, with the specified size, tessellation level and color. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Diameter of the sphere. + /// The number of times the surface triangles are subdivided. + /// Color of the sphere. + public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessellation, Color color) + { + if (tessellation < 3) + throw new ArgumentOutOfRangeException("tessellation"); + + var verticalSegments = tessellation; + var horizontalSegments = tessellation * 2; + + var radius = diameter / 2; + + // Start with a single vertex at the bottom of the sphere. + AddVertex(Vector3.Down * radius, color, Vector3.Down); + + // Create rings of vertices at progressively higher latitudes. + for (var i = 0; i < verticalSegments - 1; i++) + { + var latitude = (i + 1) * MathHelper.Pi / + verticalSegments - MathHelper.PiOver2; + + var dy = (float) Math.Sin(latitude); + var dxz = (float) Math.Cos(latitude); + + // Create a single ring of vertices at this latitude. + for (var j = 0; j < horizontalSegments; j++) + { + var longitude = j * MathHelper.TwoPi / horizontalSegments; + + var dx = (float) Math.Cos(longitude) * dxz; + var dz = (float) Math.Sin(longitude) * dxz; + + var normal = new Vector3(dx, dy, dz); + + AddVertex(normal * radius, color, normal); + } + } + + // Finish with a single vertex at the top of the sphere. + AddVertex(Vector3.Up * radius, color, Vector3.Up); + + // Create a fan connecting the bottom vertex to the bottom latitude ring. + for (var i = 0; i < horizontalSegments; i++) + { + AddIndex(0); + AddIndex(1 + (i + 1) % horizontalSegments); + AddIndex(1 + i); + } + + // Fill the sphere body with triangles joining each pair of latitude rings. + for (var i = 0; i < verticalSegments - 2; i++) + for (var j = 0; j < horizontalSegments; j++) + { + var nextI = i + 1; + var nextJ = (j + 1) % horizontalSegments; + + AddIndex(1 + i * horizontalSegments + j); + AddIndex(1 + i * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + j); + + AddIndex(1 + i * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + j); + } + + // Create a fan connecting the top vertex to the top latitude ring. + for (var i = 0; i < horizontalSegments; i++) + { + AddIndex(CurrentVertex - 1); + AddIndex(CurrentVertex - 2 - (i + 1) % horizontalSegments); + AddIndex(CurrentVertex - 2 - i); + } + + InitializePrimitive(graphicsDevice); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs b/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs new file mode 100644 index 000000000..58b92bf8d --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs @@ -0,0 +1,299 @@ +#region File Description + +//----------------------------------------------------------------------------- +// TeapotPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using System.Diagnostics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing teapots. + /// This teapot model was created by Martin Newell and Jim Blinn in 1975. + /// It consists of ten cubic bezier patches, a type of curved surface which can be tessellated to create triangles at + /// various levels of detail. The use of curved surfaces allows a smoothly curved, visually interesting, and instantly + /// recognizable shape to be specified by a tiny amount of data, which made the teapot a popular test data set for + /// computer graphics researchers. It has been used in so many papers and demos that many graphics programmers have + /// come to think of it as a standard geometric primitive, right up there with cubes and spheres! + /// + public class TeapotPrimitive : BezierPrimitive + { + /// + /// Static data array defines the bezier patches that make up the teapot. + /// + private static readonly TeapotPatch[] TeapotPatches = + { + // Rim. + new TeapotPatch(true, new[] + { + 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 + }), + + // Body. + new TeapotPatch(true, new[] + { + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 + }), + + new TeapotPatch(true, new[] + { + 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 + }), + + // Lid. + new TeapotPatch(true, new[] + { + 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3 + }), + + new TeapotPatch(true, new[] + { + 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117 + }), + + // Handle. + new TeapotPatch(false, new[] + { + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56 + }), + + new TeapotPatch(false, new[] + { + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67 + }), + + // Spout. + new TeapotPatch(false, new[] + { + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83 + }), + + new TeapotPatch(false, new[] + { + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 + }), + + // Bottom. + new TeapotPatch(true, new[] + { + 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37 + }) + }; + + /// + /// Static array defines the control point positions that make up the teapot. + /// + private static readonly Vector3[] TeapotControlPoints = + { + new Vector3(0f, 0.345f, -0.05f), + new Vector3(-0.028f, 0.345f, -0.05f), + new Vector3(-0.05f, 0.345f, -0.028f), + new Vector3(-0.05f, 0.345f, -0f), + new Vector3(0f, 0.3028125f, -0.334375f), + new Vector3(-0.18725f, 0.3028125f, -0.334375f), + new Vector3(-0.334375f, 0.3028125f, -0.18725f), + new Vector3(-0.334375f, 0.3028125f, -0f), + new Vector3(0f, 0.3028125f, -0.359375f), + new Vector3(-0.20125f, 0.3028125f, -0.359375f), + new Vector3(-0.359375f, 0.3028125f, -0.20125f), + new Vector3(-0.359375f, 0.3028125f, -0f), + new Vector3(0f, 0.27f, -0.375f), + new Vector3(-0.21f, 0.27f, -0.375f), + new Vector3(-0.375f, 0.27f, -0.21f), + new Vector3(-0.375f, 0.27f, -0f), + new Vector3(0f, 0.13875f, -0.4375f), + new Vector3(-0.245f, 0.13875f, -0.4375f), + new Vector3(-0.4375f, 0.13875f, -0.245f), + new Vector3(-0.4375f, 0.13875f, -0f), + new Vector3(0f, 0.007499993f, -0.5f), + new Vector3(-0.28f, 0.007499993f, -0.5f), + new Vector3(-0.5f, 0.007499993f, -0.28f), + new Vector3(-0.5f, 0.007499993f, -0f), + new Vector3(0f, -0.105f, -0.5f), + new Vector3(-0.28f, -0.105f, -0.5f), + new Vector3(-0.5f, -0.105f, -0.28f), + new Vector3(-0.5f, -0.105f, -0f), + new Vector3(0f, -0.105f, 0.5f), + new Vector3(0f, -0.2175f, -0.5f), + new Vector3(-0.28f, -0.2175f, -0.5f), + new Vector3(-0.5f, -0.2175f, -0.28f), + new Vector3(-0.5f, -0.2175f, -0f), + new Vector3(0f, -0.27375f, -0.375f), + new Vector3(-0.21f, -0.27375f, -0.375f), + new Vector3(-0.375f, -0.27375f, -0.21f), + new Vector3(-0.375f, -0.27375f, -0f), + new Vector3(0f, -0.2925f, -0.375f), + new Vector3(-0.21f, -0.2925f, -0.375f), + new Vector3(-0.375f, -0.2925f, -0.21f), + new Vector3(-0.375f, -0.2925f, -0f), + new Vector3(0f, 0.17625f, 0.4f), + new Vector3(-0.075f, 0.17625f, 0.4f), + new Vector3(-0.075f, 0.2325f, 0.375f), + new Vector3(0f, 0.2325f, 0.375f), + new Vector3(0f, 0.17625f, 0.575f), + new Vector3(-0.075f, 0.17625f, 0.575f), + new Vector3(-0.075f, 0.2325f, 0.625f), + new Vector3(0f, 0.2325f, 0.625f), + new Vector3(0f, 0.17625f, 0.675f), + new Vector3(-0.075f, 0.17625f, 0.675f), + new Vector3(-0.075f, 0.2325f, 0.75f), + new Vector3(0f, 0.2325f, 0.75f), + new Vector3(0f, 0.12f, 0.675f), + new Vector3(-0.075f, 0.12f, 0.675f), + new Vector3(-0.075f, 0.12f, 0.75f), + new Vector3(0f, 0.12f, 0.75f), + new Vector3(0f, 0.06375f, 0.675f), + new Vector3(-0.075f, 0.06375f, 0.675f), + new Vector3(-0.075f, 0.007499993f, 0.75f), + new Vector3(0f, 0.007499993f, 0.75f), + new Vector3(0f, -0.04875001f, 0.625f), + new Vector3(-0.075f, -0.04875001f, 0.625f), + new Vector3(-0.075f, -0.09562501f, 0.6625f), + new Vector3(0f, -0.09562501f, 0.6625f), + new Vector3(-0.075f, -0.105f, 0.5f), + new Vector3(-0.075f, -0.18f, 0.475f), + new Vector3(0f, -0.18f, 0.475f), + new Vector3(0f, 0.02624997f, -0.425f), + new Vector3(-0.165f, 0.02624997f, -0.425f), + new Vector3(-0.165f, -0.18f, -0.425f), + new Vector3(0f, -0.18f, -0.425f), + new Vector3(0f, 0.02624997f, -0.65f), + new Vector3(-0.165f, 0.02624997f, -0.65f), + new Vector3(-0.165f, -0.12375f, -0.775f), + new Vector3(0f, -0.12375f, -0.775f), + new Vector3(0f, 0.195f, -0.575f), + new Vector3(-0.0625f, 0.195f, -0.575f), + new Vector3(-0.0625f, 0.17625f, -0.6f), + new Vector3(0f, 0.17625f, -0.6f), + new Vector3(0f, 0.27f, -0.675f), + new Vector3(-0.0625f, 0.27f, -0.675f), + new Vector3(-0.0625f, 0.27f, -0.825f), + new Vector3(0f, 0.27f, -0.825f), + new Vector3(0f, 0.28875f, -0.7f), + new Vector3(-0.0625f, 0.28875f, -0.7f), + new Vector3(-0.0625f, 0.2934375f, -0.88125f), + new Vector3(0f, 0.2934375f, -0.88125f), + new Vector3(0f, 0.28875f, -0.725f), + new Vector3(-0.0375f, 0.28875f, -0.725f), + new Vector3(-0.0375f, 0.298125f, -0.8625f), + new Vector3(0f, 0.298125f, -0.8625f), + new Vector3(0f, 0.27f, -0.7f), + new Vector3(-0.0375f, 0.27f, -0.7f), + new Vector3(-0.0375f, 0.27f, -0.8f), + new Vector3(0f, 0.27f, -0.8f), + new Vector3(0f, 0.4575f, -0f), + new Vector3(0f, 0.4575f, -0.2f), + new Vector3(-0.1125f, 0.4575f, -0.2f), + new Vector3(-0.2f, 0.4575f, -0.1125f), + new Vector3(-0.2f, 0.4575f, -0f), + new Vector3(0f, 0.3825f, -0f), + new Vector3(0f, 0.27f, -0.35f), + new Vector3(-0.196f, 0.27f, -0.35f), + new Vector3(-0.35f, 0.27f, -0.196f), + new Vector3(-0.35f, 0.27f, -0f), + new Vector3(0f, 0.3075f, -0.1f), + new Vector3(-0.056f, 0.3075f, -0.1f), + new Vector3(-0.1f, 0.3075f, -0.056f), + new Vector3(-0.1f, 0.3075f, -0f), + new Vector3(0f, 0.3075f, -0.325f), + new Vector3(-0.182f, 0.3075f, -0.325f), + new Vector3(-0.325f, 0.3075f, -0.182f), + new Vector3(-0.325f, 0.3075f, -0f), + new Vector3(0f, 0.27f, -0.325f), + new Vector3(-0.182f, 0.27f, -0.325f), + new Vector3(-0.325f, 0.27f, -0.182f), + new Vector3(-0.325f, 0.27f, -0f), + new Vector3(0f, -0.33f, -0f), + new Vector3(-0.1995f, -0.33f, -0.35625f), + new Vector3(0f, -0.31125f, -0.375f), + new Vector3(0f, -0.33f, -0.35625f), + new Vector3(-0.35625f, -0.33f, -0.1995f), + new Vector3(-0.375f, -0.31125f, -0f), + new Vector3(-0.35625f, -0.33f, -0f), + new Vector3(-0.21f, -0.31125f, -0.375f), + new Vector3(-0.375f, -0.31125f, -0.21f) + }; + + /// + /// Constructs a new teapot primitive, with the specified size and tessellation level. + /// + public TeapotPrimitive(GraphicsDevice graphicsDevice, float size = 1, int tessellation = 8) + { + if (tessellation < 1) + throw new ArgumentOutOfRangeException(nameof(tessellation)); + + foreach (var patch in TeapotPatches) + { + // Because the teapot is symmetrical from left to right, we only store data for one side, + // then tessellate each patch twice, mirroring in X. + TessellatePatch(patch, tessellation, new Vector3(size, size, size)); + TessellatePatch(patch, tessellation, new Vector3(-size, size, size)); + + if (patch.MirrorZ) + { + // Some parts of the teapot (the body, lid, and rim, but not the handle or spout) are also symmetrical from front to back, + // so we tessellate them four times, mirroring in Z as well as X. + TessellatePatch(patch, tessellation, new Vector3(size, size, -size)); + TessellatePatch(patch, tessellation, new Vector3(-size, size, -size)); + } + } + + InitializePrimitive(graphicsDevice); + } + + /// + /// Tessellates the specified bezier patch. + /// + private void TessellatePatch(TeapotPatch patch, int tessellation, Vector3 scale) + { + // Look up the 16 control points for this patch. + var controlPoints = new Vector3[16]; + + for (var i = 0; i < 16; i++) + { + var index = patch.Indices[i]; + controlPoints[i] = TeapotControlPoints[index] * scale; + } + + // Is this patch being mirrored? + var isMirrored = Math.Sign(scale.X) != Math.Sign(scale.Z); + + // Create the index and vertex data. + CreatePatchIndices(tessellation, isMirrored); + CreatePatchVertices(controlPoints, tessellation, isMirrored); + } + + /// + /// The teapot model consists of 10 bezier patches. Each patch has 16 control points, plus a flag indicating whether it + /// should be mirrored in the Z axis as well as in X (all of the teapot is symmetrical from left to right, but only + /// some parts are symmetrical from front to back). The control points are stored as integer indices into the + /// TeapotControlPoints array. + /// + private class TeapotPatch + { + public readonly int[] Indices; + public readonly bool MirrorZ; + + public TeapotPatch(bool mirrorZ, int[] indices) + { + Debug.Assert(indices.Length == 16); + + Indices = indices; + MirrorZ = mirrorZ; + } + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs b/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs new file mode 100644 index 000000000..33cfe3bc6 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs @@ -0,0 +1,260 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TGC.MonoGame.TP.Geometries.Textures +{ + /// + /// Textured 3D box or cube. + /// + public class BoxPrimitive + { + /// + /// Create a box with a center at the given point, with a size and a color in each vertex. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Size of the box. + /// The box texture. + public BoxPrimitive(GraphicsDevice graphicsDevice, Vector3 size, Texture2D texture) + { + Effect = new BasicEffect(graphicsDevice); + Effect.TextureEnabled = true; + Effect.Texture = texture; + Effect.EnableDefaultLighting(); + + CreateVertexBuffer(graphicsDevice, size); + CreateIndexBuffer(graphicsDevice); + } + + /// + /// Represents a list of 3D vertices to be streamed to the graphics device. + /// + private VertexBuffer Vertices { get; set; } + + /// + /// Describes the rendering order of the vertices in a vertex buffer. + /// + private IndexBuffer Indices { get; set; } + + /// + /// Built-in effect that supports optional texturing, vertex coloring, fog, and lighting. + /// + private BasicEffect Effect { get; } + + /// + /// Create a vertex buffer for the figure with the given information. + /// + /// The graphics device. + /// Size of the box. + private void CreateVertexBuffer(GraphicsDevice graphicsDevice, Vector3 size) + { + var x = size.X / 2; + var y = size.Y / 2; + var z = size.Z / 2; + + var positions = new Vector3[] + { + // Back face + new Vector3(x, -y, z), + new Vector3(-x, -y, z), + new Vector3(x, y, z), + new Vector3(-x, y, z), + + // Front face + new Vector3(x, y, -z), + new Vector3(-x, y, -z), + new Vector3(x, -y, -z), + new Vector3(-x, -y, -z), + + // Top face + new Vector3(x, y, z), + new Vector3(-x, y, z), + new Vector3(x, y, -z), + new Vector3(-x, y, -z), + + // Bottom face + new Vector3(x, -y, -z), + new Vector3(x, -y, z), + new Vector3(-x, -y, z), + new Vector3(-x, -y, -z), + + // Left face + new Vector3(-x, -y, z), + new Vector3(-x, y, z), + new Vector3(-x, y, -z), + new Vector3(-x, -y, -z), + + // Right face + new Vector3(x, -y, -z), + new Vector3(x, y, -z), + new Vector3(x, y, z), + new Vector3(x, -y, z), + }; + + var textureCoordinates = new Vector2[] + { + // Back face + Vector2.Zero, + Vector2.UnitX, + Vector2.UnitY, + Vector2.One, + + // Front face + Vector2.Zero, + Vector2.UnitX, + Vector2.UnitY, + Vector2.One, + + // Top face + Vector2.UnitX, + Vector2.One, + Vector2.Zero, + Vector2.UnitY, + + // Bottom face + Vector2.Zero, + Vector2.UnitX, + Vector2.One, + Vector2.UnitY, + + // Left face + Vector2.Zero, + Vector2.UnitY, + Vector2.One, + Vector2.UnitX, + + // Right face + Vector2.Zero, + Vector2.UnitY, + Vector2.One, + Vector2.UnitX, + }; + + var normals = new Vector3[] + { + // Back face + Vector3.Backward, + Vector3.Backward, + Vector3.Backward, + Vector3.Backward, + + // Front face + Vector3.Forward, + Vector3.Forward, + Vector3.Forward, + Vector3.Forward, + + // Top face + Vector3.Up, + Vector3.Up, + Vector3.Up, + Vector3.Up, + + // Bottom face + Vector3.Down, + Vector3.Down, + Vector3.Down, + Vector3.Down, + + // Left face + Vector3.Left, + Vector3.Left, + Vector3.Left, + Vector3.Left, + + // Right face + Vector3.Right, + Vector3.Right, + Vector3.Right, + Vector3.Right, + }; + + var vertices = new VertexPositionNormalTexture[positions.Length]; + + for (int index = 0; index < vertices.Length; index++) + vertices[index] = new VertexPositionNormalTexture(positions[index], normals[index], textureCoordinates[index]); + + + Vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, + BufferUsage.None); + Vertices.SetData(vertices); + } + + /// + /// Create an index buffer for the vertex buffer that the figure has. + /// + /// The graphics device. + private void CreateIndexBuffer(GraphicsDevice graphicsDevice) + { + var indices = new ushort[] + { + + // Back face + 1, 2, 0, + 1, 3, 2, + + // Front face + 5, 6, 4, + 5, 7, 6, + + // Top face + 9, 10, 8, + 9, 11, 10, + + // Bottom face + 12, 15, 13, + 13, 15, 14, + + // Left face + 17, 16, 19, + 17, 19, 18, + + // Right face + 20, 23, 21, + 21, 23, 22, + }; + + + Indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, + BufferUsage.None); + Indices.SetData(indices); + } + + /// + /// Draw the box. + /// + /// The world matrix for this box. + /// The view matrix, normally from the camera. + /// The projection matrix, normally from the application. + public void Draw(Matrix world, Matrix view, Matrix projection) + { + // Set BasicEffect parameters. + Effect.World = world; + Effect.View = view; + Effect.Projection = projection; + + // Draw the model, using BasicEffect. + Draw(Effect); + } + + /// + /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the + /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all + /// states are set to sensible values before you call it. + /// + /// Used to set and query effects, and to choose techniques. + public void Draw(Effect effect) + { + var graphicsDevice = effect.GraphicsDevice; + + // Set our vertex declaration, vertex buffer, and index buffer. + graphicsDevice.SetVertexBuffer(Vertices); + graphicsDevice.Indices = Indices; + + foreach (var effectPass in effect.CurrentTechnique.Passes) + { + effectPass.Apply(); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.IndexCount / 3); + } + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs b/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs new file mode 100644 index 000000000..97069b31e --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs @@ -0,0 +1,125 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TGC.MonoGame.TP.Geometries.Textures +{ + /// + /// The quad is like a plane but its made by two triangle and the surface is oriented in the XY plane of the local + /// coordinate space. + /// + public class QuadPrimitive + { + /// + /// Create a textured quad. + /// + /// Used to initialize and control the presentation of the graphics device. + public QuadPrimitive(GraphicsDevice graphicsDevice) + { + CreateVertexBuffer(graphicsDevice); + CreateIndexBuffer(graphicsDevice); + + Effect = new BasicEffect(graphicsDevice); + Effect.TextureEnabled = true; + Effect.EnableDefaultLighting(); + } + + /// + /// Represents a list of 3D vertices to be streamed to the graphics device. + /// + private VertexBuffer Vertices { get; set; } + + /// + /// Describes the rendering order of the vertices in a vertex buffer, using counter-clockwise winding. + /// + private IndexBuffer Indices { get; set; } + + + /// + /// Built-in effect that supports optional texturing, vertex coloring, fog, and lighting. + /// + public BasicEffect Effect { get; private set; } + + /// + /// Create a vertex buffer for the figure with the given information. + /// + /// Used to initialize and control the presentation of the graphics device. + private void CreateVertexBuffer(GraphicsDevice graphicsDevice) + { + // Set the position and texture coordinate for each vertex + // Normals point Up as the Quad is originally XZ aligned + + var textureCoordinateLowerLeft = Vector2.Zero; + var textureCoordinateLowerRight = Vector2.UnitX; + var textureCoordinateUpperLeft = Vector2.UnitY; + var textureCoordinateUpperRight = Vector2.One; + + var vertices = new[] + { + // Possitive X, Possitive Z + new VertexPositionNormalTexture(Vector3.UnitX + Vector3.UnitZ, Vector3.Up, textureCoordinateUpperRight), + // Possitive X, Negative Z + new VertexPositionNormalTexture(Vector3.UnitX - Vector3.UnitZ, Vector3.Up, textureCoordinateLowerRight), + // Negative X, Possitive Z + new VertexPositionNormalTexture(Vector3.UnitZ - Vector3.UnitX, Vector3.Up, textureCoordinateUpperLeft), + // Negative X, Negative Z + new VertexPositionNormalTexture(-Vector3.UnitX - Vector3.UnitZ, Vector3.Up, textureCoordinateLowerLeft) + }; + + Vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, + BufferUsage.WriteOnly); + Vertices.SetData(vertices); + } + + private void CreateIndexBuffer(GraphicsDevice graphicsDevice) + { + // Set the index buffer for each vertex, using clockwise winding + var indices = new ushort[] + { + 3, 1, 0, + 3, 0, 2, + }; + + Indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, + BufferUsage.WriteOnly); + Indices.SetData(indices); + } + + /// + /// Draw the Quad. + /// + /// The world matrix for this box. + /// The view matrix, normally from the camera. + /// The projection matrix, normally from the application. + public void Draw(Matrix world, Matrix view, Matrix projection) + { + // Set BasicEffect parameters. + Effect.World = world; + Effect.View = view; + Effect.Projection = projection; + + // Draw the model, using BasicEffect. + Draw(Effect); + } + + /// + /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the + /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all + /// states are set to sensible values before you call it. + /// + /// Used to set and query effects, and to choose techniques. + public void Draw(Effect effect) + { + var graphicsDevice = effect.GraphicsDevice; + + // Set our vertex declaration, vertex buffer, and index buffer. + graphicsDevice.SetVertexBuffer(Vertices); + graphicsDevice.Indices = Indices; + + foreach (var effectPass in effect.CurrentTechnique.Passes) + { + effectPass.Apply(); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.IndexCount / 3); + } + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs b/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs new file mode 100644 index 000000000..8c8944a17 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs @@ -0,0 +1,78 @@ +#region File Description + +//----------------------------------------------------------------------------- +// TorusPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing toruses. + /// + public class TorusPrimitive : GeometricPrimitive + { + /// + /// Constructs a new torus primitive, with the specified size and tessellation level. + /// + public TorusPrimitive(GraphicsDevice graphicsDevice, float diameter = 1, float thickness = 0.333f, + int tessellation = 32) + { + if (tessellation < 3) + throw new ArgumentOutOfRangeException(nameof(tessellation)); + + // First we loop around the main ring of the torus. + for (var i = 0; i < tessellation; i++) + { + var outerAngle = i * MathHelper.TwoPi / tessellation; + + // Create a transform matrix that will align geometry to slice perpendicularly though the current ring position. + var transform = Matrix.CreateTranslation(diameter / 2, 0, 0) * Matrix.CreateRotationY(outerAngle); + + // Now we loop along the other axis, around the side of the tube. + for (var j = 0; j < tessellation; j++) + { + var innerAngle = j * MathHelper.TwoPi / tessellation; + + var dx = (float) Math.Cos(innerAngle); + var dy = (float) Math.Sin(innerAngle); + + // Create a vertex. + var normal = new Vector3(dx, dy, 0); + var position = normal * thickness / 2; + + position = Vector3.Transform(position, transform); + normal = Vector3.TransformNormal(normal, transform); + + AddVertex(position, Color.DarkGray, normal); + + // And create indices for two triangles. + var nextI = (i + 1) % tessellation; + var nextJ = (j + 1) % tessellation; + + AddIndex(i * tessellation + j); + AddIndex(i * tessellation + nextJ); + AddIndex(nextI * tessellation + j); + + AddIndex(i * tessellation + nextJ); + AddIndex(nextI * tessellation + nextJ); + AddIndex(nextI * tessellation + j); + } + } + + InitializePrimitive(graphicsDevice); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs b/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs new file mode 100644 index 000000000..aba8c7a02 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs @@ -0,0 +1,63 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Triangle in a 3D world. + /// + public class TrianglePrimitive : GeometricPrimitive + { + /// + /// Create a triangle based on the vertices and colored white. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Vertex of the triangle. + /// Vertex of the triangle. + /// Vertex of the triangle. + public TrianglePrimitive(GraphicsDevice device, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3) : this( + device, vertex1, vertex2, vertex3, Color.White) + { + } + + /// + /// Create a triangle based on vertices and color. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Vertex of the triangle. + /// Vertex of the triangle. + /// Vertex of the triangle. + /// The color of the triangle. + public TrianglePrimitive(GraphicsDevice device, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, + Color vertexColor) : this(device, vertex1, vertex2, vertex3, vertexColor, vertexColor, vertexColor) + { + } + + /// + /// Create a triangle based on the vertices and a color for each one. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Vertex of the triangle. + /// Vertex of the triangle. + /// Vertex of the triangle. + /// The color of the vertex. + /// The color of the vertex. + /// The color of the vertex. + public TrianglePrimitive(GraphicsDevice graphicsDevice, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, + Color vertexColor1, Color vertexColor2, Color vertexColor3) + { + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + var normal = Vector3.Cross(vertex2 - vertex1, vertex3 - vertex2); + normal.Normalize(); + + AddVertex(vertex1, vertexColor1, normal); + AddVertex(vertex2, vertexColor2, normal); + AddVertex(vertex3, vertexColor3, normal); + + InitializePrimitive(graphicsDevice); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 6a06032dc..f2dcd9e50 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -2,6 +2,8 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.Camera; namespace TGC.MonoGame.TP { @@ -46,12 +48,39 @@ public TGCGame() private Matrix View { get; set; } private Matrix Projection { get; set; } + + + + private CubePrimitive Box { get; set; } + + private Vector3 BoxPosition { get; set; } + private float Yaw { get; set; } + private float Pitch { get; set; } + private float Roll { get; set; } + + + // Camera to draw the scene + private FreeCamera Camera { get; set; } + /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. /// Escribir aqui el codigo de inicializacion: el procesamiento que podemos pre calcular para nuestro juego. /// protected override void Initialize() { + + var size = GraphicsDevice.Viewport.Bounds.Size; + size.X /= 2; + size.Y /= 2; + Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.One * 100f, size); + + Box = new CubePrimitive(GraphicsDevice, 10, Color.DarkCyan, Color.DarkMagenta, Color.DarkGreen, + Color.MonoGameOrange, Color.Black, Color.DarkGray); + BoxPosition = Vector3.Zero; + + + + // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. // Apago el backface culling. @@ -110,6 +139,7 @@ protected override void LoadContent() protected override void Update(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. + Camera.Update(gameTime); // Capturar Input teclado if (Keyboard.GetState().IsKeyDown(Keys.Escape)) @@ -117,6 +147,11 @@ protected override void Update(GameTime gameTime) //Salgo del juego. Exit(); } + + var time = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); + Yaw += time * 0.4f; + Pitch += time * 0.8f; + Roll += time * 0.9f; // Basado en el tiempo que paso se va generando una rotacion. Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); @@ -136,15 +171,21 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.Clear(Color.Black); // Para dibujar le modelo necesitamos pasarle informacion que el efecto esta esperando. - Effect.Parameters["View"].SetValue(View); - Effect.Parameters["Projection"].SetValue(Projection); + Effect.Parameters["View"].SetValue(Camera.View); + Effect.Parameters["Projection"].SetValue(Camera.Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - foreach (var mesh in Model.Meshes) + foreach (var mesh in Model.Meshes) { Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); mesh.Draw(); } + + + DrawGeometry(Box, BoxPosition, Yaw, Pitch, Roll); + + + } /// @@ -157,5 +198,16 @@ protected override void UnloadContent() base.UnloadContent(); } + + private void DrawGeometry(GeometricPrimitive geometry, Vector3 position, float yaw, float pitch, float roll) + { + var effect = geometry.Effect; + + effect.World = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll) * Matrix.CreateTranslation(position); + effect.View = Camera.View; + effect.Projection = Camera.Projection; + + geometry.Draw(effect); + } } } \ No newline at end of file From c4ca2813522dfb36ee0dc3c865216860d6de22a5 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 20:42:08 -0300 Subject: [PATCH 06/73] Limpio cosas innecesarias para la camara --- TGC.MonoGame.TP/Geometries/Arrow.cs | 177 ----------- TGC.MonoGame.TP/Geometries/BezierPrimitive.cs | 181 ----------- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 93 ------ .../Geometries/CylinderPrimitive.cs | 106 ------- TGC.MonoGame.TP/Geometries/FullScreenQuad.cs | 74 ----- .../Geometries/GeometricPrimitive.cs | 174 ---------- TGC.MonoGame.TP/Geometries/SpherePrimitive.cs | 119 ------- TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs | 299 ------------------ .../Geometries/Textures/BoxPrimitive.cs | 260 --------------- .../Geometries/Textures/QuadPrimitive.cs | 125 -------- TGC.MonoGame.TP/Geometries/TorusPrimitive.cs | 78 ----- .../Geometries/TrianglePrimitive.cs | 63 ---- TGC.MonoGame.TP/TGCGame.cs | 32 +- 13 files changed, 1 insertion(+), 1780 deletions(-) delete mode 100644 TGC.MonoGame.TP/Geometries/Arrow.cs delete mode 100644 TGC.MonoGame.TP/Geometries/BezierPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/CubePrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/FullScreenQuad.cs delete mode 100644 TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/SpherePrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/TorusPrimitive.cs delete mode 100644 TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/Arrow.cs b/TGC.MonoGame.TP/Geometries/Arrow.cs deleted file mode 100644 index c1173a695..000000000 --- a/TGC.MonoGame.TP/Geometries/Arrow.cs +++ /dev/null @@ -1,177 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Text; - -namespace TGC.MonoGame.TP.Geometries -{ - public class Arrow - { - private readonly Vector3 ORIGINAL_DIR = Vector3.Up; - - private VertexBuffer VertexBuffer { get; set; } - - public Color BodyColor { get; set; } - - public Color HeadColor { get; set; } - - public float Thickness { get; set; } - - public Vector2 HeadSize { get; set; } - - private BasicEffect Effect { get; set; } - - public Vector3 FromPosition { get; set; } - - public Vector3 ToPosition { get; set; } - - public Arrow(GraphicsDevice device) - { - VertexBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, 54, BufferUsage.None); - - Thickness = 0.06f; - HeadSize = new Vector2(0.3f, 0.6f); - BodyColor = Color.Blue; - HeadColor = Color.LightBlue; - - Effect = new BasicEffect(device); - Effect.VertexColorEnabled = true; - Effect.TextureEnabled = false; - } - - - /// - /// Actualizar parámetros de la flecha en base a los valores configurados - /// - public void UpdateValues() - { - var vertices = new VertexPositionColor[54]; - - //Crear caja en vertical en Y con longitud igual al módulo de la recta. - var lineVec = Vector3.Subtract(FromPosition, ToPosition); - var lineLength = lineVec.Length(); - var min = new Vector3(-Thickness, 0, -Thickness); - var max = new Vector3(Thickness, lineLength, Thickness); - - // Front face - vertices[0] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); - vertices[1] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); - vertices[2] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); - vertices[3] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); - vertices[4] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); - vertices[5] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); - - // Back face (remember this is facing *away* from the camera, so vertices should be clockwise order) - vertices[6] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); - vertices[7] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); - vertices[8] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); - vertices[9] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); - vertices[10] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); - vertices[11] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); - - // Top face - vertices[12] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); - vertices[13] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); - vertices[14] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); - vertices[15] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); - vertices[16] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); - vertices[17] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); - - // Bottom face (remember this is facing *away* from the camera, so vertices should be clockwise order) - vertices[18] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); - vertices[19] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); - vertices[20] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); - vertices[21] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); - vertices[22] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); - vertices[23] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); - - // Left face - vertices[24] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); - vertices[25] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); - vertices[26] = new VertexPositionColor(new Vector3(min.X, min.Y, max.Z), BodyColor); - vertices[27] = new VertexPositionColor(new Vector3(min.X, max.Y, min.Z), BodyColor); - vertices[28] = new VertexPositionColor(new Vector3(min.X, min.Y, min.Z), BodyColor); - vertices[29] = new VertexPositionColor(new Vector3(min.X, max.Y, max.Z), BodyColor); - - // Right face (remember this is facing *away* from the camera, so vertices should be clockwise order) - vertices[30] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); - vertices[31] = new VertexPositionColor(new Vector3(max.X, min.Y, max.Z), BodyColor); - vertices[32] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); - vertices[33] = new VertexPositionColor(new Vector3(max.X, max.Y, min.Z), BodyColor); - vertices[34] = new VertexPositionColor(new Vector3(max.X, max.Y, max.Z), BodyColor); - vertices[35] = new VertexPositionColor(new Vector3(max.X, min.Y, min.Z), BodyColor); - - //Vertices del cuerpo de la flecha - var hMin = new Vector3(-HeadSize.X, lineLength, -HeadSize.X); - var hMax = new Vector3(HeadSize.X, lineLength + HeadSize.Y, HeadSize.X); - - //Bottom face - vertices[36] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); - vertices[37] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); - vertices[38] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); - vertices[39] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); - vertices[40] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); - vertices[41] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); - - //Left face - vertices[42] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); - vertices[43] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); - vertices[44] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); - - //Right face - vertices[45] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); - vertices[46] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); - vertices[47] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); - - //Back face - vertices[48] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMin.Z), HeadColor); - vertices[49] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); - vertices[50] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMin.Z), HeadColor); - - //Front face - vertices[51] = new VertexPositionColor(new Vector3(hMin.X, hMin.Y, hMax.Z), HeadColor); - vertices[52] = new VertexPositionColor(new Vector3(0, hMax.Y, 0), HeadColor); - vertices[53] = new VertexPositionColor(new Vector3(hMax.X, hMin.Y, hMax.Z), HeadColor); - - //Obtener matriz de rotacion respecto del vector de la linea - lineVec.Normalize(); - var angle = MathF.Acos(Vector3.Dot(ORIGINAL_DIR, lineVec)); - var axisRotation = Vector3.Cross(ORIGINAL_DIR, lineVec); - axisRotation.Normalize(); - var t = Matrix.CreateFromAxisAngle(axisRotation, angle) * Matrix.CreateTranslation(FromPosition); - - //Transformar todos los puntos - for (var i = 0; i < vertices.Length; i++) - { - vertices[i].Position = Vector3.Transform(vertices[i].Position, t); - } - - //Cargar vertexBuffer - VertexBuffer.SetData(vertices); - } - - - public void Draw(Matrix world, Matrix view, Matrix projection) - { - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; - - var graphicsDevice = Effect.GraphicsDevice; - graphicsDevice.SetVertexBuffer(VertexBuffer); - - foreach (var effectPass in Effect.CurrentTechnique.Passes) - { - effectPass.Apply(); - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 18); - } - } - - public void Dispose() - { - Effect.Dispose(); - VertexBuffer.Dispose(); - } - } -} diff --git a/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs b/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs deleted file mode 100644 index 7f314542f..000000000 --- a/TGC.MonoGame.TP/Geometries/BezierPrimitive.cs +++ /dev/null @@ -1,181 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// BezierPrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using System.Diagnostics; -using Microsoft.Xna.Framework; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Base class for primitives that are made out of cubic bezier patches (a type of curved surface). - /// This is used by the TeapotPrimitive. - /// - public abstract class BezierPrimitive : GeometricPrimitive - { - /// - /// Creates indices for a patch that is tessellated at the specified level. - /// - protected void CreatePatchIndices(int tessellation, bool isMirrored) - { - var stride = tessellation + 1; - - for (var i = 0; i < tessellation; i++) - for (var j = 0; j < tessellation; j++) - { - // Make a list of six index values (two triangles). - int[] indices = - { - i * stride + j, - (i + 1) * stride + j, - (i + 1) * stride + j + 1, - - i * stride + j, - (i + 1) * stride + j + 1, - i * stride + j + 1 - }; - - // If this patch is mirrored, reverse the indices to keep the correct winding order. - if (isMirrored) Array.Reverse(indices); - - // Create the indices. - foreach (var index in indices) AddIndex(CurrentVertex + index); - } - } - - /// - /// Creates vertices for a patch that is tessellated at the specified level. - /// - protected void CreatePatchVertices(Vector3[] patch, int tessellation, bool isMirrored) - { - Debug.Assert(patch.Length == 16); - - for (var i = 0; i <= tessellation; i++) - { - var ti = (float) i / tessellation; - - for (var j = 0; j <= tessellation; j++) - { - var tj = (float) j / tessellation; - - // Perform four horizontal bezier interpolations between the control points of this patch. - var p1 = Bezier(patch[0], patch[1], patch[2], patch[3], ti); - var p2 = Bezier(patch[4], patch[5], patch[6], patch[7], ti); - var p3 = Bezier(patch[8], patch[9], patch[10], patch[11], ti); - var p4 = Bezier(patch[12], patch[13], patch[14], patch[15], ti); - - // Perform a vertical interpolation between the results of the previous horizontal interpolations, to compute the position. - var position = Bezier(p1, p2, p3, p4, tj); - - // Perform another four bezier interpolations between the control points, but this time vertically rather than horizontally. - var q1 = Bezier(patch[0], patch[4], patch[8], patch[12], tj); - var q2 = Bezier(patch[1], patch[5], patch[9], patch[13], tj); - var q3 = Bezier(patch[2], patch[6], patch[10], patch[14], tj); - var q4 = Bezier(patch[3], patch[7], patch[11], patch[15], tj); - - // Compute vertical and horizontal tangent vectors. - var tangentA = BezierTangent(p1, p2, p3, p4, tj); - var tangentB = BezierTangent(q1, q2, q3, q4, ti); - - // Cross the two tangent vectors to compute the normal. - var normal = Vector3.Cross(tangentA, tangentB); - - if (normal.Length() > 0.0001f) - { - normal.Normalize(); - - // If this patch is mirrored, we must invert the normal. - if (isMirrored) - normal = -normal; - } - else - { - // In a tidy and well constructed bezier patch, the preceding normal computation will always work. - // But the classic teapot model is not tidy or well constructed! At the top and bottom of the teapot, - // it contains degenerate geometry where a patch has several control points in the same place, - // which causes the tangent computation to fail and produce a zero normal. - // We 'fix' these cases by just hard-coding a normal that points either straight up or straight down, - // depending on whether we are on the top or bottom of the teapot. - // This is not a robust solution for all possible degenerate bezier patches, but hey, - // it's good enough to make the teapot work correctly! - - if (position.Y > 0) - normal = Vector3.Up; - else - normal = Vector3.Down; - } - - // Create the vertex. - AddVertex(position, Color.BurlyWood, normal); - } - } - } - - /// - /// Performs a cubic bezier interpolation between four scalar control points, - /// returning the value at the specified time (t ranges 0 to 1). - /// - private static float Bezier(float p1, float p2, float p3, float p4, float t) - { - return p1 * (1 - t) * (1 - t) * (1 - t) + - p2 * 3 * t * (1 - t) * (1 - t) + - p3 * 3 * t * t * (1 - t) + - p4 * t * t * t; - } - - /// - /// Performs a cubic bezier interpolation between four Vector3 control points, - /// returning the value at the specified time (t ranges 0 to 1). - /// - private static Vector3 Bezier(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, float t) - { - var result = new Vector3(); - - result.X = Bezier(p1.X, p2.X, p3.X, p4.X, t); - result.Y = Bezier(p1.Y, p2.Y, p3.Y, p4.Y, t); - result.Z = Bezier(p1.Z, p2.Z, p3.Z, p4.Z, t); - - return result; - } - - /// - /// Computes the tangent of a cubic bezier curve at the specified time, when given four scalar control points. - /// - private static float BezierTangent(float p1, float p2, float p3, float p4, float t) - { - return p1 * (-1 + 2 * t - t * t) + - p2 * (1 - 4 * t + 3 * t * t) + - p3 * (2 * t - 3 * t * t) + - p4 * (t * t); - } - - /// - /// Computes the tangent of a cubic bezier curve at the specified time, when given four Vector3 control points. - /// This is used for calculating normals (by crossing the horizontal and vertical tangent vectors). - /// - private static Vector3 BezierTangent(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, float t) - { - var result = new Vector3(); - - result.X = BezierTangent(p1.X, p2.X, p3.X, p4.X, t); - result.Y = BezierTangent(p1.Y, p2.Y, p3.Y, p4.Y, t); - result.Z = BezierTangent(p1.Z, p2.Z, p3.Z, p4.Z, t); - - result.Normalize(); - - return result; - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs deleted file mode 100644 index daa6bda3d..000000000 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ /dev/null @@ -1,93 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// CubePrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Geometric primitive class for drawing cubes. - /// - public class CubePrimitive : GeometricPrimitive - { - public CubePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Color.White, - Color.White, Color.White, Color.White, Color.White) - { - } - - public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) : this(graphicsDevice, size, color, - color, color, color, color, color) - { - } - - /// - /// Constructs a new cube primitive, with the specified size. - /// - public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color1, Color color2, Color color3, - Color color4, Color color5, Color color6) - { - // A cube has six faces, each one pointing in a different direction. - Vector3[] normals = - { - // front normal - Vector3.UnitZ, - // back normal - -Vector3.UnitZ, - // right normal - Vector3.UnitX, - // left normal - -Vector3.UnitX, - // top normal - Vector3.UnitY, - // bottom normal - -Vector3.UnitY - }; - - Color[] colors = - { - color1, color2, color3, color4, color5, color6 - }; - - var i = 0; - // Create each face in turn. - foreach (var normal in normals) - { - // Get two vectors perpendicular to the face normal and to each other. - var side1 = new Vector3(normal.Y, normal.Z, normal.X); - var side2 = Vector3.Cross(normal, side1); - - // Six indices (two triangles) per face. - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 2); - AddIndex(CurrentVertex + 3); - - // Four vertices per face. - AddVertex((normal - side1 - side2) * size / 2, colors[i], normal); - AddVertex((normal - side1 + side2) * size / 2, colors[i], normal); - AddVertex((normal + side1 + side2) * size / 2, colors[i], normal); - AddVertex((normal + side1 - side2) * size / 2, colors[i], normal); - - i++; - } - - InitializePrimitive(graphicsDevice); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs b/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs deleted file mode 100644 index efff9de85..000000000 --- a/TGC.MonoGame.TP/Geometries/CylinderPrimitive.cs +++ /dev/null @@ -1,106 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// CylinderPrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Geometric primitive class for drawing cylinders. - /// - public class CylinderPrimitive : GeometricPrimitive - { - /// - /// Constructs a new cylinder primitive, with the specified size and tessellation level. - /// - public CylinderPrimitive(GraphicsDevice graphicsDevice, float height = 1, float diameter = 1, - int tessellation = 32) - { - if (tessellation < 3) - throw new ArgumentOutOfRangeException(nameof(tessellation)); - - height /= 2; - - var radius = diameter / 2; - - // Create a ring of triangles around the outside of the cylinder. - for (var i = 0; i < tessellation; i++) - { - var normal = GetCircleVector(i, tessellation); - - AddVertex(normal * radius + Vector3.Up * height, Color.AliceBlue, normal); - AddVertex(normal * radius + Vector3.Down * height, Color.DarkGray, normal); - - AddIndex(i * 2); - AddIndex(i * 2 + 1); - AddIndex((i * 2 + 2) % (tessellation * 2)); - - AddIndex(i * 2 + 1); - AddIndex((i * 2 + 3) % (tessellation * 2)); - AddIndex((i * 2 + 2) % (tessellation * 2)); - } - - // Create flat triangle fan caps to seal the top and bottom. - CreateCap(tessellation, height, radius, Vector3.Up); - CreateCap(tessellation, height, radius, Vector3.Down); - - InitializePrimitive(graphicsDevice); - } - - /// - /// Helper method creates a triangle fan to close the ends of the cylinder. - /// - private void CreateCap(int tessellation, float height, float radius, Vector3 normal) - { - // Create cap indices. - for (var i = 0; i < tessellation - 2; i++) - if (normal.Y > 0) - { - AddIndex(CurrentVertex); - AddIndex(CurrentVertex + (i + 1) % tessellation); - AddIndex(CurrentVertex + (i + 2) % tessellation); - } - else - { - AddIndex(CurrentVertex); - AddIndex(CurrentVertex + (i + 2) % tessellation); - AddIndex(CurrentVertex + (i + 1) % tessellation); - } - - // Create cap vertices. - for (var i = 0; i < tessellation; i++) - { - var position = GetCircleVector(i, tessellation) * radius + normal * height; - - AddVertex(position, Color.Azure, normal); - } - } - - /// - /// Helper method computes a point on a circle. - /// - private static Vector3 GetCircleVector(int i, int tessellation) - { - var angle = i * MathHelper.TwoPi / tessellation; - - var dx = (float) Math.Cos(angle); - var dz = (float) Math.Sin(angle); - - return new Vector3(dx, 0, dz); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs b/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs deleted file mode 100644 index 9bef78006..000000000 --- a/TGC.MonoGame.TP/Geometries/FullScreenQuad.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace TGC.MonoGame.TP.Geometries -{ - public class FullScreenQuad - { - private readonly GraphicsDevice device; - private IndexBuffer indexBuffer; - private VertexBuffer vertexBuffer; - - /// - /// Create a quad used in clip space - /// - /// Used to initialize and control the presentation of the graphics device. - public FullScreenQuad(GraphicsDevice device) - { - this.device = device; - CreateVertexBuffer(); - CreateIndexBuffer(); - } - - private void CreateVertexBuffer() - { - var vertices = new VertexPositionTexture[4]; - vertices[0].Position = new Vector3(-1f, -1f, 0f); - vertices[0].TextureCoordinate = new Vector2(0f, 1f); - vertices[1].Position = new Vector3(-1f, 1f, 0f); - vertices[1].TextureCoordinate = new Vector2(0f, 0f); - vertices[2].Position = new Vector3(1f, -1f, 0f); - vertices[2].TextureCoordinate = new Vector2(1f, 1f); - vertices[3].Position = new Vector3(1f, 1f, 0f); - vertices[3].TextureCoordinate = new Vector2(1f, 0f); - - vertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, 4, - BufferUsage.WriteOnly); - vertexBuffer.SetData(vertices); - } - - private void CreateIndexBuffer() - { - var indices = new ushort[6]; - - indices[0] = 0; - indices[1] = 1; - indices[2] = 3; - indices[3] = 0; - indices[4] = 3; - indices[5] = 2; - - indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indexBuffer.SetData(indices); - } - - - public void Draw(Effect effect) - { - device.SetVertexBuffer(vertexBuffer); - device.Indices = indexBuffer; - - foreach (var pass in effect.CurrentTechnique.Passes) - { - pass.Apply(); - device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2); - } - } - - public void Dispose() - { - vertexBuffer.Dispose(); - indexBuffer.Dispose(); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs deleted file mode 100644 index 5c87dbd0c..000000000 --- a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs +++ /dev/null @@ -1,174 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// GeometricPrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Base class for simple geometric primitive models. This provides a vertex buffer, an index buffer, plus methods for - /// drawing the model. Classes for specific types of primitive (CubePrimitive, SpherePrimitive, etc.) are derived from - /// this common base, and use the AddVertex and AddIndex methods to specify their geometry. - /// - public abstract class GeometricPrimitive : IDisposable - { - #region Fields - - // During the process of constructing a primitive model, vertex and index data is stored on the CPU in these managed lists. - public List Vertices { get; } = new List(); - - public List Indices { get; } = new List(); - - // Once all the geometry has been specified, the InitializePrimitive method copies the vertex and index data into these buffers, - // which store it on the GPU ready for efficient rendering. - private VertexBuffer VertexBuffer { get; set; } - - private IndexBuffer IndexBuffer { get; set; } - public BasicEffect Effect { get; set; } - - #endregion Fields - - #region Initialization - - /// - /// Adds a new vertex to the primitive model. This should only be called during the initialization process, before - /// InitializePrimitive. - /// - protected void AddVertex(Vector3 position, Color color, Vector3 normal) - { - Vertices.Add(new VertexPositionColorNormal(position, color, normal)); - } - - /// - /// Adds a new index to the primitive model. This should only be called during the initialization process, before - /// InitializePrimitive. - /// - protected void AddIndex(int index) - { - if (index > ushort.MaxValue) - throw new ArgumentOutOfRangeException(nameof(index)); - - Indices.Add((ushort) index); - } - - /// - /// Queries the index of the current vertex. This starts at zero, and increments every time AddVertex is called. - /// - protected int CurrentVertex => Vertices.Count; - - /// - /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index - /// data into GPU format buffers, ready for efficient rendering. - /// - protected void InitializePrimitive(GraphicsDevice graphicsDevice) - { - // Create a vertex declaration, describing the format of our vertex data. - - // Create a vertex buffer, and copy our vertex data into it. - VertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColorNormal), Vertices.Count, - BufferUsage.None); - VertexBuffer.SetData(Vertices.ToArray()); - - // Create an index buffer, and copy our index data into it. - IndexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), Indices.Count, BufferUsage.None); - - IndexBuffer.SetData(Indices.ToArray()); - - // Create a BasicEffect, which will be used to render the primitive. - Effect = new BasicEffect(graphicsDevice); - Effect.VertexColorEnabled = true; - Effect.EnableDefaultLighting(); - } - - /// - /// Finalizer. - /// - ~GeometricPrimitive() - { - Dispose(false); - } - - /// - /// Frees resources used by this object. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Frees resources used by this object. - /// - protected virtual void Dispose(bool disposing) - { - if (!disposing) return; - VertexBuffer?.Dispose(); - IndexBuffer?.Dispose(); - Effect?.Dispose(); - } - - #endregion Initialization - - #region Draw - - /// - /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the - /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all - /// states are set to sensible values before you call it. - /// - /// Used to set and query effects, and to choose techniques. - public void Draw(Effect effect) - { - var graphicsDevice = effect.GraphicsDevice; - - // Set our vertex declaration, vertex buffer, and index buffer. - graphicsDevice.SetVertexBuffer(VertexBuffer); - - graphicsDevice.Indices = IndexBuffer; - - foreach (var effectPass in effect.CurrentTechnique.Passes) - { - effectPass.Apply(); - - var primitiveCount = Indices.Count / 3; - - graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, primitiveCount); - } - } - - /// - /// Draw the box. - /// - /// The world matrix for this box. - /// The view matrix, normally from the camera. - /// The projection matrix, normally from the application. - public void Draw(Matrix world, Matrix view, Matrix projection) - { - // Set BasicEffect parameters. - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; - - // Draw the model, using BasicEffect. - Draw(Effect); - } - - #endregion Draw - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs deleted file mode 100644 index 9d4e8bc93..000000000 --- a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs +++ /dev/null @@ -1,119 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// SpherePrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Geometric primitive class for drawing spheres. - /// - public class SpherePrimitive : GeometricPrimitive - { - /// - /// Constructs a new sphere primitive, with the specified size, tessellation level and white color. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Diameter of the sphere. - /// The number of times the surface triangles are subdivided. - public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter = 1, int tessellation = 16) : this( - graphicsDevice, diameter, tessellation, Color.White) - { - } - - /// - /// Constructs a new sphere primitive, with the specified size, tessellation level and color. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Diameter of the sphere. - /// The number of times the surface triangles are subdivided. - /// Color of the sphere. - public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessellation, Color color) - { - if (tessellation < 3) - throw new ArgumentOutOfRangeException("tessellation"); - - var verticalSegments = tessellation; - var horizontalSegments = tessellation * 2; - - var radius = diameter / 2; - - // Start with a single vertex at the bottom of the sphere. - AddVertex(Vector3.Down * radius, color, Vector3.Down); - - // Create rings of vertices at progressively higher latitudes. - for (var i = 0; i < verticalSegments - 1; i++) - { - var latitude = (i + 1) * MathHelper.Pi / - verticalSegments - MathHelper.PiOver2; - - var dy = (float) Math.Sin(latitude); - var dxz = (float) Math.Cos(latitude); - - // Create a single ring of vertices at this latitude. - for (var j = 0; j < horizontalSegments; j++) - { - var longitude = j * MathHelper.TwoPi / horizontalSegments; - - var dx = (float) Math.Cos(longitude) * dxz; - var dz = (float) Math.Sin(longitude) * dxz; - - var normal = new Vector3(dx, dy, dz); - - AddVertex(normal * radius, color, normal); - } - } - - // Finish with a single vertex at the top of the sphere. - AddVertex(Vector3.Up * radius, color, Vector3.Up); - - // Create a fan connecting the bottom vertex to the bottom latitude ring. - for (var i = 0; i < horizontalSegments; i++) - { - AddIndex(0); - AddIndex(1 + (i + 1) % horizontalSegments); - AddIndex(1 + i); - } - - // Fill the sphere body with triangles joining each pair of latitude rings. - for (var i = 0; i < verticalSegments - 2; i++) - for (var j = 0; j < horizontalSegments; j++) - { - var nextI = i + 1; - var nextJ = (j + 1) % horizontalSegments; - - AddIndex(1 + i * horizontalSegments + j); - AddIndex(1 + i * horizontalSegments + nextJ); - AddIndex(1 + nextI * horizontalSegments + j); - - AddIndex(1 + i * horizontalSegments + nextJ); - AddIndex(1 + nextI * horizontalSegments + nextJ); - AddIndex(1 + nextI * horizontalSegments + j); - } - - // Create a fan connecting the top vertex to the top latitude ring. - for (var i = 0; i < horizontalSegments; i++) - { - AddIndex(CurrentVertex - 1); - AddIndex(CurrentVertex - 2 - (i + 1) % horizontalSegments); - AddIndex(CurrentVertex - 2 - i); - } - - InitializePrimitive(graphicsDevice); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs b/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs deleted file mode 100644 index 58b92bf8d..000000000 --- a/TGC.MonoGame.TP/Geometries/TeapotPrimitive.cs +++ /dev/null @@ -1,299 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// TeapotPrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using System.Diagnostics; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Geometric primitive class for drawing teapots. - /// This teapot model was created by Martin Newell and Jim Blinn in 1975. - /// It consists of ten cubic bezier patches, a type of curved surface which can be tessellated to create triangles at - /// various levels of detail. The use of curved surfaces allows a smoothly curved, visually interesting, and instantly - /// recognizable shape to be specified by a tiny amount of data, which made the teapot a popular test data set for - /// computer graphics researchers. It has been used in so many papers and demos that many graphics programmers have - /// come to think of it as a standard geometric primitive, right up there with cubes and spheres! - /// - public class TeapotPrimitive : BezierPrimitive - { - /// - /// Static data array defines the bezier patches that make up the teapot. - /// - private static readonly TeapotPatch[] TeapotPatches = - { - // Rim. - new TeapotPatch(true, new[] - { - 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 - }), - - // Body. - new TeapotPatch(true, new[] - { - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 - }), - - new TeapotPatch(true, new[] - { - 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 - }), - - // Lid. - new TeapotPatch(true, new[] - { - 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3 - }), - - new TeapotPatch(true, new[] - { - 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117 - }), - - // Handle. - new TeapotPatch(false, new[] - { - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56 - }), - - new TeapotPatch(false, new[] - { - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67 - }), - - // Spout. - new TeapotPatch(false, new[] - { - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83 - }), - - new TeapotPatch(false, new[] - { - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 - }), - - // Bottom. - new TeapotPatch(true, new[] - { - 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37 - }) - }; - - /// - /// Static array defines the control point positions that make up the teapot. - /// - private static readonly Vector3[] TeapotControlPoints = - { - new Vector3(0f, 0.345f, -0.05f), - new Vector3(-0.028f, 0.345f, -0.05f), - new Vector3(-0.05f, 0.345f, -0.028f), - new Vector3(-0.05f, 0.345f, -0f), - new Vector3(0f, 0.3028125f, -0.334375f), - new Vector3(-0.18725f, 0.3028125f, -0.334375f), - new Vector3(-0.334375f, 0.3028125f, -0.18725f), - new Vector3(-0.334375f, 0.3028125f, -0f), - new Vector3(0f, 0.3028125f, -0.359375f), - new Vector3(-0.20125f, 0.3028125f, -0.359375f), - new Vector3(-0.359375f, 0.3028125f, -0.20125f), - new Vector3(-0.359375f, 0.3028125f, -0f), - new Vector3(0f, 0.27f, -0.375f), - new Vector3(-0.21f, 0.27f, -0.375f), - new Vector3(-0.375f, 0.27f, -0.21f), - new Vector3(-0.375f, 0.27f, -0f), - new Vector3(0f, 0.13875f, -0.4375f), - new Vector3(-0.245f, 0.13875f, -0.4375f), - new Vector3(-0.4375f, 0.13875f, -0.245f), - new Vector3(-0.4375f, 0.13875f, -0f), - new Vector3(0f, 0.007499993f, -0.5f), - new Vector3(-0.28f, 0.007499993f, -0.5f), - new Vector3(-0.5f, 0.007499993f, -0.28f), - new Vector3(-0.5f, 0.007499993f, -0f), - new Vector3(0f, -0.105f, -0.5f), - new Vector3(-0.28f, -0.105f, -0.5f), - new Vector3(-0.5f, -0.105f, -0.28f), - new Vector3(-0.5f, -0.105f, -0f), - new Vector3(0f, -0.105f, 0.5f), - new Vector3(0f, -0.2175f, -0.5f), - new Vector3(-0.28f, -0.2175f, -0.5f), - new Vector3(-0.5f, -0.2175f, -0.28f), - new Vector3(-0.5f, -0.2175f, -0f), - new Vector3(0f, -0.27375f, -0.375f), - new Vector3(-0.21f, -0.27375f, -0.375f), - new Vector3(-0.375f, -0.27375f, -0.21f), - new Vector3(-0.375f, -0.27375f, -0f), - new Vector3(0f, -0.2925f, -0.375f), - new Vector3(-0.21f, -0.2925f, -0.375f), - new Vector3(-0.375f, -0.2925f, -0.21f), - new Vector3(-0.375f, -0.2925f, -0f), - new Vector3(0f, 0.17625f, 0.4f), - new Vector3(-0.075f, 0.17625f, 0.4f), - new Vector3(-0.075f, 0.2325f, 0.375f), - new Vector3(0f, 0.2325f, 0.375f), - new Vector3(0f, 0.17625f, 0.575f), - new Vector3(-0.075f, 0.17625f, 0.575f), - new Vector3(-0.075f, 0.2325f, 0.625f), - new Vector3(0f, 0.2325f, 0.625f), - new Vector3(0f, 0.17625f, 0.675f), - new Vector3(-0.075f, 0.17625f, 0.675f), - new Vector3(-0.075f, 0.2325f, 0.75f), - new Vector3(0f, 0.2325f, 0.75f), - new Vector3(0f, 0.12f, 0.675f), - new Vector3(-0.075f, 0.12f, 0.675f), - new Vector3(-0.075f, 0.12f, 0.75f), - new Vector3(0f, 0.12f, 0.75f), - new Vector3(0f, 0.06375f, 0.675f), - new Vector3(-0.075f, 0.06375f, 0.675f), - new Vector3(-0.075f, 0.007499993f, 0.75f), - new Vector3(0f, 0.007499993f, 0.75f), - new Vector3(0f, -0.04875001f, 0.625f), - new Vector3(-0.075f, -0.04875001f, 0.625f), - new Vector3(-0.075f, -0.09562501f, 0.6625f), - new Vector3(0f, -0.09562501f, 0.6625f), - new Vector3(-0.075f, -0.105f, 0.5f), - new Vector3(-0.075f, -0.18f, 0.475f), - new Vector3(0f, -0.18f, 0.475f), - new Vector3(0f, 0.02624997f, -0.425f), - new Vector3(-0.165f, 0.02624997f, -0.425f), - new Vector3(-0.165f, -0.18f, -0.425f), - new Vector3(0f, -0.18f, -0.425f), - new Vector3(0f, 0.02624997f, -0.65f), - new Vector3(-0.165f, 0.02624997f, -0.65f), - new Vector3(-0.165f, -0.12375f, -0.775f), - new Vector3(0f, -0.12375f, -0.775f), - new Vector3(0f, 0.195f, -0.575f), - new Vector3(-0.0625f, 0.195f, -0.575f), - new Vector3(-0.0625f, 0.17625f, -0.6f), - new Vector3(0f, 0.17625f, -0.6f), - new Vector3(0f, 0.27f, -0.675f), - new Vector3(-0.0625f, 0.27f, -0.675f), - new Vector3(-0.0625f, 0.27f, -0.825f), - new Vector3(0f, 0.27f, -0.825f), - new Vector3(0f, 0.28875f, -0.7f), - new Vector3(-0.0625f, 0.28875f, -0.7f), - new Vector3(-0.0625f, 0.2934375f, -0.88125f), - new Vector3(0f, 0.2934375f, -0.88125f), - new Vector3(0f, 0.28875f, -0.725f), - new Vector3(-0.0375f, 0.28875f, -0.725f), - new Vector3(-0.0375f, 0.298125f, -0.8625f), - new Vector3(0f, 0.298125f, -0.8625f), - new Vector3(0f, 0.27f, -0.7f), - new Vector3(-0.0375f, 0.27f, -0.7f), - new Vector3(-0.0375f, 0.27f, -0.8f), - new Vector3(0f, 0.27f, -0.8f), - new Vector3(0f, 0.4575f, -0f), - new Vector3(0f, 0.4575f, -0.2f), - new Vector3(-0.1125f, 0.4575f, -0.2f), - new Vector3(-0.2f, 0.4575f, -0.1125f), - new Vector3(-0.2f, 0.4575f, -0f), - new Vector3(0f, 0.3825f, -0f), - new Vector3(0f, 0.27f, -0.35f), - new Vector3(-0.196f, 0.27f, -0.35f), - new Vector3(-0.35f, 0.27f, -0.196f), - new Vector3(-0.35f, 0.27f, -0f), - new Vector3(0f, 0.3075f, -0.1f), - new Vector3(-0.056f, 0.3075f, -0.1f), - new Vector3(-0.1f, 0.3075f, -0.056f), - new Vector3(-0.1f, 0.3075f, -0f), - new Vector3(0f, 0.3075f, -0.325f), - new Vector3(-0.182f, 0.3075f, -0.325f), - new Vector3(-0.325f, 0.3075f, -0.182f), - new Vector3(-0.325f, 0.3075f, -0f), - new Vector3(0f, 0.27f, -0.325f), - new Vector3(-0.182f, 0.27f, -0.325f), - new Vector3(-0.325f, 0.27f, -0.182f), - new Vector3(-0.325f, 0.27f, -0f), - new Vector3(0f, -0.33f, -0f), - new Vector3(-0.1995f, -0.33f, -0.35625f), - new Vector3(0f, -0.31125f, -0.375f), - new Vector3(0f, -0.33f, -0.35625f), - new Vector3(-0.35625f, -0.33f, -0.1995f), - new Vector3(-0.375f, -0.31125f, -0f), - new Vector3(-0.35625f, -0.33f, -0f), - new Vector3(-0.21f, -0.31125f, -0.375f), - new Vector3(-0.375f, -0.31125f, -0.21f) - }; - - /// - /// Constructs a new teapot primitive, with the specified size and tessellation level. - /// - public TeapotPrimitive(GraphicsDevice graphicsDevice, float size = 1, int tessellation = 8) - { - if (tessellation < 1) - throw new ArgumentOutOfRangeException(nameof(tessellation)); - - foreach (var patch in TeapotPatches) - { - // Because the teapot is symmetrical from left to right, we only store data for one side, - // then tessellate each patch twice, mirroring in X. - TessellatePatch(patch, tessellation, new Vector3(size, size, size)); - TessellatePatch(patch, tessellation, new Vector3(-size, size, size)); - - if (patch.MirrorZ) - { - // Some parts of the teapot (the body, lid, and rim, but not the handle or spout) are also symmetrical from front to back, - // so we tessellate them four times, mirroring in Z as well as X. - TessellatePatch(patch, tessellation, new Vector3(size, size, -size)); - TessellatePatch(patch, tessellation, new Vector3(-size, size, -size)); - } - } - - InitializePrimitive(graphicsDevice); - } - - /// - /// Tessellates the specified bezier patch. - /// - private void TessellatePatch(TeapotPatch patch, int tessellation, Vector3 scale) - { - // Look up the 16 control points for this patch. - var controlPoints = new Vector3[16]; - - for (var i = 0; i < 16; i++) - { - var index = patch.Indices[i]; - controlPoints[i] = TeapotControlPoints[index] * scale; - } - - // Is this patch being mirrored? - var isMirrored = Math.Sign(scale.X) != Math.Sign(scale.Z); - - // Create the index and vertex data. - CreatePatchIndices(tessellation, isMirrored); - CreatePatchVertices(controlPoints, tessellation, isMirrored); - } - - /// - /// The teapot model consists of 10 bezier patches. Each patch has 16 control points, plus a flag indicating whether it - /// should be mirrored in the Z axis as well as in X (all of the teapot is symmetrical from left to right, but only - /// some parts are symmetrical from front to back). The control points are stored as integer indices into the - /// TeapotControlPoints array. - /// - private class TeapotPatch - { - public readonly int[] Indices; - public readonly bool MirrorZ; - - public TeapotPatch(bool mirrorZ, int[] indices) - { - Debug.Assert(indices.Length == 16); - - Indices = indices; - MirrorZ = mirrorZ; - } - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs b/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs deleted file mode 100644 index 33cfe3bc6..000000000 --- a/TGC.MonoGame.TP/Geometries/Textures/BoxPrimitive.cs +++ /dev/null @@ -1,260 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace TGC.MonoGame.TP.Geometries.Textures -{ - /// - /// Textured 3D box or cube. - /// - public class BoxPrimitive - { - /// - /// Create a box with a center at the given point, with a size and a color in each vertex. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Size of the box. - /// The box texture. - public BoxPrimitive(GraphicsDevice graphicsDevice, Vector3 size, Texture2D texture) - { - Effect = new BasicEffect(graphicsDevice); - Effect.TextureEnabled = true; - Effect.Texture = texture; - Effect.EnableDefaultLighting(); - - CreateVertexBuffer(graphicsDevice, size); - CreateIndexBuffer(graphicsDevice); - } - - /// - /// Represents a list of 3D vertices to be streamed to the graphics device. - /// - private VertexBuffer Vertices { get; set; } - - /// - /// Describes the rendering order of the vertices in a vertex buffer. - /// - private IndexBuffer Indices { get; set; } - - /// - /// Built-in effect that supports optional texturing, vertex coloring, fog, and lighting. - /// - private BasicEffect Effect { get; } - - /// - /// Create a vertex buffer for the figure with the given information. - /// - /// The graphics device. - /// Size of the box. - private void CreateVertexBuffer(GraphicsDevice graphicsDevice, Vector3 size) - { - var x = size.X / 2; - var y = size.Y / 2; - var z = size.Z / 2; - - var positions = new Vector3[] - { - // Back face - new Vector3(x, -y, z), - new Vector3(-x, -y, z), - new Vector3(x, y, z), - new Vector3(-x, y, z), - - // Front face - new Vector3(x, y, -z), - new Vector3(-x, y, -z), - new Vector3(x, -y, -z), - new Vector3(-x, -y, -z), - - // Top face - new Vector3(x, y, z), - new Vector3(-x, y, z), - new Vector3(x, y, -z), - new Vector3(-x, y, -z), - - // Bottom face - new Vector3(x, -y, -z), - new Vector3(x, -y, z), - new Vector3(-x, -y, z), - new Vector3(-x, -y, -z), - - // Left face - new Vector3(-x, -y, z), - new Vector3(-x, y, z), - new Vector3(-x, y, -z), - new Vector3(-x, -y, -z), - - // Right face - new Vector3(x, -y, -z), - new Vector3(x, y, -z), - new Vector3(x, y, z), - new Vector3(x, -y, z), - }; - - var textureCoordinates = new Vector2[] - { - // Back face - Vector2.Zero, - Vector2.UnitX, - Vector2.UnitY, - Vector2.One, - - // Front face - Vector2.Zero, - Vector2.UnitX, - Vector2.UnitY, - Vector2.One, - - // Top face - Vector2.UnitX, - Vector2.One, - Vector2.Zero, - Vector2.UnitY, - - // Bottom face - Vector2.Zero, - Vector2.UnitX, - Vector2.One, - Vector2.UnitY, - - // Left face - Vector2.Zero, - Vector2.UnitY, - Vector2.One, - Vector2.UnitX, - - // Right face - Vector2.Zero, - Vector2.UnitY, - Vector2.One, - Vector2.UnitX, - }; - - var normals = new Vector3[] - { - // Back face - Vector3.Backward, - Vector3.Backward, - Vector3.Backward, - Vector3.Backward, - - // Front face - Vector3.Forward, - Vector3.Forward, - Vector3.Forward, - Vector3.Forward, - - // Top face - Vector3.Up, - Vector3.Up, - Vector3.Up, - Vector3.Up, - - // Bottom face - Vector3.Down, - Vector3.Down, - Vector3.Down, - Vector3.Down, - - // Left face - Vector3.Left, - Vector3.Left, - Vector3.Left, - Vector3.Left, - - // Right face - Vector3.Right, - Vector3.Right, - Vector3.Right, - Vector3.Right, - }; - - var vertices = new VertexPositionNormalTexture[positions.Length]; - - for (int index = 0; index < vertices.Length; index++) - vertices[index] = new VertexPositionNormalTexture(positions[index], normals[index], textureCoordinates[index]); - - - Vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, - BufferUsage.None); - Vertices.SetData(vertices); - } - - /// - /// Create an index buffer for the vertex buffer that the figure has. - /// - /// The graphics device. - private void CreateIndexBuffer(GraphicsDevice graphicsDevice) - { - var indices = new ushort[] - { - - // Back face - 1, 2, 0, - 1, 3, 2, - - // Front face - 5, 6, 4, - 5, 7, 6, - - // Top face - 9, 10, 8, - 9, 11, 10, - - // Bottom face - 12, 15, 13, - 13, 15, 14, - - // Left face - 17, 16, 19, - 17, 19, 18, - - // Right face - 20, 23, 21, - 21, 23, 22, - }; - - - Indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, - BufferUsage.None); - Indices.SetData(indices); - } - - /// - /// Draw the box. - /// - /// The world matrix for this box. - /// The view matrix, normally from the camera. - /// The projection matrix, normally from the application. - public void Draw(Matrix world, Matrix view, Matrix projection) - { - // Set BasicEffect parameters. - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; - - // Draw the model, using BasicEffect. - Draw(Effect); - } - - /// - /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the - /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all - /// states are set to sensible values before you call it. - /// - /// Used to set and query effects, and to choose techniques. - public void Draw(Effect effect) - { - var graphicsDevice = effect.GraphicsDevice; - - // Set our vertex declaration, vertex buffer, and index buffer. - graphicsDevice.SetVertexBuffer(Vertices); - graphicsDevice.Indices = Indices; - - foreach (var effectPass in effect.CurrentTechnique.Passes) - { - effectPass.Apply(); - graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.IndexCount / 3); - } - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs b/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs deleted file mode 100644 index 97069b31e..000000000 --- a/TGC.MonoGame.TP/Geometries/Textures/QuadPrimitive.cs +++ /dev/null @@ -1,125 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace TGC.MonoGame.TP.Geometries.Textures -{ - /// - /// The quad is like a plane but its made by two triangle and the surface is oriented in the XY plane of the local - /// coordinate space. - /// - public class QuadPrimitive - { - /// - /// Create a textured quad. - /// - /// Used to initialize and control the presentation of the graphics device. - public QuadPrimitive(GraphicsDevice graphicsDevice) - { - CreateVertexBuffer(graphicsDevice); - CreateIndexBuffer(graphicsDevice); - - Effect = new BasicEffect(graphicsDevice); - Effect.TextureEnabled = true; - Effect.EnableDefaultLighting(); - } - - /// - /// Represents a list of 3D vertices to be streamed to the graphics device. - /// - private VertexBuffer Vertices { get; set; } - - /// - /// Describes the rendering order of the vertices in a vertex buffer, using counter-clockwise winding. - /// - private IndexBuffer Indices { get; set; } - - - /// - /// Built-in effect that supports optional texturing, vertex coloring, fog, and lighting. - /// - public BasicEffect Effect { get; private set; } - - /// - /// Create a vertex buffer for the figure with the given information. - /// - /// Used to initialize and control the presentation of the graphics device. - private void CreateVertexBuffer(GraphicsDevice graphicsDevice) - { - // Set the position and texture coordinate for each vertex - // Normals point Up as the Quad is originally XZ aligned - - var textureCoordinateLowerLeft = Vector2.Zero; - var textureCoordinateLowerRight = Vector2.UnitX; - var textureCoordinateUpperLeft = Vector2.UnitY; - var textureCoordinateUpperRight = Vector2.One; - - var vertices = new[] - { - // Possitive X, Possitive Z - new VertexPositionNormalTexture(Vector3.UnitX + Vector3.UnitZ, Vector3.Up, textureCoordinateUpperRight), - // Possitive X, Negative Z - new VertexPositionNormalTexture(Vector3.UnitX - Vector3.UnitZ, Vector3.Up, textureCoordinateLowerRight), - // Negative X, Possitive Z - new VertexPositionNormalTexture(Vector3.UnitZ - Vector3.UnitX, Vector3.Up, textureCoordinateUpperLeft), - // Negative X, Negative Z - new VertexPositionNormalTexture(-Vector3.UnitX - Vector3.UnitZ, Vector3.Up, textureCoordinateLowerLeft) - }; - - Vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, - BufferUsage.WriteOnly); - Vertices.SetData(vertices); - } - - private void CreateIndexBuffer(GraphicsDevice graphicsDevice) - { - // Set the index buffer for each vertex, using clockwise winding - var indices = new ushort[] - { - 3, 1, 0, - 3, 0, 2, - }; - - Indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, - BufferUsage.WriteOnly); - Indices.SetData(indices); - } - - /// - /// Draw the Quad. - /// - /// The world matrix for this box. - /// The view matrix, normally from the camera. - /// The projection matrix, normally from the application. - public void Draw(Matrix world, Matrix view, Matrix projection) - { - // Set BasicEffect parameters. - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; - - // Draw the model, using BasicEffect. - Draw(Effect); - } - - /// - /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the - /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all - /// states are set to sensible values before you call it. - /// - /// Used to set and query effects, and to choose techniques. - public void Draw(Effect effect) - { - var graphicsDevice = effect.GraphicsDevice; - - // Set our vertex declaration, vertex buffer, and index buffer. - graphicsDevice.SetVertexBuffer(Vertices); - graphicsDevice.Indices = Indices; - - foreach (var effectPass in effect.CurrentTechnique.Passes) - { - effectPass.Apply(); - graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Indices.IndexCount / 3); - } - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs b/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs deleted file mode 100644 index 8c8944a17..000000000 --- a/TGC.MonoGame.TP/Geometries/TorusPrimitive.cs +++ /dev/null @@ -1,78 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// TorusPrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Geometric primitive class for drawing toruses. - /// - public class TorusPrimitive : GeometricPrimitive - { - /// - /// Constructs a new torus primitive, with the specified size and tessellation level. - /// - public TorusPrimitive(GraphicsDevice graphicsDevice, float diameter = 1, float thickness = 0.333f, - int tessellation = 32) - { - if (tessellation < 3) - throw new ArgumentOutOfRangeException(nameof(tessellation)); - - // First we loop around the main ring of the torus. - for (var i = 0; i < tessellation; i++) - { - var outerAngle = i * MathHelper.TwoPi / tessellation; - - // Create a transform matrix that will align geometry to slice perpendicularly though the current ring position. - var transform = Matrix.CreateTranslation(diameter / 2, 0, 0) * Matrix.CreateRotationY(outerAngle); - - // Now we loop along the other axis, around the side of the tube. - for (var j = 0; j < tessellation; j++) - { - var innerAngle = j * MathHelper.TwoPi / tessellation; - - var dx = (float) Math.Cos(innerAngle); - var dy = (float) Math.Sin(innerAngle); - - // Create a vertex. - var normal = new Vector3(dx, dy, 0); - var position = normal * thickness / 2; - - position = Vector3.Transform(position, transform); - normal = Vector3.TransformNormal(normal, transform); - - AddVertex(position, Color.DarkGray, normal); - - // And create indices for two triangles. - var nextI = (i + 1) % tessellation; - var nextJ = (j + 1) % tessellation; - - AddIndex(i * tessellation + j); - AddIndex(i * tessellation + nextJ); - AddIndex(nextI * tessellation + j); - - AddIndex(i * tessellation + nextJ); - AddIndex(nextI * tessellation + nextJ); - AddIndex(nextI * tessellation + j); - } - } - - InitializePrimitive(graphicsDevice); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs b/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs deleted file mode 100644 index aba8c7a02..000000000 --- a/TGC.MonoGame.TP/Geometries/TrianglePrimitive.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace TGC.MonoGame.TP.Geometries -{ - /// - /// Triangle in a 3D world. - /// - public class TrianglePrimitive : GeometricPrimitive - { - /// - /// Create a triangle based on the vertices and colored white. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Vertex of the triangle. - /// Vertex of the triangle. - /// Vertex of the triangle. - public TrianglePrimitive(GraphicsDevice device, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3) : this( - device, vertex1, vertex2, vertex3, Color.White) - { - } - - /// - /// Create a triangle based on vertices and color. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Vertex of the triangle. - /// Vertex of the triangle. - /// Vertex of the triangle. - /// The color of the triangle. - public TrianglePrimitive(GraphicsDevice device, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, - Color vertexColor) : this(device, vertex1, vertex2, vertex3, vertexColor, vertexColor, vertexColor) - { - } - - /// - /// Create a triangle based on the vertices and a color for each one. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Vertex of the triangle. - /// Vertex of the triangle. - /// Vertex of the triangle. - /// The color of the vertex. - /// The color of the vertex. - /// The color of the vertex. - public TrianglePrimitive(GraphicsDevice graphicsDevice, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, - Color vertexColor1, Color vertexColor2, Color vertexColor3) - { - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - var normal = Vector3.Cross(vertex2 - vertex1, vertex3 - vertex2); - normal.Normalize(); - - AddVertex(vertex1, vertexColor1, normal); - AddVertex(vertex2, vertexColor2, normal); - AddVertex(vertex3, vertexColor3, normal); - - InitializePrimitive(graphicsDevice); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index f2dcd9e50..57380df8b 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; -using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.Camera; namespace TGC.MonoGame.TP @@ -47,13 +46,7 @@ public TGCGame() private Matrix World { get; set; } private Matrix View { get; set; } private Matrix Projection { get; set; } - - - - private CubePrimitive Box { get; set; } - - private Vector3 BoxPosition { get; set; } private float Yaw { get; set; } private float Pitch { get; set; } private float Roll { get; set; } @@ -72,14 +65,7 @@ protected override void Initialize() var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; - Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.One * 100f, size); - - Box = new CubePrimitive(GraphicsDevice, 10, Color.DarkCyan, Color.DarkMagenta, Color.DarkGreen, - Color.MonoGameOrange, Color.Black, Color.DarkGray); - BoxPosition = Vector3.Zero; - - - + Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.UnitZ * 150f, size); // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. @@ -181,11 +167,6 @@ protected override void Draw(GameTime gameTime) mesh.Draw(); } - - DrawGeometry(Box, BoxPosition, Yaw, Pitch, Roll); - - - } /// @@ -198,16 +179,5 @@ protected override void UnloadContent() base.UnloadContent(); } - - private void DrawGeometry(GeometricPrimitive geometry, Vector3 position, float yaw, float pitch, float roll) - { - var effect = geometry.Effect; - - effect.World = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll) * Matrix.CreateTranslation(position); - effect.View = Camera.View; - effect.Projection = Camera.Projection; - - geometry.Draw(effect); - } } } \ No newline at end of file From 53355218fc90a4f34f4179b7928d94d4d016d1ce Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 20:45:09 -0300 Subject: [PATCH 07/73] Borro codigo que no va para la camara libre --- TGC.MonoGame.TP/TGCGame.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 57380df8b..5d09ce08a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -47,9 +47,6 @@ public TGCGame() private Matrix View { get; set; } private Matrix Projection { get; set; } - private float Yaw { get; set; } - private float Pitch { get; set; } - private float Roll { get; set; } // Camera to draw the scene @@ -134,10 +131,6 @@ protected override void Update(GameTime gameTime) Exit(); } - var time = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); - Yaw += time * 0.4f; - Pitch += time * 0.8f; - Roll += time * 0.9f; // Basado en el tiempo que paso se va generando una rotacion. Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); @@ -161,7 +154,7 @@ protected override void Draw(GameTime gameTime) Effect.Parameters["Projection"].SetValue(Camera.Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - foreach (var mesh in Model.Meshes) + foreach (var mesh in Model.Meshes) { Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); mesh.Draw(); From dfd31ce178eaad2f8e09fd39eae9141b1616a50f Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 19:03:02 -0300 Subject: [PATCH 08/73] Agrego lo necesario para crear un terreno plano basico --- TGC.MonoGame.TP/Environment/Terrain.cs | 74 ++++++++ .../Geometries/GeometricPrimitive.cs | 174 ++++++++++++++++++ TGC.MonoGame.TP/Geometries/SquarePrimitive.cs | 57 ++++++ TGC.MonoGame.TP/TGCGame.cs | 42 +++-- 4 files changed, 333 insertions(+), 14 deletions(-) create mode 100644 TGC.MonoGame.TP/Environment/Terrain.cs create mode 100644 TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/SquarePrimitive.cs diff --git a/TGC.MonoGame.TP/Environment/Terrain.cs b/TGC.MonoGame.TP/Environment/Terrain.cs new file mode 100644 index 000000000..63132baa9 --- /dev/null +++ b/TGC.MonoGame.TP/Environment/Terrain.cs @@ -0,0 +1,74 @@ +#region File Description + +//----------------------------------------------------------------------------- +// Terrain.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Geometries; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Environment { + /// + /// Basic primitive to build flat terrain using squares + /// + public class Terrain { + + private GraphicsDevice GraphicsDevice; + + private Vector3 FloorNormal = Vector3.Down; + private SquarePrimitive Square; + private List SquareMatrices; + + /// + /// Constructs a new terrain as a matrix of squares, with the specified square size, color, terrain width & length + /// + + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length) { + new Terrain(graphicsDevice, squareSize, color, width, length, Vector3.Zero); + } + + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length, Vector3 position) { + + GraphicsDevice = graphicsDevice; + Square = new SquarePrimitive(GraphicsDevice, squareSize, color, FloorNormal); + + // Create a list of places where the squares will be drawn + SquareMatrices = new List() { + Matrix.CreateTranslation(position) + }; + + for (int w = 0; w < width; w++) { + for (int l = 0; l < length; l++) { + if (width != 0 || length != 0) { + SquareMatrices.Add(Matrix.CreateTranslation((Vector3.Forward * l + Vector3.Right * w) * squareSize + position)); + } + } + } + + } + + public void Draw(Matrix view, Matrix projection) { + + foreach (var squareWorld in SquareMatrices) { + + var squareEffect = Square.Effect; + squareEffect.World = squareWorld; + squareEffect.View = view; + squareEffect.Projection = projection; + squareEffect.LightingEnabled = false; + Square.Draw(squareEffect); + } + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs new file mode 100644 index 000000000..5c87dbd0c --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -0,0 +1,174 @@ +#region File Description + +//----------------------------------------------------------------------------- +// GeometricPrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Base class for simple geometric primitive models. This provides a vertex buffer, an index buffer, plus methods for + /// drawing the model. Classes for specific types of primitive (CubePrimitive, SpherePrimitive, etc.) are derived from + /// this common base, and use the AddVertex and AddIndex methods to specify their geometry. + /// + public abstract class GeometricPrimitive : IDisposable + { + #region Fields + + // During the process of constructing a primitive model, vertex and index data is stored on the CPU in these managed lists. + public List Vertices { get; } = new List(); + + public List Indices { get; } = new List(); + + // Once all the geometry has been specified, the InitializePrimitive method copies the vertex and index data into these buffers, + // which store it on the GPU ready for efficient rendering. + private VertexBuffer VertexBuffer { get; set; } + + private IndexBuffer IndexBuffer { get; set; } + public BasicEffect Effect { get; set; } + + #endregion Fields + + #region Initialization + + /// + /// Adds a new vertex to the primitive model. This should only be called during the initialization process, before + /// InitializePrimitive. + /// + protected void AddVertex(Vector3 position, Color color, Vector3 normal) + { + Vertices.Add(new VertexPositionColorNormal(position, color, normal)); + } + + /// + /// Adds a new index to the primitive model. This should only be called during the initialization process, before + /// InitializePrimitive. + /// + protected void AddIndex(int index) + { + if (index > ushort.MaxValue) + throw new ArgumentOutOfRangeException(nameof(index)); + + Indices.Add((ushort) index); + } + + /// + /// Queries the index of the current vertex. This starts at zero, and increments every time AddVertex is called. + /// + protected int CurrentVertex => Vertices.Count; + + /// + /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index + /// data into GPU format buffers, ready for efficient rendering. + /// + protected void InitializePrimitive(GraphicsDevice graphicsDevice) + { + // Create a vertex declaration, describing the format of our vertex data. + + // Create a vertex buffer, and copy our vertex data into it. + VertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColorNormal), Vertices.Count, + BufferUsage.None); + VertexBuffer.SetData(Vertices.ToArray()); + + // Create an index buffer, and copy our index data into it. + IndexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), Indices.Count, BufferUsage.None); + + IndexBuffer.SetData(Indices.ToArray()); + + // Create a BasicEffect, which will be used to render the primitive. + Effect = new BasicEffect(graphicsDevice); + Effect.VertexColorEnabled = true; + Effect.EnableDefaultLighting(); + } + + /// + /// Finalizer. + /// + ~GeometricPrimitive() + { + Dispose(false); + } + + /// + /// Frees resources used by this object. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Frees resources used by this object. + /// + protected virtual void Dispose(bool disposing) + { + if (!disposing) return; + VertexBuffer?.Dispose(); + IndexBuffer?.Dispose(); + Effect?.Dispose(); + } + + #endregion Initialization + + #region Draw + + /// + /// Draws the primitive model, using the specified effect. Unlike the other Draw overload where you just specify the + /// world/view/projection matrices and color, this method does not set any render states, so you must make sure all + /// states are set to sensible values before you call it. + /// + /// Used to set and query effects, and to choose techniques. + public void Draw(Effect effect) + { + var graphicsDevice = effect.GraphicsDevice; + + // Set our vertex declaration, vertex buffer, and index buffer. + graphicsDevice.SetVertexBuffer(VertexBuffer); + + graphicsDevice.Indices = IndexBuffer; + + foreach (var effectPass in effect.CurrentTechnique.Passes) + { + effectPass.Apply(); + + var primitiveCount = Indices.Count / 3; + + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, primitiveCount); + } + } + + /// + /// Draw the box. + /// + /// The world matrix for this box. + /// The view matrix, normally from the camera. + /// The projection matrix, normally from the application. + public void Draw(Matrix world, Matrix view, Matrix projection) + { + // Set BasicEffect parameters. + Effect.World = world; + Effect.View = view; + Effect.Projection = projection; + + // Draw the model, using BasicEffect. + Draw(Effect); + } + + #endregion Draw + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs b/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs new file mode 100644 index 000000000..547211e84 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs @@ -0,0 +1,57 @@ +#region File Description + +//----------------------------------------------------------------------------- +// SquarePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + /// + /// Geometric primitive class for drawing squares. + /// + public class SquarePrimitive : GeometricPrimitive { + + public SquarePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Vector3.Up) {} + + /// + /// Constructs a new square primitive, with the specified size and color. + /// + public SquarePrimitive(GraphicsDevice graphicsDevice, float size, Color color, Vector3 faceNormal) { + + Vector3 normal = faceNormal; + + // Get two vectors perpendicular to the face normal and to each other. + var side1 = new Vector3(normal.Y, normal.Z, normal.X); + var side2 = Vector3.Cross(normal, side1); + + // Six indices (two triangles) per face. + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 2); + AddIndex(CurrentVertex + 3); + + // Four vertices per face. + AddVertex((normal - side1 - side2) * size / 2, color, normal); + AddVertex((normal - side1 + side2) * size / 2, color, normal); + AddVertex((normal + side1 + side2) * size / 2, color, normal); + AddVertex((normal + side1 - side2) * size / 2, color, normal); + + + InitializePrimitive(graphicsDevice); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 5d09ce08a..c7e018975 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using TGC.MonoGame.TP.Camera; +using TGC.MonoGame.TP.Environment; +using TGC.MonoGame.TP.Geometries; namespace TGC.MonoGame.TP { @@ -52,6 +55,13 @@ public TGCGame() // Camera to draw the scene private FreeCamera Camera { get; set; } + private SquarePrimitive Square { get; set; } + private Terrain Terrain { get; set; } + + private List SquareMatrices; + + private float SquareSize = 50f; + /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. /// Escribir aqui el codigo de inicializacion: el procesamiento que podemos pre calcular para nuestro juego. @@ -73,7 +83,9 @@ protected override void Initialize() rasterizerState.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rasterizerState; // Seria hasta aca. - + + Terrain = new Terrain(GraphicsDevice, SquareSize, Color.Brown, 4, 4); + // Configuramos nuestras matrices de la escena. World = Matrix.Identity; View = Matrix.CreateLookAt(Vector3.UnitZ * 150, Vector3.Zero, Vector3.Up); @@ -94,7 +106,8 @@ protected override void LoadContent() SpriteBatch = new SpriteBatch(GraphicsDevice); // Cargo el modelo del logo. - Model = Content.Load(ContentFolder3D + "tgc-logo/tgc-logo"); + //Model = Content.Load(ContentFolder3D + "wooden-floor/Floor"); + // Cargo un efecto basico propio declarado en el Content pipeline. // En el juego no pueden usar BasicEffect de MG, deben usar siempre efectos propios. @@ -102,14 +115,14 @@ protected override void LoadContent() // Asigno el efecto que cargue a cada parte del mesh. // Un modelo puede tener mas de 1 mesh internamente. - foreach (var mesh in Model.Meshes) - { + //foreach (var mesh in Model.Meshes) + //{ // Un mesh puede tener mas de 1 mesh part (cada 1 puede tener su propio efecto). - foreach (var meshPart in mesh.MeshParts) - { - meshPart.Effect = Effect; - } - } + // foreach (var meshPart in mesh.MeshParts) + //{ + // meshPart.Effect = Effect; + //} + //} base.LoadContent(); } @@ -133,9 +146,9 @@ protected override void Update(GameTime gameTime) // Basado en el tiempo que paso se va generando una rotacion. - Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); + //Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); - World = Matrix.CreateRotationY(Rotation); + //World = Matrix.CreateRotationY(Rotation); base.Update(gameTime); } @@ -154,12 +167,13 @@ protected override void Draw(GameTime gameTime) Effect.Parameters["Projection"].SetValue(Camera.Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - foreach (var mesh in Model.Meshes) + Terrain.Draw(View, Projection); + + /* foreach (var mesh in Model.Meshes) { Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); mesh.Draw(); - } - + }*/ } /// From a957449e85dc0f99e0b814735b358370b325b4dd Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 19:32:19 -0300 Subject: [PATCH 09/73] Arreglo un problema en el constructor de Terrain y agrego ejemplo de uso con desplazamiento --- TGC.MonoGame.TP/Environment/Terrain.cs | 7 +++---- TGC.MonoGame.TP/TGCGame.cs | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/TGC.MonoGame.TP/Environment/Terrain.cs b/TGC.MonoGame.TP/Environment/Terrain.cs index 63132baa9..6ceaec74c 100644 --- a/TGC.MonoGame.TP/Environment/Terrain.cs +++ b/TGC.MonoGame.TP/Environment/Terrain.cs @@ -34,10 +34,9 @@ public class Terrain { /// Constructs a new terrain as a matrix of squares, with the specified square size, color, terrain width & length /// - public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length) { - new Terrain(graphicsDevice, squareSize, color, width, length, Vector3.Zero); - } - + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length) : + this (graphicsDevice, squareSize, color, width, length, Vector3.Zero) {} + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length, Vector3 position) { GraphicsDevice = graphicsDevice; diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index c7e018975..b7d900129 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -55,10 +55,8 @@ public TGCGame() // Camera to draw the scene private FreeCamera Camera { get; set; } - private SquarePrimitive Square { get; set; } private Terrain Terrain { get; set; } - - private List SquareMatrices; + private Terrain Terrain2 { get; set; } private float SquareSize = 50f; @@ -84,7 +82,8 @@ protected override void Initialize() GraphicsDevice.RasterizerState = rasterizerState; // Seria hasta aca. - Terrain = new Terrain(GraphicsDevice, SquareSize, Color.Brown, 4, 4); + Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); + Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); // Configuramos nuestras matrices de la escena. World = Matrix.Identity; @@ -168,6 +167,7 @@ protected override void Draw(GameTime gameTime) Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); Terrain.Draw(View, Projection); + Terrain2.Draw(View, Projection); /* foreach (var mesh in Model.Meshes) { From e13563ac044dcec39856b2e85e94ca4fd727134c Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 19:54:46 -0300 Subject: [PATCH 10/73] Iterando para meter texturas en el piso --- TGC.MonoGame.TP/Content/Textures/floor/tiling-base.png | 3 +++ TGC.MonoGame.TP/Environment/Terrain.cs | 3 +++ TGC.MonoGame.TP/TGCGame.cs | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/Textures/floor/tiling-base.png diff --git a/TGC.MonoGame.TP/Content/Textures/floor/tiling-base.png b/TGC.MonoGame.TP/Content/Textures/floor/tiling-base.png new file mode 100644 index 000000000..49d930990 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/floor/tiling-base.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f974d040a7fce0df25aba0bf41903de012bad8d2978acc64bf157d2cf74d4ea +size 16799725 diff --git a/TGC.MonoGame.TP/Environment/Terrain.cs b/TGC.MonoGame.TP/Environment/Terrain.cs index 6ceaec74c..7cf4196ba 100644 --- a/TGC.MonoGame.TP/Environment/Terrain.cs +++ b/TGC.MonoGame.TP/Environment/Terrain.cs @@ -37,6 +37,9 @@ public class Terrain { public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length) : this (graphicsDevice, squareSize, color, width, length, Vector3.Zero) {} + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Texture2D texture, int width, int length) : + this (graphicsDevice, squareSize, Color.White, width, length, Vector3.Zero) {} + public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length, Vector3 position) { GraphicsDevice = graphicsDevice; diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index b7d900129..907a4928a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -81,9 +81,6 @@ protected override void Initialize() rasterizerState.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rasterizerState; // Seria hasta aca. - - Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); - Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); // Configuramos nuestras matrices de la escena. World = Matrix.Identity; @@ -123,6 +120,11 @@ protected override void LoadContent() //} //} + //var floorTexture = Content.Load(ContentFolderTextures + "floor/tiling-base"); + + Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); + Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + base.LoadContent(); } From faeebf7bd0558c1290f381caecbe6e8d6ac1c6d4 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 22:09:01 -0300 Subject: [PATCH 11/73] Rebase de la camara libre para poder navegar el escenario --- TGC.MonoGame.TP/TGCGame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 907a4928a..f6627ba9d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -168,8 +168,8 @@ protected override void Draw(GameTime gameTime) Effect.Parameters["Projection"].SetValue(Camera.Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - Terrain.Draw(View, Projection); - Terrain2.Draw(View, Projection); + Terrain.Draw(Camera.View, Camera.Projection); + Terrain2.Draw(Camera.View, Camera.Projection); /* foreach (var mesh in Model.Meshes) { From 0707292542325518459aac42149cd26068076150 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Mon, 29 Apr 2024 23:20:10 -0300 Subject: [PATCH 12/73] Agrego primitivas de cubos un poco customizadas --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 84 +++++++++++++++++++++ TGC.MonoGame.TP/TGCGame.cs | 8 ++ 2 files changed, 92 insertions(+) create mode 100644 TGC.MonoGame.TP/Geometries/CubePrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs new file mode 100644 index 000000000..b98e0e3fa --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -0,0 +1,84 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + /// + /// Geometric primitive class for drawing cubes. + /// + public class CubePrimitive : GeometricPrimitive { + + /// + /// Constructs a new cube primitive, with the specified size. + /// + public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + // A cube has six faces, each one pointing in a different direction. + Vector3[] normals = + { + // front normal + Vector3.UnitZ, + // back normal + -Vector3.UnitZ, + // right normal + Vector3.UnitX, + // left normal + -Vector3.UnitX, + // top normal + Vector3.UnitY, + // bottom normal + -Vector3.UnitY + }; + + var i = 0; + // Create each face in turn. + foreach (var normal in normals) + { + // Get two vectors perpendicular to the face normal and to each other. + var side1 = new Vector3(normal.Y, normal.Z, normal.X); + var side2 = Vector3.Cross(normal, side1); + + // Six indices (two triangles) per face. + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 2); + AddIndex(CurrentVertex + 3); + + // Four vertices per face. + AddVertex((normal - side1 - side2) * size / 2, color, normal); + AddVertex((normal - side1 + side2) * size / 2, color, normal); + AddVertex((normal + side1 + side2) * size / 2, color, normal); + AddVertex((normal + side1 - side2) * size / 2, color, normal); + + i++; + } + + InitializePrimitive(graphicsDevice); + } + + public void Draw(Matrix view, Matrix projection) { + + var newEffect = this.Effect; + newEffect.View = view; + newEffect.Projection = projection; + + this.Draw(newEffect); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index f6627ba9d..18992997d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -58,6 +58,8 @@ public TGCGame() private Terrain Terrain { get; set; } private Terrain Terrain2 { get; set; } + private CubePrimitive Cube1; + private float SquareSize = 50f; /// @@ -125,6 +127,9 @@ protected override void LoadContent() Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + Cube1 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube1.Effect.World = Matrix.CreateTranslation(new Vector3(50, 20, 3)); + base.LoadContent(); } @@ -171,6 +176,9 @@ protected override void Draw(GameTime gameTime) Terrain.Draw(Camera.View, Camera.Projection); Terrain2.Draw(Camera.View, Camera.Projection); + + Cube1.Draw(Camera.View, Camera.Projection); + /* foreach (var mesh in Model.Meshes) { Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); From d4ac6f58d31c14bbfe1b4d411da0df7806a8bfaa Mon Sep 17 00:00:00 2001 From: camilazzati Date: Tue, 30 Apr 2024 01:40:08 -0300 Subject: [PATCH 13/73] plataformas listas --- TGC.MonoGame.TP/TGCGame.cs | 365 ++++++++++++++++++++++++++++++++++++- 1 file changed, 358 insertions(+), 7 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 18992997d..23934a15e 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -60,6 +60,85 @@ public TGCGame() private CubePrimitive Cube1; + // --------------------------------------- + + // primera plataforma + private CubePrimitive Cube2; + private CubePrimitive Cube3; + private CubePrimitive Cube4; + private CubePrimitive Cube5; + private CubePrimitive Cube6; + private CubePrimitive Cube7; + private CubePrimitive Cube8; + private CubePrimitive Cube9; + private CubePrimitive Cube10; + private CubePrimitive Cube11; + private CubePrimitive Cube12; + private CubePrimitive Cube13; + private CubePrimitive Cube14; + private CubePrimitive Cube15; + private CubePrimitive Cube16; + private CubePrimitive Cube17; + private CubePrimitive Cube18; + + // segunda plataforma + private CubePrimitive Cube19; + private CubePrimitive Cube20; + private CubePrimitive Cube21; + private CubePrimitive Cube22; + private CubePrimitive Cube23; + private CubePrimitive Cube24; + private CubePrimitive Cube25; + private CubePrimitive Cube26; + private CubePrimitive Cube27; + + // escalera + private CubePrimitive Cube28; + private CubePrimitive Cube29; + private CubePrimitive Cube30; + private CubePrimitive Cube31; + private CubePrimitive Cube32; + private CubePrimitive Cube33; + private CubePrimitive Cube34; + private CubePrimitive Cube35; + private CubePrimitive Cube36; + + // tercera plataforma + private CubePrimitive Cube37; + private CubePrimitive Cube38; + private CubePrimitive Cube39; + private CubePrimitive Cube40; + private CubePrimitive Cube41; + private CubePrimitive Cube42; + private CubePrimitive Cube43; + private CubePrimitive Cube44; + private CubePrimitive Cube45; + + // cuarta plataforma + private CubePrimitive Cube46; + private CubePrimitive Cube47; + private CubePrimitive Cube48; + private CubePrimitive Cube49; + private CubePrimitive Cube50; + private CubePrimitive Cube51; + + // quinta plataforma + private CubePrimitive Cube52; + private CubePrimitive Cube53; + private CubePrimitive Cube54; + private CubePrimitive Cube55; + private CubePrimitive Cube56; + private CubePrimitive Cube57; + private CubePrimitive Cube58; + private CubePrimitive Cube59; + private CubePrimitive Cube60; + + + + + + // --------------------------------------- + private float SquareSize = 50f; /// @@ -124,11 +203,218 @@ protected override void LoadContent() //var floorTexture = Content.Load(ContentFolderTextures + "floor/tiling-base"); - Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); - Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + // Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); + // Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + + // PRIMERA PLATAFORMA + // primera linea + Cube1 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube1.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0)); + + Cube2 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube2.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 0)); + + Cube3 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube3.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 0)); + + // segunda linea + Cube4 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube4.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 25)); + + Cube5 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube5.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 25)); + + Cube6 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube6.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 25)); + + // tercera linea + Cube7 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube7.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 50)); + + Cube8 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube8.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 50)); + + Cube9 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube9.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 50)); + + // cuarte linea + Cube10 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube10.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 75)); + + Cube11 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube11.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 75)); + + Cube12 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube12.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 75)); + + // quinta linea + Cube13 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube13.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 100)); + + Cube14 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube14.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 100)); + + Cube15 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube15.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 100)); + + // sexta linea + Cube16 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube16.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 125)); + + Cube17 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube17.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 125)); + + Cube18 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube18.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 125)); + + // SEGUNDA PLATAFORMA + // primera linea + Cube19 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube19.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 175)); + + Cube20 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube20.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 175)); + + Cube21 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube21.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 175)); + + // segunda linda + Cube22 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube22.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 200)); + + Cube23 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube23.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 200)); + + Cube24 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube24.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 200)); + + // tercera linea + Cube25 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube25.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 225)); + + Cube26 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube26.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 225)); + + Cube27 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube27.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 225)); + + // ESCALERA + // primer escalon + Cube28 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube28.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 175)); + + Cube29 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube29.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 200)); + + Cube30 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube30.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 225)); + + // segundo escalon + Cube31 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube31.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 175)); + + Cube32 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube32.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 200)); - Cube1 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube1.Effect.World = Matrix.CreateTranslation(new Vector3(50, 20, 3)); + Cube33 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube33.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 225)); + + // tercer escalon + Cube34 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube34.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 175)); + + Cube35 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube35.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 200)); + + Cube36 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube36.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 225)); + + // TERCERA PLATAFORMA + // primera linea + Cube37 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube37.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 225)); + + Cube38 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube38.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 225)); + + Cube39 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube39.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 225)); + + // segunda linea + Cube40 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube40.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 200)); + + Cube41 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube41.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 200)); + + Cube42 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube42.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 200)); + + // tercera linea + Cube43 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube43.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 175)); + + Cube44 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube44.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 175)); + + Cube45 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube45.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 175)); + + //CUARTA PLATAFORMA + Cube46 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube46.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 125)); + + Cube47 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube47.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 100)); + + Cube48 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube48.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 75)); + + Cube49 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube49.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 50)); + + Cube50 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube50.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 25)); + + Cube51 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube51.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 0)); + + // QUINTA PLATAFORMA + // primera linea + Cube52 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube52.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -50)); + + Cube53 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube53.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -50)); + + Cube54 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube54.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -50)); + + // segunda linea + Cube55 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube55.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -75)); + + Cube56 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube56.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -75)); + + Cube57 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube57.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -75)); + + // tercera linea + Cube58 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube58.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -100)); + + Cube59 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube59.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -100)); + + Cube60 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube60.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + + + + + + base.LoadContent(); } @@ -166,18 +452,83 @@ protected override void Update(GameTime gameTime) protected override void Draw(GameTime gameTime) { // Aca deberiamos poner toda la logia de renderizado del juego. - GraphicsDevice.Clear(Color.Black); + GraphicsDevice.Clear(Color.LightSkyBlue); // Para dibujar le modelo necesitamos pasarle informacion que el efecto esta esperando. Effect.Parameters["View"].SetValue(Camera.View); Effect.Parameters["Projection"].SetValue(Camera.Projection); Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); - Terrain.Draw(Camera.View, Camera.Projection); - Terrain2.Draw(Camera.View, Camera.Projection); + //Terrain.Draw(Camera.View, Camera.Projection); + //Terrain2.Draw(Camera.View, Camera.Projection); Cube1.Draw(Camera.View, Camera.Projection); + Cube2.Draw(Camera.View, Camera.Projection); + Cube3.Draw(Camera.View, Camera.Projection); + Cube4.Draw(Camera.View, Camera.Projection); + Cube5.Draw(Camera.View, Camera.Projection); + Cube6.Draw(Camera.View, Camera.Projection); + Cube7.Draw(Camera.View, Camera.Projection); + Cube8.Draw(Camera.View, Camera.Projection); + Cube9.Draw(Camera.View, Camera.Projection); + Cube10.Draw(Camera.View, Camera.Projection); + Cube11.Draw(Camera.View, Camera.Projection); + Cube12.Draw(Camera.View, Camera.Projection); + Cube13.Draw(Camera.View, Camera.Projection); + Cube14.Draw(Camera.View, Camera.Projection); + Cube15.Draw(Camera.View, Camera.Projection); + Cube16.Draw(Camera.View, Camera.Projection); + Cube17.Draw(Camera.View, Camera.Projection); + Cube18.Draw(Camera.View, Camera.Projection); + + Cube19.Draw(Camera.View, Camera.Projection); + Cube20.Draw(Camera.View, Camera.Projection); + Cube21.Draw(Camera.View, Camera.Projection); + Cube22.Draw(Camera.View, Camera.Projection); + Cube23.Draw(Camera.View, Camera.Projection); + Cube24.Draw(Camera.View, Camera.Projection); + Cube25.Draw(Camera.View, Camera.Projection); + Cube26.Draw(Camera.View, Camera.Projection); + Cube27.Draw(Camera.View, Camera.Projection); + + Cube28.Draw(Camera.View, Camera.Projection); + Cube29.Draw(Camera.View, Camera.Projection); + Cube30.Draw(Camera.View, Camera.Projection); + Cube31.Draw(Camera.View, Camera.Projection); + Cube32.Draw(Camera.View, Camera.Projection); + Cube33.Draw(Camera.View, Camera.Projection); + Cube34.Draw(Camera.View, Camera.Projection); + Cube35.Draw(Camera.View, Camera.Projection); + Cube36.Draw(Camera.View, Camera.Projection); + + Cube37.Draw(Camera.View, Camera.Projection); + Cube38.Draw(Camera.View, Camera.Projection); + Cube39.Draw(Camera.View, Camera.Projection); + Cube40.Draw(Camera.View, Camera.Projection); + Cube41.Draw(Camera.View, Camera.Projection); + Cube42.Draw(Camera.View, Camera.Projection); + Cube43.Draw(Camera.View, Camera.Projection); + Cube44.Draw(Camera.View, Camera.Projection); + Cube45.Draw(Camera.View, Camera.Projection); + + Cube46.Draw(Camera.View, Camera.Projection); + Cube47.Draw(Camera.View, Camera.Projection); + Cube48.Draw(Camera.View, Camera.Projection); + Cube49.Draw(Camera.View, Camera.Projection); + Cube50.Draw(Camera.View, Camera.Projection); + Cube51.Draw(Camera.View, Camera.Projection); + + Cube52.Draw(Camera.View, Camera.Projection); + Cube53.Draw(Camera.View, Camera.Projection); + Cube54.Draw(Camera.View, Camera.Projection); + Cube55.Draw(Camera.View, Camera.Projection); + Cube56.Draw(Camera.View, Camera.Projection); + Cube57.Draw(Camera.View, Camera.Projection); + Cube58.Draw(Camera.View, Camera.Projection); + Cube59.Draw(Camera.View, Camera.Projection); + Cube60.Draw(Camera.View, Camera.Projection); + /* foreach (var mesh in Model.Meshes) { From de262829e64d7fd087d64c6c68ec23a9a6b940fd Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 30 Apr 2024 03:36:15 -0300 Subject: [PATCH 14/73] Agrego primitiva para rampas --- TGC.MonoGame.TP/Geometries/RampPrimitive.cs | 76 +++++++++++++++++++++ TGC.MonoGame.TP/TGCGame.cs | 19 +++--- 2 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 TGC.MonoGame.TP/Geometries/RampPrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/RampPrimitive.cs new file mode 100644 index 000000000..8e7e97b9b --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/RampPrimitive.cs @@ -0,0 +1,76 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class RampPrimitive : GeometricPrimitive { + + public RampPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(-1f, 1f, -1f), + new Vector3(1f, 1f, -1f), + new Vector3(-1f, -1f, -1f), + new Vector3(1f, -1f, -1f), + new Vector3(-1f, -1f, 1), + new Vector3(1f, -1f, 1f) + }; + + // front + AddTriangle(vertexList[0], vertexList[1], vertexList[2], size, color); + AddTriangle(vertexList[3], vertexList[2], vertexList[1], size, color); + + // bottom + AddTriangle(vertexList[2], vertexList[3], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[4], vertexList[3], size, color); + + // slope + AddTriangle(vertexList[4], vertexList[1], vertexList[0], size, color); + AddTriangle(vertexList[1], vertexList[4], vertexList[5], size, color); + + // sides + AddTriangle(vertexList[0], vertexList[2], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[3], vertexList[1], size, color); + + InitializePrimitive(graphicsDevice); + } + + private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) + { + Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddVertex(vertex1 * size / 2, color, normal); + AddVertex(vertex2 * size / 2, color, normal); + AddVertex(vertex3 * size / 2, color, normal); + } + + public void Draw(Matrix view, Matrix projection) { + + var newEffect = this.Effect; + newEffect.View = view; + newEffect.Projection = projection; + + this.Draw(newEffect); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 23934a15e..f8bc8fb2d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -59,6 +59,7 @@ public TGCGame() private Terrain Terrain2 { get; set; } private CubePrimitive Cube1; + private RampPrimitive Ramp; // --------------------------------------- @@ -410,12 +411,13 @@ protected override void LoadContent() Cube60 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); Cube60.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + // rampa + Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Red); + Ramp.Effect.World = Matrix.CreateTranslation(new Vector3(150, 150, -100)); - - base.LoadContent(); } @@ -528,13 +530,14 @@ protected override void Draw(GameTime gameTime) Cube58.Draw(Camera.View, Camera.Projection); Cube59.Draw(Camera.View, Camera.Projection); Cube60.Draw(Camera.View, Camera.Projection); - - /* foreach (var mesh in Model.Meshes) - { - Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); - mesh.Draw(); - }*/ + Ramp.Draw(Camera.View, Camera.Projection); + + /* foreach (var mesh in Model.Meshes) + { + Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); + mesh.Draw(); + }*/ } /// From 2d5d40e59b9765cd04f8f0baf0a891ffb5835cdc Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 30 Apr 2024 04:24:25 -0300 Subject: [PATCH 15/73] =?UTF-8?q?Agrego=20lista=20para=20primitivas=20geom?= =?UTF-8?q?=C3=A9tricas=20del=20escenario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 478 +++++++++++++++---------------------- 1 file changed, 199 insertions(+), 279 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index f8bc8fb2d..75793a9ed 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -58,87 +58,7 @@ public TGCGame() private Terrain Terrain { get; set; } private Terrain Terrain2 { get; set; } - private CubePrimitive Cube1; - private RampPrimitive Ramp; - - // --------------------------------------- - - // primera plataforma - private CubePrimitive Cube2; - private CubePrimitive Cube3; - private CubePrimitive Cube4; - private CubePrimitive Cube5; - private CubePrimitive Cube6; - private CubePrimitive Cube7; - private CubePrimitive Cube8; - private CubePrimitive Cube9; - private CubePrimitive Cube10; - private CubePrimitive Cube11; - private CubePrimitive Cube12; - private CubePrimitive Cube13; - private CubePrimitive Cube14; - private CubePrimitive Cube15; - private CubePrimitive Cube16; - private CubePrimitive Cube17; - private CubePrimitive Cube18; - - // segunda plataforma - private CubePrimitive Cube19; - private CubePrimitive Cube20; - private CubePrimitive Cube21; - private CubePrimitive Cube22; - private CubePrimitive Cube23; - private CubePrimitive Cube24; - private CubePrimitive Cube25; - private CubePrimitive Cube26; - private CubePrimitive Cube27; - - // escalera - private CubePrimitive Cube28; - private CubePrimitive Cube29; - private CubePrimitive Cube30; - private CubePrimitive Cube31; - private CubePrimitive Cube32; - private CubePrimitive Cube33; - private CubePrimitive Cube34; - private CubePrimitive Cube35; - private CubePrimitive Cube36; - - // tercera plataforma - private CubePrimitive Cube37; - private CubePrimitive Cube38; - private CubePrimitive Cube39; - private CubePrimitive Cube40; - private CubePrimitive Cube41; - private CubePrimitive Cube42; - private CubePrimitive Cube43; - private CubePrimitive Cube44; - private CubePrimitive Cube45; - - // cuarta plataforma - private CubePrimitive Cube46; - private CubePrimitive Cube47; - private CubePrimitive Cube48; - private CubePrimitive Cube49; - private CubePrimitive Cube50; - private CubePrimitive Cube51; - - // quinta plataforma - private CubePrimitive Cube52; - private CubePrimitive Cube53; - private CubePrimitive Cube54; - private CubePrimitive Cube55; - private CubePrimitive Cube56; - private CubePrimitive Cube57; - private CubePrimitive Cube58; - private CubePrimitive Cube59; - private CubePrimitive Cube60; - - - - - - // --------------------------------------- + private List Track; private float SquareSize = 50f; @@ -195,227 +115,290 @@ protected override void LoadContent() // Un modelo puede tener mas de 1 mesh internamente. //foreach (var mesh in Model.Meshes) //{ - // Un mesh puede tener mas de 1 mesh part (cada 1 puede tener su propio efecto). - // foreach (var meshPart in mesh.MeshParts) - //{ - // meshPart.Effect = Effect; - //} + // Un mesh puede tener mas de 1 mesh part (cada 1 puede tener su propio efecto). + // foreach (var meshPart in mesh.MeshParts) + //{ + // meshPart.Effect = Effect; + //} //} //var floorTexture = Content.Load(ContentFolderTextures + "floor/tiling-base"); - - // Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); - // Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + + // Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); + // Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); + + RampPrimitive Ramp; + CubePrimitive Cube; + Track = new List(); // PRIMERA PLATAFORMA // primera linea - Cube1 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube1.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0)); + Track.Add(Cube); - Cube2 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube2.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 0)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 0)); + Track.Add(Cube); - Cube3 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube3.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 0)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 0)); + Track.Add(Cube); // segunda linea - Cube4 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube4.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 25)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 25)); + Track.Add(Cube); - Cube5 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube5.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 25)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 25)); + Track.Add(Cube); - Cube6 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube6.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 25)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 25)); + Track.Add(Cube); // tercera linea - Cube7 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube7.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 50)); + Track.Add(Cube); - Cube8 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube8.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 50)); + Track.Add(Cube); - Cube9 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube9.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 50)); + Track.Add(Cube); // cuarte linea - Cube10 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube10.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 75)); + Track.Add(Cube); - Cube11 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube11.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 75)); + Track.Add(Cube); - Cube12 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube12.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 75)); + Track.Add(Cube); // quinta linea - Cube13 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube13.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 100)); + Track.Add(Cube); - Cube14 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube14.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 100)); + Track.Add(Cube); - Cube15 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube15.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 100)); + Track.Add(Cube); // sexta linea - Cube16 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube16.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 125)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 125)); + Track.Add(Cube); - Cube17 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube17.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 125)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 125)); + Track.Add(Cube); - Cube18 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube18.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 125)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 125)); + Track.Add(Cube); // SEGUNDA PLATAFORMA // primera linea - Cube19 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube19.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 175)); + Track.Add(Cube); - Cube20 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube20.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 175)); + Track.Add(Cube); - Cube21 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube21.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 175)); + Track.Add(Cube); // segunda linda - Cube22 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube22.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 200)); + Track.Add(Cube); - Cube23 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube23.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 200)); + Track.Add(Cube); - Cube24 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube24.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 200)); + Track.Add(Cube); // tercera linea - Cube25 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube25.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 225)); + Track.Add(Cube); - Cube26 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube26.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 225)); + Track.Add(Cube); - Cube27 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube27.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 225)); + Track.Add(Cube); // ESCALERA // primer escalon - Cube28 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube28.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 175)); + Track.Add(Cube); - Cube29 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube29.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 200)); + Track.Add(Cube); - Cube30 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube30.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 225)); + Track.Add(Cube); // segundo escalon - Cube31 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube31.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 175)); + Track.Add(Cube); - Cube32 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube32.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 200)); + Track.Add(Cube); - Cube33 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube33.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 225)); + Track.Add(Cube); // tercer escalon - Cube34 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube34.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 175)); + Track.Add(Cube); - Cube35 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube35.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 200)); + Track.Add(Cube); - Cube36 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube36.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 225)); + Track.Add(Cube); // TERCERA PLATAFORMA // primera linea - Cube37 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube37.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 225)); + Track.Add(Cube); - Cube38 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube38.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 225)); + Track.Add(Cube); - Cube39 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube39.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 225)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 225)); + Track.Add(Cube); // segunda linea - Cube40 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube40.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 200)); + Track.Add(Cube); - Cube41 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube41.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 200)); + Track.Add(Cube); - Cube42 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube42.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 200)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 200)); + Track.Add(Cube); // tercera linea - Cube43 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube43.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 175)); + Track.Add(Cube); - Cube44 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube44.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 175)); + Track.Add(Cube); - Cube45 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube45.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 175)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 175)); + Track.Add(Cube); //CUARTA PLATAFORMA - Cube46 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube46.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 125)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 125)); + Track.Add(Cube); - Cube47 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube47.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 100)); + Track.Add(Cube); - Cube48 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube48.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 75)); + Track.Add(Cube); - Cube49 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube49.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 50)); + Track.Add(Cube); - Cube50 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube50.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 25)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 25)); + Track.Add(Cube); - Cube51 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube51.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 0)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 0)); + Track.Add(Cube); // QUINTA PLATAFORMA // primera linea - Cube52 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube52.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -50)); + Track.Add(Cube); - Cube53 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube53.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -50)); + Track.Add(Cube); - Cube54 = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube54.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -50)); + Track.Add(Cube); // segunda linea - Cube55 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube55.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -75)); + Track.Add(Cube); - Cube56 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube56.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -75)); + Track.Add(Cube); - Cube57 = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube57.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -75)); + Track.Add(Cube); // tercera linea - Cube58 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube58.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -100)); + Track.Add(Cube); - Cube59 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube59.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -100)); + Track.Add(Cube); - Cube60 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube60.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + Track.Add(Cube); // rampa Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Red); Ramp.Effect.World = Matrix.CreateTranslation(new Vector3(150, 150, -100)); - - + Track.Add(Ramp); base.LoadContent(); @@ -454,7 +437,7 @@ protected override void Update(GameTime gameTime) protected override void Draw(GameTime gameTime) { // Aca deberiamos poner toda la logia de renderizado del juego. - GraphicsDevice.Clear(Color.LightSkyBlue); + GraphicsDevice.Clear(Color.DarkBlue); // Para dibujar le modelo necesitamos pasarle informacion que el efecto esta esperando. Effect.Parameters["View"].SetValue(Camera.View); @@ -465,73 +448,10 @@ protected override void Draw(GameTime gameTime) //Terrain2.Draw(Camera.View, Camera.Projection); - Cube1.Draw(Camera.View, Camera.Projection); - Cube2.Draw(Camera.View, Camera.Projection); - Cube3.Draw(Camera.View, Camera.Projection); - Cube4.Draw(Camera.View, Camera.Projection); - Cube5.Draw(Camera.View, Camera.Projection); - Cube6.Draw(Camera.View, Camera.Projection); - Cube7.Draw(Camera.View, Camera.Projection); - Cube8.Draw(Camera.View, Camera.Projection); - Cube9.Draw(Camera.View, Camera.Projection); - Cube10.Draw(Camera.View, Camera.Projection); - Cube11.Draw(Camera.View, Camera.Projection); - Cube12.Draw(Camera.View, Camera.Projection); - Cube13.Draw(Camera.View, Camera.Projection); - Cube14.Draw(Camera.View, Camera.Projection); - Cube15.Draw(Camera.View, Camera.Projection); - Cube16.Draw(Camera.View, Camera.Projection); - Cube17.Draw(Camera.View, Camera.Projection); - Cube18.Draw(Camera.View, Camera.Projection); - - Cube19.Draw(Camera.View, Camera.Projection); - Cube20.Draw(Camera.View, Camera.Projection); - Cube21.Draw(Camera.View, Camera.Projection); - Cube22.Draw(Camera.View, Camera.Projection); - Cube23.Draw(Camera.View, Camera.Projection); - Cube24.Draw(Camera.View, Camera.Projection); - Cube25.Draw(Camera.View, Camera.Projection); - Cube26.Draw(Camera.View, Camera.Projection); - Cube27.Draw(Camera.View, Camera.Projection); - - Cube28.Draw(Camera.View, Camera.Projection); - Cube29.Draw(Camera.View, Camera.Projection); - Cube30.Draw(Camera.View, Camera.Projection); - Cube31.Draw(Camera.View, Camera.Projection); - Cube32.Draw(Camera.View, Camera.Projection); - Cube33.Draw(Camera.View, Camera.Projection); - Cube34.Draw(Camera.View, Camera.Projection); - Cube35.Draw(Camera.View, Camera.Projection); - Cube36.Draw(Camera.View, Camera.Projection); - - Cube37.Draw(Camera.View, Camera.Projection); - Cube38.Draw(Camera.View, Camera.Projection); - Cube39.Draw(Camera.View, Camera.Projection); - Cube40.Draw(Camera.View, Camera.Projection); - Cube41.Draw(Camera.View, Camera.Projection); - Cube42.Draw(Camera.View, Camera.Projection); - Cube43.Draw(Camera.View, Camera.Projection); - Cube44.Draw(Camera.View, Camera.Projection); - Cube45.Draw(Camera.View, Camera.Projection); - - Cube46.Draw(Camera.View, Camera.Projection); - Cube47.Draw(Camera.View, Camera.Projection); - Cube48.Draw(Camera.View, Camera.Projection); - Cube49.Draw(Camera.View, Camera.Projection); - Cube50.Draw(Camera.View, Camera.Projection); - Cube51.Draw(Camera.View, Camera.Projection); - - Cube52.Draw(Camera.View, Camera.Projection); - Cube53.Draw(Camera.View, Camera.Projection); - Cube54.Draw(Camera.View, Camera.Projection); - Cube55.Draw(Camera.View, Camera.Projection); - Cube56.Draw(Camera.View, Camera.Projection); - Cube57.Draw(Camera.View, Camera.Projection); - Cube58.Draw(Camera.View, Camera.Projection); - Cube59.Draw(Camera.View, Camera.Projection); - Cube60.Draw(Camera.View, Camera.Projection); - - Ramp.Draw(Camera.View, Camera.Projection); + foreach (GeometricPrimitive primitive in Track) + { + primitive.Draw(primitive.Effect.World, Camera.View, Camera.Projection); + } /* foreach (var mesh in Model.Meshes) { From 74021939de72a713c752f758fa58397750471829 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 30 Apr 2024 06:27:46 -0300 Subject: [PATCH 16/73] Agrego otras plataformas --- TGC.MonoGame.TP/TGCGame.cs | 248 +++++++++++-------------------------- 1 file changed, 75 insertions(+), 173 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 75793a9ed..28ce89f1a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -134,271 +134,173 @@ protected override void LoadContent() // PRIMERA PLATAFORMA // primera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 0)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 0)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 0)); Track.Add(Cube); // segunda linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 25)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 25)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 25)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 25)); Track.Add(Cube); // tercera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 50)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 50)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 50)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 50)); Track.Add(Cube); // cuarte linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 75)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 75)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 75)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 75)); Track.Add(Cube); // quinta linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 100)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 100)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 100)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 100)); Track.Add(Cube); // sexta linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 125)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 125)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 125)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 125)); Track.Add(Cube); // SEGUNDA PLATAFORMA // primera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 175)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 175)); Track.Add(Cube); // segunda linda Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 200)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 200)); Track.Add(Cube); // tercera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 225)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(25, 0, 225)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 0, 225)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 225)); Track.Add(Cube); // ESCALERA // primer escalon Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(75, 25, 225)); + Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(75, 25, 200)); Track.Add(Cube); // segundo escalon Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(100, 50, 225)); + Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(100, 50, 200)); Track.Add(Cube); // tercer escalon Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(125, 75, 225)); + Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(125, 75, 200)); Track.Add(Cube); // TERCERA PLATAFORMA // primera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 225)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 225)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 225)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); Track.Add(Cube); // segunda linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 200)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); Track.Add(Cube); // tercera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, 175)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 175)); + //CUARTA PLATAFORMA + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, 175)); - Track.Add(Cube); - //CUARTA PLATAFORMA + // QUINTA PLATAFORMA + // primera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 125)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); Track.Add(Cube); + // segunda linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 100)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); Track.Add(Cube); + // tercera linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 75)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); Track.Add(Cube); + // rampa + Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Ramp.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); + Track.Add(Ramp); + + // canaleta Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 50)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); Track.Add(Cube); + Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Ramp.Effect.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; + Track.Add(Ramp); + Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Ramp.Effect.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; + Track.Add(Ramp); + // planos inclinados (ROLL) + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); + Track.Add(Cube); Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 25)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); + Track.Add(Cube); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, 0)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); Track.Add(Cube); - - // QUINTA PLATAFORMA - // primera linea - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -50)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); Track.Add(Cube); - - // segunda linea Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -75)); + Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -75)); + // rampa grande + Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Gray); + Ramp.Effect.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); + Track.Add(Ramp); + + // cuadrados grandes + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Red); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -75)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Orange); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); Track.Add(Cube); - - // tercera linea - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(150, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Yellow); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(175, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Green); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Blue); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); + Track.Add(Cube); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Indigo); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); + Track.Add(Cube); + Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Purple); + Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); Track.Add(Cube); - - // rampa - Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Red); - Ramp.Effect.World = Matrix.CreateTranslation(new Vector3(150, 150, -100)); - Track.Add(Ramp); base.LoadContent(); From a748b25f1eb8b51e9f39a7f4727c8df08a7c64c5 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 30 Apr 2024 07:08:40 -0300 Subject: [PATCH 17/73] =?UTF-8?q?Agrego=20primitiva=20para=20pir=C3=A1mide?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Geometries/PyramidPrimitive.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs b/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs new file mode 100644 index 000000000..40019ec5f --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs @@ -0,0 +1,70 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class PyramidPrimitive : GeometricPrimitive { + + public PyramidPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(0f, 0.5f, 0f), + new Vector3(-1f, -1f, -1f), + new Vector3(1f, -1f, -1f), + new Vector3(-1f, -1f, 1), + new Vector3(1f, -1f, 1f) + }; + + // bottom + AddTriangle(vertexList[1], vertexList[2], vertexList[3], size, color); + AddTriangle(vertexList[4], vertexList[3], vertexList[2], size, color); + + // sides + AddTriangle(vertexList[0], vertexList[1], vertexList[3], size, color); + AddTriangle(vertexList[0], vertexList[3], vertexList[4], size, color); + AddTriangle(vertexList[0], vertexList[4], vertexList[2], size, color); + AddTriangle(vertexList[0], vertexList[2], vertexList[1], size, color); + + InitializePrimitive(graphicsDevice); + } + + private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) + { + Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddVertex(vertex1 * size / 2, color, normal); + AddVertex(vertex2 * size / 2, color, normal); + AddVertex(vertex3 * size / 2, color, normal); + } + + public void Draw(Matrix view, Matrix projection) { + + var newEffect = this.Effect; + newEffect.View = view; + newEffect.Projection = projection; + + this.Draw(newEffect); + } + } +} \ No newline at end of file From d7a9517dc233dbf4e152dd39bd7cf2d3a8b5c72e Mon Sep 17 00:00:00 2001 From: camilazzati Date: Tue, 30 Apr 2024 09:20:22 -0300 Subject: [PATCH 18/73] agrego bolita --- TGC.MonoGame.TP/Geometries/SpherePrimitive.cs | 132 ++++++++++++++++++ TGC.MonoGame.TP/TGCGame.cs | 11 +- 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 TGC.MonoGame.TP/Geometries/SpherePrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs new file mode 100644 index 000000000..d55333c1c --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs @@ -0,0 +1,132 @@ +#region File Description + +//----------------------------------------------------------------------------- +// SpherePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries +{ + /// + /// Geometric primitive class for drawing spheres. + /// + public class SpherePrimitive : GeometricPrimitive + { + /// + /// Constructs a new sphere primitive, with the specified size, tessellation level and white color. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Diameter of the sphere. + /// The number of times the surface triangles are subdivided. + public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter = 1, int tessellation = 16) : this( + graphicsDevice, diameter, tessellation, Color.White) + { + } + + /// + /// Constructs a new sphere primitive, with the specified size, tessellation level and color. + /// + /// Used to initialize and control the presentation of the graphics device. + /// Diameter of the sphere. + /// The number of times the surface triangles are subdivided. + /// Color of the sphere. + public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessellation, Color color) + { + if (tessellation < 3) + throw new ArgumentOutOfRangeException("tessellation"); + + var verticalSegments = tessellation; + var horizontalSegments = tessellation * 2; + + var radius = diameter / 2; + + // Start with a single vertex at the bottom of the sphere. + AddVertex(Vector3.Down * radius, color, Vector3.Down); + + // Create rings of vertices at progressively higher latitudes. + for (var i = 0; i < verticalSegments - 1; i++) + { + var latitude = (i + 1) * MathHelper.Pi / + verticalSegments - MathHelper.PiOver2; + + var dy = (float) Math.Sin(latitude); + var dxz = (float) Math.Cos(latitude); + + // Create a single ring of vertices at this latitude. + for (var j = 0; j < horizontalSegments; j++) + { + var longitude = j * MathHelper.TwoPi / horizontalSegments; + + var dx = (float) Math.Cos(longitude) * dxz; + var dz = (float) Math.Sin(longitude) * dxz; + + var normal = new Vector3(dx, dy, dz); + + AddVertex(normal * radius, color, normal); + } + } + + // Finish with a single vertex at the top of the sphere. + AddVertex(Vector3.Up * radius, color, Vector3.Up); + + // Create a fan connecting the bottom vertex to the bottom latitude ring. + for (var i = 0; i < horizontalSegments; i++) + { + AddIndex(0); + AddIndex(1 + (i + 1) % horizontalSegments); + AddIndex(1 + i); + } + + // Fill the sphere body with triangles joining each pair of latitude rings. + for (var i = 0; i < verticalSegments - 2; i++) + for (var j = 0; j < horizontalSegments; j++) + { + var nextI = i + 1; + var nextJ = (j + 1) % horizontalSegments; + + AddIndex(1 + i * horizontalSegments + j); + AddIndex(1 + i * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + j); + + AddIndex(1 + i * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + nextJ); + AddIndex(1 + nextI * horizontalSegments + j); + } + + // Create a fan connecting the top vertex to the top latitude ring. + for (var i = 0; i < horizontalSegments; i++) + { + AddIndex(CurrentVertex - 1); + AddIndex(CurrentVertex - 2 - (i + 1) % horizontalSegments); + AddIndex(CurrentVertex - 2 - i); + } + + + + + InitializePrimitive(graphicsDevice); + } + + public void Draw(Matrix view, Matrix projection) { + + var newEffect = this.Effect; + newEffect.View = view; + newEffect.Projection = projection; + + this.Draw(newEffect); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 23934a15e..e6a27e26a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using BepuPhysics.Collidables; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -133,8 +134,9 @@ public TGCGame() private CubePrimitive Cube59; private CubePrimitive Cube60; + // BOLITA - + private SpherePrimitive Bola; // --------------------------------------- @@ -410,6 +412,11 @@ protected override void LoadContent() Cube60 = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); Cube60.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); + // BOLITA + + Bola = new SpherePrimitive(GraphicsDevice, 25, 50, Color.White); + Bola.Effect.World = Matrix.CreateTranslation(new Vector3(25, 25, 0)); + @@ -528,6 +535,8 @@ protected override void Draw(GameTime gameTime) Cube58.Draw(Camera.View, Camera.Projection); Cube59.Draw(Camera.View, Camera.Projection); Cube60.Draw(Camera.View, Camera.Projection); + + Bola.Draw(Camera.View, Camera.Projection); /* foreach (var mesh in Model.Meshes) From 3a28a55aaf44252f8e75cbae6a6f2e23e4616ad5 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 30 Apr 2024 17:27:55 -0300 Subject: [PATCH 19/73] =?UTF-8?q?Modificaci=C3=B3n=20de=20la=20posici?= =?UTF-8?q?=C3=B3n=20de=20la=20esfera.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 62098aa16..31e828469 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -252,9 +252,9 @@ protected override void LoadContent() Track.Add(Ramp); // BOLITA - + // Propuesta de punto de inicio del escenario Bola = new SpherePrimitive(GraphicsDevice, 25, 50, Color.White); - Bola.Effect.World = Matrix.CreateTranslation(new Vector3(25, 25, 0)); + Bola.Effect.World = Matrix.CreateTranslation(new Vector3(25, 25, -800)); // planos inclinados (ROLL) Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); From b609ec463aadc369fe54e61449776328c135ec44 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 30 Apr 2024 17:43:19 -0300 Subject: [PATCH 20/73] Variables en desuso comentadas --- TGC.MonoGame.TP/TGCGame.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 31e828469..9d06cc98a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -63,7 +63,9 @@ public TGCGame() private SpherePrimitive Bola; private List Track; - private float SquareSize = 50f; + // Comentada porque no está en uso + //private float SquareSize = 50f; + /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. From 1a9d016744d228bc89ce17686b9f4eb66fb1eb7f Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 30 Apr 2024 19:08:55 -0300 Subject: [PATCH 21/73] Agrego integrantes en el README --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e0c207bd0..61ca77c28 100644 --- a/README.md +++ b/README.md @@ -22,16 +22,15 @@ Los recursos usados se almacenan utilizando [Git LFS](https://git-lfs.github.com TGC, Tgcito | Apellido, Nombre ------------ | ------------- -| | | +| Mango Alexis Brian | +| Lazzati Camila | +| Bertani Luis Federico | +| Luca Colamonici | +| Esposta Franco Nahuel | ## Capturas -![screenshot1](https://github.com/tgc-utn/tgc-monogame-tp/blob/master/TGC.MonoGame.TP/Icon.bmp) -![screenshot2](https://github.com/tgc-utn/tgc-monogame-tp/blob/master/TGC.MonoGame.TP/Icon.bmp) -![screenshot3](https://github.com/tgc-utn/tgc-monogame-tp/blob/master/TGC.MonoGame.TP/Icon.bmp) -![screenshot4](https://github.com/tgc-utn/tgc-monogame-tp/blob/master/TGC.MonoGame.TP/Icon.bmp) -![screenshot5](https://github.com/tgc-utn/tgc-monogame-tp/blob/master/TGC.MonoGame.TP/Icon.bmp) +**WIP** ## Game Play - -[![Watch the video](https://img.youtube.com/vi/pgEwUC0jvH4/0.jpg)](https://www.youtube.com/playlist?list=PLRM4L32DjvnazuMl8wZlbpEYL5Qh63ulG) +**WIP** From b7fee363e6ac6c4f1819eff16dc17b77c15b335d Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 30 Apr 2024 19:37:39 -0300 Subject: [PATCH 22/73] Acomodo el punto inicial de la camara --- TGC.MonoGame.TP/TGCGame.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 9d06cc98a..ae4287811 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -77,7 +77,8 @@ protected override void Initialize() var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; - Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, Vector3.UnitZ * 150f, size); + var cameraPosition = new Vector3(20f, 100f, 500f); + Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. From 93a8d521b8cd3052577e685c8bf41b530b561813 Mon Sep 17 00:00:00 2001 From: camilazzati Date: Tue, 30 Apr 2024 19:56:56 -0300 Subject: [PATCH 23/73] . --- TGC.MonoGame.TP/TGCGame.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index e6a27e26a..9a3012f93 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -171,6 +171,7 @@ protected override void Initialize() Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 250); + base.Initialize(); } @@ -413,16 +414,10 @@ protected override void LoadContent() Cube60.Effect.World = Matrix.CreateTranslation(new Vector3(200, 100, -100)); // BOLITA - Bola = new SpherePrimitive(GraphicsDevice, 25, 50, Color.White); Bola.Effect.World = Matrix.CreateTranslation(new Vector3(25, 25, 0)); - - - - - base.LoadContent(); } @@ -537,6 +532,7 @@ protected override void Draw(GameTime gameTime) Cube60.Draw(Camera.View, Camera.Projection); Bola.Draw(Camera.View, Camera.Projection); + /* foreach (var mesh in Model.Meshes) From 4801d6cdbf3d2331590693a7059f3a302c6f3d56 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 30 Apr 2024 20:25:31 -0300 Subject: [PATCH 24/73] Acomodo la camara atras del personaje --- TGC.MonoGame.TP/Camera/FreeCamera.cs | 10 +++++----- TGC.MonoGame.TP/TGCGame.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TGC.MonoGame.TP/Camera/FreeCamera.cs b/TGC.MonoGame.TP/Camera/FreeCamera.cs index 65bfba986..e2751fd4e 100644 --- a/TGC.MonoGame.TP/Camera/FreeCamera.cs +++ b/TGC.MonoGame.TP/Camera/FreeCamera.cs @@ -36,7 +36,7 @@ public FreeCamera(float aspectRatio, Vector3 position) : base(aspectRatio) private void CalculateView() { - View = Matrix.CreateLookAt(Position, Position + FrontDirection, UpDirection); + View = Matrix.CreateLookAt(Position, Position - FrontDirection, UpDirection); } /// @@ -61,25 +61,25 @@ private void ProcessKeyboard(float elapsedTime) if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left)) { - Position += -RightDirection * currentMovementSpeed * elapsedTime; + Position += RightDirection * currentMovementSpeed * elapsedTime; changed = true; } if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) { - Position += RightDirection * currentMovementSpeed * elapsedTime; + Position += -RightDirection * currentMovementSpeed * elapsedTime; changed = true; } if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up)) { - Position += FrontDirection * currentMovementSpeed * elapsedTime; + Position += -FrontDirection * currentMovementSpeed * elapsedTime; changed = true; } if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down)) { - Position += -FrontDirection * currentMovementSpeed * elapsedTime; + Position += FrontDirection * currentMovementSpeed * elapsedTime; changed = true; } } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index ae4287811..e255fc503 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -77,7 +77,7 @@ protected override void Initialize() var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; - var cameraPosition = new Vector3(20f, 100f, 500f); + var cameraPosition = new Vector3(25f, 100f, -1100f); Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. From c5c86851a43ca2edc89b26e4e0813797adee9ca4 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 30 Apr 2024 20:28:54 -0300 Subject: [PATCH 25/73] Arreglo forma de mover la camara --- TGC.MonoGame.TP/Camera/FreeCamera.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/Camera/FreeCamera.cs b/TGC.MonoGame.TP/Camera/FreeCamera.cs index e2751fd4e..cd449d1f1 100644 --- a/TGC.MonoGame.TP/Camera/FreeCamera.cs +++ b/TGC.MonoGame.TP/Camera/FreeCamera.cs @@ -93,7 +93,7 @@ private void ProcessMouseMovement(float elapsedTime) var mouseDelta = mouseState.Position.ToVector2() - pastMousePosition; mouseDelta *= MouseSensitivity * elapsedTime; - yaw -= mouseDelta.X; + yaw += mouseDelta.X; pitch += mouseDelta.Y; if (pitch > 89.0f) From 9135b8929edcf8fab3ac5dca0d130a067c15b18b Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sat, 4 May 2024 04:03:58 -0300 Subject: [PATCH 26/73] =?UTF-8?q?Agrego=20nuevas=20geometr=C3=ADas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomPrimitives/CustomCubePrimitive.cs | 68 ++++++++++++++ .../CustomPrimitives/CustomPrimitive.cs | 45 ++++++++++ .../CustomPrimitives/DiamondPrimitive.cs | 77 ++++++++++++++++ .../CustomPrimitives/LightningPrimitive.cs | 67 ++++++++++++++ .../CustomPrimitives/OctahedronPrimitive.cs | 52 +++++++++++ .../PyramidPrimitive.cs | 23 +---- .../{ => CustomPrimitives}/RampPrimitive.cs | 23 +---- .../CustomPrimitives/RupeePrimitive.cs | 89 +++++++++++++++++++ 8 files changed, 400 insertions(+), 44 deletions(-) create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs rename TGC.MonoGame.TP/Geometries/{ => CustomPrimitives}/PyramidPrimitive.cs (65%) rename TGC.MonoGame.TP/Geometries/{ => CustomPrimitives}/RampPrimitive.cs (68%) create mode 100644 TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs new file mode 100644 index 000000000..b7fcea330 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs @@ -0,0 +1,68 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class CustomCubePrimitive : CustomPrimitive { + + // Esta clase crea un modelo prácticamente igual de al CubePrimitive. + // La agrago al proyecto únicamente como referencia para el uso de CustomPrimitive. + + public CustomCubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(-1f, 1f, -1f), + new Vector3(1f, 1f, -1f), + new Vector3(-1f, 1f, 1f), + new Vector3(1f, 1f, 1f), + new Vector3(-1f, -1f, -1f), + new Vector3(1f, -1f, -1f), + new Vector3(-1f, -1f, 1), + new Vector3(1f, -1f, 1f) + }; + + // front normal + AddTriangle(vertexList[2], vertexList[6], vertexList[3], size, color); + AddTriangle(vertexList[7], vertexList[3], vertexList[6], size, color); + + // back normal + AddTriangle(vertexList[0], vertexList[1], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[4], vertexList[1], size, color); + + // right normal + AddTriangle(vertexList[1], vertexList[3], vertexList[5], size, color); + AddTriangle(vertexList[7], vertexList[5], vertexList[3], size, color); + + // left normal + AddTriangle(vertexList[0], vertexList[4], vertexList[2], size, color); + AddTriangle(vertexList[6], vertexList[2], vertexList[4], size, color); + + // top normal + AddTriangle(vertexList[0], vertexList[2], vertexList[1], size, color); + AddTriangle(vertexList[3], vertexList[1], vertexList[2], size, color); + + // bottom normal + AddTriangle(vertexList[4], vertexList[5], vertexList[6], size, color); + AddTriangle(vertexList[7], vertexList[6], vertexList[5], size, color); + + InitializePrimitive(graphicsDevice); + } + + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs new file mode 100644 index 000000000..468f82703 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs @@ -0,0 +1,45 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class CustomPrimitive : GeometricPrimitive { + + protected void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) + { + Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); + + AddIndex(CurrentVertex + 0); + AddIndex(CurrentVertex + 1); + AddIndex(CurrentVertex + 2); + + AddVertex(vertex1 * size / 2, color, normal); + AddVertex(vertex2 * size / 2, color, normal); + AddVertex(vertex3 * size / 2, color, normal); + } + + public void Draw(Matrix view, Matrix projection) { + + var newEffect = this.Effect; + newEffect.View = view; + newEffect.Projection = projection; + + this.Draw(newEffect); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs new file mode 100644 index 000000000..519f64fc9 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs @@ -0,0 +1,77 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class DiamondPrimitive : CustomPrimitive { + + public DiamondPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(-0.25f, 1f, (float) -Math.Sqrt(3)/4), + new Vector3(-0.5f, 1f, 0f), + new Vector3(-0.25f, 1f, (float) Math.Sqrt(3)/4), + new Vector3(0.25f, 1f, (float) Math.Sqrt(3)/4), + new Vector3(0.5f, 1f, 0f), + new Vector3(0.25f, 1f, (float) -Math.Sqrt(3)/4), + + new Vector3(-0.5f, 0.4f, (float) -Math.Sqrt(3)/2), + new Vector3(-1f, 0.4f, 0f), + new Vector3(-0.5f, 0.4f, (float) Math.Sqrt(3)/2), + new Vector3(0.5f, 0.4f, (float) Math.Sqrt(3)/2), + new Vector3(1f, 0.4f, 0f), + new Vector3(0.5f, 0.4f, (float) -Math.Sqrt(3)/2), + + new Vector3(0f, -1f, 0f) + }; + + // top + AddTriangle(vertexList[0], vertexList[1], vertexList[2], size, color); + AddTriangle(vertexList[0], vertexList[2], vertexList[5], size, color); + AddTriangle(vertexList[3], vertexList[5], vertexList[2], size, color); + AddTriangle(vertexList[4], vertexList[5], vertexList[3], size, color); + + // middle + AddTriangle(vertexList[0], vertexList[6], vertexList[1], size, color); + AddTriangle(vertexList[7], vertexList[1], vertexList[6], size, color); + AddTriangle(vertexList[1], vertexList[7], vertexList[2], size, color); + AddTriangle(vertexList[8], vertexList[2], vertexList[7], size, color); + AddTriangle(vertexList[2], vertexList[8], vertexList[3], size, color); + AddTriangle(vertexList[9], vertexList[3], vertexList[8], size, color); + AddTriangle(vertexList[3], vertexList[9], vertexList[4], size, color); + AddTriangle(vertexList[10], vertexList[4], vertexList[9], size, color); + AddTriangle(vertexList[4], vertexList[10], vertexList[5], size, color); + AddTriangle(vertexList[11], vertexList[5], vertexList[10], size, color); + AddTriangle(vertexList[5], vertexList[11], vertexList[0], size, color); + AddTriangle(vertexList[6], vertexList[0], vertexList[11], size, color); + + //// bottom + AddTriangle(vertexList[12], vertexList[11], vertexList[10], size, color); + AddTriangle(vertexList[12], vertexList[10], vertexList[9], size, color); + AddTriangle(vertexList[12], vertexList[9], vertexList[8], size, color); + AddTriangle(vertexList[12], vertexList[8], vertexList[7], size, color); + AddTriangle(vertexList[12], vertexList[7], vertexList[6], size, color); + AddTriangle(vertexList[12], vertexList[6], vertexList[11], size, color); + + InitializePrimitive(graphicsDevice); + } + + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs new file mode 100644 index 000000000..d87f68ea6 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs @@ -0,0 +1,67 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class LightningPrimitive : CustomPrimitive { + + public LightningPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(0.2f, 1f, 0.2f), + new Vector3(-0.5f, -0.1f, 0.2f), + new Vector3(-0.02f, -0.1f, 0.2f), + new Vector3(-0.2f, -1f, 0.2f), + new Vector3(0.5f, 0.1f, 0.2f), + new Vector3(0.02f, 0.1f, 0.2f), + new Vector3(0.2f, 1f, -0.2f), + new Vector3(-0.5f, -0.1f, -0.2f), + new Vector3(-0.02f, -0.1f, -0.2f), + new Vector3(-0.2f, -1f, -0.2f), + new Vector3(0.5f, 0.1f, -0.2f), + new Vector3(0.02f, 0.1f, -0.2f) + }; + + // top - front/back + AddTriangle(vertexList[0], vertexList[1], vertexList[2], size, color); + AddTriangle(vertexList[6], vertexList[8], vertexList[7], size, color); + // top - sides + AddTriangle(vertexList[6], vertexList[7], vertexList[0], size, color); + AddTriangle(vertexList[1], vertexList[0], vertexList[7], size, color); + AddTriangle(vertexList[7], vertexList[8], vertexList[1], size, color); + AddTriangle(vertexList[2], vertexList[1], vertexList[8], size, color); + AddTriangle(vertexList[8], vertexList[6], vertexList[2], size, color); + AddTriangle(vertexList[0], vertexList[2], vertexList[6], size, color); + + // bottom - front/back + AddTriangle(vertexList[3], vertexList[4], vertexList[5], size, color); + AddTriangle(vertexList[9], vertexList[11], vertexList[10], size, color); + // bottom - sides + AddTriangle(vertexList[9], vertexList[10], vertexList[3], size, color); + AddTriangle(vertexList[4], vertexList[3], vertexList[10], size, color); + AddTriangle(vertexList[10], vertexList[11], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[4], vertexList[11], size, color); + AddTriangle(vertexList[11], vertexList[9], vertexList[5], size, color); + AddTriangle(vertexList[3], vertexList[5], vertexList[9], size, color); + + InitializePrimitive(graphicsDevice); + } + + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs new file mode 100644 index 000000000..0d04806f8 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs @@ -0,0 +1,52 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class OctahedronPrimitive : CustomPrimitive { + + public OctahedronPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(0f, 1f, 0f), + new Vector3(-1f, 0, -1f), + new Vector3(1f, 0, -1f), + new Vector3(-1f, 0, 1), + new Vector3(1f, 0, 1f), + new Vector3(0f, -1f, 0f) + }; + + // top + AddTriangle(vertexList[0], vertexList[1], vertexList[3], size, color); + AddTriangle(vertexList[0], vertexList[3], vertexList[4], size, color); + AddTriangle(vertexList[0], vertexList[4], vertexList[2], size, color); + AddTriangle(vertexList[0], vertexList[2], vertexList[1], size, color); + + // bottom + AddTriangle(vertexList[5], vertexList[3], vertexList[1], size, color); + AddTriangle(vertexList[5], vertexList[4], vertexList[3], size, color); + AddTriangle(vertexList[5], vertexList[2], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[1], vertexList[2], size, color); + + InitializePrimitive(graphicsDevice); + } + + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs similarity index 65% rename from TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs rename to TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs index 40019ec5f..cbdb21bf1 100644 --- a/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs @@ -19,7 +19,7 @@ namespace TGC.MonoGame.TP.Geometries { - public class PyramidPrimitive : GeometricPrimitive { + public class PyramidPrimitive : CustomPrimitive { public PyramidPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { @@ -45,26 +45,5 @@ public PyramidPrimitive(GraphicsDevice graphicsDevice, float size, Color color) InitializePrimitive(graphicsDevice); } - private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) - { - Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddVertex(vertex1 * size / 2, color, normal); - AddVertex(vertex2 * size / 2, color, normal); - AddVertex(vertex3 * size / 2, color, normal); - } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs similarity index 68% rename from TGC.MonoGame.TP/Geometries/RampPrimitive.cs rename to TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 8e7e97b9b..978cfd702 100644 --- a/TGC.MonoGame.TP/Geometries/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -18,7 +18,7 @@ namespace TGC.MonoGame.TP.Geometries { - public class RampPrimitive : GeometricPrimitive { + public class RampPrimitive : CustomPrimitive { public RampPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { @@ -51,26 +51,5 @@ public RampPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { InitializePrimitive(graphicsDevice); } - private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) - { - Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddVertex(vertex1 * size / 2, color, normal); - AddVertex(vertex2 * size / 2, color, normal); - AddVertex(vertex3 * size / 2, color, normal); - } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs new file mode 100644 index 000000000..b794743f2 --- /dev/null +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs @@ -0,0 +1,89 @@ +#region File Description + +//----------------------------------------------------------------------------- +// CubePrimitive.cs +// +// Microsoft XNA Community Game Platform +// Copyright (C) Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- + +#endregion File Description + +#region Using Statements + +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#endregion Using Statements + +namespace TGC.MonoGame.TP.Geometries { + + public class RupeePrimitive : CustomPrimitive { + + public RupeePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + + Vector3[] vertexList = + { + new Vector3(0f, 0.65f, 0.2f), + new Vector3(-0.3f, 0.35f, 0.2f), + new Vector3(-0.3f, -0.35f, 0.2f), + new Vector3(0f, -0.65f, 0.2f), + new Vector3(0.3f, -0.35f, 0.2f), + new Vector3(0.3f, 0.35f, 0.2f), + new Vector3(0f, 1f, 0f), + new Vector3(-0.5f, 0.5f, 0f), + new Vector3(-0.5f, -0.5f, 0f), + new Vector3(0f, -1f, 0f), + new Vector3(0.5f, -0.5f, 0f), + new Vector3(0.5f, 0.5f, 0f), + new Vector3(0f, 0.65f, -0.2f), + new Vector3(-0.3f, 0.35f, -0.2f), + new Vector3(-0.3f, -0.35f, -0.2f), + new Vector3(0f, -0.65f, -0.2f), + new Vector3(0.3f, -0.35f, -0.2f), + new Vector3(0.3f, 0.35f, -0.2f) + }; + + // front + AddTriangle(vertexList[0], vertexList[1], vertexList[5], size, color); + AddTriangle(vertexList[3], vertexList[4], vertexList[2], size, color); + AddTriangle(vertexList[4], vertexList[5], vertexList[2], size, color); + AddTriangle(vertexList[1], vertexList[2], vertexList[5], size, color); + // front to middle + AddTriangle(vertexList[6], vertexList[7], vertexList[0], size, color); + AddTriangle(vertexList[1], vertexList[0], vertexList[7], size, color); + AddTriangle(vertexList[7], vertexList[8], vertexList[1], size, color); + AddTriangle(vertexList[2], vertexList[1], vertexList[8], size, color); + AddTriangle(vertexList[8], vertexList[9], vertexList[2], size, color); + AddTriangle(vertexList[3], vertexList[2], vertexList[9], size, color); + AddTriangle(vertexList[9], vertexList[10], vertexList[3], size, color); + AddTriangle(vertexList[4], vertexList[3], vertexList[10], size, color); + AddTriangle(vertexList[10], vertexList[11], vertexList[4], size, color); + AddTriangle(vertexList[5], vertexList[4], vertexList[11], size, color); + AddTriangle(vertexList[11], vertexList[6], vertexList[5], size, color); + AddTriangle(vertexList[0], vertexList[5], vertexList[6], size, color); + + // back + AddTriangle(vertexList[12], vertexList[17], vertexList[13], size, color); + AddTriangle(vertexList[15], vertexList[14], vertexList[16], size, color); + AddTriangle(vertexList[16], vertexList[14], vertexList[17], size, color); + AddTriangle(vertexList[13], vertexList[17], vertexList[14], size, color); + // back to middle + AddTriangle(vertexList[6], vertexList[7], vertexList[12], size, color); + AddTriangle(vertexList[13], vertexList[12], vertexList[7], size, color); + AddTriangle(vertexList[7], vertexList[8], vertexList[13], size, color); + AddTriangle(vertexList[14], vertexList[13], vertexList[8], size, color); + AddTriangle(vertexList[8], vertexList[9], vertexList[14], size, color); + AddTriangle(vertexList[15], vertexList[14], vertexList[9], size, color); + AddTriangle(vertexList[9], vertexList[10], vertexList[15], size, color); + AddTriangle(vertexList[16], vertexList[15], vertexList[10], size, color); + AddTriangle(vertexList[10], vertexList[11], vertexList[16], size, color); + AddTriangle(vertexList[17], vertexList[16], vertexList[11], size, color); + AddTriangle(vertexList[11], vertexList[6], vertexList[17], size, color); + AddTriangle(vertexList[12], vertexList[17], vertexList[6], size, color); + + InitializePrimitive(graphicsDevice); + } + + } +} \ No newline at end of file From 1c804210afb1ff091372ec0391bda207233c518c Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sat, 4 May 2024 04:19:24 -0300 Subject: [PATCH 27/73] =?UTF-8?q?Corrijo=20tri=C3=A1ngulos=20de=20Lightnin?= =?UTF-8?q?gPrimitive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Geometries/CustomPrimitives/LightningPrimitive.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs index d87f68ea6..1342af292 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs @@ -46,8 +46,8 @@ public LightningPrimitive(GraphicsDevice graphicsDevice, float size, Color color AddTriangle(vertexList[1], vertexList[0], vertexList[7], size, color); AddTriangle(vertexList[7], vertexList[8], vertexList[1], size, color); AddTriangle(vertexList[2], vertexList[1], vertexList[8], size, color); - AddTriangle(vertexList[8], vertexList[6], vertexList[2], size, color); - AddTriangle(vertexList[0], vertexList[2], vertexList[6], size, color); + AddTriangle(vertexList[11], vertexList[6], vertexList[5], size, color); + AddTriangle(vertexList[0], vertexList[5], vertexList[6], size, color); // bottom - front/back AddTriangle(vertexList[3], vertexList[4], vertexList[5], size, color); @@ -57,8 +57,8 @@ public LightningPrimitive(GraphicsDevice graphicsDevice, float size, Color color AddTriangle(vertexList[4], vertexList[3], vertexList[10], size, color); AddTriangle(vertexList[10], vertexList[11], vertexList[4], size, color); AddTriangle(vertexList[5], vertexList[4], vertexList[11], size, color); - AddTriangle(vertexList[11], vertexList[9], vertexList[5], size, color); - AddTriangle(vertexList[3], vertexList[5], vertexList[9], size, color); + AddTriangle(vertexList[8], vertexList[9], vertexList[2], size, color); + AddTriangle(vertexList[3], vertexList[2], vertexList[9], size, color); InitializePrimitive(graphicsDevice); } From cde1a0a047e07eb437ab8921faf847d6e836e942 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sat, 18 May 2024 11:52:34 -0300 Subject: [PATCH 28/73] Saco BasicEffect --- TGC.MonoGame.TP/Content/Content.mgcb | 2 - TGC.MonoGame.TP/Environment/Terrain.cs | 6 +- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 17 +- .../Geometries/GeometricPrimitive.cs | 40 ++-- .../Geometries/PyramidPrimitive.cs | 20 +- TGC.MonoGame.TP/Geometries/RampPrimitive.cs | 16 +- TGC.MonoGame.TP/Geometries/SpherePrimitive.cs | 31 +-- TGC.MonoGame.TP/Geometries/SquarePrimitive.cs | 8 +- TGC.MonoGame.TP/TGCGame.cs | 218 ++++++++---------- 9 files changed, 147 insertions(+), 211 deletions(-) diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 1d6b630b3..5b1cbd309 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -24,7 +24,6 @@ /processor:ModelProcessor /processorParam:ColorKeyColor=0,0,0,0 /processorParam:ColorKeyEnabled=True -/processorParam:DefaultEffect=BasicEffect /processorParam:GenerateMipmaps=True /processorParam:GenerateTangentFrames=False /processorParam:PremultiplyTextureAlpha=True @@ -55,7 +54,6 @@ /processor:ModelProcessor /processorParam:ColorKeyColor=0,0,0,0 /processorParam:ColorKeyEnabled=True -/processorParam:DefaultEffect=BasicEffect /processorParam:GenerateMipmaps=True /processorParam:GenerateTangentFrames=False /processorParam:PremultiplyTextureAlpha=True diff --git a/TGC.MonoGame.TP/Environment/Terrain.cs b/TGC.MonoGame.TP/Environment/Terrain.cs index 7cf4196ba..07c188056 100644 --- a/TGC.MonoGame.TP/Environment/Terrain.cs +++ b/TGC.MonoGame.TP/Environment/Terrain.cs @@ -43,7 +43,7 @@ public Terrain(GraphicsDevice graphicsDevice, float squareSize, Texture2D textur public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length, Vector3 position) { GraphicsDevice = graphicsDevice; - Square = new SquarePrimitive(GraphicsDevice, squareSize, color, FloorNormal); + //Square = new SquarePrimitive(GraphicsDevice, squareSize, color, FloorNormal); // Create a list of places where the squares will be drawn SquareMatrices = new List() { @@ -65,10 +65,10 @@ public void Draw(Matrix view, Matrix projection) { foreach (var squareWorld in SquareMatrices) { var squareEffect = Square.Effect; - squareEffect.World = squareWorld; + /*squareEffect.World = squareWorld; squareEffect.View = view; squareEffect.Projection = projection; - squareEffect.LightingEnabled = false; + squareEffect.LightingEnabled = false;*/ Square.Draw(squareEffect); } } diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index b98e0e3fa..2fd14b757 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -25,7 +26,10 @@ public class CubePrimitive : GeometricPrimitive { /// /// Constructs a new cube primitive, with the specified size. /// - public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public CubePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; + // A cube has six faces, each one pointing in a different direction. Vector3[] normals = { @@ -69,16 +73,7 @@ public CubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { i++; } - InitializePrimitive(graphicsDevice); - } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); + InitializePrimitive(graphicsDevice, content); } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs index 5c87dbd0c..6e56ee71b 100644 --- a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -29,6 +30,8 @@ public abstract class GeometricPrimitive : IDisposable { #region Fields + public const string ContentFolderEffects = "Effects/"; + // During the process of constructing a primitive model, vertex and index data is stored on the CPU in these managed lists. public List Vertices { get; } = new List(); @@ -39,7 +42,11 @@ public abstract class GeometricPrimitive : IDisposable private VertexBuffer VertexBuffer { get; set; } private IndexBuffer IndexBuffer { get; set; } - public BasicEffect Effect { get; set; } + public Effect Effect { get; set; } + + public Matrix World { get; set; } + public Color Color { get; set; } + #endregion Fields @@ -75,8 +82,8 @@ protected void AddIndex(int index) /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index /// data into GPU format buffers, ready for efficient rendering. /// - protected void InitializePrimitive(GraphicsDevice graphicsDevice) - { + // + protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager content, Effect? primitiveEffect = null) { // Create a vertex declaration, describing the format of our vertex data. // Create a vertex buffer, and copy our vertex data into it. @@ -89,10 +96,8 @@ protected void InitializePrimitive(GraphicsDevice graphicsDevice) IndexBuffer.SetData(Indices.ToArray()); - // Create a BasicEffect, which will be used to render the primitive. - Effect = new BasicEffect(graphicsDevice); - Effect.VertexColorEnabled = true; - Effect.EnableDefaultLighting(); + Effect = primitiveEffect ?? content.Load(ContentFolderEffects + "BasicShader"); + } /// @@ -151,21 +156,16 @@ public void Draw(Effect effect) graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, primitiveCount); } } - - /// - /// Draw the box. - /// - /// The world matrix for this box. - /// The view matrix, normally from the camera. - /// The projection matrix, normally from the application. - public void Draw(Matrix world, Matrix view, Matrix projection) + + public void Draw(Matrix view, Matrix projection) { - // Set BasicEffect parameters. - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; + // Set Effect parameters. + Effect.Parameters["World"].SetValue(World); + Effect.Parameters["View"].SetValue(view); + Effect.Parameters["Projection"].SetValue(projection); + Effect.Parameters["DiffuseColor"].SetValue(Color.ToVector3()); - // Draw the model, using BasicEffect. + // Draw the model. Draw(Effect); } diff --git a/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs b/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs index 40019ec5f..3fd9fe27f 100644 --- a/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/PyramidPrimitive.cs @@ -13,6 +13,7 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -21,7 +22,7 @@ namespace TGC.MonoGame.TP.Geometries { public class PyramidPrimitive : GeometricPrimitive { - public PyramidPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public PyramidPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { Vector3[] vertexList = { @@ -42,11 +43,13 @@ public PyramidPrimitive(GraphicsDevice graphicsDevice, float size, Color color) AddTriangle(vertexList[0], vertexList[4], vertexList[2], size, color); AddTriangle(vertexList[0], vertexList[2], vertexList[1], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } - private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) - { + private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) { + + Color = color; + Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); AddIndex(CurrentVertex + 0); @@ -57,14 +60,5 @@ private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, floa AddVertex(vertex2 * size / 2, color, normal); AddVertex(vertex3 * size / 2, color, normal); } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/RampPrimitive.cs index 8e7e97b9b..7aa802ef3 100644 --- a/TGC.MonoGame.TP/Geometries/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/RampPrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -20,7 +21,9 @@ namespace TGC.MonoGame.TP.Geometries { public class RampPrimitive : GeometricPrimitive { - public RampPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public RampPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -48,7 +51,7 @@ public RampPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { AddTriangle(vertexList[0], vertexList[2], vertexList[4], size, color); AddTriangle(vertexList[5], vertexList[3], vertexList[1], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) @@ -63,14 +66,5 @@ private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, floa AddVertex(vertex2 * size / 2, color, normal); AddVertex(vertex3 * size / 2, color, normal); } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs index d55333c1c..51aa119ec 100644 --- a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs @@ -13,6 +13,7 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -25,17 +26,8 @@ namespace TGC.MonoGame.TP.Geometries /// public class SpherePrimitive : GeometricPrimitive { - /// - /// Constructs a new sphere primitive, with the specified size, tessellation level and white color. - /// - /// Used to initialize and control the presentation of the graphics device. - /// Diameter of the sphere. - /// The number of times the surface triangles are subdivided. - public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter = 1, int tessellation = 16) : this( - graphicsDevice, diameter, tessellation, Color.White) - { - } + /// /// Constructs a new sphere primitive, with the specified size, tessellation level and color. /// @@ -43,7 +35,7 @@ public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter = 1, int te /// Diameter of the sphere. /// The number of times the surface triangles are subdivided. /// Color of the sphere. - public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessellation, Color color) + public SpherePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float diameter, int tessellation, Color color, Matrix world) { if (tessellation < 3) throw new ArgumentOutOfRangeException("tessellation"); @@ -53,6 +45,9 @@ public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessel var radius = diameter / 2; + World = world; + Color = color; + // Start with a single vertex at the bottom of the sphere. AddVertex(Vector3.Down * radius, color, Vector3.Down); @@ -114,19 +109,7 @@ public SpherePrimitive(GraphicsDevice graphicsDevice, float diameter, int tessel AddIndex(CurrentVertex - 2 - i); } - - - - InitializePrimitive(graphicsDevice); - } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); + InitializePrimitive(graphicsDevice, content); } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs b/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs index 547211e84..7ae0039e8 100644 --- a/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -22,14 +23,15 @@ namespace TGC.MonoGame.TP.Geometries { /// public class SquarePrimitive : GeometricPrimitive { - public SquarePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Vector3.Up) {} + // public SquarePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Vector3.Up) {} /// /// Constructs a new square primitive, with the specified size and color. /// - public SquarePrimitive(GraphicsDevice graphicsDevice, float size, Color color, Vector3 faceNormal) { + public SquarePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color, Vector3 faceNormal) { Vector3 normal = faceNormal; + Color = color; // Get two vectors perpendicular to the face normal and to each other. var side1 = new Vector3(normal.Y, normal.Z, normal.X); @@ -51,7 +53,7 @@ public SquarePrimitive(GraphicsDevice graphicsDevice, float size, Color color, V AddVertex((normal + side1 - side2) * size / 2, color, normal); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index eb1a0f51e..8bfba3b32 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -118,219 +118,202 @@ protected override void LoadContent() // En el juego no pueden usar BasicEffect de MG, deben usar siempre efectos propios. Effect = Content.Load(ContentFolderEffects + "BasicShader"); - // Asigno el efecto que cargue a cada parte del mesh. - // Un modelo puede tener mas de 1 mesh internamente. - //foreach (var mesh in Model.Meshes) - //{ - // Un mesh puede tener mas de 1 mesh part (cada 1 puede tener su propio efecto). - // foreach (var meshPart in mesh.MeshParts) - //{ - // meshPart.Effect = Effect; - //} - //} - - //var floorTexture = Content.Load(ContentFolderTextures + "floor/tiling-base"); - - // Terrain = new Terrain(GraphicsDevice, SquareSize, Color.BlueViolet, 4, 4); - // Terrain2 = new Terrain(GraphicsDevice, SquareSize, Color.Coral, 2, 2, new Vector3(50, 20, 3)); - RampPrimitive Ramp; CubePrimitive Cube; Track = new List(); // PRIMERA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 0)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 0)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 25)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 25)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 50)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 50)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 75)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 75)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 100)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 100)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 125)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 125)); Track.Add(Cube); // SEGUNDA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 175)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 175)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 200)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 200)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 225)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 225)); Track.Add(Cube); // ESCALERA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(75, 25, 200)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(75, 25, 200)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(100, 50, 200)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(100, 50, 200)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(125, 75, 200)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(125, 75, 200)); Track.Add(Cube); // TERCERA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); Track.Add(Cube); //CUARTA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); Track.Add(Cube); // QUINTA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); Track.Add(Cube); // RAMPA - Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Ramp.Effect.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); + Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Ramp.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); Track.Add(Ramp); // CANALETA - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); Track.Add(Cube); - Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Ramp.Effect.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; + Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; Track.Add(Ramp); - Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Ramp.Effect.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; + Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; Track.Add(Ramp); // BOLITA // Propuesta de punto de inicio del escenario - Bola = new SpherePrimitive(GraphicsDevice, 25, 50, Color.White); - Bola.Effect.World = Matrix.CreateTranslation(new Vector3(25, 25, -800)); + Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(new Vector3(25, 25, -800))); // PLANOS INCLINADOS (ROLL) - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.BlueViolet); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.LightPink); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); Track.Add(Cube); // RAMPA GRANDE - Ramp = new RampPrimitive(GraphicsDevice, 25f, Color.LightPink); - Ramp.Effect.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); + Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.LightPink); + Ramp.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); Track.Add(Ramp); // CUADRADOS GRANDES - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Red); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Red); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Orange); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Orange); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Yellow); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Yellow); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Green); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Green); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Blue); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Blue); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Indigo); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Indigo); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Purple); - Cube.Effect.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Purple); + Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); Track.Add(Cube); // PLATAFORMA FINAL - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Aquamarine); - Cube.Effect.World = Matrix.CreateScale(7f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(425 , -125, -75)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); + Cube.World = Matrix.CreateScale(7f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(425 , -125, -75)); Track.Add(Cube); // aca iria la banderita del final - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.White); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(425, -100, -75)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.White); + Cube.World = Matrix.CreateTranslation(new Vector3(425, -100, -75)); Track.Add(Cube); // aca irian cartelitos //jump - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Black); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(-25, 50, 150)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); + Cube.World = Matrix.CreateTranslation(new Vector3(-25, 50, 150)); Track.Add(Cube); //up (flechita?) - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Black); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(50, 75, 250)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); + Cube.World = Matrix.CreateTranslation(new Vector3(50, 75, 250)); Track.Add(Cube); //jump - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Black); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 150, 150)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); + Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, 150)); Track.Add(Cube); //jump - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Black); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 150, -25)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); + Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, -25)); Track.Add(Cube); //down (flechita?) - Cube = new CubePrimitive(GraphicsDevice, 25f, Color.Black); - Cube.Effect.World = Matrix.CreateTranslation(new Vector3(200, 175, -475)); + Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); + Cube.World = Matrix.CreateTranslation(new Vector3(200, 175, -475)); Track.Add(Cube); @@ -354,12 +337,6 @@ protected override void Update(GameTime gameTime) Exit(); } - - // Basado en el tiempo que paso se va generando una rotacion. - //Rotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); - - //World = Matrix.CreateRotationY(Rotation); - base.Update(gameTime); } @@ -375,21 +352,14 @@ protected override void Draw(GameTime gameTime) // Para dibujar le modelo necesitamos pasarle informacion que el efecto esta esperando. Effect.Parameters["View"].SetValue(Camera.View); Effect.Parameters["Projection"].SetValue(Camera.Projection); - Effect.Parameters["DiffuseColor"].SetValue(Color.DarkBlue.ToVector3()); Bola.Draw(Camera.View, Camera.Projection); foreach (GeometricPrimitive primitive in Track) { - primitive.Draw(primitive.Effect.World, Camera.View, Camera.Projection); + primitive.Draw(Camera.View, Camera.Projection); } - - /* foreach (var mesh in Model.Meshes) - { - Effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * World); - mesh.Draw(); - }*/ } /// From fcee0e3e9661b3f33a71a4adabae96a99d52cf68 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sat, 18 May 2024 12:28:39 -0300 Subject: [PATCH 29/73] Arreglo problemas del merge --- TGC.MonoGame.TP/Environment/Terrain.cs | 76 ------------------- .../CustomPrimitives/CustomCubePrimitive.cs | 11 ++- .../CustomPrimitives/CustomPrimitive.cs | 11 +-- .../CustomPrimitives/DiamondPrimitive.cs | 7 +- .../CustomPrimitives/LightningPrimitive.cs | 7 +- .../CustomPrimitives/OctahedronPrimitive.cs | 7 +- .../CustomPrimitives/PyramidPrimitive.cs | 12 --- .../CustomPrimitives/RampPrimitive.cs | 13 ---- .../CustomPrimitives/RupeePrimitive.cs | 7 +- TGC.MonoGame.TP/Geometries/SquarePrimitive.cs | 59 -------------- TGC.MonoGame.TP/TGCGame.cs | 4 - 11 files changed, 28 insertions(+), 186 deletions(-) delete mode 100644 TGC.MonoGame.TP/Environment/Terrain.cs delete mode 100644 TGC.MonoGame.TP/Geometries/SquarePrimitive.cs diff --git a/TGC.MonoGame.TP/Environment/Terrain.cs b/TGC.MonoGame.TP/Environment/Terrain.cs deleted file mode 100644 index 07c188056..000000000 --- a/TGC.MonoGame.TP/Environment/Terrain.cs +++ /dev/null @@ -1,76 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// Terrain.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using TGC.MonoGame.TP.Geometries; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Environment { - /// - /// Basic primitive to build flat terrain using squares - /// - public class Terrain { - - private GraphicsDevice GraphicsDevice; - - private Vector3 FloorNormal = Vector3.Down; - private SquarePrimitive Square; - private List SquareMatrices; - - /// - /// Constructs a new terrain as a matrix of squares, with the specified square size, color, terrain width & length - /// - - public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length) : - this (graphicsDevice, squareSize, color, width, length, Vector3.Zero) {} - - public Terrain(GraphicsDevice graphicsDevice, float squareSize, Texture2D texture, int width, int length) : - this (graphicsDevice, squareSize, Color.White, width, length, Vector3.Zero) {} - - public Terrain(GraphicsDevice graphicsDevice, float squareSize, Color color, int width, int length, Vector3 position) { - - GraphicsDevice = graphicsDevice; - //Square = new SquarePrimitive(GraphicsDevice, squareSize, color, FloorNormal); - - // Create a list of places where the squares will be drawn - SquareMatrices = new List() { - Matrix.CreateTranslation(position) - }; - - for (int w = 0; w < width; w++) { - for (int l = 0; l < length; l++) { - if (width != 0 || length != 0) { - SquareMatrices.Add(Matrix.CreateTranslation((Vector3.Forward * l + Vector3.Right * w) * squareSize + position)); - } - } - } - - } - - public void Draw(Matrix view, Matrix projection) { - - foreach (var squareWorld in SquareMatrices) { - - var squareEffect = Square.Effect; - /*squareEffect.World = squareWorld; - squareEffect.View = view; - squareEffect.Projection = projection; - squareEffect.LightingEnabled = false;*/ - Square.Draw(squareEffect); - } - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs index b7fcea330..bd5dcd96d 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomCubePrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -20,10 +21,12 @@ namespace TGC.MonoGame.TP.Geometries { public class CustomCubePrimitive : CustomPrimitive { - // Esta clase crea un modelo prácticamente igual de al CubePrimitive. - // La agrago al proyecto únicamente como referencia para el uso de CustomPrimitive. + // Esta clase crea un modelo pr�cticamente igual de al CubePrimitive. + // La agrago al proyecto �nicamente como referencia para el uso de CustomPrimitive. - public CustomCubePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public CustomCubePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -61,7 +64,7 @@ public CustomCubePrimitive(GraphicsDevice graphicsDevice, float size, Color colo AddTriangle(vertexList[4], vertexList[5], vertexList[6], size, color); AddTriangle(vertexList[7], vertexList[6], vertexList[5], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs index 468f82703..a5b24ffaf 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/CustomPrimitive.cs @@ -18,7 +18,7 @@ namespace TGC.MonoGame.TP.Geometries { - public class CustomPrimitive : GeometricPrimitive { + public abstract class CustomPrimitive : GeometricPrimitive { protected void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) { @@ -32,14 +32,5 @@ protected void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, fl AddVertex(vertex2 * size / 2, color, normal); AddVertex(vertex3 * size / 2, color, normal); } - - public void Draw(Matrix view, Matrix projection) { - - var newEffect = this.Effect; - newEffect.View = view; - newEffect.Projection = projection; - - this.Draw(newEffect); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs index 519f64fc9..e709f38a1 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/DiamondPrimitive.cs @@ -13,6 +13,7 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -21,7 +22,9 @@ namespace TGC.MonoGame.TP.Geometries { public class DiamondPrimitive : CustomPrimitive { - public DiamondPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public DiamondPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -70,7 +73,7 @@ public DiamondPrimitive(GraphicsDevice graphicsDevice, float size, Color color) AddTriangle(vertexList[12], vertexList[7], vertexList[6], size, color); AddTriangle(vertexList[12], vertexList[6], vertexList[11], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs index 1342af292..178b796c8 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/LightningPrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -20,7 +21,9 @@ namespace TGC.MonoGame.TP.Geometries { public class LightningPrimitive : CustomPrimitive { - public LightningPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public LightningPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -60,7 +63,7 @@ public LightningPrimitive(GraphicsDevice graphicsDevice, float size, Color color AddTriangle(vertexList[8], vertexList[9], vertexList[2], size, color); AddTriangle(vertexList[3], vertexList[2], vertexList[9], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs index 0d04806f8..b5e895e86 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/OctahedronPrimitive.cs @@ -13,6 +13,7 @@ using System; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -21,7 +22,9 @@ namespace TGC.MonoGame.TP.Geometries { public class OctahedronPrimitive : CustomPrimitive { - public OctahedronPrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public OctahedronPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -45,7 +48,7 @@ public OctahedronPrimitive(GraphicsDevice graphicsDevice, float size, Color colo AddTriangle(vertexList[5], vertexList[2], vertexList[4], size, color); AddTriangle(vertexList[5], vertexList[1], vertexList[2], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs index 06b853771..aa1e706ca 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/PyramidPrimitive.cs @@ -47,17 +47,5 @@ public PyramidPrimitive(GraphicsDevice graphicsDevice, ContentManager content, f InitializePrimitive(graphicsDevice, content); } - private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) { - - Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddVertex(vertex1 * size / 2, color, normal); - AddVertex(vertex2 * size / 2, color, normal); - AddVertex(vertex3 * size / 2, color, normal); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index cb6675cef..62a6e9732 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -53,18 +53,5 @@ public RampPrimitive(GraphicsDevice graphicsDevice, ContentManager content, floa InitializePrimitive(graphicsDevice, content); } - - private void AddTriangle(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, float size, Color color) - { - Vector3 normal = Vector3.Cross(vertex1 - vertex2, vertex1 - vertex3); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddVertex(vertex1 * size / 2, color, normal); - AddVertex(vertex2 * size / 2, color, normal); - AddVertex(vertex3 * size / 2, color, normal); - } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs index b794743f2..0c9bac114 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs @@ -12,6 +12,7 @@ #region Using Statements using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion Using Statements @@ -20,7 +21,9 @@ namespace TGC.MonoGame.TP.Geometries { public class RupeePrimitive : CustomPrimitive { - public RupeePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { + public RupeePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + + Color = color; Vector3[] vertexList = { @@ -82,7 +85,7 @@ public RupeePrimitive(GraphicsDevice graphicsDevice, float size, Color color) { AddTriangle(vertexList[11], vertexList[6], vertexList[17], size, color); AddTriangle(vertexList[12], vertexList[17], vertexList[6], size, color); - InitializePrimitive(graphicsDevice); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs b/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs deleted file mode 100644 index 7ae0039e8..000000000 --- a/TGC.MonoGame.TP/Geometries/SquarePrimitive.cs +++ /dev/null @@ -1,59 +0,0 @@ -#region File Description - -//----------------------------------------------------------------------------- -// SquarePrimitive.cs -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#endregion File Description - -#region Using Statements - -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; - -#endregion Using Statements - -namespace TGC.MonoGame.TP.Geometries { - /// - /// Geometric primitive class for drawing squares. - /// - public class SquarePrimitive : GeometricPrimitive { - - // public SquarePrimitive(GraphicsDevice graphicsDevice) : this(graphicsDevice, 1, Color.White, Vector3.Up) {} - - /// - /// Constructs a new square primitive, with the specified size and color. - /// - public SquarePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color, Vector3 faceNormal) { - - Vector3 normal = faceNormal; - Color = color; - - // Get two vectors perpendicular to the face normal and to each other. - var side1 = new Vector3(normal.Y, normal.Z, normal.X); - var side2 = Vector3.Cross(normal, side1); - - // Six indices (two triangles) per face. - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 1); - AddIndex(CurrentVertex + 2); - - AddIndex(CurrentVertex + 0); - AddIndex(CurrentVertex + 2); - AddIndex(CurrentVertex + 3); - - // Four vertices per face. - AddVertex((normal - side1 - side2) * size / 2, color, normal); - AddVertex((normal - side1 + side2) * size / 2, color, normal); - AddVertex((normal + side1 + side2) * size / 2, color, normal); - AddVertex((normal + side1 - side2) * size / 2, color, normal); - - - InitializePrimitive(graphicsDevice, content); - } - } -} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 8bfba3b32..b8acb5bd3 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -5,7 +5,6 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using TGC.MonoGame.TP.Camera; -using TGC.MonoGame.TP.Environment; using TGC.MonoGame.TP.Geometries; namespace TGC.MonoGame.TP @@ -56,9 +55,6 @@ public TGCGame() // Camera to draw the scene private FreeCamera Camera { get; set; } - private Terrain Terrain { get; set; } - private Terrain Terrain2 { get; set; } - // BOLITA private SpherePrimitive Bola; private List Track; From 63807afb11d0a9121e92705c373172b72aeb76af Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sat, 18 May 2024 12:37:38 -0300 Subject: [PATCH 30/73] Limpieza de variables y codigo sin usar --- TGC.MonoGame.TP/TGCGame.cs | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index b8acb5bd3..7e11983f4 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -43,14 +43,6 @@ public TGCGame() private GraphicsDeviceManager Graphics { get; } private SpriteBatch SpriteBatch { get; set; } - private Model Model { get; set; } - private Effect Effect { get; set; } - private float Rotation { get; set; } - private Matrix World { get; set; } - private Matrix View { get; set; } - private Matrix Projection { get; set; } - - // Camera to draw the scene private FreeCamera Camera { get; set; } @@ -85,13 +77,6 @@ protected override void Initialize() rasterizerState.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rasterizerState; // Seria hasta aca. - - // Configuramos nuestras matrices de la escena. - World = Matrix.Identity; - View = Matrix.CreateLookAt(Vector3.UnitZ * 150, Vector3.Zero, Vector3.Up); - Projection = - Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 250); - base.Initialize(); } @@ -106,14 +91,6 @@ protected override void LoadContent() // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. SpriteBatch = new SpriteBatch(GraphicsDevice); - // Cargo el modelo del logo. - //Model = Content.Load(ContentFolder3D + "wooden-floor/Floor"); - - - // Cargo un efecto basico propio declarado en el Content pipeline. - // En el juego no pueden usar BasicEffect de MG, deben usar siempre efectos propios. - Effect = Content.Load(ContentFolderEffects + "BasicShader"); - RampPrimitive Ramp; CubePrimitive Cube; Track = new List(); @@ -345,14 +322,8 @@ protected override void Draw(GameTime gameTime) // Aca deberiamos poner toda la logia de renderizado del juego. GraphicsDevice.Clear(Color.LightSkyBlue); - // Para dibujar le modelo necesitamos pasarle informacion que el efecto esta esperando. - Effect.Parameters["View"].SetValue(Camera.View); - Effect.Parameters["Projection"].SetValue(Camera.Projection); - Bola.Draw(Camera.View, Camera.Projection); - - foreach (GeometricPrimitive primitive in Track) { primitive.Draw(Camera.View, Camera.Projection); } From 03c568e6fe1cf4e6e45a15a92b4fc568eed5589d Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 21 May 2024 02:10:11 -0300 Subject: [PATCH 31/73] Corrijo normales de RupeePrimitive --- .../CustomPrimitives/RupeePrimitive.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs index 0c9bac114..3a91a29f3 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RupeePrimitive.cs @@ -72,18 +72,18 @@ public RupeePrimitive(GraphicsDevice graphicsDevice, ContentManager content, flo AddTriangle(vertexList[16], vertexList[14], vertexList[17], size, color); AddTriangle(vertexList[13], vertexList[17], vertexList[14], size, color); // back to middle - AddTriangle(vertexList[6], vertexList[7], vertexList[12], size, color); - AddTriangle(vertexList[13], vertexList[12], vertexList[7], size, color); - AddTriangle(vertexList[7], vertexList[8], vertexList[13], size, color); - AddTriangle(vertexList[14], vertexList[13], vertexList[8], size, color); - AddTriangle(vertexList[8], vertexList[9], vertexList[14], size, color); - AddTriangle(vertexList[15], vertexList[14], vertexList[9], size, color); - AddTriangle(vertexList[9], vertexList[10], vertexList[15], size, color); - AddTriangle(vertexList[16], vertexList[15], vertexList[10], size, color); - AddTriangle(vertexList[10], vertexList[11], vertexList[16], size, color); - AddTriangle(vertexList[17], vertexList[16], vertexList[11], size, color); - AddTriangle(vertexList[11], vertexList[6], vertexList[17], size, color); - AddTriangle(vertexList[12], vertexList[17], vertexList[6], size, color); + AddTriangle(vertexList[6], vertexList[12], vertexList[7], size, color); + AddTriangle(vertexList[13], vertexList[7], vertexList[12], size, color); + AddTriangle(vertexList[7], vertexList[13], vertexList[8], size, color); + AddTriangle(vertexList[14], vertexList[8], vertexList[13], size, color); + AddTriangle(vertexList[8], vertexList[14], vertexList[9], size, color); + AddTriangle(vertexList[15], vertexList[9], vertexList[14], size, color); + AddTriangle(vertexList[9], vertexList[15], vertexList[10], size, color); + AddTriangle(vertexList[16], vertexList[10], vertexList[15], size, color); + AddTriangle(vertexList[10], vertexList[16], vertexList[11], size, color); + AddTriangle(vertexList[17], vertexList[11], vertexList[16], size, color); + AddTriangle(vertexList[11], vertexList[17], vertexList[6], size, color); + AddTriangle(vertexList[12], vertexList[6], vertexList[17], size, color); InitializePrimitive(graphicsDevice, content); } From e255ceab24d09fbc9a346a0ebc9e5e53f7703caf Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 21 May 2024 03:17:40 -0300 Subject: [PATCH 32/73] Agrego FollowCamera --- TGC.MonoGame.TP/Camera/FollowCamera.cs | 112 +++++++++++++++++++++++++ TGC.MonoGame.TP/TGCGame.cs | 41 +++++++-- 2 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 TGC.MonoGame.TP/Camera/FollowCamera.cs diff --git a/TGC.MonoGame.TP/Camera/FollowCamera.cs b/TGC.MonoGame.TP/Camera/FollowCamera.cs new file mode 100644 index 000000000..5c0eaa497 --- /dev/null +++ b/TGC.MonoGame.TP/Camera/FollowCamera.cs @@ -0,0 +1,112 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Text; + +namespace TGC.MonoGame.TP +{ + /// + /// Una camara que sigue objetos + /// + class FollowCamera + { + private const float AxisDistanceToTarget = 100f; + + private const float AngleFollowSpeed = 0.015f; + + private const float AngleThreshold = 0.85f; + + public Matrix Projection { get; private set; } + + public Matrix View { get; private set; } + + private Vector3 CurrentBackwardVector { get; set; } = Vector3.Backward; + + private float BackwardVectorInterpolator { get; set; } = 0f; + + private Vector3 PastBackwardVector { get; set; } = Vector3.Backward; + + /// + /// Crea una FollowCamera que sigue a una matriz de mundo + /// + /// + public FollowCamera(float aspectRatio) + { + // Orthographic camera + // Projection = Matrix.CreateOrthographic(screenWidth, screenHeight, 0.01f, 10000f); + + // Perspective camera + // Uso 60° como FOV, aspect ratio, pongo las distancias a near plane y far plane en 0.1 y 100000 (mucho) respectivamente + Projection = Matrix.CreatePerspectiveFieldOfView(MathF.PI / 3f, aspectRatio, 0.1f, 100000f); + } + + /// + /// Actualiza la Camara usando una matriz de mundo actualizada para seguirla + /// + /// The Game Time to calculate framerate-independent movement + /// The World matrix to follow + public void Update(GameTime gameTime, Matrix followedWorld) + { + // Obtengo el tiempo + var elapsedTime = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); + + // Obtengo la posicion de la matriz de mundo que estoy siguiendo + var followedPosition = followedWorld.Translation; + + // Obtengo el vector Backward de la matriz de mundo que estoy siguiendo + var followedBackward = followedWorld.Backward; + + // Si el producto escalar entre el vector Backward anterior + // y el actual es mas grande que un limite, + // muevo el Interpolator (desde 0 a 1) mas cerca de 1 + if (Vector3.Dot(followedBackward, PastBackwardVector) > AngleThreshold) + { + // Incremento el Interpolator + BackwardVectorInterpolator += elapsedTime * AngleFollowSpeed; + + // No permito que Interpolator pase de 1 + BackwardVectorInterpolator = MathF.Min(BackwardVectorInterpolator, 1f); + + // Calculo el vector Backward a partir de la interpolacion + // Esto mueve el vector Backward para igualar al vector Backward que sigo + // En este caso uso la curva x^2 para hacerlo mas suave + // Interpolator se convertira en 1 eventualmente + CurrentBackwardVector = Vector3.Lerp(CurrentBackwardVector, followedBackward, BackwardVectorInterpolator * BackwardVectorInterpolator); + } + else + // Si el angulo no pasa de cierto limite, lo pongo de nuevo en cero + BackwardVectorInterpolator = 0f; + + // Guardo el vector Derecha para usar en la siguiente iteracion + PastBackwardVector = followedBackward; + + // Calculo la posicion del a camara + // tomo la posicion que estoy siguiendo, agrego un offset en los ejes Y y Derecha + var offsetedPosition = followedPosition + + CurrentBackwardVector * AxisDistanceToTarget + + Vector3.Up * AxisDistanceToTarget; + + // Calculo el vector Arriba actualizado + // Nota: No se puede usar el vector Arriba por defecto (0, 1, 0) + // Como no es correcto, se calcula con este truco de producto vectorial + + // Calcular el vector Adelante haciendo la resta entre el destino y el origen + // y luego normalizandolo (Esta operacion es cara!) + // (La siguiente operacion necesita vectores normalizados) + var forward = (followedPosition - offsetedPosition); + forward.Normalize(); + + // Obtengo el vector Derecha asumiendo que la camara tiene el vector Arriba apuntando hacia arriba + // y no esta rotada en el eje X (Roll) + var right = Vector3.Cross(forward, Vector3.Up); + + // Una vez que tengo la correcta direccion Derecha, obtengo la correcta direccion Arriba usando + // otro producto vectorial + var cameraCorrectUp = Vector3.Cross(right, forward); + + // Calculo la matriz de Vista de la camara usando la Posicion, La Posicion a donde esta mirando, + // y su vector Arriba + View = Matrix.CreateLookAt(offsetedPosition, followedPosition, cameraCorrectUp); + } + } +} diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 7e11983f4..49462d5a2 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using BepuPhysics.Collidables; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -46,8 +45,10 @@ public TGCGame() // Camera to draw the scene private FreeCamera Camera { get; set; } + private FollowCamera FollowCamera { get; set; } // BOLITA + private Vector3 Position { get; set; } private SpherePrimitive Bola; private List Track; @@ -65,8 +66,13 @@ protected override void Initialize() var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; - var cameraPosition = new Vector3(25f, 100f, -1100f); - Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); + + + //var cameraPosition = new Vector3(25f, 100f, -1100f); + //Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); + // Creo una camaar para seguir a nuestro auto. + FollowCamera = new FollowCamera(GraphicsDevice.Viewport.AspectRatio); + // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. @@ -301,14 +307,35 @@ protected override void LoadContent() protected override void Update(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. - Camera.Update(gameTime); + float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + float speed = 100; // Capturar Input teclado - if (Keyboard.GetState().IsKeyDown(Keys.Escape)) + var keyboardState = Keyboard.GetState(); + if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) + { + Position += Vector3.Right * speed * elapsedTime; + } + else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) + { + Position += Vector3.Left * speed * elapsedTime; + } + else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) + { + Position += Vector3.Forward * speed * elapsedTime; + } + else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) + { + Position += Vector3.Backward * speed * elapsedTime; + } + else if(Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Salgo del juego. Exit(); } + Bola.World = Matrix.CreateTranslation(Position); + + FollowCamera.Update(gameTime, Bola.World); base.Update(gameTime); } @@ -322,10 +349,10 @@ protected override void Draw(GameTime gameTime) // Aca deberiamos poner toda la logia de renderizado del juego. GraphicsDevice.Clear(Color.LightSkyBlue); - Bola.Draw(Camera.View, Camera.Projection); + Bola.Draw(FollowCamera.View, FollowCamera.Projection); foreach (GeometricPrimitive primitive in Track) { - primitive.Draw(Camera.View, Camera.Projection); + primitive.Draw(FollowCamera.View, FollowCamera.Projection); } } From a63e0e8fe7dc616fd09aa01fca1e1ecd83314e63 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 21 May 2024 16:15:14 -0300 Subject: [PATCH 33/73] =?UTF-8?q?Corrijo=20inicializaci=C3=B3n=20de=20la?= =?UTF-8?q?=20variable=20posici=C3=B3n=20de=20la=20bola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 49462d5a2..609c4cc50 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -203,7 +203,8 @@ protected override void LoadContent() // BOLITA // Propuesta de punto de inicio del escenario - Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(new Vector3(25, 25, -800))); + Position = new Vector3(25, 25, -775); + Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(Position)); // PLANOS INCLINADOS (ROLL) Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); From b71b6b4efa5416dee8d2bbe483959a1e70efb6ba Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 21 May 2024 17:28:44 -0300 Subject: [PATCH 34/73] =?UTF-8?q?Agregada=20cinem=C3=A1tica.=20Falta=20cor?= =?UTF-8?q?regir=20la=20aceleraci=C3=B3n=20a=20los=20costados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 609c4cc50..9543d9563 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -48,7 +48,15 @@ public TGCGame() private FollowCamera FollowCamera { get; set; } // BOLITA + //física private Vector3 Position { get; set; } + private Vector3 Velocity { get; set; } + private Vector3 Acceleration { get; set; } = Vector3.Zero; + + private Quaternion Rotation { get; set; } = Quaternion.Identity; + private Vector3 RotationAxis {get; set; } = Vector3.UnitY; + private float RotationAngle = 0f; + //física private SpherePrimitive Bola; private List Track; @@ -315,27 +323,41 @@ protected override void Update(GameTime gameTime) var keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { - Position += Vector3.Right * speed * elapsedTime; + //Position += Vector3.Right * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation); } else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { - Position += Vector3.Left * speed * elapsedTime; + //Position += Vector3.Left * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation) * (- 1); } else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { - Position += Vector3.Forward * speed * elapsedTime; + //Position += Vector3.Forward * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); } else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { - Position += Vector3.Backward * speed * elapsedTime; + //Position += Vector3.Backward * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); } else if(Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Salgo del juego. Exit(); } + + Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); + + var direction = Vector3.Transform(Vector3.UnitZ, Rotation); + + Velocity += Acceleration * elapsedTime; + Position += direction * Velocity * elapsedTime * 0.5f; + Bola.World = Matrix.CreateTranslation(Position); + Acceleration = Vector3.Zero; + FollowCamera.Update(gameTime, Bola.World); base.Update(gameTime); From 3068bedd14fc311e826ab0e75f95528237fa3109 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 21 May 2024 22:07:55 -0300 Subject: [PATCH 35/73] =?UTF-8?q?Reduzco=20la=20cantidad=20de=20tri=C3=A1n?= =?UTF-8?q?gulos=20de=20la=20esfera?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 9543d9563..babd6479c 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -212,7 +212,7 @@ protected override void LoadContent() // BOLITA // Propuesta de punto de inicio del escenario Position = new Vector3(25, 25, -775); - Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(Position)); + Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 10, Color.Red, Matrix.CreateTranslation(Position)); // PLANOS INCLINADOS (ROLL) Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); From 78e3bfb5c87c818cf709342f8d035d53fe02a7d5 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 21 May 2024 23:16:31 -0300 Subject: [PATCH 36/73] Agrego entidad de personaje principal con cambio de materiales usando texturas + arreglo direccion de la camara y distancia de seguimiento al personaje --- TGC.MonoGame.TP/Camera/FollowCamera.cs | 14 +- .../Content/3D/geometries/sphere.fbx | 3 + TGC.MonoGame.TP/Content/3D/sphere.fbx | 3 + TGC.MonoGame.TP/Content/Content.mgcb | 506 +++++++++++++++++- TGC.MonoGame.TP/Content/Effects/PBR.fx | 258 +++++++++ .../Content/Textures/materials/gold/ao.png | 3 + .../Content/Textures/materials/gold/color.jpg | 3 + .../Textures/materials/gold/displacement.jpg | 3 + .../Textures/materials/gold/metalness.jpg | 3 + .../Textures/materials/gold/normal.jpg | 3 + .../Textures/materials/gold/roughness.jpg | 3 + .../Content/Textures/materials/ground/ao.jpg | 3 + .../Textures/materials/ground/color.jpg | 3 + .../materials/ground/displacement.jpg | 3 + .../Textures/materials/ground/metalness.jpg | 3 + .../Textures/materials/ground/normal.jpg | 3 + .../Textures/materials/ground/roughness.jpg | 3 + .../Textures/materials/harsh-metal/ao.png | 3 + .../Textures/materials/harsh-metal/color.jpg | 3 + .../materials/harsh-metal/displacement.jpg | 3 + .../materials/harsh-metal/metalness.jpg | 3 + .../Textures/materials/harsh-metal/normal.jpg | 3 + .../materials/harsh-metal/roughness.jpg | 3 + .../Content/Textures/materials/marble/ao.png | 3 + .../Textures/materials/marble/color.jpg | 3 + .../materials/marble/displacement.jpg | 3 + .../Textures/materials/marble/metalness.jpg | 3 + .../Textures/materials/marble/normal.jpg | 3 + .../Textures/materials/marble/roughness.jpg | 3 + .../Content/Textures/materials/metal/ao.png | 3 + .../Textures/materials/metal/color.jpg | 3 + .../Textures/materials/metal/displacement.jpg | 3 + .../Textures/materials/metal/metalness.jpg | 3 + .../Textures/materials/metal/normal.jpg | 3 + .../Textures/materials/metal/roughness.jpg | 3 + .../MainCharacter/MainCharacter.cs | 216 ++++++++ TGC.MonoGame.TP/MainCharacter/Material.cs | 11 + TGC.MonoGame.TP/TGCGame.cs | 61 +-- 38 files changed, 1094 insertions(+), 68 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/3D/geometries/sphere.fbx create mode 100644 TGC.MonoGame.TP/Content/3D/sphere.fbx create mode 100644 TGC.MonoGame.TP/Content/Effects/PBR.fx create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/ao.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/ground/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/metal/roughness.jpg create mode 100644 TGC.MonoGame.TP/MainCharacter/MainCharacter.cs create mode 100644 TGC.MonoGame.TP/MainCharacter/Material.cs diff --git a/TGC.MonoGame.TP/Camera/FollowCamera.cs b/TGC.MonoGame.TP/Camera/FollowCamera.cs index 5c0eaa497..007f6347d 100644 --- a/TGC.MonoGame.TP/Camera/FollowCamera.cs +++ b/TGC.MonoGame.TP/Camera/FollowCamera.cs @@ -10,9 +10,9 @@ namespace TGC.MonoGame.TP /// class FollowCamera { - private const float AxisDistanceToTarget = 100f; + private const float AxisDistanceToTarget = 20f; - private const float AngleFollowSpeed = 0.015f; + private const float AngleFollowSpeed = 0.03f; private const float AngleThreshold = 0.85f; @@ -20,11 +20,11 @@ class FollowCamera public Matrix View { get; private set; } - private Vector3 CurrentBackwardVector { get; set; } = Vector3.Backward; + private Vector3 CurrentBackwardVector { get; set; } = Vector3.Forward; private float BackwardVectorInterpolator { get; set; } = 0f; - private Vector3 PastBackwardVector { get; set; } = Vector3.Backward; + private Vector3 PastBackwardVector { get; set; } = Vector3.Forward; /// /// Crea una FollowCamera que sigue a una matriz de mundo @@ -54,7 +54,7 @@ public void Update(GameTime gameTime, Matrix followedWorld) var followedPosition = followedWorld.Translation; // Obtengo el vector Backward de la matriz de mundo que estoy siguiendo - var followedBackward = followedWorld.Backward; + var followedBackward = followedWorld.Forward; // Si el producto escalar entre el vector Backward anterior // y el actual es mas grande que un limite, @@ -84,7 +84,7 @@ public void Update(GameTime gameTime, Matrix followedWorld) // tomo la posicion que estoy siguiendo, agrego un offset en los ejes Y y Derecha var offsetedPosition = followedPosition + CurrentBackwardVector * AxisDistanceToTarget - + Vector3.Up * AxisDistanceToTarget; + + Vector3.Up * AxisDistanceToTarget * 5f; // Calculo el vector Arriba actualizado // Nota: No se puede usar el vector Arriba por defecto (0, 1, 0) @@ -93,7 +93,7 @@ public void Update(GameTime gameTime, Matrix followedWorld) // Calcular el vector Adelante haciendo la resta entre el destino y el origen // y luego normalizandolo (Esta operacion es cara!) // (La siguiente operacion necesita vectores normalizados) - var forward = (followedPosition - offsetedPosition); + var forward = followedPosition - offsetedPosition; forward.Normalize(); // Obtengo el vector Derecha asumiendo que la camara tiene el vector Arriba apuntando hacia arriba diff --git a/TGC.MonoGame.TP/Content/3D/geometries/sphere.fbx b/TGC.MonoGame.TP/Content/3D/geometries/sphere.fbx new file mode 100644 index 000000000..fd3ccbd6c --- /dev/null +++ b/TGC.MonoGame.TP/Content/3D/geometries/sphere.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7133524057e856ee41b279adb598c9ddb326f5e2c79818512aa2cabea22bc472 +size 43324 diff --git a/TGC.MonoGame.TP/Content/3D/sphere.fbx b/TGC.MonoGame.TP/Content/3D/sphere.fbx new file mode 100644 index 000000000..fd3ccbd6c --- /dev/null +++ b/TGC.MonoGame.TP/Content/3D/sphere.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7133524057e856ee41b279adb598c9ddb326f5e2c79818512aa2cabea22bc472 +size 43324 diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 5b1cbd309..63f93d2ef 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -13,17 +13,31 @@ #---------------------------------- Content ---------------------------------# -#begin Effects/BasicShader.fx -/importer:EffectImporter -/processor:EffectProcessor -/processorParam:DebugMode=Auto -/build:Effects/BasicShader.fx +#begin 3D/geometries/sphere.fbx +/importer:FbxImporter +/processor:ModelProcessor +/processorParam:ColorKeyColor=0,0,0,0 +/processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect +/processorParam:GenerateMipmaps=True +/processorParam:GenerateTangentFrames=False +/processorParam:PremultiplyTextureAlpha=True +/processorParam:PremultiplyVertexColors=True +/processorParam:ResizeTexturesToPowerOfTwo=False +/processorParam:RotationX=0 +/processorParam:RotationY=0 +/processorParam:RotationZ=0 +/processorParam:Scale=1 +/processorParam:SwapWindingOrder=False +/processorParam:TextureFormat=Compressed +/build:3D/geometries/sphere.fbx -#begin Models/sign/StreetSign.fbx +#begin 3D/sphere.fbx /importer:FbxImporter /processor:ModelProcessor /processorParam:ColorKeyColor=0,0,0,0 /processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect /processorParam:GenerateMipmaps=True /processorParam:GenerateTangentFrames=False /processorParam:PremultiplyTextureAlpha=True @@ -35,9 +49,21 @@ /processorParam:Scale=1 /processorParam:SwapWindingOrder=False /processorParam:TextureFormat=Compressed -/build:Models/sign/StreetSign.fbx +/build:3D/sphere.fbx -#begin Models/sign/textures/Sign.png +#begin Effects/BasicShader.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:Effects/BasicShader.fx + +#begin Effects/PBR.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:Effects/PBR.fx + +#begin Models/sign/Sign.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -49,11 +75,31 @@ /processorParam:TextureFormat=Color /build:Models/sign/Sign.png +#begin Models/sign/StreetSign.fbx +/importer:FbxImporter +/processor:ModelProcessor +/processorParam:ColorKeyColor=0,0,0,0 +/processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect +/processorParam:GenerateMipmaps=True +/processorParam:GenerateTangentFrames=False +/processorParam:PremultiplyTextureAlpha=True +/processorParam:PremultiplyVertexColors=True +/processorParam:ResizeTexturesToPowerOfTwo=False +/processorParam:RotationX=0 +/processorParam:RotationY=0 +/processorParam:RotationZ=0 +/processorParam:Scale=1 +/processorParam:SwapWindingOrder=False +/processorParam:TextureFormat=Compressed +/build:Models/sign/StreetSign.fbx + #begin Models/tgc-logo/tgc-logo.fbx /importer:FbxImporter /processor:ModelProcessor /processorParam:ColorKeyColor=0,0,0,0 /processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect /processorParam:GenerateMipmaps=True /processorParam:GenerateTangentFrames=False /processorParam:PremultiplyTextureAlpha=True @@ -67,3 +113,447 @@ /processorParam:TextureFormat=Compressed /build:Models/tgc-logo/tgc-logo.fbx +#begin Textures/floor/tiling-base.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/floor/tiling-base.png + +#begin Textures/materials/gold/ao.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/ao.png + +#begin Textures/materials/gold/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/color.jpg + +#begin Textures/materials/gold/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/displacement.jpg + +#begin Textures/materials/gold/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/metalness.jpg + +#begin Textures/materials/gold/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/normal.jpg + +#begin Textures/materials/gold/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/gold/roughness.jpg + +#begin Textures/materials/ground/ao.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/ao.jpg + +#begin Textures/materials/ground/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/color.jpg + +#begin Textures/materials/ground/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/displacement.jpg + +#begin Textures/materials/ground/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/metalness.jpg + +#begin Textures/materials/ground/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/normal.jpg + +#begin Textures/materials/ground/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/ground/roughness.jpg + +#begin Textures/materials/harsh-metal/ao.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/ao.png + +#begin Textures/materials/harsh-metal/ao.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/ao.png + +#begin Textures/materials/harsh-metal/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/color.jpg + +#begin Textures/materials/harsh-metal/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/color.jpg + +#begin Textures/materials/harsh-metal/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/displacement.jpg + +#begin Textures/materials/harsh-metal/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/displacement.jpg + +#begin Textures/materials/harsh-metal/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/metalness.jpg + +#begin Textures/materials/harsh-metal/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/metalness.jpg + +#begin Textures/materials/harsh-metal/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/normal.jpg + +#begin Textures/materials/harsh-metal/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/normal.jpg + +#begin Textures/materials/harsh-metal/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/roughness.jpg + +#begin Textures/materials/harsh-metal/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/harsh-metal/roughness.jpg + +#begin Textures/materials/marble/ao.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/ao.png + +#begin Textures/materials/marble/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/color.jpg + +#begin Textures/materials/marble/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/displacement.jpg + +#begin Textures/materials/marble/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/metalness.jpg + +#begin Textures/materials/marble/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/normal.jpg + +#begin Textures/materials/marble/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/marble/roughness.jpg + +#begin Textures/materials/metal/ao.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/ao.png + +#begin Textures/materials/metal/color.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/color.jpg + +#begin Textures/materials/metal/displacement.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/displacement.jpg + +#begin Textures/materials/metal/metalness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/metalness.jpg + +#begin Textures/materials/metal/normal.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/normal.jpg + +#begin Textures/materials/metal/roughness.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/materials/metal/roughness.jpg + diff --git a/TGC.MonoGame.TP/Content/Effects/PBR.fx b/TGC.MonoGame.TP/Content/Effects/PBR.fx new file mode 100644 index 000000000..ac02ddafe --- /dev/null +++ b/TGC.MonoGame.TP/Content/Effects/PBR.fx @@ -0,0 +1,258 @@ +#if OPENGL + #define SV_POSITION POSITION + #define VS_SHADERMODEL vs_3_0 + #define PS_SHADERMODEL ps_3_0 +#else + #define VS_SHADERMODEL vs_4_0_level_9_1 + #define PS_SHADERMODEL ps_4_0_level_9_1 +#endif + +float4x4 matWorld; //Matriz de transformacion World +float4x4 matWorldViewProj; //Matriz World * View * Projection +float3x3 matInverseTransposeWorld; //Matriz Transpose(Invert(World)) + +//Textura para Albedo +texture albedoTexture; +sampler2D albedoSampler = sampler_state +{ + Texture = (albedoTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Normals +texture normalTexture; +sampler2D normalSampler = sampler_state +{ + Texture = (normalTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Metallic +texture metallicTexture; +sampler2D metallicSampler = sampler_state +{ + Texture = (metallicTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Roughness +texture roughnessTexture; +sampler2D roughnessSampler = sampler_state +{ + Texture = (roughnessTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Ambient Occlusion +texture aoTexture; +sampler2D aoSampler = sampler_state +{ + Texture = (aoTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Input del Vertex Shader +struct Light +{ + float3 Position; + float3 Color; +} ; + +#define LIGHT_COUNT 4 + +float3 lightPositions[4]; +float3 lightColors[4]; + +float3 eyePosition; //Posicion de la camara + +static const float PI = 3.14159265359; + +//Input del Vertex Shader +struct VertexShaderInput +{ + float4 Position : POSITION0; + float3 Normal : NORMAL0; + float2 TextureCoordinates : TEXCOORD0; +}; + +//Output del Vertex Shader +struct VertexShaderOutput +{ + float4 Position : POSITION0; + float2 TextureCoordinates : TEXCOORD0; + float3 WorldNormal : TEXCOORD1; + float4 WorldPosition : TEXCOORD2; +}; + +//Vertex Shader +VertexShaderOutput MainVS(VertexShaderInput input) +{ + VertexShaderOutput output; + + // Proyectamos la position + output.Position = mul(input.Position, matWorldViewProj); + + // Propagamos las coordenadas de textura + output.TextureCoordinates = input.TextureCoordinates; + + // Usamos la matriz normal para proyectar el vector normal + output.WorldNormal = mul(input.Normal, matInverseTransposeWorld); + + // Usamos la matriz de world para proyectar la posicion + output.WorldPosition = mul(input.Position, matWorld); + + return output; +} + +float3 getNormalFromMap(float2 textureCoordinates, float3 worldPosition, float3 worldNormal) +{ + float3 tangentNormal = tex2D(normalSampler, textureCoordinates).xyz * 2.0 - 1.0; + + float3 Q1 = ddx(worldPosition); + float3 Q2 = ddy(worldPosition); + float2 st1 = ddx(textureCoordinates); + float2 st2 = ddy(textureCoordinates); + + worldNormal = normalize(worldNormal.xyz); + float3 T = normalize(Q1 * st2.y - Q2 * st1.y); + float3 B = -normalize(cross(worldNormal, T)); + float3x3 TBN = float3x3(T, B, worldNormal); + + return normalize(mul(tangentNormal, TBN)); +} + +float DistributionGGX(float3 normal, float3 halfVector, float roughness) +{ + float a = roughness * roughness; + float a2 = a * a; + float NdotH = max(dot(normal, halfVector), 0.0); + float NdotH2 = NdotH * NdotH; + + float nom = a2; + float denom = (NdotH2 * (a2 - 1.0) + 1.0); + denom = PI * denom * denom; + + return nom / denom; +} + +float GeometrySchlickGGX(float NdotV, float roughness) +{ + float r = (roughness + 1.0); + float k = (r * r) / 8.0; + + float nom = NdotV; + float denom = NdotV * (1.0 - k) + k; + + return nom / denom; +} + +float GeometrySmith(float3 normal, float3 view, float3 light, float roughness) +{ + float NdotV = max(dot(normal, view), 0.0); + float NdotL = max(dot(normal, light), 0.0); + float ggx2 = GeometrySchlickGGX(NdotV, roughness); + float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} + +float3 fresnelSchlick(float cosTheta, float3 F0) +{ + return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); +} + +//Pixel Shader +float4 MainPS(VertexShaderOutput input) : COLOR +{ + float3 albedo = pow(tex2D(albedoSampler, input.TextureCoordinates).rgb, float3(2.2, 2.2, 2.2)); + float metallic = tex2D(metallicSampler, input.TextureCoordinates).r; + float roughness = tex2D(roughnessSampler, input.TextureCoordinates).r; + float ao = tex2D(aoSampler, input.TextureCoordinates).r; + + + + float3 worldNormal = input.WorldNormal; + float3 normal = getNormalFromMap(input.TextureCoordinates, input.WorldPosition.xyz, worldNormal); + float3 view = normalize(eyePosition - input.WorldPosition.xyz); + + float3 F0 = float3(0.04, 0.04, 0.04); + F0 = lerp(F0, albedo, metallic); + + // Reflectance equation + float3 Lo = float3(0.0, 0.0, 0.0); + + for (int index = 0; index < 4; index++) + { + float3 light = lightPositions[index] - input.WorldPosition.xyz; + float distance = length(light); + // Normalize our light vector after using its length + light = normalize(light); + float3 halfVector = normalize(view + light); + float attenuation = 1.0 / (distance); + float3 radiance = lightColors[index] * attenuation; + + + // Cook-Torrance BRDF + float NDF = DistributionGGX(normal, halfVector, roughness); + float G = GeometrySmith(normal, view, light, roughness); + float3 F = fresnelSchlick(max(dot(halfVector, view), 0.0), F0); + + float3 nominator = NDF * G * F; + float denominator = 4.0 * max(dot(normal, view), 0.0) + 0.001; + float3 specular = nominator / denominator; + + float3 kS = F; + + float3 kD = float3(1.0, 1.0, 1.0) - kS; + + kD *= 1.0 - metallic; + + // Scale light by NdotL + float NdotL = max(dot(normal, light), 0.0); + + //TODO + Lo += (kD * NdotL * albedo / PI + specular) * radiance; + } + + float3 ambient = float3(0.03, 0.03, 0.03) * albedo * ao; + + float3 color = ambient + Lo; + + // HDR tonemapping + color = color / (color + float3(1, 1, 1)); + + float exponent = 1.0 / 2.2; + // Gamma correct + color = pow(color, float3(exponent, exponent, exponent)); + + return float4(color, 1.0); +} + +technique PBR +{ + pass P0 + { + VertexShader = compile VS_SHADERMODEL MainVS(); + PixelShader = compile PS_SHADERMODEL MainPS(); + } +}; \ No newline at end of file diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png new file mode 100644 index 000000000..da83020f2 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de8724d7a74f84750b643d16e9ae9fdf911cc71c9ab37b7f5df9b57c1a4470e9 +size 151 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold/color.jpg new file mode 100644 index 000000000..18ac4367a --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:993c2ed9106078e13910128d5e4ff283a12cc794c666b03bc0e4f647cd539b93 +size 4983449 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold/displacement.jpg new file mode 100644 index 000000000..840409aee --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7ec767389cc8af82d4a16ff616d9b96897fd07c2f6291128f9d5c5378dc30ed +size 872221 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold/metalness.jpg new file mode 100644 index 000000000..e10310441 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c00541f20b4db336a906a6d171330427c898ac3edb327b87025b7fa3d3e7a4b +size 422351 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold/normal.jpg new file mode 100644 index 000000000..155af1a86 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a61b34ab6a6962f77b475d68b3dd7106e0e3dae85a432478859d2f2c0a0e920 +size 2673784 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold/roughness.jpg new file mode 100644 index 000000000..9d609dcbe --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e188527e8a183d7acc025bcf21fdab89b757f52552e71064eb67024ffcecbac5 +size 2178185 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/ao.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/ao.jpg new file mode 100644 index 000000000..41b45dddd --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/ao.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8541699952bcf8bb41f701cf81d10a3a8a0dbdcc904b25c3ab62802eb21f490e +size 2274967 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/color.jpg new file mode 100644 index 000000000..5c82bc83b --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d35e1f871609f5e4c47a032d5e622c30f163576eb3dbb0d2afba1be226a3679 +size 8673710 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/displacement.jpg new file mode 100644 index 000000000..752470d48 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02a93fdb0b100403ea474a5b12dc25190394f20880f7963ceaff5b330b7fdb66 +size 1720113 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/metalness.jpg new file mode 100644 index 000000000..a9837c364 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:701e25ba73adcd45a90c701fa66e4b1d0916577de163ea906cfdb14f9a1ecb59 +size 735 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/normal.jpg new file mode 100644 index 000000000..47c89d4f1 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77ba2ce37b76cae6b29b2878b1cf0dc6141abd486925ac4904bb5ffadb108fe8 +size 9794785 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/ground/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/ground/roughness.jpg new file mode 100644 index 000000000..fe4afcc0e --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/ground/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62a2931ff01ae3ed58f7cfa3467c0e16e4ad0fe78141841e05ae58ce31ad105c +size 3242027 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/ao.png new file mode 100644 index 000000000..da83020f2 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de8724d7a74f84750b643d16e9ae9fdf911cc71c9ab37b7f5df9b57c1a4470e9 +size 151 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/color.jpg new file mode 100644 index 000000000..58a6b3766 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:232ec9db41e093957a3586af6f35f1aa93a119e8f64c2bba9036808d1eed8be1 +size 5609432 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/displacement.jpg new file mode 100644 index 000000000..ebfacb99e --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e1b4e22fa8929aacf8020b3eb54dd8483c257a44cc6f6ef90dca21f03adf682 +size 2917872 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/metalness.jpg new file mode 100644 index 000000000..8a4d1e1b1 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:256a395ac5c23500e64362d2e2e230b747e72d7daa4387f4feb70785a9de46d3 +size 3360526 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/normal.jpg new file mode 100644 index 000000000..b14b26ed1 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38a4d89e44d23f3c56e31e9c6582496965a2e6f74d00867a000e57c53d5f59ea +size 5554346 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/roughness.jpg new file mode 100644 index 000000000..e55697be3 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/harsh-metal/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3732160ae1c62cc4206b2d07b2d9b43b6c0f93a082c5b13d70edd7a040ab626 +size 2912566 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png new file mode 100644 index 000000000..e3542ec8a --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11fdc43f6316601b8bbabf8c4706dc04972920bb293c0d706d1f9981dd6107f3 +size 157 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg new file mode 100644 index 000000000..67306298e --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d608a8eabeba10aefabb6e8be3eb0bbc49090fb799b75fa6e231fcbdee55fc8 +size 4756197 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg new file mode 100644 index 000000000..08e821917 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:315f39976d6248eb1bb8e5ad899e42f17e6653655c6c25901eb0317811f9d1a0 +size 3268121 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/metalness.jpg new file mode 100644 index 000000000..a9837c364 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:701e25ba73adcd45a90c701fa66e4b1d0916577de163ea906cfdb14f9a1ecb59 +size 735 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg new file mode 100644 index 000000000..31959cf9c --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72121aa2409c314fe2036dfda99e9b2ea88514e2b07507c20aa527da693643a8 +size 1367869 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg new file mode 100644 index 000000000..415d96239 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72bc83992be6ad0c0838be9b26e466ea8b2348dd5c7d7be8c4ff9dfc50695855 +size 2274425 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/metal/ao.png new file mode 100644 index 000000000..da83020f2 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de8724d7a74f84750b643d16e9ae9fdf911cc71c9ab37b7f5df9b57c1a4470e9 +size 151 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/metal/color.jpg new file mode 100644 index 000000000..f84d65319 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6722c39247c99b776dc0c916fefb9695f187b37317680103b77970fa8b9eeb6 +size 3288584 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/metal/displacement.jpg new file mode 100644 index 000000000..2a656a4ef --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ea4c182c457eca4d689b9b6e8c1376d65d708afdba00daefd5f0b1462b266f7 +size 3476334 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/metal/metalness.jpg new file mode 100644 index 000000000..afd0fe3a6 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b65d6b9091747bd81ee58adedcb6209d8ee21b2bde9298d7216989ada85ef622 +size 16545 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/metal/normal.jpg new file mode 100644 index 000000000..e776b9827 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe51f6acc7acaf3c0041f990bdcaf680afbf5367747373724235af7f50df35b6 +size 6183275 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/metal/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/metal/roughness.jpg new file mode 100644 index 000000000..041389a0f --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/metal/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be9a6b25066276c22f3d82f3a9ef491d4595ea4d8d1db71f3076310eb5bff5ef +size 2694458 diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs new file mode 100644 index 000000000..1fe41482c --- /dev/null +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -0,0 +1,216 @@ +using System; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace TGC.MonoGame.TP.MainCharacter +{ + public class Character + { + const string ContentFolder3D = "3D/"; + const string ContentFolderEffects = "Effects/"; + const string ContentFolderTextures = "Textures/"; + + string TexturePath; + + ContentManager Content; + + Model Sphere; + public Matrix World; + Matrix Scale = Matrix.CreateScale(12.5f); + Effect Effect; + + Material CurrentMaterial = Material.RustedMetal; + + Vector3 Position; + Vector3 Velocity; + Vector3 Acceleration = Vector3.Zero; + Quaternion Rotation = Quaternion.Identity; + Vector3 RotationAxis = Vector3.UnitY; + float RotationAngle = 0f; + + + public Character(ContentManager content, Vector3 initialPosition) + { + Content = content; + + + InitializeEffect(); + InitializeSphere(initialPosition); + InitializeTextures(); + } + + + private void InitializeSphere(Vector3 initialPosition) + { + // Got to set a texture, else the translation to mesh does not map UV + Sphere = Content.Load(ContentFolder3D + "geometries/sphere"); + + Position = initialPosition; + World = Scale * Matrix.CreateTranslation(Position); + + // Apply the effect to all mesh parts + Sphere.Meshes.FirstOrDefault().MeshParts.FirstOrDefault().Effect = Effect; + } + + private void InitializeEffect() + { + Effect = Content.Load(ContentFolderEffects + "PBR"); + Effect.CurrentTechnique = Effect.Techniques["PBR"]; + } + + private void InitializeTextures() + { + UpdateMaterialPath(); + LoadTextures(); + } + + public void Update(GameTime gameTime) + { + ProcessMaterialChange(); + ProcessMovement(gameTime); + } + + public void Draw(Matrix view, Matrix projection) + { + var worldView = World * view; + Effect.Parameters["matWorld"].SetValue(World); + Effect.Parameters["matWorldViewProj"].SetValue(worldView * projection); + Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(World))); + + Sphere.Meshes.FirstOrDefault().Draw(); + } + + private void LoadTextures() + { + Texture2D albedo, ao, metalness, roughness, normals; + + normals = Content.Load(TexturePath + "normal"); + ao = Content.Load(TexturePath + "ao"); + metalness = Content.Load(TexturePath + "metalness"); + roughness = Content.Load(TexturePath + "roughness"); + albedo = Content.Load(TexturePath + "color"); + + Effect.Parameters["albedoTexture"]?.SetValue(albedo); + Effect.Parameters["normalTexture"]?.SetValue(normals); + Effect.Parameters["metallicTexture"]?.SetValue(metalness); + Effect.Parameters["roughnessTexture"]?.SetValue(roughness); + Effect.Parameters["aoTexture"]?.SetValue(ao); + } + + private void ProcessMaterialChange() + { + var keyboardState = Keyboard.GetState(); + + if (keyboardState.IsKeyDown(Keys.D1)) + { + CurrentMaterial = Material.RustedMetal; + } + else if (keyboardState.IsKeyDown(Keys.D2)) + { + CurrentMaterial = Material.Grass; + } + else if (keyboardState.IsKeyDown(Keys.D3)) + { + CurrentMaterial = Material.Gold; + } + else if (keyboardState.IsKeyDown(Keys.D4)) + { + CurrentMaterial = Material.Marble; + } + else if (keyboardState.IsKeyDown(Keys.D5)) + { + CurrentMaterial = Material.Metal; + } + + SwitchMaterial(); + } + + private void UpdateMaterialPath() + { + TexturePath = ContentFolderTextures + "materials/"; + switch (CurrentMaterial) + { + case Material.RustedMetal: + TexturePath += "harsh-metal"; + break; + + case Material.Marble: + TexturePath += "marble"; + break; + + case Material.Gold: + TexturePath += "gold"; + break; + + case Material.Metal: + TexturePath += "metal"; + break; + + case Material.Grass: + TexturePath += "ground"; + break; + } + + TexturePath += "/"; + } + + private void SwitchMaterial() + { + // We do not dispose textures, as they cannot be loaded again + UpdateMaterialPath(); + LoadTextures(); + } + + private void ProcessMovement(GameTime gameTime) + { + // Aca deberiamos poner toda la logica de actualizacion del juego. + float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + + float speed = 100; + + // Capturar Input teclado + var keyboardState = Keyboard.GetState(); + + + if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) + { + //Position += Vector3.Right * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation); + } + else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) + { + //Position += Vector3.Left * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation) * (- 1); + } + else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) + { + //Position += Vector3.Forward * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); + } + else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) + { + //Position += Vector3.Backward * speed * elapsedTime; + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); + } + + Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); + + var direction = Vector3.Transform(Vector3.UnitZ, Rotation); + + Velocity += Acceleration * elapsedTime; + Position += direction * Velocity * elapsedTime * 0.5f; + + MoveTo(Position); + + Acceleration = Vector3.Zero; + } + + public void MoveTo(Vector3 position) + { + World = Scale * Matrix.CreateTranslation(position); + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/MainCharacter/Material.cs b/TGC.MonoGame.TP/MainCharacter/Material.cs new file mode 100644 index 000000000..467cf3b6a --- /dev/null +++ b/TGC.MonoGame.TP/MainCharacter/Material.cs @@ -0,0 +1,11 @@ +namespace TGC.MonoGame.TP.MainCharacter +{ + public enum Material + { + RustedMetal, + Grass, + Gold, + Marble, + Metal + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index babd6479c..728ebdf6a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework.Input; using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.MainCharacter; namespace TGC.MonoGame.TP { @@ -44,20 +45,11 @@ public TGCGame() private SpriteBatch SpriteBatch { get; set; } // Camera to draw the scene - private FreeCamera Camera { get; set; } private FollowCamera FollowCamera { get; set; } // BOLITA //física - private Vector3 Position { get; set; } - private Vector3 Velocity { get; set; } - private Vector3 Acceleration { get; set; } = Vector3.Zero; - - private Quaternion Rotation { get; set; } = Quaternion.Identity; - private Vector3 RotationAxis {get; set; } = Vector3.UnitY; - private float RotationAngle = 0f; - //física - private SpherePrimitive Bola; + private Character MainCharacter; private List Track; // Comentada porque no está en uso @@ -210,9 +202,7 @@ protected override void LoadContent() Track.Add(Ramp); // BOLITA - // Propuesta de punto de inicio del escenario - Position = new Vector3(25, 25, -775); - Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 10, Color.Red, Matrix.CreateTranslation(Position)); + MainCharacter = new Character(Content, initialPosition: new Vector3(25, 25, -775)); // PLANOS INCLINADOS (ROLL) Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); @@ -315,50 +305,15 @@ protected override void LoadContent() /// protected override void Update(GameTime gameTime) { - // Aca deberiamos poner toda la logica de actualizacion del juego. - float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - - float speed = 100; - // Capturar Input teclado - var keyboardState = Keyboard.GetState(); - if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) - { - //Position += Vector3.Right * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation); - } - else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) - { - //Position += Vector3.Left * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation) * (- 1); - } - else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) - { - //Position += Vector3.Forward * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); - } - else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) - { - //Position += Vector3.Backward * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); - } - else if(Keyboard.GetState().IsKeyDown(Keys.Escape)) + if(Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Salgo del juego. Exit(); } - Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); - - var direction = Vector3.Transform(Vector3.UnitZ, Rotation); - - Velocity += Acceleration * elapsedTime; - Position += direction * Velocity * elapsedTime * 0.5f; - - Bola.World = Matrix.CreateTranslation(Position); - - Acceleration = Vector3.Zero; - - FollowCamera.Update(gameTime, Bola.World); + MainCharacter.Update(gameTime); + + FollowCamera.Update(gameTime, MainCharacter.World); base.Update(gameTime); } @@ -372,7 +327,7 @@ protected override void Draw(GameTime gameTime) // Aca deberiamos poner toda la logia de renderizado del juego. GraphicsDevice.Clear(Color.LightSkyBlue); - Bola.Draw(FollowCamera.View, FollowCamera.Projection); + MainCharacter.Draw(FollowCamera.View, FollowCamera.Projection); foreach (GeometricPrimitive primitive in Track) { primitive.Draw(FollowCamera.View, FollowCamera.Projection); From abab36ff0d461fc34929bd2c5b6d65eb77ad6585 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 21 May 2024 23:55:11 -0300 Subject: [PATCH 37/73] =?UTF-8?q?Cinem=C3=A1tica=20completa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 74 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 728ebdf6a..78ad2ee60 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -49,6 +49,14 @@ public TGCGame() // BOLITA //física + private Vector3 Position {get; set; } + private Vector3 Velocity { get; set; } + private Vector3 Acceleration { get; set; } = Vector3.Zero; + //vectores físicos + private Quaternion Rotation { get; set; } = Quaternion.Identity; + private Vector3 RotationAxis {get; set; } = Vector3.UnitY; + private float RotationAngle = 0f; + //física private Character MainCharacter; private List Track; @@ -305,14 +313,74 @@ protected override void LoadContent() /// protected override void Update(GameTime gameTime) { - if(Keyboard.GetState().IsKeyDown(Keys.Escape)) + // Aca deberiamos poner toda la logica de actualizacion del juego. + float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + + var directionX = new Vector3(); + var directionY = new Vector3(); + var directionZ = new Vector3(); + + bool salto = false; + float speed = 100; + // Capturar Input teclado + var keyboardState = Keyboard.GetState(); + if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) + { + Acceleration = Vector3.Transform(Vector3.UnitX * speed, Rotation); + } + else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) + { + Acceleration = Vector3.Transform(Vector3.UnitX * speed, Rotation) * (- 1); + } + else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) + { + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); + } + else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) + { + Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); + } + else if(Keyboard.GetState().IsKeyDown(Keys.Space) && Velocity.Y == 0f) + { + Velocity += Vector3.Up * speed; + salto = true; + } + else if(Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Salgo del juego. Exit(); } - MainCharacter.Update(gameTime); - + Vector3 gravity = Vector3.Zero; + + Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); + + directionX = Vector3.Transform(Vector3.UnitX, Rotation); + directionY = Vector3.Transform(Vector3.UnitY, Rotation); + directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); + + if(Position.Y <= 25f) + { + gravity = new Vector3(0f, 0f, 0f); + if (!salto) + { + Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); + } + } + else + { + gravity = new Vector3(0f, -100f, 0f); + } + + Velocity += (Acceleration + gravity) * elapsedTime; + Position += (directionX + directionY + directionZ) * Velocity * elapsedTime * 0.5f; + + //SolveVerticalMovement(Velocity); + + MainCharacter.World = Matrix.CreateTranslation(Position); + + Acceleration = Vector3.Zero; + FollowCamera.Update(gameTime, MainCharacter.World); base.Update(gameTime); From 4364ff51119234878ea5c7e42582563bf999879e Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Wed, 22 May 2024 00:27:29 -0300 Subject: [PATCH 38/73] Fix del movimiento del personaje y ciclos de update con texturas --- .../MainCharacter/MainCharacter.cs | 73 +++++++++++++------ TGC.MonoGame.TP/TGCGame.cs | 73 +------------------ 2 files changed, 52 insertions(+), 94 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 1fe41482c..c0d00b584 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -104,28 +104,35 @@ private void ProcessMaterialChange() { var keyboardState = Keyboard.GetState(); + var NewMaterial = CurrentMaterial; + if (keyboardState.IsKeyDown(Keys.D1)) { - CurrentMaterial = Material.RustedMetal; + NewMaterial = Material.RustedMetal; } else if (keyboardState.IsKeyDown(Keys.D2)) { - CurrentMaterial = Material.Grass; + NewMaterial = Material.Grass; } else if (keyboardState.IsKeyDown(Keys.D3)) { - CurrentMaterial = Material.Gold; + NewMaterial = Material.Gold; } else if (keyboardState.IsKeyDown(Keys.D4)) { - CurrentMaterial = Material.Marble; + NewMaterial = Material.Marble; } else if (keyboardState.IsKeyDown(Keys.D5)) { - CurrentMaterial = Material.Metal; + NewMaterial = Material.Metal; } - SwitchMaterial(); + if (NewMaterial != CurrentMaterial) + { + CurrentMaterial = NewMaterial; + SwitchMaterial(); + } + } private void UpdateMaterialPath() @@ -169,39 +176,59 @@ private void ProcessMovement(GameTime gameTime) // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - float speed = 100; + var directionX = new Vector3(); + var directionY = new Vector3(); + var directionZ = new Vector3(); + bool salto = false; + float speed = 100; // Capturar Input teclado var keyboardState = Keyboard.GetState(); - - if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { - //Position += Vector3.Right * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation); + Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation); } - else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) + if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { - //Position += Vector3.Left * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitY * speed, Rotation) * (- 1); + Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation) * (- 1); } - else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) + if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { - //Position += Vector3.Forward * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); + Acceleration += Vector3.Transform(Vector3.UnitZ * speed, Rotation); } - else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) + if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { - //Position += Vector3.Backward * speed * elapsedTime; - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); + Acceleration += Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); } + if(Keyboard.GetState().IsKeyDown(Keys.Space) && Velocity.Y == 0f) + { + Velocity += Vector3.Up * speed; + salto = true; + } + + Vector3 gravity = Vector3.Zero; Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); - var direction = Vector3.Transform(Vector3.UnitZ, Rotation); + directionX = Vector3.Transform(Vector3.UnitX, Rotation); + directionY = Vector3.Transform(Vector3.UnitY, Rotation); + directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); + + if(Position.Y <= 25f) + { + gravity = new Vector3(0f, 0f, 0f); + if (!salto) + { + Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); + } + } + else + { + gravity = new Vector3(0f, -100f, 0f); + } - Velocity += Acceleration * elapsedTime; - Position += direction * Velocity * elapsedTime * 0.5f; + Velocity += (Acceleration + gravity) * elapsedTime; + Position += (directionX + directionY + directionZ) * Velocity * elapsedTime * 0.5f; MoveTo(Position); diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 78ad2ee60..4afd86982 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -48,15 +48,6 @@ public TGCGame() private FollowCamera FollowCamera { get; set; } // BOLITA - //física - private Vector3 Position {get; set; } - private Vector3 Velocity { get; set; } - private Vector3 Acceleration { get; set; } = Vector3.Zero; - //vectores físicos - private Quaternion Rotation { get; set; } = Quaternion.Identity; - private Vector3 RotationAxis {get; set; } = Vector3.UnitY; - private float RotationAngle = 0f; - //física private Character MainCharacter; private List Track; @@ -313,73 +304,13 @@ protected override void LoadContent() /// protected override void Update(GameTime gameTime) { - // Aca deberiamos poner toda la logica de actualizacion del juego. - float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - - var directionX = new Vector3(); - var directionY = new Vector3(); - var directionZ = new Vector3(); - - bool salto = false; - float speed = 100; - // Capturar Input teclado - var keyboardState = Keyboard.GetState(); - if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) - { - Acceleration = Vector3.Transform(Vector3.UnitX * speed, Rotation); - } - else if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) - { - Acceleration = Vector3.Transform(Vector3.UnitX * speed, Rotation) * (- 1); - } - else if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) - { - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation); - } - else if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) - { - Acceleration = Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); - } - else if(Keyboard.GetState().IsKeyDown(Keys.Space) && Velocity.Y == 0f) - { - Velocity += Vector3.Up * speed; - salto = true; - } - else if(Keyboard.GetState().IsKeyDown(Keys.Escape)) + if(Keyboard.GetState().IsKeyDown(Keys.Escape)) { //Salgo del juego. Exit(); } - Vector3 gravity = Vector3.Zero; - - Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); - - directionX = Vector3.Transform(Vector3.UnitX, Rotation); - directionY = Vector3.Transform(Vector3.UnitY, Rotation); - directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); - - if(Position.Y <= 25f) - { - gravity = new Vector3(0f, 0f, 0f); - if (!salto) - { - Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); - } - } - else - { - gravity = new Vector3(0f, -100f, 0f); - } - - Velocity += (Acceleration + gravity) * elapsedTime; - Position += (directionX + directionY + directionZ) * Velocity * elapsedTime * 0.5f; - - //SolveVerticalMovement(Velocity); - - MainCharacter.World = Matrix.CreateTranslation(Position); - - Acceleration = Vector3.Zero; + MainCharacter.Update(gameTime); FollowCamera.Update(gameTime, MainCharacter.World); From 1bad6ea1d73e9492171994a9909f94416d5baecf Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Tue, 21 May 2024 13:54:20 -0300 Subject: [PATCH 39/73] =?UTF-8?q?Primer=20intento=20de=20limpieza=20de=20c?= =?UTF-8?q?=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Camera/FreeCamera.cs | 2 +- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 23 +- .../CustomPrimitives/RampPrimitive.cs | 21 +- .../Geometries/GeometricPrimitive.cs | 2 +- TGC.MonoGame.TP/Stages/Stage.cs | 278 ++++++++++++++++++ TGC.MonoGame.TP/TGCGame.cs | 3 - 6 files changed, 315 insertions(+), 14 deletions(-) create mode 100644 TGC.MonoGame.TP/Stages/Stage.cs diff --git a/TGC.MonoGame.TP/Camera/FreeCamera.cs b/TGC.MonoGame.TP/Camera/FreeCamera.cs index cd449d1f1..246f53933 100644 --- a/TGC.MonoGame.TP/Camera/FreeCamera.cs +++ b/TGC.MonoGame.TP/Camera/FreeCamera.cs @@ -4,7 +4,7 @@ namespace TGC.MonoGame.TP.Camera { - internal class FreeCamera : Camera + class FreeCamera : Camera { private readonly bool lockMouse; diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 2fd14b757..6598415e8 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -17,19 +17,30 @@ #endregion Using Statements -namespace TGC.MonoGame.TP.Geometries { +namespace TGC.MonoGame.TP.Geometries +{ /// /// Geometric primitive class for drawing cubes. /// - public class CubePrimitive : GeometricPrimitive { - + public class CubePrimitive : GeometricPrimitive + { + /// /// Constructs a new cube primitive, with the specified size. /// - public CubePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + public CubePrimitive( + GraphicsDevice graphicsDevice, + ContentManager content, + Color color, + float size = 25f, + Vector3? coordinates = null, + Vector3? scale = null, + Matrix? rotation = null + ) + { Color = color; - + // A cube has six faces, each one pointing in a different direction. Vector3[] normals = { @@ -73,6 +84,8 @@ public CubePrimitive(GraphicsDevice graphicsDevice, ContentManager content, floa i++; } + World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 62a6e9732..1c60bb497 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -17,11 +17,22 @@ #endregion Using Statements -namespace TGC.MonoGame.TP.Geometries { +namespace TGC.MonoGame.TP.Geometries +{ - public class RampPrimitive : CustomPrimitive { - - public RampPrimitive(GraphicsDevice graphicsDevice, ContentManager content, float size, Color color) { + public class RampPrimitive : CustomPrimitive + { + + public RampPrimitive( + GraphicsDevice graphicsDevice, + ContentManager content, + Color color, + float size, + Vector3? coordinates = null, + Vector3? scale = null, + Matrix? rotation = null + ) + { Color = color; @@ -51,6 +62,8 @@ public RampPrimitive(GraphicsDevice graphicsDevice, ContentManager content, floa AddTriangle(vertexList[0], vertexList[2], vertexList[4], size, color); AddTriangle(vertexList[5], vertexList[3], vertexList[1], size, color); + World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs index 6e56ee71b..1a673a811 100644 --- a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -82,7 +82,6 @@ protected void AddIndex(int index) /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index /// data into GPU format buffers, ready for efficient rendering. /// - // protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager content, Effect? primitiveEffect = null) { // Create a vertex declaration, describing the format of our vertex data. @@ -99,6 +98,7 @@ protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager Effect = primitiveEffect ?? content.Load(ContentFolderEffects + "BasicShader"); } + /// /// Finalizer. diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs new file mode 100644 index 000000000..973a6fcd0 --- /dev/null +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -0,0 +1,278 @@ + +using System.Collections.Generic; +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Camera; +using TGC.MonoGame.TP.Geometries; + +abstract class Stage +{ + + GraphicsDevice GraphicsDevice; + ContentManager Content; + Vector3 CharacterPosition; + + protected List Track; + + + public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) + { + GraphicsDevice = graphicsDevice; + Content = content; + CharacterPosition = characterPosition; + + Track = new List(); + + } + + public void AddPrimitive(GeometricPrimitive primitive) + { + Track.Add(primitive); + } + + public void AddPrimitives(List primitives) + { + foreach (GeometricPrimitive primitive in primitives) + { + AddPrimitive(primitive); + } + } + + public void Draw(Matrix view, Matrix projection) + { + foreach (GeometricPrimitive primitive in Track) + { + primitive.Draw(view, projection); + } + } + + abstract protected List TrackParameters(); + +} + +abstract class GeometricCandidate +{ + + protected Color Color; + protected Vector3 Coordinates; + protected Vector3 Scale; + protected Matrix Rotation; + protected float Size; + + public GeometricCandidate(Color color, float size, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null) + { + Color = color; + Size = size; + Coordinates = coordinates ?? Vector3.Zero; + Scale = scale ?? Vector3.One; + Rotation = rotation ?? Matrix.Identity; + } + + abstract public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content); +} + +class CubeCandidate : GeometricCandidate +{ + + public CubeCandidate(Color color, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null, float size = 25f) : + base(color, size, coordinates, scale, rotation) + { } + override public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content) + { + return new CubePrimitive(graphicsDevice, content, Color, Size, Coordinates, Scale, Rotation); + } +} + +class RampCandidate : GeometricCandidate +{ + + public RampCandidate(Color color, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null, float size = 25f) : + base(color, size, coordinates, scale, rotation) + { } + override public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content) + { + return new RampPrimitive(graphicsDevice, content, Color, Size, Coordinates, Scale, Rotation); + } +} + +class Stage_01 : Stage +{ + + public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : + base(graphicsDevice, content, new Vector3(25, 25, -800)) {} + + protected override List TrackParameters() + { + List primitiveParameters = new List(); + + // PRIMERA PLATAFORMA + primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 0), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 25), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 50), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 75), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 100), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 125), scale: new Vector3(3f, 1f, 1f))); + + // SEGUNDA PLATAFORMA + primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 175), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 200), scale: new Vector3(3f, 1f, 1f))); + primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 225), scale: new Vector3(3f, 1f, 1f))); + + // ESCALERA + primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(75, 25, 200), scale: new Vector3(1f, 1f, 3f))); + primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(100, 50, 200), scale: new Vector3(1f, 1f, 3f))); + primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(125, 75, 200), scale: new Vector3(1f, 1f, 3f))); + + // TERCERA PLATAFORMA + + + return primitiveParameters; + + } + + +} + +// TERCERA PLATAFORMA +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); +Track.Add(Cube); + +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); +Track.Add(Cube); + +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); +Track.Add(Cube); + +//CUARTA PLATAFORMA +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); +Track.Add(Cube); + + +// QUINTA PLATAFORMA +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); +Track.Add(Cube); + +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); +Track.Add(Cube); + +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); +Track.Add(Cube); + +// RAMPA +Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Ramp.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); +Track.Add(Ramp); + +// CANALETA +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Cube.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); +Track.Add(Cube); +Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; +Track.Add(Ramp); +Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; +Track.Add(Ramp); + +// BOLITA +// Propuesta de punto de inicio del escenario +Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(new Vector3(25, 25, -800))); + +// PLANOS INCLINADOS (ROLL) +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); +Track.Add(Cube); + +// RAMPA GRANDE +Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.LightPink); +Ramp.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); +Track.Add(Ramp); + +// CUADRADOS GRANDES +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Red); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Orange); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Yellow); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Green); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Blue); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Indigo); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); +Track.Add(Cube); +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Purple); +Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); +Track.Add(Cube); + +// PLATAFORMA FINAL +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); +Cube.World = Matrix.CreateScale(7f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(425, -125, -75)); +Track.Add(Cube); + +// aca iria la banderita del final +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.White); +Cube.World = Matrix.CreateTranslation(new Vector3(425, -100, -75)); +Track.Add(Cube); + +// aca irian cartelitos +//jump +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); +Cube.World = Matrix.CreateTranslation(new Vector3(-25, 50, 150)); +Track.Add(Cube); + +//up (flechita?) +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); +Cube.World = Matrix.CreateTranslation(new Vector3(50, 75, 250)); +Track.Add(Cube); + +//jump +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); +Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, 150)); +Track.Add(Cube); + +//jump +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); +Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, -25)); +Track.Add(Cube); + +//down (flechita?) +Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); +Cube.World = Matrix.CreateTranslation(new Vector3(200, 175, -475)); +Track.Add(Cube); \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 4afd86982..056ac939a 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -50,9 +50,6 @@ public TGCGame() // BOLITA private Character MainCharacter; private List Track; - - // Comentada porque no está en uso - //private float SquareSize = 50f; /// From 9965cf0c6a7aeb1cf89b283a075c9053db955a05 Mon Sep 17 00:00:00 2001 From: FrancoEsposta Date: Sat, 25 May 2024 12:24:02 -0300 Subject: [PATCH 40/73] Muevo la creacion de stages a una clase particular para limpiar la clase principal y facilitar la creacion de stages en el futuro --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 2 +- .../CustomPrimitives/RampPrimitive.cs | 2 +- TGC.MonoGame.TP/Stages/Stage.cs | 267 ++---------------- TGC.MonoGame.TP/Stages/Stage_01.cs | 125 ++++++++ TGC.MonoGame.TP/TGCGame.cs | 204 +------------ 5 files changed, 157 insertions(+), 443 deletions(-) create mode 100644 TGC.MonoGame.TP/Stages/Stage_01.cs diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 6598415e8..96e52ef65 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -26,7 +26,7 @@ public class CubePrimitive : GeometricPrimitive { /// - /// Constructs a new cube primitive, with the specified size. + /// Constructs a new cube primitive. /// public CubePrimitive( GraphicsDevice graphicsDevice, diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 1c60bb497..4044ef980 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -27,7 +27,7 @@ public RampPrimitive( GraphicsDevice graphicsDevice, ContentManager content, Color color, - float size, + float size = 25f, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index 973a6fcd0..cd6eba9d0 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -6,38 +6,34 @@ using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.MainCharacter; abstract class Stage { - GraphicsDevice GraphicsDevice; - ContentManager Content; - Vector3 CharacterPosition; + protected GraphicsDevice GraphicsDevice; + protected ContentManager Content; protected List Track; + protected List Signs; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + protected List Pickups; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + + public Vector3 CharacterInitialPosition; + + //TODO: por acá podría estar el tema de los puntos de respawn + public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { GraphicsDevice = graphicsDevice; Content = content; - CharacterPosition = characterPosition; - - Track = new List(); - - } - public void AddPrimitive(GeometricPrimitive primitive) - { - Track.Add(primitive); - } + CharacterInitialPosition = characterPosition; - public void AddPrimitives(List primitives) - { - foreach (GeometricPrimitive primitive in primitives) - { - AddPrimitive(primitive); - } + LoadTrack(); + LoadSigns(); + LoadPickups(); } public void Draw(Matrix view, Matrix projection) @@ -46,233 +42,22 @@ public void Draw(Matrix view, Matrix projection) { primitive.Draw(view, projection); } - } - - abstract protected List TrackParameters(); - -} - -abstract class GeometricCandidate -{ - - protected Color Color; - protected Vector3 Coordinates; - protected Vector3 Scale; - protected Matrix Rotation; - protected float Size; - - public GeometricCandidate(Color color, float size, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null) - { - Color = color; - Size = size; - Coordinates = coordinates ?? Vector3.Zero; - Scale = scale ?? Vector3.One; - Rotation = rotation ?? Matrix.Identity; - } - - abstract public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content); -} - -class CubeCandidate : GeometricCandidate -{ - - public CubeCandidate(Color color, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null, float size = 25f) : - base(color, size, coordinates, scale, rotation) - { } - override public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content) - { - return new CubePrimitive(graphicsDevice, content, Color, Size, Coordinates, Scale, Rotation); - } -} - -class RampCandidate : GeometricCandidate -{ - - public RampCandidate(Color color, Vector3? coordinates = null, Vector3? scale = null, Matrix? rotation = null, float size = 25f) : - base(color, size, coordinates, scale, rotation) - { } - override public GeometricPrimitive Build(GraphicsDevice graphicsDevice, ContentManager content) - { - return new RampPrimitive(graphicsDevice, content, Color, Size, Coordinates, Scale, Rotation); - } -} - -class Stage_01 : Stage -{ - - public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : - base(graphicsDevice, content, new Vector3(25, 25, -800)) {} - - protected override List TrackParameters() - { - List primitiveParameters = new List(); - - // PRIMERA PLATAFORMA - primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 0), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 25), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 50), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 75), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 100), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 125), scale: new Vector3(3f, 1f, 1f))); - - // SEGUNDA PLATAFORMA - primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(25, 0, 175), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(25, 0, 200), scale: new Vector3(3f, 1f, 1f))); - primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(25, 0, 225), scale: new Vector3(3f, 1f, 1f))); - - // ESCALERA - primitiveParameters.Add(new CubeCandidate(Color.BlueViolet, coordinates: new Vector3(75, 25, 200), scale: new Vector3(1f, 1f, 3f))); - primitiveParameters.Add(new CubeCandidate(Color.Aquamarine, coordinates: new Vector3(100, 50, 200), scale: new Vector3(1f, 1f, 3f))); - primitiveParameters.Add(new CubeCandidate(Color.LightPink, coordinates: new Vector3(125, 75, 200), scale: new Vector3(1f, 1f, 3f))); - - // TERCERA PLATAFORMA + foreach (GeometricPrimitive sign in Signs) + { + sign.Draw(view, projection); + } - return primitiveParameters; - + foreach (GeometricPrimitive pickup in Pickups) + { + pickup.Draw(view, projection); + } } + abstract protected void LoadTrack(); -} - -// TERCERA PLATAFORMA -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); -Track.Add(Cube); - -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); -Track.Add(Cube); - -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); -Track.Add(Cube); - -//CUARTA PLATAFORMA -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); -Track.Add(Cube); - - -// QUINTA PLATAFORMA -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); -Track.Add(Cube); - -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); -Track.Add(Cube); - -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); -Track.Add(Cube); - -// RAMPA -Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Ramp.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); -Track.Add(Ramp); - -// CANALETA -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Cube.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); -Track.Add(Cube); -Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; -Track.Add(Ramp); -Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; -Track.Add(Ramp); - -// BOLITA -// Propuesta de punto de inicio del escenario -Bola = new SpherePrimitive(GraphicsDevice, Content, 25, 50, Color.Red, Matrix.CreateTranslation(new Vector3(25, 25, -800))); - -// PLANOS INCLINADOS (ROLL) -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); -Track.Add(Cube); - -// RAMPA GRANDE -Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.LightPink); -Ramp.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); -Track.Add(Ramp); - -// CUADRADOS GRANDES -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Red); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Orange); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Yellow); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Green); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Blue); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Indigo); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); -Track.Add(Cube); -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Purple); -Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); -Track.Add(Cube); - -// PLATAFORMA FINAL -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); -Cube.World = Matrix.CreateScale(7f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(425, -125, -75)); -Track.Add(Cube); - -// aca iria la banderita del final -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.White); -Cube.World = Matrix.CreateTranslation(new Vector3(425, -100, -75)); -Track.Add(Cube); - -// aca irian cartelitos -//jump -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); -Cube.World = Matrix.CreateTranslation(new Vector3(-25, 50, 150)); -Track.Add(Cube); - -//up (flechita?) -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); -Cube.World = Matrix.CreateTranslation(new Vector3(50, 75, 250)); -Track.Add(Cube); - -//jump -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); -Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, 150)); -Track.Add(Cube); + abstract protected void LoadPickups(); -//jump -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); -Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, -25)); -Track.Add(Cube); + abstract protected void LoadSigns(); -//down (flechita?) -Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); -Cube.World = Matrix.CreateTranslation(new Vector3(200, 175, -475)); -Track.Add(Cube); \ No newline at end of file +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs new file mode 100644 index 000000000..f0941597d --- /dev/null +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.MainCharacter; + +class Stage_01 : Stage +{ + + public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : + base(graphicsDevice, content, characterPosition: new Vector3(25, 25, -800)) {} + + protected override void LoadTrack() + { + Track = new List + { + // PRIMERA PLATAFORMA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, 0), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, 25), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, 50), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, 75), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, 100), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, 125), scale: new Vector3(3f, 1f, 1f)), + + // SEGUNDA PLATAFORMA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, 175), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, 200), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, 225), scale: new Vector3(3f, 1f, 1f)), + + // ESCALERA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(75, 25, 200), scale: new Vector3(1f, 1f, 3f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(100, 50, 200), scale: new Vector3(1f, 1f, 3f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(125, 75, 200), scale: new Vector3(1f, 1f, 3f)), + + // TERCERA PLATAFORMA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(175, 100, 225), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 100, 200), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(175, 100, 175), scale: new Vector3(3f, 1f, 1f)), + + //CUARTA PLATAFORMA + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 100, 62), scale: new Vector3(1f, 1f, 6f)), + + // QUINTA PLATAFORMA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(175, 100, -50), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 100, -75), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(175, 100, -100), scale: new Vector3(3f, 1f, 1f)), + + // RAMPA + new RampPrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 125, -125), scale: new Vector3(3f, 1f, 1f)), + + // CANALETA + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(175, 125, -250), scale: new Vector3(3f, 1f, 9f)), + new RampPrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(150, 150, -250), scale: new Vector3(9f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(200, 150, -250), scale: new Vector3(9f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0)), + + // PLANOS INCLINADOS (ROLL) + + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, -75), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6))), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, -175), scale: new Vector3(3f, 1f, 4f)), + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, -275), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, -375), scale: new Vector3(3f, 1f, 4f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, -475), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6))), + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, -575), scale: new Vector3(3f, 1f, 4f)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, -675), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, -775), scale: new Vector3(3f, 1f, 4f)), + + // RAMPA GRANDE + new RampPrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(175, 125, -450), scale: new Vector3(7f, 7f, 7f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0)), + + // CUADRADOS GRANDES + new CubePrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(275, 25, -425), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Orange, coordinates: new Vector3(300, 0, -400), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Yellow, coordinates: new Vector3(325, -25, -375), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(350, -50, -350), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(375, -75, -325), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Indigo, coordinates: new Vector3(400, -100, -300), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Purple, coordinates: new Vector3(425, -125, -275), scale: new Vector3(9f, 1f, 9f)), + + // PLATAFORMA FINAL + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(425, -125, -75), scale: new Vector3(7f, 1f, 6f)) + }; + + } + + protected override void LoadSigns() + { + Signs = new List + { + // aca iria la banderita del final + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(425, -100, -75)), + + // aca irian cartelitos + //jump + new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(-25, 50, 150)), + + //up (flechita?) + new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(50, 75, 250)), + + //jump + new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(200, 150, 150)), + + //jump + new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(200, 150, -25)), + + //down (flechita?) + new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(200, 175, -475)) + }; + } + + protected override void LoadPickups() + { + Pickups = new List(); + } + + +} + + + + + + + diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 056ac939a..e7811f134 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -49,7 +49,7 @@ public TGCGame() // BOLITA private Character MainCharacter; - private List Track; + private Stage Stage; /// @@ -93,203 +93,9 @@ protected override void LoadContent() // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. SpriteBatch = new SpriteBatch(GraphicsDevice); - RampPrimitive Ramp; - CubePrimitive Cube; - Track = new List(); - - // PRIMERA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 0)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 25)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 50)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 75)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 100)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 125)); - Track.Add(Cube); - - // SEGUNDA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 175)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(25, 0, 225)); - Track.Add(Cube); - - // ESCALERA - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(75, 25, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(100, 50, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(1f, 1f, 3f) * Matrix.CreateTranslation(new Vector3(125, 75, 200)); - Track.Add(Cube); - - // TERCERA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 225)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 200)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, 175)); - Track.Add(Cube); - - //CUARTA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(1f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(175, 100, 62)); - Track.Add(Cube); - - - // QUINTA PLATAFORMA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -50)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -75)); - Track.Add(Cube); - - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 100, -100)); - Track.Add(Cube); - - // RAMPA - Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Ramp.World = Matrix.CreateScale(3f, 1f, 1f) * Matrix.CreateTranslation(new Vector3(175, 125, -125)); - Track.Add(Ramp); - - // CANALETA - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(175, 125, -250)); - Track.Add(Cube); - Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(150, 150, -250)); // * ; - Track.Add(Ramp); - Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Ramp.World = Matrix.CreateScale(9f, 1f, 1f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0) * Matrix.CreateTranslation(new Vector3(200, 150, -250)); // * ; - Track.Add(Ramp); - - // BOLITA - MainCharacter = new Character(Content, initialPosition: new Vector3(25, 25, -775)); - - // PLANOS INCLINADOS (ROLL) - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -75)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -175)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -275)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -375)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6)) * Matrix.CreateTranslation(new Vector3(25, 0, -475)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.BlueViolet); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -575)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6) * Matrix.CreateTranslation(new Vector3(25, 0, -675)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(3f, 1f, 4f) * Matrix.CreateTranslation(new Vector3(25, 0, -775)); - Track.Add(Cube); - - // RAMPA GRANDE - Ramp = new RampPrimitive(GraphicsDevice, Content, 25f, Color.LightPink); - Ramp.World = Matrix.CreateScale(7f, 7f, 7f) * Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0) * Matrix.CreateTranslation(new Vector3(175, 125, -450)); - Track.Add(Ramp); - - // CUADRADOS GRANDES - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Red); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(275, 25, -425)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Orange); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(300, 0, -400)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Yellow); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(325, -25, -375)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Green); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(350, -50, -350)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Blue); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(375, -75, -325)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Indigo); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(400, -100, -300)); - Track.Add(Cube); - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Purple); - Cube.World = Matrix.CreateScale(9f, 1f, 9f) * Matrix.CreateTranslation(new Vector3(425, -125, -275)); - Track.Add(Cube); - - // PLATAFORMA FINAL - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Aquamarine); - Cube.World = Matrix.CreateScale(7f, 1f, 6f) * Matrix.CreateTranslation(new Vector3(425 , -125, -75)); - Track.Add(Cube); - - // aca iria la banderita del final - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.White); - Cube.World = Matrix.CreateTranslation(new Vector3(425, -100, -75)); - Track.Add(Cube); - - // aca irian cartelitos - //jump - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); - Cube.World = Matrix.CreateTranslation(new Vector3(-25, 50, 150)); - Track.Add(Cube); - - //up (flechita?) - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); - Cube.World = Matrix.CreateTranslation(new Vector3(50, 75, 250)); - Track.Add(Cube); - - //jump - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); - Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, 150)); - Track.Add(Cube); - - //jump - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); - Cube.World = Matrix.CreateTranslation(new Vector3(200, 150, -25)); - Track.Add(Cube); - - //down (flechita?) - Cube = new CubePrimitive(GraphicsDevice, Content, 25f, Color.Black); - Cube.World = Matrix.CreateTranslation(new Vector3(200, 175, -475)); - Track.Add(Cube); + Stage = new Stage_01(GraphicsDevice, Content); + MainCharacter = new Character(Content, Stage.CharacterInitialPosition); base.LoadContent(); } @@ -325,9 +131,7 @@ protected override void Draw(GameTime gameTime) MainCharacter.Draw(FollowCamera.View, FollowCamera.Projection); - foreach (GeometricPrimitive primitive in Track) { - primitive.Draw(FollowCamera.View, FollowCamera.Projection); - } + Stage.Draw(FollowCamera.View, FollowCamera.Projection); } /// From 955a64f1026ba4e9d3a0e5bc25efaa32589152ac Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 28 May 2024 04:33:03 -0300 Subject: [PATCH 41/73] =?UTF-8?q?Agrego=20m=C3=A9todos=20a=20implementar?= =?UTF-8?q?=20en=20Stage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Stages/Stage.cs | 23 ++++++++++++++++++----- TGC.MonoGame.TP/Stages/Stage_01.cs | 18 ++++++++++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index cd6eba9d0..06474214e 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -14,16 +14,14 @@ abstract class Stage protected GraphicsDevice GraphicsDevice; protected ContentManager Content; - protected List Track; + protected List Track; // circuito y obstáculos fijos + protected List Obstacles; // obstáculos móviles protected List Signs; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive protected List Pickups; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + protected List Checkpoints; // puntos de respawn public Vector3 CharacterInitialPosition; - //TODO: por acá podría estar el tema de los puntos de respawn - - - public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { GraphicsDevice = graphicsDevice; @@ -32,10 +30,15 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char CharacterInitialPosition = characterPosition; LoadTrack(); + LoadObstacles(); LoadSigns(); LoadPickups(); + LoadCheckpoints(); } + public abstract void Update(GameTime gameTime); + + public void Draw(Matrix view, Matrix projection) { foreach (GeometricPrimitive primitive in Track) @@ -43,6 +46,11 @@ public void Draw(Matrix view, Matrix projection) primitive.Draw(view, projection); } + foreach (GeometricPrimitive primitive in Obstacles) + { + primitive.Draw(view, projection); + } + foreach (GeometricPrimitive sign in Signs) { sign.Draw(view, projection); @@ -56,8 +64,13 @@ public void Draw(Matrix view, Matrix projection) abstract protected void LoadTrack(); + abstract protected void LoadObstacles(); + abstract protected void LoadPickups(); abstract protected void LoadSigns(); + abstract protected void LoadCheckpoints(); + + } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index f0941597d..e64a6d53f 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -56,7 +56,6 @@ protected override void LoadTrack() new RampPrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(200, 150, -250), scale: new Vector3(9f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0)), // PLANOS INCLINADOS (ROLL) - new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, -75), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6))), new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, -175), scale: new Vector3(3f, 1f, 4f)), new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(25, 0, -275), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / 6)), @@ -74,7 +73,7 @@ protected override void LoadTrack() new CubePrimitive(GraphicsDevice, Content, Color.Orange, coordinates: new Vector3(300, 0, -400), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Yellow, coordinates: new Vector3(325, -25, -375), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(350, -50, -350), scale: new Vector3(9f, 1f, 9f)), - new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(375, -75, -325), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(375, -75, -325), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Indigo, coordinates: new Vector3(400, -100, -300), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Purple, coordinates: new Vector3(425, -125, -275), scale: new Vector3(9f, 1f, 9f)), @@ -84,6 +83,11 @@ protected override void LoadTrack() } + protected override void LoadObstacles() + { + Obstacles = new List(); + } + protected override void LoadSigns() { Signs = new List @@ -114,6 +118,16 @@ protected override void LoadPickups() Pickups = new List(); } + protected override void LoadCheckpoints() + { + Checkpoints = new List(); + } + + public override void Update(GameTime gameTime) + { + // TODO: actualizar el estado de todas las piezas móviles del nivel + + } } From 37e47f62c4d761f1043d1f5a525acf3b873ed2c3 Mon Sep 17 00:00:00 2001 From: LColamonici Date: Wed, 29 May 2024 16:13:51 -0300 Subject: [PATCH 42/73] agrego rotacion a la esfera al moverse --- .../Collisions/BoundingCylinder.cs | 544 ++++++++++++++++++ .../Collisions/BoundingVolumesExtensions.cs | 221 +++++++ .../Collisions/OrientedBoundingBox.cs | 429 ++++++++++++++ .../Collisions/TGCCollisionUtils.cs | 74 +++ .../MainCharacter/MainCharacter.cs | 21 +- TGC.MonoGame.TP/TGC.MonoGame.TP.sln | 25 + 6 files changed, 1313 insertions(+), 1 deletion(-) create mode 100644 TGC.MonoGame.TP/Collisions/BoundingCylinder.cs create mode 100644 TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs create mode 100644 TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs create mode 100644 TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs create mode 100644 TGC.MonoGame.TP/TGC.MonoGame.TP.sln diff --git a/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs b/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs new file mode 100644 index 000000000..594445be5 --- /dev/null +++ b/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs @@ -0,0 +1,544 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Text; + +namespace TGC.MonoGame.Samples.Collisions +{ + + /// + /// Represents a Bounding Cylinder to test for intersections + /// + class BoundingCylinder + { + // The center of the Cylinder in World Space + private Vector3 _center; + + // The radius of the Cylinder + private float _radius; + + // The distance from the Cylinder center to either its top or bottom + private float _halfHeight; + + // A matrix describing the Cylinder rotation + private Matrix _rotation; + + + // Matrices + // These are used to test for intersections, and serve to transform points to the Cylinder space or vice versa + + + // The opposite of the translation matrix, to calculate the InverseTransform + private Matrix _oppositeTranslation; + + // The inverse of the rotation matrix, to calculate the InverseTransform + private Matrix _inverseRotation; + + // An internal matrix to transform points from Cylinder space back to local space + private Matrix _inverseTransform; + + // An internal scale matrix to calculate the final Transform matrix + private Matrix _scale; + + // An internal translation matrix to calculate the final Transform matrix + private Matrix _translation; + + + /// + /// The center of the Cylinder in World Space + /// + public Vector3 Center + { + get => _center; + set + { + _center = value; + UpdateTranslation(); + UpdateInverseRotation(); + UpdateTransform(); + } + } + + /// + /// The radius of the Cylinder + /// + public float Radius + { + get => _radius; + set + { + _radius = value; + UpdateScale(); + UpdateTransform(); + } + } + + /// + /// The distance from the Cylinder center to either its top or bottom + /// + public float HalfHeight + { + get => _halfHeight; + set + { + _halfHeight = value; + UpdateScale(); + UpdateTransform(); + } + } + + /// + /// A matrix describing the Cylinder rotation + /// + public Matrix Rotation + { + get => _rotation; + set + { + _rotation = value; + IsXZAligned = _rotation.Equals(Matrix.Identity); + UpdateInverseRotation(); + UpdateTransform(); + } + } + + + // An internal matrix to transform points from local space to Cylinder space + public Matrix Transform { get; private set; } + + /// + /// True if this Cylinder has no rotation, and its circular shape is aligned to the XZ plane + /// + public bool IsXZAligned { get; private set; } + + + + /// + /// Creates a Bounding Cylinder with a center, radius and half-length. Note that it is XZ aligned. + /// + /// The center of the cylinder. + /// The horizontal radius of the cylinder. + /// Half the height of the cylinder. + public BoundingCylinder(Vector3 center, float radius, float halfLength) + { + _center = center; + _radius = radius; + _halfHeight = halfLength; + _rotation = Matrix.Identity; + IsXZAligned = true; + + UpdateTranslation(); + UpdateScale(); + UpdateInverseRotation(); + UpdateTransform(); + } + + /// + /// Moves the Cylinder center by a delta offset, and updates the internal values of the Cylinder. + /// + /// The amount of translation on each axis + public void Move(Vector3 delta) + { + _center += delta; + + UpdateTranslation(); + UpdateInverseRotation(); + UpdateTransform(); + } + + /// + /// Rotates the Cylinder using a rotation matrix. Considers the previous rotation and applies the new one. + /// Then it updates the internal values of the Cylinder. + /// + /// The rotation matrix to apply to the Cylinder + public void Rotate(Matrix rotation) + { + _rotation *= rotation; + IsXZAligned = _rotation.Equals(Matrix.Identity); + UpdateInverseRotation(); + UpdateTransform(); + } + + /// + /// Rotates the Cylinder using a quaternion. Considers the previous rotation and applies the new one. + /// Then it updates the internal values of the Cylinder. + /// + /// The rotation quaternion to apply to the Cylinder + public void Rotate(Quaternion rotation) + { + Rotate(Matrix.CreateFromQuaternion(rotation)); + } + + + /// + /// Check if this intersects a . + /// + /// The to test for intersection. + /// + /// true if this intersects , + /// false if it does not. + /// + public bool Intersects(Ray ray) + { + var origin = Vector3.Transform(ray.Position, _inverseTransform); + var direction = Vector3.TransformNormal(ray.Direction, _inverseTransform); + + var x0 = origin.X; + var xt = direction.X; + var y0 = origin.Y; + var yt = direction.Y; + var z0 = origin.Z; + var zt = direction.Z; + + // Note: This solution is based on these equations + // x^2 + z^2 = 1, -1 <= y <= 1 | For the cylinder + // (x, y, z) = (x0, y0, z0) + t * (xt, yt, zt) | For the ray + + float t1, t2; + + if (yt == 0) + { + if (y0 > 1) return false; + if (y0 < -1) return false; + t1 = float.MinValue; + t2 = float.MaxValue; + } + else + { + t1 = (-1 - y0) / yt; + t2 = (1 - y0) / yt; + } + + float a = xt * xt + zt * zt, + b = 2 * x0 * xt + 2 * z0 * zt, + c = x0 * x0 + z0 * z0 - 1; + + var root = b * b - 4 * a * c; + + if (root < 0) return false; + if (root == 0) + { + var t = -b / (2 * a); + return t >= t1 && t <= t2; + } + var up = -b; + var down = 2 * a; + var sqrt = MathF.Sqrt(root); + + float t3, t4; + t3 = (up - sqrt) / down; + t4 = (up + sqrt) / down; + + if (t3 <= t1 && t4 >= t2) return true; + if (t3 >= t1 && t3 <= t2) return true; + if (t4 >= t1 && t4 <= t2) return true; + return false; + } + + /// + /// Check if this contains a point. + /// + /// The to test. + /// + /// if this contains + /// or if it does not. + /// + public ContainmentType Contains(Vector3 point) + { + var transformedPoint = Vector3.Transform(point, _inverseRotation); + + if (MathF.Abs(_center.Y - transformedPoint.Y) > _halfHeight) + return ContainmentType.Disjoint; + + var centerToPoint = transformedPoint - _center; + + var squaredPointX = centerToPoint.X * centerToPoint.X; + var squaredPointZ = centerToPoint.Z * centerToPoint.Z; + var squaredRadius = _radius * _radius; + + return ((squaredPointX + squaredPointZ) <= squaredRadius) ? ContainmentType.Contains : ContainmentType.Disjoint; + } + + + /// + /// Gets the closest point in a cylinder from a point. + /// + /// The point from which to find the closest position. + /// A position in the cylinder that is the closest to + private Vector3 ClosestPoint(Vector3 point) + { + // Transform the point to cylindrical UVW coordinates + var uvwPoint = Vector3.Transform(point, _inverseRotation); + + // Find the closest point in UVW coordinates + + var direction = uvwPoint - _center; + direction.Y = 0; + if (direction.LengthSquared() > (_radius * _radius)) + { + direction.Normalize(); + direction *= _radius; + } + + var distanceY = uvwPoint.Y - _center.Y; + if (MathF.Abs(distanceY) > _halfHeight) + return _center + new Vector3(0, _halfHeight, 0) * Math.Sign(distanceY) + direction; + + var uvwResult = _center + new Vector3(0, distanceY, 0) + direction; + + + + + // Transform that result back to world coordinates + var translatedRotation = Matrix.Invert(_inverseRotation); + return Vector3.Transform(uvwResult, translatedRotation); + } + + + + /// + /// Check if this intersects a . + /// + /// The to test for intersection. + /// + /// true if this intersects , + /// false if it does not. + /// + public bool Intersects(BoundingSphere sphere) + { + // Transform the sphere center to cylindrical UVW coordinates + var uvwSphereCenter = Vector3.Transform(sphere.Center, _inverseRotation); + + // We check if there is intersection in UVW space + + var sphereRadius = sphere.Radius; + var distanceY = MathF.Abs(uvwSphereCenter.Y - _center.Y); + + // If the sphere is way too high or too low there is no intersection + if (distanceY > _halfHeight + sphereRadius) + return false; + + var centerToCenter = uvwSphereCenter - _center; + centerToCenter.Y = 0; + + var addedRadius = _radius + sphereRadius; + + // If the sphere is too far in the XZ plane there is no intersection + if (centerToCenter.LengthSquared() > (addedRadius * addedRadius)) + return false; + + // If the sphere's center is inside the Y coordinates of the cylinder, there is an intersection + if (distanceY < _halfHeight) + return true; + + // Check if the closest point to the center of the sphere belongs to the cylinder + centerToCenter.Normalize(); + centerToCenter *= _radius; + centerToCenter.Y = _halfHeight * MathF.Sign(uvwSphereCenter.Y - _center.Y); + centerToCenter += _center; + + return (centerToCenter - uvwSphereCenter).LengthSquared() <= (sphereRadius * sphereRadius); + } + + + /// + /// Check if this intersects a Line Segment. + /// + /// The start point of the Line Segment to test for intersection. + /// The end point of the Line Segment to test for intersection. + /// + /// true if this intersects with the Line Segment, + /// false if it does not. + /// + public Vector3? Intersects(Vector3 pointA, Vector3 pointB) + { + var halfHeight = Vector3.TransformNormal(Vector3.Up, Transform); + var cylinderInit = _center - halfHeight; + var cylinderEnd = _center + halfHeight; + + var t = -1f; + var q = Vector3.Zero; + + Vector3 d = cylinderEnd - cylinderInit, m = pointA - cylinderInit, n = pointB - pointA; + var md = Vector3.Dot(m, d); + var nd = Vector3.Dot(n, d); + var dd = Vector3.Dot(d, d); + + // Test if segment fully outside either endcap of cylinder + if (md < 0.0f && md + nd < 0.0f) return null; // Segment outside ’p’ side of cylinder + if (md > dd && md + nd > dd) return null; // Segment outside ’q’ side of cylinder + var nn = Vector3.Dot(n, n); + var mn = Vector3.Dot(m, n); + var a = dd * nn - nd * nd; + var k = Vector3.Dot(m, m) - _radius * _radius; + var c = dd * k - md * md; + if (MathF.Abs(a) < float.Epsilon) + { + // Segment runs parallel to cylinder axis + if (c > 0.0f) + return null; // 'a' and thus the segment lie outside cylinder + // Now known that segment intersects cylinder; figure out how it intersects + if (md < 0.0f) + t = -mn / nn; // Intersect segment against 'p' endcap + else if (md > dd) + t = (nd - mn) / nn; // Intersect segment against ’q’ endcap + else + t = 0.0f; // 'a' lies inside cylinder + q = pointA + t * n; + return q; + } + var b = dd * mn - nd * md; + var discr = b * b - a * c; + if (discr < 0.0f) + return null; // No real roots; no intersection + t = (-b - MathF.Sqrt(discr)) / a; + if (t < 0.0f || t > 1.0f) + return null; // Intersection lies outside segment + + if (md + t * nd < 0.0f) + { + // Intersection outside cylinder on 'p' side + if (nd <= 0.0f) + return null; // Segment pointing away from endcap + t = -md / nd; + // Keep intersection if Dot(S(t) - p, S(t) - p) <= r^2 + if (k + t * (2.0f * mn + t * nn) <= 0.0f) + return q; + else + return null; + } + if (md + t * nd > dd) + { + // Intersection outside cylinder on 'q' side + if (nd >= 0.0f) + return null; // Segment pointing away from endcap + t = (dd - md) / nd; + // Keep intersection if Dot(S(t) - q, S(t) - q) <= r^2 + if (k + dd - 2.0f * md + t * (2.0f * (mn - nd) + t * nn) <= 0.0f) + return q; + else + return null; + } + + // Segment intersects cylinder between the endcaps; t is correct + q = pointA + t * n; + return q; + } + + + + /// + /// Check if this intersects a . + /// + /// The box to test for intersection. + /// A indicating if the bounding volumes intersect with each other. + public BoxCylinderIntersection Intersects(BoundingBox box) + { + if (IsXZAligned) + return IntersectsXZAligned(box); + else + // TODO: Implement the method from + // https://github.com/teikitu/teikitu_release/blob/master/teikitu/src/TgS%20COLLISION/TgS%20Collision%20-%20F%20-%20Cylinder-Box.c_inc + throw new NotImplementedException(); + } + + /// + /// Check if this , assumed XZ aligned, intersects a . + /// + /// The box to test for intersection. + /// A indicating if the bounding volumes intersect with each other. + private BoxCylinderIntersection IntersectsXZAligned(BoundingBox box) + { + // Calculate the closest point + var closestPoint = BoundingVolumesExtensions.ClosestPoint(box, _center); + + // Is closest point the same as the center? + // This means that the center is inside the box + if (closestPoint.Equals(_center)) + return BoxCylinderIntersection.Intersecting; + + // Distance in Y, is it greater, less, or in the center? + var differenceInY = MathF.Abs(closestPoint.Y - _center.Y); + + // If the absolute of the distance is greater than half the height, we are not intersecting + if (differenceInY > _halfHeight) + return BoxCylinderIntersection.None; + + var radiusSquared = _radius * _radius; + var centerDistance = new Vector2(_center.X - closestPoint.X, _center.Z - closestPoint.Z); + var differenceInRadius = centerDistance.LengthSquared() - radiusSquared; + + // If the distance is equal, this means that we are on the top/bottom faces + // We are colliding on the top or bottom, so check if we are in the radius. + // We are either on the edge or not colliding + if (differenceInY == _halfHeight) + return (differenceInRadius <= 0f) ? BoxCylinderIntersection.Edge : BoxCylinderIntersection.None; + + // If we got here, the closest point is not at the top/bottom + // It depends on our distance to classify the intersection + + if (differenceInRadius == 0f) + return BoxCylinderIntersection.Edge; + else if (differenceInRadius < 0f) + return BoxCylinderIntersection.Intersecting; + else + return BoxCylinderIntersection.None; + } + + + + /// + /// Updates the Translation matrix and the Opposite Translation matrix as well, + /// based on the contents of . + /// + private void UpdateTranslation() + { + _translation = Matrix.CreateTranslation(_center); + _oppositeTranslation = Matrix.CreateTranslation(-_center); + } + + /// + /// Updates the Scale matrix based on the contents of and . + /// + private void UpdateScale() + { + _scale = Matrix.CreateScale(_radius, _halfHeight, _radius); + } + + /// + /// Updates the Inverse Rotation matrix, used in intersection tests, based on the values of , + /// and . + /// + private void UpdateInverseRotation() + { + _inverseRotation = + _oppositeTranslation * + Matrix.Invert(_rotation) * + _translation; + } + + /// + /// Updates the Transform and Inverse Transform matrices, based on the values of , and . + /// + private void UpdateTransform() + { + Transform = _scale * _rotation * _translation; + _inverseTransform = Matrix.Invert(Transform); + } + } + + + /// + /// Describes the type of intersection a and a had. + /// + public enum BoxCylinderIntersection + { + ///The box touches the cylinder at an edge. Penetration is zero. + Edge, + ///The box touches the cylinder. Penetration is more than zero. + Intersecting, + ///The box and the cylinder do not intersect. + None, + } + +} diff --git a/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs new file mode 100644 index 000000000..053a2037b --- /dev/null +++ b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs @@ -0,0 +1,221 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; + +namespace TGC.MonoGame.Samples.Collisions +{ + /// + /// Class that extends BoundingVolumes classes + /// + public static class BoundingVolumesExtensions + { + /// + /// Get an extents vector that contains the half-size on each axis of the box. + /// + /// A to calculate its extents + /// The extents on each axis + public static Vector3 GetExtents(BoundingBox box) + { + var max = box.Max; + var min = box.Min; + + return (max - min) * 0.5f; + } + + /// + /// Gets the total volume of the box in units. + /// + /// A to calculate its volume + /// The volume of the box in units + public static float GetVolume(BoundingBox box) + { + var difference = box.Max - box.Min; + return difference.X * difference.Y * difference.Z; + } + + /// + /// Gets the center position of the box. + /// + /// A to calculate its center + /// The position of the center of the box. + public static Vector3 GetCenter(BoundingBox box) + { + return (box.Max + box.Min) * 0.5f; + } + + + /// + /// Scales the box by a given scalar. + /// + /// The scale for every axis + /// The to scale + /// A new box with its extents scaled + public static BoundingBox Scale(BoundingBox box, float scale) + { + var center = GetCenter(box); + var extents = GetExtents(box); + var scaledExtents = extents * scale; + + return new BoundingBox(center - scaledExtents, center + scaledExtents); + } + + /// + /// Scales the box by a given scalar per axis. + /// + /// The to calculate its scale + /// The scale for each axis + /// A new BoundingBox with its extents scaled + public static BoundingBox Scale(BoundingBox box, Vector3 scale) + { + var center = GetCenter(box); + var extents = GetExtents(box); + var scaledExtents = extents * scale; + + return new BoundingBox(center - scaledExtents, center + scaledExtents); + } + + /// + /// Gets the closest point to the box. + /// + /// A to calculate the closest point + /// The point to find the closest point from + /// The position inside the box that is closer to the given point + public static Vector3 ClosestPoint(BoundingBox box, Vector3 point) + { + var min = box.Min; + var max = box.Max; + point.X = MathHelper.Clamp(point.X, min.X, max.X); + point.Y = MathHelper.Clamp(point.Y, min.Y, max.Y); + point.Z = MathHelper.Clamp(point.Z, min.Z, max.Z); + return point; + } + + /// + /// Gets the normal vector from a point in the box surface. + /// + /// A to calculate the normal + /// The point in the surface of the box + /// The normal vector of the surface in which the point is in + public static Vector3 GetNormalFromPoint(BoundingBox box, Vector3 point) + { + var normal = Vector3.Zero; + var min = float.MaxValue; + + point -= GetCenter(box); + var extents = GetExtents(box); + + var distance = MathF.Abs(extents.X - Math.Abs(point.X)); + if (distance < min) + { + min = distance; + normal = Math.Sign(point.X) * Vector3.UnitX; + // Cardinal axis for X + } + distance = Math.Abs(extents.Y - Math.Abs(point.Y)); + if (distance < min) + { + min = distance; + normal = Math.Sign(point.Y) * Vector3.UnitY; + // Cardinal axis for Y + } + distance = Math.Abs(extents.Z - Math.Abs(point.Z)); + if (distance < min) + { + normal = Math.Sign(point.Z) * Vector3.UnitZ; + // Cardinal axis for Z + } + return normal; + } + + /// + /// Creates a BoundingBox from a Matrix. + /// + /// The Matrix that describes a transformation to apply to each point of a box + /// The BoundingBox created from the Matrix + public static BoundingBox FromMatrix(Matrix matrix) + { + return new BoundingBox(Vector3.Transform(-Vector3.One * 0.5f, matrix), Vector3.Transform(Vector3.One * 0.5f, matrix)); + } + + /// + /// Creates a BoundingBox from a Model, using all its sub-meshes. + /// + /// The model to create the box + /// The BoundingBox that encloses the vertices from the model + public static BoundingBox CreateAABBFrom(Model model) + { + var minPoint = Vector3.One * float.MaxValue; + var maxPoint = Vector3.One * float.MinValue; + + var transforms = new Matrix[model.Bones.Count]; + model.CopyAbsoluteBoneTransformsTo(transforms); + + var meshes = model.Meshes; + for (int index = 0; index < meshes.Count; index++) + { + var meshParts = meshes[index].MeshParts; + for (int subIndex = 0; subIndex < meshParts.Count; subIndex++) + { + var vertexBuffer = meshParts[subIndex].VertexBuffer; + var declaration = vertexBuffer.VertexDeclaration; + var vertexSize = declaration.VertexStride / sizeof(float); + + var rawVertexBuffer = new float[vertexBuffer.VertexCount * vertexSize]; + vertexBuffer.GetData(rawVertexBuffer); + + for (var vertexIndex = 0; vertexIndex < rawVertexBuffer.Length; vertexIndex += vertexSize) + { + var transform = transforms[meshes[index].ParentBone.Index]; + var vertex = new Vector3(rawVertexBuffer[vertexIndex], rawVertexBuffer[vertexIndex + 1], rawVertexBuffer[vertexIndex + 2]); + vertex = Vector3.Transform(vertex, transform); + minPoint = Vector3.Min(minPoint, vertex); + maxPoint = Vector3.Max(maxPoint, vertex); + } + } + } + return new BoundingBox(minPoint, maxPoint); + } + + /// + /// Creates a BoundingSphere from a Model, using all its sub-meshes. + /// + /// The model to create the sphere + /// The BoundingSphere which radius encloses the vertices from the model + public static BoundingSphere CreateSphereFrom(Model model) + { + var minPoint = Vector3.One * float.MaxValue; + var maxPoint = Vector3.One * float.MinValue; + + var transforms = new Matrix[model.Bones.Count]; + model.CopyAbsoluteBoneTransformsTo(transforms); + + var meshes = model.Meshes; + for (var index = 0; index < meshes.Count; index++) + { + var meshParts = meshes[index].MeshParts; + for (var subIndex = 0; subIndex < meshParts.Count; subIndex++) + { + var vertexBuffer = meshParts[subIndex].VertexBuffer; + var declaration = vertexBuffer.VertexDeclaration; + int vertexSize = declaration.VertexStride / sizeof(float); + + var rawVertexBuffer = new float[vertexBuffer.VertexCount * vertexSize]; + vertexBuffer.GetData(rawVertexBuffer); + + for (var vertexIndex = 0; vertexIndex < rawVertexBuffer.Length; vertexIndex += vertexSize) + { + var transform = transforms[meshes[index].ParentBone.Index]; + var vertex = new Vector3(rawVertexBuffer[vertexIndex], rawVertexBuffer[vertexIndex + 1], rawVertexBuffer[vertexIndex + 2]); + vertex = Vector3.Transform(vertex, transform); + minPoint = Vector3.Min(minPoint, vertex); + maxPoint = Vector3.Max(maxPoint, vertex); + } + } + } + var difference = (maxPoint - minPoint) * 0.5f; + return new BoundingSphere(difference, difference.Length()); + } + + } +} diff --git a/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs new file mode 100644 index 000000000..e2741dddb --- /dev/null +++ b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs @@ -0,0 +1,429 @@ +using Microsoft.Xna.Framework; +using System; + +namespace TGC.MonoGame.Samples.Collisions +{ + /// + /// Represents an Oriented-BoundingBox (OBB). + /// + public class OrientedBoundingBox + { + /// + /// Center. + /// + public Vector3 Center { get; set; } + + /// + /// Orientation + /// + public Matrix Orientation { get; set; } + + /// + /// Extents + /// + public Vector3 Extents { get; set; } + + + + + /// + /// Builds an empty Bounding Oriented Box. + /// + public OrientedBoundingBox() { } + + /// + /// Builds a Oriented Bounding-Box with a center and extents. + /// + /// + /// + public OrientedBoundingBox(Vector3 center, Vector3 extents) + { + Center = center; + Extents = extents; + Orientation = Matrix.Identity; + } + + /// + /// Rotate the OBB with a given Matrix. + /// Note that this is a relative rotation. + /// + /// Rotation matrix + public void Rotate(Matrix rotation) + { + Orientation *= rotation; + } + + /// + /// Rotate the OBB with a given Quaternion. + /// Note that this is a relative rotation. + /// + /// Rotation quaternion + public void Rotate(Quaternion rotation) + { + Rotate(Matrix.CreateFromQuaternion(rotation)); + } + + + /// + /// Creates an OBB from a given set of points. + /// Searches for the best OBB orientation that matches the points. + /// Note that it is an expensive operation. + /// + /// An array of points in World Space + /// A generated Oriented Bounding Box that contains the set of points + public static OrientedBoundingBox ComputeFromPoints(Vector3[] points) + { + return ComputeFromPointsRecursive(points, Vector3.Zero, new Vector3(360, 360, 360), 10f); + } + + + /// + /// Calculates an OBB with a given set of points. + /// Tests every orientations between initValues and endValues, stepping through angle intervals with a given step size. + /// Goes on until it reaches a step less than 0.01 + /// + /// A generated Oriented Bounding Box that contains the set of points + private static OrientedBoundingBox ComputeFromPointsRecursive(Vector3[] points, Vector3 initValues, Vector3 endValues, + float step) + { + var minObb = new OrientedBoundingBox(); + var minimumVolume = float.MaxValue; + var minInitValues = Vector3.Zero; + var minEndValues = Vector3.Zero; + var transformedPoints = new Vector3[points.Length]; + float y, z; + + var x = initValues.X; + while (x <= endValues.X) + { + y = initValues.Y; + var rotationX = MathHelper.ToRadians(x); + while (y <= endValues.Y) + { + z = initValues.Z; + var rotationY = MathHelper.ToRadians(y); + while (z <= endValues.Z) + { + // Rotation matrix + var rotationZ = MathHelper.ToRadians(z); + var rotationMatrix = Matrix.CreateFromYawPitchRoll(rotationY, rotationX, rotationZ); + + // Transform every point to OBB-Space + for (var index = 0; index < transformedPoints.Length; index++) + transformedPoints[index] = Vector3.Transform(points[index], rotationMatrix); + + // Obtain an AABB enclosing every transformed point + var aabb = BoundingBox.CreateFromPoints(transformedPoints); + + // Calculate the volume of the AABB + var volume = BoundingVolumesExtensions.GetVolume(aabb); + + // Find lesser volume + if (volume < minimumVolume) + { + minimumVolume = volume; + minInitValues = new Vector3(x, y, z); + minEndValues = new Vector3(x + step, y + step, z + step); + + // Restore the AABB center in World-Space + var center = BoundingVolumesExtensions.GetCenter(aabb); + center = Vector3.Transform(center, rotationMatrix); + + // Create OBB + minObb = new OrientedBoundingBox(center, BoundingVolumesExtensions.GetExtents(aabb)); + minObb.Orientation = rotationMatrix; + } + + z += step; + } + y += step; + } + x += step; + } + + // Loop again if the step is higher than a given acceptance threshold + if (step > 0.01f) + minObb = ComputeFromPointsRecursive(points, minInitValues, minEndValues, step / 10f); + + return minObb; + } + + /// + /// Creates an OrientedBoundingBox from a BoundingBox. + /// + /// A BoundingBox to create the OrientedBoundingBox from + /// The generated OrientedBoundingBox + public static OrientedBoundingBox FromAABB(BoundingBox box) + { + var center = BoundingVolumesExtensions.GetCenter(box); + var extents = BoundingVolumesExtensions.GetExtents(box); + return new OrientedBoundingBox(center, extents); + } + + /// + /// Converts a point from World-Space to OBB-Space. + /// + /// Point in World-Space + /// The point in OBB-Space + public Vector3 ToOBBSpace(Vector3 point) + { + var difference = point - Center; + return Vector3.Transform(difference, Orientation); + } + + + /// + /// A helper method to create an array from a Vector3 + /// + /// The vector to create the array from + /// An array of length three with each position matching the Vector3 coordinates + private float[] ToArray(Vector3 vector) + { + return new[] { vector.X, vector.Y, vector.Z }; + } + + + + /// + /// A helper method to create an array from a 3x3 Matrix + /// + /// A 3x3 Matrix to create the array from + /// An array of length nine with each position matching the matrix elements + private float[] ToFloatArray(Matrix matrix) + { + return new[] + { + matrix.M11, matrix.M21, matrix.M31, + matrix.M12, matrix.M22, matrix.M32, + matrix.M13, matrix.M23, matrix.M33, + }; + } + + /// + /// Tests if this OBB intersects with another OBB. + /// + /// The other OBB to test + /// True if the two boxes intersect + public bool Intersects(OrientedBoundingBox box) + { + float ra; + float rb; + var R = new float[3, 3]; + var AbsR = new float[3, 3]; + var ae = ToArray(Extents); + var be = ToArray(box.Extents); + + // Compute rotation matrix expressing the other box in this box coordinate frame + + var result = ToFloatArray(Matrix.Multiply(Orientation, box.Orientation)); + + for (var i = 0; i < 3; i++) + for (var j = 0; j < 3; j++) + R[i, j] = result[i * 3 + j]; + + + // Compute translation vector t + var tVec = box.Center - Center; + + // Bring translation into this boxs coordinate frame + + var t = ToArray(Vector3.Transform(tVec, Orientation)); + + // Compute common subexpressions. Add in an epsilon term to + // counteract arithmetic errors when two edges are parallel and + // their cross product is (near) null (see text for details) + + for (var i = 0; i < 3; i++) + for (var j = 0; j < 3; j++) + AbsR[i, j] = MathF.Abs(R[i, j]) + float.Epsilon; + + // Test axes L = A0, L = A1, L = A2 + for (var i = 0; i < 3; i++) + { + ra = ae[i]; + rb = be[0] * AbsR[i, 0] + be[1] * AbsR[i, 1] + be[2] * AbsR[i, 2]; + if (MathF.Abs(t[i]) > ra + rb) return false; + } + + // Test axes L = B0, L = B1, L = B2 + for (var i = 0; i < 3; i++) + { + ra = ae[0] * AbsR[0, i] + ae[1] * AbsR[1, i] + ae[2] * AbsR[2, i]; + rb = be[i]; + if (MathF.Abs(t[0] * R[0, i] + t[1] * R[1, i] + t[2] * R[2, i]) > ra + rb) return false; + } + + // Test axis L = A0 x B0 + ra = ae[1] * AbsR[2, 0] + ae[2] * AbsR[1, 0]; + rb = be[1] * AbsR[0, 2] + be[2] * AbsR[0, 1]; + if (MathF.Abs(t[2] * R[1, 0] - t[1] * R[2, 0]) > ra + rb) return false; + + // Test axis L = A0 x B1 + ra = ae[1] * AbsR[2, 1] + ae[2] * AbsR[1, 1]; + rb = be[0] * AbsR[0, 2] + be[2] * AbsR[0, 0]; + if (MathF.Abs(t[2] * R[1, 1] - t[1] * R[2, 1]) > ra + rb) return false; + + // Test axis L = A0 x B2 + ra = ae[1] * AbsR[2, 2] + ae[2] * AbsR[1, 2]; + rb = be[0] * AbsR[0, 1] + be[1] * AbsR[0, 0]; + if (MathF.Abs(t[2] * R[1, 2] - t[1] * R[2, 2]) > ra + rb) return false; + + // Test axis L = A1 x B0 + ra = ae[0] * AbsR[2, 0] + ae[2] * AbsR[0, 0]; + rb = be[1] * AbsR[1, 2] + be[2] * AbsR[1, 1]; + if (MathF.Abs(t[0] * R[2, 0] - t[2] * R[0, 0]) > ra + rb) return false; + + // Test axis L = A1 x B1 + ra = ae[0] * AbsR[2, 1] + ae[2] * AbsR[0, 1]; + rb = be[0] * AbsR[1, 2] + be[2] * AbsR[1, 0]; + if (MathF.Abs(t[0] * R[2, 1] - t[2] * R[0, 1]) > ra + rb) return false; + + // Test axis L = A1 x B2 + ra = ae[0] * AbsR[2, 2] + ae[2] * AbsR[0, 2]; + rb = be[0] * AbsR[1, 1] + be[1] * AbsR[1, 0]; + if (MathF.Abs(t[0] * R[2, 2] - t[2] * R[0, 2]) > ra + rb) return false; + + // Test axis L = A2 x B0 + ra = ae[0] * AbsR[1, 0] + ae[1] * AbsR[0, 0]; + rb = be[1] * AbsR[2, 2] + be[2] * AbsR[2, 1]; + if (MathF.Abs(t[1] * R[0, 0] - t[0] * R[1, 0]) > ra + rb) return false; + + // Test axis L = A2 x B1 + ra = ae[0] * AbsR[1, 1] + ae[1] * AbsR[0, 1]; + rb = be[0] * AbsR[2, 2] + be[2] * AbsR[2, 0]; + if (MathF.Abs(t[1] * R[0, 1] - t[0] * R[1, 1]) > ra + rb) return false; + + // Test axis L = A2 x B2 + ra = ae[0] * AbsR[1, 2] + ae[1] * AbsR[0, 2]; + rb = be[0] * AbsR[2, 1] + be[1] * AbsR[2, 0]; + if (MathF.Abs(t[1] * R[0, 2] - t[0] * R[1, 2]) > ra + rb) return false; + + // Since no separating axis is found, the OBBs must be intersecting + return true; + } + + + /// + /// Tests if this OBB intersects with another AABB. + /// + /// The other AABB to test + /// True if the two boxes intersect + public bool Intersects(BoundingBox box) + { + return Intersects(FromAABB(box)); + } + + /// + /// Tests if this OBB intersects with a Ray. + /// + /// The ray to test + /// The length in the ray direction from the ray origin + /// True if the OBB intersects the Ray + public bool Intersects(Ray ray, out float? result) + { + //Transform Ray to OBB-Space + var rayOrigin = ray.Position; + var rayDestination = rayOrigin + ray.Direction; + + + var rayOriginInOBBSpace = ToOBBSpace(rayOrigin); + var rayDestinationInOBBSpace = ToOBBSpace(rayDestination); + + var rayInOBBSpace = new Ray(rayOriginInOBBSpace, Vector3.Normalize(rayDestinationInOBBSpace - rayOriginInOBBSpace)); + + // Create an AABB that encloses OBB + var enclosingBox = new BoundingBox(-Extents, Extents); + + // Perform Ray-AABB intersection + var testResult = enclosingBox.Intersects(rayInOBBSpace); + result = testResult; + + return testResult != null; + } + + + /// + /// Tests if this OBB intersects with a Sphere. + /// + /// The sphere to test + /// True if the OBB intersects the Sphere + public bool Intersects(BoundingSphere sphere) + { + // Transform sphere to OBB-Space + var obbSpaceSphere = new BoundingSphere(ToOBBSpace(sphere.Center), sphere.Radius); + + // Create AABB enclosing the OBB + var aabb = new BoundingBox(-Extents, Extents); + + return aabb.Intersects(obbSpaceSphere); + } + + + + /// + /// Tests the intersection between the OBB and a Plane. + /// + /// The plane to test + /// Front if the OBB is in front of the plane, back if it is behind, and intersecting if it intersects with the plane + public PlaneIntersectionType Intersects(Plane plane) + { + // Maximum extent in direction of plane normal + var normal = Vector3.Transform(plane.Normal, Orientation); + + // Maximum extent in direction of plane normal + var r = MathF.Abs(Extents.X * normal.X) + + MathF.Abs(Extents.Y * normal.Y) + + MathF.Abs(Extents.Z * normal.Z); + + // signed distance between box center and plane + var d = Vector3.Dot(plane.Normal, Center) + plane.D; + + + // Return signed distance + if (MathF.Abs(d) < r) + return PlaneIntersectionType.Intersecting; + else if (d < 0.0f) + return PlaneIntersectionType.Front; + else + return PlaneIntersectionType.Back; + } + + /// + /// Tests the intersection between the OBB and a Frustum. + /// + /// The frustum to test + /// True if the OBB intersects with the Frustum, false otherwise + public bool Intersects(BoundingFrustum frustum) + { + var planes = new[] + { + frustum.Left, + frustum.Right, + frustum.Far, + frustum.Near, + frustum.Bottom, + frustum.Top + }; + + for (var faceIndex = 0; faceIndex < 6; ++faceIndex) + { + var side = Intersects(planes[faceIndex]); + if (side == PlaneIntersectionType.Back) + return false; + } + return true; + } + + /// + /// Converts a point from OBB-Space to World-Space. + /// + /// Point in OBB-Space + /// The point in World-Space + public Vector3 ToWorldSpace(Vector3 point) + { + return Center + Vector3.Transform(point, Orientation); + } + + } + +} diff --git a/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs b/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs new file mode 100644 index 000000000..c51acb923 --- /dev/null +++ b/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs @@ -0,0 +1,74 @@ +using Microsoft.Xna.Framework; + +namespace TGC.MonoGame.Samples.Collisions +{ + /// + /// Utilidades para hacer detección de colisiones + /// + public class TGCCollisionUtils + { + /// + /// Detecta colision entre un segmento pq y un triangulo abc. + /// Devuelve true si hay colision y carga las coordenadas barycentricas (u,v,w) de la colision, el + /// instante t de colision y el punto c de colision. + /// Basado en: Real Time Collision Detection pag 191 + /// + /// Inicio del segmento + /// Fin del segmento + /// Vertice 1 del triangulo + /// Vertice 2 del triangulo + /// Vertice 3 del triangulo + /// Coordenadas barycentricas de colision + /// Instante de colision + /// Punto de colision + /// True si hay colision + public static bool IntersectSegmentTriangle(Vector3 p, Vector3 q, Vector3 a, Vector3 b, Vector3 c, + out Vector3 uvw, out float t, out Vector3 col) + { + float u; + float v; + float w; + uvw = Vector3.Zero; + col = Vector3.Zero; + t = -1; + + var ab = b - a; + var ac = c - a; + var qp = p - q; + + // Compute triangle normal. Can be precalculated or cached if intersecting multiple segments against the same triangle + var n = Vector3.Cross(ab, ac); + + // Compute denominator d. If d <= 0, segment is parallel to or points away from triangle, so exit early + var d = Vector3.Dot(qp, n); + if (d <= 0.0f) return false; + + // Compute intersection t value of pq with plane of triangle. A ray intersects iff 0 <= t. + // Segment intersects iff 0 <= t <= 1. Delay dividing by d until intersection has been found to pierce triangle + var ap = p - a; + t = Vector3.Dot(ap, n); + if (t < 0.0f) return false; + if (t > d) return false; // For segment; exclude this code line for a ray test + + // Compute barycentric coordinate components and test if within bounds + var e = Vector3.Cross(qp, ap); + v = Vector3.Dot(ac, e); + if (v < 0.0f || v > d) return false; + w = -Vector3.Dot(ab, e); + if (w < 0.0f || v + w > d) return false; + + // Segment/ray intersects triangle. Perform delayed division and compute the last barycentric coordinate component + var ood = 1.0f / d; + t *= ood; + v *= ood; + w *= ood; + u = 1.0f - v - w; + + uvw.X = u; + uvw.Y = v; + uvw.Z = w; + col = p + t * (p - q); + return true; + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index c0d00b584..98b44e88b 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -31,6 +31,12 @@ public class Character Vector3 RotationAxis = Vector3.UnitY; float RotationAngle = 0f; + Vector3 BallSpinAxis=Vector3.UnitX; + float BallSpinAngle=0f; + Matrix WorldWithBallSpin; + float BallPitch=0f; + float BallRoll=0f; + public Character(ContentManager content, Vector3 initialPosition) { @@ -50,6 +56,7 @@ private void InitializeSphere(Vector3 initialPosition) Position = initialPosition; World = Scale * Matrix.CreateTranslation(Position); + WorldWithBallSpin=World; // Apply the effect to all mesh parts Sphere.Meshes.FirstOrDefault().MeshParts.FirstOrDefault().Effect = Effect; @@ -75,11 +82,13 @@ public void Update(GameTime gameTime) public void Draw(Matrix view, Matrix projection) { - var worldView = World * view; + var worldView = WorldWithBallSpin * view; Effect.Parameters["matWorld"].SetValue(World); Effect.Parameters["matWorldViewProj"].SetValue(worldView * projection); Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(World))); + //Game.Gizmos.DrawSphere(World, Vector3.One*20, Color.Red); + Sphere.Meshes.FirstOrDefault().Draw(); } @@ -208,6 +217,15 @@ private void ProcessMovement(GameTime gameTime) Vector3 gravity = Vector3.Zero; + Vector3 SpinVelocity=Velocity; + + + BallSpinAngle += Velocity.Length()*elapsedTime / (MathHelper.Pi*12.5f); + BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); + + if(Acceleration==Vector3.Zero && Velocity!=Vector3.Zero) Velocity *= (1-elapsedTime); + if(Velocity==Vector3.Zero) BallSpinAxis = Vector3.UnitZ; + Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); directionX = Vector3.Transform(Vector3.UnitX, Rotation); @@ -238,6 +256,7 @@ private void ProcessMovement(GameTime gameTime) public void MoveTo(Vector3 position) { World = Scale * Matrix.CreateTranslation(position); + WorldWithBallSpin=Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle) * World; } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/TGC.MonoGame.TP.sln b/TGC.MonoGame.TP/TGC.MonoGame.TP.sln new file mode 100644 index 000000000..0236c4f12 --- /dev/null +++ b/TGC.MonoGame.TP/TGC.MonoGame.TP.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TGC.MonoGame.TP", "TGC.MonoGame.TP.csproj", "{8D3E53BE-50D1-4D4A-BE67-D0551CABB0E2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D3E53BE-50D1-4D4A-BE67-D0551CABB0E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D3E53BE-50D1-4D4A-BE67-D0551CABB0E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D3E53BE-50D1-4D4A-BE67-D0551CABB0E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D3E53BE-50D1-4D4A-BE67-D0551CABB0E2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C52A956B-0518-4E6D-99E2-4A47D8F6CC52} + EndGlobalSection +EndGlobal From ee5a616e0acebb41540337b8d482571733fc0c9f Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sat, 1 Jun 2024 16:21:21 -0300 Subject: [PATCH 43/73] Agrego un 2do nivel --- TGC.MonoGame.TP/Stages/Stage_02.cs | 234 +++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 TGC.MonoGame.TP/Stages/Stage_02.cs diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs new file mode 100644 index 000000000..5b033645e --- /dev/null +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -0,0 +1,234 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.MainCharacter; + + +class Stage_02 : Stage +{ + + public Stage_02(GraphicsDevice graphicsDevice, ContentManager content) : + base(graphicsDevice, content, characterPosition: new Vector3(300f, 25f, 0f)) { } + + protected override void LoadTrack() + { + Track = new List() + { + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(0, 0, 0), scale: new Vector3(30, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(87.5f, 50, -112.5f), scale: new Vector3(1, 3, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(87.5f, 50, 112.5f), scale: new Vector3(1, 3, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(87.5f, 112.5f, 0), scale: new Vector3(1, 2, 10), rotation: Matrix.CreateFromYawPitchRoll(3.1415927f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-625, 0, 0), scale: new Vector3(20, 1, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1000, 0, 0), scale: new Vector3(10, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1212.5f, 0, 0), scale: new Vector3(7, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, 25, 0), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-1.5707964f, 3.1415927f, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, 0, -175), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1275, -12.5f, -362.5f), scale: new Vector3(2, 2, 5), rotation: Matrix.CreateFromYawPitchRoll(3.1415927f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, 0, -312.5f), scale: new Vector3(2, 1, 2), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -12.5f, -400), scale: new Vector3(2, 2, 5), rotation: Matrix.CreateFromYawPitchRoll(-3.1415927f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -537.5f), scale: new Vector3(10, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(1.5707964f, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -25, -662.5f), scale: new Vector3(1, 3, 3), rotation: Matrix.CreateFromYawPitchRoll(3.926991f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1150, -50, -687.5f), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1350, -50, -687.5f), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -812.5f), scale: new Vector3(1, 7, 7), rotation: Matrix.CreateFromYawPitchRoll(0.7853983f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -75, -925), scale: new Vector3(6, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -100, -1012.5f), scale: new Vector3(4, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -125, -1162.5f), scale: new Vector3(3, 1, 7), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -125, -1300), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(4.712389f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1025, -125, -1312.5f), scale: new Vector3(12, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-775, -125, -1312.5f), scale: new Vector3(4, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-625, -125, -1312.5f), scale: new Vector3(4, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-475, -125, -1312.5f), scale: new Vector3(4, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-375, -150, -1275), scale: new Vector3(2, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-287.5f, -175, -1250), scale: new Vector3(3, 1, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-200, -200, -1225), scale: new Vector3(2, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(12.5f, -200, -1287.5f), scale: new Vector3(15, 1, 5), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-25, -200, -1125), scale: new Vector3(12, 1, 2), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(237.5f, -225, -1162.5f), scale: new Vector3(5, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(287.5f, -237.5f, -850), scale: new Vector3(3, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(262.5f, -250, -675), scale: new Vector3(3, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(250, -262.5f, -575), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-4.712389f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-175, -262.5f, -537.5f), scale: new Vector3(30, 1, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-175, -262.5f, -600), scale: new Vector3(30, 1, 2), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-600, -287.5f, -575), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-700, -312.5f, -575), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(-1.5707964f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-762.5f, -337.5f, -575), scale: new Vector3(1, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-787.5f, -362.5f, -575), scale: new Vector3(1, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-812.5f, -387.5f, -575), scale: new Vector3(1, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-875, -412.5f, -575), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-875, -412.5f, -725), scale: new Vector3(4, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-875, -412.5f, -1500), scale: new Vector3(6, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-762.5f, -362.5f, -1737.5f), scale: new Vector3(1, 3, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-987.5f, -362.5f, -1737.5f), scale: new Vector3(1, 3, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-875, -312.5f, -1737.5f), scale: new Vector3(10, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-875f, -412.5f, -1825f), scale: new Vector3(10f, 1f, 20f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)) + }; + } + + protected override void LoadObstacles() + { + Obstacles = new List() + { + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -875), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -975), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1075), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1175), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1275), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1375), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-887.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-962.5f, 37.5f, -37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1037.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, -12.5f, -825), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1137.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1062.5f, -87.5f, -1287.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-987.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-525, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-400, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-275, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875f, -412.5f, -1825f), scale: new Vector3(10f, 1f, 20f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + + }; + } + + protected override void LoadSigns() + { + Signs = new List + { + + }; + } + + protected override void LoadPickups() + { + Pickups = new List() + { + // TODO: modificar los constructores de los otros modelos + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-387.5f, 25f, 0f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-412.5f, 25f, 0f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-437.5f, 25f, 0f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-462.5f, 25f, 0f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-487.5f, 25f, 0f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-562.5f, 25f, 62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-587.5f, 25f, 62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-612.5f, 25f, 62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-637.5f, 25f, 62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-687.5f, 25f, -62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-712.5f, 25f, -62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-737.5f, 25f, -62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-762.5f, 25f, -62.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, 25f, -150f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, 25f, -175f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, 25f, -200f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, -25f, -550f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, -25f, -525f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, -25f, -500f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1150f, -25f, -675f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1150f, -25f, -700f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new OctahedronPrimitive(GraphicsDevice, Content, Color.Turquoise, coordinates: new Vector3(-1150f, -25f, -737.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new LightningPrimitive(GraphicsDevice, Content, Color.Yellow, coordinates: new Vector3(-1350f, -25f, -737.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1350f, -25f, -700f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1350f, -25f, -675f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, -25f, -912.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1250f, -50f, -987.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -75f, -1050f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -75f, -1075f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -100f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -100f, -1150f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -100f, -1175f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-1237.5f, -100f, -1200f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-937.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-912.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-787.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-762.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-637.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-612.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-487.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-462.5f, -100f, -1312.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-162.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-137.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-112.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-87.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-62.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-37.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-12.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(12.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(37.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(62.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotationgit c: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new DiamondPrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(87.5f, -175f, -1125f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(100f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(150f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(50f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(0f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-50f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-100f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-150f, -175f, -1287.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(287.5f, -200f, -987.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(287.5f, -212.5f, -737.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(262.5f, -225f, -650f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(187.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(137.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(87.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(37.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-12.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-62.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-112.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-162.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-212.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-262.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-312.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-362.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-412.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-462.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-512.5f, -237.5f, -600f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new DiamondPrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(-487.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new DiamondPrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(-450f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new DiamondPrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(-362.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new DiamondPrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(-325f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-237.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-212.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-187.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-162.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-137.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-112.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-87.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-62.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-37.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-12.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(12.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(37.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(62.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(87.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(112.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(137.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(162.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new LightningPrimitive(GraphicsDevice, Content, Color.Yellow, coordinates: new Vector3(187.5f, -237.5f, -537.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-600f, -262.5f, -575f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-712.5f, -287.5f, -575f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-875f, -387.5f, -575f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + //new RupeePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(-875f, -387.5f, -712.5f), scale: new Vector3(1f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)) + }; + } + + protected override void LoadCheckpoints() + { + Checkpoints = new List() + { + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1762.5f), scale: new Vector3(10, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -337.5f, -1737.5f), scale: new Vector3(10, 5, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-812.5f, -300, -575), scale: new Vector3(1, 6, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(237.5f, -200, -625), scale: new Vector3(5, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-412.5f, -87.5f, -1250), scale: new Vector3(1, 4, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, 12.5f, -550), scale: new Vector3(8, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) + }; + } + + public override void Update(GameTime gameTime) + { + // TODO: actualizar el estado de todas las piezas móviles del nivel + + } + +} From 31bd72fd0c4e51e42588e24d1d570f42cfd6e9aa Mon Sep 17 00:00:00 2001 From: LColamonici Date: Sat, 1 Jun 2024 19:58:27 -0300 Subject: [PATCH 44/73] fuente de luz creada (falta tocar posicion y cantidad de luz) --- TGC.MonoGame.TP/Content/Effects/PBR.fx | 67 +++-- .../Content/Effects/PBR_4_luces.fx | 258 ++++++++++++++++++ .../MainCharacter/MainCharacter.cs | 9 +- 3 files changed, 297 insertions(+), 37 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/Effects/PBR_4_luces.fx diff --git a/TGC.MonoGame.TP/Content/Effects/PBR.fx b/TGC.MonoGame.TP/Content/Effects/PBR.fx index ac02ddafe..a70097dd1 100644 --- a/TGC.MonoGame.TP/Content/Effects/PBR.fx +++ b/TGC.MonoGame.TP/Content/Effects/PBR.fx @@ -36,6 +36,7 @@ sampler2D normalSampler = sampler_state }; //Textura para Metallic +//texture metallicTexture; texture metallicTexture; sampler2D metallicSampler = sampler_state { @@ -80,8 +81,8 @@ struct Light #define LIGHT_COUNT 4 -float3 lightPositions[4]; -float3 lightColors[4]; +float3 lightPosition; +float3 lightColor; float3 eyePosition; //Posicion de la camara @@ -201,38 +202,36 @@ float4 MainPS(VertexShaderOutput input) : COLOR // Reflectance equation float3 Lo = float3(0.0, 0.0, 0.0); - for (int index = 0; index < 4; index++) - { - float3 light = lightPositions[index] - input.WorldPosition.xyz; - float distance = length(light); - // Normalize our light vector after using its length - light = normalize(light); - float3 halfVector = normalize(view + light); - float attenuation = 1.0 / (distance); - float3 radiance = lightColors[index] * attenuation; - - - // Cook-Torrance BRDF - float NDF = DistributionGGX(normal, halfVector, roughness); - float G = GeometrySmith(normal, view, light, roughness); - float3 F = fresnelSchlick(max(dot(halfVector, view), 0.0), F0); - - float3 nominator = NDF * G * F; - float denominator = 4.0 * max(dot(normal, view), 0.0) + 0.001; - float3 specular = nominator / denominator; - - float3 kS = F; - - float3 kD = float3(1.0, 1.0, 1.0) - kS; - - kD *= 1.0 - metallic; - - // Scale light by NdotL - float NdotL = max(dot(normal, light), 0.0); - - //TODO - Lo += (kD * NdotL * albedo / PI + specular) * radiance; - } + float3 light = lightPosition - input.WorldPosition.xyz; + float distance = length(light); + // Normalize our light vector after using its length + light = normalize(light); + float3 halfVector = normalize(view + light); + float attenuation = 1.0 / (distance); + float3 radiance = lightColor * attenuation; + + + // Cook-Torrance BRDF + float NDF = DistributionGGX(normal, halfVector, roughness); + float G = GeometrySmith(normal, view, light, roughness); + float3 F = fresnelSchlick(max(dot(halfVector, view), 0.0), F0); + + float3 nominator = NDF * G * F; + float denominator = 4.0 * max(dot(normal, view), 0.0) + 0.001; + float3 specular = nominator / denominator; + + float3 kS = F; + + float3 kD = float3(1.0, 1.0, 1.0) - kS; + + kD *= 1.0 - metallic; + + // Scale light by NdotL + float NdotL = max(dot(normal, light), 0.0); + + //TODO + Lo += (kD * NdotL * albedo / PI + specular) * radiance; + float3 ambient = float3(0.03, 0.03, 0.03) * albedo * ao; diff --git a/TGC.MonoGame.TP/Content/Effects/PBR_4_luces.fx b/TGC.MonoGame.TP/Content/Effects/PBR_4_luces.fx new file mode 100644 index 000000000..ac02ddafe --- /dev/null +++ b/TGC.MonoGame.TP/Content/Effects/PBR_4_luces.fx @@ -0,0 +1,258 @@ +#if OPENGL + #define SV_POSITION POSITION + #define VS_SHADERMODEL vs_3_0 + #define PS_SHADERMODEL ps_3_0 +#else + #define VS_SHADERMODEL vs_4_0_level_9_1 + #define PS_SHADERMODEL ps_4_0_level_9_1 +#endif + +float4x4 matWorld; //Matriz de transformacion World +float4x4 matWorldViewProj; //Matriz World * View * Projection +float3x3 matInverseTransposeWorld; //Matriz Transpose(Invert(World)) + +//Textura para Albedo +texture albedoTexture; +sampler2D albedoSampler = sampler_state +{ + Texture = (albedoTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Normals +texture normalTexture; +sampler2D normalSampler = sampler_state +{ + Texture = (normalTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Metallic +texture metallicTexture; +sampler2D metallicSampler = sampler_state +{ + Texture = (metallicTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Roughness +texture roughnessTexture; +sampler2D roughnessSampler = sampler_state +{ + Texture = (roughnessTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Textura para Ambient Occlusion +texture aoTexture; +sampler2D aoSampler = sampler_state +{ + Texture = (aoTexture); + ADDRESSU = WRAP; + ADDRESSV = WRAP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; + MIPFILTER = LINEAR; +}; + +//Input del Vertex Shader +struct Light +{ + float3 Position; + float3 Color; +} ; + +#define LIGHT_COUNT 4 + +float3 lightPositions[4]; +float3 lightColors[4]; + +float3 eyePosition; //Posicion de la camara + +static const float PI = 3.14159265359; + +//Input del Vertex Shader +struct VertexShaderInput +{ + float4 Position : POSITION0; + float3 Normal : NORMAL0; + float2 TextureCoordinates : TEXCOORD0; +}; + +//Output del Vertex Shader +struct VertexShaderOutput +{ + float4 Position : POSITION0; + float2 TextureCoordinates : TEXCOORD0; + float3 WorldNormal : TEXCOORD1; + float4 WorldPosition : TEXCOORD2; +}; + +//Vertex Shader +VertexShaderOutput MainVS(VertexShaderInput input) +{ + VertexShaderOutput output; + + // Proyectamos la position + output.Position = mul(input.Position, matWorldViewProj); + + // Propagamos las coordenadas de textura + output.TextureCoordinates = input.TextureCoordinates; + + // Usamos la matriz normal para proyectar el vector normal + output.WorldNormal = mul(input.Normal, matInverseTransposeWorld); + + // Usamos la matriz de world para proyectar la posicion + output.WorldPosition = mul(input.Position, matWorld); + + return output; +} + +float3 getNormalFromMap(float2 textureCoordinates, float3 worldPosition, float3 worldNormal) +{ + float3 tangentNormal = tex2D(normalSampler, textureCoordinates).xyz * 2.0 - 1.0; + + float3 Q1 = ddx(worldPosition); + float3 Q2 = ddy(worldPosition); + float2 st1 = ddx(textureCoordinates); + float2 st2 = ddy(textureCoordinates); + + worldNormal = normalize(worldNormal.xyz); + float3 T = normalize(Q1 * st2.y - Q2 * st1.y); + float3 B = -normalize(cross(worldNormal, T)); + float3x3 TBN = float3x3(T, B, worldNormal); + + return normalize(mul(tangentNormal, TBN)); +} + +float DistributionGGX(float3 normal, float3 halfVector, float roughness) +{ + float a = roughness * roughness; + float a2 = a * a; + float NdotH = max(dot(normal, halfVector), 0.0); + float NdotH2 = NdotH * NdotH; + + float nom = a2; + float denom = (NdotH2 * (a2 - 1.0) + 1.0); + denom = PI * denom * denom; + + return nom / denom; +} + +float GeometrySchlickGGX(float NdotV, float roughness) +{ + float r = (roughness + 1.0); + float k = (r * r) / 8.0; + + float nom = NdotV; + float denom = NdotV * (1.0 - k) + k; + + return nom / denom; +} + +float GeometrySmith(float3 normal, float3 view, float3 light, float roughness) +{ + float NdotV = max(dot(normal, view), 0.0); + float NdotL = max(dot(normal, light), 0.0); + float ggx2 = GeometrySchlickGGX(NdotV, roughness); + float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} + +float3 fresnelSchlick(float cosTheta, float3 F0) +{ + return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); +} + +//Pixel Shader +float4 MainPS(VertexShaderOutput input) : COLOR +{ + float3 albedo = pow(tex2D(albedoSampler, input.TextureCoordinates).rgb, float3(2.2, 2.2, 2.2)); + float metallic = tex2D(metallicSampler, input.TextureCoordinates).r; + float roughness = tex2D(roughnessSampler, input.TextureCoordinates).r; + float ao = tex2D(aoSampler, input.TextureCoordinates).r; + + + + float3 worldNormal = input.WorldNormal; + float3 normal = getNormalFromMap(input.TextureCoordinates, input.WorldPosition.xyz, worldNormal); + float3 view = normalize(eyePosition - input.WorldPosition.xyz); + + float3 F0 = float3(0.04, 0.04, 0.04); + F0 = lerp(F0, albedo, metallic); + + // Reflectance equation + float3 Lo = float3(0.0, 0.0, 0.0); + + for (int index = 0; index < 4; index++) + { + float3 light = lightPositions[index] - input.WorldPosition.xyz; + float distance = length(light); + // Normalize our light vector after using its length + light = normalize(light); + float3 halfVector = normalize(view + light); + float attenuation = 1.0 / (distance); + float3 radiance = lightColors[index] * attenuation; + + + // Cook-Torrance BRDF + float NDF = DistributionGGX(normal, halfVector, roughness); + float G = GeometrySmith(normal, view, light, roughness); + float3 F = fresnelSchlick(max(dot(halfVector, view), 0.0), F0); + + float3 nominator = NDF * G * F; + float denominator = 4.0 * max(dot(normal, view), 0.0) + 0.001; + float3 specular = nominator / denominator; + + float3 kS = F; + + float3 kD = float3(1.0, 1.0, 1.0) - kS; + + kD *= 1.0 - metallic; + + // Scale light by NdotL + float NdotL = max(dot(normal, light), 0.0); + + //TODO + Lo += (kD * NdotL * albedo / PI + specular) * radiance; + } + + float3 ambient = float3(0.03, 0.03, 0.03) * albedo * ao; + + float3 color = ambient + Lo; + + // HDR tonemapping + color = color / (color + float3(1, 1, 1)); + + float exponent = 1.0 / 2.2; + // Gamma correct + color = pow(color, float3(exponent, exponent, exponent)); + + return float4(color, 1.0); +} + +technique PBR +{ + pass P0 + { + VertexShader = compile VS_SHADERMODEL MainVS(); + PixelShader = compile PS_SHADERMODEL MainPS(); + } +}; \ No newline at end of file diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 98b44e88b..071e19966 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -83,9 +83,11 @@ public void Update(GameTime gameTime) public void Draw(Matrix view, Matrix projection) { var worldView = WorldWithBallSpin * view; - Effect.Parameters["matWorld"].SetValue(World); + Effect.Parameters["matWorld"].SetValue(WorldWithBallSpin); Effect.Parameters["matWorldViewProj"].SetValue(worldView * projection); - Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(World))); + Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(WorldWithBallSpin))); + Effect.Parameters["lightPosition"].SetValue(new Vector3(25, 80, -800)); + Effect.Parameters["lightColor"].SetValue(new Vector3(253, 251, 211)); //Game.Gizmos.DrawSphere(World, Vector3.One*20, Color.Red); @@ -223,7 +225,8 @@ private void ProcessMovement(GameTime gameTime) BallSpinAngle += Velocity.Length()*elapsedTime / (MathHelper.Pi*12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); - if(Acceleration==Vector3.Zero && Velocity!=Vector3.Zero) Velocity *= (1-elapsedTime); + //if(Acceleration==Vector3.Zero && Velocity!=Vector3.Zero) Velocity *= (1-(elapsedTime/2)); + if(Acceleration==Vector3.Zero || Vector3.Dot(Acceleration, Velocity)<0) Velocity *= (1-(elapsedTime)); if(Velocity==Vector3.Zero) BallSpinAxis = Vector3.UnitZ; Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); From 0e49c7d3cfe381903ee22c6c278275b3a4a0836c Mon Sep 17 00:00:00 2001 From: LColamonici Date: Tue, 4 Jun 2024 23:35:16 -0300 Subject: [PATCH 45/73] corregida iluminacion y algunas texturas, agregado movimiento de camara con mouse --- TGC.MonoGame.TP/Camera/FollowCamera.cs | 33 ++++++++++++++-- TGC.MonoGame.TP/Content/Effects/PBR.fx | 4 +- .../materials/gold but wood/ao jpg.jpg | 3 ++ .../Textures/materials/gold but wood/ao.png | 3 ++ .../materials/gold but wood/color.jpg | 3 ++ .../materials/gold but wood/displacement.jpg | 3 ++ .../materials/gold but wood/metalness.jpg | 3 ++ .../materials/gold but wood/normal.jpg | 3 ++ .../materials/gold but wood/roughness.jpg | 3 ++ .../Textures/materials/gold/ao vieja.png | 3 ++ .../Content/Textures/materials/gold/ao.png | 4 +- .../Textures/materials/marble original/ao.png | 3 ++ .../materials/marble original/color.jpg | 3 ++ .../marble original/displacement.jpg | 3 ++ .../materials/marble original/metalness.jpg | 3 ++ .../materials/marble original/normal.jpg | 3 ++ .../materials/marble original/roughness.jpg | 3 ++ .../Textures/materials/marble/ao jpg.jpg | 3 ++ .../Content/Textures/materials/marble/ao.png | 4 +- .../Textures/materials/marble/color.jpg | 4 +- .../materials/marble/displacement png.png | 3 ++ .../materials/marble/displacement.jpg | 4 +- .../Textures/materials/marble/normal.jpg | 4 +- .../Textures/materials/marble/roughness.jpg | 4 +- .../MainCharacter/MainCharacter.cs | 39 +++++++++++++++---- TGC.MonoGame.TP/Stages/Stage.cs | 15 ++++++- TGC.MonoGame.TP/TGCGame.cs | 8 +++- 27 files changed, 143 insertions(+), 28 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao jpg.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold but wood/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/gold/ao vieja.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/ao.png create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/color.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/displacement.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/metalness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/normal.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble original/roughness.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/ao jpg.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/materials/marble/displacement png.png diff --git a/TGC.MonoGame.TP/Camera/FollowCamera.cs b/TGC.MonoGame.TP/Camera/FollowCamera.cs index 007f6347d..90e42bf14 100644 --- a/TGC.MonoGame.TP/Camera/FollowCamera.cs +++ b/TGC.MonoGame.TP/Camera/FollowCamera.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Graphics; namespace TGC.MonoGame.TP { @@ -10,7 +12,7 @@ namespace TGC.MonoGame.TP /// class FollowCamera { - private const float AxisDistanceToTarget = 20f; + private const float AxisDistanceToTarget = 5f; private const float AngleFollowSpeed = 0.03f; @@ -25,7 +27,7 @@ class FollowCamera private float BackwardVectorInterpolator { get; set; } = 0f; private Vector3 PastBackwardVector { get; set; } = Vector3.Forward; - + //private Effect ballEffect; /// /// Crea una FollowCamera que sigue a una matriz de mundo /// @@ -34,7 +36,7 @@ public FollowCamera(float aspectRatio) { // Orthographic camera // Projection = Matrix.CreateOrthographic(screenWidth, screenHeight, 0.01f, 10000f); - + //ballEffect = Content.Load(ContentFolderEffects + "PBR"); // Perspective camera // Uso 60° como FOV, aspect ratio, pongo las distancias a near plane y far plane en 0.1 y 100000 (mucho) respectivamente Projection = Matrix.CreatePerspectiveFieldOfView(MathF.PI / 3f, aspectRatio, 0.1f, 100000f); @@ -45,11 +47,33 @@ public FollowCamera(float aspectRatio) /// /// The Game Time to calculate framerate-independent movement /// The World matrix to follow + + private Vector2 pastMousePosition=Vector2.Zero; + private float MouseSensitivity=0.3f; + public Vector3 CamPosition; + public void Update(GameTime gameTime, Matrix followedWorld) { // Obtengo el tiempo var elapsedTime = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); + var mouseState = Mouse.GetState(); + + if (mouseState.RightButton.Equals(ButtonState.Pressed)) + { + var mouseDelta = mouseState.Position.ToVector2() - pastMousePosition; + mouseDelta *= MouseSensitivity * elapsedTime; + followedWorld=Matrix.CreateRotationY(mouseDelta.X) * followedWorld; + //var size = GraphicsDevice.Viewport.Bounds.Size; + //Mouse.SetPosition(screenCenter.X, screenCenter.Y); + //Mouse.SetCursor(MouseCursor.Crosshair); + } + + else + { + Mouse.SetCursor(MouseCursor.Arrow); + } + // Obtengo la posicion de la matriz de mundo que estoy siguiendo var followedPosition = followedWorld.Translation; @@ -106,7 +130,10 @@ public void Update(GameTime gameTime, Matrix followedWorld) // Calculo la matriz de Vista de la camara usando la Posicion, La Posicion a donde esta mirando, // y su vector Arriba + CamPosition=offsetedPosition; + View = Matrix.CreateLookAt(offsetedPosition, followedPosition, cameraCorrectUp); + } } } diff --git a/TGC.MonoGame.TP/Content/Effects/PBR.fx b/TGC.MonoGame.TP/Content/Effects/PBR.fx index a70097dd1..ca2914c30 100644 --- a/TGC.MonoGame.TP/Content/Effects/PBR.fx +++ b/TGC.MonoGame.TP/Content/Effects/PBR.fx @@ -202,12 +202,12 @@ float4 MainPS(VertexShaderOutput input) : COLOR // Reflectance equation float3 Lo = float3(0.0, 0.0, 0.0); - float3 light = lightPosition - input.WorldPosition.xyz; + float3 light = (lightPosition - input.WorldPosition.xyz); float distance = length(light); // Normalize our light vector after using its length light = normalize(light); float3 halfVector = normalize(view + light); - float attenuation = 1.0 / (distance); + float attenuation = 1.0 / (distance); //cambiar para bajar o subir atenuacion float3 radiance = lightColor * attenuation; diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao jpg.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao jpg.jpg new file mode 100644 index 000000000..43fb0d745 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao jpg.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0615e3b4f9be53a96174a9292898c8f955ca54669715b0253cfec17f36cbd3b +size 327951 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao.png new file mode 100644 index 000000000..fed477561 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4547a5568ccfc486a9ef8ae8538c73eaef38b4cfd93dbbdedff61d583285edf6 +size 745475 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/color.jpg new file mode 100644 index 000000000..48ab43f9c --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2b30158fc4971324701bd82149a0ad6e3c5f5b3abb528ebf6bc8afa7d4750db +size 210128 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/displacement.jpg new file mode 100644 index 000000000..ce45230ac --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8dd811bc31d73a0b414997b776a971d2985bf2e200f4dd2feeec557f3b510d8 +size 67549 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/metalness.jpg new file mode 100644 index 000000000..a9837c364 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:701e25ba73adcd45a90c701fa66e4b1d0916577de163ea906cfdb14f9a1ecb59 +size 735 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/normal.jpg new file mode 100644 index 000000000..45863002c --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2d0fd8637a51e7ea9b3de5529e81c0de3e888998b09059130a037ffb7f234dc +size 74307 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/roughness.jpg new file mode 100644 index 000000000..da0f5f71f --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold but wood/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1580e852e37c321c9a949a49815c88b97fe7c0d68582cb9a8d8027ef7b72695 +size 208046 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/ao vieja.png b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao vieja.png new file mode 100644 index 000000000..da83020f2 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao vieja.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de8724d7a74f84750b643d16e9ae9fdf911cc71c9ab37b7f5df9b57c1a4470e9 +size 151 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png index da83020f2..6ccab8738 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png +++ b/TGC.MonoGame.TP/Content/Textures/materials/gold/ao.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:de8724d7a74f84750b643d16e9ae9fdf911cc71c9ab37b7f5df9b57c1a4470e9 -size 151 +oid sha256:28deb373cfdf115f8fa538a6e1993f02f412dd7d99fc7cba7f5a2efdd2b94531 +size 468138 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/marble original/ao.png new file mode 100644 index 000000000..e3542ec8a --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/ao.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11fdc43f6316601b8bbabf8c4706dc04972920bb293c0d706d1f9981dd6107f3 +size 157 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble original/color.jpg new file mode 100644 index 000000000..67306298e --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/color.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d608a8eabeba10aefabb6e8be3eb0bbc49090fb799b75fa6e231fcbdee55fc8 +size 4756197 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble original/displacement.jpg new file mode 100644 index 000000000..08e821917 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/displacement.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:315f39976d6248eb1bb8e5ad899e42f17e6653655c6c25901eb0317811f9d1a0 +size 3268121 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/metalness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble original/metalness.jpg new file mode 100644 index 000000000..a9837c364 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/metalness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:701e25ba73adcd45a90c701fa66e4b1d0916577de163ea906cfdb14f9a1ecb59 +size 735 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble original/normal.jpg new file mode 100644 index 000000000..31959cf9c --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/normal.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72121aa2409c314fe2036dfda99e9b2ea88514e2b07507c20aa527da693643a8 +size 1367869 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble original/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble original/roughness.jpg new file mode 100644 index 000000000..415d96239 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble original/roughness.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72bc83992be6ad0c0838be9b26e466ea8b2348dd5c7d7be8c4ff9dfc50695855 +size 2274425 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/ao jpg.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao jpg.jpg new file mode 100644 index 000000000..8aec2ba6f --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao jpg.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2fcff03a4594777fac47d501e9cb06f079cb6c489cfa1f3c2ddd3bd7345d1caf +size 170667 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png index e3542ec8a..6ef176e62 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/ao.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11fdc43f6316601b8bbabf8c4706dc04972920bb293c0d706d1f9981dd6107f3 -size 157 +oid sha256:c27ecff0b54a247128887571663c49d076d0009d4c7ea625a8e47d3757fd03fd +size 447102 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg index 67306298e..9aa17966c 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/color.jpg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d608a8eabeba10aefabb6e8be3eb0bbc49090fb799b75fa6e231fcbdee55fc8 -size 4756197 +oid sha256:aeadf981438f953eb523db21ae8cf19f06cd4d0fe7ded3341d9a44881a7b334e +size 139092 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement png.png b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement png.png new file mode 100644 index 000000000..de55231c3 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement png.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:673d7b8df5e49367318d0fc1ff33cc27e2b47d2c87341ee8a517ed739f6b6576 +size 1400426 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg index 08e821917..98253790d 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/displacement.jpg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:315f39976d6248eb1bb8e5ad899e42f17e6653655c6c25901eb0317811f9d1a0 -size 3268121 +oid sha256:fc83a2e557a10ccf7641c98db48a11936d8ca9d4b793083d8f8a5128140d12e3 +size 43435 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg index 31959cf9c..86e70dc37 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/normal.jpg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:72121aa2409c314fe2036dfda99e9b2ea88514e2b07507c20aa527da693643a8 -size 1367869 +oid sha256:4f6904f57d2023196df160c30746b53bfc61177f8f82d291c6e5ba4bc9fa7f9d +size 9760 diff --git a/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg b/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg index 415d96239..0b7e18ed8 100644 --- a/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg +++ b/TGC.MonoGame.TP/Content/Textures/materials/marble/roughness.jpg @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:72bc83992be6ad0c0838be9b26e466ea8b2348dd5c7d7be8c4ff9dfc50695855 -size 2274425 +oid sha256:bc6895b2518c6e9e29378c2c9d9b002496d526fdaacd15c17f343fb7ecfe4aa5 +size 12619 diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 071e19966..1c96c3949 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using TGC.MonoGame.TP.Camera; namespace TGC.MonoGame.TP.MainCharacter { @@ -34,20 +35,24 @@ public class Character Vector3 BallSpinAxis=Vector3.UnitX; float BallSpinAngle=0f; Matrix WorldWithBallSpin; - float BallPitch=0f; - float BallRoll=0f; - + //float BallPitch=0f; + //float BallRoll=0f; + Vector3 LightPos{get;set;} + public Matrix Spin;// public Character(ContentManager content, Vector3 initialPosition) { Content = content; - + Spin= Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); InitializeEffect(); InitializeSphere(initialPosition); InitializeTextures(); + InitializeLight(); + } + void InitializeLight(){ + LightPos=Position+ new Vector3(0,10,0); } - private void InitializeSphere(Vector3 initialPosition) { @@ -86,11 +91,13 @@ public void Draw(Matrix view, Matrix projection) Effect.Parameters["matWorld"].SetValue(WorldWithBallSpin); Effect.Parameters["matWorldViewProj"].SetValue(worldView * projection); Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(WorldWithBallSpin))); - Effect.Parameters["lightPosition"].SetValue(new Vector3(25, 80, -800)); + //Effect.Parameters["lightPosition"].SetValue(new Vector3(25, 180, -800)); + //Effect.Parameters["lightPosition"].SetValue(Position + new Vector3(0, 60, 0)); + Effect.Parameters["lightPosition"].SetValue(LightPos); Effect.Parameters["lightColor"].SetValue(new Vector3(253, 251, 211)); //Game.Gizmos.DrawSphere(World, Vector3.One*20, Color.Red); - + Sphere.Meshes.FirstOrDefault().Draw(); } @@ -111,6 +118,8 @@ private void LoadTextures() Effect.Parameters["aoTexture"]?.SetValue(ao); } + + private void ProcessMaterialChange() { var keyboardState = Keyboard.GetState(); @@ -142,6 +151,7 @@ private void ProcessMaterialChange() { CurrentMaterial = NewMaterial; SwitchMaterial(); + LoadTextures(); } } @@ -182,11 +192,15 @@ private void SwitchMaterial() LoadTextures(); } + private Vector2 pastMousePosition=Vector2.Zero; + private float MouseSensitivity=0.3f; private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + + var directionX = new Vector3(); var directionY = new Vector3(); var directionZ = new Vector3(); @@ -224,6 +238,11 @@ private void ProcessMovement(GameTime gameTime) BallSpinAngle += Velocity.Length()*elapsedTime / (MathHelper.Pi*12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); + //DeltaX+=elapsedTime*Velocity.X/MathHelper.TwoPi; + //DeltaZ+=elapsedTime*Velocity.Z/MathHelper.TwoPi; + //Spin*=Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle); + //BallSpinAxis.X=Math.Abs(BallSpinAxis.X); + //BallSpinAxis.Z=Math.Abs(BallSpinAxis.Z); //if(Acceleration==Vector3.Zero && Velocity!=Vector3.Zero) Velocity *= (1-(elapsedTime/2)); if(Acceleration==Vector3.Zero || Vector3.Dot(Acceleration, Velocity)<0) Velocity *= (1-(elapsedTime)); @@ -251,15 +270,19 @@ private void ProcessMovement(GameTime gameTime) Velocity += (Acceleration + gravity) * elapsedTime; Position += (directionX + directionY + directionZ) * Velocity * elapsedTime * 0.5f; + MoveTo(Position); Acceleration = Vector3.Zero; } - + //float DeltaX, DeltaZ; public void MoveTo(Vector3 position) { World = Scale * Matrix.CreateTranslation(position); WorldWithBallSpin=Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle) * World; + LightPos=Position+ new Vector3(0,30,-30); + + //WorldWithBallSpin=Matrix.CreateRotationX(DeltaX) * Matrix.CreateRotationZ(DeltaZ) * World; } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index 06474214e..a20a9eec9 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -21,7 +21,13 @@ abstract class Stage protected List Checkpoints; // puntos de respawn public Vector3 CharacterInitialPosition; - + //private SpriteBatch SpriteBatch; + + public void LoadSpriteBatch(){ + //SpriteBatch=new SpriteBatch(GraphicsDevice); + //SpriteBatch.Begin(); + + } public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { GraphicsDevice = graphicsDevice; @@ -34,11 +40,13 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char LoadSigns(); LoadPickups(); LoadCheckpoints(); + LoadSpriteBatch(); } public abstract void Update(GameTime gameTime); - + private SpriteFont SpriteFont { get; set; } + public void Draw(Matrix view, Matrix projection) { foreach (GeometricPrimitive primitive in Track) @@ -60,6 +68,9 @@ public void Draw(Matrix view, Matrix projection) { pickup.Draw(view, projection); } + + //SpriteBatch.DrawString(SpriteFont, "Launch spheres with the 'Z' key.", new Vector2(GraphicsDevice.Viewport.Width - 500, 25), Color.White); + } abstract protected void LoadTrack(); diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index e7811f134..a6788a3ed 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -82,21 +82,25 @@ protected override void Initialize() base.Initialize(); } - + private SpriteFont SpriteFont{get;set;} /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo, despues de Initialize. /// Escribir aqui el codigo de inicializacion: cargar modelos, texturas, estructuras de optimizacion, el procesamiento /// que podemos pre calcular para nuestro juego. /// + public Effect BallEffect; protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. SpriteBatch = new SpriteBatch(GraphicsDevice); + Stage = new Stage_01(GraphicsDevice, Content); MainCharacter = new Character(Content, Stage.CharacterInitialPosition); + BallEffect = Content.Load(ContentFolderEffects + "PBR"); + base.LoadContent(); } @@ -115,7 +119,9 @@ protected override void Update(GameTime gameTime) MainCharacter.Update(gameTime); + FollowCamera.Update(gameTime, MainCharacter.World); + BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); base.Update(gameTime); } From 6feda2c47a569bbd56e14c33f5a9700ddaba7b7b Mon Sep 17 00:00:00 2001 From: LColamonici Date: Sat, 15 Jun 2024 13:52:01 -0300 Subject: [PATCH 46/73] camara funcionando y cambiando direccion de la pelota, falta skybox --- TGC.MonoGame.TP/Camera/FollowCamera.cs | 23 +++++++++++++++---- .../MainCharacter/MainCharacter.cs | 18 +++++++++++---- TGC.MonoGame.TP/TGCGame.cs | 8 +++++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/TGC.MonoGame.TP/Camera/FollowCamera.cs b/TGC.MonoGame.TP/Camera/FollowCamera.cs index 90e42bf14..48a6bd0d4 100644 --- a/TGC.MonoGame.TP/Camera/FollowCamera.cs +++ b/TGC.MonoGame.TP/Camera/FollowCamera.cs @@ -32,8 +32,10 @@ class FollowCamera /// Crea una FollowCamera que sigue a una matriz de mundo /// /// - public FollowCamera(float aspectRatio) + public Point ScreenCenter; + public FollowCamera(float aspectRatio, Point HalfSize) { + ScreenCenter=HalfSize; // Orthographic camera // Projection = Matrix.CreateOrthographic(screenWidth, screenHeight, 0.01f, 10000f); //ballEffect = Content.Load(ContentFolderEffects + "PBR"); @@ -51,6 +53,8 @@ public FollowCamera(float aspectRatio) private Vector2 pastMousePosition=Vector2.Zero; private float MouseSensitivity=0.3f; public Vector3 CamPosition; + public float CamRotation=0; + public bool camMoving=false; public void Update(GameTime gameTime, Matrix followedWorld) { @@ -61,17 +65,28 @@ public void Update(GameTime gameTime, Matrix followedWorld) if (mouseState.RightButton.Equals(ButtonState.Pressed)) { - var mouseDelta = mouseState.Position.ToVector2() - pastMousePosition; + if(!camMoving) + { + Mouse.SetPosition(0, ScreenCenter.Y); + camMoving=true; + } + var mouseDelta = mouseState.Position.ToVector2(); mouseDelta *= MouseSensitivity * elapsedTime; - followedWorld=Matrix.CreateRotationY(mouseDelta.X) * followedWorld; + CamRotation+=mouseDelta.X; + followedWorld=Matrix.CreateRotationY(CamRotation) * followedWorld; //var size = GraphicsDevice.Viewport.Bounds.Size; //Mouse.SetPosition(screenCenter.X, screenCenter.Y); //Mouse.SetCursor(MouseCursor.Crosshair); + Mouse.SetPosition(0, ScreenCenter.Y); + Mouse.SetCursor(MouseCursor.Crosshair); + pastMousePosition=mouseState.Position.ToVector2(); } else { Mouse.SetCursor(MouseCursor.Arrow); + camMoving=false; + //Mouse.SetPosition(ScreenCenter.X, ScreenCenter.Y); } // Obtengo la posicion de la matriz de mundo que estoy siguiendo @@ -95,7 +110,7 @@ public void Update(GameTime gameTime, Matrix followedWorld) // Esto mueve el vector Backward para igualar al vector Backward que sigo // En este caso uso la curva x^2 para hacerlo mas suave // Interpolator se convertira en 1 eventualmente - CurrentBackwardVector = Vector3.Lerp(CurrentBackwardVector, followedBackward, BackwardVectorInterpolator * BackwardVectorInterpolator); + CurrentBackwardVector = Vector3.Lerp(CurrentBackwardVector, followedBackward, BackwardVectorInterpolator ); } else // Si el angulo no pasa de cierto limite, lo pongo de nuevo en cero diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 1c96c3949..ff9dbe1f2 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Runtime.Intrinsics.Arm; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -38,6 +39,10 @@ public class Character //float BallPitch=0f; //float BallRoll=0f; + public Vector3 ForwardVector=Vector3.UnitX; + + public Vector3 RightVector=Vector3.UnitZ; + Vector3 LightPos{get;set;} public Matrix Spin;// public Character(ContentManager content, Vector3 initialPosition) @@ -194,6 +199,11 @@ private void SwitchMaterial() private Vector2 pastMousePosition=Vector2.Zero; private float MouseSensitivity=0.3f; + + public void ChangeDirection(float angle){ + ForwardVector = Vector3.Transform(Vector3.UnitX, Matrix.CreateRotationY(angle)); + RightVector = Vector3.Transform(Vector3.UnitZ, Matrix.CreateRotationY(angle)); + } private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. @@ -211,19 +221,19 @@ private void ProcessMovement(GameTime gameTime) var keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { - Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation); + Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation); //amtes unitx } if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { - Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation) * (- 1); + Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation) * (- 1); } if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { - Acceleration += Vector3.Transform(Vector3.UnitZ * speed, Rotation); + Acceleration += Vector3.Transform(RightVector * speed, Rotation); //antes unitz } if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { - Acceleration += Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); + Acceleration += Vector3.Transform(RightVector * speed, Rotation) * (-1); } if(Keyboard.GetState().IsKeyDown(Keys.Space) && Velocity.Y == 0f) { diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 5db45c924..63bba3844 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -56,18 +56,20 @@ public TGCGame() /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. /// Escribir aqui el codigo de inicializacion: el procesamiento que podemos pre calcular para nuestro juego. /// + public Point screenSize; protected override void Initialize() { var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; + screenSize=size; //var cameraPosition = new Vector3(25f, 100f, -1100f); //Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); // Creo una camaar para seguir a nuestro auto. - FollowCamera = new FollowCamera(GraphicsDevice.Viewport.AspectRatio); + FollowCamera = new FollowCamera(GraphicsDevice.Viewport.AspectRatio, size); // La logica de inicializacion que no depende del contenido se recomienda poner en este metodo. @@ -122,10 +124,12 @@ protected override void Update(GameTime gameTime) FollowCamera.Update(gameTime, MainCharacter.World); + + MainCharacter.ChangeDirection(FollowCamera.CamRotation); BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); - World = Matrix.CreateRotationY(Rotation); + //World = Matrix.CreateRotationY(Rotation); base.Update(gameTime); } From 03373772d918ca23b2236aa82df4678dec7401c8 Mon Sep 17 00:00:00 2001 From: LColamonici Date: Fri, 21 Jun 2024 14:59:18 -0300 Subject: [PATCH 47/73] implementacion skybox (falta) --- TGC.MonoGame.TP/Camera/FollowCamera.cs | 15 ++- TGC.MonoGame.TP/Content/3D/skybox/cube.fbx | 3 + TGC.MonoGame.TP/Content/Content.mgcb | 123 +++++++++++------- TGC.MonoGame.TP/Content/Effects/SkyBox.fx | 64 +++++++++ TGC.MonoGame.TP/Content/Models/cube.fbx | 3 + .../Content/Models/skybox/cube.fbx | 3 + .../Content/Textures/skybox/skyboxTexture.jpg | 3 + .../skyboxes/empty-space/empty-space.dds | 3 + .../Textures/skyboxes/islands/islands.dds | 3 + .../Textures/skyboxes/skybox/skybox.dds | 3 + .../skyboxes/sun-in-space/sun-in-space.dds | 3 + .../Textures/skyboxes/sunset/sunset.dds | 3 + .../MainCharacter/MainCharacter.cs | 4 +- TGC.MonoGame.TP/SkyBox/SkyBox.cs | 95 ++++++++++++++ TGC.MonoGame.TP/Stages/Stage.cs | 24 ++++ TGC.MonoGame.TP/Stages/Stage_01.cs | 4 +- TGC.MonoGame.TP/TGCGame.cs | 26 +++- 17 files changed, 324 insertions(+), 58 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/3D/skybox/cube.fbx create mode 100644 TGC.MonoGame.TP/Content/Effects/SkyBox.fx create mode 100644 TGC.MonoGame.TP/Content/Models/cube.fbx create mode 100644 TGC.MonoGame.TP/Content/Models/skybox/cube.fbx create mode 100644 TGC.MonoGame.TP/Content/Textures/skybox/skyboxTexture.jpg create mode 100644 TGC.MonoGame.TP/Content/Textures/skyboxes/empty-space/empty-space.dds create mode 100644 TGC.MonoGame.TP/Content/Textures/skyboxes/islands/islands.dds create mode 100644 TGC.MonoGame.TP/Content/Textures/skyboxes/skybox/skybox.dds create mode 100644 TGC.MonoGame.TP/Content/Textures/skyboxes/sun-in-space/sun-in-space.dds create mode 100644 TGC.MonoGame.TP/Content/Textures/skyboxes/sunset/sunset.dds create mode 100644 TGC.MonoGame.TP/SkyBox/SkyBox.cs diff --git a/TGC.MonoGame.TP/Camera/FollowCamera.cs b/TGC.MonoGame.TP/Camera/FollowCamera.cs index 48a6bd0d4..6f8040764 100644 --- a/TGC.MonoGame.TP/Camera/FollowCamera.cs +++ b/TGC.MonoGame.TP/Camera/FollowCamera.cs @@ -63,16 +63,18 @@ public void Update(GameTime gameTime, Matrix followedWorld) var mouseState = Mouse.GetState(); - if (mouseState.RightButton.Equals(ButtonState.Pressed)) + if (true) { + var mouseDelta = mouseState.Position.ToVector2(); if(!camMoving) { - Mouse.SetPosition(0, ScreenCenter.Y); + Mouse.SetPosition(ScreenCenter.X, ScreenCenter.Y); + mouseDelta = new Vector2(0, ScreenCenter.Y); camMoving=true; } - var mouseDelta = mouseState.Position.ToVector2(); + mouseDelta *= MouseSensitivity * elapsedTime; - CamRotation+=mouseDelta.X; + CamRotation-=mouseDelta.X; followedWorld=Matrix.CreateRotationY(CamRotation) * followedWorld; //var size = GraphicsDevice.Viewport.Bounds.Size; //Mouse.SetPosition(screenCenter.X, screenCenter.Y); @@ -82,12 +84,13 @@ public void Update(GameTime gameTime, Matrix followedWorld) pastMousePosition=mouseState.Position.ToVector2(); } - else + /*else { Mouse.SetCursor(MouseCursor.Arrow); camMoving=false; + CamRotation=0; //Mouse.SetPosition(ScreenCenter.X, ScreenCenter.Y); - } + }*/ // Obtengo la posicion de la matriz de mundo que estoy siguiendo var followedPosition = followedWorld.Translation; diff --git a/TGC.MonoGame.TP/Content/3D/skybox/cube.fbx b/TGC.MonoGame.TP/Content/3D/skybox/cube.fbx new file mode 100644 index 000000000..a2de74f05 --- /dev/null +++ b/TGC.MonoGame.TP/Content/3D/skybox/cube.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd80f2f0d3ded3a1dccd83450fe771f19697436e342ed9fc3b0a8797a5c9dc1c +size 10535 diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 63f93d2ef..3f8b914fc 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -57,12 +57,24 @@ /processorParam:DebugMode=Auto /build:Effects/BasicShader.fx +#begin Effects/PBR_4_luces.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:Effects/PBR_4_luces.fx + #begin Effects/PBR.fx /importer:EffectImporter /processor:EffectProcessor /processorParam:DebugMode=Auto /build:Effects/PBR.fx +#begin Effects/SkyBox.fx +/importer:EffectImporter +/processor:EffectProcessor +/processorParam:DebugMode=Auto +/build:Effects/SkyBox.fx + #begin Models/sign/Sign.png /importer:TextureImporter /processor:TextureProcessor @@ -94,6 +106,25 @@ /processorParam:TextureFormat=Compressed /build:Models/sign/StreetSign.fbx +#begin Models/skybox/cube.fbx +/importer:FbxImporter +/processor:ModelProcessor +/processorParam:ColorKeyColor=0,0,0,0 +/processorParam:ColorKeyEnabled=True +/processorParam:DefaultEffect=BasicEffect +/processorParam:GenerateMipmaps=True +/processorParam:GenerateTangentFrames=False +/processorParam:PremultiplyTextureAlpha=True +/processorParam:PremultiplyVertexColors=True +/processorParam:ResizeTexturesToPowerOfTwo=False +/processorParam:RotationX=0 +/processorParam:RotationY=0 +/processorParam:RotationZ=0 +/processorParam:Scale=1 +/processorParam:SwapWindingOrder=False +/processorParam:TextureFormat=Compressed +/build:Models/skybox/cube.fbx + #begin Models/tgc-logo/tgc-logo.fbx /importer:FbxImporter /processor:ModelProcessor @@ -281,7 +312,7 @@ /processorParam:TextureFormat=Color /build:Textures/materials/harsh-metal/ao.png -#begin Textures/materials/harsh-metal/ao.png +#begin Textures/materials/harsh-metal/color.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -291,9 +322,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/ao.png +/build:Textures/materials/harsh-metal/color.jpg -#begin Textures/materials/harsh-metal/color.jpg +#begin Textures/materials/harsh-metal/displacement.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -303,9 +334,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/color.jpg +/build:Textures/materials/harsh-metal/displacement.jpg -#begin Textures/materials/harsh-metal/color.jpg +#begin Textures/materials/harsh-metal/metalness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -315,9 +346,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/color.jpg +/build:Textures/materials/harsh-metal/metalness.jpg -#begin Textures/materials/harsh-metal/displacement.jpg +#begin Textures/materials/harsh-metal/normal.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -327,9 +358,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/displacement.jpg +/build:Textures/materials/harsh-metal/normal.jpg -#begin Textures/materials/harsh-metal/displacement.jpg +#begin Textures/materials/harsh-metal/roughness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -339,9 +370,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/displacement.jpg +/build:Textures/materials/harsh-metal/roughness.jpg -#begin Textures/materials/harsh-metal/metalness.jpg +#begin Textures/materials/marble/ao.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -351,9 +382,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/metalness.jpg +/build:Textures/materials/marble/ao.png -#begin Textures/materials/harsh-metal/metalness.jpg +#begin Textures/materials/marble/color.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -363,9 +394,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/metalness.jpg +/build:Textures/materials/marble/color.jpg -#begin Textures/materials/harsh-metal/normal.jpg +#begin Textures/materials/marble/displacement.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -375,9 +406,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/normal.jpg +/build:Textures/materials/marble/displacement.jpg -#begin Textures/materials/harsh-metal/normal.jpg +#begin Textures/materials/marble/metalness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -387,9 +418,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/normal.jpg +/build:Textures/materials/marble/metalness.jpg -#begin Textures/materials/harsh-metal/roughness.jpg +#begin Textures/materials/marble/normal.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -399,9 +430,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/roughness.jpg +/build:Textures/materials/marble/normal.jpg -#begin Textures/materials/harsh-metal/roughness.jpg +#begin Textures/materials/marble/roughness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -411,9 +442,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/harsh-metal/roughness.jpg +/build:Textures/materials/marble/roughness.jpg -#begin Textures/materials/marble/ao.png +#begin Textures/materials/metal/ao.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -423,9 +454,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/ao.png +/build:Textures/materials/metal/ao.png -#begin Textures/materials/marble/color.jpg +#begin Textures/materials/metal/color.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -435,9 +466,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/color.jpg +/build:Textures/materials/metal/color.jpg -#begin Textures/materials/marble/displacement.jpg +#begin Textures/materials/metal/displacement.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -447,9 +478,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/displacement.jpg +/build:Textures/materials/metal/displacement.jpg -#begin Textures/materials/marble/metalness.jpg +#begin Textures/materials/metal/metalness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -459,9 +490,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/metalness.jpg +/build:Textures/materials/metal/metalness.jpg -#begin Textures/materials/marble/normal.jpg +#begin Textures/materials/metal/normal.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -471,9 +502,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/normal.jpg +/build:Textures/materials/metal/normal.jpg -#begin Textures/materials/marble/roughness.jpg +#begin Textures/materials/metal/roughness.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -483,9 +514,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/marble/roughness.jpg +/build:Textures/materials/metal/roughness.jpg -#begin Textures/materials/metal/ao.png +#begin Textures/skybox/skyboxTexture.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -495,9 +526,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/ao.png +/build:Textures/skybox/skyboxTexture.jpg -#begin Textures/materials/metal/color.jpg +#begin Textures/skyboxes/empty-space/empty-space.dds /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -507,9 +538,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/color.jpg +/build:Textures/skyboxes/empty-space/empty-space.dds -#begin Textures/materials/metal/displacement.jpg +#begin Textures/skyboxes/islands/islands.dds /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -519,9 +550,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/displacement.jpg +/build:Textures/skyboxes/islands/islands.dds -#begin Textures/materials/metal/metalness.jpg +#begin Textures/skyboxes/skybox/skybox.dds /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -531,9 +562,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/metalness.jpg +/build:Textures/skyboxes/skybox/skybox.dds -#begin Textures/materials/metal/normal.jpg +#begin Textures/skyboxes/sun-in-space/sun-in-space.dds /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -543,9 +574,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/normal.jpg +/build:Textures/skyboxes/sun-in-space/sun-in-space.dds -#begin Textures/materials/metal/roughness.jpg +#begin Textures/skyboxes/sunset/sunset.dds /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -555,5 +586,5 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/materials/metal/roughness.jpg +/build:Textures/skyboxes/sunset/sunset.dds diff --git a/TGC.MonoGame.TP/Content/Effects/SkyBox.fx b/TGC.MonoGame.TP/Content/Effects/SkyBox.fx new file mode 100644 index 000000000..8de80d375 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Effects/SkyBox.fx @@ -0,0 +1,64 @@ +#if OPENGL +#define SV_POSITION POSITION +#define VS_SHADERMODEL vs_3_0 +#define PS_SHADERMODEL ps_3_0 +#else +#define VS_SHADERMODEL vs_4_0_level_9_1 +#define PS_SHADERMODEL ps_4_0_level_9_1 +#endif + +float4x4 World; +float4x4 View; +float4x4 Projection; + +float3 CameraPosition; + +texture SkyBoxTexture; +samplerCUBE SkyBoxSampler = sampler_state +{ + texture = ; + magfilter = LINEAR; + minfilter = LINEAR; + mipfilter = LINEAR; + AddressU = Mirror; + AddressV = Mirror; +}; + +struct VertexShaderInput +{ + float4 Position : POSITION0; +}; + +struct VertexShaderOutput +{ + float4 Position : POSITION0; + float3 TextureCoordinate : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(VertexShaderInput input) +{ + VertexShaderOutput output; + + float4 worldPosition = mul(input.Position, World); + float4 viewPosition = mul(worldPosition, View); + output.Position = mul(viewPosition, Projection); + + float4 VertexPosition = mul(input.Position, World); + output.TextureCoordinate = VertexPosition.xyz - CameraPosition; + + return output; +} + +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + return float4(texCUBE(SkyBoxSampler, normalize(input.TextureCoordinate)).rgb, 1); +} + +technique Skybox +{ + pass Pass1 + { + VertexShader = compile VS_SHADERMODEL VertexShaderFunction(); + PixelShader = compile PS_SHADERMODEL PixelShaderFunction(); + } +} diff --git a/TGC.MonoGame.TP/Content/Models/cube.fbx b/TGC.MonoGame.TP/Content/Models/cube.fbx new file mode 100644 index 000000000..a2de74f05 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Models/cube.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd80f2f0d3ded3a1dccd83450fe771f19697436e342ed9fc3b0a8797a5c9dc1c +size 10535 diff --git a/TGC.MonoGame.TP/Content/Models/skybox/cube.fbx b/TGC.MonoGame.TP/Content/Models/skybox/cube.fbx new file mode 100644 index 000000000..a2de74f05 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Models/skybox/cube.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd80f2f0d3ded3a1dccd83450fe771f19697436e342ed9fc3b0a8797a5c9dc1c +size 10535 diff --git a/TGC.MonoGame.TP/Content/Textures/skybox/skyboxTexture.jpg b/TGC.MonoGame.TP/Content/Textures/skybox/skyboxTexture.jpg new file mode 100644 index 000000000..bd72a5293 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skybox/skyboxTexture.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98aea1d60e5d4c515eed6b7e0ab97abd8205fe9c610856f92b2d9da081510507 +size 49843 diff --git a/TGC.MonoGame.TP/Content/Textures/skyboxes/empty-space/empty-space.dds b/TGC.MonoGame.TP/Content/Textures/skyboxes/empty-space/empty-space.dds new file mode 100644 index 000000000..79fae0998 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skyboxes/empty-space/empty-space.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2052983e0a47441c30d2df775a5534ac3b80f3d2c79cdbfe53513024f76b455b +size 6291584 diff --git a/TGC.MonoGame.TP/Content/Textures/skyboxes/islands/islands.dds b/TGC.MonoGame.TP/Content/Textures/skyboxes/islands/islands.dds new file mode 100644 index 000000000..7d0b5b14a --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skyboxes/islands/islands.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cda4801d277ef878396a90af657e0f3adb4c3ae11915f79364473253109a3fce +size 6291584 diff --git a/TGC.MonoGame.TP/Content/Textures/skyboxes/skybox/skybox.dds b/TGC.MonoGame.TP/Content/Textures/skyboxes/skybox/skybox.dds new file mode 100644 index 000000000..6ea3d4ae5 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skyboxes/skybox/skybox.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:065b6dd047bd2b3e5f729ad3b09c4e9698ffce3cac7c3baf5ffee28206884963 +size 6291584 diff --git a/TGC.MonoGame.TP/Content/Textures/skyboxes/sun-in-space/sun-in-space.dds b/TGC.MonoGame.TP/Content/Textures/skyboxes/sun-in-space/sun-in-space.dds new file mode 100644 index 000000000..bef424ecc --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skyboxes/sun-in-space/sun-in-space.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9d9620d752f45f70f42e31dac907437b113e854e9ddc4e6f53bd2c1e5674b1a +size 6291584 diff --git a/TGC.MonoGame.TP/Content/Textures/skyboxes/sunset/sunset.dds b/TGC.MonoGame.TP/Content/Textures/skyboxes/sunset/sunset.dds new file mode 100644 index 000000000..a299a0ddf --- /dev/null +++ b/TGC.MonoGame.TP/Content/Textures/skyboxes/sunset/sunset.dds @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c9ca721ffdd9102726f2f2c93cad93f4907615c602fa6db1a035023570c1a35 +size 6291584 diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index ff9dbe1f2..749cd2873 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -26,7 +26,7 @@ public class Character Material CurrentMaterial = Material.RustedMetal; - Vector3 Position; + public Vector3 Position; Vector3 Velocity; Vector3 Acceleration = Vector3.Zero; Quaternion Rotation = Quaternion.Identity; @@ -198,7 +198,7 @@ private void SwitchMaterial() } private Vector2 pastMousePosition=Vector2.Zero; - private float MouseSensitivity=0.3f; + //private float MouseSensitivity=0.3f; public void ChangeDirection(float angle){ ForwardVector = Vector3.Transform(Vector3.UnitX, Matrix.CreateRotationY(angle)); diff --git a/TGC.MonoGame.TP/SkyBox/SkyBox.cs b/TGC.MonoGame.TP/SkyBox/SkyBox.cs new file mode 100644 index 000000000..647466824 --- /dev/null +++ b/TGC.MonoGame.TP/SkyBox/SkyBox.cs @@ -0,0 +1,95 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TGC.MonoGame.Samples.Samples.Shaders.SkyBox +{ + /// + /// Handles all of the aspects of working with a SkyBox. + /// + public class SkyBox + { + /// + /// Creates a new SkyBox + /// + /// The geometry to use for SkyBox. + /// The SkyBox texture to use. + /// The size of the cube. + public SkyBox(Model model, TextureCube texture, Effect effect) : this(model, texture, effect, 50) + { + } + + /// + /// Creates a new SkyBox + /// + /// The geometry to use for SkyBox. + /// The SkyBox texture to use. + /// The SkyBox fx to use. + /// The SkyBox fx to use. + public SkyBox(Model model, TextureCube texture, Effect effect, float size) + { + Model = model; + Texture = texture; + Effect = effect; + Size = size; + } + + /// + /// The size of the cube, used so that we can resize the box + /// for different sized environments. + /// + private float Size { get; } + + /// + /// The effect file that the SkyBox will use to render + /// + private Effect Effect { get; } + + /// + /// The actual SkyBox texture + /// + private TextureCube Texture { get; } + + /// + /// The SkyBox model, which will just be a cube + /// + public Model Model { get; set; } + + /// + /// Does the actual drawing of the SkyBox with our SkyBox effect. + /// There is no world matrix, because we're assuming the SkyBox won't + /// be moved around. The size of the SkyBox can be changed with the size + /// variable. + /// + /// The view matrix for the effect + /// The projection matrix for the effect + /// The position of the camera + public void Draw(Matrix view, Matrix projection, Vector3 cameraPosition) + { + // Go through each pass in the effect, but we know there is only one... + foreach (var pass in Effect.CurrentTechnique.Passes) + { + pass.Apply(); + + // Draw all of the components of the mesh, but we know the cube really + // only has one mesh + foreach (var mesh in Model.Meshes) + { + // Assign the appropriate values to each of the parameters + foreach (var part in mesh.MeshParts) + { + part.Effect = Effect; + part.Effect.Parameters["World"].SetValue( + Matrix.CreateScale(Size) * Matrix.CreateTranslation(cameraPosition)); + part.Effect.Parameters["View"].SetValue(view); + part.Effect.Parameters["Projection"].SetValue(projection); + part.Effect.Parameters["SkyBoxTexture"].SetValue(Texture); + part.Effect.Parameters["CameraPosition"].SetValue(cameraPosition); + } + + // Draw the mesh with the SkyBox effect + mesh.Draw(); + } + } + } + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index a20a9eec9..c6d5847bf 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -7,9 +7,17 @@ using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; +using TGC.MonoGame.Samples.Samples.Shaders.SkyBox; +using TGC.MonoGame.TP; abstract class Stage { + public const string ContentFolder3D = "Models/"; + public const string ContentFolderEffects = "Effects/"; + public const string ContentFolderMusic = "Music/"; + public const string ContentFolderSounds = "Sounds/"; + public const string ContentFolderSpriteFonts = "SpriteFonts/"; + public const string ContentFolderTextures = "Textures/"; protected GraphicsDevice GraphicsDevice; protected ContentManager Content; @@ -35,6 +43,8 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char CharacterInitialPosition = characterPosition; + LoadSkyBox(); + LoadTrack(); LoadObstacles(); LoadSigns(); @@ -46,6 +56,7 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char public abstract void Update(GameTime gameTime); private SpriteFont SpriteFont { get; set; } + public Vector3 CamPosition{get;set;} public void Draw(Matrix view, Matrix projection) { @@ -68,6 +79,7 @@ public void Draw(Matrix view, Matrix projection) { pickup.Draw(view, projection); } + SkyBox.Draw(view, projection, CamPosition); //SpriteBatch.DrawString(SpriteFont, "Launch spheres with the 'Z' key.", new Vector2(GraphicsDevice.Viewport.Width - 500, 25), Color.White); @@ -84,4 +96,16 @@ public void Draw(Matrix view, Matrix projection) abstract protected void LoadCheckpoints(); + public Model SkyBoxModel; + public TextureCube SkyBoxTexture; + public Effect SkyBoxEffect; + public SkyBox SkyBox; + public void LoadSkyBox(){ + SkyBoxModel = Content.Load(ContentFolder3D + "skybox/cube"); + SkyBoxTexture =Content.Load(ContentFolderTextures+"skyboxes/islands/islands"); + SkyBoxEffect = Content.Load(ContentFolderEffects + "SkyBox"); + SkyBox=new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 1000); + } + + } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index e64a6d53f..1f8a100dc 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -123,9 +123,11 @@ protected override void LoadCheckpoints() Checkpoints = new List(); } + + public override void Update(GameTime gameTime) { - // TODO: actualizar el estado de todas las piezas móviles del nivel + // TODO: actualizar el estado de todas las piezas m�viles del nivel } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 63bba3844..171bdcd6d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using TGC.MonoGame.Samples.Samples.Shaders.SkyBox; using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; @@ -91,14 +92,19 @@ protected override void Initialize() /// que podemos pre calcular para nuestro juego. /// public Effect BallEffect; + + protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. - SpriteBatch = new SpriteBatch(GraphicsDevice); - + //SpriteBatch = new SpriteBatch(GraphicsDevice); + + Stage = new Stage_01(GraphicsDevice, Content); + //Stage.SkyBoxModel = Content.Load(); + MainCharacter = new Character(Content, Stage.CharacterInitialPosition); BallEffect = Content.Load(ContentFolderEffects + "PBR"); @@ -125,6 +131,8 @@ protected override void Update(GameTime gameTime) FollowCamera.Update(gameTime, MainCharacter.World); + Stage.CamPosition=FollowCamera.CamPosition; + MainCharacter.ChangeDirection(FollowCamera.CamRotation); BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); @@ -140,14 +148,26 @@ protected override void Update(GameTime gameTime) /// protected override void Draw(GameTime gameTime) { - // Aca deberiamos poner toda la logia de renderizado del juego. GraphicsDevice.Clear(Color.LightSkyBlue); + // Aca deberiamos poner toda la logia de renderizado del juego. + var originalRasterizerState = GraphicsDevice.RasterizerState; + var rasterizerState = new RasterizerState(); + rasterizerState.CullMode = CullMode.None; + Graphics.GraphicsDevice.RasterizerState = rasterizerState; + //GraphicsDevice.DepthStencilState = DepthStencilState.None; + //GraphicsDevice.Clear(Color.LightSkyBlue); + + // + //Stage.SkyBox.Draw(FollowCamera.View, FollowCamera.Projection, FollowCamera.CamPosition); MainCharacter.Draw(FollowCamera.View, FollowCamera.Projection); Stage.Draw(FollowCamera.View, FollowCamera.Projection); + GraphicsDevice.RasterizerState = originalRasterizerState; + + //base.Draw(gameTime); } /// From c383c58815f816e01b2981133fad145f40ed19fe Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Sat, 22 Jun 2024 01:47:39 -0300 Subject: [PATCH 48/73] Procesamiento de colisiones. Co-authored-by: LColamonici --- .../Collisions/BoundingCylinder.cs | 2 +- .../Collisions/BoundingVolumesExtensions.cs | 2 +- .../Collisions/OrientedBoundingBox.cs | 2 +- .../Collisions/TGCCollisionUtils.cs | 2 +- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 13 ++ .../CustomPrimitives/RampPrimitive.cs | 13 ++ TGC.MonoGame.TP/Geometries/SpherePrimitive.cs | 2 +- .../MainCharacter/MainCharacter.cs | 120 +++++++++++++++- TGC.MonoGame.TP/Stages/Stage.cs | 128 ++++++++++-------- TGC.MonoGame.TP/Stages/Stage_01.cs | 45 +++++- TGC.MonoGame.TP/Stages/Stage_02.cs | 43 ++++++ TGC.MonoGame.TP/TGCGame.cs | 13 +- 12 files changed, 314 insertions(+), 71 deletions(-) diff --git a/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs b/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs index 594445be5..3f69453df 100644 --- a/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs +++ b/TGC.MonoGame.TP/Collisions/BoundingCylinder.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; -namespace TGC.MonoGame.Samples.Collisions +namespace TGC.MonoGame.TP.Collisions { /// diff --git a/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs index 053a2037b..e29bbb8fe 100644 --- a/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs +++ b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace TGC.MonoGame.Samples.Collisions +namespace TGC.MonoGame.TP.Collisions { /// /// Class that extends BoundingVolumes classes diff --git a/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs index e2741dddb..550fb0a7d 100644 --- a/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs +++ b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs @@ -1,7 +1,7 @@ using Microsoft.Xna.Framework; using System; -namespace TGC.MonoGame.Samples.Collisions +namespace TGC.MonoGame.TP.Collisions { /// /// Represents an Oriented-BoundingBox (OBB). diff --git a/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs b/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs index c51acb923..ac1ff282d 100644 --- a/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs +++ b/TGC.MonoGame.TP/Collisions/TGCCollisionUtils.cs @@ -1,6 +1,6 @@ using Microsoft.Xna.Framework; -namespace TGC.MonoGame.Samples.Collisions +namespace TGC.MonoGame.TP.Collisions { /// /// Utilidades para hacer detección de colisiones diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 96e52ef65..6785d90a2 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -28,6 +28,8 @@ public class CubePrimitive : GeometricPrimitive /// /// Constructs a new cube primitive. /// + /// + public BoundingBox BoundingCube { get; set; } public CubePrimitive( GraphicsDevice graphicsDevice, ContentManager content, @@ -35,12 +37,14 @@ public CubePrimitive( float size = 25f, Vector3? coordinates = null, Vector3? scale = null, + //BoundingBox? boundingBox = null, Matrix? rotation = null ) { Color = color; + // A cube has six faces, each one pointing in a different direction. Vector3[] normals = { @@ -86,6 +90,15 @@ public CubePrimitive( World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + if (coordinates.HasValue && scale.HasValue) + { + Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 + Vector3 regularSize = scale.Value; + // Ahora puedes usar regularVector, que es de tipo Vector3 + BoundingCube = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + } + + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 4044ef980..950baf145 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -11,6 +11,7 @@ #region Using Statements +using BepuPhysics.CollisionDetection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -23,6 +24,8 @@ namespace TGC.MonoGame.TP.Geometries public class RampPrimitive : CustomPrimitive { + public BoundingBox BoundingRamp { get; set; } + public RampPrimitive( GraphicsDevice graphicsDevice, ContentManager content, @@ -64,6 +67,16 @@ public RampPrimitive( World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + if (coordinates.HasValue && scale.HasValue) + { + Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 + Vector3 regularSize = scale.Value; + // Ahora puedes usar regularVector, que es de tipo Vector3 + BoundingRamp = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + } + + + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs index 51aa119ec..c1b06b71e 100644 --- a/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/SpherePrimitive.cs @@ -35,7 +35,7 @@ public class SpherePrimitive : GeometricPrimitive /// Diameter of the sphere. /// The number of times the surface triangles are subdivided. /// Color of the sphere. - public SpherePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float diameter, int tessellation, Color color, Matrix world) + public SpherePrimitive(GraphicsDevice graphicsDevice, ContentManager content, float diameter, int tessellation, Color color, Matrix world, BoundingSphere? boundingSphere) { if (tessellation < 3) throw new ArgumentOutOfRangeException("tessellation"); diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 1c96c3949..829b4a61e 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -5,6 +5,8 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using TGC.MonoGame.TP.Camera; +using TGC.MonoGame.TP.Stages; +using TGC.MonoGame.TP.Collisions; namespace TGC.MonoGame.TP.MainCharacter { @@ -32,6 +34,12 @@ public class Character Vector3 RotationAxis = Vector3.UnitY; float RotationAngle = 0f; + // Colisiones + public BoundingSphere EsferaBola { get; set; } + public bool OnGround { get; set; } + public Stage ActualStage; + // Colisiones + Vector3 BallSpinAxis=Vector3.UnitX; float BallSpinAngle=0f; Matrix WorldWithBallSpin; @@ -39,14 +47,16 @@ public class Character //float BallRoll=0f; Vector3 LightPos{get;set;} - public Matrix Spin;// - public Character(ContentManager content, Vector3 initialPosition) + public Matrix Spin; + public Character(ContentManager content, Stage stage) { Content = content; Spin= Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); + ActualStage = stage; + InitializeEffect(); - InitializeSphere(initialPosition); + InitializeSphere(stage.CharacterInitialPosition); InitializeTextures(); InitializeLight(); } @@ -63,6 +73,23 @@ private void InitializeSphere(Vector3 initialPosition) World = Scale * Matrix.CreateTranslation(Position); WorldWithBallSpin=World; + /* + // Colisiones: ¿van en lo principal? + int index = 0; + for (; index < ActualStage.Colliders.Count; index++) + ActualStage.Colliders[index] = BoundingVolumesExtensions.FromMatrix(ActualStage.StairsWorld[index]); + + // Instantiate a BoundingBox for the Box + ActualStage.Colliders[index] = BoundingVolumesExtensions.FromMatrix(ActualStage.BoxWorld); + index++; + // Instantiate a BoundingBox for the Floor. Note that the height is almost zero + ActualStage.Colliders[index] = new BoundingBox(new Vector3(-200f, -0.001f, -200f), new Vector3(200f, 0f, 200f)); + // Colisiones + */ + + // Bounding Sphere asociado a la bola principal + EsferaBola = new BoundingSphere(Position, 10f); + // Apply the effect to all mesh parts Sphere.Meshes.FirstOrDefault().MeshParts.FirstOrDefault().Effect = Effect; } @@ -83,6 +110,10 @@ public void Update(GameTime gameTime) { ProcessMaterialChange(); ProcessMovement(gameTime); + ProcessCollision(Velocity); + + // Verificar colisiones con los colliders del escenario actual + //ActualStage.CheckCollisions(Position); } public void Draw(Matrix view, Matrix projection) @@ -120,6 +151,83 @@ private void LoadTextures() + private void ProcessCollision(Vector3 scaledVelocity) + { + // Si la esfera tiene velocidad vertical + if (scaledVelocity.Y == 0f) + return; + + + // Empieza moviendo la esfera + BoundingSphere NuevaEsfera = EsferaBola; //tuvimos que crear una variable auxiliar porque no podemos modificarla directamente + NuevaEsfera.Center += Vector3.Up * scaledVelocity.Y; + EsferaBola = NuevaEsfera; + // Set the OnGround flag on false, update it later if we find a collision + OnGround = false; + + + // Collision detection + var collided = false; + var foundIndex = -1; + for (var index = 0; index < ActualStage.Colliders.Count; index++) + { + if (!EsferaBola.Intersects(ActualStage.Colliders[index]).Equals(BoxCylinderIntersection.Intersecting)) + continue; + + // If we collided with something, set our velocity in Y to zero to reset acceleration + Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); + + // Set our index and collision flag to true + // The index is to tell which collider the Robot intersects with + collided = true; + foundIndex = index; + break; + } + + + // We correct based on differences in Y until we don't collide anymore + // Not usual to iterate here more than once, but could happen + while (collided) + { + var collider = ActualStage.Colliders[foundIndex]; + var colliderY = BoundingVolumesExtensions.GetCenter(collider).Y; + var sphereY = EsferaBola.Center.Y; + var extents = BoundingVolumesExtensions.GetExtents(collider); + + float penetration; + // If we are on top of the collider, push up + // Also, set the OnGround flag to true + if (sphereY > colliderY) + { + penetration = colliderY + extents.Y - sphereY + EsferaBola.Radius; + OnGround = true; + } + + // If we are on bottom of the collider, push down + else + penetration = -sphereY - EsferaBola.Radius + colliderY - extents.Y; + + // Move our Cylinder so we are not colliding anymore + NuevaEsfera = EsferaBola; + NuevaEsfera.Center += Vector3.Up * penetration; + EsferaBola = NuevaEsfera; + collided = false; + + // Check for collisions again + for (var index = 0; index < ActualStage.Colliders.Count; index++) + { + if (!EsferaBola.Intersects(ActualStage.Colliders[index]).Equals(BoxCylinderIntersection.Intersecting)) + continue; + + // Iterate until we don't collide with anything anymore + collided = true; + foundIndex = index; + break; + } + } + + } + private void ProcessMaterialChange() { var keyboardState = Keyboard.GetState(); @@ -206,6 +314,7 @@ private void ProcessMovement(GameTime gameTime) var directionZ = new Vector3(); bool salto = false; + //bool onGround = true; float speed = 100; // Capturar Input teclado var keyboardState = Keyboard.GetState(); @@ -229,6 +338,7 @@ private void ProcessMovement(GameTime gameTime) { Velocity += Vector3.Up * speed; salto = true; + ProcessCollision(Velocity); } Vector3 gravity = Vector3.Zero; @@ -254,7 +364,9 @@ private void ProcessMovement(GameTime gameTime) directionY = Vector3.Transform(Vector3.UnitY, Rotation); directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); - if(Position.Y <= 25f) + + //if(Position.Y <= 25f) + if(OnGround==true) { gravity = new Vector3(0f, 0f, 0f); if (!salto) diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index a20a9eec9..e4a8f0bf2 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -7,81 +7,95 @@ using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; +using TGC.MonoGame.TP.Collisions; -abstract class Stage +namespace TGC.MonoGame.TP.Stages { - - protected GraphicsDevice GraphicsDevice; - protected ContentManager Content; - - protected List Track; // circuito y obstáculos fijos - protected List Obstacles; // obstáculos móviles - protected List Signs; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive - protected List Pickups; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive - protected List Checkpoints; // puntos de respawn - - public Vector3 CharacterInitialPosition; - //private SpriteBatch SpriteBatch; - - public void LoadSpriteBatch(){ - //SpriteBatch=new SpriteBatch(GraphicsDevice); - //SpriteBatch.Begin(); - - } - public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) + public abstract class Stage { - GraphicsDevice = graphicsDevice; - Content = content; - CharacterInitialPosition = characterPosition; + protected GraphicsDevice GraphicsDevice; + protected ContentManager Content; - LoadTrack(); - LoadObstacles(); - LoadSigns(); - LoadPickups(); - LoadCheckpoints(); - LoadSpriteBatch(); - } + protected List Track; // circuito y obstáculos fijos + protected List Obstacles; // obstáculos móviles + protected List Signs; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + protected List Pickups; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + protected List Checkpoints; // puntos de respawn - public abstract void Update(GameTime gameTime); + //COLISIONES + public List Colliders; + public Matrix BoxWorld { get; set; } //Matriz de mundo + public Matrix[] StairsWorld { get; set; } //Escaleras + public Matrix FloorWorld { get; set; } //Colisión con el piso + //COLISIONES - private SpriteFont SpriteFont { get; set; } - - public void Draw(Matrix view, Matrix projection) - { - foreach (GeometricPrimitive primitive in Track) - { - primitive.Draw(view, projection); + public Vector3 CharacterInitialPosition; + //private SpriteBatch SpriteBatch; + + public void LoadSpriteBatch(){ + //SpriteBatch=new SpriteBatch(GraphicsDevice); + //SpriteBatch.Begin(); + } - - foreach (GeometricPrimitive primitive in Obstacles) + public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { - primitive.Draw(view, projection); - } + GraphicsDevice = graphicsDevice; + Content = content; - foreach (GeometricPrimitive sign in Signs) - { - sign.Draw(view, projection); - } + CharacterInitialPosition = characterPosition; - foreach (GeometricPrimitive pickup in Pickups) - { - pickup.Draw(view, projection); + Colliders = new List(); + + LoadTrack(); + LoadObstacles(); + LoadSigns(); + LoadPickups(); + LoadCheckpoints(); + LoadSpriteBatch(); + LoadColliders(); } - - //SpriteBatch.DrawString(SpriteFont, "Launch spheres with the 'Z' key.", new Vector2(GraphicsDevice.Viewport.Width - 500, 25), Color.White); - } + public abstract void Update(GameTime gameTime); - abstract protected void LoadTrack(); + private SpriteFont SpriteFont { get; set; } + + public void Draw(Matrix view, Matrix projection) + { + foreach (GeometricPrimitive primitive in Track) + { + primitive.Draw(view, projection); + } + + foreach (GeometricPrimitive primitive in Obstacles) + { + primitive.Draw(view, projection); + } + + foreach (GeometricPrimitive sign in Signs) + { + sign.Draw(view, projection); + } + + foreach (GeometricPrimitive pickup in Pickups) + { + pickup.Draw(view, projection); + } + + //SpriteBatch.DrawString(SpriteFont, "Launch spheres with the 'Z' key.", new Vector2(GraphicsDevice.Viewport.Width - 500, 25), Color.White); - abstract protected void LoadObstacles(); + } - abstract protected void LoadPickups(); + abstract protected void LoadTrack(); - abstract protected void LoadSigns(); + abstract protected void LoadObstacles(); - abstract protected void LoadCheckpoints(); + abstract protected void LoadColliders(); + abstract protected void LoadPickups(); + abstract protected void LoadSigns(); + + abstract protected void LoadCheckpoints(); + } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index e64a6d53f..d21e5e500 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; +using TGC.MonoGame.TP.Stages; class Stage_01 : Stage { @@ -12,6 +13,48 @@ class Stage_01 : Stage public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : base(graphicsDevice, content, characterPosition: new Vector3(25, 25, -800)) {} + protected override void LoadColliders() + { + for(int i=0; i < Track.Count; i++) + { + GeometricPrimitive objetoActual = Track[i]; + if(objetoActual is CubePrimitive) + { + CubePrimitive aux = (CubePrimitive)objetoActual; + Colliders.Add(aux.BoundingCube); + } + if(objetoActual is RampPrimitive) + { + RampPrimitive aux = (RampPrimitive)objetoActual; + Colliders.Add(aux.BoundingRamp); + } + } + + for(int i=0; i < Obstacles.Count; i++) + { + // GeometricPrimitive cuboActual = Obstacles[i]; + // Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Signs.Count; i++) + { + CubePrimitive cuboActual = (CubePrimitive)Signs[i]; + Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Pickups.Count; i++) + { + //Geometric cuboActual = Pickups[i]; + //Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Checkpoints.Count; i++) + { + //GeometricPrimitive cuboActual = Checkpoints[i]; + //Colliders.Add(cuboActual.BoundingCube); + } + } + protected override void LoadTrack() { Track = new List @@ -125,7 +168,7 @@ protected override void LoadCheckpoints() public override void Update(GameTime gameTime) { - // TODO: actualizar el estado de todas las piezas móviles del nivel + // TODO: actualizar el estado de todas las piezas m�viles del nivel } diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index 5b033645e..e57e274bc 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; +using TGC.MonoGame.TP.Stages; class Stage_02 : Stage @@ -13,6 +14,48 @@ class Stage_02 : Stage public Stage_02(GraphicsDevice graphicsDevice, ContentManager content) : base(graphicsDevice, content, characterPosition: new Vector3(300f, 25f, 0f)) { } + protected override void LoadColliders() + { + for(int i=0; i < Track.Count; i++) + { + GeometricPrimitive objetoActual = Track[i]; + if(objetoActual is CubePrimitive) + { + CubePrimitive aux = (CubePrimitive)objetoActual; + Colliders.Add(aux.BoundingCube); + } + if(objetoActual is RampPrimitive) + { + RampPrimitive aux = (RampPrimitive)objetoActual; + Colliders.Add(aux.BoundingRamp); + } + } + + for(int i=0; i < Obstacles.Count; i++) + { + // GeometricPrimitive cuboActual = Obstacles[i]; + // Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Signs.Count; i++) + { + CubePrimitive cuboActual = (CubePrimitive)Signs[i]; + Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Pickups.Count; i++) + { + //Geometric cuboActual = Pickups[i]; + //Colliders.Add(cuboActual.BoundingCube); + } + + for(int i=0; i < Checkpoints.Count; i++) + { + //GeometricPrimitive cuboActual = Checkpoints[i]; + //Colliders.Add(cuboActual.BoundingCube); + } + } + protected override void LoadTrack() { Track = new List() diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 5db45c924..833f45fbc 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -5,7 +5,9 @@ using Microsoft.Xna.Framework.Input; using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.Collisions; using TGC.MonoGame.TP.MainCharacter; +using TGC.MonoGame.TP.Stages; namespace TGC.MonoGame.TP { @@ -23,6 +25,8 @@ public class TGCGame : Game public const string ContentFolderSpriteFonts = "SpriteFonts/"; public const string ContentFolderTextures = "Textures/"; + + /// /// Constructor del juego. /// @@ -50,6 +54,8 @@ public TGCGame() // BOLITA private Character MainCharacter; private Stage Stage; + + /// @@ -97,7 +103,7 @@ protected override void LoadContent() Stage = new Stage_01(GraphicsDevice, Content); - MainCharacter = new Character(Content, Stage.CharacterInitialPosition); + MainCharacter = new Character(Content, Stage); BallEffect = Content.Load(ContentFolderEffects + "PBR"); @@ -120,13 +126,12 @@ protected override void Update(GameTime gameTime) MainCharacter.Update(gameTime); + + FollowCamera.Update(gameTime, MainCharacter.World); BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); - - World = Matrix.CreateRotationY(Rotation); - base.Update(gameTime); } From 14107933afb52d01ac03786e7e0a1ebed0631994 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Sun, 23 Jun 2024 21:19:50 -0300 Subject: [PATCH 49/73] Colisiones - Problemas con movimiento en piso --- TGC.MonoGame.TP/Entity.cs | 21 + TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 5 +- .../Geometries/GeometricPrimitive.cs | 3 +- .../MainCharacter/MainCharacter.cs | 390 +++++++++++------- TGC.MonoGame.TP/Stages/Stage.cs | 10 +- TGC.MonoGame.TP/Stages/Stage_01.cs | 3 +- TGC.MonoGame.TP/TGCGame.cs | 33 +- 7 files changed, 295 insertions(+), 170 deletions(-) create mode 100644 TGC.MonoGame.TP/Entity.cs diff --git a/TGC.MonoGame.TP/Entity.cs b/TGC.MonoGame.TP/Entity.cs new file mode 100644 index 000000000..d12731196 --- /dev/null +++ b/TGC.MonoGame.TP/Entity.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; + +public class Entity : IDisposable +{ + + public Vector3 Position {get; set;} + public Vector3 Velocity {get; set;} + public Vector3 Acceleration {get; set;} = Vector3.Zero; + public Quaternion Rotation {get; set;} = Quaternion.Identity; + public Vector3 RotationAxis {get; set;} = Vector3.UnitY; + public float RotationAngle {get; set;} = 0f; + + public void Dispose() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 6785d90a2..81aac3002 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -30,6 +30,9 @@ public class CubePrimitive : GeometricPrimitive /// /// public BoundingBox BoundingCube { get; set; } + private Vector3 minVert; + private Vector3 maxVert; + public CubePrimitive( GraphicsDevice graphicsDevice, ContentManager content, @@ -93,7 +96,7 @@ public CubePrimitive( if (coordinates.HasValue && scale.HasValue) { Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 - Vector3 regularSize = scale.Value; + Vector3 regularSize = scale.Value * 25; // Ahora puedes usar regularVector, que es de tipo Vector3 BoundingCube = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); } diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs index 1a673a811..3fd65145c 100644 --- a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -26,7 +26,8 @@ namespace TGC.MonoGame.TP.Geometries /// drawing the model. Classes for specific types of primitive (CubePrimitive, SpherePrimitive, etc.) are derived from /// this common base, and use the AddVertex and AddIndex methods to specify their geometry. /// - public abstract class GeometricPrimitive : IDisposable + /// + public abstract class GeometricPrimitive : Entity { #region Fields diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 829b4a61e..9d4e4bdd8 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -7,10 +7,13 @@ using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Stages; using TGC.MonoGame.TP.Collisions; +using TGC.MonoGame.TP.Geometries; +using TGC.MonoGame.TP.MainCharacter; +using System.Collections.Generic; namespace TGC.MonoGame.TP.MainCharacter { - public class Character + public class Character : Entity { const string ContentFolder3D = "3D/"; const string ContentFolderEffects = "Effects/"; @@ -27,12 +30,7 @@ public class Character Material CurrentMaterial = Material.RustedMetal; - Vector3 Position; - Vector3 Velocity; - Vector3 Acceleration = Vector3.Zero; - Quaternion Rotation = Quaternion.Identity; - Vector3 RotationAxis = Vector3.UnitY; - float RotationAngle = 0f; + private List myEntities; // Colisiones public BoundingSphere EsferaBola { get; set; } @@ -43,14 +41,13 @@ public class Character Vector3 BallSpinAxis=Vector3.UnitX; float BallSpinAngle=0f; Matrix WorldWithBallSpin; - //float BallPitch=0f; - //float BallRoll=0f; Vector3 LightPos{get;set;} public Matrix Spin; - public Character(ContentManager content, Stage stage) + public Character(ContentManager content, Stage stage, List entities) { Content = content; + myEntities = entities; Spin= Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); ActualStage = stage; @@ -73,27 +70,18 @@ private void InitializeSphere(Vector3 initialPosition) World = Scale * Matrix.CreateTranslation(Position); WorldWithBallSpin=World; - /* - // Colisiones: ¿van en lo principal? - int index = 0; - for (; index < ActualStage.Colliders.Count; index++) - ActualStage.Colliders[index] = BoundingVolumesExtensions.FromMatrix(ActualStage.StairsWorld[index]); - - // Instantiate a BoundingBox for the Box - ActualStage.Colliders[index] = BoundingVolumesExtensions.FromMatrix(ActualStage.BoxWorld); - index++; - // Instantiate a BoundingBox for the Floor. Note that the height is almost zero - ActualStage.Colliders[index] = new BoundingBox(new Vector3(-200f, -0.001f, -200f), new Vector3(200f, 0f, 200f)); - // Colisiones - */ - // Bounding Sphere asociado a la bola principal - EsferaBola = new BoundingSphere(Position, 10f); + UpdateBBSphere(Position); // Apply the effect to all mesh parts Sphere.Meshes.FirstOrDefault().MeshParts.FirstOrDefault().Effect = Effect; } + private void UpdateBBSphere(Vector3 center) + { + EsferaBola = new BoundingSphere(center, 10f); + } + private void InitializeEffect() { Effect = Content.Load(ContentFolderEffects + "PBR"); @@ -110,10 +98,6 @@ public void Update(GameTime gameTime) { ProcessMaterialChange(); ProcessMovement(gameTime); - ProcessCollision(Velocity); - - // Verificar colisiones con los colliders del escenario actual - //ActualStage.CheckCollisions(Position); } public void Draw(Matrix view, Matrix projection) @@ -122,13 +106,8 @@ public void Draw(Matrix view, Matrix projection) Effect.Parameters["matWorld"].SetValue(WorldWithBallSpin); Effect.Parameters["matWorldViewProj"].SetValue(worldView * projection); Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(WorldWithBallSpin))); - //Effect.Parameters["lightPosition"].SetValue(new Vector3(25, 180, -800)); - //Effect.Parameters["lightPosition"].SetValue(Position + new Vector3(0, 60, 0)); Effect.Parameters["lightPosition"].SetValue(LightPos); Effect.Parameters["lightColor"].SetValue(new Vector3(253, 251, 211)); - - //Game.Gizmos.DrawSphere(World, Vector3.One*20, Color.Red); - Sphere.Meshes.FirstOrDefault().Draw(); } @@ -148,85 +127,6 @@ private void LoadTextures() Effect.Parameters["roughnessTexture"]?.SetValue(roughness); Effect.Parameters["aoTexture"]?.SetValue(ao); } - - - - private void ProcessCollision(Vector3 scaledVelocity) - { - // Si la esfera tiene velocidad vertical - if (scaledVelocity.Y == 0f) - return; - - - // Empieza moviendo la esfera - BoundingSphere NuevaEsfera = EsferaBola; //tuvimos que crear una variable auxiliar porque no podemos modificarla directamente - NuevaEsfera.Center += Vector3.Up * scaledVelocity.Y; - EsferaBola = NuevaEsfera; - // Set the OnGround flag on false, update it later if we find a collision - OnGround = false; - - - // Collision detection - var collided = false; - var foundIndex = -1; - for (var index = 0; index < ActualStage.Colliders.Count; index++) - { - if (!EsferaBola.Intersects(ActualStage.Colliders[index]).Equals(BoxCylinderIntersection.Intersecting)) - continue; - - // If we collided with something, set our velocity in Y to zero to reset acceleration - Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); - - // Set our index and collision flag to true - // The index is to tell which collider the Robot intersects with - collided = true; - foundIndex = index; - break; - } - - - // We correct based on differences in Y until we don't collide anymore - // Not usual to iterate here more than once, but could happen - while (collided) - { - var collider = ActualStage.Colliders[foundIndex]; - var colliderY = BoundingVolumesExtensions.GetCenter(collider).Y; - var sphereY = EsferaBola.Center.Y; - var extents = BoundingVolumesExtensions.GetExtents(collider); - - float penetration; - // If we are on top of the collider, push up - // Also, set the OnGround flag to true - if (sphereY > colliderY) - { - penetration = colliderY + extents.Y - sphereY + EsferaBola.Radius; - OnGround = true; - } - - // If we are on bottom of the collider, push down - else - penetration = -sphereY - EsferaBola.Radius + colliderY - extents.Y; - - // Move our Cylinder so we are not colliding anymore - NuevaEsfera = EsferaBola; - NuevaEsfera.Center += Vector3.Up * penetration; - EsferaBola = NuevaEsfera; - collided = false; - - // Check for collisions again - for (var index = 0; index < ActualStage.Colliders.Count; index++) - { - if (!EsferaBola.Intersects(ActualStage.Colliders[index]).Equals(BoxCylinderIntersection.Intersecting)) - continue; - - // Iterate until we don't collide with anything anymore - collided = true; - foundIndex = index; - break; - } - } - - } private void ProcessMaterialChange() { @@ -300,31 +200,228 @@ private void SwitchMaterial() LoadTextures(); } + public float DistanceToGround(Vector3 pos) + { + float dist = 1000000.0f; + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + Ray tempRay = new Ray(pos, -Vector3.Up); + float? tempDist = tempRay.Intersects(entityAux.BoundingCube); + + if (dist > tempDist) + { + dist = (float)tempDist; + } + } + } + + return dist; + } + + public bool IsOnGround(Vector3 pos) + { + GeometricPrimitive collidedEntity = null; + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + Ray tempRay = new Ray(pos, -Vector3.Up); + float? dist = tempRay.Intersects(entityAux.BoundingCube); + + if (dist.HasValue && dist < 10.2f) + { + collidedEntity = (CubePrimitive)entity; + return true; + } + } + } + return false; + } + + public bool IsColliding() + { + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + if (EsferaBola.Intersects(entityAux.BoundingCube)) + { + return true; + } + } + } + return false; + } + + public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) + { + Vector3 oldPosition = Position; + Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; + Vector3 newPosition = oldPosition + movement; + + UpdateBBSphere(newPosition); + int steps = 1000; + bool neverFound = true; + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + if (EsferaBola.Intersects(entityAux.BoundingCube)) + { + neverFound = false; + if (IsOnGround(newPosition)) + { + //LocalVelocity = new Vector3(LocalVelocity.X, 0.0f, LocalVelocity.Z); + } + + bool intersecting = true; + float moveFactor = 1.0f; + while (intersecting && steps > 0) + { + steps -= 1; + movement = LocalVelocity * deltaTime * deltaTime * 0.5f; + newPosition = oldPosition + movement * moveFactor; + UpdateBBSphere(newPosition); + intersecting = EsferaBola.Intersects(entityAux.BoundingCube); + moveFactor = moveFactor / 2.0f; + } + + Position = newPosition; + UpdateBBSphere(Position); + } + } + } + + if (neverFound) + { + Position = newPosition; + UpdateBBSphere(Position); + } + } + + public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) + { + Vector3 oldPosition = Position; + Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; + Vector3 newPosition = oldPosition + movement; + + UpdateBBSphere(newPosition); + + bool collisionDetected = false; + + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + if (EsferaBola.Intersects(entityAux.BoundingCube)) + { + collisionDetected = true; + + // Manejar la colisión + Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); + + // Resolver la posición después de la colisión + newPosition = ResolveCollision(oldPosition, newPosition, collisionNormal); + + // Actualizar la esfera de colisión + UpdateBBSphere(newPosition); + + // Puedes hacer más ajustes según tu lógica específica de juego + // Por ejemplo, ajustar la velocidad según la normal de la colisión + // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); + } + } + } + + // Si no hubo colisión, simplemente actualizar la posición + if (!collisionDetected) + { + Position = newPosition; + UpdateBBSphere(Position); + } + } + + private Vector3 GetCollisionNormal(BoundingBox boundingBox) + { + // Aquí obtienes la normal de la colisión basada en la caja de colisión + // Puedes implementar la lógica según tus necesidades específicas + // Por ejemplo, calcular la normal de la cara con la que colisiona la esfera + // y devolverla como un vector normalizado + // Este es un ejemplo simplificado, puede necesitar ajustes según tu escenario + return Vector3.Normalize(Position - boundingBox.Min); + } + + private Vector3 ResolveCollision(Vector3 oldPosition, Vector3 newPosition, Vector3 collisionNormal) + { + // Calcula el vector desde la posición anterior hacia la nueva posición + Vector3 movementDirection = newPosition - oldPosition; + + // Calcula la distancia que se movió la bola antes de la colisión + float movementDistance = movementDirection.Length(); + + // Si no se movió, no hay colisión que resolver + if (movementDistance == 0) + return newPosition; + + // Normaliza la dirección del movimiento + Vector3 movementDirectionNormalized = movementDirection / movementDistance; + + // Calcula la distancia a lo largo de la normal de la colisión + float distanceAlongNormal = Vector3.Dot(collisionNormal, newPosition - oldPosition); + + // Si la bola se estaba moviendo hacia el objeto (distancia negativa a lo largo de la normal), la refleja + if (distanceAlongNormal < 0) + { + // Calcula la parte de la velocidad que va en la dirección opuesta a la normal + Vector3 velocityParallel = distanceAlongNormal * collisionNormal; + + // Calcula la parte de la velocidad que va en la dirección perpendicular a la normal + Vector3 velocityPerpendicular = newPosition - oldPosition - velocityParallel; + + // Invierte la parte de la velocidad paralela para simular un rebote + newPosition = oldPosition - velocityParallel + velocityPerpendicular; + } + + // Retorna la nueva posición ajustada después de la resolución de la colisión + return newPosition; + } + private Vector2 pastMousePosition=Vector2.Zero; private float MouseSensitivity=0.3f; + + private Vector3 GetVelocity() + { + return Velocity; + } + private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - - - var directionX = new Vector3(); var directionY = new Vector3(); var directionZ = new Vector3(); - bool salto = false; - //bool onGround = true; - float speed = 100; + float speed = 100f; + // Capturar Input teclado var keyboardState = Keyboard.GetState(); + + // Procesamiento del movimiento horizontal if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation); } if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { - Acceleration += Vector3.Transform(Vector3.UnitX * -speed, Rotation) * (- 1); + Acceleration += Vector3.Transform(Vector3.UnitX * speed, Rotation); } if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { @@ -332,30 +429,26 @@ private void ProcessMovement(GameTime gameTime) } if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { - Acceleration += Vector3.Transform(Vector3.UnitZ * speed, Rotation) * (-1); - } - if(Keyboard.GetState().IsKeyDown(Keys.Space) && Velocity.Y == 0f) - { - Velocity += Vector3.Up * speed; - salto = true; - ProcessCollision(Velocity); + Acceleration += Vector3.Transform(Vector3.UnitZ * -speed, Rotation); } - Vector3 gravity = Vector3.Zero; - - Vector3 SpinVelocity=Velocity; + Acceleration += new Vector3(0f, -100f, 0f); + //Procesamiento del movimiento vertical + float distGround = DistanceToGround(Position); + if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround < 12.5f || IsColliding())) + { + Velocity += Vector3.Up * speed * 100; + } BallSpinAngle += Velocity.Length()*elapsedTime / (MathHelper.Pi*12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); - //DeltaX+=elapsedTime*Velocity.X/MathHelper.TwoPi; - //DeltaZ+=elapsedTime*Velocity.Z/MathHelper.TwoPi; - //Spin*=Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle); - //BallSpinAxis.X=Math.Abs(BallSpinAxis.X); - //BallSpinAxis.Z=Math.Abs(BallSpinAxis.Z); - - //if(Acceleration==Vector3.Zero && Velocity!=Vector3.Zero) Velocity *= (1-(elapsedTime/2)); - if(Acceleration==Vector3.Zero || Vector3.Dot(Acceleration, Velocity)<0) Velocity *= (1-(elapsedTime)); + + if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) + { + Velocity *= (1 - (elapsedTime)); + } + if(Velocity==Vector3.Zero) BallSpinAxis = Vector3.UnitZ; Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); @@ -364,25 +457,10 @@ private void ProcessMovement(GameTime gameTime) directionY = Vector3.Transform(Vector3.UnitY, Rotation); directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); - - //if(Position.Y <= 25f) - if(OnGround==true) - { - gravity = new Vector3(0f, 0f, 0f); - if (!salto) - { - Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); - } - } - else - { - gravity = new Vector3(0f, -100f, 0f); - } - - Velocity += (Acceleration + gravity) * elapsedTime; - Position += (directionX + directionY + directionZ) * Velocity * elapsedTime * 0.5f; - + Velocity += Acceleration; + ProcessCollision(Velocity * (directionX + directionY + directionZ), elapsedTime); + MoveTo(Position); Acceleration = Vector3.Zero; diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index e4a8f0bf2..43aad7e8f 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -17,11 +17,11 @@ public abstract class Stage protected GraphicsDevice GraphicsDevice; protected ContentManager Content; - protected List Track; // circuito y obstáculos fijos - protected List Obstacles; // obstáculos móviles - protected List Signs; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive - protected List Pickups; //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive - protected List Checkpoints; // puntos de respawn + public List Track { get; set; } // circuito y obstáculos fijos + public List Obstacles { get; set; } // obstáculos móviles + public List Signs { get; set; } //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + public List Pickups { get; set; } //FIXME: eventualmente podrían ser algo distinto a GeometricPrimitive + public List Checkpoints { get; set; } // puntos de respawn //COLISIONES public List Colliders; diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index d21e5e500..b582ab5c4 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -11,7 +11,7 @@ class Stage_01 : Stage { public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : - base(graphicsDevice, content, characterPosition: new Vector3(25, 25, -800)) {} + base(graphicsDevice, content, characterPosition: new Vector3(25, 40, -800)) {} protected override void LoadColliders() { @@ -169,7 +169,6 @@ protected override void LoadCheckpoints() public override void Update(GameTime gameTime) { // TODO: actualizar el estado de todas las piezas m�viles del nivel - } } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 833f45fbc..13469ffde 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -54,8 +54,7 @@ public TGCGame() // BOLITA private Character MainCharacter; private Stage Stage; - - + protected List Entities; /// @@ -69,7 +68,6 @@ protected override void Initialize() size.X /= 2; size.Y /= 2; - //var cameraPosition = new Vector3(25f, 100f, -1100f); //Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); // Creo una camaar para seguir a nuestro auto. @@ -99,17 +97,42 @@ protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. SpriteBatch = new SpriteBatch(GraphicsDevice); - + Entities = new List(); Stage = new Stage_01(GraphicsDevice, Content); - MainCharacter = new Character(Content, Stage); + MainCharacter = new Character(Content, Stage, Entities); BallEffect = Content.Load(ContentFolderEffects + "PBR"); + MergeEntities(Stage.Track, Stage.Obstacles, Stage.Signs, Stage.Pickups); + base.LoadContent(); } + private void MergeEntities(List Track, List Obstacles, List Signs, List Pickups) + { + foreach(GeometricPrimitive myTrack in Track) + { + Entities.Add(myTrack); + } + + foreach(GeometricPrimitive myObstacle in Obstacles) + { + Entities.Add(myObstacle); + } + + foreach(GeometricPrimitive mySign in Signs) + { + Entities.Add(mySign); + } + + foreach(GeometricPrimitive myPickup in Pickups) + { + Entities.Add(myPickup); + } + } + /// /// Se llama en cada frame. /// Se debe escribir toda la logica de computo del modelo, asi como tambien verificar entradas del usuario y reacciones From 1f20169274ed528468b98dd4daa953c541a88e46 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Mon, 24 Jun 2024 01:50:22 -0300 Subject: [PATCH 50/73] Hay movimiento pero faltan ajustes. --- .../MainCharacter/MainCharacter.cs | 186 +++++++++++------- 1 file changed, 110 insertions(+), 76 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 9d4e4bdd8..231b84f6d 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -30,25 +30,36 @@ public class Character : Entity Material CurrentMaterial = Material.RustedMetal; - private List myEntities; + private List myEntities; // Colisiones public BoundingSphere EsferaBola { get; set; } public bool OnGround { get; set; } public Stage ActualStage; + public struct Face + { + public Vector3 Normal; + public Vector3[] Vertices; + + public Face(Vector3 normal, Vector3[] vertices) + { + Normal = normal; + Vertices = vertices; + } + } // Colisiones - Vector3 BallSpinAxis=Vector3.UnitX; - float BallSpinAngle=0f; + Vector3 BallSpinAxis = Vector3.UnitX; + float BallSpinAngle = 0f; Matrix WorldWithBallSpin; - Vector3 LightPos{get;set;} + Vector3 LightPos { get; set; } public Matrix Spin; public Character(ContentManager content, Stage stage, List entities) { Content = content; myEntities = entities; - Spin= Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); + Spin = Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); ActualStage = stage; @@ -57,8 +68,9 @@ public Character(ContentManager content, Stage stage, List entities) InitializeTextures(); InitializeLight(); } - void InitializeLight(){ - LightPos=Position+ new Vector3(0,10,0); + void InitializeLight() + { + LightPos = Position + new Vector3(0, 10, 0); } private void InitializeSphere(Vector3 initialPosition) @@ -68,7 +80,7 @@ private void InitializeSphere(Vector3 initialPosition) Position = initialPosition; World = Scale * Matrix.CreateTranslation(Position); - WorldWithBallSpin=World; + WorldWithBallSpin = World; // Bounding Sphere asociado a la bola principal UpdateBBSphere(Position); @@ -127,7 +139,7 @@ private void LoadTextures() Effect.Parameters["roughnessTexture"]?.SetValue(roughness); Effect.Parameters["aoTexture"]?.SetValue(ao); } - + private void ProcessMaterialChange() { var keyboardState = Keyboard.GetState(); @@ -155,13 +167,13 @@ private void ProcessMaterialChange() NewMaterial = Material.Metal; } - if (NewMaterial != CurrentMaterial) + if (NewMaterial != CurrentMaterial) { CurrentMaterial = NewMaterial; SwitchMaterial(); LoadTextures(); } - + } private void UpdateMaterialPath() @@ -223,7 +235,6 @@ public float DistanceToGround(Vector3 pos) public bool IsOnGround(Vector3 pos) { - GeometricPrimitive collidedEntity = null; foreach (Entity entity in myEntities) { if (entity is CubePrimitive) @@ -232,9 +243,8 @@ public bool IsOnGround(Vector3 pos) Ray tempRay = new Ray(pos, -Vector3.Up); float? dist = tempRay.Intersects(entityAux.BoundingCube); - if (dist.HasValue && dist < 10.2f) + if (dist.HasValue && dist < 9.8f) { - collidedEntity = (CubePrimitive)entity; return true; } } @@ -258,15 +268,17 @@ public bool IsColliding() return false; } - public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) + public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) { Vector3 oldPosition = Position; Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; Vector3 newPosition = oldPosition + movement; UpdateBBSphere(newPosition); - int steps = 1000; - bool neverFound = true; + + bool collisionDetected = false; + bool isOnGround = IsOnGround(newPosition); // Verificar si está en el suelo en la nueva posición + foreach (Entity entity in myEntities) { if (entity is CubePrimitive) @@ -274,47 +286,57 @@ public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) CubePrimitive entityAux = (CubePrimitive)entity; if (EsferaBola.Intersects(entityAux.BoundingCube)) { - neverFound = false; - if (IsOnGround(newPosition)) - { - //LocalVelocity = new Vector3(LocalVelocity.X, 0.0f, LocalVelocity.Z); - } + collisionDetected = true; - bool intersecting = true; - float moveFactor = 1.0f; - while (intersecting && steps > 0) + // Manejar la colisión + Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); + + // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) + if (Math.Abs(collisionNormal.Y) > 0.9) // Ajusta este valor según tu escenario { - steps -= 1; - movement = LocalVelocity * deltaTime * deltaTime * 0.5f; - newPosition = oldPosition + movement * moveFactor; + isOnGround = true; + + // Resolver la posición después de la colisión + newPosition = ResolveCollision(oldPosition, newPosition, collisionNormal); + + // Actualizar la esfera de colisión UpdateBBSphere(newPosition); - intersecting = EsferaBola.Intersects(entityAux.BoundingCube); - moveFactor = moveFactor / 2.0f; } - Position = newPosition; - UpdateBBSphere(Position); + // Puedes hacer más ajustes según tu lógica específica de juego + // Por ejemplo, ajustar la velocidad según la normal de la colisión + // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); } } } - if (neverFound) + // Permitir el movimiento horizontal si no está en el suelo + if (isOnGround) + { + /*newPosition.X += LocalVelocity.X / deltaTime; + newPosition.Z += LocalVelocity.Z / deltaTime;*/ + newPosition.Y = oldPosition.Y; + } + + // Actualizar la posición solo si no hubo colisión con el suelo o está en el suelo + if (!collisionDetected || isOnGround) { Position = newPosition; UpdateBBSphere(Position); } } - public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) + + + public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) { Vector3 oldPosition = Position; Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; Vector3 newPosition = oldPosition + movement; UpdateBBSphere(newPosition); - - bool collisionDetected = false; - + int steps = 1000; + bool neverFound = true; foreach (Entity entity in myEntities) { if (entity is CubePrimitive) @@ -322,26 +344,31 @@ public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) CubePrimitive entityAux = (CubePrimitive)entity; if (EsferaBola.Intersects(entityAux.BoundingCube)) { - collisionDetected = true; - - // Manejar la colisión - Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); - - // Resolver la posición después de la colisión - newPosition = ResolveCollision(oldPosition, newPosition, collisionNormal); + neverFound = false; + if (IsOnGround(newPosition)) + { + //LocalVelocity = new Vector3(LocalVelocity.X, 0.0f, LocalVelocity.Z); + } - // Actualizar la esfera de colisión - UpdateBBSphere(newPosition); + bool intersecting = true; + float moveFactor = 1.0f; + while (intersecting && steps > 0) + { + steps -= 1; + movement = LocalVelocity * deltaTime * deltaTime * 0.5f; + newPosition = oldPosition + movement * moveFactor; + UpdateBBSphere(newPosition); + intersecting = EsferaBola.Intersects(entityAux.BoundingCube); + moveFactor = moveFactor / 2.0f; + } - // Puedes hacer más ajustes según tu lógica específica de juego - // Por ejemplo, ajustar la velocidad según la normal de la colisión - // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); + Position = newPosition; + UpdateBBSphere(Position); } } } - // Si no hubo colisión, simplemente actualizar la posición - if (!collisionDetected) + if (neverFound) { Position = newPosition; UpdateBBSphere(Position); @@ -350,70 +377,77 @@ public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) private Vector3 GetCollisionNormal(BoundingBox boundingBox) { - // Aquí obtienes la normal de la colisión basada en la caja de colisión - // Puedes implementar la lógica según tus necesidades específicas - // Por ejemplo, calcular la normal de la cara con la que colisiona la esfera - // y devolverla como un vector normalizado - // Este es un ejemplo simplificado, puede necesitar ajustes según tu escenario - return Vector3.Normalize(Position - boundingBox.Min); + // Calcula el centro de la caja de colisión + Vector3 boxCenter = (boundingBox.Max + boundingBox.Min) * 0.5f; + + // Calcula el vector desde el centro de la caja de colisión hacia la posición actual + Vector3 collisionVector = Position - boxCenter; + + // Normaliza el vector para obtener la dirección de la normal de la colisión + return Vector3.Normalize(collisionVector); } private Vector3 ResolveCollision(Vector3 oldPosition, Vector3 newPosition, Vector3 collisionNormal) { - // Calcula el vector desde la posición anterior hacia la nueva posición + // Calcula el vector desde la posición anterior hacia la nueva posición Vector3 movementDirection = newPosition - oldPosition; - // Calcula la distancia que se movió la bola antes de la colisión + // Calcula la distancia que se movió la bola antes de la colisión float movementDistance = movementDirection.Length(); - // Si no se movió, no hay colisión que resolver + // Si no se movió, no hay colisión que resolver if (movementDistance == 0) return newPosition; - // Normaliza la dirección del movimiento + // Normaliza la dirección del movimiento Vector3 movementDirectionNormalized = movementDirection / movementDistance; - // Calcula la distancia a lo largo de la normal de la colisión + // Calcula la distancia a lo largo de la normal de la colisión float distanceAlongNormal = Vector3.Dot(collisionNormal, newPosition - oldPosition); // Si la bola se estaba moviendo hacia el objeto (distancia negativa a lo largo de la normal), la refleja if (distanceAlongNormal < 0) { - // Calcula la parte de la velocidad que va en la dirección opuesta a la normal + // Calcula la parte de la velocidad que va en la dirección opuesta a la normal Vector3 velocityParallel = distanceAlongNormal * collisionNormal; - // Calcula la parte de la velocidad que va en la dirección perpendicular a la normal + // Calcula la parte de la velocidad que va en la dirección perpendicular a la normal Vector3 velocityPerpendicular = newPosition - oldPosition - velocityParallel; // Invierte la parte de la velocidad paralela para simular un rebote newPosition = oldPosition - velocityParallel + velocityPerpendicular; + + // Aplica alguna fricción o amortiguación opcional para reducir la velocidad después del rebote + newPosition -= newPosition * 0.1f; // Ajusta el factor de amortiguación según tu necesidad } - // Retorna la nueva posición ajustada después de la resolución de la colisión + // Retorna la nueva posición ajustada después de la resolución de la colisión return newPosition; } - private Vector2 pastMousePosition=Vector2.Zero; - private float MouseSensitivity=0.3f; + + + private Vector2 pastMousePosition = Vector2.Zero; + private float MouseSensitivity = 0.3f; private Vector3 GetVelocity() { return Velocity; } - private void ProcessMovement(GameTime gameTime) + private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; var directionX = new Vector3(); var directionY = new Vector3(); var directionZ = new Vector3(); - + float speed = 100f; // Capturar Input teclado var keyboardState = Keyboard.GetState(); - + // Procesamiento del movimiento horizontal if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { @@ -441,7 +475,7 @@ private void ProcessMovement(GameTime gameTime) Velocity += Vector3.Up * speed * 100; } - BallSpinAngle += Velocity.Length()*elapsedTime / (MathHelper.Pi*12.5f); + BallSpinAngle += Velocity.Length() * elapsedTime / (MathHelper.Pi * 12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) @@ -449,7 +483,7 @@ private void ProcessMovement(GameTime gameTime) Velocity *= (1 - (elapsedTime)); } - if(Velocity==Vector3.Zero) BallSpinAxis = Vector3.UnitZ; + if (Velocity == Vector3.Zero) BallSpinAxis = Vector3.UnitZ; Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); @@ -460,7 +494,7 @@ private void ProcessMovement(GameTime gameTime) Velocity += Acceleration; ProcessCollision(Velocity * (directionX + directionY + directionZ), elapsedTime); - + MoveTo(Position); Acceleration = Vector3.Zero; @@ -469,9 +503,9 @@ private void ProcessMovement(GameTime gameTime) public void MoveTo(Vector3 position) { World = Scale * Matrix.CreateTranslation(position); - WorldWithBallSpin=Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle) * World; - LightPos=Position+ new Vector3(0,30,-30); - + WorldWithBallSpin = Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle) * World; + LightPos = Position + new Vector3(0, 30, -30); + //WorldWithBallSpin=Matrix.CreateRotationX(DeltaX) * Matrix.CreateRotationZ(DeltaZ) * World; } } From bd8cf2d072e8caae81c5f57ac3b42142d1a10b9e Mon Sep 17 00:00:00 2001 From: LColamonici Date: Fri, 28 Jun 2024 02:38:50 -0300 Subject: [PATCH 51/73] avance grande en manejo de colisiones (falta limpiar el codigo) --- .../MainCharacter/MainCharacter.cs | 140 +++++++++++++++++- TGC.MonoGame.TP/TGCGame.cs | 2 +- 2 files changed, 138 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 1cf44f4d8..a2cec1c91 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -66,6 +66,8 @@ public Face(Vector3 normal, Vector3[] vertices) Vector3 LightPos { get; set; } public Matrix Spin; + Vector3 startPos; + public Vector3 ForwardVector=Vector3.UnitX; @@ -75,6 +77,7 @@ public Character(ContentManager content, Stage stage, List entities) Content = content; myEntities = entities; Spin = Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); + startPos=stage.CharacterInitialPosition; ActualStage = stage; @@ -391,6 +394,92 @@ public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) } } + public static Vector3 GetCollisionPoint(BoundingSphere sphere, BoundingBox box) + { + // Encuentra el punto más cercano en la superficie de la caja al centro de la esfera + Vector3 closestPoint = Vector3.Clamp(sphere.Center, box.Min, box.Max); + + // Calcula la dirección desde el punto más cercano al centro de la esfera + Vector3 direction = sphere.Center - closestPoint; + + // Si la dirección es cero, el centro de la esfera está dentro de la caja, podemos retornar el punto más cercano + if (direction == Vector3.Zero) + { + return closestPoint; + } + + // Normaliza la dirección + direction.Normalize(); + + // Calcula el punto exacto de colisión en la superficie de la esfera + Vector3 collisionPoint = closestPoint + direction * sphere.Radius; + + return collisionPoint; + } + + Vector3 getCollisionNormalNEW(BoundingSphere sphere, BoundingBox box){ + Vector3 puntoContacto = GetCollisionPoint(sphere, box); + return Vector3.Normalize(sphere.Center-puntoContacto); + } + public void ProcessCollisionNEW( float deltaTime) + { + Vector3 oldPosition = Position; + Vector3 movement = Velocity * deltaTime * deltaTime * 0.5f; + Vector3 newPosition = oldPosition + movement; + + UpdateBBSphere(newPosition); + + bool collisionDetected = false; + bool isOnGround = IsOnGround(newPosition); // Verificar si está en el suelo en la nueva posición + + foreach (Entity entity in myEntities) + { + if (entity is CubePrimitive) + { + CubePrimitive entityAux = (CubePrimitive)entity; + if (EsferaBola.Intersects(entityAux.BoundingCube)) + { + collisionDetected = true; + + // Manejar la colisión + Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); + //Vector3 surfaceNormal = GetCollisionSurfaceNormal(EsferaBola, entityAux.BoundingCube); + Vector3 surfaceNormal = getCollisionNormalNEW(EsferaBola, entityAux.BoundingCube); + + // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) + if (Math.Abs(collisionNormal.Y) > 0.9) // Ajusta este valor según tu escenario + { + isOnGround = true; + //if(Velocity.Y<0.1) Velocity = new Vector3(Velocity.X, 0, Velocity.Z); + } + Velocity = Vector3.Reflect(Velocity, surfaceNormal) ; + movement = Velocity * deltaTime * deltaTime * 0.5f; + newPosition = oldPosition + movement; + UpdateBBSphere(newPosition); + // Puedes hacer más ajustes según tu lógica específica de juego + // Por ejemplo, ajustar la velocidad según la normal de la colisión + // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); + } + } + } + + + // Permitir el movimiento horizontal si no está en el suelo + if (isOnGround) + { + /*newPosition.X += LocalVelocity.X / deltaTime; + newPosition.Z += LocalVelocity.Z / deltaTime;*/ + newPosition.Y = oldPosition.Y; + } + + // Actualizar la posición solo si no hubo colisión con el suelo o está en el suelo + if (!collisionDetected || isOnGround) + { + Position = newPosition; + UpdateBBSphere(Position); + } + } + private Vector3 GetCollisionNormal(BoundingBox boundingBox) { // Calcula el centro de la caja de colisión @@ -403,6 +492,43 @@ private Vector3 GetCollisionNormal(BoundingBox boundingBox) return Vector3.Normalize(collisionVector); } + public static Vector3 GetCollisionSurfaceNormal(BoundingSphere sphere, BoundingBox box) + { + // Calcula el punto más cercano de la caja al centro de la esfera + Vector3 closestPoint = Vector3.Clamp(sphere.Center, box.Min, box.Max); + + // Calcula la diferencia entre el punto más cercano y el centro de la esfera + Vector3 difference = sphere.Center - closestPoint; + + // Determina la cara tocada + if (closestPoint.X == box.Min.X) + { + return Vector3.Left; // Normal (-1, 0, 0) + } + if (closestPoint.X == box.Max.X) + { + return Vector3.Right; // Normal (1, 0, 0) + } + if (closestPoint.Y == box.Min.Y) + { + return Vector3.Down; // Normal (0, -1, 0) + } + if (closestPoint.Y == box.Max.Y) + { + return Vector3.Up; // Normal (0, 1, 0) + } + if (closestPoint.Z == box.Min.Z) + { + return Vector3.Backward; // Normal (0, 0, -1) + } + if (closestPoint.Z == box.Max.Z) + { + return Vector3.Forward; // Normal (0, 0, 1) + } + + return Vector3.Zero; + } + private Vector3 ResolveCollision(Vector3 oldPosition, Vector3 newPosition, Vector3 collisionNormal) { // Calcula el vector desde la posición anterior hacia la nueva posición @@ -498,7 +624,9 @@ private void ProcessMovement(GameTime gameTime) Velocity += Vector3.Up * speed * 100; } - BallSpinAngle += Velocity.Length() * elapsedTime / (MathHelper.Pi * 120.5f); + + Vector3 HorizontalVelocity = new Vector3(Velocity.X, 0, Velocity.Z); + BallSpinAngle += HorizontalVelocity.Length() * elapsedTime * elapsedTime / (MathHelper.Pi * 12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) @@ -516,10 +644,16 @@ private void ProcessMovement(GameTime gameTime) Velocity += Acceleration; - ProcessCollision(Velocity * (directionX + directionY + directionZ), elapsedTime); + //ProcessCollision(Velocity * (directionX + directionY + directionZ), elapsedTime); + ProcessCollisionNEW(elapsedTime); MoveTo(Position); + /*if(Position.Y < -100){ + MoveTo(startPos); + UpdateBBSphere(startPos); + } */ + Acceleration = Vector3.Zero; } //float DeltaX, DeltaZ; @@ -527,7 +661,7 @@ public void MoveTo(Vector3 position) { World = Scale * Matrix.CreateTranslation(position); WorldWithBallSpin = Matrix.CreateFromAxisAngle(BallSpinAxis, BallSpinAngle) * World; - LightPos = Position + new Vector3(0, 30, -30); + LightPos = position + new Vector3(0, 30, -30); //WorldWithBallSpin=Matrix.CreateRotationX(DeltaX) * Matrix.CreateRotationZ(DeltaZ) * World; } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 9e2149c22..1e8f06335 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -43,7 +43,7 @@ public TGCGame() // Carpeta raiz donde va a estar toda la Media. Content.RootDirectory = "Content"; // Hace que el mouse sea visible. - IsMouseVisible = true; + IsMouseVisible = false; } private GraphicsDeviceManager Graphics { get; } From 5534be66b64c2f04633342d052b4f696df17cb51 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Sat, 29 Jun 2024 01:54:41 -0300 Subject: [PATCH 52/73] Colisiones resueltas. --- .../CustomPrimitives/RampPrimitive.cs | 9 +- .../MainCharacter/MainCharacter.cs | 345 +++--------------- 2 files changed, 64 insertions(+), 290 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 950baf145..6bf7ba512 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -15,6 +15,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Collisions; #endregion Using Statements @@ -73,10 +74,14 @@ public RampPrimitive( Vector3 regularSize = scale.Value; // Ahora puedes usar regularVector, que es de tipo Vector3 BoundingRamp = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + /*BoundingRamp = new OrientedBoundingBox(regularCoordinates, regularSize); + if(rotation.HasValue) + { + Matrix rotationOBB = (Matrix)rotation; + BoundingRamp.Rotate(rotationOBB); + }*/ } - - InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index a2cec1c91..344197abd 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -66,18 +66,18 @@ public Face(Vector3 normal, Vector3[] vertices) Vector3 LightPos { get; set; } public Matrix Spin; - Vector3 startPos; + //Vector3 startPos; - public Vector3 ForwardVector=Vector3.UnitX; + public Vector3 ForwardVector = Vector3.UnitX; - public Vector3 RightVector=Vector3.UnitZ; + public Vector3 RightVector = Vector3.UnitZ; public Character(ContentManager content, Stage stage, List entities) { Content = content; myEntities = entities; Spin = Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); - startPos=stage.CharacterInitialPosition; + //startPos=stage.CharacterInitialPosition; ActualStage = stage; @@ -234,18 +234,14 @@ private void SwitchMaterial() public float DistanceToGround(Vector3 pos) { float dist = 1000000.0f; - foreach (Entity entity in myEntities) + foreach (BoundingBox box in ActualStage.Colliders) { - if (entity is CubePrimitive) - { - CubePrimitive entityAux = (CubePrimitive)entity; - Ray tempRay = new Ray(pos, -Vector3.Up); - float? tempDist = tempRay.Intersects(entityAux.BoundingCube); + Ray tempRay = new Ray(pos, -Vector3.Up); + float? tempDist = tempRay.Intersects(box); - if (dist > tempDist) - { - dist = (float)tempDist; - } + if (dist > tempDist) + { + dist = (float)tempDist; } } @@ -254,18 +250,13 @@ public float DistanceToGround(Vector3 pos) public bool IsOnGround(Vector3 pos) { - foreach (Entity entity in myEntities) + foreach (BoundingBox box in ActualStage.Colliders) { - if (entity is CubePrimitive) + Ray tempRay = new Ray(pos, -Vector3.Up); + float? dist = tempRay.Intersects(box); + if (dist.HasValue && dist <= 12.5f) { - CubePrimitive entityAux = (CubePrimitive)entity; - Ray tempRay = new Ray(pos, -Vector3.Up); - float? dist = tempRay.Intersects(entityAux.BoundingCube); - - if (dist.HasValue && dist < 9.8f) - { - return true; - } + return true; } } return false; @@ -273,127 +264,16 @@ public bool IsOnGround(Vector3 pos) public bool IsColliding() { - foreach (Entity entity in myEntities) + foreach (BoundingBox box in ActualStage.Colliders) { - if (entity is CubePrimitive) + if (EsferaBola.Intersects(box)) { - CubePrimitive entityAux = (CubePrimitive)entity; - if (EsferaBola.Intersects(entityAux.BoundingCube)) - { - return true; - } + return true; } } return false; } - public void ProcessCollision(Vector3 LocalVelocity, float deltaTime) - { - Vector3 oldPosition = Position; - Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; - Vector3 newPosition = oldPosition + movement; - - UpdateBBSphere(newPosition); - - bool collisionDetected = false; - bool isOnGround = IsOnGround(newPosition); // Verificar si está en el suelo en la nueva posición - - foreach (Entity entity in myEntities) - { - if (entity is CubePrimitive) - { - CubePrimitive entityAux = (CubePrimitive)entity; - if (EsferaBola.Intersects(entityAux.BoundingCube)) - { - collisionDetected = true; - - // Manejar la colisión - Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); - - // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) - if (Math.Abs(collisionNormal.Y) > 0.9) // Ajusta este valor según tu escenario - { - isOnGround = true; - - // Resolver la posición después de la colisión - newPosition = ResolveCollision(oldPosition, newPosition, collisionNormal); - - // Actualizar la esfera de colisión - UpdateBBSphere(newPosition); - } - - // Puedes hacer más ajustes según tu lógica específica de juego - // Por ejemplo, ajustar la velocidad según la normal de la colisión - // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); - } - } - } - - // Permitir el movimiento horizontal si no está en el suelo - if (isOnGround) - { - /*newPosition.X += LocalVelocity.X / deltaTime; - newPosition.Z += LocalVelocity.Z / deltaTime;*/ - newPosition.Y = oldPosition.Y; - } - - // Actualizar la posición solo si no hubo colisión con el suelo o está en el suelo - if (!collisionDetected || isOnGround) - { - Position = newPosition; - UpdateBBSphere(Position); - } - } - - - - public void ProcessCollision_Old(Vector3 LocalVelocity, float deltaTime) - { - Vector3 oldPosition = Position; - Vector3 movement = LocalVelocity * deltaTime * deltaTime * 0.5f; - Vector3 newPosition = oldPosition + movement; - - UpdateBBSphere(newPosition); - int steps = 1000; - bool neverFound = true; - foreach (Entity entity in myEntities) - { - if (entity is CubePrimitive) - { - CubePrimitive entityAux = (CubePrimitive)entity; - if (EsferaBola.Intersects(entityAux.BoundingCube)) - { - neverFound = false; - if (IsOnGround(newPosition)) - { - //LocalVelocity = new Vector3(LocalVelocity.X, 0.0f, LocalVelocity.Z); - } - - bool intersecting = true; - float moveFactor = 1.0f; - while (intersecting && steps > 0) - { - steps -= 1; - movement = LocalVelocity * deltaTime * deltaTime * 0.5f; - newPosition = oldPosition + movement * moveFactor; - UpdateBBSphere(newPosition); - intersecting = EsferaBola.Intersects(entityAux.BoundingCube); - moveFactor = moveFactor / 2.0f; - } - - Position = newPosition; - UpdateBBSphere(Position); - } - } - } - - if (neverFound) - { - Position = newPosition; - UpdateBBSphere(Position); - } - } - public static Vector3 GetCollisionPoint(BoundingSphere sphere, BoundingBox box) { // Encuentra el punto más cercano en la superficie de la caja al centro de la esfera @@ -417,11 +297,12 @@ public static Vector3 GetCollisionPoint(BoundingSphere sphere, BoundingBox box) return collisionPoint; } - Vector3 getCollisionNormalNEW(BoundingSphere sphere, BoundingBox box){ + Vector3 getCollisionNormalNEW(BoundingSphere sphere, BoundingBox box) + { Vector3 puntoContacto = GetCollisionPoint(sphere, box); - return Vector3.Normalize(sphere.Center-puntoContacto); + return Vector3.Normalize(sphere.Center - puntoContacto); } - public void ProcessCollisionNEW( float deltaTime) + public void ProcessCollisionNEW(float deltaTime) { Vector3 oldPosition = Position; Vector3 movement = Velocity * deltaTime * deltaTime * 0.5f; @@ -431,46 +312,31 @@ public void ProcessCollisionNEW( float deltaTime) bool collisionDetected = false; bool isOnGround = IsOnGround(newPosition); // Verificar si está en el suelo en la nueva posición + //bool isOnGround = false; - foreach (Entity entity in myEntities) + foreach (BoundingBox collider in ActualStage.Colliders) { - if (entity is CubePrimitive) + if (EsferaBola.Intersects(collider)) { - CubePrimitive entityAux = (CubePrimitive)entity; - if (EsferaBola.Intersects(entityAux.BoundingCube)) + collisionDetected = true; + + // Manejar la colisión + Vector3 surfaceNormal = getCollisionNormalNEW(EsferaBola, collider); + + // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) + if (Math.Abs(surfaceNormal.Y) > 0f) // Ajusta este valor según tu escenario { - collisionDetected = true; - - // Manejar la colisión - Vector3 collisionNormal = GetCollisionNormal(entityAux.BoundingCube); - //Vector3 surfaceNormal = GetCollisionSurfaceNormal(EsferaBola, entityAux.BoundingCube); - Vector3 surfaceNormal = getCollisionNormalNEW(EsferaBola, entityAux.BoundingCube); - - // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) - if (Math.Abs(collisionNormal.Y) > 0.9) // Ajusta este valor según tu escenario - { - isOnGround = true; - //if(Velocity.Y<0.1) Velocity = new Vector3(Velocity.X, 0, Velocity.Z); - } - Velocity = Vector3.Reflect(Velocity, surfaceNormal) ; - movement = Velocity * deltaTime * deltaTime * 0.5f; - newPosition = oldPosition + movement; - UpdateBBSphere(newPosition); - // Puedes hacer más ajustes según tu lógica específica de juego - // Por ejemplo, ajustar la velocidad según la normal de la colisión - // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); + isOnGround = true; } + Velocity = Vector3.Reflect(Velocity, surfaceNormal); + movement = Velocity * deltaTime * deltaTime * 0.5f; + newPosition = oldPosition + movement; + UpdateBBSphere(newPosition); + // Puedes hacer más ajustes según tu lógica específica de juego + // Por ejemplo, ajustar la velocidad según la normal de la colisión + // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); } } - - - // Permitir el movimiento horizontal si no está en el suelo - if (isOnGround) - { - /*newPosition.X += LocalVelocity.X / deltaTime; - newPosition.Z += LocalVelocity.Z / deltaTime;*/ - newPosition.Y = oldPosition.Y; - } // Actualizar la posición solo si no hubo colisión con el suelo o está en el suelo if (!collisionDetected || isOnGround) @@ -480,115 +346,17 @@ public void ProcessCollisionNEW( float deltaTime) } } - private Vector3 GetCollisionNormal(BoundingBox boundingBox) - { - // Calcula el centro de la caja de colisión - Vector3 boxCenter = (boundingBox.Max + boundingBox.Min) * 0.5f; - - // Calcula el vector desde el centro de la caja de colisión hacia la posición actual - Vector3 collisionVector = Position - boxCenter; - - // Normaliza el vector para obtener la dirección de la normal de la colisión - return Vector3.Normalize(collisionVector); - } - - public static Vector3 GetCollisionSurfaceNormal(BoundingSphere sphere, BoundingBox box) - { - // Calcula el punto más cercano de la caja al centro de la esfera - Vector3 closestPoint = Vector3.Clamp(sphere.Center, box.Min, box.Max); - - // Calcula la diferencia entre el punto más cercano y el centro de la esfera - Vector3 difference = sphere.Center - closestPoint; - - // Determina la cara tocada - if (closestPoint.X == box.Min.X) - { - return Vector3.Left; // Normal (-1, 0, 0) - } - if (closestPoint.X == box.Max.X) - { - return Vector3.Right; // Normal (1, 0, 0) - } - if (closestPoint.Y == box.Min.Y) - { - return Vector3.Down; // Normal (0, -1, 0) - } - if (closestPoint.Y == box.Max.Y) - { - return Vector3.Up; // Normal (0, 1, 0) - } - if (closestPoint.Z == box.Min.Z) - { - return Vector3.Backward; // Normal (0, 0, -1) - } - if (closestPoint.Z == box.Max.Z) - { - return Vector3.Forward; // Normal (0, 0, 1) - } - - return Vector3.Zero; - } - - private Vector3 ResolveCollision(Vector3 oldPosition, Vector3 newPosition, Vector3 collisionNormal) - { - // Calcula el vector desde la posición anterior hacia la nueva posición - Vector3 movementDirection = newPosition - oldPosition; - - // Calcula la distancia que se movió la bola antes de la colisión - float movementDistance = movementDirection.Length(); - - // Si no se movió, no hay colisión que resolver - if (movementDistance == 0) - return newPosition; - - // Normaliza la dirección del movimiento - Vector3 movementDirectionNormalized = movementDirection / movementDistance; - - // Calcula la distancia a lo largo de la normal de la colisión - float distanceAlongNormal = Vector3.Dot(collisionNormal, newPosition - oldPosition); - - // Si la bola se estaba moviendo hacia el objeto (distancia negativa a lo largo de la normal), la refleja - if (distanceAlongNormal < 0) - { - // Calcula la parte de la velocidad que va en la dirección opuesta a la normal - Vector3 velocityParallel = distanceAlongNormal * collisionNormal; - - // Calcula la parte de la velocidad que va en la dirección perpendicular a la normal - Vector3 velocityPerpendicular = newPosition - oldPosition - velocityParallel; - - // Invierte la parte de la velocidad paralela para simular un rebote - newPosition = oldPosition - velocityParallel + velocityPerpendicular; - - // Aplica alguna fricción o amortiguación opcional para reducir la velocidad después del rebote - newPosition -= newPosition * 0.1f; // Ajusta el factor de amortiguación según tu necesidad - } - - // Retorna la nueva posición ajustada después de la resolución de la colisión - return newPosition; - } - - - - private Vector2 pastMousePosition = Vector2.Zero; - //private float MouseSensitivity = 0.3f; - - private Vector3 GetVelocity() + public void ChangeDirection(float angle) { - return Velocity; - } - public void ChangeDirection(float angle){ ForwardVector = Vector3.Transform(Vector3.UnitX, Matrix.CreateRotationY(angle)); RightVector = Vector3.Transform(Vector3.UnitZ, Matrix.CreateRotationY(angle)); } - - private void ProcessMovement(GameTime gameTime) + + private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - var directionX = new Vector3(); - var directionY = new Vector3(); - var directionZ = new Vector3(); float speed = 100f; @@ -602,7 +370,7 @@ private void ProcessMovement(GameTime gameTime) } if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { - Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation) * (- 1); + Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation) * (-1); } if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) @@ -619,9 +387,11 @@ private void ProcessMovement(GameTime gameTime) //Procesamiento del movimiento vertical float distGround = DistanceToGround(Position); - if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround < 12.5f || IsColliding())) + if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround <= 12.5f || IsColliding())) { - Velocity += Vector3.Up * speed * 100; + // Seteo la velocidad vertical en 0 para que el salto sea siempre a la misma distancia + Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); + Velocity += Vector3.Up * speed * 100f; } @@ -631,28 +401,27 @@ private void ProcessMovement(GameTime gameTime) if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) { - Velocity *= (1 - (elapsedTime)); + Velocity *= 1 - elapsedTime; } if (Velocity == Vector3.Zero) BallSpinAxis = Vector3.UnitZ; Rotation = Quaternion.CreateFromAxisAngle(RotationAxis, RotationAngle); - directionX = Vector3.Transform(Vector3.UnitX, Rotation); - directionY = Vector3.Transform(Vector3.UnitY, Rotation); - directionZ = Vector3.Transform(Vector3.UnitZ, Rotation); - Velocity += Acceleration; - //ProcessCollision(Velocity * (directionX + directionY + directionZ), elapsedTime); ProcessCollisionNEW(elapsedTime); MoveTo(Position); - /*if(Position.Y < -100){ - MoveTo(startPos); - UpdateBBSphere(startPos); - } */ + // Resetea la posición inicial del nivel si se cae al vacío + if (Position.Y < -200) + { + Position = ActualStage.CharacterInitialPosition; + Velocity = Vector3.Zero; + MoveTo(Position); + UpdateBBSphere(Position); + } Acceleration = Vector3.Zero; } From f578374eb4e7dd6a75cee0c5fda4b5cbdc0fdcc3 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Sat, 29 Jun 2024 01:57:07 -0300 Subject: [PATCH 53/73] =?UTF-8?q?Limpieza=20de=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/MainCharacter/MainCharacter.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 344197abd..51ae1d8f0 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -31,9 +31,6 @@ public class Character : Entity Material CurrentMaterial = Material.RustedMetal; - - private List myEntities; - //public Vector3 Position; //Vector3 Velocity; //Vector3 Acceleration = Vector3.Zero; @@ -75,9 +72,7 @@ public Face(Vector3 normal, Vector3[] vertices) public Character(ContentManager content, Stage stage, List entities) { Content = content; - myEntities = entities; Spin = Matrix.CreateFromAxisAngle(Vector3.UnitZ, 0); - //startPos=stage.CharacterInitialPosition; ActualStage = stage; @@ -332,9 +327,6 @@ public void ProcessCollisionNEW(float deltaTime) movement = Velocity * deltaTime * deltaTime * 0.5f; newPosition = oldPosition + movement; UpdateBBSphere(newPosition); - // Puedes hacer más ajustes según tu lógica específica de juego - // Por ejemplo, ajustar la velocidad según la normal de la colisión - // LocalVelocity = ModifyVelocity(LocalVelocity, collisionNormal); } } From 6c176987d90a1dc91456ec2cc7028afd072de93e Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sun, 30 Jun 2024 07:32:37 -0300 Subject: [PATCH 54/73] =?UTF-8?q?Agrego=20pantalla=20de=20t=C3=ADtulo=20y?= =?UTF-8?q?=20men=C3=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CascadiaCode/CascadiaCodePL.spritefont | 3 ++ .../CascadiaCode/CascadiaCodePL.ttf | 3 ++ .../CascadiaCode/CascadiaMonoPL.spritefont | 3 ++ .../CascadiaCode/CascadiaMonoPL.ttf | 3 ++ .../SpriteFonts/CascadiaCode/README.md | 3 ++ TGC.MonoGame.TP/UI/Menu.cs | 53 +++++++++++++++++++ TGC.MonoGame.TP/UI/Text.cs | 30 +++++++++++ TGC.MonoGame.TP/UI/TitleScreen.cs | 34 ++++++++++++ 8 files changed, 132 insertions(+) create mode 100644 TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont create mode 100644 TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.ttf create mode 100644 TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont create mode 100644 TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.ttf create mode 100644 TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/README.md create mode 100644 TGC.MonoGame.TP/UI/Menu.cs create mode 100644 TGC.MonoGame.TP/UI/Text.cs create mode 100644 TGC.MonoGame.TP/UI/TitleScreen.cs diff --git a/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont new file mode 100644 index 000000000..dfef2ed04 --- /dev/null +++ b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:614f12e5e8de24b83eea52f603d9c1ecea18ba583aa563ca6fe6a8e47e73a9a3 +size 2081 diff --git a/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.ttf b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.ttf new file mode 100644 index 000000000..959bc1aad --- /dev/null +++ b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaCodePL.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3820b704b8bfe098ff41d8e6d42db603248febf468b4beeff0dc1df3285c283 +size 675392 diff --git a/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont new file mode 100644 index 000000000..211043230 --- /dev/null +++ b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e712d1f58f1e600fdfdf2a305fd7fdf3086519f0c2eea8995d8ede3af7a1eb8 +size 2017 diff --git a/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.ttf b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.ttf new file mode 100644 index 000000000..d24235e0d --- /dev/null +++ b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/CascadiaMonoPL.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f02c890470910330273fd68f268277c9d7fb44298be38e95bbdfa2ad260667f0 +size 651084 diff --git a/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/README.md b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/README.md new file mode 100644 index 000000000..88c81d52c --- /dev/null +++ b/TGC.MonoGame.TP/Content/SpriteFonts/CascadiaCode/README.md @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4428a2c273f8e44c1320e1efd706a64365a5ce4fc3eb099095fa95fae62927ed +size 70 diff --git a/TGC.MonoGame.TP/UI/Menu.cs b/TGC.MonoGame.TP/UI/Menu.cs new file mode 100644 index 000000000..3db229b11 --- /dev/null +++ b/TGC.MonoGame.TP/UI/Menu.cs @@ -0,0 +1,53 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TGC.MonoGame.TP.UI +{ + internal class Menu : Text + { + Option selected; + + public enum Option + { + Resume, + Restart, + GodMode, + SelectStage, + Exit + } + + public void Update() + { + + } + + public override void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + { + + spriteBatch.Begin(); + + var position = CenterText(graphicsDevice, font, "Resume", 1f); + spriteBatch.DrawString(font, "Resume", position, selected == Option.Resume ? Color.White : Color.Gray); + position.Y += 25; + + spriteBatch.DrawString(font, "Restart", position, selected == Option.Restart ? Color.White : Color.Gray); + position.Y += 25; + + spriteBatch.DrawString(font, "God Mode", position, selected == Option.GodMode ? Color.White : Color.Gray); + position.Y += 30; + + spriteBatch.DrawString(font, "Select stage", position, selected == Option.SelectStage ? Color.White : Color.Gray); + position.Y += 30; + + spriteBatch.DrawString(font, "Exit", position, selected == Option.Exit ? Color.White : Color.Gray); + + spriteBatch.End(); + + } + } +} diff --git a/TGC.MonoGame.TP/UI/Text.cs b/TGC.MonoGame.TP/UI/Text.cs new file mode 100644 index 000000000..92012052f --- /dev/null +++ b/TGC.MonoGame.TP/UI/Text.cs @@ -0,0 +1,30 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TGC.MonoGame.TP.UI +{ + public abstract class Text + { + public abstract void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font); + + protected Vector2 CenterText(GraphicsDevice graphicsDevice, SpriteFont font, String text, float scale) + { + Vector2 size = font.MeasureString(text); + return new Vector2((graphicsDevice.Viewport.Width - size.X * scale) / 2, (graphicsDevice.Viewport.Height - size.Y * scale) / 2); + } + + protected void DrawStringWithShadow(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color color, float scale) + { + // shadow + spriteBatch.DrawString(font, text, position + new Vector2(2, 2), Color.Black, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + // text + spriteBatch.DrawString(font, text, position, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + } + + } +} diff --git a/TGC.MonoGame.TP/UI/TitleScreen.cs b/TGC.MonoGame.TP/UI/TitleScreen.cs new file mode 100644 index 000000000..1c5e13fe2 --- /dev/null +++ b/TGC.MonoGame.TP/UI/TitleScreen.cs @@ -0,0 +1,34 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TGC.MonoGame.TP.UI +{ + internal class TitleScreen : Text + { + + const string titleText = "Marble It Down!"; + const float titleScale = 5f; + + const string pressStartText = "Press any key"; + const float pressStartScale = 1f; + + public override void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + { + spriteBatch.Begin(); + + var titlePosition = CenterText(graphicsDevice, font, titleText, titleScale); + DrawStringWithShadow(spriteBatch, font, pressStartText, titlePosition, Color.Yellow, titleScale); + + var pressStartPosition = CenterText(graphicsDevice, font, titleText, titleScale) + new Vector2(0,200); + DrawStringWithShadow(spriteBatch, font, pressStartText, pressStartPosition, Color.White, pressStartScale); + + spriteBatch.End(); + } + + } +} From d55bfc8fa1dcec0f18bd254621e77ade47254faa Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sun, 30 Jun 2024 08:01:13 -0300 Subject: [PATCH 55/73] Modificaciones en TextHelper --- TGC.MonoGame.TP/UI/HUD.cs | 30 +++++++++++++++++++ TGC.MonoGame.TP/UI/Menu.cs | 19 ++++++------ TGC.MonoGame.TP/UI/{Text.cs => TextHelper.cs} | 13 +++++--- TGC.MonoGame.TP/UI/TitleScreen.cs | 12 ++++---- 4 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 TGC.MonoGame.TP/UI/HUD.cs rename TGC.MonoGame.TP/UI/{Text.cs => TextHelper.cs} (56%) diff --git a/TGC.MonoGame.TP/UI/HUD.cs b/TGC.MonoGame.TP/UI/HUD.cs new file mode 100644 index 000000000..133291818 --- /dev/null +++ b/TGC.MonoGame.TP/UI/HUD.cs @@ -0,0 +1,30 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TGC.MonoGame.TP.UI +{ + internal class HUD + { + public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font, float gameTimer, float score) + { + spriteBatch.Begin(); + + // Timer + var timerText = gameTimer.ToString(@"mm\:ss"); + var timerSize = font.MeasureString(timerText); + var timerPosition = TextHelper.CenterText(graphicsDevice, font, timerText, 1f, 10); + spriteBatch.DrawString(font, timerText, timerPosition, Color.White); + + // Score + spriteBatch.DrawString(font, "Score: " + score, new Vector2(10, 10), Color.White); + + spriteBatch.End(); + } + + } +} diff --git a/TGC.MonoGame.TP/UI/Menu.cs b/TGC.MonoGame.TP/UI/Menu.cs index 3db229b11..eafd38f04 100644 --- a/TGC.MonoGame.TP/UI/Menu.cs +++ b/TGC.MonoGame.TP/UI/Menu.cs @@ -8,8 +8,9 @@ namespace TGC.MonoGame.TP.UI { - internal class Menu : Text + internal class Menu { + const float LineSpacing = 25f; Option selected; public enum Option @@ -26,24 +27,24 @@ public void Update() } - public override void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Begin(); - var position = CenterText(graphicsDevice, font, "Resume", 1f); + var position = TextHelper.CenterText(graphicsDevice, font, "Resume", 1f); spriteBatch.DrawString(font, "Resume", position, selected == Option.Resume ? Color.White : Color.Gray); - position.Y += 25; - + + position.Y += LineSpacing; spriteBatch.DrawString(font, "Restart", position, selected == Option.Restart ? Color.White : Color.Gray); - position.Y += 25; - + + position.Y += LineSpacing; spriteBatch.DrawString(font, "God Mode", position, selected == Option.GodMode ? Color.White : Color.Gray); - position.Y += 30; + position.Y += LineSpacing; spriteBatch.DrawString(font, "Select stage", position, selected == Option.SelectStage ? Color.White : Color.Gray); - position.Y += 30; + position.Y += LineSpacing; spriteBatch.DrawString(font, "Exit", position, selected == Option.Exit ? Color.White : Color.Gray); spriteBatch.End(); diff --git a/TGC.MonoGame.TP/UI/Text.cs b/TGC.MonoGame.TP/UI/TextHelper.cs similarity index 56% rename from TGC.MonoGame.TP/UI/Text.cs rename to TGC.MonoGame.TP/UI/TextHelper.cs index 92012052f..27e646fb3 100644 --- a/TGC.MonoGame.TP/UI/Text.cs +++ b/TGC.MonoGame.TP/UI/TextHelper.cs @@ -8,17 +8,22 @@ namespace TGC.MonoGame.TP.UI { - public abstract class Text + public class TextHelper { - public abstract void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font); - protected Vector2 CenterText(GraphicsDevice graphicsDevice, SpriteFont font, String text, float scale) + public static Vector2 CenterText(GraphicsDevice graphicsDevice, SpriteFont font, String text, float scale) { Vector2 size = font.MeasureString(text); return new Vector2((graphicsDevice.Viewport.Width - size.X * scale) / 2, (graphicsDevice.Viewport.Height - size.Y * scale) / 2); } - protected void DrawStringWithShadow(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color color, float scale) + public static Vector2 CenterText(GraphicsDevice graphicsDevice, SpriteFont font, String text, float scale, float yCoordinate) + { + Vector2 size = font.MeasureString(text); + return new Vector2((graphicsDevice.Viewport.Width - size.X * scale) / 2, yCoordinate); + } + + public static void DrawStringWithShadow(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color color, float scale) { // shadow spriteBatch.DrawString(font, text, position + new Vector2(2, 2), Color.Black, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); diff --git a/TGC.MonoGame.TP/UI/TitleScreen.cs b/TGC.MonoGame.TP/UI/TitleScreen.cs index 1c5e13fe2..4c23bd0b7 100644 --- a/TGC.MonoGame.TP/UI/TitleScreen.cs +++ b/TGC.MonoGame.TP/UI/TitleScreen.cs @@ -8,7 +8,7 @@ namespace TGC.MonoGame.TP.UI { - internal class TitleScreen : Text + internal class TitleScreen { const string titleText = "Marble It Down!"; @@ -17,15 +17,15 @@ internal class TitleScreen : Text const string pressStartText = "Press any key"; const float pressStartScale = 1f; - public override void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Begin(); - var titlePosition = CenterText(graphicsDevice, font, titleText, titleScale); - DrawStringWithShadow(spriteBatch, font, pressStartText, titlePosition, Color.Yellow, titleScale); + var titlePosition = TextHelper.CenterText(graphicsDevice, font, titleText, titleScale); + TextHelper.DrawStringWithShadow(spriteBatch, font, pressStartText, titlePosition, Color.Yellow, titleScale); - var pressStartPosition = CenterText(graphicsDevice, font, titleText, titleScale) + new Vector2(0,200); - DrawStringWithShadow(spriteBatch, font, pressStartText, pressStartPosition, Color.White, pressStartScale); + var pressStartPosition = TextHelper.CenterText(graphicsDevice, font, titleText, titleScale) + new Vector2(0,200); + TextHelper.DrawStringWithShadow(spriteBatch, font, pressStartText, pressStartPosition, Color.White, pressStartScale); spriteBatch.End(); } From 0f96fe7721e956519855bc175f7aee9a0baee084 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sun, 30 Jun 2024 09:09:12 -0300 Subject: [PATCH 56/73] Correcciones en TitleScreen --- TGC.MonoGame.TP/UI/TitleScreen.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/UI/TitleScreen.cs b/TGC.MonoGame.TP/UI/TitleScreen.cs index 4c23bd0b7..ff698942b 100644 --- a/TGC.MonoGame.TP/UI/TitleScreen.cs +++ b/TGC.MonoGame.TP/UI/TitleScreen.cs @@ -12,19 +12,19 @@ internal class TitleScreen { const string titleText = "Marble It Down!"; - const float titleScale = 5f; + const float titleScale = 3f; const string pressStartText = "Press any key"; const float pressStartScale = 1f; - public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + public static void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Begin(); var titlePosition = TextHelper.CenterText(graphicsDevice, font, titleText, titleScale); - TextHelper.DrawStringWithShadow(spriteBatch, font, pressStartText, titlePosition, Color.Yellow, titleScale); + TextHelper.DrawStringWithShadow(spriteBatch, font, titleText, titlePosition, Color.Yellow, titleScale); - var pressStartPosition = TextHelper.CenterText(graphicsDevice, font, titleText, titleScale) + new Vector2(0,200); + var pressStartPosition = TextHelper.CenterText(graphicsDevice, font, pressStartText, pressStartScale, graphicsDevice.Viewport.Height - 100); TextHelper.DrawStringWithShadow(spriteBatch, font, pressStartText, pressStartPosition, Color.White, pressStartScale); spriteBatch.End(); From ae5636566cd285a0cfcc74193c2eed24f9dd7a13 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sun, 30 Jun 2024 10:08:27 -0300 Subject: [PATCH 57/73] Agrego SpriteFont al ContentManager --- TGC.MonoGame.TP/Content/Content.mgcb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 3f8b914fc..7f12c1dcd 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -144,6 +144,20 @@ /processorParam:TextureFormat=Compressed /build:Models/tgc-logo/tgc-logo.fbx +#begin SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:SpriteFonts/CascadiaCode/CascadiaCodePL.spritefont + +#begin SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:SpriteFonts/CascadiaCode/CascadiaMonoPL.spritefont + #begin Textures/floor/tiling-base.png /importer:TextureImporter /processor:TextureProcessor From 7848b2137f11c6764a6dc6cf7fd551311a62462c Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Sun, 30 Jun 2024 10:13:56 -0300 Subject: [PATCH 58/73] =?UTF-8?q?Elimino=20archivo=20de=20m=C3=A1s=20inclu?= =?UTF-8?q?idos=20en=20el=20=C3=BAltimo=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/TGCGame.cs | 63 ++++++++++++++++++++++--------- TGC.MonoGame.TP/UI/HUD.cs | 11 ++++-- TGC.MonoGame.TP/UI/Menu.cs | 1 - TGC.MonoGame.TP/UI/TextHelper.cs | 6 +++ TGC.MonoGame.TP/UI/TextUI.cs | 9 +++++ TGC.MonoGame.TP/UI/TitleScreen.cs | 8 +++- 6 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 TGC.MonoGame.TP/UI/TextUI.cs diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 1e8f06335..546ecc6d2 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -9,6 +9,7 @@ using TGC.MonoGame.TP.Collisions; using TGC.MonoGame.TP.MainCharacter; using TGC.MonoGame.TP.Stages; +using TGC.MonoGame.TP.UI; namespace TGC.MonoGame.TP { @@ -48,6 +49,9 @@ public TGCGame() private GraphicsDeviceManager Graphics { get; } private SpriteBatch SpriteBatch { get; set; } + private SpriteFont SpriteFont { get; set; } + private TextUI UIStatus = TextUI.Title; + private TimeSpan Timer = TimeSpan.Zero; // Camera to draw the scene private FollowCamera FollowCamera { get; set; } @@ -89,7 +93,7 @@ protected override void Initialize() base.Initialize(); } - private SpriteFont SpriteFont{get;set;} + /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo, despues de Initialize. /// Escribir aqui el codigo de inicializacion: cargar modelos, texturas, estructuras de optimizacion, el procesamiento @@ -97,12 +101,13 @@ protected override void Initialize() /// public Effect BallEffect; - protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. SpriteBatch = new SpriteBatch(GraphicsDevice); + SpriteFont = Content.Load(ContentFolderSpriteFonts + "CascadiaCode/CascadiaCodePL"); + Entities = new List(); Stage = new Stage_01(GraphicsDevice, Content); @@ -147,27 +152,37 @@ private void MergeEntities(List Track, List protected override void Update(GameTime gameTime) { - if(Keyboard.GetState().IsKeyDown(Keys.Escape)) + if (UIStatus == TextUI.HUD) { - //Salgo del juego. - Exit(); - } - + Timer += gameTime.ElapsedGameTime; - MainCharacter.Update(gameTime); + if (Keyboard.GetState().IsKeyDown(Keys.Escape)) + { + //Salgo del juego. + Exit(); + } - + MainCharacter.Update(gameTime); + FollowCamera.Update(gameTime, MainCharacter.World); + Stage.CamPosition = FollowCamera.CamPosition; - FollowCamera.Update(gameTime, MainCharacter.World); - - Stage.CamPosition=FollowCamera.CamPosition; - - MainCharacter.ChangeDirection(FollowCamera.CamRotation); - BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); - - //World = Matrix.CreateRotationY(Rotation); + MainCharacter.ChangeDirection(FollowCamera.CamRotation); + BallEffect.Parameters["eyePosition"].SetValue(FollowCamera.CamPosition); + //World = Matrix.CreateRotationY(Rotation); + } + else if (UIStatus == TextUI.Title) + { + if (TitleScreen.PressAnyKey()) + { + UIStatus = TextUI.HUD; + } + } + else if (UIStatus == TextUI.Menu) + { + //Menu.Update(); + } base.Update(gameTime); } @@ -197,6 +212,20 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.RasterizerState = originalRasterizerState; + + if (UIStatus == TextUI.HUD) + { + HUD.Draw(GraphicsDevice, SpriteBatch, SpriteFont, Timer, 0); + } + else if (UIStatus == TextUI.Title) + { + TitleScreen.Draw(GraphicsDevice, SpriteBatch, SpriteFont); + } + else if (UIStatus == TextUI.Menu) + { + // TODO + // Menu.Draw(); + } //base.Draw(gameTime); } diff --git a/TGC.MonoGame.TP/UI/HUD.cs b/TGC.MonoGame.TP/UI/HUD.cs index 133291818..02f8a86c0 100644 --- a/TGC.MonoGame.TP/UI/HUD.cs +++ b/TGC.MonoGame.TP/UI/HUD.cs @@ -10,18 +10,21 @@ namespace TGC.MonoGame.TP.UI { internal class HUD { - public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font, float gameTimer, float score) + const float timerScale = 1.5f; + + public static void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font, TimeSpan gameTimer, float score) { spriteBatch.Begin(); // Timer var timerText = gameTimer.ToString(@"mm\:ss"); var timerSize = font.MeasureString(timerText); - var timerPosition = TextHelper.CenterText(graphicsDevice, font, timerText, 1f, 10); - spriteBatch.DrawString(font, timerText, timerPosition, Color.White); + var timerPosition = TextHelper.CenterText(graphicsDevice, font, timerText, timerScale, 10); + TextHelper.DrawString(spriteBatch, font, timerText, timerPosition, Color.White, timerScale); + // TODO: ¿agregar score? // Score - spriteBatch.DrawString(font, "Score: " + score, new Vector2(10, 10), Color.White); + // TextHelper.DrawString(spriteBatch, font, "Score: " + score, new Vector2(10, 10), Color.White, 1.5f); spriteBatch.End(); } diff --git a/TGC.MonoGame.TP/UI/Menu.cs b/TGC.MonoGame.TP/UI/Menu.cs index eafd38f04..67910ebc0 100644 --- a/TGC.MonoGame.TP/UI/Menu.cs +++ b/TGC.MonoGame.TP/UI/Menu.cs @@ -24,7 +24,6 @@ public enum Option public void Update() { - } public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) diff --git a/TGC.MonoGame.TP/UI/TextHelper.cs b/TGC.MonoGame.TP/UI/TextHelper.cs index 27e646fb3..0aaf0bae5 100644 --- a/TGC.MonoGame.TP/UI/TextHelper.cs +++ b/TGC.MonoGame.TP/UI/TextHelper.cs @@ -23,6 +23,12 @@ public static Vector2 CenterText(GraphicsDevice graphicsDevice, SpriteFont font, return new Vector2((graphicsDevice.Viewport.Width - size.X * scale) / 2, yCoordinate); } + public static void DrawString(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color color, float scale) + { + // text + spriteBatch.DrawString(font, text, position, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + } + public static void DrawStringWithShadow(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color color, float scale) { // shadow diff --git a/TGC.MonoGame.TP/UI/TextUI.cs b/TGC.MonoGame.TP/UI/TextUI.cs new file mode 100644 index 000000000..b464230d1 --- /dev/null +++ b/TGC.MonoGame.TP/UI/TextUI.cs @@ -0,0 +1,9 @@ +namespace TGC.MonoGame.TP.UI +{ + public enum TextUI + { + Title, + HUD, + Menu + } +} diff --git a/TGC.MonoGame.TP/UI/TitleScreen.cs b/TGC.MonoGame.TP/UI/TitleScreen.cs index ff698942b..d416f6aad 100644 --- a/TGC.MonoGame.TP/UI/TitleScreen.cs +++ b/TGC.MonoGame.TP/UI/TitleScreen.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Linq; @@ -10,13 +11,18 @@ namespace TGC.MonoGame.TP.UI { internal class TitleScreen { - const string titleText = "Marble It Down!"; const float titleScale = 3f; const string pressStartText = "Press any key"; const float pressStartScale = 1f; + public static Boolean PressAnyKey() + { + KeyboardState keyboardState = Keyboard.GetState(); + return keyboardState.GetPressedKeyCount() > 0; + } + public static void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Begin(); From e42f5c34d814dc79cc8b9dfd7f5f7aa139fe755a Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Sun, 30 Jun 2024 23:57:36 -0300 Subject: [PATCH 59/73] Resuelto colisiones con OBB --- .../Collisions/BoundingVolumesExtensions.cs | 53 +++++++ .../Collisions/OrientedBoundingBox.cs | 104 ++++++++++++- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 15 +- .../CustomPrimitives/RampPrimitive.cs | 16 +- .../MainCharacter/MainCharacter.cs | 142 +++++++----------- TGC.MonoGame.TP/Stages/Stage.cs | 7 +- 6 files changed, 225 insertions(+), 112 deletions(-) diff --git a/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs index e29bbb8fe..407292e2b 100644 --- a/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs +++ b/TGC.MonoGame.TP/Collisions/BoundingVolumesExtensions.cs @@ -91,6 +91,22 @@ public static Vector3 ClosestPoint(BoundingBox box, Vector3 point) return point; } + /// + /// Gets the closest point to the box. + /// + /// A to calculate the closest point + /// The point to find the closest point from + /// The position inside the box that is closer to the given point + public static Vector3 ClosestPoint(OrientedBoundingBox box, Vector3 point) + { + var min = -box.Extents; + var max = box.Extents; + point.X = MathHelper.Clamp(point.X, min.X, max.X); + point.Y = MathHelper.Clamp(point.Y, min.Y, max.Y); + point.Z = MathHelper.Clamp(point.Z, min.Z, max.Z); + return point; + } + /// /// Gets the normal vector from a point in the box surface. /// @@ -128,6 +144,43 @@ public static Vector3 GetNormalFromPoint(BoundingBox box, Vector3 point) return normal; } + /// + /// Gets the normal vector from a point in the box surface. + /// + /// A to calculate the normal + /// The point in the surface of the box + /// The normal vector of the surface in which the point is in + public static Vector3 GetNormalFromPoint(OrientedBoundingBox box, Vector3 point) + { + var normal = Vector3.Zero; + var min = float.MaxValue; + + point -= box.Center; + var extents = box.Extents; + + var distance = MathF.Abs(extents.X - Math.Abs(point.X)); + if (distance < min) + { + min = distance; + normal = Math.Sign(point.X) * Vector3.UnitX; + // Cardinal axis for X + } + distance = Math.Abs(extents.Y - Math.Abs(point.Y)); + if (distance < min) + { + min = distance; + normal = Math.Sign(point.Y) * Vector3.UnitY; + // Cardinal axis for Y + } + distance = Math.Abs(extents.Z - Math.Abs(point.Z)); + if (distance < min) + { + normal = Math.Sign(point.Z) * Vector3.UnitZ; + // Cardinal axis for Z + } + return normal; + } + /// /// Creates a BoundingBox from a Matrix. /// diff --git a/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs index 550fb0a7d..8052b4f4a 100644 --- a/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs +++ b/TGC.MonoGame.TP/Collisions/OrientedBoundingBox.cs @@ -218,9 +218,9 @@ public bool Intersects(OrientedBoundingBox box) var result = ToFloatArray(Matrix.Multiply(Orientation, box.Orientation)); for (var i = 0; i < 3; i++) - for (var j = 0; j < 3; j++) - R[i, j] = result[i * 3 + j]; - + for (var j = 0; j < 3; j++) + R[i, j] = result[i * 3 + j]; + // Compute translation vector t var tVec = box.Center - Center; @@ -319,7 +319,7 @@ public bool Intersects(BoundingBox box) /// The ray to test /// The length in the ray direction from the ray origin /// True if the OBB intersects the Ray - public bool Intersects(Ray ray, out float? result) + public float? Intersects(Ray ray) { //Transform Ray to OBB-Space var rayOrigin = ray.Position; @@ -335,10 +335,9 @@ public bool Intersects(Ray ray, out float? result) var enclosingBox = new BoundingBox(-Extents, Extents); // Perform Ray-AABB intersection - var testResult = enclosingBox.Intersects(rayInOBBSpace); - result = testResult; + var result = enclosingBox.Intersects(rayInOBBSpace); - return testResult != null; + return result; } @@ -358,7 +357,50 @@ public bool Intersects(BoundingSphere sphere) return aabb.Intersects(obbSpaceSphere); } + public static OrientedBoundingBox ComputeOBBFromTriangle(Vector3[] vertices) + { + // Calcular el centro promedio de todos los vértices de la rampa + Vector3 center = Vector3.Zero; + foreach (var vertex in vertices) + { + center += vertex; + } + center /= vertices.Length; + + // Calcular los ejes principales de la OBB + Vector3 axis1 = Vector3.Normalize(vertices[1] - vertices[0]); + Vector3 axis2 = Vector3.Normalize(Vector3.Cross(vertices[2] - vertices[0], axis1)); + Vector3 axis3 = Vector3.Cross(axis1, axis2); + + // Calcular las dimensiones de la OBB + float maxLength1 = 0; + float maxLength2 = 0; + float maxLength3 = 0; + + foreach (var vertex in vertices) + { + float length1 = Vector3.Dot(vertex - center, axis1); + float length2 = Vector3.Dot(vertex - center, axis2); + float length3 = Vector3.Dot(vertex - center, axis3); + + maxLength1 = Math.Max(maxLength1, Math.Abs(length1)); + maxLength2 = Math.Max(maxLength2, Math.Abs(length2)); + maxLength3 = Math.Max(maxLength3, Math.Abs(length3)); + } + // Construir la matriz de transformación de la OBB + Matrix transform = Matrix.Identity; + transform.Right = axis1 * maxLength1; // Eje X + transform.Up = axis2 * maxLength2; // Eje Y + transform.Forward = axis3 * maxLength3; // Eje Z + transform.Translation = center; + + // Crear y devolver la OBB + Vector3 size = new(maxLength1 * 2, maxLength2 * 2, maxLength3 * 2); // Tamaño basado en las longitudes máximas + OrientedBoundingBox boundingTriangle = new(center, size); //OBB auxiliar para poder rotarla + boundingTriangle.Rotate(transform); + return boundingTriangle; + } /// /// Tests the intersection between the OBB and a Plane. @@ -414,6 +456,52 @@ public bool Intersects(BoundingFrustum frustum) return true; } + public Vector3 ClosestPointTo(Vector3 point) + { + // vector from box centre to point + var directionVector = point - Center; + + // for each OBB axis... + // ...project d onto that axis to get the distance + // along the axis of d from the box center + // then if distance farther than the box extents, clamp to the box + // then step that distance along the axis to get world coordinate + + + + var distanceX = Vector3.Dot(directionVector, Orientation.Right); + if (distanceX > Extents.X) + { + distanceX = Extents.X; + } + else if (distanceX < -Extents.X) + { + distanceX = -Extents.X; + } + + var distanceY = Vector3.Dot(directionVector, Orientation.Up); + if (distanceY > Extents.Y) + { + distanceY = Extents.Y; + } + else if (distanceY < -Extents.Y) + { + distanceY = -Extents.Y; + } + + var distanceZ = Vector3.Dot(directionVector, Orientation.Forward); + if (distanceZ > Extents.Z) + { + distanceZ = Extents.Z; + } + else if (distanceZ < -Extents.Z) + { + distanceZ = -Extents.Z; + } + + return Center + distanceX * Orientation.Right + distanceY * Orientation.Up + distanceZ * Orientation.Forward; + } + /// /// Converts a point from OBB-Space to World-Space. /// @@ -425,5 +513,5 @@ public Vector3 ToWorldSpace(Vector3 point) } } - + } diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 81aac3002..d4d237cbc 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -14,6 +14,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using TGC.MonoGame.TP.Collisions; #endregion Using Statements @@ -29,10 +30,7 @@ public class CubePrimitive : GeometricPrimitive /// Constructs a new cube primitive. /// /// - public BoundingBox BoundingCube { get; set; } - private Vector3 minVert; - private Vector3 maxVert; - + public OrientedBoundingBox BoundingCube { get; set; } public CubePrimitive( GraphicsDevice graphicsDevice, ContentManager content, @@ -98,9 +96,14 @@ public CubePrimitive( Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 Vector3 regularSize = scale.Value * 25; // Ahora puedes usar regularVector, que es de tipo Vector3 - BoundingCube = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + //BoundingCube = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + BoundingCube = new OrientedBoundingBox(regularCoordinates, regularSize / 2); + if (rotation.HasValue) + { + Matrix rotationOBB = rotation.Value; + BoundingCube.Rotate(rotationOBB); + } } - InitializePrimitive(graphicsDevice, content); } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 6bf7ba512..0866c62a2 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -25,7 +25,7 @@ namespace TGC.MonoGame.TP.Geometries public class RampPrimitive : CustomPrimitive { - public BoundingBox BoundingRamp { get; set; } + public OrientedBoundingBox BoundingRamp { get; set; } public RampPrimitive( GraphicsDevice graphicsDevice, @@ -71,17 +71,15 @@ public RampPrimitive( if (coordinates.HasValue && scale.HasValue) { Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 - Vector3 regularSize = scale.Value; + Vector3 regularSize = scale.Value * 25; // Ahora puedes usar regularVector, que es de tipo Vector3 - BoundingRamp = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); - /*BoundingRamp = new OrientedBoundingBox(regularCoordinates, regularSize); - if(rotation.HasValue) - { - Matrix rotationOBB = (Matrix)rotation; - BoundingRamp.Rotate(rotationOBB); - }*/ + //BoundingRamp = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); + BoundingRamp = OrientedBoundingBox.ComputeOBBFromTriangle(vertexList); + //BoundingRamp = new OrientedBoundingBox(regularCoordinates, regularSize / 2); } + + InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 51ae1d8f0..9269be3f2 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -11,6 +11,7 @@ using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.MainCharacter; using System.Collections.Generic; +using System.Diagnostics; namespace TGC.MonoGame.TP.MainCharacter { @@ -31,29 +32,15 @@ public class Character : Entity Material CurrentMaterial = Material.RustedMetal; - //public Vector3 Position; - //Vector3 Velocity; - //Vector3 Acceleration = Vector3.Zero; - //Quaternion Rotation = Quaternion.Identity; - //Vector3 RotationAxis = Vector3.UnitY; - //float RotationAngle = 0f; + // Checkpoints + public Vector3 LastCheckpoint; + // Checkpoints // Colisiones public BoundingSphere EsferaBola { get; set; } - public bool OnGround { get; set; } + public Vector3 contactPoint { get; set; } public Stage ActualStage; - public struct Face - { - public Vector3 Normal; - public Vector3[] Vertices; - - public Face(Vector3 normal, Vector3[] vertices) - { - Normal = normal; - Vertices = vertices; - } - } // Colisiones Vector3 BallSpinAxis = Vector3.UnitX; @@ -104,7 +91,7 @@ private void InitializeSphere(Vector3 initialPosition) private void UpdateBBSphere(Vector3 center) { - EsferaBola = new BoundingSphere(center, 10f); + EsferaBola = new BoundingSphere(center, 12.5f); } private void InitializeEffect() @@ -133,6 +120,7 @@ public void Draw(Matrix view, Matrix projection) Effect.Parameters["matInverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(WorldWithBallSpin))); Effect.Parameters["lightPosition"].SetValue(LightPos); Effect.Parameters["lightColor"].SetValue(new Vector3(253, 251, 211)); + Effect.GraphicsDevice.BlendState = BlendState.Opaque; Sphere.Meshes.FirstOrDefault().Draw(); } @@ -228,11 +216,14 @@ private void SwitchMaterial() public float DistanceToGround(Vector3 pos) { - float dist = 1000000.0f; - foreach (BoundingBox box in ActualStage.Colliders) + float dist = 10000000.0f; + //float dist = float.MaxValue; + foreach (OrientedBoundingBox box in ActualStage.Colliders) { + if (box is null) + continue; Ray tempRay = new Ray(pos, -Vector3.Up); - float? tempDist = tempRay.Intersects(box); + float? tempDist = box.Intersects(tempRay); if (dist > tempDist) { @@ -243,13 +234,13 @@ public float DistanceToGround(Vector3 pos) return dist; } - public bool IsOnGround(Vector3 pos) + public bool IsColliding() { - foreach (BoundingBox box in ActualStage.Colliders) + foreach (OrientedBoundingBox box in ActualStage.Colliders) { - Ray tempRay = new Ray(pos, -Vector3.Up); - float? dist = tempRay.Intersects(box); - if (dist.HasValue && dist <= 12.5f) + if (box is null) + continue; + if (box.Intersects(EsferaBola)) { return true; } @@ -257,46 +248,28 @@ public bool IsOnGround(Vector3 pos) return false; } - public bool IsColliding() + public bool IsOnGround(Vector3 pos) { - foreach (BoundingBox box in ActualStage.Colliders) + foreach (OrientedBoundingBox box in ActualStage.Colliders) { - if (EsferaBola.Intersects(box)) + if(box is null) + continue; + Ray tempRay = new Ray(pos, -Vector3.Up); + float? dist = box.Intersects(tempRay); + if (dist.HasValue && dist <= 12.5f) { return true; } } return false; } - - public static Vector3 GetCollisionPoint(BoundingSphere sphere, BoundingBox box) + + Vector3 getCollisionNormalNEW(BoundingSphere sphere, OrientedBoundingBox box) { - // Encuentra el punto más cercano en la superficie de la caja al centro de la esfera - Vector3 closestPoint = Vector3.Clamp(sphere.Center, box.Min, box.Max); - - // Calcula la dirección desde el punto más cercano al centro de la esfera - Vector3 direction = sphere.Center - closestPoint; - - // Si la dirección es cero, el centro de la esfera está dentro de la caja, podemos retornar el punto más cercano - if (direction == Vector3.Zero) - { - return closestPoint; - } - - // Normaliza la dirección - direction.Normalize(); - - // Calcula el punto exacto de colisión en la superficie de la esfera - Vector3 collisionPoint = closestPoint + direction * sphere.Radius; - - return collisionPoint; - } - - Vector3 getCollisionNormalNEW(BoundingSphere sphere, BoundingBox box) - { - Vector3 puntoContacto = GetCollisionPoint(sphere, box); + Vector3 puntoContacto = box.ClosestPointTo(sphere.Center); return Vector3.Normalize(sphere.Center - puntoContacto); } + public void ProcessCollisionNEW(float deltaTime) { Vector3 oldPosition = Position; @@ -305,37 +278,41 @@ public void ProcessCollisionNEW(float deltaTime) UpdateBBSphere(newPosition); - bool collisionDetected = false; - bool isOnGround = IsOnGround(newPosition); // Verificar si está en el suelo en la nueva posición - //bool isOnGround = false; + Vector3 desirePosition = newPosition; + Vector3 surfaceNormal = Vector3.Zero; - foreach (BoundingBox collider in ActualStage.Colliders) + float squareRadius = EsferaBola.Radius * EsferaBola.Radius; + foreach (OrientedBoundingBox collider in ActualStage.Colliders) { - if (EsferaBola.Intersects(collider)) + if (collider is null) + continue; + + Vector3 puntoContacto = collider.ClosestPointTo(EsferaBola.Center); + float distanceToSquared = Vector3.DistanceSquared(puntoContacto, EsferaBola.Center); + if(distanceToSquared <= squareRadius) { - collisionDetected = true; + contactPoint = puntoContacto; // Manejar la colisión - Vector3 surfaceNormal = getCollisionNormalNEW(EsferaBola, collider); - - // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) - if (Math.Abs(surfaceNormal.Y) > 0f) // Ajusta este valor según tu escenario - { - isOnGround = true; - } - Velocity = Vector3.Reflect(Velocity, surfaceNormal); - movement = Velocity * deltaTime * deltaTime * 0.5f; - newPosition = oldPosition + movement; + surfaceNormal = getCollisionNormalNEW(EsferaBola, collider); + + // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) + newPosition = contactPoint + surfaceNormal * EsferaBola.Radius; UpdateBBSphere(newPosition); + } } - // Actualizar la posición solo si no hubo colisión con el suelo o está en el suelo - if (!collisionDetected || isOnGround) - { - Position = newPosition; - UpdateBBSphere(Position); - } + // Calculamos la diferencia entre la nueva posición y la "anterior" + float difference = Vector3.Distance(newPosition, desirePosition); + + // Modificamos la velocidad en base a la colisión + float newVelocity = Vector3.Dot(Velocity, -surfaceNormal); + Velocity += 1.5f * newVelocity * surfaceNormal; + + Position = newPosition; + UpdateBBSphere(newPosition); + } public void ChangeDirection(float angle) @@ -344,7 +321,6 @@ public void ChangeDirection(float angle) RightVector = Vector3.Transform(Vector3.UnitZ, Matrix.CreateRotationY(angle)); } - private void ProcessMovement(GameTime gameTime) { // Aca deberiamos poner toda la logica de actualizacion del juego. @@ -355,7 +331,7 @@ private void ProcessMovement(GameTime gameTime) // Capturar Input teclado var keyboardState = Keyboard.GetState(); - // Procesamiento del movimiento horizontal + // Procesamiento del movimiento horizontal if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation); //amtes unitx @@ -372,21 +348,19 @@ private void ProcessMovement(GameTime gameTime) if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { Acceleration += Vector3.Transform(RightVector * speed, Rotation) * (-1); - } Acceleration += new Vector3(0f, -100f, 0f); - + //Procesamiento del movimiento vertical float distGround = DistanceToGround(Position); - if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround <= 12.5f || IsColliding())) + if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround <= 12.5f || (IsColliding() && IsOnGround(Position)))) { // Seteo la velocidad vertical en 0 para que el salto sea siempre a la misma distancia Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); Velocity += Vector3.Up * speed * 100f; } - Vector3 HorizontalVelocity = new Vector3(Velocity.X, 0, Velocity.Z); BallSpinAngle += HorizontalVelocity.Length() * elapsedTime * elapsedTime / (MathHelper.Pi * 12.5f); BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index c480c02ee..cff7e0f05 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -42,10 +42,7 @@ public void LoadSpriteBatch(){ //COLISIONES - public List Colliders; - public Matrix BoxWorld { get; set; } //Matriz de mundo - public Matrix[] StairsWorld { get; set; } //Escaleras - public Matrix FloorWorld { get; set; } //Colisión con el piso + public List Colliders; //COLISIONES @@ -82,7 +79,7 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char CharacterInitialPosition = characterPosition; - Colliders = new List(); + Colliders = new List(); LoadTrack(); LoadObstacles(); From d33eff4accf76da55e598dac6ef04ee30a0705ca Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Mon, 1 Jul 2024 08:55:01 -0300 Subject: [PATCH 60/73] Agrego UIManager y Menu --- TGC.MonoGame.TP/UI/GameStatus.cs | 10 +++ TGC.MonoGame.TP/UI/Menu.cs | 23 ++---- TGC.MonoGame.TP/UI/MenuOption.cs | 11 +++ TGC.MonoGame.TP/UI/TextUI.cs | 9 --- TGC.MonoGame.TP/UI/UIManager.cs | 124 +++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 25 deletions(-) create mode 100644 TGC.MonoGame.TP/UI/GameStatus.cs create mode 100644 TGC.MonoGame.TP/UI/MenuOption.cs delete mode 100644 TGC.MonoGame.TP/UI/TextUI.cs create mode 100644 TGC.MonoGame.TP/UI/UIManager.cs diff --git a/TGC.MonoGame.TP/UI/GameStatus.cs b/TGC.MonoGame.TP/UI/GameStatus.cs new file mode 100644 index 000000000..cc704b1d9 --- /dev/null +++ b/TGC.MonoGame.TP/UI/GameStatus.cs @@ -0,0 +1,10 @@ +namespace TGC.MonoGame.TP.UI +{ + public enum GameStatus + { + Title, + Playing, + Menu, + Exit + } +} diff --git a/TGC.MonoGame.TP/UI/Menu.cs b/TGC.MonoGame.TP/UI/Menu.cs index 67910ebc0..5319b2a49 100644 --- a/TGC.MonoGame.TP/UI/Menu.cs +++ b/TGC.MonoGame.TP/UI/Menu.cs @@ -11,40 +11,31 @@ namespace TGC.MonoGame.TP.UI internal class Menu { const float LineSpacing = 25f; - Option selected; - public enum Option + public static void Update() { - Resume, - Restart, - GodMode, - SelectStage, - Exit - } - public void Update() - { } - public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + public static void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font, MenuOption selected) { spriteBatch.Begin(); var position = TextHelper.CenterText(graphicsDevice, font, "Resume", 1f); - spriteBatch.DrawString(font, "Resume", position, selected == Option.Resume ? Color.White : Color.Gray); + spriteBatch.DrawString(font, "Resume", position, selected == MenuOption.Resume ? Color.White : Color.Gray); position.Y += LineSpacing; - spriteBatch.DrawString(font, "Restart", position, selected == Option.Restart ? Color.White : Color.Gray); + spriteBatch.DrawString(font, "Restart", position, selected == MenuOption.Restart ? Color.White : Color.Gray); position.Y += LineSpacing; - spriteBatch.DrawString(font, "God Mode", position, selected == Option.GodMode ? Color.White : Color.Gray); + spriteBatch.DrawString(font, "God Mode", position, selected == MenuOption.GodMode ? Color.White : Color.Gray); position.Y += LineSpacing; - spriteBatch.DrawString(font, "Select stage", position, selected == Option.SelectStage ? Color.White : Color.Gray); + spriteBatch.DrawString(font, "Select stage", position, selected == MenuOption.SelectStage ? Color.White : Color.Gray); position.Y += LineSpacing; - spriteBatch.DrawString(font, "Exit", position, selected == Option.Exit ? Color.White : Color.Gray); + spriteBatch.DrawString(font, "Exit", position, selected == MenuOption.Exit ? Color.White : Color.Gray); spriteBatch.End(); diff --git a/TGC.MonoGame.TP/UI/MenuOption.cs b/TGC.MonoGame.TP/UI/MenuOption.cs new file mode 100644 index 000000000..cca3abb14 --- /dev/null +++ b/TGC.MonoGame.TP/UI/MenuOption.cs @@ -0,0 +1,11 @@ +namespace TGC.MonoGame.TP.UI +{ + public enum MenuOption + { + Resume, + Restart, + GodMode, + SelectStage, + Exit + } +} diff --git a/TGC.MonoGame.TP/UI/TextUI.cs b/TGC.MonoGame.TP/UI/TextUI.cs deleted file mode 100644 index b464230d1..000000000 --- a/TGC.MonoGame.TP/UI/TextUI.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace TGC.MonoGame.TP.UI -{ - public enum TextUI - { - Title, - HUD, - Menu - } -} diff --git a/TGC.MonoGame.TP/UI/UIManager.cs b/TGC.MonoGame.TP/UI/UIManager.cs new file mode 100644 index 000000000..75a6b6bf4 --- /dev/null +++ b/TGC.MonoGame.TP/UI/UIManager.cs @@ -0,0 +1,124 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TGC.MonoGame.TP.UI +{ + internal class UIManager + { + private GraphicsDevice _graphicsDevice; + private SpriteBatch _spriteBatch; + private SpriteFont _spriteFont; + + public GameStatus UIStatus { get; set; } + public MenuOption MenuStatus { get; set; } + public TimeSpan Timer { get; set; } + public int Score { get; set; } + + private KeyboardState _previouskeyboardState; + + public UIManager(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, SpriteFont font) + { + _graphicsDevice = graphicsDevice; + _spriteBatch = spriteBatch; + _spriteFont = font; + _previouskeyboardState = Keyboard.GetState(); + + UIStatus = GameStatus.Title; + MenuStatus = MenuOption.Resume; + Timer = TimeSpan.Zero; + Score = 0; + } + + public void Update(GameTime gameTime) + { + if (UIStatus == GameStatus.Playing) + { + Timer += gameTime.ElapsedGameTime; + } + else if (UIStatus == GameStatus.Title) + { + if (TitleScreen.PressAnyKey()) + { + UIStatus = GameStatus.Playing; + } + } + else if (UIStatus == GameStatus.Menu) + { + KeyboardState keyboardState = Keyboard.GetState(); + if ((IsKeyPressed(keyboardState, _previouskeyboardState, Keys.Down) || IsKeyPressed(keyboardState, _previouskeyboardState, Keys.S)) && MenuStatus < MenuOption.Exit) + { + MenuStatus++; + //TODO: AudioManager.SelectMenuSound.Play(); + } + else if ((IsKeyPressed(keyboardState, _previouskeyboardState, Keys.Up) || IsKeyPressed(keyboardState, _previouskeyboardState, Keys.W)) && MenuStatus > MenuOption.Resume) + { + MenuStatus--; + //TODO: AudioManager.SelectMenuSound.Play(); + } + else if (keyboardState.IsKeyDown(Keys.Enter)) + { + HandleMenuSelection(); + } + + _previouskeyboardState = keyboardState; + } + } + + private bool IsKeyPressed(KeyboardState keyboardState, KeyboardState previouskeyboardState, Keys key) + { + return keyboardState.IsKeyDown(key) && previouskeyboardState.IsKeyUp(key); + } + + private void HandleMenuSelection() + { + switch (MenuStatus) + { + case MenuOption.Resume: + // TODO: AudioManager.ResumeBackgroundMusic(); + UIStatus = GameStatus.Playing; + break; + + case MenuOption.Restart: + // TODO: AudioManager.ResumeBackgroundMusic(); + // TODO: Restart position, timer, score + UIStatus = GameStatus.Playing; + break; + + case MenuOption.GodMode: + // TODO: God mode + break; + + case MenuOption.SelectStage: + // TODO: select stage + break; + + case MenuOption.Exit: + // TODO: select stage + UIStatus = GameStatus.Exit; + break; + } + } + + public void Draw() + { + if (UIStatus == GameStatus.Playing) + { + HUD.Draw(_graphicsDevice, _spriteBatch, _spriteFont, Timer, Score); + } + else if (UIStatus == GameStatus.Title) + { + TitleScreen.Draw(_graphicsDevice, _spriteBatch, _spriteFont); + } + else if (UIStatus == GameStatus.Menu) + { + Menu.Draw(_graphicsDevice, _spriteBatch, _spriteFont, MenuStatus); + } + } + } +} From 4129a8b78b6368eddecc63d92cb9559d237bcf40 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Mon, 1 Jul 2024 08:57:40 -0300 Subject: [PATCH 61/73] Integro UIManager en TGCGame --- TGC.MonoGame.TP/TGCGame.cs | 46 +++++++++++--------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 546ecc6d2..4ba7c2f40 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -50,9 +50,8 @@ public TGCGame() private GraphicsDeviceManager Graphics { get; } private SpriteBatch SpriteBatch { get; set; } private SpriteFont SpriteFont { get; set; } - private TextUI UIStatus = TextUI.Title; - private TimeSpan Timer = TimeSpan.Zero; - + private UIManager UI; + // Camera to draw the scene private FollowCamera FollowCamera { get; set; } @@ -107,6 +106,7 @@ protected override void LoadContent() SpriteBatch = new SpriteBatch(GraphicsDevice); SpriteFont = Content.Load(ContentFolderSpriteFonts + "CascadiaCode/CascadiaCodePL"); + UI = new UIManager(GraphicsDevice, SpriteBatch, SpriteFont); Entities = new List(); @@ -152,16 +152,15 @@ private void MergeEntities(List Track, List protected override void Update(GameTime gameTime) { - if (UIStatus == TextUI.HUD) + if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { - Timer += gameTime.ElapsedGameTime; - - if (Keyboard.GetState().IsKeyDown(Keys.Escape)) - { - //Salgo del juego. - Exit(); - } + UI.UIStatus = GameStatus.Menu; + } + UI.Update(gameTime); + // actualiza el estado solo si está jugando + if (UI.UIStatus == GameStatus.Playing) + { MainCharacter.Update(gameTime); FollowCamera.Update(gameTime, MainCharacter.World); @@ -172,16 +171,9 @@ protected override void Update(GameTime gameTime) //World = Matrix.CreateRotationY(Rotation); } - else if (UIStatus == TextUI.Title) - { - if (TitleScreen.PressAnyKey()) - { - UIStatus = TextUI.HUD; - } - } - else if (UIStatus == TextUI.Menu) + else if (UI.UIStatus == GameStatus.Exit) { - //Menu.Update(); + Exit(); } base.Update(gameTime); @@ -213,19 +205,7 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.RasterizerState = originalRasterizerState; - if (UIStatus == TextUI.HUD) - { - HUD.Draw(GraphicsDevice, SpriteBatch, SpriteFont, Timer, 0); - } - else if (UIStatus == TextUI.Title) - { - TitleScreen.Draw(GraphicsDevice, SpriteBatch, SpriteFont); - } - else if (UIStatus == TextUI.Menu) - { - // TODO - // Menu.Draw(); - } + UI.Draw(); //base.Draw(gameTime); } From 215371961b8dfc4f09154468b4606f4117f0ef68 Mon Sep 17 00:00:00 2001 From: LColamonici Date: Mon, 1 Jul 2024 09:25:36 -0300 Subject: [PATCH 62/73] skybox funcionando --- TGC.MonoGame.TP/Content/Content.mgcb | 4 ++-- TGC.MonoGame.TP/Stages/Stage.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 3f8b914fc..417fed98f 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -546,7 +546,7 @@ /processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyEnabled=True /processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True +/processorParam:PremultiplyAlpha=False /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color @@ -558,7 +558,7 @@ /processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyEnabled=True /processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True +/processorParam:PremultiplyAlpha=False /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index cff7e0f05..1a9662b9f 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -70,7 +70,7 @@ public void Draw(Matrix view, Matrix projection) { pickup.Draw(view, projection); } - //SkyBox.Draw(view, projection, CamPosition); + SkyBox.Draw(view, projection, CamPosition); } public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { @@ -88,6 +88,7 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char LoadCheckpoints(); LoadSpriteBatch(); LoadColliders(); + LoadSkyBox(); } public abstract void Update(GameTime gameTime); @@ -113,7 +114,7 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char public SkyBox SkyBox; public void LoadSkyBox(){ SkyBoxModel = Content.Load(ContentFolder3D + "skybox/cube"); - SkyBoxTexture =Content.Load(ContentFolderTextures+"skyboxes/islands/islands"); + SkyBoxTexture =Content.Load(ContentFolderTextures+"skyboxes/skybox/skybox"); SkyBoxEffect = Content.Load(ContentFolderEffects + "SkyBox"); SkyBox=new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 1000); } From 2183e146ba95b07b8050a163011b66730e18eb1b Mon Sep 17 00:00:00 2001 From: LColamonici Date: Mon, 1 Jul 2024 09:31:23 -0300 Subject: [PATCH 63/73] correccion en skybox --- TGC.MonoGame.TP/Stages/Stage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index 1a9662b9f..4f2fb479a 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -116,7 +116,7 @@ public void LoadSkyBox(){ SkyBoxModel = Content.Load(ContentFolder3D + "skybox/cube"); SkyBoxTexture =Content.Load(ContentFolderTextures+"skyboxes/skybox/skybox"); SkyBoxEffect = Content.Load(ContentFolderEffects + "SkyBox"); - SkyBox=new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 1000); + SkyBox=new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 2000); } From 78bf74d3bfc6165c026cac74709dabb64952389f Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Mon, 1 Jul 2024 20:14:09 -0300 Subject: [PATCH 64/73] Terminado colisiones en Stage 01 --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 18 +---- .../CustomPrimitives/RampPrimitive.cs | 75 ++++++++++++++++--- .../MainCharacter/MainCharacter.cs | 2 +- TGC.MonoGame.TP/Stages/Stage_01.cs | 39 +++++----- TGC.MonoGame.TP/Stages/Stage_02.cs | 10 +-- 5 files changed, 95 insertions(+), 49 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index d4d237cbc..1f45c6cc7 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -90,20 +90,10 @@ public CubePrimitive( } World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); - - if (coordinates.HasValue && scale.HasValue) - { - Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 - Vector3 regularSize = scale.Value * 25; - // Ahora puedes usar regularVector, que es de tipo Vector3 - //BoundingCube = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); - BoundingCube = new OrientedBoundingBox(regularCoordinates, regularSize / 2); - if (rotation.HasValue) - { - Matrix rotationOBB = rotation.Value; - BoundingCube.Rotate(rotationOBB); - } - } + BoundingCube = new OrientedBoundingBox(coordinates ?? Vector3.Zero, (scale ?? Vector3.One) * 25 / 2); + BoundingCube.Rotate(rotation ?? Matrix.Identity); + + InitializePrimitive(graphicsDevice, content); } diff --git a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs index 0866c62a2..63660fbf1 100644 --- a/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CustomPrimitives/RampPrimitive.cs @@ -16,6 +16,8 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Collisions; +using System; +using System.Collections.Generic; #endregion Using Statements @@ -25,7 +27,8 @@ namespace TGC.MonoGame.TP.Geometries public class RampPrimitive : CustomPrimitive { - public OrientedBoundingBox BoundingRamp { get; set; } + public List BoundingRamps { get; set; } + private List Triangles { get; set; } public RampPrimitive( GraphicsDevice graphicsDevice, @@ -38,6 +41,10 @@ public RampPrimitive( ) { + Triangles = new List(); // Inicialización aquí + + BoundingRamps = new List(); + Color = color; Vector3[] vertexList = @@ -66,21 +73,67 @@ public RampPrimitive( AddTriangle(vertexList[0], vertexList[2], vertexList[4], size, color); AddTriangle(vertexList[5], vertexList[3], vertexList[1], size, color); - World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); - - if (coordinates.HasValue && scale.HasValue) + // Definir los triángulos usando los vértices de la lista + for (int i = 0; i < vertexList.Length; i += 3) { - Vector3 regularCoordinates = coordinates.Value; // Convertir Vector3? a Vector3 - Vector3 regularSize = scale.Value * 25; - // Ahora puedes usar regularVector, que es de tipo Vector3 - //BoundingRamp = new BoundingBox(regularCoordinates - regularSize / 2, regularCoordinates + regularSize / 2); - BoundingRamp = OrientedBoundingBox.ComputeOBBFromTriangle(vertexList); - //BoundingRamp = new OrientedBoundingBox(regularCoordinates, regularSize / 2); + Vector3 v1 = vertexList[i]; + Vector3 v2 = vertexList[i + 1]; + Vector3 v3 = vertexList[i + 2]; + + this.AddTriangle(v1, v2, v3); } - + World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + + // Calcular OBB para cada triángulo y almacenarla + foreach (var triangle in Triangles) + { + // Calcular el centro y los lados del triángulo + Vector3 centroid = (triangle.V1 + triangle.V2 + triangle.V3) / 3f; + Vector3 side1 = triangle.V2 - triangle.V1; + Vector3 side2 = triangle.V3 - triangle.V1; + + // Calcular el sistema de coordenadas local para la OBB + Vector3 localX = Vector3.Normalize(side1); + Vector3 localY = Vector3.Normalize(Vector3.Cross(localX, side2)); + Vector3 localZ = Vector3.Cross(localX, localY); + + // Crear la matriz de rotación para la OBB + Matrix rotationMatrix = Matrix.CreateWorld(centroid, localZ, localY); + + // Calcular dimensiones de la OBB (puedes ajustar esto según tus necesidades) + Vector3 extents = new Vector3(side1.Length() / 2f, side2.Length() / 2f, 0.1f); + + // Crear la OBB y rotarla + OrientedBoundingBox obb = new OrientedBoundingBox(centroid, extents); + obb.Rotate(rotationMatrix); + + // Agregar la OBB a la lista de OBBs de triángulos + BoundingRamps.Add(obb); + } InitializePrimitive(graphicsDevice, content); } + + // Función para agregar un triángulo a la rampa + private void AddTriangle(Vector3 v1, Vector3 v2, Vector3 v3) + { + Triangles.Add(new Triangle(v1, v2, v3)); + } + + // Clase interna para representar un triángulo + private class Triangle + { + public Vector3 V1 { get; } + public Vector3 V2 { get; } + public Vector3 V3 { get; } + + public Triangle(Vector3 v1, Vector3 v2, Vector3 v3) + { + V1 = v1; + V2 = v2; + V3 = v3; + } + } } } \ No newline at end of file diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 9269be3f2..612d4c994 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -381,7 +381,7 @@ private void ProcessMovement(GameTime gameTime) MoveTo(Position); // Resetea la posición inicial del nivel si se cae al vacío - if (Position.Y < -200) + if (Position.Y < -500) { Position = ActualStage.CharacterInitialPosition; Velocity = Vector3.Zero; diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index 5e80422aa..c5dc63e53 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -4,51 +4,54 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Geometries; -using TGC.MonoGame.TP.MainCharacter; using TGC.MonoGame.TP.Stages; class Stage_01 : Stage { - public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : - base(graphicsDevice, content, characterPosition: new Vector3(25, 40, -800)) {} + public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : + base(graphicsDevice, content, characterPosition: new Vector3(25, 40, -800)) + { } protected override void LoadColliders() { - for(int i=0; i < Track.Count; i++) + for (int i = 0; i < Track.Count; i++) { GeometricPrimitive objetoActual = Track[i]; - if(objetoActual is CubePrimitive) + if (objetoActual is CubePrimitive) { CubePrimitive aux = (CubePrimitive)objetoActual; Colliders.Add(aux.BoundingCube); } - if(objetoActual is RampPrimitive) + if (objetoActual is RampPrimitive) { RampPrimitive aux = (RampPrimitive)objetoActual; - Colliders.Add(aux.BoundingRamp); + foreach (var boundingRamp in aux.BoundingRamps) + { + Colliders.Add(boundingRamp); + } } } - for(int i=0; i < Obstacles.Count; i++) + for (int i = 0; i < Obstacles.Count; i++) { - // GeometricPrimitive cuboActual = Obstacles[i]; - // Colliders.Add(cuboActual.BoundingCube); + // GeometricPrimitive cuboActual = Obstacles[i]; + // Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Signs.Count; i++) + for (int i = 0; i < Signs.Count; i++) { CubePrimitive cuboActual = (CubePrimitive)Signs[i]; Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Pickups.Count; i++) + for (int i = 0; i < Pickups.Count; i++) { //Geometric cuboActual = Pickups[i]; //Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Checkpoints.Count; i++) + for (int i = 0; i < Checkpoints.Count; i++) { //GeometricPrimitive cuboActual = Checkpoints[i]; //Colliders.Add(cuboActual.BoundingCube); @@ -91,12 +94,12 @@ protected override void LoadTrack() new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(175, 100, -100), scale: new Vector3(3f, 1f, 1f)), // RAMPA - new RampPrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 125, -125), scale: new Vector3(3f, 1f, 1f)), + new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(175, 110, -135), scale: new Vector3(2.5f, 2.5f, 0.75f), rotation: Matrix.CreateFromYawPitchRoll(0, (float)Math.PI / (-3), 0)), // CANALETA new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(175, 125, -250), scale: new Vector3(3f, 1f, 9f)), - new RampPrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(150, 150, -250), scale: new Vector3(9f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(200, 150, -250), scale: new Vector3(9f, 1f, 1f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(150, 145, -250), scale: new Vector3(9f, 1f, 0.25f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, (float)Math.PI / (-6), 0)), + new CubePrimitive(GraphicsDevice, Content, Color.BlueViolet, coordinates: new Vector3(200, 145, -250), scale: new Vector3(9f, 1f, 0.25f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / (-2), (float)Math.PI / (-6), 0)), // PLANOS INCLINADOS (ROLL) new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(25, 0, -75), scale: new Vector3(3f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6))), @@ -109,14 +112,14 @@ protected override void LoadTrack() new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(25, 0, -775), scale: new Vector3(3f, 1f, 4f)), // RAMPA GRANDE - new RampPrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(175, 125, -450), scale: new Vector3(7f, 7f, 7f), rotation: Matrix.CreateFromYawPitchRoll((float)Math.PI / 2, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.LightPink, coordinates: new Vector3(240, 80, -412), scale: new Vector3(9f, 1f, 4f), rotation: Matrix.CreateFromYawPitchRoll(0, 0, (float)Math.PI / (-6))), // CUADRADOS GRANDES new CubePrimitive(GraphicsDevice, Content, Color.Red, coordinates: new Vector3(275, 25, -425), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Orange, coordinates: new Vector3(300, 0, -400), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Yellow, coordinates: new Vector3(325, -25, -375), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Green, coordinates: new Vector3(350, -50, -350), scale: new Vector3(9f, 1f, 9f)), - new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(375, -75, -325), scale: new Vector3(9f, 1f, 9f)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(375, -75, -325), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Indigo, coordinates: new Vector3(400, -100, -300), scale: new Vector3(9f, 1f, 9f)), new CubePrimitive(GraphicsDevice, Content, Color.Purple, coordinates: new Vector3(425, -125, -275), scale: new Vector3(9f, 1f, 9f)), diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index e57e274bc..08acf9a20 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using TGC.MonoGame.TP.Geometries; -using TGC.MonoGame.TP.MainCharacter; using TGC.MonoGame.TP.Stages; - class Stage_02 : Stage { @@ -27,7 +24,10 @@ protected override void LoadColliders() if(objetoActual is RampPrimitive) { RampPrimitive aux = (RampPrimitive)objetoActual; - Colliders.Add(aux.BoundingRamp); + foreach(var boundingRamp in aux.BoundingRamps) + { + Colliders.Add(boundingRamp); + } } } From 8f7a82d58044072ff167c66fb92e254429ff02a4 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Mon, 1 Jul 2024 22:19:19 -0300 Subject: [PATCH 65/73] =?UTF-8?q?Agregado=20modificador=20de=20velocidad?= =?UTF-8?q?=20seg=C3=BAn=20material=20de=20la=20esfera?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainCharacter/MainCharacter.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 612d4c994..d31e5edd2 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -50,9 +50,6 @@ public class Character : Entity Vector3 LightPos { get; set; } public Matrix Spin; - //Vector3 startPos; - - public Vector3 ForwardVector = Vector3.UnitX; public Vector3 RightVector = Vector3.UnitZ; @@ -326,7 +323,25 @@ private void ProcessMovement(GameTime gameTime) // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - float speed = 100f; + float speed; + switch (CurrentMaterial) + { + case Material.Grass: + speed = 95f; + break; + case Material.Gold: + speed = 115f; + break; + case Material.Marble: + speed = 80f; + break; + case Material.Metal: + speed = 100f; + break; + default: + speed = 150f; + break; + } // Capturar Input teclado var keyboardState = Keyboard.GetState(); From 7ad44551c8d7c54999fe28393189ff57c8424749 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 2 Jul 2024 14:19:48 -0300 Subject: [PATCH 66/73] =?UTF-8?q?Actualizaci=C3=B3n=20de=20escenario=202.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 1 + TGC.MonoGame.TP/MainCharacter/MainCharacter.cs | 2 +- TGC.MonoGame.TP/Stages/Stage_01.cs | 1 - TGC.MonoGame.TP/Stages/Stage_02.cs | 8 ++++---- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 1f45c6cc7..45172fc97 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -90,6 +90,7 @@ public CubePrimitive( } World = Matrix.CreateScale(scale ?? Vector3.One) * (rotation ?? Matrix.Identity) * Matrix.CreateTranslation(coordinates ?? Vector3.Zero); + BoundingCube = new OrientedBoundingBox(coordinates ?? Vector3.Zero, (scale ?? Vector3.One) * 25 / 2); BoundingCube.Rotate(rotation ?? Matrix.Identity); diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index d31e5edd2..23b430284 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -279,7 +279,7 @@ public void ProcessCollisionNEW(float deltaTime) Vector3 surfaceNormal = Vector3.Zero; float squareRadius = EsferaBola.Radius * EsferaBola.Radius; - foreach (OrientedBoundingBox collider in ActualStage.Colliders) + foreach (var collider in ActualStage.Colliders) { if (collider is null) continue; diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index c5dc63e53..821a219d8 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -126,7 +126,6 @@ protected override void LoadTrack() // PLATAFORMA FINAL new CubePrimitive(GraphicsDevice, Content, Color.Aquamarine, coordinates: new Vector3(425, -125, -75), scale: new Vector3(7f, 1f, 6f)) }; - } protected override void LoadObstacles() diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index 08acf9a20..00affba85 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -33,8 +33,8 @@ protected override void LoadColliders() for(int i=0; i < Obstacles.Count; i++) { - // GeometricPrimitive cuboActual = Obstacles[i]; - // Colliders.Add(cuboActual.BoundingCube); + CubePrimitive cuboActual = (CubePrimitive)Obstacles[i]; + Colliders.Add(cuboActual.BoundingCube); } for(int i=0; i < Signs.Count; i++) @@ -51,8 +51,8 @@ protected override void LoadColliders() for(int i=0; i < Checkpoints.Count; i++) { - //GeometricPrimitive cuboActual = Checkpoints[i]; - //Colliders.Add(cuboActual.BoundingCube); + CubePrimitive cuboActual = (CubePrimitive)Checkpoints[i]; + Colliders.Add(cuboActual.BoundingCube); } } From 2313ade302d963ba3b3830e17dd4cd1e7a41dab4 Mon Sep 17 00:00:00 2001 From: Federico Bertani Date: Tue, 2 Jul 2024 15:42:09 -0300 Subject: [PATCH 67/73] =?UTF-8?q?Correci=C3=B3n=20en=20el=20giro=20cuando?= =?UTF-8?q?=20hay=20velocidad=20cero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/MainCharacter/MainCharacter.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 23b430284..82a18b82f 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -12,6 +12,7 @@ using TGC.MonoGame.TP.MainCharacter; using System.Collections.Generic; using System.Diagnostics; +using System.IO; namespace TGC.MonoGame.TP.MainCharacter { @@ -378,7 +379,18 @@ private void ProcessMovement(GameTime gameTime) Vector3 HorizontalVelocity = new Vector3(Velocity.X, 0, Velocity.Z); BallSpinAngle += HorizontalVelocity.Length() * elapsedTime * elapsedTime / (MathHelper.Pi * 12.5f); - BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); + + // se normaliza el vector yCrossVelocity solo si alguna de componentes es distinta de 0 + Vector3 yCrossVelocity = Vector3.Cross(Vector3.UnitY, Velocity); + if (Math.Abs(yCrossVelocity.X) > 0 || Math.Abs(yCrossVelocity.Y) > 0 || Math.Abs(yCrossVelocity.Z) > 0) + { + BallSpinAxis = Vector3.Normalize(yCrossVelocity); + } + else + { + BallSpinAxis = Vector3.Zero; + } + if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) { From 766102611896916cddc95743412f3ce099b17442 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 2 Jul 2024 16:27:02 -0300 Subject: [PATCH 68/73] Agregado procesamiento de checkpoints --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 1 - .../MainCharacter/MainCharacter.cs | 35 +++++++++++++++++-- TGC.MonoGame.TP/Stages/Stage.cs | 6 ++++ TGC.MonoGame.TP/Stages/Stage_01.cs | 13 +++---- TGC.MonoGame.TP/TGCGame.cs | 9 +++-- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 45172fc97..24972e74a 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -38,7 +38,6 @@ public CubePrimitive( float size = 25f, Vector3? coordinates = null, Vector3? scale = null, - //BoundingBox? boundingBox = null, Matrix? rotation = null ) { diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 23b430284..64d768bf1 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -60,6 +60,8 @@ public Character(ContentManager content, Stage stage, List entities) ActualStage = stage; + LastCheckpoint = stage.CharacterInitialPosition; + InitializeEffect(); InitializeSphere(stage.CharacterInitialPosition); InitializeTextures(); @@ -231,6 +233,23 @@ public float DistanceToGround(Vector3 pos) return dist; } + public void ChangeLastCheckpoint() + { + foreach(OrientedBoundingBox box in ActualStage.CheckpointColliders) + { + if(box is null) + continue; + if(box.Intersects(EsferaBola)) + { + LastCheckpoint = box.Center + (Vector3.One * EsferaBola.Radius); + } + if(ActualStage.CheckpointColliders.IndexOf(box) == ActualStage.CheckpointColliders.LastIndexOf(box)) + { + // Acá debe ir algún efecto que nos permita ir al siguiente nivel + } + } + } + public bool IsColliding() { foreach (OrientedBoundingBox box in ActualStage.Colliders) @@ -378,7 +397,17 @@ private void ProcessMovement(GameTime gameTime) Vector3 HorizontalVelocity = new Vector3(Velocity.X, 0, Velocity.Z); BallSpinAngle += HorizontalVelocity.Length() * elapsedTime * elapsedTime / (MathHelper.Pi * 12.5f); - BallSpinAxis = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, Velocity)); + + // se normaliza el vector yCrossVelocity solo si alguna de componentes es distinta de 0 + Vector3 yCrossVelocity = Vector3.Cross(Vector3.UnitY, Velocity); + if (Math.Abs(yCrossVelocity.X) > 0 || Math.Abs(yCrossVelocity.Y) > 0 || Math.Abs(yCrossVelocity.Z) > 0) + { + BallSpinAxis = Vector3.Normalize(yCrossVelocity); + } + else + { + BallSpinAxis = Vector3.Zero; + } if (Acceleration == Vector3.Zero || Vector3.Dot(Acceleration, Velocity) < 0) { @@ -395,10 +424,12 @@ private void ProcessMovement(GameTime gameTime) MoveTo(Position); + ChangeLastCheckpoint(); + // Resetea la posición inicial del nivel si se cae al vacío if (Position.Y < -500) { - Position = ActualStage.CharacterInitialPosition; + Position = LastCheckpoint; Velocity = Vector3.Zero; MoveTo(Position); UpdateBBSphere(Position); diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index 4f2fb479a..f06cd94a8 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -43,6 +43,7 @@ public void LoadSpriteBatch(){ //COLISIONES public List Colliders; + public List CheckpointColliders; //COLISIONES @@ -70,6 +71,10 @@ public void Draw(Matrix view, Matrix projection) { pickup.Draw(view, projection); } + foreach (GeometricPrimitive checkpoint in Checkpoints) + { + checkpoint.Draw(view, projection); + } SkyBox.Draw(view, projection, CamPosition); } public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) @@ -80,6 +85,7 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char CharacterInitialPosition = characterPosition; Colliders = new List(); + CheckpointColliders = new List(); LoadTrack(); LoadObstacles(); diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index 821a219d8..100e98983 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -53,8 +53,8 @@ protected override void LoadColliders() for (int i = 0; i < Checkpoints.Count; i++) { - //GeometricPrimitive cuboActual = Checkpoints[i]; - //Colliders.Add(cuboActual.BoundingCube); + CubePrimitive cuboActual = (CubePrimitive)Checkpoints[i]; + CheckpointColliders.Add(cuboActual.BoundingCube); } } @@ -137,9 +137,6 @@ protected override void LoadSigns() { Signs = new List { - // aca iria la banderita del final - new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(425, -100, -75)), - // aca irian cartelitos //jump new CubePrimitive(GraphicsDevice, Content, Color.Black, coordinates: new Vector3(-25, 50, 150)), @@ -165,7 +162,11 @@ protected override void LoadPickups() protected override void LoadCheckpoints() { - Checkpoints = new List(); + Checkpoints = new List() + { + // aca iria la banderita del final + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(425, -100, -75)) + }; } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 1e8f06335..0b92dbf9d 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -109,15 +109,14 @@ protected override void LoadContent() MainCharacter = new Character(Content, Stage, Entities); - BallEffect = Content.Load(ContentFolderEffects + "PBR"); - MergeEntities(Stage.Track, Stage.Obstacles, Stage.Signs, Stage.Pickups); + MergeEntities(Stage.Track, Stage.Obstacles, Stage.Signs, Stage.Pickups, Stage.Checkpoints); base.LoadContent(); } - private void MergeEntities(List Track, List Obstacles, List Signs, List Pickups) + private void MergeEntities(List Track, List Obstacles, List Signs, List Pickups, List Checkpoints) { foreach(GeometricPrimitive myTrack in Track) { @@ -138,6 +137,10 @@ private void MergeEntities(List Track, List From d64754a24bb0805851c3b45ff3a6f2fe91b92e0d Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Tue, 2 Jul 2024 18:40:48 -0300 Subject: [PATCH 69/73] =?UTF-8?q?Se=20agrega=20chequeo=20de=20=C3=BAltimo?= =?UTF-8?q?=20checkpoint=20que=20cambia=20efecto=20(a=20modificar)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainCharacter/MainCharacter.cs | 27 ++++++++++--------- TGC.MonoGame.TP/TGCGame.cs | 3 --- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 7cadf794f..a6534df00 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -172,7 +172,6 @@ private void ProcessMaterialChange() { CurrentMaterial = NewMaterial; SwitchMaterial(); - LoadTextures(); } } @@ -236,17 +235,21 @@ public float DistanceToGround(Vector3 pos) public void ChangeLastCheckpoint() { - foreach(OrientedBoundingBox box in ActualStage.CheckpointColliders) + foreach (OrientedBoundingBox box in ActualStage.CheckpointColliders) { - if(box is null) + if (box is null) continue; - if(box.Intersects(EsferaBola)) + if (box.Intersects(EsferaBola)) { LastCheckpoint = box.Center + (Vector3.One * EsferaBola.Radius); - } - if(ActualStage.CheckpointColliders.IndexOf(box) == ActualStage.CheckpointColliders.LastIndexOf(box)) - { - // Acá debe ir algún efecto que nos permita ir al siguiente nivel + + //El último checkpoint es el final del nivel. + if (ActualStage.CheckpointColliders.IndexOf(box) == ActualStage.CheckpointColliders.LastIndexOf(box)) + { + //Debería de imprimir algún texto en pantalla, para saber que llegamos al checkpoint final. + CurrentMaterial = Material.Gold; + SwitchMaterial(); + } } } } @@ -269,7 +272,7 @@ public bool IsOnGround(Vector3 pos) { foreach (OrientedBoundingBox box in ActualStage.Colliders) { - if(box is null) + if (box is null) continue; Ray tempRay = new Ray(pos, -Vector3.Up); float? dist = box.Intersects(tempRay); @@ -280,7 +283,7 @@ public bool IsOnGround(Vector3 pos) } return false; } - + Vector3 getCollisionNormalNEW(BoundingSphere sphere, OrientedBoundingBox box) { Vector3 puntoContacto = box.ClosestPointTo(sphere.Center); @@ -306,7 +309,7 @@ public void ProcessCollisionNEW(float deltaTime) Vector3 puntoContacto = collider.ClosestPointTo(EsferaBola.Center); float distanceToSquared = Vector3.DistanceSquared(puntoContacto, EsferaBola.Center); - if(distanceToSquared <= squareRadius) + if (distanceToSquared <= squareRadius) { contactPoint = puntoContacto; @@ -386,7 +389,7 @@ private void ProcessMovement(GameTime gameTime) } Acceleration += new Vector3(0f, -100f, 0f); - + //Procesamiento del movimiento vertical float distGround = DistanceToGround(Position); if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround <= 12.5f || (IsColliding() && IsOnGround(Position)))) diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 0b92dbf9d..8dee591a0 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -159,9 +159,6 @@ protected override void Update(GameTime gameTime) MainCharacter.Update(gameTime); - - - FollowCamera.Update(gameTime, MainCharacter.World); Stage.CamPosition=FollowCamera.CamPosition; From 0a92a6b66f7465c83c8580d6018084ecee09598f Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Wed, 3 Jul 2024 02:46:20 -0300 Subject: [PATCH 70/73] =?UTF-8?q?Cambio=20de=20escenario=20al=20cruzar=20e?= =?UTF-8?q?l=20=C3=BAltimo=20checkpoint=20del=20nivel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Geometries/CubePrimitive.cs | 6 +- .../Geometries/GeometricPrimitive.cs | 11 +-- .../MainCharacter/MainCharacter.cs | 42 +++++---- TGC.MonoGame.TP/Stages/Stage.cs | 89 ++++++++++--------- TGC.MonoGame.TP/Stages/Stage_02.cs | 14 +-- TGC.MonoGame.TP/TGCGame.cs | 23 ++++- 6 files changed, 112 insertions(+), 73 deletions(-) diff --git a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs index 24972e74a..edbfab2d8 100644 --- a/TGC.MonoGame.TP/Geometries/CubePrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/CubePrimitive.cs @@ -11,6 +11,7 @@ #region Using Statements +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -38,7 +39,8 @@ public CubePrimitive( float size = 25f, Vector3? coordinates = null, Vector3? scale = null, - Matrix? rotation = null + Matrix? rotation = null, + string? Text = "" ) { @@ -93,8 +95,6 @@ public CubePrimitive( BoundingCube = new OrientedBoundingBox(coordinates ?? Vector3.Zero, (scale ?? Vector3.One) * 25 / 2); BoundingCube.Rotate(rotation ?? Matrix.Identity); - - InitializePrimitive(graphicsDevice, content); } } diff --git a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs index 3fd65145c..7fb826baa 100644 --- a/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs +++ b/TGC.MonoGame.TP/Geometries/GeometricPrimitive.cs @@ -71,7 +71,7 @@ protected void AddIndex(int index) if (index > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(index)); - Indices.Add((ushort) index); + Indices.Add((ushort)index); } /// @@ -83,7 +83,8 @@ protected void AddIndex(int index) /// Once all the geometry has been specified by calling AddVertex and AddIndex, this method copies the vertex and index /// data into GPU format buffers, ready for efficient rendering. /// - protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager content, Effect? primitiveEffect = null) { + protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager content, Effect? primitiveEffect = null) + { // Create a vertex declaration, describing the format of our vertex data. // Create a vertex buffer, and copy our vertex data into it. @@ -97,9 +98,9 @@ protected void InitializePrimitive(GraphicsDevice graphicsDevice, ContentManager IndexBuffer.SetData(Indices.ToArray()); Effect = primitiveEffect ?? content.Load(ContentFolderEffects + "BasicShader"); - + } - + /// /// Finalizer. @@ -157,7 +158,7 @@ public void Draw(Effect effect) graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, primitiveCount); } } - + public void Draw(Matrix view, Matrix projection) { // Set Effect parameters. diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index a6534df00..1b6b4cc58 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -1,18 +1,12 @@ using System; using System.Linq; -using System.Runtime.Intrinsics.Arm; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; -using TGC.MonoGame.TP.Camera; using TGC.MonoGame.TP.Stages; using TGC.MonoGame.TP.Collisions; -using TGC.MonoGame.TP.Geometries; -using TGC.MonoGame.TP.MainCharacter; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; namespace TGC.MonoGame.TP.MainCharacter { @@ -35,6 +29,8 @@ public class Character : Entity // Checkpoints public Vector3 LastCheckpoint; + public bool FinishedStage; + private OrientedBoundingBox ObbLastCheckpoint; // Checkpoints @@ -63,6 +59,8 @@ public Character(ContentManager content, Stage stage, List entities) LastCheckpoint = stage.CharacterInitialPosition; + FinishedStage = false; + InitializeEffect(); InitializeSphere(stage.CharacterInitialPosition); InitializeTextures(); @@ -233,25 +231,39 @@ public float DistanceToGround(Vector3 pos) return dist; } - public void ChangeLastCheckpoint() + public void UpdateLastCheckpoint() { + OrientedBoundingBox nearestCheckpoint = null; + bool foundCheckpoint = false; + foreach (OrientedBoundingBox box in ActualStage.CheckpointColliders) { if (box is null) continue; + if (box.Intersects(EsferaBola)) { - LastCheckpoint = box.Center + (Vector3.One * EsferaBola.Radius); - - //El último checkpoint es el final del nivel. - if (ActualStage.CheckpointColliders.IndexOf(box) == ActualStage.CheckpointColliders.LastIndexOf(box)) + if (nearestCheckpoint == null || ActualStage.CheckpointColliders.IndexOf(box) > ActualStage.CheckpointColliders.IndexOf(nearestCheckpoint)) { - //Debería de imprimir algún texto en pantalla, para saber que llegamos al checkpoint final. - CurrentMaterial = Material.Gold; - SwitchMaterial(); + nearestCheckpoint = box; + foundCheckpoint = true; } } } + + if (foundCheckpoint) + { + LastCheckpoint = nearestCheckpoint.Center + (Vector3.One * EsferaBola.Radius); + ObbLastCheckpoint = nearestCheckpoint; + + // Verificar si es el último checkpoint + if (ActualStage.CheckpointColliders.IndexOf(ObbLastCheckpoint) == ActualStage.CheckpointColliders.Count - 1) + { + // Imprimir algún mensaje o cambiar de nivel + FinishedStage = true; + ObbLastCheckpoint = null; // Reiniciar el último checkpoint, si es necesario + } + } } public bool IsColliding() @@ -428,7 +440,7 @@ private void ProcessMovement(GameTime gameTime) MoveTo(Position); - ChangeLastCheckpoint(); + UpdateLastCheckpoint(); // Resetea la posición inicial del nivel si se cae al vacío if (Position.Y < -500) diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index f06cd94a8..d926d8b86 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -13,7 +13,7 @@ namespace TGC.MonoGame.TP.Stages; - public abstract class Stage +public abstract class Stage { public const string ContentFolder3D = "Models/"; public const string ContentFolderEffects = "Effects/"; @@ -32,24 +32,25 @@ public abstract class Stage public List Checkpoints; // puntos de respawn public Vector3 CharacterInitialPosition; - //private SpriteBatch SpriteBatch; - - public void LoadSpriteBatch(){ - //SpriteBatch=new SpriteBatch(GraphicsDevice); - //SpriteBatch.Begin(); - + private SpriteBatch SpriteBatch; + + public void LoadSpriteBatch() + { + SpriteBatch = new SpriteBatch(GraphicsDevice); + SpriteBatch.Begin(); + } - //COLISIONES - public List Colliders; - public List CheckpointColliders; - //COLISIONES + //COLISIONES + public List Colliders; + public List CheckpointColliders; + //COLISIONES private SpriteFont SpriteFont { get; set; } - public Vector3 CamPosition{get;set;} - + public Vector3 CamPosition { get; set; } + public void Draw(Matrix view, Matrix projection) { foreach (GeometricPrimitive primitive in Track) @@ -76,41 +77,44 @@ public void Draw(Matrix view, Matrix projection) checkpoint.Draw(view, projection); } SkyBox.Draw(view, projection, CamPosition); + } - public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) - { - GraphicsDevice = graphicsDevice; - Content = content; - - CharacterInitialPosition = characterPosition; - - Colliders = new List(); - CheckpointColliders = new List(); - - LoadTrack(); - LoadObstacles(); - LoadSigns(); - LoadPickups(); - LoadCheckpoints(); - LoadSpriteBatch(); - LoadColliders(); - LoadSkyBox(); - } + public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) + { + + + GraphicsDevice = graphicsDevice; + Content = content; + + CharacterInitialPosition = characterPosition; - public abstract void Update(GameTime gameTime); + Colliders = new List(); + CheckpointColliders = new List(); + LoadTrack(); + LoadObstacles(); + LoadSigns(); + LoadPickups(); + LoadCheckpoints(); + LoadSpriteBatch(); + LoadColliders(); + LoadSkyBox(); + } + + public abstract void Update(GameTime gameTime); - abstract protected void LoadTrack(); - abstract protected void LoadObstacles(); + abstract protected void LoadTrack(); - abstract protected void LoadColliders(); + abstract protected void LoadObstacles(); - abstract protected void LoadPickups(); + abstract protected void LoadColliders(); - abstract protected void LoadSigns(); + abstract protected void LoadPickups(); - abstract protected void LoadCheckpoints(); + abstract protected void LoadSigns(); + + abstract protected void LoadCheckpoints(); @@ -118,11 +122,12 @@ public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 char public TextureCube SkyBoxTexture; public Effect SkyBoxEffect; public SkyBox SkyBox; - public void LoadSkyBox(){ + public void LoadSkyBox() + { SkyBoxModel = Content.Load(ContentFolder3D + "skybox/cube"); - SkyBoxTexture =Content.Load(ContentFolderTextures+"skyboxes/skybox/skybox"); + SkyBoxTexture = Content.Load(ContentFolderTextures + "skyboxes/skybox/skybox"); SkyBoxEffect = Content.Load(ContentFolderEffects + "SkyBox"); - SkyBox=new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 2000); + SkyBox = new SkyBox(SkyBoxModel, SkyBoxTexture, SkyBoxEffect, 2000); } diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index 00affba85..168eabbc0 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -52,7 +52,7 @@ protected override void LoadColliders() for(int i=0; i < Checkpoints.Count; i++) { CubePrimitive cuboActual = (CubePrimitive)Checkpoints[i]; - Colliders.Add(cuboActual.BoundingCube); + CheckpointColliders.Add(cuboActual.BoundingCube); } } @@ -259,12 +259,12 @@ protected override void LoadCheckpoints() { Checkpoints = new List() { - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1762.5f), scale: new Vector3(10, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -337.5f, -1737.5f), scale: new Vector3(10, 5, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-812.5f, -300, -575), scale: new Vector3(1, 6, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(237.5f, -200, -625), scale: new Vector3(5, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-412.5f, -87.5f, -1250), scale: new Vector3(1, 4, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, 12.5f, -550), scale: new Vector3(8, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, 12.5f, -550), scale: new Vector3(8, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL PRIMERO + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-412.5f, -87.5f, -1250), scale: new Vector3(1, 4, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL SEGUNDO + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(237.5f, -200, -625), scale: new Vector3(5, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL TERCERO + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-812.5f, -300, -575), scale: new Vector3(1, 6, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL CUARTO + new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -337.5f, -1737.5f), scale: new Vector3(10, 5, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) // ESTE ES EL QUINTO + //new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1762.5f), scale: new Vector3(10, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) // ESTE ES EL ÚLTIMO }; } diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index 8dee591a0..e8d14deff 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -47,7 +47,7 @@ public TGCGame() } private GraphicsDeviceManager Graphics { get; } - private SpriteBatch SpriteBatch { get; set; } + public SpriteBatch SpriteBatch { get; set; } // Camera to draw the scene private FollowCamera FollowCamera { get; set; } @@ -116,6 +116,22 @@ protected override void LoadContent() base.LoadContent(); } + private void UpdateContent() + { + SpriteBatch = new SpriteBatch(GraphicsDevice); + Entities = new List(); + + Stage = new Stage_02(GraphicsDevice, Content); + + MainCharacter = new Character(Content, Stage, Entities); + + BallEffect = Content.Load(ContentFolderEffects + "PBR"); + + MergeEntities(Stage.Track, Stage.Obstacles, Stage.Signs, Stage.Pickups, Stage.Checkpoints); + + base.LoadContent(); + } + private void MergeEntities(List Track, List Obstacles, List Signs, List Pickups, List Checkpoints) { foreach(GeometricPrimitive myTrack in Track) @@ -156,6 +172,11 @@ protected override void Update(GameTime gameTime) Exit(); } + if(MainCharacter.FinishedStage) + { + UpdateContent(); + MainCharacter.FinishedStage = false; + } MainCharacter.Update(gameTime); From 2a67ace96957a0db2833a381b663d07b388c5480 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Wed, 3 Jul 2024 15:04:03 -0300 Subject: [PATCH 71/73] =?UTF-8?q?Agregados=20efectos=20de=20sonido=20y=20m?= =?UTF-8?q?=C3=BAsica=20de=20fondo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TGC.MonoGame.TP/Content/Content.mgcb | 36 ++++++++++++++ TGC.MonoGame.TP/Content/Music/stage_01.mp3 | 3 ++ TGC.MonoGame.TP/Content/Music/stage_02.mp3 | 3 ++ .../Content/Sounds/act_cleared.mp3 | 3 ++ TGC.MonoGame.TP/Content/Sounds/checkpoint.mp3 | 3 ++ TGC.MonoGame.TP/Content/Sounds/jump.mp3 | 3 ++ TGC.MonoGame.TP/Content/Sounds/moving.mp3 | 3 ++ .../MainCharacter/MainCharacter.cs | 48 +++++++++++++++++-- TGC.MonoGame.TP/Stages/Stage.cs | 4 ++ TGC.MonoGame.TP/Stages/Stage_01.cs | 8 +++- TGC.MonoGame.TP/Stages/Stage_02.cs | 24 ++++++---- TGC.MonoGame.TP/TGCGame.cs | 3 ++ 12 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 TGC.MonoGame.TP/Content/Music/stage_01.mp3 create mode 100644 TGC.MonoGame.TP/Content/Music/stage_02.mp3 create mode 100644 TGC.MonoGame.TP/Content/Sounds/act_cleared.mp3 create mode 100644 TGC.MonoGame.TP/Content/Sounds/checkpoint.mp3 create mode 100644 TGC.MonoGame.TP/Content/Sounds/jump.mp3 create mode 100644 TGC.MonoGame.TP/Content/Sounds/moving.mp3 diff --git a/TGC.MonoGame.TP/Content/Content.mgcb b/TGC.MonoGame.TP/Content/Content.mgcb index 417fed98f..bf28edf6b 100644 --- a/TGC.MonoGame.TP/Content/Content.mgcb +++ b/TGC.MonoGame.TP/Content/Content.mgcb @@ -144,6 +144,42 @@ /processorParam:TextureFormat=Compressed /build:Models/tgc-logo/tgc-logo.fbx +#begin Music/stage_01.mp3 +/importer:Mp3Importer +/processor:SongProcessor +/processorParam:Quality=Best +/build:Music/stage_01.mp3 + +#begin Music/stage_02.mp3 +/importer:Mp3Importer +/processor:SongProcessor +/processorParam:Quality=Best +/build:Music/stage_02.mp3 + +#begin Sounds/act_cleared.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:Sounds/act_cleared.mp3 + +#begin Sounds/checkpoint.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:Sounds/checkpoint.mp3 + +#begin Sounds/jump.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:Sounds/jump.mp3 + +#begin Sounds/moving.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:Sounds/moving.mp3 + #begin Textures/floor/tiling-base.png /importer:TextureImporter /processor:TextureProcessor diff --git a/TGC.MonoGame.TP/Content/Music/stage_01.mp3 b/TGC.MonoGame.TP/Content/Music/stage_01.mp3 new file mode 100644 index 000000000..934690628 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Music/stage_01.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e76eb6a57fc4c60b0e1493318658d1256162ef1f33eeb9af6d9c29961574fd0a +size 2864082 diff --git a/TGC.MonoGame.TP/Content/Music/stage_02.mp3 b/TGC.MonoGame.TP/Content/Music/stage_02.mp3 new file mode 100644 index 000000000..76c569a70 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Music/stage_02.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc667260bca7ede55b135529a85cd4247550c318d536d1cdc1ad973edcb33d31 +size 2136109 diff --git a/TGC.MonoGame.TP/Content/Sounds/act_cleared.mp3 b/TGC.MonoGame.TP/Content/Sounds/act_cleared.mp3 new file mode 100644 index 000000000..d22e825fc --- /dev/null +++ b/TGC.MonoGame.TP/Content/Sounds/act_cleared.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ca61d6eebfac1edf39833affb24d482c89057a358ae01a5307a025c656cb6cb +size 97774 diff --git a/TGC.MonoGame.TP/Content/Sounds/checkpoint.mp3 b/TGC.MonoGame.TP/Content/Sounds/checkpoint.mp3 new file mode 100644 index 000000000..1bc02c2d1 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Sounds/checkpoint.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29b925434b7e9b357e0c299c5339e4810f887d249040baad9ba13eeb77726d03 +size 14605 diff --git a/TGC.MonoGame.TP/Content/Sounds/jump.mp3 b/TGC.MonoGame.TP/Content/Sounds/jump.mp3 new file mode 100644 index 000000000..129068410 --- /dev/null +++ b/TGC.MonoGame.TP/Content/Sounds/jump.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f78766421ca36fd470e31068ffeec929e0bb7fac14f92d576bc13299cffb243 +size 52392 diff --git a/TGC.MonoGame.TP/Content/Sounds/moving.mp3 b/TGC.MonoGame.TP/Content/Sounds/moving.mp3 new file mode 100644 index 000000000..dd3a68c0f --- /dev/null +++ b/TGC.MonoGame.TP/Content/Sounds/moving.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4760fa92445f156ce16e6159892ba28a6e21ba690a5ca288d61da02902e259cd +size 12996 diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 1b6b4cc58..8cb01ace8 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -7,6 +7,8 @@ using TGC.MonoGame.TP.Stages; using TGC.MonoGame.TP.Collisions; using System.Collections.Generic; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; namespace TGC.MonoGame.TP.MainCharacter { @@ -16,6 +18,9 @@ public class Character : Entity const string ContentFolderEffects = "Effects/"; const string ContentFolderTextures = "Textures/"; + const string ContentFolderMusic = "Music/"; + const string ContentFolderSounds = "Sounds/"; + string TexturePath; ContentManager Content; @@ -27,12 +32,25 @@ public class Character : Entity Material CurrentMaterial = Material.RustedMetal; + + // Checkpoints public Vector3 LastCheckpoint; public bool FinishedStage; private OrientedBoundingBox ObbLastCheckpoint; // Checkpoints + // Sonidos + public SoundEffect CheckpointSound; + public SoundEffectInstance CheckpointSoundInstance; + public SoundEffect FinalStageSound; + public SoundEffectInstance FinalStageSoundInstance; + public SoundEffect MovementSound; + public SoundEffectInstance MovementSoundInstance; + public SoundEffect JumpSound; + public SoundEffectInstance JumpSoundInstance; + // Sonidos + // Colisiones public BoundingSphere EsferaBola { get; set; } @@ -61,11 +79,26 @@ public Character(ContentManager content, Stage stage, List entities) FinishedStage = false; + InitializeSounds(); InitializeEffect(); InitializeSphere(stage.CharacterInitialPosition); InitializeTextures(); InitializeLight(); } + void InitializeSounds() + { + CheckpointSound = Content.Load(ContentFolderSounds + "checkpoint"); + CheckpointSoundInstance = CheckpointSound.CreateInstance(); + + FinalStageSound = Content.Load(ContentFolderSounds + "act_cleared"); + FinalStageSoundInstance = FinalStageSound.CreateInstance(); + + MovementSound = Content.Load(ContentFolderSounds + "moving"); + MovementSoundInstance = MovementSound.CreateInstance(); + + JumpSound = Content.Load(ContentFolderSounds + "jump"); + JumpSoundInstance = JumpSound.CreateInstance(); + } void InitializeLight() { LightPos = Position + new Vector3(0, 10, 0); @@ -256,11 +289,15 @@ public void UpdateLastCheckpoint() LastCheckpoint = nearestCheckpoint.Center + (Vector3.One * EsferaBola.Radius); ObbLastCheckpoint = nearestCheckpoint; + CheckpointSound.Play(); + // Verificar si es el último checkpoint if (ActualStage.CheckpointColliders.IndexOf(ObbLastCheckpoint) == ActualStage.CheckpointColliders.Count - 1) { // Imprimir algún mensaje o cambiar de nivel FinishedStage = true; + MediaPlayer.Stop(); + FinalStageSound.Play(); ObbLastCheckpoint = null; // Reiniciar el último checkpoint, si es necesario } } @@ -331,18 +368,23 @@ public void ProcessCollisionNEW(float deltaTime) // Determinar si la colisión es con el suelo (por ejemplo, si la normal es vertical hacia arriba) newPosition = contactPoint + surfaceNormal * EsferaBola.Radius; UpdateBBSphere(newPosition); - } } // Calculamos la diferencia entre la nueva posición y la "anterior" - float difference = Vector3.Distance(newPosition, desirePosition); + float difference = Vector3.Distance(newPosition, oldPosition); // Modificamos la velocidad en base a la colisión float newVelocity = Vector3.Dot(Velocity, -surfaceNormal); Velocity += 1.5f * newVelocity * surfaceNormal; Position = newPosition; + + if (IsOnGround(newPosition) && newPosition != oldPosition && difference > 0.3f) + { + MovementSoundInstance.Play(); + } + UpdateBBSphere(newPosition); } @@ -389,7 +431,6 @@ private void ProcessMovement(GameTime gameTime) if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { Acceleration += Vector3.Transform(ForwardVector * -speed, Rotation) * (-1); - } if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { @@ -406,6 +447,7 @@ private void ProcessMovement(GameTime gameTime) float distGround = DistanceToGround(Position); if (Keyboard.GetState().IsKeyDown(Keys.Space) && (distGround <= 12.5f || (IsColliding() && IsOnGround(Position)))) { + JumpSoundInstance.Play(); // Seteo la velocidad vertical en 0 para que el salto sea siempre a la misma distancia Velocity = new Vector3(Velocity.X, 0f, Velocity.Z); Velocity += Vector3.Up * speed * 100f; diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index d926d8b86..6e89e0046 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -10,6 +10,7 @@ using TGC.MonoGame.TP.Collisions; using TGC.MonoGame.Samples.Samples.Shaders.SkyBox; using TGC.MonoGame.TP; +using Microsoft.Xna.Framework.Media; namespace TGC.MonoGame.TP.Stages; @@ -41,6 +42,9 @@ public void LoadSpriteBatch() } + // Música de fondo + public Song BackgroundMusic; + //COLISIONES public List Colliders; diff --git a/TGC.MonoGame.TP/Stages/Stage_01.cs b/TGC.MonoGame.TP/Stages/Stage_01.cs index 100e98983..44c432e83 100644 --- a/TGC.MonoGame.TP/Stages/Stage_01.cs +++ b/TGC.MonoGame.TP/Stages/Stage_01.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Media; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.Stages; @@ -11,7 +12,12 @@ class Stage_01 : Stage public Stage_01(GraphicsDevice graphicsDevice, ContentManager content) : base(graphicsDevice, content, characterPosition: new Vector3(25, 40, -800)) - { } + { + BackgroundMusic = Content.Load(ContentFolderMusic + "stage_01"); + MediaPlayer.Volume = 0.25f; + MediaPlayer.Play(BackgroundMusic); + MediaPlayer.IsRepeating = true; + } protected override void LoadColliders() { diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index 168eabbc0..d36b92ccb 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Media; using TGC.MonoGame.TP.Geometries; using TGC.MonoGame.TP.Stages; @@ -9,47 +10,52 @@ class Stage_02 : Stage { public Stage_02(GraphicsDevice graphicsDevice, ContentManager content) : - base(graphicsDevice, content, characterPosition: new Vector3(300f, 25f, 0f)) { } + base(graphicsDevice, content, characterPosition: new Vector3(300f, 25f, 0f)) + { + BackgroundMusic = Content.Load(ContentFolderMusic + "stage_02"); + MediaPlayer.Play(BackgroundMusic); + MediaPlayer.IsRepeating = true; + } protected override void LoadColliders() { - for(int i=0; i < Track.Count; i++) + for (int i = 0; i < Track.Count; i++) { GeometricPrimitive objetoActual = Track[i]; - if(objetoActual is CubePrimitive) + if (objetoActual is CubePrimitive) { CubePrimitive aux = (CubePrimitive)objetoActual; Colliders.Add(aux.BoundingCube); } - if(objetoActual is RampPrimitive) + if (objetoActual is RampPrimitive) { RampPrimitive aux = (RampPrimitive)objetoActual; - foreach(var boundingRamp in aux.BoundingRamps) + foreach (var boundingRamp in aux.BoundingRamps) { Colliders.Add(boundingRamp); } } } - for(int i=0; i < Obstacles.Count; i++) + for (int i = 0; i < Obstacles.Count; i++) { CubePrimitive cuboActual = (CubePrimitive)Obstacles[i]; Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Signs.Count; i++) + for (int i = 0; i < Signs.Count; i++) { CubePrimitive cuboActual = (CubePrimitive)Signs[i]; Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Pickups.Count; i++) + for (int i = 0; i < Pickups.Count; i++) { //Geometric cuboActual = Pickups[i]; //Colliders.Add(cuboActual.BoundingCube); } - for(int i=0; i < Checkpoints.Count; i++) + for (int i = 0; i < Checkpoints.Count; i++) { CubePrimitive cuboActual = (CubePrimitive)Checkpoints[i]; CheckpointColliders.Add(cuboActual.BoundingCube); diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index e8d14deff..8d01b6bc4 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -9,6 +9,7 @@ using TGC.MonoGame.TP.Collisions; using TGC.MonoGame.TP.MainCharacter; using TGC.MonoGame.TP.Stages; +using Microsoft.Xna.Framework.Audio; namespace TGC.MonoGame.TP { @@ -98,6 +99,8 @@ protected override void Initialize() public Effect BallEffect; + + protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. From f49fe514113373ad906f591043dc5adafff727b0 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Wed, 3 Jul 2024 20:37:47 -0300 Subject: [PATCH 72/73] =?UTF-8?q?Correcci=C3=B3n=20de=20UI.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainCharacter/MainCharacter.cs | 20 +++++-- TGC.MonoGame.TP/Stages/Stage.cs | 9 ++-- TGC.MonoGame.TP/TGCGame.cs | 54 ++++++++++--------- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 8cb01ace8..60fec24e6 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -9,6 +9,8 @@ using System.Collections.Generic; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Media; +using TGC.MonoGame.TP.UI; +using System.Net; namespace TGC.MonoGame.TP.MainCharacter { @@ -30,6 +32,8 @@ public class Character : Entity Matrix Scale = Matrix.CreateScale(12.5f); Effect Effect; + public GameStatus Status; + Material CurrentMaterial = Material.RustedMetal; @@ -139,6 +143,7 @@ private void InitializeTextures() public void Update(GameTime gameTime) { + ProcessMaterialChange(); ProcessMovement(gameTime); } @@ -286,7 +291,7 @@ public void UpdateLastCheckpoint() if (foundCheckpoint) { - LastCheckpoint = nearestCheckpoint.Center + (Vector3.One * EsferaBola.Radius); + LastCheckpoint = nearestCheckpoint.Center + new Vector3 (0f, 0f, 5f) * EsferaBola.Radius; ObbLastCheckpoint = nearestCheckpoint; CheckpointSound.Play(); @@ -397,6 +402,11 @@ public void ChangeDirection(float angle) private void ProcessMovement(GameTime gameTime) { + if(Status != GameStatus.Playing) + { + return; + } + // Aca deberiamos poner toda la logica de actualizacion del juego. float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; @@ -407,16 +417,16 @@ private void ProcessMovement(GameTime gameTime) speed = 95f; break; case Material.Gold: - speed = 115f; + speed = 105f; break; case Material.Marble: - speed = 80f; + speed = 100f; break; case Material.Metal: - speed = 100f; + speed = 90f; break; default: - speed = 150f; + speed = 98f; break; } diff --git a/TGC.MonoGame.TP/Stages/Stage.cs b/TGC.MonoGame.TP/Stages/Stage.cs index 6e89e0046..5729e9e33 100644 --- a/TGC.MonoGame.TP/Stages/Stage.cs +++ b/TGC.MonoGame.TP/Stages/Stage.cs @@ -50,13 +50,14 @@ public void LoadSpriteBatch() public List Colliders; public List CheckpointColliders; //COLISIONES - - - private SpriteFont SpriteFont { get; set; } + public Vector3 CamPosition { get; set; } public void Draw(Matrix view, Matrix projection) { + + + foreach (GeometricPrimitive primitive in Track) { primitive.Draw(view, projection); @@ -80,8 +81,8 @@ public void Draw(Matrix view, Matrix projection) { checkpoint.Draw(view, projection); } + SkyBox.Draw(view, projection, CamPosition); - } public Stage(GraphicsDevice graphicsDevice, ContentManager content, Vector3 characterPosition) { diff --git a/TGC.MonoGame.TP/TGCGame.cs b/TGC.MonoGame.TP/TGCGame.cs index ba34ef3e7..ff36dab03 100644 --- a/TGC.MonoGame.TP/TGCGame.cs +++ b/TGC.MonoGame.TP/TGCGame.cs @@ -28,7 +28,7 @@ public class TGCGame : Game public const string ContentFolderSpriteFonts = "SpriteFonts/"; public const string ContentFolderTextures = "Textures/"; - + /// /// Constructor del juego. @@ -37,10 +37,10 @@ public TGCGame() { // Maneja la configuracion y la administracion del dispositivo grafico. Graphics = new GraphicsDeviceManager(this); - + Graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - 100; Graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 100; - + // Para que el juego sea pantalla completa se puede usar Graphics IsFullScreen. // Carpeta raiz donde va a estar toda la Media. Content.RootDirectory = "Content"; @@ -50,11 +50,9 @@ public TGCGame() private GraphicsDeviceManager Graphics { get; } public SpriteBatch SpriteBatch { get; set; } - - private SpriteBatch SpriteBatch { get; set; } private SpriteFont SpriteFont { get; set; } private UIManager UI; - + // Camera to draw the scene private FollowCamera FollowCamera { get; set; } @@ -62,7 +60,7 @@ public TGCGame() private Character MainCharacter; private Stage Stage; protected List Entities; - + /// /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. @@ -75,7 +73,7 @@ protected override void Initialize() var size = GraphicsDevice.Viewport.Bounds.Size; size.X /= 2; size.Y /= 2; - screenSize=size; + screenSize = size; //var cameraPosition = new Vector3(25f, 100f, -1100f); //Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, cameraPosition, size); @@ -103,9 +101,6 @@ protected override void Initialize() /// public Effect BallEffect; - - - protected override void LoadContent() { // Aca es donde deberiamos cargar todos los contenido necesarios antes de iniciar el juego. @@ -145,26 +140,26 @@ private void UpdateContent() private void MergeEntities(List Track, List Obstacles, List Signs, List Pickups, List Checkpoints) { - foreach(GeometricPrimitive myTrack in Track) + foreach (GeometricPrimitive myTrack in Track) { Entities.Add(myTrack); } - - foreach(GeometricPrimitive myObstacle in Obstacles) + + foreach (GeometricPrimitive myObstacle in Obstacles) { Entities.Add(myObstacle); } - foreach(GeometricPrimitive mySign in Signs) + foreach (GeometricPrimitive mySign in Signs) { Entities.Add(mySign); } - foreach(GeometricPrimitive myPickup in Pickups) + foreach (GeometricPrimitive myPickup in Pickups) { Entities.Add(myPickup); } - foreach(GeometricPrimitive myCheckpoint in Checkpoints) + foreach (GeometricPrimitive myCheckpoint in Checkpoints) { Entities.Add(myCheckpoint); } @@ -183,18 +178,20 @@ protected override void Update(GameTime gameTime) } UI.Update(gameTime); - if(MainCharacter.FinishedStage) - { - UpdateContent(); - MainCharacter.FinishedStage = false; - } + MainCharacter.Status = UI.UIStatus; MainCharacter.Update(gameTime); FollowCamera.Update(gameTime, MainCharacter.World); // actualiza el estado solo si está jugando - if (UI.UIStatus == GameStatus.Playing) + if (UI.UIStatus == GameStatus.Playing) { + if (MainCharacter.FinishedStage) + { + UpdateContent(); + UI.UIStatus = GameStatus.Menu; + } + MainCharacter.Update(gameTime); FollowCamera.Update(gameTime, MainCharacter.World); @@ -228,7 +225,7 @@ protected override void Draw(GameTime gameTime) //GraphicsDevice.DepthStencilState = DepthStencilState.None; //GraphicsDevice.Clear(Color.LightSkyBlue); - + // //Stage.SkyBox.Draw(FollowCamera.View, FollowCamera.Projection, FollowCamera.CamPosition); @@ -238,9 +235,16 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.RasterizerState = originalRasterizerState; + // Configuramos el DepthStencilState para la UI + DepthStencilState depthStencilStateUI = new DepthStencilState(); + depthStencilStateUI.DepthBufferEnable = false; // Desactivamos el uso del búfer de profundidad para la UI + GraphicsDevice.DepthStencilState = depthStencilStateUI; + // Dibujamos la interfaz de usuario (UI) UI.Draw(); - //base.Draw(gameTime); + + // Restauramos el estado original del DepthStencilState después de la UI + GraphicsDevice.DepthStencilState = DepthStencilState.Default; } /// From c9baab8b40257f3e8669f99f948afddf6bcaa9c4 Mon Sep 17 00:00:00 2001 From: Alexis Brian Mango Date: Wed, 3 Jul 2024 21:24:43 -0300 Subject: [PATCH 73/73] Terminado escenario 2 --- .../MainCharacter/MainCharacter.cs | 2 +- TGC.MonoGame.TP/Stages/Stage_02.cs | 58 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs index 60fec24e6..81b52487a 100644 --- a/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs +++ b/TGC.MonoGame.TP/MainCharacter/MainCharacter.cs @@ -289,7 +289,7 @@ public void UpdateLastCheckpoint() } } - if (foundCheckpoint) + if (foundCheckpoint && ObbLastCheckpoint != nearestCheckpoint) { LastCheckpoint = nearestCheckpoint.Center + new Vector3 (0f, 0f, 5f) * EsferaBola.Radius; ObbLastCheckpoint = nearestCheckpoint; diff --git a/TGC.MonoGame.TP/Stages/Stage_02.cs b/TGC.MonoGame.TP/Stages/Stage_02.cs index d36b92ccb..e76d47dbb 100644 --- a/TGC.MonoGame.TP/Stages/Stage_02.cs +++ b/TGC.MonoGame.TP/Stages/Stage_02.cs @@ -73,20 +73,20 @@ protected override void LoadTrack() new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-625, 0, 0), scale: new Vector3(20, 1, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1000, 0, 0), scale: new Vector3(10, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1212.5f, 0, 0), scale: new Vector3(7, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, 25, 0), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-1.5707964f, 3.1415927f, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, 25, 0), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-1.5707964f, 3.1415927f, 1.5707964f)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, 0, -175), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1275, -12.5f, -362.5f), scale: new Vector3(2, 2, 5), rotation: Matrix.CreateFromYawPitchRoll(3.1415927f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1275, -24.5f, -362.5f), scale: new Vector3(2, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, (float)System.Math.PI / -9, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, 0, -312.5f), scale: new Vector3(2, 1, 2), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -12.5f, -400), scale: new Vector3(2, 2, 5), rotation: Matrix.CreateFromYawPitchRoll(-3.1415927f, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -24.5f, -400), scale: new Vector3(2, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, (float)System.Math.PI / -9, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -537.5f), scale: new Vector3(10, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(1.5707964f, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -25, -662.5f), scale: new Vector3(1, 3, 3), rotation: Matrix.CreateFromYawPitchRoll(3.926991f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -662.5f), scale: new Vector3(1, 3, 3), rotation: Matrix.CreateFromYawPitchRoll(3.926991f, 0, 1.5707964f)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1150, -50, -687.5f), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1350, -50, -687.5f), scale: new Vector3(4, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -812.5f), scale: new Vector3(1, 7, 7), rotation: Matrix.CreateFromYawPitchRoll(0.7853983f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1250, -50, -812.5f), scale: new Vector3(1, 7, 7), rotation: Matrix.CreateFromYawPitchRoll(0.7853983f, 0, 1.5707964f)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -75, -925), scale: new Vector3(6, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -100, -1012.5f), scale: new Vector3(4, 1, 6), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1237.5f, -125, -1162.5f), scale: new Vector3(3, 1, 7), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -125, -1300), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(4.712389f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1225, -125, -1300), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(4.712389f, 0, 1.5707964f)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-1025, -125, -1312.5f), scale: new Vector3(12, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-775, -125, -1312.5f), scale: new Vector3(4, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-625, -125, -1312.5f), scale: new Vector3(4, 1, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), @@ -99,7 +99,7 @@ protected override void LoadTrack() new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(237.5f, -225, -1162.5f), scale: new Vector3(5, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(287.5f, -237.5f, -850), scale: new Vector3(3, 1, 10), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(262.5f, -250, -675), scale: new Vector3(3, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new RampPrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(250, -262.5f, -575), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-4.712389f, 0, 1.5707964f)), + new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(250, -262.5f, -575), scale: new Vector3(1, 4, 4), rotation: Matrix.CreateFromYawPitchRoll(-4.712389f, 0, 1.5707964f)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-175, -262.5f, -537.5f), scale: new Vector3(30, 1, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-175, -262.5f, -600), scale: new Vector3(30, 1, 2), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), new CubePrimitive(GraphicsDevice, Content, Color.Gray, coordinates: new Vector3(-600, -287.5f, -575), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), @@ -121,23 +121,23 @@ protected override void LoadObstacles() { Obstacles = new List() { - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -875), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -975), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1075), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1175), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1275), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1375), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-887.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-962.5f, 37.5f, -37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1037.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, -12.5f, -825), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1137.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1062.5f, -87.5f, -1287.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-987.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-525, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-400, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-275, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875f, -412.5f, -1825f), scale: new Vector3(10f, 1f, 20f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -875), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -975), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -1075), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -1175), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -1275), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875, -412.5f, -1375), scale: new Vector3(4, 1, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-887.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-962.5f, 37.5f, -37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-1037.5f, 37.5f, 37.5f), scale: new Vector3(1, 2, 3), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-1250, -12.5f, -825), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-1137.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-1062.5f, -87.5f, -1287.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-987.5f, -87.5f, -1337.5f), scale: new Vector3(1, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-525, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-400, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-275, -225, -537.5f), scale: new Vector3(2, 2, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), + new CubePrimitive(GraphicsDevice, Content, Color.Blue, coordinates: new Vector3(-875f, -412.5f, -1825f), scale: new Vector3(10f, 1f, 20f), rotation: Matrix.CreateFromYawPitchRoll(0f, 0f, 0f)), }; } @@ -265,11 +265,11 @@ protected override void LoadCheckpoints() { Checkpoints = new List() { - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-1250, 12.5f, -550), scale: new Vector3(8, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL PRIMERO - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-412.5f, -87.5f, -1250), scale: new Vector3(1, 4, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL SEGUNDO - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(237.5f, -200, -625), scale: new Vector3(5, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL TERCERO - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-812.5f, -300, -575), scale: new Vector3(1, 6, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL CUARTO - new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -337.5f, -1737.5f), scale: new Vector3(10, 5, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) // ESTE ES EL QUINTO + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(-1250, 12.5f, -550), scale: new Vector3(8, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL PRIMERO + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(-412.5f, -87.5f, -1250), scale: new Vector3(1, 4, 8), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL SEGUNDO + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(237.5f, -200, -625), scale: new Vector3(5, 4, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL TERCERO + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(-812.5f, -300, -575), scale: new Vector3(1, 6, 4), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)), // ESTE ES EL CUARTO + new CubePrimitive(GraphicsDevice, Content, Color.White, coordinates: new Vector3(-875, -337.5f, -1737.5f), scale: new Vector3(10, 5, 1), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) // ESTE ES EL QUINTO //new CubePrimitive(GraphicsDevice, Content, Color.DarkGray, coordinates: new Vector3(-875, -412.5f, -1762.5f), scale: new Vector3(10, 1, 15), rotation: Matrix.CreateFromYawPitchRoll(0, 0, 0)) // ESTE ES EL ÚLTIMO }; }