mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa matrix
This commit is contained in:
parent
28dae3df60
commit
f920900519
@ -3,7 +3,7 @@
|
||||
#
|
||||
|
||||
# Add source to this project's executable.
|
||||
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizer-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp")
|
||||
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizer-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp" "common/matrix.cpp")
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
||||
|
17
framework/common/math.hpp
Normal file
17
framework/common/math.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef XNA_COMMON_MATH_HPP
|
||||
#define XNA_COMMON_MATH_HPP
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace xna {
|
||||
struct MathHelper {
|
||||
static constexpr double E = 2.7182818284590451;
|
||||
static constexpr double PI = 3.1415926535897931;
|
||||
static constexpr double TAU = 6.2831853071795862;
|
||||
static constexpr double EPSILON = std::numeric_limits<double>::epsilon();
|
||||
};
|
||||
|
||||
using Math = MathHelper;
|
||||
}
|
||||
|
||||
#endif
|
287
framework/common/matrix.cpp
Normal file
287
framework/common/matrix.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
#include "matrix.hpp"
|
||||
|
||||
namespace xna {
|
||||
Matrix Matrix::CreateBillboard(Vector3 const& objectPosition, Vector3 const& cameraPosition, Vector3 const& cameraUpVector, Vector3* cameraForwardVector)
|
||||
{
|
||||
Vector3 result1 = Vector3::Subtract(objectPosition, cameraPosition);
|
||||
const auto d = result1.LengthSquared();
|
||||
|
||||
if (d < 9.9999997473787516E-05)
|
||||
result1 = cameraForwardVector ? -*cameraForwardVector : Vector3::Forward();
|
||||
else
|
||||
result1 = Vector3::Multiply(result1, 1.0f / sqrt(d));
|
||||
|
||||
Vector3 result2 = Vector3::Cross(cameraUpVector, result1);
|
||||
result2.Normalize();
|
||||
|
||||
Vector3 result3 = Vector3::Cross(result1, result2);
|
||||
|
||||
Matrix result;
|
||||
result.M11 = result2.X;
|
||||
result.M12 = result2.Y;
|
||||
result.M13 = result2.Z;
|
||||
result.M14 = 0.0f;
|
||||
result.M21 = result3.X;
|
||||
result.M22 = result3.Y;
|
||||
result.M23 = result3.Z;
|
||||
result.M24 = 0.0f;
|
||||
result.M31 = result1.X;
|
||||
result.M32 = result1.Y;
|
||||
result.M33 = result1.Z;
|
||||
result.M34 = 0.0f;
|
||||
result.M41 = objectPosition.X;
|
||||
result.M42 = objectPosition.Y;
|
||||
result.M43 = objectPosition.Z;
|
||||
result.M44 = 1.0f;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateConstrainedBillboard(Vector3 const& objectPosition, Vector3 const& cameraPosition, Vector3 const& rotateAxis, Vector3* cameraForwardVector, Vector3* objectForwardVector)
|
||||
{
|
||||
Vector3 result1 = Vector3::Subtract(objectPosition, cameraPosition);
|
||||
const auto d = result1.LengthSquared();
|
||||
|
||||
if (d < 9.9999997473787516E-05)
|
||||
result1 = cameraForwardVector ? -*cameraForwardVector : Vector3::Forward();
|
||||
else
|
||||
result1 = Vector3::Multiply(result1, 1.0f / sqrt(d));
|
||||
|
||||
//Vector3 vector2 = rotateAxis;
|
||||
float result2 = Vector3::Dot(rotateAxis, result1);
|
||||
const auto factor = 0.998254656791687;
|
||||
const auto forward = Vector3::Forward();
|
||||
Vector3 result3 = forward;
|
||||
Vector3 result4;
|
||||
|
||||
if (abs(result2) > factor) {
|
||||
if (objectForwardVector) {
|
||||
result2 = Vector3::Dot(rotateAxis, *objectForwardVector);
|
||||
|
||||
if (abs(result2) > factor) {
|
||||
auto const _abs = abs(rotateAxis.X * forward.X + rotateAxis.Y * forward.Y + rotateAxis.Z * forward.Z);
|
||||
|
||||
if (_abs > factor)
|
||||
result3 = Vector3::Right();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (abs(rotateAxis.X * forward.X + rotateAxis.Y * forward.Y + rotateAxis.Z * forward.Z) > factor)
|
||||
result3 = Vector3::Right();
|
||||
}
|
||||
|
||||
result4 = Vector3::Cross(rotateAxis, result3);
|
||||
result4.Normalize();
|
||||
|
||||
result3 = Vector3::Cross(result4, rotateAxis);
|
||||
result3.Normalize();
|
||||
}
|
||||
else
|
||||
{
|
||||
result4 = Vector3::Cross(rotateAxis, result1);
|
||||
result4.Normalize();
|
||||
result3 = Vector3::Cross(result4, rotateAxis);
|
||||
result3.Normalize();
|
||||
}
|
||||
|
||||
Matrix constrainedBillboard;
|
||||
constrainedBillboard.M11 = result4.X;
|
||||
constrainedBillboard.M12 = result4.Y;
|
||||
constrainedBillboard.M13 = result4.Z;
|
||||
constrainedBillboard.M14 = 0.0f;
|
||||
constrainedBillboard.M21 = rotateAxis.X;
|
||||
constrainedBillboard.M22 = rotateAxis.Y;
|
||||
constrainedBillboard.M23 = rotateAxis.Z;
|
||||
constrainedBillboard.M24 = 0.0f;
|
||||
constrainedBillboard.M31 = result3.X;
|
||||
constrainedBillboard.M32 = result3.Y;
|
||||
constrainedBillboard.M33 = result3.Z;
|
||||
constrainedBillboard.M34 = 0.0f;
|
||||
constrainedBillboard.M41 = objectPosition.X;
|
||||
constrainedBillboard.M42 = objectPosition.Y;
|
||||
constrainedBillboard.M43 = objectPosition.Z;
|
||||
constrainedBillboard.M44 = 1.0f;
|
||||
return constrainedBillboard;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateRotationX(float radians)
|
||||
{
|
||||
const auto num1 = cos(radians);
|
||||
const auto num2 = sin(radians);
|
||||
|
||||
Matrix rotationX;
|
||||
rotationX.M11 = 1.0f;
|
||||
rotationX.M12 = 0.0f;
|
||||
rotationX.M13 = 0.0f;
|
||||
rotationX.M14 = 0.0f;
|
||||
rotationX.M21 = 0.0f;
|
||||
rotationX.M22 = num1;
|
||||
rotationX.M23 = num2;
|
||||
rotationX.M24 = 0.0f;
|
||||
rotationX.M31 = 0.0f;
|
||||
rotationX.M32 = -num2;
|
||||
rotationX.M33 = num1;
|
||||
rotationX.M34 = 0.0f;
|
||||
rotationX.M41 = 0.0f;
|
||||
rotationX.M42 = 0.0f;
|
||||
rotationX.M43 = 0.0f;
|
||||
rotationX.M44 = 1.0f;
|
||||
return rotationX;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateRotationY(float radians)
|
||||
{
|
||||
const auto num1 = cos(radians);
|
||||
const auto num2 = sin(radians);
|
||||
Matrix rotationY;
|
||||
rotationY.M11 = num1;
|
||||
rotationY.M12 = 0.0f;
|
||||
rotationY.M13 = -num2;
|
||||
rotationY.M14 = 0.0f;
|
||||
rotationY.M21 = 0.0f;
|
||||
rotationY.M22 = 1.0f;
|
||||
rotationY.M23 = 0.0f;
|
||||
rotationY.M24 = 0.0f;
|
||||
rotationY.M31 = num2;
|
||||
rotationY.M32 = 0.0f;
|
||||
rotationY.M33 = num1;
|
||||
rotationY.M34 = 0.0f;
|
||||
rotationY.M41 = 0.0f;
|
||||
rotationY.M42 = 0.0f;
|
||||
rotationY.M43 = 0.0f;
|
||||
rotationY.M44 = 1.0f;
|
||||
return rotationY;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateRotationZ(float radians)
|
||||
{
|
||||
const auto num1 = cos(radians);
|
||||
const auto num2 = sin(radians);
|
||||
Matrix rotationZ;
|
||||
rotationZ.M11 = num1;
|
||||
rotationZ.M12 = num2;
|
||||
rotationZ.M13 = 0.0f;
|
||||
rotationZ.M14 = 0.0f;
|
||||
rotationZ.M21 = -num2;
|
||||
rotationZ.M22 = num1;
|
||||
rotationZ.M23 = 0.0f;
|
||||
rotationZ.M24 = 0.0f;
|
||||
rotationZ.M31 = 0.0f;
|
||||
rotationZ.M32 = 0.0f;
|
||||
rotationZ.M33 = 1.0f;
|
||||
rotationZ.M34 = 0.0f;
|
||||
rotationZ.M41 = 0.0f;
|
||||
rotationZ.M42 = 0.0f;
|
||||
rotationZ.M43 = 0.0f;
|
||||
rotationZ.M44 = 1.0f;
|
||||
return rotationZ;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateFromAxisAngle(Vector3 const& axis, float angle)
|
||||
{
|
||||
const auto x = axis.X;
|
||||
const auto y = axis.Y;
|
||||
const auto z = axis.Z;
|
||||
const auto num1 = sin(angle);
|
||||
const auto num2 = cos(angle);
|
||||
const auto num3 = x * x;
|
||||
const auto num4 = y * y;
|
||||
const auto num5 = z * z;
|
||||
const auto num6 = x * y;
|
||||
const auto num7 = x * z;
|
||||
const auto num8 = y * z;
|
||||
|
||||
Matrix fromAxisAngle;
|
||||
fromAxisAngle.M11 = num3 + num2 * (1.0f - num3);
|
||||
fromAxisAngle.M12 = (num6 - num2 * num6 + num1 * z);
|
||||
fromAxisAngle.M13 = (num7 - num2 * num7 - num1 * y);
|
||||
fromAxisAngle.M14 = 0.0f;
|
||||
fromAxisAngle.M21 = (num6 - num2 * num6 - num1 * z);
|
||||
fromAxisAngle.M22 = num4 + num2 * (1.0f - num4);
|
||||
fromAxisAngle.M23 = (num8 - num2 * num8 + num1 * x);
|
||||
fromAxisAngle.M24 = 0.0f;
|
||||
fromAxisAngle.M31 = (num7 - num2 * num7 + num1 * y);
|
||||
fromAxisAngle.M32 = (num8 - num2 * num8 - num1 * x);
|
||||
fromAxisAngle.M33 = num5 + num2 * (1.0f - num5);
|
||||
fromAxisAngle.M34 = 0.0f;
|
||||
fromAxisAngle.M41 = 0.0f;
|
||||
fromAxisAngle.M42 = 0.0f;
|
||||
fromAxisAngle.M43 = 0.0f;
|
||||
fromAxisAngle.M44 = 1.0f;
|
||||
return fromAxisAngle;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance) {
|
||||
if (fieldOfView <= 0.0 || fieldOfView >= Math::PI || nearPlaneDistance <= 0.0 || farPlaneDistance <= 0.0 || nearPlaneDistance >= farPlaneDistance) {
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
const auto num1 = 1.0f / tan(fieldOfView * 0.5);
|
||||
const auto num2 = num1 / aspectRatio;
|
||||
|
||||
Matrix perspectiveFieldOfView;
|
||||
perspectiveFieldOfView.M11 = num2;
|
||||
perspectiveFieldOfView.M12 = perspectiveFieldOfView.M13 = perspectiveFieldOfView.M14 = 0.0f;
|
||||
perspectiveFieldOfView.M22 = num1;
|
||||
perspectiveFieldOfView.M21 = perspectiveFieldOfView.M23 = perspectiveFieldOfView.M24 = 0.0f;
|
||||
perspectiveFieldOfView.M31 = perspectiveFieldOfView.M32 = 0.0f;
|
||||
perspectiveFieldOfView.M33 = farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
|
||||
perspectiveFieldOfView.M34 = -1.0f;
|
||||
perspectiveFieldOfView.M41 = perspectiveFieldOfView.M42 = perspectiveFieldOfView.M44 = 0.0f;
|
||||
perspectiveFieldOfView.M43 = (nearPlaneDistance * farPlaneDistance / (nearPlaneDistance - farPlaneDistance));
|
||||
return perspectiveFieldOfView;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateLookAt(Vector3 const& cameraPosition, Vector3 const& cameraTarget, Vector3 const& cameraUpVector)
|
||||
{
|
||||
Vector3 vector3_1 = Vector3::Normalize(cameraPosition - cameraTarget);
|
||||
Vector3 vector3_2 = Vector3::Normalize(Vector3::Cross(cameraUpVector, vector3_1));
|
||||
Vector3 vector1 = Vector3::Cross(vector3_1, vector3_2);
|
||||
|
||||
Matrix lookAt;
|
||||
lookAt.M11 = vector3_2.X;
|
||||
lookAt.M12 = vector1.X;
|
||||
lookAt.M13 = vector3_1.X;
|
||||
lookAt.M14 = 0.0f;
|
||||
lookAt.M21 = vector3_2.Y;
|
||||
lookAt.M22 = vector1.Y;
|
||||
lookAt.M23 = vector3_1.Y;
|
||||
lookAt.M24 = 0.0f;
|
||||
lookAt.M31 = vector3_2.Z;
|
||||
lookAt.M32 = vector1.Z;
|
||||
lookAt.M33 = vector3_1.Z;
|
||||
lookAt.M34 = 0.0f;
|
||||
lookAt.M41 = -Vector3::Dot(vector3_2, cameraPosition);
|
||||
lookAt.M42 = -Vector3::Dot(vector1, cameraPosition);
|
||||
lookAt.M43 = -Vector3::Dot(vector3_1, cameraPosition);
|
||||
lookAt.M44 = 1.0f;
|
||||
return lookAt;
|
||||
}
|
||||
|
||||
Matrix Matrix::CreateWorld(Vector3 const& position, Vector3 const& forward, Vector3 const& up)
|
||||
{
|
||||
Vector3 vector3_1 = Vector3::Normalize(-forward);
|
||||
Vector3 vector2 = Vector3::Normalize(Vector3::Cross(up, vector3_1));
|
||||
Vector3 vector3_2 = Vector3::Cross(vector3_1, vector2);
|
||||
|
||||
Matrix world;
|
||||
world.M11 = vector2.X;
|
||||
world.M12 = vector2.Y;
|
||||
world.M13 = vector2.Z;
|
||||
world.M14 = 0.0f;
|
||||
world.M21 = vector3_2.X;
|
||||
world.M22 = vector3_2.Y;
|
||||
world.M23 = vector3_2.Z;
|
||||
world.M24 = 0.0f;
|
||||
world.M31 = vector3_1.X;
|
||||
world.M32 = vector3_1.Y;
|
||||
world.M33 = vector3_1.Z;
|
||||
world.M34 = 0.0f;
|
||||
world.M41 = position.X;
|
||||
world.M42 = position.Y;
|
||||
world.M43 = position.Z;
|
||||
world.M44 = 1.0f;
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
#ifndef XNA_COMMON_MATRIX_HPP
|
||||
#define XNA_COMMON_MATRIX_HPP
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "math.hpp"
|
||||
#include "vectors.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct Matrix {
|
||||
float M11{ 0 };
|
||||
@ -22,8 +26,11 @@ namespace xna {
|
||||
|
||||
constexpr Matrix() = default;
|
||||
|
||||
constexpr Matrix(float M11, float M12, float M13, float M14, float M21, float M22, float M23, float M24, float M31, float M32, float M33, float M34, float M41, float M42, float M43, float M44)
|
||||
:
|
||||
constexpr Matrix(
|
||||
float M11, float M12, float M13, float M14,
|
||||
float M21, float M22, float M23, float M24,
|
||||
float M31, float M32, float M33, float M34,
|
||||
float M41, float M42, float M43, float M44) :
|
||||
M11(M11), M12(M12), M13(M13), M14(M14),
|
||||
M21(M21), M22(M22), M23(M23), M24(M24),
|
||||
M31(M31), M32(M32), M33(M33), M34(M34),
|
||||
@ -35,6 +42,550 @@ namespace xna {
|
||||
&& M31 == other.M31 && M32 == other.M32 && M33 == other.M33 && M34 == other.M34
|
||||
&& M41 == other.M41 && M42 == other.M42 && M43 == other.M43 && M44 == other.M44;
|
||||
}
|
||||
|
||||
constexpr static Matrix Identity() {
|
||||
return Matrix(
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
constexpr Vector3 Up() const noexcept { return Vector3(M21, M22, M23); }
|
||||
constexpr Vector3 Down() const noexcept { return Vector3(-M21, -M22, -M23); }
|
||||
constexpr Vector3 Right() const noexcept { return Vector3(M11, M12, M13); }
|
||||
constexpr Vector3 Left() const noexcept { return Vector3(-M11, -M12, -M13); }
|
||||
constexpr Vector3 Forward() const noexcept { return Vector3(-M31, -M32, -M33); }
|
||||
constexpr Vector3 Backward() const noexcept { return Vector3(M31, M32, M33); }
|
||||
constexpr Vector3 Translation() const noexcept { return Vector3(M41, M42, M43); }
|
||||
|
||||
constexpr void Up(Vector3 const& value) noexcept {
|
||||
M21 = value.X;
|
||||
M22 = value.Y;
|
||||
M23 = value.Z;
|
||||
}
|
||||
|
||||
constexpr void Down(Vector3 const& value) noexcept {
|
||||
M21 = -value.X;
|
||||
M22 = -value.Y;
|
||||
M23 = -value.Z;
|
||||
}
|
||||
|
||||
constexpr void Right(Vector3 const& value) noexcept {
|
||||
M11 = value.X;
|
||||
M12 = value.Y;
|
||||
M13 = value.Z;
|
||||
}
|
||||
|
||||
constexpr void Left(Vector3 const& value) noexcept {
|
||||
M11 = -value.X;
|
||||
M12 = -value.Y;
|
||||
M13 = -value.Z;
|
||||
}
|
||||
|
||||
constexpr void Forward(Vector3 const& value) noexcept {
|
||||
M31 = -value.X;
|
||||
M32 = -value.Y;
|
||||
M33 = -value.Z;
|
||||
}
|
||||
|
||||
constexpr void Backward(Vector3 const& value) noexcept {
|
||||
M31 = value.X;
|
||||
M32 = value.Y;
|
||||
M33 = value.Z;
|
||||
}
|
||||
|
||||
constexpr void Translation(Vector3 const& value) noexcept {
|
||||
M41 = value.X;
|
||||
M42 = value.Y;
|
||||
M43 = value.Z;
|
||||
}
|
||||
|
||||
static Matrix CreateBillboard(Vector3 const& objectPosition, Vector3 const& cameraPosition, Vector3 const& cameraUpVector, Vector3* cameraForwardVector);
|
||||
|
||||
static Matrix CreateConstrainedBillboard(
|
||||
Vector3 const& objectPosition,
|
||||
Vector3 const& cameraPosition,
|
||||
Vector3 const& rotateAxis,
|
||||
Vector3* cameraForwardVector,
|
||||
Vector3* objectForwardVector);
|
||||
|
||||
static constexpr Matrix CreateTranslation(Vector3 const& position) {
|
||||
Matrix translation;
|
||||
translation.M11 = 1.0f;
|
||||
translation.M12 = 0.0f;
|
||||
translation.M13 = 0.0f;
|
||||
translation.M14 = 0.0f;
|
||||
translation.M21 = 0.0f;
|
||||
translation.M22 = 1.0f;
|
||||
translation.M23 = 0.0f;
|
||||
translation.M24 = 0.0f;
|
||||
translation.M31 = 0.0f;
|
||||
translation.M32 = 0.0f;
|
||||
translation.M33 = 1.0f;
|
||||
translation.M34 = 0.0f;
|
||||
translation.M41 = position.X;
|
||||
translation.M42 = position.Y;
|
||||
translation.M43 = position.Z;
|
||||
translation.M44 = 1.0f;
|
||||
return translation;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateTranslation(float xPosition, float yPosition, float zPosition) {
|
||||
Matrix translation;
|
||||
translation.M11 = 1.0f;
|
||||
translation.M12 = 0.0f;
|
||||
translation.M13 = 0.0f;
|
||||
translation.M14 = 0.0f;
|
||||
translation.M21 = 0.0f;
|
||||
translation.M22 = 1.0f;
|
||||
translation.M23 = 0.0f;
|
||||
translation.M24 = 0.0f;
|
||||
translation.M31 = 0.0f;
|
||||
translation.M32 = 0.0f;
|
||||
translation.M33 = 1.0f;
|
||||
translation.M34 = 0.0f;
|
||||
translation.M41 = xPosition;
|
||||
translation.M42 = yPosition;
|
||||
translation.M43 = zPosition;
|
||||
translation.M44 = 1.0f;
|
||||
return translation;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateScale(float xScale, float yScale, float zScale) {
|
||||
Matrix scale;
|
||||
scale.M11 = xScale;
|
||||
scale.M12 = 0.0f;
|
||||
scale.M13 = 0.0f;
|
||||
scale.M14 = 0.0f;
|
||||
scale.M21 = 0.0f;
|
||||
scale.M22 = yScale;
|
||||
scale.M23 = 0.0f;
|
||||
scale.M24 = 0.0f;
|
||||
scale.M31 = 0.0f;
|
||||
scale.M32 = 0.0f;
|
||||
scale.M33 = zScale;
|
||||
scale.M34 = 0.0f;
|
||||
scale.M41 = 0.0f;
|
||||
scale.M42 = 0.0f;
|
||||
scale.M43 = 0.0f;
|
||||
scale.M44 = 1.0f;
|
||||
return scale;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateScale(Vector3 const& scales) {
|
||||
Matrix scale;
|
||||
scale.M11 = scales.X;
|
||||
scale.M12 = 0.0f;
|
||||
scale.M13 = 0.0f;
|
||||
scale.M14 = 0.0f;
|
||||
scale.M21 = 0.0f;
|
||||
scale.M22 = scales.Y;
|
||||
scale.M23 = 0.0f;
|
||||
scale.M24 = 0.0f;
|
||||
scale.M31 = 0.0f;
|
||||
scale.M32 = 0.0f;
|
||||
scale.M33 = scales.Z;
|
||||
scale.M34 = 0.0f;
|
||||
scale.M41 = 0.0f;
|
||||
scale.M42 = 0.0f;
|
||||
scale.M43 = 0.0f;
|
||||
scale.M44 = 1.0f;
|
||||
return scale;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateScale(float scale) {
|
||||
Matrix scale1;
|
||||
scale1.M11 = scale;
|
||||
scale1.M12 = 0.0f;
|
||||
scale1.M13 = 0.0f;
|
||||
scale1.M14 = 0.0f;
|
||||
scale1.M21 = 0.0f;
|
||||
scale1.M22 = scale;
|
||||
scale1.M23 = 0.0f;
|
||||
scale1.M24 = 0.0f;
|
||||
scale1.M31 = 0.0f;
|
||||
scale1.M32 = 0.0f;
|
||||
scale1.M33 = scale;
|
||||
scale1.M34 = 0.0f;
|
||||
scale1.M41 = 0.0f;
|
||||
scale1.M42 = 0.0f;
|
||||
scale1.M43 = 0.0f;
|
||||
scale1.M44 = 1.0f;
|
||||
return scale1;
|
||||
}
|
||||
|
||||
static Matrix CreateRotationX(float radians);
|
||||
static Matrix CreateRotationY(float radians);
|
||||
static Matrix CreateRotationZ(float radians);
|
||||
static Matrix CreateFromAxisAngle(Vector3 const& axis, float angle);
|
||||
static Matrix CreatePerspectiveFieldOfView(
|
||||
float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance);
|
||||
|
||||
static constexpr Matrix CreatePerspective(
|
||||
float width, float height, float nearPlaneDistance, float farPlaneDistance) {
|
||||
if (nearPlaneDistance <= 0.0 || farPlaneDistance <= 0.0 || nearPlaneDistance >= farPlaneDistance) {
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
Matrix perspective;
|
||||
perspective.M11 = 2.0f * nearPlaneDistance / width;
|
||||
perspective.M12 = perspective.M13 = perspective.M14 = 0.0f;
|
||||
perspective.M22 = 2.0f * nearPlaneDistance / height;
|
||||
perspective.M21 = perspective.M23 = perspective.M24 = 0.0f;
|
||||
perspective.M33 = farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
|
||||
perspective.M31 = perspective.M32 = 0.0f;
|
||||
perspective.M34 = -1.0f;
|
||||
perspective.M41 = perspective.M42 = perspective.M44 = 0.0f;
|
||||
perspective.M43 = (nearPlaneDistance * farPlaneDistance / (nearPlaneDistance - farPlaneDistance));
|
||||
return perspective;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreatePerspectiveOffCenter(
|
||||
float left, float right, float bottom, float top,
|
||||
float nearPlaneDistance, float farPlaneDistance) {
|
||||
if (nearPlaneDistance <= 0.0 || farPlaneDistance <= 0.0 || nearPlaneDistance >= farPlaneDistance) {
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
Matrix perspectiveOffCenter;
|
||||
perspectiveOffCenter.M11 = (2.0 * nearPlaneDistance / (right - left));
|
||||
perspectiveOffCenter.M12 = perspectiveOffCenter.M13 = perspectiveOffCenter.M14 = 0.0f;
|
||||
perspectiveOffCenter.M22 = (2.0 * nearPlaneDistance / (top - bottom));
|
||||
perspectiveOffCenter.M21 = perspectiveOffCenter.M23 = perspectiveOffCenter.M24 = 0.0f;
|
||||
perspectiveOffCenter.M31 = (left + right) / (right - left);
|
||||
perspectiveOffCenter.M32 = (top + bottom) / (top - bottom);
|
||||
perspectiveOffCenter.M33 = farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
|
||||
perspectiveOffCenter.M34 = -1.0f;
|
||||
perspectiveOffCenter.M43 = (nearPlaneDistance * farPlaneDistance / (nearPlaneDistance - farPlaneDistance));
|
||||
perspectiveOffCenter.M41 = perspectiveOffCenter.M42 = perspectiveOffCenter.M44 = 0.0f;
|
||||
return perspectiveOffCenter;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) {
|
||||
Matrix orthographic;
|
||||
orthographic.M11 = 2.0f / width;
|
||||
orthographic.M12 = orthographic.M13 = orthographic.M14 = 0.0f;
|
||||
orthographic.M22 = 2.0f / height;
|
||||
orthographic.M21 = orthographic.M23 = orthographic.M24 = 0.0f;
|
||||
orthographic.M33 = (1.0 / (zNearPlane - zFarPlane));
|
||||
orthographic.M31 = orthographic.M32 = orthographic.M34 = 0.0f;
|
||||
orthographic.M41 = orthographic.M42 = 0.0f;
|
||||
orthographic.M43 = zNearPlane / (zNearPlane - zFarPlane);
|
||||
orthographic.M44 = 1.0f;
|
||||
return orthographic;
|
||||
}
|
||||
|
||||
static constexpr Matrix CreateOrthographicOffCenter(
|
||||
float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) {
|
||||
Matrix orthographicOffCenter;
|
||||
orthographicOffCenter.M11 = (2.0F / (right - left));
|
||||
orthographicOffCenter.M12 = orthographicOffCenter.M13 = orthographicOffCenter.M14 = 0.0f;
|
||||
orthographicOffCenter.M22 = (2.0F / (top - bottom));
|
||||
orthographicOffCenter.M21 = orthographicOffCenter.M23 = orthographicOffCenter.M24 = 0.0f;
|
||||
orthographicOffCenter.M33 = (1.0F / (zNearPlane - zFarPlane));
|
||||
orthographicOffCenter.M31 = orthographicOffCenter.M32 = orthographicOffCenter.M34 = 0.0f;
|
||||
orthographicOffCenter.M41 = ((left + right) / (left - right));
|
||||
orthographicOffCenter.M42 = ((top + bottom) / (bottom - top));
|
||||
orthographicOffCenter.M43 = zNearPlane / (zNearPlane - zFarPlane);
|
||||
orthographicOffCenter.M44 = 1.0f;
|
||||
return orthographicOffCenter;
|
||||
}
|
||||
|
||||
static Matrix CreateLookAt(
|
||||
Vector3 const& cameraPosition, Vector3 const& cameraTarget, Vector3 const& cameraUpVector);
|
||||
static Matrix CreateWorld(
|
||||
Vector3 const& position, Vector3 const& forward, Vector3 const& up);
|
||||
|
||||
static Matrix CreateFromQuaternion(Quaternion const& quaternion);
|
||||
static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll);
|
||||
static Matrix CreateShadow(Vector3 lightDirection, Plane plane);
|
||||
static Matrix CreateReflection(Plane value);
|
||||
static Matrix Transform(Matrix value, Quaternion rotation);
|
||||
static Matrix Transpose(Matrix matrix);
|
||||
|
||||
constexpr float Determinant() const {
|
||||
const auto num1 = (M33 * M44 - M34 * M43);
|
||||
const auto num2 = (M32 * M44 - M34 * M42);
|
||||
const auto num3 = (M32 * M43 - M33 * M42);
|
||||
const auto num4 = (M31 * M44 - M34 * M41);
|
||||
const auto num5 = (M31 * M43 - M33 * M41);
|
||||
const auto num6 = (M31 * M42 - M32 * M41);
|
||||
return
|
||||
(M11 * (M22 * num1 - M23 * num2 + M24 * num3) - M12
|
||||
* (M21 * num1 - M23 * num4 + M24 * num5) + M13
|
||||
* (M21 * num2 - M22 * num4 + M24 * num6) - M14
|
||||
* (M21 * num3 - M22 * num5 + M23 * num6));
|
||||
}
|
||||
|
||||
static constexpr Matrix Invert(Matrix const& matrix) {
|
||||
const auto m11 = matrix.M11;
|
||||
const auto m12 = matrix.M12;
|
||||
const auto m13 = matrix.M13;
|
||||
const auto m14 = matrix.M14;
|
||||
const auto m21 = matrix.M21;
|
||||
const auto m22 = matrix.M22;
|
||||
const auto m23 = matrix.M23;
|
||||
const auto m24 = matrix.M24;
|
||||
const auto m31 = matrix.M31;
|
||||
const auto m32 = matrix.M32;
|
||||
const auto m33 = matrix.M33;
|
||||
const auto m34 = matrix.M34;
|
||||
const auto m41 = matrix.M41;
|
||||
const auto m42 = matrix.M42;
|
||||
const auto m43 = matrix.M43;
|
||||
const auto m44 = matrix.M44;
|
||||
|
||||
const auto num1 = (m33 * m44 - m34 * m43);
|
||||
const auto num2 = (m32 * m44 - m34 * m42);
|
||||
const auto num3 = (m32 * m43 - m33 * m42);
|
||||
const auto num4 = (m31 * m44 - m34 * m41);
|
||||
const auto num5 = (m31 * m43 - m33 * m41);
|
||||
const auto num6 = (m31 * m42 - m32 * m41);
|
||||
const auto num7 = (m22 * num1 - m23 * num2 + m24 * num3);
|
||||
const auto num8 = -(m21 * num1 - m23 * num4 + m24 * num5);
|
||||
const auto num9 = (m21 * num2 - m22 * num4 + m24 * num6);
|
||||
const auto num10 = -(m21 * num3 - m22 * num5 + m23 * num6);
|
||||
const auto num11 = (1.0F / (m11 * num7 + m12 * num8 + m13 * num9 + m14 * num10));
|
||||
|
||||
Matrix matrix1;
|
||||
matrix1.M11 = num7 * num11;
|
||||
matrix1.M21 = num8 * num11;
|
||||
matrix1.M31 = num9 * num11;
|
||||
matrix1.M41 = num10 * num11;
|
||||
matrix1.M12 = -(m12 * num1 - m13 * num2 + m14 * num3) * num11;
|
||||
matrix1.M22 = (m11 * num1 - m13 * num4 + m14 * num5) * num11;
|
||||
matrix1.M32 = -(m11 * num2 - m12 * num4 + m14 * num6) * num11;
|
||||
matrix1.M42 = (m11 * num3 - m12 * num5 + m13 * num6) * num11;
|
||||
|
||||
const auto num12 = (m23 * m44 - m24 * m43);
|
||||
const auto num13 = (m22 * m44 - m24 * m42);
|
||||
const auto num14 = (m22 * m43 - m23 * m42);
|
||||
const auto num15 = (m21 * m44 - m24 * m41);
|
||||
const auto num16 = (m21 * m43 - m23 * m41);
|
||||
const auto num17 = (m21 * m42 - m22 * m41);
|
||||
|
||||
matrix1.M13 = (m12 * num12 - m13 * num13 + m14 * num14) * num11;
|
||||
matrix1.M23 = -(m11 * num12 - m13 * num15 + m14 * num16) * num11;
|
||||
matrix1.M33 = (m11 * num13 - m12 * num15 + m14 * num17) * num11;
|
||||
matrix1.M43 = -(m11 * num14 - m12 * num16 + m13 * num17) * num11;
|
||||
|
||||
const auto num18 = (m23 * m34 - m24 * m33);
|
||||
const auto num19 = (m22 * m34 - m24 * m32);
|
||||
const auto num20 = (m22 * m33 - m23 * m32);
|
||||
const auto num21 = (m21 * m34 - m24 * m31);
|
||||
const auto num22 = (m21 * m33 - m23 * m31);
|
||||
const auto num23 = (m21 * m32 - m22 * m31);
|
||||
|
||||
matrix1.M14 = -(m12 * num18 - m13 * num19 + m14 * num20) * num11;
|
||||
matrix1.M24 = (m11 * num18 - m13 * num21 + m14 * num22) * num11;
|
||||
matrix1.M34 = -(m11 * num19 - m12 * num21 + m14 * num23) * num11;
|
||||
matrix1.M44 = (m11 * num20 - m12 * num22 + m13 * num23) * num11;
|
||||
|
||||
return matrix1;
|
||||
}
|
||||
|
||||
static constexpr Matrix Lerp(Matrix const& matrix1, Matrix const& matrix2, float amount) {
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
|
||||
matrix.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
|
||||
matrix.M13 = matrix1.M13 + (matrix2.M13 - matrix1.M13) * amount;
|
||||
matrix.M14 = matrix1.M14 + (matrix2.M14 - matrix1.M14) * amount;
|
||||
matrix.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
|
||||
matrix.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
|
||||
matrix.M23 = matrix1.M23 + (matrix2.M23 - matrix1.M23) * amount;
|
||||
matrix.M24 = matrix1.M24 + (matrix2.M24 - matrix1.M24) * amount;
|
||||
matrix.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
|
||||
matrix.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
|
||||
matrix.M33 = matrix1.M33 + (matrix2.M33 - matrix1.M33) * amount;
|
||||
matrix.M34 = matrix1.M34 + (matrix2.M34 - matrix1.M34) * amount;
|
||||
matrix.M41 = matrix1.M41 + (matrix2.M41 - matrix1.M41) * amount;
|
||||
matrix.M42 = matrix1.M42 + (matrix2.M42 - matrix1.M42) * amount;
|
||||
matrix.M43 = matrix1.M43 + (matrix2.M43 - matrix1.M43) * amount;
|
||||
matrix.M44 = matrix1.M44 + (matrix2.M44 - matrix1.M44) * amount;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Negate(Matrix const& matrix) {
|
||||
Matrix matrix1;
|
||||
matrix1.M11 = -matrix.M11;
|
||||
matrix1.M12 = -matrix.M12;
|
||||
matrix1.M13 = -matrix.M13;
|
||||
matrix1.M14 = -matrix.M14;
|
||||
matrix1.M21 = -matrix.M21;
|
||||
matrix1.M22 = -matrix.M22;
|
||||
matrix1.M23 = -matrix.M23;
|
||||
matrix1.M24 = -matrix.M24;
|
||||
matrix1.M31 = -matrix.M31;
|
||||
matrix1.M32 = -matrix.M32;
|
||||
matrix1.M33 = -matrix.M33;
|
||||
matrix1.M34 = -matrix.M34;
|
||||
matrix1.M41 = -matrix.M41;
|
||||
matrix1.M42 = -matrix.M42;
|
||||
matrix1.M43 = -matrix.M43;
|
||||
matrix1.M44 = -matrix.M44;
|
||||
return matrix1;
|
||||
}
|
||||
|
||||
static constexpr Matrix Add(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 + matrix2.M11;
|
||||
matrix.M12 = matrix1.M12 + matrix2.M12;
|
||||
matrix.M13 = matrix1.M13 + matrix2.M13;
|
||||
matrix.M14 = matrix1.M14 + matrix2.M14;
|
||||
matrix.M21 = matrix1.M21 + matrix2.M21;
|
||||
matrix.M22 = matrix1.M22 + matrix2.M22;
|
||||
matrix.M23 = matrix1.M23 + matrix2.M23;
|
||||
matrix.M24 = matrix1.M24 + matrix2.M24;
|
||||
matrix.M31 = matrix1.M31 + matrix2.M31;
|
||||
matrix.M32 = matrix1.M32 + matrix2.M32;
|
||||
matrix.M33 = matrix1.M33 + matrix2.M33;
|
||||
matrix.M34 = matrix1.M34 + matrix2.M34;
|
||||
matrix.M41 = matrix1.M41 + matrix2.M41;
|
||||
matrix.M42 = matrix1.M42 + matrix2.M42;
|
||||
matrix.M43 = matrix1.M43 + matrix2.M43;
|
||||
matrix.M44 = matrix1.M44 + matrix2.M44;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Subtract(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 - matrix2.M11;
|
||||
matrix.M12 = matrix1.M12 - matrix2.M12;
|
||||
matrix.M13 = matrix1.M13 - matrix2.M13;
|
||||
matrix.M14 = matrix1.M14 - matrix2.M14;
|
||||
matrix.M21 = matrix1.M21 - matrix2.M21;
|
||||
matrix.M22 = matrix1.M22 - matrix2.M22;
|
||||
matrix.M23 = matrix1.M23 - matrix2.M23;
|
||||
matrix.M24 = matrix1.M24 - matrix2.M24;
|
||||
matrix.M31 = matrix1.M31 - matrix2.M31;
|
||||
matrix.M32 = matrix1.M32 - matrix2.M32;
|
||||
matrix.M33 = matrix1.M33 - matrix2.M33;
|
||||
matrix.M34 = matrix1.M34 - matrix2.M34;
|
||||
matrix.M41 = matrix1.M41 - matrix2.M41;
|
||||
matrix.M42 = matrix1.M42 - matrix2.M42;
|
||||
matrix.M43 = matrix1.M43 - matrix2.M43;
|
||||
matrix.M44 = matrix1.M44 - matrix2.M44;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Multiply(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
Matrix matrix;
|
||||
matrix.M11 = (matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21 + matrix1.M13 * matrix2.M31 + matrix1.M14 * matrix2.M41);
|
||||
matrix.M12 = (matrix1.M11 * matrix2.M12 + matrix1.M12 * matrix2.M22 + matrix1.M13 * matrix2.M32 + matrix1.M14 * matrix2.M42);
|
||||
matrix.M13 = (matrix1.M11 * matrix2.M13 + matrix1.M12 * matrix2.M23 + matrix1.M13 * matrix2.M33 + matrix1.M14 * matrix2.M43);
|
||||
matrix.M14 = (matrix1.M11 * matrix2.M14 + matrix1.M12 * matrix2.M24 + matrix1.M13 * matrix2.M34 + matrix1.M14 * matrix2.M44);
|
||||
matrix.M21 = (matrix1.M21 * matrix2.M11 + matrix1.M22 * matrix2.M21 + matrix1.M23 * matrix2.M31 + matrix1.M24 * matrix2.M41);
|
||||
matrix.M22 = (matrix1.M21 * matrix2.M12 + matrix1.M22 * matrix2.M22 + matrix1.M23 * matrix2.M32 + matrix1.M24 * matrix2.M42);
|
||||
matrix.M23 = (matrix1.M21 * matrix2.M13 + matrix1.M22 * matrix2.M23 + matrix1.M23 * matrix2.M33 + matrix1.M24 * matrix2.M43);
|
||||
matrix.M24 = (matrix1.M21 * matrix2.M14 + matrix1.M22 * matrix2.M24 + matrix1.M23 * matrix2.M34 + matrix1.M24 * matrix2.M44);
|
||||
matrix.M31 = (matrix1.M31 * matrix2.M11 + matrix1.M32 * matrix2.M21 + matrix1.M33 * matrix2.M31 + matrix1.M34 * matrix2.M41);
|
||||
matrix.M32 = (matrix1.M31 * matrix2.M12 + matrix1.M32 * matrix2.M22 + matrix1.M33 * matrix2.M32 + matrix1.M34 * matrix2.M42);
|
||||
matrix.M33 = (matrix1.M31 * matrix2.M13 + matrix1.M32 * matrix2.M23 + matrix1.M33 * matrix2.M33 + matrix1.M34 * matrix2.M43);
|
||||
matrix.M34 = (matrix1.M31 * matrix2.M14 + matrix1.M32 * matrix2.M24 + matrix1.M33 * matrix2.M34 + matrix1.M34 * matrix2.M44);
|
||||
matrix.M41 = (matrix1.M41 * matrix2.M11 + matrix1.M42 * matrix2.M21 + matrix1.M43 * matrix2.M31 + matrix1.M44 * matrix2.M41);
|
||||
matrix.M42 = (matrix1.M41 * matrix2.M12 + matrix1.M42 * matrix2.M22 + matrix1.M43 * matrix2.M32 + matrix1.M44 * matrix2.M42);
|
||||
matrix.M43 = (matrix1.M41 * matrix2.M13 + matrix1.M42 * matrix2.M23 + matrix1.M43 * matrix2.M33 + matrix1.M44 * matrix2.M43);
|
||||
matrix.M44 = (matrix1.M41 * matrix2.M14 + matrix1.M42 * matrix2.M24 + matrix1.M43 * matrix2.M34 + matrix1.M44 * matrix2.M44);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Multiply(Matrix const& matrix1, float scaleFactor) {
|
||||
float num = scaleFactor;
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 * num;
|
||||
matrix.M12 = matrix1.M12 * num;
|
||||
matrix.M13 = matrix1.M13 * num;
|
||||
matrix.M14 = matrix1.M14 * num;
|
||||
matrix.M21 = matrix1.M21 * num;
|
||||
matrix.M22 = matrix1.M22 * num;
|
||||
matrix.M23 = matrix1.M23 * num;
|
||||
matrix.M24 = matrix1.M24 * num;
|
||||
matrix.M31 = matrix1.M31 * num;
|
||||
matrix.M32 = matrix1.M32 * num;
|
||||
matrix.M33 = matrix1.M33 * num;
|
||||
matrix.M34 = matrix1.M34 * num;
|
||||
matrix.M41 = matrix1.M41 * num;
|
||||
matrix.M42 = matrix1.M42 * num;
|
||||
matrix.M43 = matrix1.M43 * num;
|
||||
matrix.M44 = matrix1.M44 * num;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Divide(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 / matrix2.M11;
|
||||
matrix.M12 = matrix1.M12 / matrix2.M12;
|
||||
matrix.M13 = matrix1.M13 / matrix2.M13;
|
||||
matrix.M14 = matrix1.M14 / matrix2.M14;
|
||||
matrix.M21 = matrix1.M21 / matrix2.M21;
|
||||
matrix.M22 = matrix1.M22 / matrix2.M22;
|
||||
matrix.M23 = matrix1.M23 / matrix2.M23;
|
||||
matrix.M24 = matrix1.M24 / matrix2.M24;
|
||||
matrix.M31 = matrix1.M31 / matrix2.M31;
|
||||
matrix.M32 = matrix1.M32 / matrix2.M32;
|
||||
matrix.M33 = matrix1.M33 / matrix2.M33;
|
||||
matrix.M34 = matrix1.M34 / matrix2.M34;
|
||||
matrix.M41 = matrix1.M41 / matrix2.M41;
|
||||
matrix.M42 = matrix1.M42 / matrix2.M42;
|
||||
matrix.M43 = matrix1.M43 / matrix2.M43;
|
||||
matrix.M44 = matrix1.M44 / matrix2.M44;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static constexpr Matrix Divide(Matrix const& matrix1, float divider) {
|
||||
float num = 1.0f / divider;
|
||||
Matrix matrix;
|
||||
matrix.M11 = matrix1.M11 * num;
|
||||
matrix.M12 = matrix1.M12 * num;
|
||||
matrix.M13 = matrix1.M13 * num;
|
||||
matrix.M14 = matrix1.M14 * num;
|
||||
matrix.M21 = matrix1.M21 * num;
|
||||
matrix.M22 = matrix1.M22 * num;
|
||||
matrix.M23 = matrix1.M23 * num;
|
||||
matrix.M24 = matrix1.M24 * num;
|
||||
matrix.M31 = matrix1.M31 * num;
|
||||
matrix.M32 = matrix1.M32 * num;
|
||||
matrix.M33 = matrix1.M33 * num;
|
||||
matrix.M34 = matrix1.M34 * num;
|
||||
matrix.M41 = matrix1.M41 * num;
|
||||
matrix.M42 = matrix1.M42 * num;
|
||||
matrix.M43 = matrix1.M43 * num;
|
||||
matrix.M44 = matrix1.M44 * num;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
constexpr Matrix operator-() const {
|
||||
return Matrix::Negate(*this);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator+(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
return Matrix::Add(matrix1, matrix2);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator-(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
return Matrix::Subtract(matrix1, matrix2);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator*(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
return Matrix::Multiply(matrix1, matrix2);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator*(Matrix const& matrix, float factor) {
|
||||
return Matrix::Multiply(matrix, factor);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator*(float factor, Matrix const& matrix) {
|
||||
return Matrix::Multiply(matrix, factor);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator/(Matrix const& matrix1, Matrix const& matrix2) {
|
||||
return Matrix::Divide(matrix1, matrix2);
|
||||
}
|
||||
|
||||
friend constexpr Matrix operator/(Matrix const& matrix, float divider) {
|
||||
return Matrix::Divide(matrix, divider);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,25 @@ namespace xna {
|
||||
constexpr bool operator==(const Vector3& other) const {
|
||||
return X == other.X && Y == other.Y && Z == other.Z;
|
||||
}
|
||||
|
||||
static Vector3 Cross(Vector3 const& vector1, Vector3 const& vector2) { return {}; }
|
||||
static float Dot(Vector3 const& vector1, Vector3 const& vector2) { return 0; }
|
||||
static Vector3 Forward() { return {}; }
|
||||
static Vector3 Right() { return {}; }
|
||||
float LengthSquared() const { return 0; };
|
||||
static Vector3 Normalize(Vector3 const& value) { return {}; }
|
||||
static Vector3 Multiply(Vector3 value1, Vector3 value2) { return {}; }
|
||||
static Vector3 Subtract(Vector3 value1, Vector3 value2) { return {}; }
|
||||
static Vector3 Multiply(Vector3 value1, float value) { return {}; }
|
||||
void Normalize(){}
|
||||
|
||||
constexpr Vector3 operator-() const {
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
friend constexpr Vector3 operator-(Vector3 const& value1, Vector3 const& value2) {
|
||||
return Vector3();
|
||||
}
|
||||
};
|
||||
|
||||
struct Vector4 {
|
||||
|
@ -44,11 +44,17 @@ namespace xna {
|
||||
struct Rectangle;
|
||||
using PRectangle = std::shared_ptr<Rectangle>;
|
||||
struct Vector2;
|
||||
using Vec2 = Vector2;
|
||||
using PVector2 = std::shared_ptr<Vector2>;
|
||||
using PVec2 = std::shared_ptr<Vector2>;
|
||||
struct Vector3;
|
||||
using Vec3 = Vector3;
|
||||
using PVector3 = std::shared_ptr<Vector3>;
|
||||
using PVec3 = std::shared_ptr<Vector3>;
|
||||
struct Vector4;
|
||||
using Vec4 = Vector4;
|
||||
using PVector4 = std::shared_ptr<Vector4>;
|
||||
using PVec4 = std::shared_ptr<Vector4>;
|
||||
|
||||
//Game
|
||||
class DrawableGameComponent;
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "dxgi.h"
|
||||
#include "d3d11.h"
|
||||
#include <d3dcompiler.h>
|
||||
#include <DirectXMath.h>
|
||||
#include <d3dcompiler.h>
|
@ -33,7 +33,7 @@ namespace xna {
|
||||
public:
|
||||
D3D11_BUFFER_DESC _description;
|
||||
ID3D11Buffer* _buffer = nullptr;
|
||||
D3D11_SUBRESOURCE_DATA _initialData{}
|
||||
D3D11_SUBRESOURCE_DATA _initialData{};
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user