mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ScriptCore: Added more properties to components
- Added CircleRenderer - Transform: Added Rotation, RotationEuler, RotationAxisAngle and Scale - RigidBody: Added BodyType and GravityScale - Added ColorRGBA
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GlitchyEngine.Math;
|
||||
|
||||
using static GlitchyEngine.Math.Math;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a color with red, blue, green color channels and alpha.
|
||||
/// <br/>Each channel is represented by a <see cref="float"/>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack=1)]
|
||||
public struct ColorRGBA
|
||||
{
|
||||
internal const float SrgbToLin = 2.2f;
|
||||
internal const float LinToSRGB = (float)(1.0 / 2.2);
|
||||
|
||||
/// <summary>
|
||||
/// The red component of the color.
|
||||
/// </summary>
|
||||
public float R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component of the color.
|
||||
/// </summary>
|
||||
public float G;
|
||||
|
||||
/// <summary>
|
||||
/// The blue component of the color.
|
||||
/// </summary>
|
||||
public float B;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component of the color.
|
||||
/// </summary>
|
||||
public float A;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of ColorRGBA with all components set to 0.
|
||||
/// </summary>
|
||||
public ColorRGBA() { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of ColorRGBA with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component of the color.</param>
|
||||
/// <param name="g">The green component of the color.</param>
|
||||
/// <param name="b">The blue component of the color.</param>
|
||||
/// <param name="a">The alpha component of the color.</param>
|
||||
public ColorRGBA(float r, float g, float b, float a = 1.0f)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = a;
|
||||
}
|
||||
|
||||
public static explicit operator float4(ColorRGBA color) => new float4(color.R, color.G, color.B, color.A);
|
||||
public static explicit operator ColorRGBA(float4 vector) => new ColorRGBA(vector.X, vector.Y, vector.Z, vector.W);
|
||||
|
||||
// Converts a Color from sRGB color space to Linear color space.
|
||||
public static ColorRGBA SRgbToLinear(ColorRGBA sRGB) => new ColorRGBA(pow(sRGB.R, SrgbToLin), pow(sRGB.G, SrgbToLin), pow(sRGB.B, SrgbToLin), sRGB.A);
|
||||
|
||||
// Converts a Color from linear color space to sRGB color space.
|
||||
public static ColorRGBA LinearToSRGB(ColorRGBA linear) => new ColorRGBA(pow(linear.R, LinToSRGB), pow(linear.G, LinToSRGB), pow(linear.B, LinToSRGB), linear.A);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GlitchyEngine.Math;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a rotation around an axis by a specific angle.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack=1)]
|
||||
public struct RotationAxisAngle
|
||||
{
|
||||
/// <summary>
|
||||
/// The axis around which the rotation is applied.
|
||||
/// </summary>
|
||||
public float3 Axis;
|
||||
/// <summary>
|
||||
/// The angle in radians around the <see cref="Axis"/>.
|
||||
/// </summary>
|
||||
public float Angle;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of an axis angle rotation.
|
||||
/// </summary>
|
||||
/// <param name="axis">The axis.</param>
|
||||
/// <param name="angle">The angle in radians.</param>
|
||||
public RotationAxisAngle(float3 axis, float angle)
|
||||
{
|
||||
Axis = axis;
|
||||
Angle = angle;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user