-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
165 changed files
with
9,967 additions
and
12 deletions.
There are no files selected for viewing
Binary file added
BIN
+27.7 KB
Source/.vs/Genesis/FileContentIndex/2942be7b-3501-4b85-919b-cacf61852f95.vsidx
Binary file not shown.
Binary file removed
BIN
-27.5 KB
Source/.vs/Genesis/FileContentIndex/383e2e0f-5703-4698-95a6-4dc798d511a2.vsidx
Binary file not shown.
Binary file renamed
BIN
+164 KB
...7311488-664a-4f4c-90c4-ae9b084e9415.vsidx → ...a57dfb9-bb77-49a5-bc94-0dca90d3b990.vsidx
Binary file not shown.
Binary file removed
BIN
-33.3 KB
Source/.vs/Genesis/FileContentIndex/7d7ef1b3-a6c3-4b2e-9072-0fb7024093be.vsidx
Binary file not shown.
Binary file added
BIN
+34.1 KB
Source/.vs/Genesis/FileContentIndex/8781238c-d095-4f81-b950-99477e0cd3d2.vsidx
Binary file not shown.
Binary file added
BIN
+22.7 KB
Source/.vs/Genesis/FileContentIndex/ac656b2e-ef68-4be2-b56a-242bb5b457f1.vsidx
Binary file not shown.
Binary file removed
BIN
-15.2 KB
Source/.vs/Genesis/FileContentIndex/f4096e87-86f4-4c75-a60a-46a596cf04a8.vsidx
Binary file not shown.
Binary file not shown.
127 changes: 127 additions & 0 deletions
127
Source/Genesis/Core/Behaviors/Physics2D/BufferedSpriteCollider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using BulletSharp; | ||
using BulletSharp.Math; | ||
using Genesis.Core.GameElements; | ||
using Genesis.Graphics.Shapes; | ||
using Genesis.Math; | ||
using Genesis.Physics; | ||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Genesis.Core.Behaviors.Physics2D | ||
{ | ||
/// <summary> | ||
/// Represents a behavior for creating a physics collider for 2D sprites using BulletSharp. | ||
/// </summary> | ||
public class BufferedSpriteCollider : Physics.PhysicsBehavior | ||
{ | ||
/// <summary> | ||
/// Gets or sets the rigid body associated with the collider. | ||
/// </summary> | ||
public RigidBody RigidBody { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the linear factor for the RigidBody's motion. | ||
/// </summary> | ||
public Vec3 LinearFactor { get; set; } = new Vec3(0, 0, 0); | ||
|
||
/// <summary> | ||
/// Gets or sets the angular factor for the RigidBody's rotation. | ||
/// </summary> | ||
public Vec3 AngularFactor { get; set; } = new Vec3(0, 0, 0); | ||
|
||
/// <summary> | ||
/// Gets the physics object associated with the collider. | ||
/// </summary> | ||
/// <returns>The rigid body associated with the collider.</returns> | ||
public override object GetPhysicsObject() | ||
{ | ||
return RigidBody; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the typed physics object associated with the collider. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the physics object.</typeparam> | ||
/// <returns>The typed rigid body associated with the collider.</returns> | ||
public override T GetPhysicsObject<T>() | ||
{ | ||
return (T)(object)RigidBody; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a rigid body for the collider. | ||
/// </summary> | ||
/// <param name="mass">The mass of the rigid body.</param> | ||
/// <param name="handler">The physics handler for managing the collider.</param> | ||
public void CreateRigidBody(float mass, PhysicHandler handler) | ||
{ | ||
if (this.Parent.GetType() == typeof(BufferedSprite)) | ||
{ | ||
var bufferedSprite = (BufferedSprite)this.Parent; | ||
CompoundShape compoundShape = new CompoundShape(true); | ||
|
||
foreach(var deffinition in bufferedSprite.ShapeDeffinitions) | ||
{ | ||
Box2DShape box2DShape = new Box2DShape(new Vector3(deffinition.sizeX, deffinition.sizeY, 0f) / 2); | ||
BulletSharp.Math.Matrix boxtransform = BulletSharp.Math.Matrix.Translation(new Vector3(deffinition.locX, deffinition.locY, 0f)); | ||
compoundShape.AddChildShape(boxtransform, box2DShape); | ||
} | ||
RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(mass, null, compoundShape, compoundShape.CalculateLocalInertia(mass)); | ||
BulletSharp.Math.Matrix transform = BulletSharp.Math.Matrix.Translation(bufferedSprite.Location.ToBulletVec3()); | ||
Matrix startTransform = transform; | ||
info.MotionState = new DefaultMotionState(startTransform); | ||
|
||
RigidBody = new BulletSharp.RigidBody(info); | ||
RigidBody.UserObject = this.Parent; | ||
RigidBody.LinearFactor = this.LinearFactor.ToBulletVec3(); | ||
RigidBody.AngularFactor = this.AngularFactor.ToBulletVec3(); | ||
//RigidBody.CollisionFlags = CollisionFlags.StaticObject; | ||
|
||
handler.ManageElement(this); | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("Invalid element for this Behavior"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Placeholder for OnDestroy event. No implementation. | ||
/// </summary> | ||
public override void OnDestroy(Game game, GameElement parent) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Placeholder for OnInit event. No implementation. | ||
/// </summary> | ||
public override void OnInit(Game game, GameElement parent) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Placeholder for OnRender event. No implementation. | ||
/// </summary> | ||
public override void OnRender(Game game, GameElement parent) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Placeholder for OnUpdate event. No implementation. | ||
/// </summary> | ||
public override void OnUpdate(Game game, GameElement parent) | ||
{ | ||
Matrix transform = BulletSharp.Math.Matrix.Translation(Parent.Location.ToBulletVec3()); | ||
RigidBody.MotionState = new DefaultMotionState(transform); | ||
RigidBody.Activate(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ProjectView>ProjectFiles</ProjectView> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,5 @@ private Rect GetStringBounds(Vec3 location) | |
rect.Height = FontSize; | ||
return rect; | ||
} | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.