Skip to content

Commit

Permalink
Fixes, added matrix transform method
Browse files Browse the repository at this point in the history
  • Loading branch information
kraifpatrik committed Feb 2, 2022
1 parent e46abdd commit 97946e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions BBMOD_GML/scripts/BBMOD_Camera/BBMOD_Camera.gml
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ function BBMOD_Camera() constructor
return undefined;
}
_screenPos = _screenPos.Scale(1.0 / _screenPos.W);
_screenPos.X = (_screenPos.X * 0.5 + 0.5) * _screenWidth;
_screenPos.Y = (1.0 - (_screenPos.Y * 0.5 + 0.5)) * _screenHeight;
_screenPos.X = ((_screenPos.X * 0.5) + 0.5) * _screenWidth;
_screenPos.Y = (1.0 - ((_screenPos.Y * 0.5) + 0.5)) * _screenHeight;
return _screenPos;
};

Expand Down
14 changes: 12 additions & 2 deletions BBMOD_GML/scripts/BBMOD_Matrix/BBMOD_Matrix.gml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function BBMOD_Matrix(_raw=undefined) constructor
/// @func ApplyView()
/// @desc Changes the view world matrix to this one.
/// @return {BBMOD_Matrix} Returns `self`.
static ApplyWorld = function () {
static ApplyView = function () {
gml_pragma("forceinline");
matrix_set(matrix_view, Raw);
return self;
Expand All @@ -201,7 +201,7 @@ function BBMOD_Matrix(_raw=undefined) constructor
/// @func ApplyProjection()
/// @desc Changes the current projeciton matrix to this one.
/// @return {BBMOD_Matrix} Returns `self`.
static ApplyWorld = function () {
static ApplyProjection = function () {
gml_pragma("forceinline");
matrix_set(matrix_projection, Raw);
return self;
Expand Down Expand Up @@ -425,6 +425,16 @@ function BBMOD_Matrix(_raw=undefined) constructor
return _res;
};

/// @func Transform(_vector)
/// @desc Transforms a vector by the matrix and returns the result as a new
/// vector.
/// @param {BBMOD_Vec4} _vector The vector to transform.
/// @return {BBMOD_Vec4} The tranformed vector.
static Transform = function (_vector) {
gml_pragma("forceinline");
return _vector.Transform(Raw);
};

/// @func Transpose()
/// @desc Creates a transpose of this matrix.
/// @return {BBMOD_Matrix} The transposed matrix.
Expand Down
1 change: 1 addition & 0 deletions docs_src/Changelog/Changelog3.1.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This tiny release mainly adds support for orthographic camera projection, as req
## GML API:
### Core module:
* Added new methods `ApplyWorld`, `ApplyView` and `ApplyProjection` to `BBMOD_Matrix`, using which you can set it as the current world/view/projection matrix respectively.
* Added new method `BBMOD_Matrix.Transform`, using which you can transform a `BBMOD_Vec4` with the matrix.

### Camera module:
* Added new property `BBMOD_Camera.Orthographic`, using which you can enable orthographic projection.
Expand Down

0 comments on commit 97946e9

Please sign in to comment.