mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-04-03 11:09:40 -04:00
BREAKING CHANGE. Replaced Vector2, Vector3 and Vector4 with System.Numerics.
- Testing out a breaking change so we can use System.Numerics.
This commit is contained in:
parent
3b3bdc34c4
commit
85c5585dec
@ -7,282 +7,12 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
// Vector2 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector2
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
public Vector2(float x, float y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector2(float value)
|
||||
{
|
||||
this.x = value;
|
||||
this.y = value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector2) && Equals((Vector2)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector2(" + x + " " + y + ")";
|
||||
}
|
||||
|
||||
// Common values
|
||||
public static Vector2 Zero { get { return Raymath.Vector2Zero(); } }
|
||||
public static Vector2 One { get { return Raymath.Vector2One(); } }
|
||||
public static Vector2 UnitX { get { return new Vector2(1, 0); } }
|
||||
public static Vector2 UnitY { get { return new Vector2(0, 1); } }
|
||||
|
||||
// Convienient operators
|
||||
public static bool operator ==(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y;
|
||||
}
|
||||
|
||||
public static Vector2 operator +(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2Add(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator -(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2Subtract(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2MultiplyV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(Vector2 v, float scale)
|
||||
{
|
||||
return Raymath.Vector2Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(float scale, Vector2 v)
|
||||
{
|
||||
return Raymath.Vector2Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector2 operator /(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2DivideV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator /(Vector2 v1, float div)
|
||||
{
|
||||
return Raymath.Vector2Divide(v1, div);
|
||||
}
|
||||
|
||||
public static Vector2 operator -(Vector2 v1)
|
||||
{
|
||||
return Raymath.Vector2Negate(v1);
|
||||
}
|
||||
}
|
||||
|
||||
// Vector3 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector3
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3(float value)
|
||||
{
|
||||
this.x = value;
|
||||
this.y = value;
|
||||
this.z = value;
|
||||
}
|
||||
|
||||
// Extensions
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector3) && Equals((Vector3)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode() + z.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector3(" + x + " " + y + " " + z + ")";
|
||||
}
|
||||
|
||||
// Common values
|
||||
public static Vector3 Zero { get { return Raymath.Vector3Zero(); } }
|
||||
public static Vector3 One { get { return Raymath.Vector3One(); } }
|
||||
public static Vector3 UnitX { get { return new Vector3(1, 0, 0); } }
|
||||
public static Vector3 UnitY { get { return new Vector3(0, 1, 0); } }
|
||||
public static Vector3 UnitZ { get { return new Vector3(0, 0, 1); } }
|
||||
|
||||
// Convienient operators
|
||||
public static bool operator ==(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y && v1.z > v2.z;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y && v1.z < v2.z;
|
||||
}
|
||||
|
||||
public static Vector3 operator +(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3Add(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3Subtract(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3MultiplyV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 v, float scale)
|
||||
{
|
||||
return Raymath.Vector3Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(float scale, Vector3 v)
|
||||
{
|
||||
return Raymath.Vector3Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3DivideV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 v1, float div)
|
||||
{
|
||||
return Raymath.Vector3Divide(v1, div);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 v1)
|
||||
{
|
||||
return Raymath.Vector3Negate(v1);
|
||||
}
|
||||
}
|
||||
|
||||
// Vector4 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector4
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
public Vector4(float x, float y, float z, float w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public Vector4(float value)
|
||||
{
|
||||
x = value;
|
||||
y = value;
|
||||
z = value;
|
||||
w = value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector4) && Equals((Vector4)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode() + z.GetHashCode() + w.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector4(" + x + " " + y + " " + z + " " + w + ")";
|
||||
}
|
||||
|
||||
// convienient operators
|
||||
public static bool operator ==(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y && v1.z > v2.z && v1.w > v2.w;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y && v1.z < v2.z && v1.w < v2.w;
|
||||
}
|
||||
}
|
||||
|
||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Matrix
|
||||
|
@ -6,10 +6,9 @@
|
||||
* See LICENSE for details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using Quaternion = Raylib_cs.Vector4;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
|
92
Raylib-cs/Rlights.cs
Normal file
92
Raylib-cs/Rlights.cs
Normal file
@ -0,0 +1,92 @@
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
public struct Light
|
||||
{
|
||||
public bool enabled;
|
||||
public LightType type;
|
||||
public Vector3 position;
|
||||
public Vector3 target;
|
||||
public Color color;
|
||||
public int enabledLoc;
|
||||
public int typeLoc;
|
||||
public int posLoc;
|
||||
public int targetLoc;
|
||||
public int colorLoc;
|
||||
}
|
||||
|
||||
// Light type
|
||||
public enum LightType
|
||||
{
|
||||
LIGHT_DIRECTIONAL,
|
||||
LIGHT_POINT
|
||||
}
|
||||
|
||||
public static class Rlights
|
||||
{
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
public const int MAX_LIGHTS = 4;
|
||||
public static int lightsCount = 0; // Current amount of created lights
|
||||
public const float LIGHT_DISTANCE = 3.5f;
|
||||
public const float LIGHT_HEIGHT = 1.0f;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
public static Light CreateLight(LightType type, Vector3 pos, Vector3 targ, Color color, Shader shader)
|
||||
{
|
||||
Light light = new Light();
|
||||
|
||||
if (lightsCount < MAX_LIGHTS)
|
||||
{
|
||||
light.enabled = true;
|
||||
light.type = type;
|
||||
light.position = pos;
|
||||
light.target = targ;
|
||||
light.color = color;
|
||||
|
||||
string enabledName = $"lights[{lightsCount}].enabled\0";
|
||||
string typeName = $"lights[{lightsCount}].type\0";
|
||||
string posName = $"lights[{lightsCount}].position\0";
|
||||
string targetName = $"lights[{lightsCount}].target\0";
|
||||
string colorName = $"lights[{lightsCount}].color\0";
|
||||
|
||||
light.enabledLoc = Raylib.GetShaderLocation(shader, enabledName);
|
||||
light.typeLoc = Raylib.GetShaderLocation(shader, typeName);
|
||||
light.posLoc = Raylib.GetShaderLocation(shader, posName);
|
||||
light.targetLoc = Raylib.GetShaderLocation(shader, targetName);
|
||||
light.colorLoc = Raylib.GetShaderLocation(shader, colorName);
|
||||
|
||||
UpdateLightValues(shader, light);
|
||||
lightsCount++;
|
||||
}
|
||||
return light;
|
||||
}
|
||||
|
||||
public static void UpdateLightValues(Shader shader, Light light)
|
||||
{
|
||||
// Send to shader light enabled state and type
|
||||
/*Raylib.SetShaderValue(shader, light.enabledLoc, new int[] { light.enabled ? 1 : 0 }, ShaderUniformDataType.UNIFORM_INT);
|
||||
Raylib.SetShaderValue(shader, light.typeLoc, new int[] { (int)light.type }, ShaderUniformDataType.UNIFORM_INT);
|
||||
|
||||
// Send to shader light position values
|
||||
float[] position = { light.position.x, light.position.y, light.position.z };
|
||||
Raylib.SetShaderValue(shader, light.posLoc, ref position, ShaderUniformDataType.UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light target position values
|
||||
float[] target = { light.target.x, light.target.y, light.target.z };
|
||||
Raylib.SetShaderValue(shader, light.targetLoc, ref target, ShaderUniformDataType.UNIFORM_VEC3);
|
||||
|
||||
// Send to shader light color values
|
||||
float[] color = { light.color.r / 255, light.color.g / 255,
|
||||
light.color.b / 255, light.color.a / 255 };
|
||||
Raylib.SetShaderValue(shader, light.colorLoc, ref color, ShaderUniformDataType.UNIFORM_VEC4);*/
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user