-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from thiagomvas/development
Development
- Loading branch information
Showing
34 changed files
with
771 additions
and
70 deletions.
There are no files selected for viewing
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,45 @@ | ||
using Basalt.Common.Entities; | ||
using Basalt.Math; | ||
using System.Numerics; | ||
using static Raylib_cs.Raylib; | ||
|
||
namespace Basalt.Raylib.Components | ||
{ | ||
/// <summary> | ||
/// Represents a first-person camera controller for Raylib. | ||
/// </summary> | ||
public class FirstPersonCameraController : RayCameraController | ||
{ | ||
/// <summary> | ||
/// The sensitivity of the camera controller. | ||
/// </summary> | ||
public float Sensitivity = 0.1f; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FirstPersonCameraController"/> class. | ||
/// </summary> | ||
/// <param name="entity">The entity associated with the camera controller.</param> | ||
public FirstPersonCameraController(Entity entity) : base(entity) | ||
{ | ||
} | ||
|
||
public override void OnUpdate() | ||
{ | ||
if (!Enabled) | ||
return; | ||
|
||
Vector3 rotation = new(GetMouseDelta().X * Sensitivity, // Rotation: yaw | ||
GetMouseDelta().Y * Sensitivity, // Rotation: pitch | ||
0.0f); // Rotation: roll | ||
|
||
// Update the camera in raylib | ||
|
||
camera.Position = Entity.Transform.Position; | ||
camera.Target = camera.Position + Entity.Transform.Forward; | ||
|
||
UpdateCameraPro(ref camera, Vector3.Zero, rotation, 0); | ||
|
||
Entity.Transform.Rotation = BasaltMath.LookAtRotation(camera.Position, camera.Target, camera.Up); | ||
} | ||
} | ||
} |
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,39 @@ | ||
using Basalt.Common.Components; | ||
using Basalt.Common.Entities; | ||
using Raylib_cs; | ||
using System.Numerics; | ||
|
||
namespace Basalt.Raylib.Components | ||
{ | ||
/// <summary> | ||
/// Represents a camera controller for Raylib using Camera3D. | ||
/// </summary> | ||
public class RayCameraController : CameraControllerBase<Camera3D> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RayCameraController"/> class. | ||
/// </summary> | ||
/// <param name="entity">The entity associated with the camera controller.</param> | ||
public RayCameraController(Entity entity) : base(entity) | ||
{ | ||
Camera = new Camera3D | ||
{ | ||
Position = Entity.Transform.Position, | ||
Target = Entity.Transform.Position + Entity.Transform.Forward, | ||
Up = new Vector3(0f, 1f, 0f), | ||
FovY = 60f, | ||
Projection = CameraProjection.Perspective | ||
}; | ||
|
||
// Set the camera as the active camera in raylib | ||
Raylib_cs.Raylib.UpdateCamera(ref camera, CameraMode.FirstPerson); | ||
} | ||
|
||
protected Camera3D camera; | ||
|
||
/// <summary> | ||
/// Gets or sets the camera. | ||
/// </summary> | ||
public override Camera3D Camera { get => camera; set => camera = value; } | ||
} | ||
} |
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,55 @@ | ||
using Basalt.Common.Components; | ||
using Basalt.Common.Entities; | ||
using Basalt.Common.Exceptions; | ||
using Basalt.Common.Utils; | ||
using Basalt.Raylib.Graphics; | ||
using Raylib_cs; | ||
using System.Numerics; | ||
|
||
namespace Basalt.Raylib.Components | ||
{ | ||
/// <summary> | ||
/// A particle system that renders particles using Raylib. | ||
/// </summary> | ||
public class RaylibParticleSystem : BaseParticleSystem | ||
{ | ||
private string _modelCacheKey = "sphere"; | ||
/// <summary> | ||
/// The <see cref="ResourceCache"/> cache key for the model to use for rendering particles. | ||
/// </summary> | ||
public string ModelCacheKey | ||
{ | ||
get => _modelCacheKey; | ||
set | ||
{ | ||
_modelCacheKey = value; | ||
init = false; | ||
} | ||
} | ||
bool init = false; | ||
Model model; | ||
public RaylibParticleSystem(Entity entity) : base(entity) | ||
{ | ||
} | ||
|
||
protected override void RenderParticles() | ||
{ | ||
if (!init) | ||
{ | ||
init = true; | ||
var m = ResourceCache.Instance.GetModel(ModelCacheKey); | ||
if (m == null) | ||
{ | ||
throw new InvalidResourceKeyException(nameof(ModelCacheKey), ModelCacheKey); | ||
} | ||
model = m.Value; | ||
|
||
} | ||
foreach (var particle in _particles) | ||
{ | ||
model.Transform = Raymath.MatrixRotateXYZ(Raymath.QuaternionToEuler(particle.Rotation)); | ||
Raylib_cs.Raylib.DrawModelEx(model, particle.Position, Vector3.UnitY, 0, particle.Scale, particle.Color.ToRaylibColor()); | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using Basalt.Utility; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Basalt.Tests | ||
{ | ||
|
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
Oops, something went wrong.