Transitioned from VectorX to floatX

And some trying to update Rigidbody when transform changes
This commit is contained in:
Simon Lübeß
2023-06-25 02:47:33 +02:00
parent 5f5da2ed35
commit 9e1f648aa0
49 changed files with 1281 additions and 871 deletions
@@ -52,7 +52,7 @@ namespace GlitchyEngine.World
public AssetHandle<Texture2D> Sprite = .Invalid;
public ColorRGBA Color = .White;
public Vector4 UvTransform = .(0, 0, 1, 1);
public float4 UvTransform = .(0, 0, 1, 1);
public this()
{
@@ -70,7 +70,7 @@ namespace GlitchyEngine.World
public AssetHandle<Texture2D> Sprite = .Invalid;
public ColorRGBA Color = .White;
public Vector4 UvTransform = .(0, 0, 1, 1);
public float4 UvTransform = .(0, 0, 1, 1);
public float InnerRadius = 0.0f;
@@ -385,19 +385,79 @@ namespace GlitchyEngine.World
private int _runtimeBody = 0;
internal b2Body* RuntimeBody
protected internal b2Body* RuntimeBody
{
[Inline]
get => (b2Body*)(void*)_runtimeBody;
[Inline]
set mut => _runtimeBody = (int)(void*)value;
}
public float2 GetPosition()
{
if (RuntimeBody != null)
{
Box2D.b2Vec2 vec = Box2D.Body.GetPosition(RuntimeBody);
return *(float2*)&vec;
}
return .Zero;
}
public void SetPosition(float2 position)
{
var position;
if (RuntimeBody != null)
{
float angle = Box2D.Body.GetAngle(RuntimeBody);
Box2D.Body.SetTransform(RuntimeBody, ref *(Box2D.b2Vec2*)&position, angle);
}
}
public float GetAngle()
{
if (RuntimeBody != null)
{
return Box2D.Body.GetAngle(RuntimeBody);
}
return float.NaN;
}
public void SetAngle(float angle)
{
if (RuntimeBody != null)
{
var pos = Box2D.Body.GetPosition(RuntimeBody);
Box2D.Body.SetTransform(RuntimeBody, ref pos, angle);
}
}
}
/*struct InternalBug
{
private int i;
internal int MyInt
{
get => i;
set mut => i = value;
}
public void Bla()
{
MyInt = 5;
}
}*/
struct BoxCollider2DComponent
{
public Vector2 Offset = .(0.0f, 0.0f);
public Vector2 Size = .(0.5f, 0.5f);
public float2 Offset = .(0.0f, 0.0f);
public float2 Size = .(0.5f, 0.5f);
// TODO: move into 2D physics material
public float Density = 1.0f;
@@ -421,7 +481,7 @@ namespace GlitchyEngine.World
struct CircleCollider2DComponent
{
public Vector2 Offset = .(0.0f, 0.0f);
public float2 Offset = .(0.0f, 0.0f);
public float Radius = 0.5f;
@@ -6,11 +6,11 @@ namespace GlitchyEngine.World
{
EcsEntity _parent = .InvalidEntity;
Vector3 _position = .(0, 0, 0);
float3 _position = .(0, 0, 0);
Quaternion _rotation = .(0, 0, 0, 1);
Vector3 _scale = .(1, 1, 1);
float3 _scale = .(1, 1, 1);
Vector3 _editorRotationEuler = .Zero;
float3 _editorRotationEuler = .Zero;
Matrix _localTransform = .Identity;
public bool IsDirty = false;
@@ -52,12 +52,12 @@ namespace GlitchyEngine.World
}
}
public Vector3 Position
public float3 Position
{
get => _position;
set mut
{
if(_position == value)
if(all(_position == value))
return;
_position = value;
@@ -82,12 +82,12 @@ namespace GlitchyEngine.World
}
/// Allows the user to edit the euler angles in the editor without rotations getting funky because of singularities or ambiguity of angles.
internal Vector3 EditorRotationEuler
internal float3 EditorRotationEuler
{
get => _editorRotationEuler;
set mut
{
if (_editorRotationEuler == value)
if (all(_editorRotationEuler == value))
return;
_editorRotationEuler = value;
@@ -101,7 +101,7 @@ namespace GlitchyEngine.World
* Gets or sets the rotation using euler angles.
* @Note The rotations will be applied in the following order: YZX (the order in the vector is still XYZ!)
*/
public Vector3 RotationEuler
public float3 RotationEuler
{
get => Quaternion.ToEulerAngles(_rotation);
set mut => Rotation = Quaternion.FromEulerAngles(value.Y, value.X, value.Z);
@@ -111,7 +111,7 @@ namespace GlitchyEngine.World
* Gets or sets the rotation using axis angle, where Axis is the axis around which will be rotated and angle is the angle
* that was rotated around the axis in radians.
*/
public (Vector3 Axis, float Angle) RotationAxisAngle
public (float3 Axis, float Angle) RotationAxisAngle
{
get => _rotation.ToAxisAngle();
set mut
@@ -126,12 +126,12 @@ namespace GlitchyEngine.World
}
}
public Vector3 Scale
public float3 Scale
{
get => _scale;
set mut
{
if(_scale == value)
if(all(_scale == value))
return;
_scale = value;
+16 -16
View File
@@ -8,10 +8,10 @@ namespace GlitchyEngine.World
{
struct EditorCamera : Camera, IDisposable
{
private Vector3 _position;
private float3 _position;
private Quaternion _rotation;
private Vector3 _focalPosition = .Zero;
private float3 _focalPosition = .Zero;
private float _focalDistance = 5.0f;
private float _cameraTranslationSpeed = 2.0f;
@@ -52,12 +52,12 @@ namespace GlitchyEngine.World
}
}
public Vector3 Position
public float3 Position
{
get => _position;
set mut
{
if (_position == value)
if (all(_position == value))
return;
_position = value;
@@ -78,7 +78,7 @@ namespace GlitchyEngine.World
}
}
public Vector3 RotationEuler
public float3 RotationEuler
{
get => Quaternion.ToEulerAngles(_rotation);
set mut
@@ -92,7 +92,7 @@ namespace GlitchyEngine.World
}
}
public (Vector3 Axis, float Angle) RotationAxisAngle
public (float3 Axis, float Angle) RotationAxisAngle
{
get => _rotation.ToAxisAngle();
set mut
@@ -145,7 +145,7 @@ namespace GlitchyEngine.World
}
}
public this(Vector3 position, Quaternion rotation, float fovY, float nearPlane, float aspectRatio)
public this(float3 position, Quaternion rotation, float fovY, float nearPlane, float aspectRatio)
{
_position = position;
_rotation = rotation;
@@ -190,7 +190,7 @@ namespace GlitchyEngine.World
bool transformChanged = false;
Vector3 movement = .();
float3 movement = .();
if(Input.IsKeyPressed(Key.W))
movement.Z += 1;
@@ -207,16 +207,16 @@ namespace GlitchyEngine.World
if(Input.IsKeyPressed(Key.Control))
movement.Y -= 1;
if(movement != .Zero)
if(any(movement != .Zero))
{
movement.Normalize();
normalize(movement);
if(Input.IsKeyPressed(Key.Shift))
movement *= _cameraFastFactor;
movement *= (float)(gameTime.DeltaTime) * _cameraTranslationSpeed;
Vector4 delta = Vector4(movement, 1.0f) * _view;
float4 delta = float4(movement, 1.0f) * _view;
_position += delta.XYZ;
@@ -231,7 +231,7 @@ namespace GlitchyEngine.World
if (MouseCooldown == 0)
{
Vector3 rotationEuler = RotationEuler + Vector3(rotX, rotY, 0);
float3 rotationEuler = RotationEuler + float3(rotX, rotY, 0);
_rotation = Quaternion.FromEulerAngles(rotationEuler.Y, rotationEuler.X, rotationEuler.Z);
transformChanged = true;
@@ -262,13 +262,13 @@ namespace GlitchyEngine.World
if (MouseCooldown == 0 && Input.IsMouseButtonPressed(.LeftButton) && mouseDelta != .())
{
Vector2 movement = .(
float2 movement = .(
-mouseDelta.X,
mouseDelta.Y);
movement *= (float)(gameTime.DeltaTime) * _cameraTranslationSpeed * GetZoomSpeed();
Vector4 delta = Vector4(movement, 0.0f, 1.0f) * _view;
float4 delta = float4(movement, 0.0f, 1.0f) * _view;
_focalPosition += delta.XYZ;
@@ -280,7 +280,7 @@ namespace GlitchyEngine.World
float rotY = mouseDelta.X * _cameraRotationSpeedX;
float rotX = mouseDelta.Y * _cameraRotationSpeedY;
Vector3 rotationEuler = RotationEuler + Vector3(rotX, rotY, 0);
float3 rotationEuler = RotationEuler + float3(rotX, rotY, 0);
_rotation = Quaternion.FromEulerAngles(rotationEuler.Y, rotationEuler.X, rotationEuler.Z);
transformChanged = true;
@@ -294,7 +294,7 @@ namespace GlitchyEngine.World
{
Matrix viewRotation = Matrix.RotationQuaternion(Quaternion.Inverse(_rotation));
Vector4 offset = Vector4(0, 0, -_focalDistance, 1.0f) * viewRotation;
float4 offset = float4(0, 0, -_focalDistance, 1.0f) * viewRotation;
if (_isAltMode)
_position = _focalPosition + offset.XYZ;
else