1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementa numerics

This commit is contained in:
Danilo 2024-05-18 16:22:00 -03:00
parent 11769aa7de
commit 5d6c2c78b7
20 changed files with 149 additions and 171 deletions

View File

@ -31,7 +31,7 @@ add_executable (xna WIN32
"platform/keyboard-dx.cpp"
"platform/mouse-dx.cpp"
"platform/gamepad-dx.cpp"
"common/vectors.cpp"
"platform/soundeffect-dx.cpp"
"platform/displaymode-dx.cpp"
"platform/presentparameters-dx.cpp"
@ -51,7 +51,7 @@ add_executable (xna WIN32
"common/quaternion.cpp"
"common/collision.cpp"
"common/gjk.cpp"
)
"common/numerics.cpp")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET xna PROPERTY CXX_STANDARD 20)

View File

@ -1,4 +1,4 @@
#include "common/vectors.hpp"
#include "common/numerics.hpp"
#include "common/matrix.hpp"
#include "common/quaternion.hpp"
@ -27,14 +27,14 @@ namespace xna {
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) {
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|| sourceArrayLength < sourceIndex + length || destinationArrayLength < destinationIndex + length)
return false;
for (size_t i = 0; i < length; ++i) {
const auto& source = sourceArray[sourceIndex + i];
const auto& source = sourceArray[sourceIndex + i];
destinationArray[destinationIndex + i].X = (source.X * matrix.M11 + source.Y * matrix.M21) + matrix.M41;
destinationArray[destinationIndex + i].Y = (source.X * matrix.M12 + source.Y * matrix.M22) + matrix.M42;
destinationArray[destinationIndex + i].Y = (source.X * matrix.M12 + source.Y * matrix.M22) + matrix.M42;
}
return true;
@ -68,7 +68,7 @@ namespace xna {
return TransformNormal(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size());
}
bool Vector2::TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) {
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|| sourceArrayLength < sourceIndex + length || destinationArrayLength < destinationIndex + length)
@ -78,7 +78,7 @@ namespace xna {
{
const auto& source = sourceArray[sourceIndex + i];
destinationArray[destinationIndex].X = (source.X * matrix.M11 + source.Y * matrix.M21);
destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22);
destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22);
}
return true;
@ -144,12 +144,12 @@ namespace xna {
const auto b = rxy - rwz;
const auto c = rxy + rwz;
const auto d = 1.0f - rxx - rzz;
for (size_t i = 0; i < length; ++i) {
const auto& source = sourceArray[sourceIndex = i];
destinationArray[destinationIndex].X = source.X * a + source.Y* b;
destinationArray[destinationIndex].Y = source.X * c +source.Y * d;
destinationArray[destinationIndex].X = source.X * a + source.Y * b;
destinationArray[destinationIndex].Y = source.X * c + source.Y * d;
++sourceIndex;
++destinationIndex;
}
@ -163,7 +163,7 @@ namespace xna {
destinationArray.resize(sourceArray.size());
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length);
}
}
bool Vector3::Transform(Vector3 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength)
{
@ -428,7 +428,7 @@ namespace xna {
const auto num19 = num9 - num5;
const auto num20 = num11 + num4;
const auto num21 = 1.0f - num7 - num10;
for (size_t index = 0; index < sourceLength; ++index)
{
const auto& source = sourceArray[index];
@ -494,4 +494,4 @@ namespace xna {
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length);
}
}
}

View File

@ -2,7 +2,7 @@
#define XNA_COMMON_SHAPES_HPP
#include "default.hpp"
#include "vectors.hpp"
#include "numerics.hpp"
#include "matrix.hpp"
#include "quaternion.hpp"
#include "gjk.hpp"

View File

@ -115,7 +115,7 @@ namespace xna {
std::vector<CurveKey> Keys;
private:
friend class Curve;
friend struct Curve;
float TimeRange{ 0.0F };
float InvTimeRange{ 0.0F };

View File

@ -2,7 +2,7 @@
#define XNA_COMMON_GDK_HPP
#include "default.hpp"
#include "vectors.hpp"
#include "numerics.hpp"
#include "math.hpp"
namespace xna {

View File

@ -3,7 +3,7 @@
#include "../default.hpp"
#include "math.hpp"
#include "vectors.hpp"
#include "numerics.hpp"
namespace xna {
struct Matrix {

View File

@ -5,6 +5,126 @@
#include "../default.hpp"
namespace xna {
struct Point {
Int X{ 0 };
Int Y{ 0 };
constexpr Point() = default;
constexpr Point(const Int& X, const Int& Y)
: X(X), Y(Y) {}
constexpr bool operator==(const Point& other) const {
return X == other.X && Y == other.Y;
}
};
struct Rectangle {
Int X{ 0 };
Int Y{ 0 };
Int Width{ 0 };
Int Height{ 0 };
constexpr Rectangle() = default;
constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height) :
X(X), Y(Y), Width(Width), Height(Height) {}
constexpr bool operator==(const Rectangle& other) const {
return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y;
}
constexpr Int Left() const { return X; }
constexpr Int Right() const { return X + Width; }
constexpr Int Top() const { return Y; }
constexpr Int Bottom() const { return Y + Height; }
constexpr Point Location() const { return { X, Y }; }
constexpr void Location(Point const& p) {
X = p.X;
Y = p.Y;
}
constexpr Point Center() const { return { X + Width / 2, Y + Height / 2 }; }
constexpr static Rectangle Empty() { return {}; }
constexpr bool IsEmpty() const { return Width == 0 && Height == 0 && X == 0 && Y == 0; }
constexpr void Offset(Point const& amount) {
X += amount.X;
Y += amount.Y;
}
constexpr void Offset(Int x, Int y) {
X += x;
Y += y;
}
constexpr void Inflate(Int horizontalAmount, Int verticalAmount) {
X -= horizontalAmount;
Y -= verticalAmount;
Width += horizontalAmount * 2;
Height += verticalAmount * 2;
}
constexpr bool Contains(Int x, Int y) const {
return X <= x && x < X + Width && Y <= y && y < Y + Height;
}
constexpr bool Contains(Point const& value) const {
return X <= value.X && value.X < X + Width && Y <= value.Y && value.Y < Y + Height;
}
constexpr bool Contains(Rectangle const& value) const {
return X <= value.X && value.X + value.Width <= X + Width && Y <= value.Y && value.Y + value.Height <= Y + Height;
}
constexpr bool Intersects(Rectangle const& value) const {
return value.X < X + Width && X < value.X + value.Width && value.Y < Y + Height && Y < value.Y + value.Height;
}
constexpr static Rectangle Intersect(Rectangle const& value1, Rectangle const& value2) {
const auto left1 = value1.Left();
const auto left2 = value2.Left();
const auto bottom1 = value1.Bottom();
const auto bottom2 = value2.Bottom();
const auto maxX = value1.X > value2.X ? value1.X : value2.X;
const auto maxY = value1.Y > value2.Y ? value1.Y : value2.Y;
const auto maxl = left1 < left2 ? left1 : left2;
const auto maxb = bottom1 < bottom2 ? bottom1 : bottom2;
Rectangle rectangle{};
if (maxl > maxX && maxb > maxY) {
rectangle.X = maxX;
rectangle.Y = maxY;
rectangle.Width = maxl - maxX;
rectangle.Height = maxb - maxY;
}
return rectangle;
}
constexpr static Rectangle Union(Rectangle const& value1, Rectangle const& value2) {
const auto left1 = value1.Left();
const auto left2 = value2.Left();
const auto bottom1 = value1.Bottom();
const auto bottom2 = value2.Bottom();
const auto minX = value1.X < value2.X ? value1.X : value2.X;
const auto miny = value1.Y < value2.Y ? value1.Y : value2.Y;
const auto maxl = left1 > left2 ? left1 : left2;
const auto maxb = bottom1 > bottom2 ? bottom1 : bottom2;
Rectangle rectangle;
rectangle.X = minX;
rectangle.Y = miny;
rectangle.Width = maxl - minX;
rectangle.Height = maxb - miny;
return rectangle;
}
};
struct Vector2 {
float X{ 0 };
float Y{ 0 };

View File

@ -2,7 +2,7 @@
#define CXNA_COMMON_PACKEDVECTOR_HPP
#include "../default.hpp"
#include "vectors.hpp"
#include "numerics.hpp"
#include <cmath>
namespace xna {

View File

@ -1,10 +0,0 @@
#ifndef XNA_COMMON_POINT_HPP
#define XNA_COMMON_POINT_HPP
#include "../types.hpp"
namespace xna {
}
#endif

View File

@ -1,7 +1,7 @@
#ifndef XNA_COMMON_QUATERNION_HPP
#define XNA_COMMON_QUATERNION_HPP
#include "vectors.hpp"
#include "numerics.hpp"
namespace xna {
struct Quaternion {

View File

@ -1,128 +0,0 @@
#ifndef XNA_COMMON_RECTANGLE_HPP
#define XNA_COMMON_RECTANGLE_HPP
#include "../types.hpp"
namespace xna {
struct Point {
Int X{ 0 };
Int Y{ 0 };
constexpr Point() = default;
constexpr Point(const Int& X, const Int& Y)
: X(X), Y(Y) {}
constexpr bool operator==(const Point& other) const {
return X == other.X && Y == other.Y;
}
};
struct Rectangle {
Int X{ 0 };
Int Y{ 0 };
Int Width{ 0 };
Int Height{ 0 };
constexpr Rectangle() = default;
constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height):
X(X), Y(Y), Width(Width), Height(Height) {}
constexpr bool operator==(const Rectangle& other) const {
return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y;
}
constexpr Int Left() const { return X; }
constexpr Int Right() const { return X + Width; }
constexpr Int Top() const { return Y; }
constexpr Int Bottom() const { return Y + Height; }
constexpr Point Location() const { return { X, Y }; }
constexpr void Location(Point const& p) {
X = p.X;
Y = p.Y;
}
constexpr Point Center() const { return { X + Width / 2, Y + Height / 2 }; }
constexpr static Rectangle Empty() { return {}; }
constexpr bool IsEmpty() const { return Width == 0 && Height == 0 && X == 0 && Y == 0; }
constexpr void Offset(Point const& amount) {
X += amount.X;
Y += amount.Y;
}
constexpr void Offset(Int x, Int y) {
X += x;
Y += y;
}
constexpr void Inflate(Int horizontalAmount, Int verticalAmount) {
X -= horizontalAmount;
Y -= verticalAmount;
Width += horizontalAmount * 2;
Height += verticalAmount * 2;
}
constexpr bool Contains(Int x, Int y) const {
return X <= x && x < X + Width && Y <= y && y < Y + Height;
}
constexpr bool Contains(Point const& value) const {
return X <= value.X && value.X < X + Width && Y <= value.Y && value.Y < Y + Height;
}
constexpr bool Contains(Rectangle const& value) const {
return X <= value.X && value.X + value.Width <= X + Width && Y <= value.Y && value.Y + value.Height <= Y + Height;
}
constexpr bool Intersects(Rectangle const& value) const {
return value.X < X + Width && X < value.X + value.Width && value.Y < Y + Height && Y < value.Y + value.Height;
}
constexpr static Rectangle Intersect(Rectangle const& value1, Rectangle const& value2) {
const auto left1 = value1.Left();
const auto left2 = value2.Left();
const auto bottom1 = value1.Bottom();
const auto bottom2 = value2.Bottom();
const auto maxX = value1.X > value2.X ? value1.X : value2.X;
const auto maxY = value1.Y > value2.Y ? value1.Y : value2.Y;
const auto maxl = left1 < left2 ? left1 : left2;
const auto maxb = bottom1 < bottom2 ? bottom1 : bottom2;
Rectangle rectangle{};
if (maxl > maxX && maxb > maxY) {
rectangle.X = maxX;
rectangle.Y = maxY;
rectangle.Width = maxl - maxX;
rectangle.Height = maxb - maxY;
}
return rectangle;
}
constexpr static Rectangle Union(Rectangle const& value1, Rectangle const& value2) {
const auto left1 = value1.Left();
const auto left2 = value2.Left();
const auto bottom1 = value1.Bottom();
const auto bottom2 = value2.Bottom();
const auto minX = value1.X < value2.X ? value1.X : value2.X;
const auto miny = value1.Y < value2.Y ? value1.Y : value2.Y;
const auto maxl = left1 > left2 ? left1 : left2;
const auto maxb = bottom1 > bottom2 ? bottom1 : bottom2;
Rectangle rectangle;
rectangle.X = minX;
rectangle.Y = miny;
rectangle.Width = maxl - minX;
rectangle.Height = maxb - miny;
return rectangle;
}
};
}
#endif

View File

@ -5,8 +5,7 @@
#include "../default.hpp"
#include "../common/color.hpp"
#include "../common/matrix.hpp"
#include "../common/point.hpp"
#include "../common/rectangle.hpp"
#include "../common/numerics.hpp"
#include "../csharp/timespan.hpp"
namespace xna {

View File

@ -4,7 +4,7 @@
#include "../common/color.hpp"
#include "../common/matrix.hpp"
#include "../common/quaternion.hpp"
#include "../common/vectors.hpp"
#include "../common/numerics.hpp"
#include "../csharp/binary.hpp"
#include "../csharp/type.hpp"
#include "../default.hpp"

View File

@ -2,7 +2,7 @@
#define XNA_GAME_WINDOW_HPP
#include "../enums.hpp"
#include "../common/rectangle.hpp"
#include "../common/numerics.hpp"
namespace xna {
class IGameWindow {

View File

@ -1,7 +1,7 @@
#ifndef XNA_GRAPHICS_VERTEXPOSITION_HPP
#define XNA_GRAPHICS_VERTEXPOSITION_HPP
#include "../common/vectors.hpp"
#include "../common/numerics.hpp"
#include "../common/color.hpp"
#include "../default.hpp"

View File

@ -2,7 +2,7 @@
#define XNA_INPUT_GAMEPAD_HPP
#include "../default.hpp"
#include "../common/vectors.hpp"
#include "../common/numerics.hpp"
namespace xna {
struct IGamePadTriggers {

View File

@ -2,8 +2,7 @@
#define XNA_PLATFORM_SPRITEBATCH_DX_HPP
#include "../common/color.hpp"
#include "../common/rectangle.hpp"
#include "../common/vectors.hpp"
#include "../common/numerics.hpp"
#include "../graphics/spritebatch.hpp"
#include "../graphics/viewport.hpp"
#include "SpriteBatch.h"

View File

@ -2,7 +2,7 @@
#define XNA_PLATFORM_SPRITEFONT_DX_HPP
#include "../graphics/spritefont.hpp"
#include "../common/vectors.hpp"
#include "../common/numerics.hpp"
#include "SpriteFont.h"
#include "device-dx.hpp"

View File

@ -1,7 +1,7 @@
#ifndef XNA_PLATFORM_TEXTURE_DX_HPP
#define XNA_PLATFORM_TEXTURE_DX_HPP
#include "../common/rectangle.hpp"
#include "../common/numerics.hpp"
#include "../graphics/gresource.hpp"
#include "../graphics/texture.hpp"
#include "dxheaders.hpp"

View File

@ -10,11 +10,9 @@
#include "common/math.hpp"
#include "common/matrix.hpp"
#include "common/packedvalue.hpp"
#include "common/point.hpp"
#include "common/quaternion.hpp"
#include "common/rectangle.hpp"
#include "common/numerics.hpp"
#include "common/collision.hpp"
#include "common/vectors.hpp"
#include "content/defaultreaders.hpp"
#include "content/manager.hpp"
#include "content/reader.hpp"