07.10.2020
+ Parent, Name and Flags to objects. ~ Improved Matrix calculations
This commit is contained in:
parent
f865496414
commit
2c00dbd31a
21 changed files with 383 additions and 42 deletions
|
|
@ -1,20 +1,54 @@
|
|||
using OpenTK;
|
||||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
using OpenTK;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM2D.Types
|
||||
{
|
||||
public class Transformation : GenericTransformation
|
||||
{
|
||||
public CVector2 Position = new CVector2(0);
|
||||
public CVector2 Size = new CVector2(50);
|
||||
public float Rotation;
|
||||
private float _eulerRotation = 0;
|
||||
private CVector2 _position = new CVector2(0);
|
||||
private CVector2 _scale = new CVector2(50);
|
||||
|
||||
public override Matrix4 GetMatrix()
|
||||
public CVector2 Position
|
||||
{
|
||||
return Matrix4.CreateScale(Size.X, Size.Y, 1) *
|
||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
|
||||
Matrix4.CreateTranslation(Position.X, Position.Y, 0);
|
||||
get => _position;
|
||||
set => _position = value;
|
||||
}
|
||||
|
||||
public CVector2 Size
|
||||
{
|
||||
get => _scale;
|
||||
set => _scale = value;
|
||||
}
|
||||
public float Rotation
|
||||
{
|
||||
get => _eulerRotation;
|
||||
set => _eulerRotation = value;
|
||||
}
|
||||
|
||||
protected override Matrix4 RequestMatrix()
|
||||
{
|
||||
return Matrix4.CreateScale(_scale.X, _scale.Y, 1) *
|
||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(_eulerRotation)) *
|
||||
Matrix4.CreateTranslation(_position.X, _position.Y, 0);
|
||||
}
|
||||
|
||||
public void TurnTo(Vector2 v)
|
||||
{
|
||||
_eulerRotation = RotationUtility.TurnTowards(Position, v);
|
||||
}
|
||||
|
||||
public Vector2 LookAtVector()
|
||||
{
|
||||
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
|
||||
|
||||
Vector3 vec = Vector3.TransformNormal(Vector3.UnitX, _modelMatrix);
|
||||
vec.Normalize();
|
||||
return vec.Xy;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue