Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
f6b6e56
test case
Sep 8, 2018
f1ce6af
calculating light bounds in AABox around frustum in game example for …
Sep 9, 2018
4262193
added tight projection around camera frustum, light projection near a…
Sep 10, 2018
e1eada7
shadow bug dependent on camera direction
Sep 11, 2018
924fc01
imgui reacting to input and drawing on screen from render device
sp0lsh Sep 25, 2018
cceace4
proper init, render deinit and windows created by game
sp0lsh Sep 25, 2018
8d4f0e0
comments
sp0lsh Sep 25, 2018
f16f8d5
comments
sp0lsh Sep 25, 2018
7f23fd5
Merge branch 'dev' into fet/imgui
sp0lsh Sep 27, 2018
ef0e789
commented #pragma failing travis ci
sp0lsh Sep 28, 2018
8befcc8
removed #pragma
sp0lsh Sep 28, 2018
c5f2ab8
removed pragma from resource
sp0lsh Sep 28, 2018
4ac9b58
commented unused components
sp0lsh Sep 28, 2018
c5cab92
commented out wrong variable doh...
sp0lsh Sep 28, 2018
8522b8f
prototype of shadow casters culling
sp0lsh Sep 29, 2018
3c4215e
moved code to rendering device, tested on example scene and on sponza…
sp0lsh Sep 30, 2018
1bd2719
added AABox around every drawn mesh and still fails on sponza
sp0lsh Sep 30, 2018
a999afa
removed shadow casters AABox
sp0lsh Sep 30, 2018
5d78698
stable shadows working on sponza and test scene
sp0lsh Oct 20, 2018
9bd85a7
stable shadowmap
sp0lsh Oct 21, 2018
a121570
interpolated Percentage Closer Filtering
sp0lsh Oct 21, 2018
168d9a4
shadows prototype cleanup
sp0lsh Oct 22, 2018
85866ba
shadow ramblings
sp0lsh Oct 23, 2018
3ee3414
Merge branch 'dev' into fet/imgui
sp0lsh Oct 26, 2018
b2eddea
merged with dev
sp0lsh Oct 26, 2018
1210c94
cmake attempt
sp0lsh Oct 26, 2018
b22bd5a
moved imgui to third parties, cmake updated for Engine, RenderingDevi…
sp0lsh Oct 30, 2018
003f1e7
removed sanity spam
sp0lsh Oct 30, 2018
3d02fa9
resource cleanup
sp0lsh Oct 30, 2018
c4ee972
imguisystem cleanup
sp0lsh Oct 30, 2018
f3aacaf
imgui world component cleanup
sp0lsh Oct 30, 2018
e1711fa
added non windows API attributes to imconfig.h
sp0lsh Oct 30, 2018
d5001ab
moved imgui to pch
sp0lsh Oct 30, 2018
0f58768
silencing third party gcc -Wimplicit-fallthrough=
sp0lsh Oct 30, 2018
2b5a565
enabled -fPIC (Position Independent Code) for imgui static lib to be …
sp0lsh Oct 30, 2018
3113e77
fixing gcc includes
sp0lsh Oct 30, 2018
bc8c094
fixing cgg includes
sp0lsh Oct 30, 2018
78d1a90
made includes same as in GLTextureDeviceProxy
sp0lsh Oct 30, 2018
ab80981
removed commented out code
sp0lsh Oct 30, 2018
b9fb4b7
ImguiUpdate is now in System, Imgui context creation moved to ImguiSy…
sp0lsh Nov 1, 2018
7bd9937
moved Imgui to Engine subdirectory
sp0lsh Nov 2, 2018
32e5d29
Added clipboard support, tweaked mouse handling and input that can be…
sp0lsh Nov 2, 2018
19cca52
added UTF8 char input from keyboard keys
sp0lsh Nov 2, 2018
58e2f9a
fixing input consumption (works on all widowns: engine and game)
sp0lsh Nov 2, 2018
6984d1d
added output queue and events handled by SDL
sp0lsh Nov 3, 2018
f0c1cc5
CI fix
sp0lsh Nov 3, 2018
354c6c4
CI fix and cleanup
sp0lsh Nov 3, 2018
362d1fb
CI fix
sp0lsh Nov 3, 2018
470215d
CI fix
sp0lsh Nov 3, 2018
1572e31
fix
sp0lsh Nov 3, 2018
fd3f38c
Merge branch 'fet/imgui' into rendering/shadows-pt-2
sp0lsh Nov 3, 2018
9d1561b
Moved getting axis vector from MovementSystem to EntityTransform
sp0lsh Nov 4, 2018
23e80d3
shadowmap ortho projection has correct direction based on dir light f…
sp0lsh Nov 5, 2018
e77e88e
shadowmap projection in [0, 1] range
sp0lsh Nov 5, 2018
2351797
stable shadows on frustum transform and properties change
sp0lsh Nov 5, 2018
6a58900
shadows prototype with tight bound around frustum and ortho projectio…
sp0lsh Nov 5, 2018
dbaa34e
more changes
sp0lsh Nov 5, 2018
b28420f
tweaks to AABB intersection tests
sp0lsh Nov 7, 2018
c72f2f5
added tweakable shadow bias and glPolygonOffset
sp0lsh Nov 7, 2018
c9330cf
working evsm2 and evsm4
sp0lsh Nov 15, 2018
b747335
Merge branch 'rendering/shadows-pt-3' into rendering/shadows-pt-2
sp0lsh Nov 15, 2018
3f97ac2
shadow projection working with shadow bounds extended by vertical sha…
sp0lsh Nov 22, 2018
917f185
some EVSM4 shadows that work
sp0lsh Nov 23, 2018
a513a82
created pass with shadowmap
sp0lsh Nov 24, 2018
ab700b3
switched renderer to use Shadommap pass
sp0lsh Nov 24, 2018
f9ce34d
parametrizing shadow types
sp0lsh Nov 25, 2018
7217fce
EVSM2 seems to work as well
sp0lsh Nov 25, 2018
f205054
removed debug light parameters, shadowmap pass has pcf and evsm versions
sp0lsh Nov 25, 2018
1504210
removed debug variables from light and camera components
sp0lsh Nov 25, 2018
6cc8658
Merge branch 'dev' into rendering/shadows-pt-2
sp0lsh Nov 25, 2018
69348dc
CI fix
sp0lsh Nov 25, 2018
74f5b1e
CI fix
sp0lsh Nov 25, 2018
711c1cf
CI fix
sp0lsh Nov 25, 2018
e543a7a
CI fix
sp0lsh Nov 25, 2018
d5d0905
CI Fix
sp0lsh Nov 25, 2018
c68508a
debug rendering cleanup
sp0lsh Nov 25, 2018
e60202e
cleanup and comments
sp0lsh Nov 25, 2018
02279c9
cleanup
sp0lsh Nov 25, 2018
8308170
compilation fix
sp0lsh Nov 25, 2018
78c1a0e
cleanup
sp0lsh Nov 25, 2018
c3d708e
cleanup
sp0lsh Nov 25, 2018
ff522f2
ignore shader dump extension
sp0lsh Nov 25, 2018
e565d53
fix
sp0lsh Nov 25, 2018
ed965e4
Added comment for .dump file extention
sp0lsh Nov 25, 2018
5ff85ae
cleanup
sp0lsh Nov 25, 2018
e1e9eb6
AABB unit tests
sp0lsh Nov 25, 2018
1afdff3
Merge branch 'rendering/shadows-pt-2' of https://github.com/sp0lsh/Po…
sp0lsh Nov 25, 2018
ad72f20
Merge branch 'dev' into rendering/shadows-pt-2
sp0lsh Nov 25, 2018
3b76a3c
CI fix, tabbed documents
sp0lsh Dec 12, 2018
5f36766
CI fix, tabbed documents
sp0lsh Dec 12, 2018
eb4bb6a
review fix, tabbed code
sp0lsh Dec 12, 2018
bbf2823
assert and nullptr fix
sp0lsh Dec 12, 2018
bd69205
None RenderingSettingsComponent fix
sp0lsh Dec 12, 2018
880fb99
review fix
sp0lsh Dec 12, 2018
39baf37
review fix, updated includes
sp0lsh Dec 12, 2018
12abc19
review fix, removed commented code
sp0lsh Dec 12, 2018
6518669
magic variable moved to constant
sp0lsh Dec 12, 2018
54ce36f
CI fix
sp0lsh Dec 12, 2018
2378f9b
CI fix
sp0lsh Dec 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Engine specific files
console.log
*.dump # shader content dumps for debuging

# Engine local configurations
AssetsPathConfig.json
Expand Down Expand Up @@ -69,4 +70,3 @@ xcuserdata/

# Exculdes from ignore
!**/ThirdParty/**

75 changes: 41 additions & 34 deletions PolyEngine/Core/Src/Math/AABox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
using namespace Poly;

//------------------------------------------------------------------------------
AABox::AABox(const Vector& position, const Vector& size)
: Pos(position), Size(size)
AABox::AABox(const Vector& min, const Vector& size)
: Min(min), Size(size)
{
ASSERTE(Size.X >= 0 && Size.Y >= 0 && Size.Z >= 0, "Invalid aabox size!");
}

//------------------------------------------------------------------------------
AABox AABox::GetIntersectionVolume(const AABox& rhs) const
{
const float r1MinX = std::min(Pos.X, Pos.X + Size.X);
const float r1MaxX = std::max(Pos.X, Pos.X + Size.X);
const float r1MinY = std::min(Pos.Y, Pos.Y + Size.Y);
const float r1MaxY = std::max(Pos.Y, Pos.Y + Size.Y);
const float r1MinZ = std::min(Pos.Z, Pos.Z + Size.Z);
const float r1MaxZ = std::max(Pos.Z, Pos.Z + Size.Z);
const float r1MinX = std::min(Min.X, Min.X + Size.X);
const float r1MaxX = std::max(Min.X, Min.X + Size.X);
const float r1MinY = std::min(Min.Y, Min.Y + Size.Y);
const float r1MaxY = std::max(Min.Y, Min.Y + Size.Y);
const float r1MinZ = std::min(Min.Z, Min.Z + Size.Z);
const float r1MaxZ = std::max(Min.Z, Min.Z + Size.Z);

const float r2MinX = std::min(rhs.Pos.X, rhs.Pos.X + rhs.Size.X);
const float r2MaxX = std::max(rhs.Pos.X, rhs.Pos.X + rhs.Size.X);
const float r2MinY = std::min(rhs.Pos.Y, rhs.Pos.Y + rhs.Size.Y);
const float r2MaxY = std::max(rhs.Pos.Y, rhs.Pos.Y + rhs.Size.Y);
const float r2MinZ = std::min(rhs.Pos.Z, rhs.Pos.Z + rhs.Size.Z);
const float r2MaxZ = std::max(rhs.Pos.Z, rhs.Pos.Z + rhs.Size.Z);
const float r2MinX = std::min(rhs.Min.X, rhs.Min.X + rhs.Size.X);
const float r2MaxX = std::max(rhs.Min.X, rhs.Min.X + rhs.Size.X);
const float r2MinY = std::min(rhs.Min.Y, rhs.Min.Y + rhs.Size.Y);
const float r2MaxY = std::max(rhs.Min.Y, rhs.Min.Y + rhs.Size.Y);
const float r2MinZ = std::min(rhs.Min.Z, rhs.Min.Z + rhs.Size.Z);
const float r2MaxZ = std::max(rhs.Min.Z, rhs.Min.Z + rhs.Size.Z);

const float interLeft = std::max(r1MinX, r2MinX);
const float interTop = std::max(r1MinY, r2MinY);
Expand All @@ -36,9 +36,7 @@ AABox AABox::GetIntersectionVolume(const AABox& rhs) const
const float interDown = std::min(r1MaxZ, r2MaxZ);

if ((interLeft < interRight) && (interTop < interBottom) && (interUp < interDown))
{
return AABox(Vector(interLeft, interTop, interUp), Vector(interRight - interLeft, interBottom - interTop, interDown - interUp));
}
else
return AABox(Vector::ZERO, Vector::ZERO);
}
Expand All @@ -47,34 +45,34 @@ std::array<Vector, 8> Poly::AABox::GetVertices() const
{
SILENCE_CLANG_WARNING(-Wmissing-braces, "Everything is ok here.");
return std::array<Vector, 8>{
Pos,
Pos + Vector(Size.X, 0, 0),
Pos + Vector(Size.X, Size.Y, 0),
Pos + Vector(Size.X, Size.Y, Size.Z),
Pos + Vector(0, Size.Y, Size.Z),
Pos + Vector(0, 0, Size.Z),
Pos + Vector(0, Size.Y, 0),
Pos + Vector(Size.X, 0, Size.Z)
Min,
Min + Vector(Size.X, 0, 0),
Min + Vector(Size.X, Size.Y, 0),
Min + Vector(Size.X, Size.Y, Size.Z),
Min + Vector(0, Size.Y, Size.Z),
Min + Vector(0, 0, Size.Z),
Min + Vector(0, Size.Y, 0),
Min + Vector(Size.X, 0, Size.Z)
};
UNSILENCE_CLANG_WARNING();
}

AABox Poly::AABox::GetTransformed(const Matrix& transform) const
{
Vector min = transform * Pos;
Vector min = transform * Min;
Vector max = min;

// Gather other 7 points
SILENCE_CLANG_WARNING(-Wmissing-braces, "Everything is ok here.");
std::array<Vector, 7> points =
{
Pos + Vector(Size.X, 0, 0),
Pos + Vector(Size.X, Size.Y, 0),
Pos + Vector(Size.X, Size.Y, Size.Z),
Pos + Vector(0, Size.Y, Size.Z),
Pos + Vector(0, 0, Size.Z),
Pos + Vector(0, Size.Y, 0),
Pos + Vector(Size.X, 0, Size.Z)
Min + Vector(Size.X, 0, 0),
Min + Vector(Size.X, Size.Y, 0),
Min + Vector(Size.X, Size.Y, Size.Z),
Min + Vector(0, Size.Y, Size.Z),
Min + Vector(0, 0, Size.Z),
Min + Vector(0, Size.Y, 0),
Min + Vector(Size.X, 0, Size.Z)
};
UNSILENCE_CLANG_WARNING();

Expand All @@ -93,7 +91,16 @@ Poly::AABox& Poly::AABox::Expand(const AABox& rhs)
{
Vector min = Vector::Min(GetMin(), rhs.GetMin());
Vector max = Vector::Max(GetMax(), rhs.GetMax());
Pos = min;
Min = min;
Size = max - min;
return *this;
}

Poly::AABox& Poly::AABox::Expand(const Vector& rhs)
{
Vector min = Vector::Min(GetMin(), rhs);
Vector max = Vector::Max(GetMax(), rhs);
Min = min;
Size = max - min;
return *this;
}
Expand All @@ -102,6 +109,6 @@ Poly::AABox& Poly::AABox::Expand(const AABox& rhs)
namespace Poly {
std::ostream & operator<<(std::ostream& stream, const AABox& rect)
{
return stream << "AABox[Pos: " << rect.Pos << " Size: " << rect.Size << " ]";
return stream << "AABox[Pos: " << rect.Min << " Size: " << rect.Size << " ]";
}
}
76 changes: 58 additions & 18 deletions PolyEngine/Core/Src/Math/AABox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,92 @@ namespace Poly {
{
public:

/// <summary>Constructor from position and size.</summary>
/// <param name="position">Position of the min point of the box.</param>
/// <summary>Constructor from min and size.</summary>
/// <param name="min">Position of the min point of the box.</param>
/// <param name="size">Size (extent) of the box in each of the directions.</param>
AABox(const Vector& position, const Vector& size);
AABox(const Vector& min, const Vector& size);
AABox() = default;

/// <summary>Calculates center of the box.</summary>
/// <returns>Center of the box.</returns>
Vector GetCenter() const { return Pos + (Size * 0.5f); }
Vector GetCenter() const { return Min + (Size * 0.5f); }

/// <summary>Returns the min point of the box. (posiiton)</summary>
/// <returns>Min point of the box.</returns>
const Vector& GetMin() const { return Pos; }
const Vector& GetMin() const { return Min; }

/// <summary>Returns the max point of the box.</summary>
/// <returns>Max point of the box.</returns>
Vector GetMax() const { return Pos + Size; }
Vector GetMax() const { return Min + Size; }

/// <summary>Returns Size of the box in all three dimensions.</summary>
/// <returns>Size of the box. (extent)</returns>
const Vector& GetSize() const { return Size; }

/// <summary>Sets position of the box.</summary>
/// <param name="pos">New position</param>
void SetPosition(const Vector& pos) { Pos = pos; }
void SetMin(const Vector& pos) { Min = pos; }

/// <summary>Sets size of the box.</summary>
/// <param name="size">New size</param>
void SetSize(const Vector& size) { Size = size; }

/// <summary>Checks whether a given AABox is interecting with this AABox.</summary>
/// <param name="rhs">Other box.</param>
/// <see cref="AABox.Contains()"/>
inline bool Intersects(const AABox& rhs) const
{
return (abs(Min.X - rhs.Min.X) * 2.0f < (Size.X + rhs.Size.X))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is Vector::abs method (or at least should be), use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BasicMath.hpp has Poly::abs for float, double and long double overloads but no Vector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added this to trello.

&& (abs(Min.Y - rhs.Min.Y) * 2.0f < (Size.Y + rhs.Size.Y))
&& (abs(Min.Z - rhs.Min.Z) * 2.0f < (Size.Z + rhs.Size.Z));
}

/// <summary>Checks whether this AABox contains a given point.</summary>
/// <param name="point">Point to be checked.</param>
/// <see cref="AABox.IsCollidingWith()"/>
inline bool Contains(const Vector& point) const
{
return point.X >= Pos.X && point.X <= (Pos.X + Size.X)
&& point.Y >= Pos.Y && point.Y <= (Pos.Y + Size.Y)
&& point.Z >= Pos.Z && point.Z <= (Pos.Z + Size.Z);
return point.X >= Min.X && point.X <= (Min.X + Size.X)
&& point.Y >= Min.Y && point.Y <= (Min.Y + Size.Y)
&& point.Z >= Min.Z && point.Z <= (Min.Z + Size.Z);
}

/// <summary>Checks whether a given AABox is interecting with this AABox.</summary>
/// <summary>Checks whether a given AABox contains this AABox on all axes.</summary>
/// <param name="rhs">Other box.</param>
/// <see cref="AABox.Contains()"/>
inline bool Intersects(const AABox& rhs) const
{
return (abs(Pos.X - rhs.Pos.X) * 2 < (Size.X + rhs.Size.X))
&& (abs(Pos.Y - rhs.Pos.Y) * 2 < (Size.Y + rhs.Size.Y))
&& (abs(Pos.Z - rhs.Pos.Z) * 2 < (Size.Z + rhs.Size.Z));
inline bool Contains(const AABox& rhs) const
{
return ContainsX(rhs) && ContainsY(rhs) && ContainsZ(rhs);
}

/// <summary>Checks whether a given AABox contains this AABox on XY plane.</summary>
/// <param name="rhs">Other box.</param>
inline bool ContainsXY(const AABox& rhs) const
{
return ContainsX(rhs) && ContainsY(rhs);
}

/// <summary>Checks whether a given AABox contains this AABox on X axis.</summary>
/// <param name="rhs">Other box.</param>
inline bool ContainsX(const AABox& rhs) const
{
return (Min.X <= rhs.Min.X + rhs.Size.X)
&& (Min.X + Size.X >= rhs.Min.X);
}

/// <summary>Checks whether a given AABox contains this AABox on Y axis.</summary>
/// <param name="rhs">Other box.</param>
inline bool ContainsY(const AABox& rhs) const
{
return (Min.Y <= rhs.Min.Y + rhs.Size.Y)
&& (Min.Y + Size.Y >= rhs.Min.Y);
}

/// <summary>Checks whether a given AABox contains this AABox on Z axis.</summary>
/// <param name="rhs">Other box.</param>
inline bool ContainsZ(const AABox& rhs) const
{
return (Min.Z <= rhs.Min.Z + rhs.Size.Z)
&& (Min.Z + Size.Z >= rhs.Min.Z);
}

std::array<Vector, 8> GetVertices() const;
Expand All @@ -74,9 +112,11 @@ namespace Poly {

AABox& Expand(const AABox& rhs);

AABox& Expand(const Vector& rhs);

CORE_DLLEXPORT friend std::ostream& operator<< (std::ostream& stream, const AABox& color);
private:
Vector Pos;
Vector Min;
Vector Size;
};
}
88 changes: 55 additions & 33 deletions PolyEngine/Core/Src/Math/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,27 @@ Matrix& Matrix::SetScale(const Vector& scale) {
//------------------------------------------------------------------------------
Matrix& Matrix::SetLookAt(const Vector& pos, const Vector& lookAt, const Vector& up)
{
const Vector front((lookAt - pos).GetNormalized());
const Vector side(front.Cross(up).GetNormalized());
const Vector newUp(side.Cross(front));

SetIdentity();
// same as GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtRH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up)
Data[0] = side.X; // glm[0][0]
Data[1] = side.Y; // glm[1][0]
Data[2] = side.Z; // glm[2][0]

Vector zAxis = pos - lookAt;
zAxis.Normalize();
Vector xAxis = up.Cross(zAxis);
xAxis.Normalize();
Vector yAxis = zAxis.Cross(xAxis);
Data[4] = newUp.X; // glm[0][1]
Data[5] = newUp.Y; // glm[1][1]
Data[6] = newUp.Z; // glm[2][1]

Data[0] = xAxis.X;
Data[1] = yAxis.X;
Data[2] = zAxis.X;
Data[8] = -front.X; // glm[0][2]
Data[9] = -front.Y; // glm[1][2]
Data[10] = -front.Z; // glm[2][2]

Data[4] = xAxis.Y;
Data[5] = yAxis.Y;
Data[6] = zAxis.Y;

Data[8] = xAxis.Z;
Data[9] = yAxis.Z;
Data[10] = zAxis.Z;
Data[12] = -(side.Dot(pos)); // glm[3][0]
Data[13] = -(newUp.Dot(pos)); // glm[3][1]
Data[14] = front.Dot(pos); // glm[3][2]

return *this;
}
Expand Down Expand Up @@ -276,27 +278,47 @@ Matrix& Poly::Matrix::SetPerspective(Angle fov, float aspect, float near, float
}

//------------------------------------------------------------------------------
Matrix& Poly::Matrix::SetOrthographic(float bottom, float top, float left, float right, float near, float far)
Matrix& Poly::Matrix::SetOrthographicZO(float bottom, float top, float left, float right, float near, float far)
{
Data[0] = 2.0f / (right - left);
Data[1] = 0;
Data[2] = 0;
Data[3] = -(right + left) / (right - left);

Data[4] = 0;
Data[5] = 2.0f / (top - bottom);
Data[6] = 0;
Data[7] = -(top + bottom) / (top - bottom);
SetIdentity();
// same as orthoRH_ZO: GLM_RIGHT_HANDED && GLM_DEPTH_ZERO_TO_ONE
Data[0] = 2.0f / (right - left); // glm[0][0]
Data[1] = 0.0f;
Data[2] = 0.0f;
Data[3] = -(right + left) / (right - left); // glm[3][0]

Data[4] = 0.0f;
Data[5] = 2.0f / (top - bottom); // glm[1][1]
Data[6] = 0.0f;
Data[7] = -(top + bottom) / (top - bottom); // glm[3][1]

Data[8] = 0.0f;
Data[9] = 0.0f;
Data[10] = 1.0f / (far - near); // glm[2][2]
Data[11] = near / (far - near); // glm[3][2]

Data[8] = 0;
Data[9] = 0;
Data[10] = 2.0f / (far - near);
Data[11] = -(far + near) / (far - near);
return *this;
}

Data[12] = 0;
Data[13] = 0;
Data[14] = 0;
Data[15] = 1;
//------------------------------------------------------------------------------
Matrix& Poly::Matrix::SetOrthographic(float bottom, float top, float left, float right, float near, float far)
{
SetIdentity();
// same as orthoRH_NO: GLM_RIGHT_HANDED && GLM_DEPTH_NEGATIVE_ONE_TO_ONE
Data[0] = 2.0f / (right - left); // glm[0][0]
Data[1] = 0.0f;
Data[2] = 0.0f;
Data[3] = -(right + left) / (right - left); // glm[3][0]

Data[4] = 0.0f;
Data[5] = 2.0f / (top - bottom); // glm[1][1]
Data[6] = 0.0f;
Data[7] = -(top + bottom) / (top - bottom); // glm[3][1]

Data[8] = 0.0f;
Data[9] = 0.0f;
Data[10] = 2.0f / (far - near); // glm[2][2]
Data[11] = -(far + near) / (far - near); // glm[3][2]

return *this;
}
Expand Down
9 changes: 9 additions & 0 deletions PolyEngine/Core/Src/Math/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ namespace Poly
/// <returns>Reference to itself.</returns>
Matrix& SetPerspective(Angle fov, float aspect, float near, float far);

/// <summary>Initializes matrix with orthographics projection in range of [0, 1]</summary>
/// <param name="top">Top dimension.</param>
/// <param name="bottom">Bottom dimension.</param>
/// <param name="left">Left dimension.</param>
/// <param name="right">Right dimension</param>
/// <param name="near">Near Z plane.</param>
/// <param name="far">Far Z plane.</param>
/// <returns>Reference to itself.</returns>
Matrix& SetOrthographicZO(float top, float bottom, float left, float right, float near, float far);

/// <summary>Initializes matrix with orthographics projection</summary>
/// <param name="top">Top dimension.</param>
Expand Down
Loading