diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 2f06e3b1a..f5758f8cc 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -131,8 +131,51 @@ DEFINE_ACTION_FUNCTION(_Screen, PaletteColor) } // Dummy ZScript arbitrary textured shape drawing +IMPLEMENT_CLASS(DShape2DTransform, false, false) + +DEFINE_ACTION_FUNCTION(DShape2DTransform, Clear) +{ + PARAM_SELF_PROLOGUE(DShape2DTransform); + + return 0; +} + +DEFINE_ACTION_FUNCTION(DShape2DTransform, Rotate) +{ + PARAM_SELF_PROLOGUE(DShape2DTransform); + PARAM_FLOAT(angle); + + return 0; +} + +DEFINE_ACTION_FUNCTION(DShape2DTransform, Scale) +{ + PARAM_SELF_PROLOGUE(DShape2DTransform); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + + return 0; +} + +DEFINE_ACTION_FUNCTION(DShape2DTransform, Translate) +{ + PARAM_SELF_PROLOGUE(DShape2DTransform); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + + return 0; +} + IMPLEMENT_CLASS(DShape2D, false, false) +DEFINE_ACTION_FUNCTION(DShape2D, SetTransform) +{ + PARAM_SELF_PROLOGUE(DShape2D); + PARAM_OBJECT(transform, DShape2DTransform); + + return 0; +} + DEFINE_ACTION_FUNCTION(DShape2D, Clear) { PARAM_SELF_PROLOGUE(DShape2D); diff --git a/src/v_video.h b/src/v_video.h index 61871a088..484007c6d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -209,6 +209,14 @@ struct VMVa_List const uint8_t *reginfo; }; +class DShape2DTransform : public DObject +{ + + DECLARE_CLASS(DShape2DTransform, DObject) +public: + DMatrix3x3 transform; +}; + // intermediate struct for fake shape drawing enum EClearWhich @@ -226,6 +234,11 @@ public: TArray mIndices; TArray mVertices; TArray mCoords; + + DMatrix3x3 transform; + + bool dirty = true; + TArray mTransformedVertices; }; // diff --git a/src/vectors.h b/src/vectors.h index 76bf8132f..6be576ffa 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -979,6 +979,35 @@ Outside comments: A faster version with only 10 (not 24) multiplies. TMatrix3x3(const Vector3 &axis, TAngle degrees); + static TMatrix3x3 Rotate2D(double radians) + { + double c = g_cos(radians); + double s = g_sin(radians); + TMatrix3x3 ret; + ret.Cells[0][0] = c; ret.Cells[0][1] = -s; ret.Cells[0][2] = 0; + ret.Cells[1][0] = s; ret.Cells[1][1] = c; ret.Cells[1][2] = 0; + ret.Cells[2][0] = 0; ret.Cells[2][1] = 0; ret.Cells[2][2] = 1; + return ret; + } + + static TMatrix3x3 Scale2D(TVector2 scaleVec) + { + TMatrix3x3 ret; + ret.Cells[0][0] = scaleVec.X; ret.Cells[0][1] = 0; ret.Cells[0][2] = 0; + ret.Cells[1][0] = 0; ret.Cells[1][1] = scaleVec.Y; ret.Cells[1][2] = 0; + ret.Cells[2][0] = 0; ret.Cells[2][1] = 0; ret.Cells[2][2] = 1; + return ret; + } + + static TMatrix3x3 Translate2D(TVector2 translateVec) + { + TMatrix3x3 ret; + ret.Cells[0][0] = 1; ret.Cells[0][1] = 0; ret.Cells[0][2] = translateVec.X; + ret.Cells[1][0] = 0; ret.Cells[1][1] = 1; ret.Cells[1][2] = translateVec.Y; + ret.Cells[2][0] = 0; ret.Cells[2][1] = 0; ret.Cells[2][2] = 1; + return ret; + } + void Zero() { memset (this, 0, sizeof *this); diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index 650b9f249..122f9cf69 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -172,6 +172,14 @@ enum DrawTextureTags DTA_Monospace, // Strings only: Use a fixed distance between characters. }; +class Shape2DTransform : Object native +{ + native void Clear(); + native void Rotate(double angle); + native void Scale(Vector2 scaleVec); + native void Translate(Vector2 translateVec); +} + class Shape2D : Object native { enum EClearWhich @@ -181,6 +189,8 @@ class Shape2D : Object native C_Indices = 4, }; + native void SetTransform(Shape2DTransform transform); + native void Clear( int which = C_Verts|C_Coords|C_Indices ); native void PushVertex( Vector2 v ); native void PushCoord( Vector2 c );