Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
2004seraph committed Feb 9, 2024
2 parents 7399ce3 + 583af24 commit 8ee0c66
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 95 deletions.
24 changes: 2 additions & 22 deletions GREngine.Core/GREngine.Core.Physics2D/CollisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,15 @@ public interface ICollisionSystem
{
}
//This should be a singleton service
public class CollisionSystem : ICollisionSystem
public class CollisionSystem : GameComponent, ICollisionSystem
{
HashSet<VerletObject> verletObjects = new HashSet<VerletObject>();
Vector2 gravity = new Vector2(0, 1000f);
Vector2 position = new Vector2(300, 0);
float radius = 300f;

int subSteps = 1;

// Singleton Pattern
public static CollisionSystem instance;
private CollisionSystem()
{
}
public static CollisionSystem Instance
{
get
{
if (instance == null)
{
if (instance == null)
{
instance = new CollisionSystem();
}
}

return instance;
}
}
public CollisionSystem(Game game) : base(game){}

public void Update(float dt)
{
Expand Down
36 changes: 20 additions & 16 deletions Testing/CollisionTesting/PolygonToPolygonTestingSet1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

public class PolygonToPolygonTestingSet1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;

private Texture2D _texture;
private Texture2D texture;
private Texture2D pixelTexture;
private CollisionSystem collisionSystem;

Expand Down Expand Up @@ -106,20 +106,24 @@ public class PolygonToPolygonTestingSet1 : Game

public PolygonToPolygonTestingSet1()
{
_graphics = new GraphicsDeviceManager(this);
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
IsMouseVisible = true;

collisionSystem = new(this);
}

protected override void Initialize()
{
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.ApplyChanges();
graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
graphics.ApplyChanges();

// TODO: Add your initialization logic here

Components.Add(collisionSystem);
Services.AddService<ICollisionSystem>(collisionSystem);

// TODO: Add your initialization logic here
collisionSystem = CollisionSystem.Instance;
Services.AddService<ICollisionSystem>(collisionSystem);
collisionSystem.SetPosition(new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2));

List<PointF> squarePointFList = new List<PointF>
Expand Down Expand Up @@ -453,8 +457,8 @@ protected override void Initialize()

protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_texture = this.Content.Load<Texture2D>("collision/circle");
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = this.Content.Load<Texture2D>("collision/circle");
pixelTexture = Content.Load<Texture2D>("collision/pixel");

}
Expand Down Expand Up @@ -534,15 +538,15 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(new Color(31, 31, 31));

// TODO: Add your drawing code here
_spriteBatch.Begin();
spriteBatch.Begin();

//drawing polygons
foreach (PolygonCollider obj in collisionSystem.GetVerletObjects().OfType<PolygonCollider>())
{
obj.DrawDebug(_spriteBatch, pixelTexture);
obj.DrawDebug(spriteBatch, pixelTexture);
}

_spriteBatch.End();
spriteBatch.End();

base.Draw(gameTime);
}
Expand Down
28 changes: 15 additions & 13 deletions Testing/CollisionTesting/PolygonToPolygonTestingSet2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

public class PolygonToPolygonTestingSet2 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;

private Texture2D _texture;
private Texture2D texture;
private Texture2D pixelTexture;
private CollisionSystem collisionSystem;

Expand Down Expand Up @@ -106,19 +106,21 @@ public class PolygonToPolygonTestingSet2 : Game

public PolygonToPolygonTestingSet2()
{
_graphics = new GraphicsDeviceManager(this);
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;

collisionSystem = new(this);
}

protected override void Initialize()
{
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.ApplyChanges();
graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
graphics.ApplyChanges();

// TODO: Add your initialization logic here
collisionSystem = CollisionSystem.Instance;
Components.Add(collisionSystem);
Services.AddService<ICollisionSystem>(collisionSystem);
collisionSystem.SetPosition(new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2));

Expand Down Expand Up @@ -487,8 +489,8 @@ protected override void Initialize()

protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_texture = this.Content.Load<Texture2D>("collision/circle");
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = this.Content.Load<Texture2D>("collision/circle");
pixelTexture = Content.Load<Texture2D>("collision/pixel");

}
Expand Down Expand Up @@ -568,15 +570,15 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(new Color(31, 31, 31));

// TODO: Add your drawing code here
_spriteBatch.Begin();
spriteBatch.Begin();

//drawing polygons
foreach (PolygonCollider obj in collisionSystem.GetVerletObjects().OfType<PolygonCollider>())
{
obj.DrawDebug(_spriteBatch, pixelTexture);
obj.DrawDebug(spriteBatch, pixelTexture);
}

_spriteBatch.End();
spriteBatch.End();

base.Draw(gameTime);
}
Expand Down
28 changes: 15 additions & 13 deletions Testing/CollisionTesting/PolygonToPolygonTestingSet3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

public class PolygonToPolygonTestingSet3 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;

private Texture2D _texture;
private Texture2D texture;
private Texture2D pixelTexture;
private CollisionSystem collisionSystem;

Expand All @@ -33,19 +33,21 @@ public class PolygonToPolygonTestingSet3 : Game

public PolygonToPolygonTestingSet3()
{
_graphics = new GraphicsDeviceManager(this);
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;

collisionSystem = new(this);
}

protected override void Initialize()
{
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.ApplyChanges();
graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
graphics.ApplyChanges();

// TODO: Add your initialization logic here
collisionSystem = CollisionSystem.Instance;
Components.Add(collisionSystem);
Services.AddService<ICollisionSystem>(collisionSystem);
collisionSystem.SetPosition(new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2));

Expand Down Expand Up @@ -199,8 +201,8 @@ protected override void Initialize()

protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_texture = this.Content.Load<Texture2D>("collision/circle");
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = this.Content.Load<Texture2D>("collision/circle");
pixelTexture = Content.Load<Texture2D>("collision/pixel");

}
Expand Down Expand Up @@ -248,15 +250,15 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(new Color(31, 31, 31));

// TODO: Add your drawing code here
_spriteBatch.Begin();
spriteBatch.Begin();

//drawing polygons
foreach (PolygonCollider obj in collisionSystem.GetVerletObjects().OfType<PolygonCollider>())
{
obj.DrawDebug(_spriteBatch, pixelTexture);
obj.DrawDebug(spriteBatch, pixelTexture);
}

_spriteBatch.End();
spriteBatch.End();

base.Draw(gameTime);
}
Expand Down
30 changes: 16 additions & 14 deletions Testing/CollisionTesting/PolygonToPolygonTestingSet4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

public class PolygonToPolygonTestingSet4 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;

private Texture2D _texture;
private Texture2D texture;
private Texture2D pixelTexture;
private CollisionSystem collisionSystem;

Expand Down Expand Up @@ -110,19 +110,21 @@ public class PolygonToPolygonTestingSet4 : Game

public PolygonToPolygonTestingSet4()
{
_graphics = new GraphicsDeviceManager(this);
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
IsMouseVisible = true;

collisionSystem = new(this);
}

protected override void Initialize()
{
_graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
_graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
_graphics.ApplyChanges();
graphics.PreferredBackBufferWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
graphics.ApplyChanges();

// TODO: Add your initialization logic here
collisionSystem = CollisionSystem.Instance;
Components.Add(collisionSystem);
Services.AddService<ICollisionSystem>(collisionSystem);
collisionSystem.SetPosition(new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2));

Expand Down Expand Up @@ -496,8 +498,8 @@ protected override void Initialize()

protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_texture = this.Content.Load<Texture2D>("collision/circle");
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = this.Content.Load<Texture2D>("collision/circle");
pixelTexture = Content.Load<Texture2D>("collision/pixel");

}
Expand Down Expand Up @@ -586,15 +588,15 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(new Color(31, 31, 31));

// TODO: Add your drawing code here
_spriteBatch.Begin();
spriteBatch.Begin();

//drawing polygons
foreach (PolygonCollider obj in collisionSystem.GetVerletObjects().OfType<PolygonCollider>())
{
obj.DrawDebug(_spriteBatch, pixelTexture);
obj.DrawDebug(spriteBatch, pixelTexture);
}

_spriteBatch.End();
spriteBatch.End();

base.Draw(gameTime);
}
Expand Down
54 changes: 39 additions & 15 deletions Testing/Content/Content.mgcb
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:DesktopGL
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#


#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:DesktopGL
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#

#begin collision/circle.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:collision/circle.png

#begin collision/pixel.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:collision/pixel.png

4 changes: 2 additions & 2 deletions Testing/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

using var game = new Testing.Game1();

using var game = new PolygonToPolygonTestingSet4();
game.Run();

0 comments on commit 8ee0c66

Please sign in to comment.