mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa Vetores
This commit is contained in:
parent
c6797f4d93
commit
6b37ede720
@ -623,6 +623,47 @@ namespace xna {
|
|||||||
vector3.Z = num3;
|
vector3.Z = num3;
|
||||||
return vector3;
|
return vector3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 Vector4::Transform(Vector2 const& position, Matrix const& matrix)
|
||||||
|
{
|
||||||
|
const auto num1 = (position.X * matrix.M11 + position.Y * matrix.M21) + matrix.M41;
|
||||||
|
const auto num2 = (position.X * matrix.M12 + position.Y * matrix.M22) + matrix.M42;
|
||||||
|
const auto num3 = (position.X * matrix.M13 + position.Y * matrix.M23) + matrix.M43;
|
||||||
|
const auto num4 = (position.X * matrix.M14 + position.Y * matrix.M24) + matrix.M44;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num1;
|
||||||
|
vector4.Y = num2;
|
||||||
|
vector4.Z = num3;
|
||||||
|
vector4.W = num4;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 Vector4::Transform(Vector3 const& position, Matrix const& matrix)
|
||||||
|
{
|
||||||
|
const auto num1 = (position.X * matrix.M11 + position.Y * matrix.M21 + position.Z * matrix.M31) + matrix.M41;
|
||||||
|
const auto num2 = (position.X * matrix.M12 + position.Y * matrix.M22 + position.Z * matrix.M32) + matrix.M42;
|
||||||
|
const auto num3 = (position.X * matrix.M13 + position.Y * matrix.M23 + position.Z * matrix.M33) + matrix.M43;
|
||||||
|
const auto num4 = (position.X * matrix.M14 + position.Y * matrix.M24 + position.Z * matrix.M34) + matrix.M44;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num1;
|
||||||
|
vector4.Y = num2;
|
||||||
|
vector4.Z = num3;
|
||||||
|
vector4.W = num4;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 Vector4::Transform(Vector4 const& vector, Matrix const& matrix) {
|
||||||
|
const auto num1 = (vector.X * matrix.M11 + vector.Y * matrix.M21 + vector.Z * matrix.M31 + vector.W * matrix.M41);
|
||||||
|
const auto num2 = (vector.X * matrix.M12 + vector.Y * matrix.M22 + vector.Z * matrix.M32 + vector.W * matrix.M42);
|
||||||
|
const auto num3 = (vector.X * matrix.M13 + vector.Y * matrix.M23 + vector.Z * matrix.M33 + vector.W * matrix.M43);
|
||||||
|
const auto num4 = (vector.X * matrix.M14 + vector.Y * matrix.M24 + vector.Z * matrix.M34 + vector.W * matrix.M44);
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num1;
|
||||||
|
vector4.Y = num2;
|
||||||
|
vector4.Z = num3;
|
||||||
|
vector4.W = num4;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -57,6 +57,55 @@ namespace xna {
|
|||||||
vector3.Z = num15;
|
vector3.Z = num15;
|
||||||
return vector3;
|
return vector3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 Vector4::Transform(Vector2 const& value, Quaternion const& rotation)
|
||||||
|
{
|
||||||
|
const auto num1 = rotation.X + rotation.X;
|
||||||
|
const auto num2 = rotation.Y + rotation.Y;
|
||||||
|
const auto num3 = rotation.Z + rotation.Z;
|
||||||
|
const auto num4 = rotation.W * num1;
|
||||||
|
const auto num5 = rotation.W * num2;
|
||||||
|
const auto num6 = rotation.W * num3;
|
||||||
|
const auto num7 = rotation.X * num1;
|
||||||
|
const auto num8 = rotation.X * num2;
|
||||||
|
const auto num9 = rotation.X * num3;
|
||||||
|
const auto num10 = rotation.Y * num2;
|
||||||
|
const auto num11 = rotation.Y * num3;
|
||||||
|
const auto num12 = rotation.Z * num3;
|
||||||
|
const auto num13 = (value.X * (1.0F - num10 - num12) + value.Y * (num8 - num6));
|
||||||
|
const auto num14 = (value.X * (num8 + num6) + value.Y * (1.0F - num7 - num12));
|
||||||
|
const auto num15 = (value.X * (num9 - num5) + value.Y * (num11 + num4));
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num13;
|
||||||
|
vector4.Y = num14;
|
||||||
|
vector4.Z = num15;
|
||||||
|
vector4.W = 1.0f;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 Vector4::Transform(Vector3 const& value, Quaternion const& rotation) {
|
||||||
|
const auto num1 = rotation.X + rotation.X;
|
||||||
|
const auto num2 = rotation.Y + rotation.Y;
|
||||||
|
const auto num3 = rotation.Z + rotation.Z;
|
||||||
|
const auto num4 = rotation.W * num1;
|
||||||
|
const auto num5 = rotation.W * num2;
|
||||||
|
const auto num6 = rotation.W * num3;
|
||||||
|
const auto num7 = rotation.X * num1;
|
||||||
|
const auto num8 = rotation.X * num2;
|
||||||
|
const auto num9 = rotation.X * num3;
|
||||||
|
const auto num10 = rotation.Y * num2;
|
||||||
|
const auto num11 = rotation.Y * num3;
|
||||||
|
const auto num12 = rotation.Z * num3;
|
||||||
|
const auto num13 = (value.X * (1.0F - num10 - num12) + value.Y * (num8 - num6) + value.Z * (num9 + num5));
|
||||||
|
const auto num14 = (value.X * (num8 + num6) + value.Y * (1.0F - num7 - num12) + value.Z * (num11 - num4));
|
||||||
|
const auto num15 = (value.X * (num9 - num5) + value.Y * (num11 + num4) + value.Z * (1.0F - num7 - num10));
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num13;
|
||||||
|
vector4.Y = num14;
|
||||||
|
vector4.Z = num15;
|
||||||
|
vector4.W = 1.0f;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -2,18 +2,113 @@
|
|||||||
#define XNA_COMMON_RECTANGLE_HPP
|
#define XNA_COMMON_RECTANGLE_HPP
|
||||||
|
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
|
#include "point.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
Int Height{ 0 };
|
|
||||||
Int Width{ 0 };
|
|
||||||
Int X{ 0 };
|
Int X{ 0 };
|
||||||
Int Y{ 0 };
|
Int Y{ 0 };
|
||||||
|
Int Width{ 0 };
|
||||||
|
Int Height{ 0 };
|
||||||
|
|
||||||
constexpr Rectangle() = default;
|
constexpr Rectangle() = default;
|
||||||
|
|
||||||
constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height):
|
constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height):
|
||||||
X(X), Y(Y), Width(Width), Height(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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,14 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector2::Transform(std::vector<Vector2> sourceArray, Matrix const& matrix, std::vector<Vector2>& destinationArray)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
|
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) {
|
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) {
|
||||||
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|
||||||
@ -32,6 +40,14 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector2::Transform(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, matrix, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
bool Vector2::TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength) {
|
bool Vector2::TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength) {
|
||||||
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength)
|
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength)
|
||||||
return false;
|
return false;
|
||||||
@ -44,6 +60,14 @@ namespace xna {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector2::TransformNormal(std::vector<Vector2> const& sourceArray, Matrix const& matrix, std::vector<Vector2>& destinationArray)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
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) {
|
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
|
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|
||||||
@ -60,6 +84,14 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector2::TransformNormal(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return TransformNormal(sourceArray.data(), sourceArray.size(), sourceIndex, matrix, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength) {
|
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength) {
|
||||||
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength)
|
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength)
|
||||||
return false;
|
return false;
|
||||||
@ -86,6 +118,14 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector2::Transform(std::vector<Vector2> const& sourceArray, Quaternion const& rotation, std::vector<Vector2>& destinationArray)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), rotation, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation,
|
bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation,
|
||||||
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) {
|
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) {
|
||||||
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|
if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength
|
||||||
@ -117,30 +157,20 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::Normalize() {
|
bool Vector2::Transform(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
const auto num = 1.0f / std::sqrt(X * X + Y * Y + Z * Z);
|
|
||||||
X *= num;
|
|
||||||
Y *= num;
|
|
||||||
Z *= num;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 Vector3::Normalize(Vector3 const& value) {
|
|
||||||
const auto num = 1.0f / std::sqrt(value.X * value.X + value.Y * value.Y + value.Z * value.Z);
|
|
||||||
|
|
||||||
Vector3 vector3;
|
|
||||||
vector3.X = value.X * num;
|
|
||||||
vector3.Y = value.Y * num;
|
|
||||||
vector3.Z = value.Z * num;
|
|
||||||
|
|
||||||
return vector3;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool xna::Vector3::Transform(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray)
|
|
||||||
{
|
{
|
||||||
if (destinationArray.size() < sourceArray.size())
|
if (destinationArray.empty())
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || destinationLength < sourceArrayLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t index = 0; index < sourceArray.size(); ++index)
|
for (size_t index = 0; index < sourceArrayLength; ++index)
|
||||||
{
|
{
|
||||||
const auto& source = sourceArray[index];
|
const auto& source = sourceArray[index];
|
||||||
destinationArray[index].X = (source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31) + matrix.M41;
|
destinationArray[index].X = (source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31) + matrix.M41;
|
||||||
@ -151,9 +181,17 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::Transform(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
bool Vector3::Transform(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray)
|
||||||
{
|
{
|
||||||
if (sourceArray.size() < sourceIndex + length || destinationArray.size() < destinationIndex + length)
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::Transform(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceArrayLength < sourceIndex + length || destinationLength < destinationIndex + length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t index = 0; index < length; ++index)
|
for (size_t index = 0; index < length; ++index)
|
||||||
@ -161,18 +199,26 @@ namespace xna {
|
|||||||
const auto& source = sourceArray[sourceIndex + index];
|
const auto& source = sourceArray[sourceIndex + index];
|
||||||
destinationArray[destinationIndex + index].X = (source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31) + matrix.M41;
|
destinationArray[destinationIndex + index].X = (source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31) + matrix.M41;
|
||||||
destinationArray[destinationIndex + index].Y = (source.X * matrix.M12 + source.Y * matrix.M22 + source.Z * matrix.M32) + matrix.M42;
|
destinationArray[destinationIndex + index].Y = (source.X * matrix.M12 + source.Y * matrix.M22 + source.Z * matrix.M32) + matrix.M42;
|
||||||
destinationArray[destinationIndex + index].Z = (source.X * matrix.M13 + source.Y * matrix.M23 + source.Z * matrix.M33) + matrix.M43;
|
destinationArray[destinationIndex + index].Z = (source.X * matrix.M13 + source.Y * matrix.M23 + source.Z * matrix.M33) + matrix.M43;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray)
|
bool Vector3::Transform(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
{
|
{
|
||||||
if (destinationArray.size() < sourceArray.size())
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, matrix, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector3* destinationArray, size_t destionationArrayLength)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceArrayLength < destionationArrayLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t index = 0; index < sourceArray.size(); ++index)
|
for (size_t index = 0; index < sourceArrayLength; ++index)
|
||||||
{
|
{
|
||||||
const auto& source = sourceArray[index];
|
const auto& source = sourceArray[index];
|
||||||
destinationArray[index].X = source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31;
|
destinationArray[index].X = source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31;
|
||||||
@ -183,9 +229,17 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray)
|
||||||
{
|
{
|
||||||
if (sourceArray.size() < sourceIndex + length || destinationArray.size() < destinationIndex + length)
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return TransformNormal(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceArrayLength < sourceIndex + length || destinationLength < destinationIndex + length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t index = 0; index < length; ++index) {
|
for (size_t index = 0; index < length; ++index) {
|
||||||
@ -198,9 +252,17 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, Quaternion const& rotation, std::vector<Vector3>& destinationArray)
|
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
{
|
{
|
||||||
if (destinationArray.size() < sourceArray.size())
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return TransformNormal(sourceArray.data(), sourceArray.size(), sourceIndex, matrix, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector3* destinationArray, size_t destinationLength)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || destinationLength < sourceArrayLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto num1 = rotation.X + rotation.X;
|
const auto num1 = rotation.X + rotation.X;
|
||||||
@ -225,7 +287,7 @@ namespace xna {
|
|||||||
const auto num20 = num11 + num4;
|
const auto num20 = num11 + num4;
|
||||||
const auto num21 = 1.0f - num7 - num10;
|
const auto num21 = 1.0f - num7 - num10;
|
||||||
|
|
||||||
for (size_t index = 0; index < sourceArray.size(); ++index)
|
for (size_t index = 0; index < sourceArrayLength; ++index)
|
||||||
{
|
{
|
||||||
const auto& source = sourceArray[index];
|
const auto& source = sourceArray[index];
|
||||||
destinationArray[index].X = source.X * num13 + source.Y * num14 + source.Z * num15;
|
destinationArray[index].X = source.X * num13 + source.Y * num14 + source.Z * num15;
|
||||||
@ -236,11 +298,19 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, Quaternion const& rotation, std::vector<Vector3>& destinationArray)
|
||||||
{
|
{
|
||||||
if (sourceArray.size() < sourceIndex + length || destinationArray.size() < destinationIndex + length)
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return TransformNormal(sourceArray.data(), sourceArray.size(), rotation, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceArrayLength < sourceIndex + length || destinationLength < destinationIndex + length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto num1 = rotation.X + rotation.X;
|
const auto num1 = rotation.X + rotation.X;
|
||||||
const auto num2 = rotation.Y + rotation.Y;
|
const auto num2 = rotation.Y + rotation.Y;
|
||||||
const auto num3 = rotation.Z + rotation.Z;
|
const auto num3 = rotation.Z + rotation.Z;
|
||||||
@ -273,4 +343,155 @@ namespace xna {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Vector3::TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return TransformNormal(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(Vector4 const* sourceArray, size_t sourceLength, Matrix const& matrix, Vector4* destinationArray, size_t destinationLength)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || destinationLength < sourceLength)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (size_t index = 0; index < sourceLength; ++index)
|
||||||
|
{
|
||||||
|
const auto& source = sourceArray[index];
|
||||||
|
destinationArray[index].X = source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31 + source.W * matrix.M41;
|
||||||
|
destinationArray[index].Y = source.X * matrix.M12 + source.Y * matrix.M22 + source.Z * matrix.M32 + source.W * matrix.M42;
|
||||||
|
destinationArray[index].Z = source.X * matrix.M13 + source.Y * matrix.M23 + source.Z * matrix.M33 + source.W * matrix.M43;
|
||||||
|
destinationArray[index].W = source.X * matrix.M14 + source.Y * matrix.M24 + source.Z * matrix.M34 + source.W * matrix.M44;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(std::vector<Vector4> const& sourceArray, size_t sourceLength, Matrix const& matrix, std::vector<Vector4>& destinationArray)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(Vector4 const* sourceArray, size_t sourceLength, size_t sourceIndex, Matrix const& matrix, Vector4* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceLength < sourceIndex + length || destinationLength < destinationIndex + length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
const auto& source = sourceArray[sourceIndex + i];
|
||||||
|
destinationArray[destinationIndex].X = source.X * matrix.M11 + source.Y * matrix.M21 + source.Z * matrix.M31 + source.W * matrix.M41;
|
||||||
|
destinationArray[destinationIndex].Y = source.X * matrix.M12 + source.Y * matrix.M22 + source.Z * matrix.M32 + source.W * matrix.M42;
|
||||||
|
destinationArray[destinationIndex].Z = source.X * matrix.M13 + source.Y * matrix.M23 + source.Z * matrix.M33 + source.W * matrix.M43;
|
||||||
|
destinationArray[destinationIndex].W = source.X * matrix.M14 + source.Y * matrix.M24 + source.Z * matrix.M34 + source.W * matrix.M44;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(std::vector<Vector4> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector4>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, matrix, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(Vector4 const* sourceArray, size_t sourceLength, Quaternion const& rotation, Vector4* destinationArray, size_t destinationLength)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || destinationLength < sourceLength)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto num1 = rotation.X + rotation.X;
|
||||||
|
const auto num2 = rotation.Y + rotation.Y;
|
||||||
|
const auto num3 = rotation.Z + rotation.Z;
|
||||||
|
const auto num4 = rotation.W * num1;
|
||||||
|
const auto num5 = rotation.W * num2;
|
||||||
|
const auto num6 = rotation.W * num3;
|
||||||
|
const auto num7 = rotation.X * num1;
|
||||||
|
const auto num8 = rotation.X * num2;
|
||||||
|
const auto num9 = rotation.X * num3;
|
||||||
|
const auto num10 = rotation.Y * num2;
|
||||||
|
const auto num11 = rotation.Y * num3;
|
||||||
|
const auto num12 = rotation.Z * num3;
|
||||||
|
const auto num13 = 1.0f - num10 - num12;
|
||||||
|
const auto num14 = num8 - num6;
|
||||||
|
const auto num15 = num9 + num5;
|
||||||
|
const auto num16 = num8 + num6;
|
||||||
|
const auto num17 = 1.0f - num7 - num12;
|
||||||
|
const auto num18 = num11 - num4;
|
||||||
|
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];
|
||||||
|
destinationArray[index].X = source.Z * num13 + source.Y * num14 + source.Z * num15;
|
||||||
|
destinationArray[index].Y = source.Z * num16 + source.Y * num17 + source.Z * num18;
|
||||||
|
destinationArray[index].Z = source.Z * num19 + source.Y * num20 + source.Z * num21;
|
||||||
|
destinationArray[index].W = sourceArray[index].W;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(std::vector<Vector4> const& sourceArray, Quaternion const& rotation, std::vector<Vector4>& destinationArray)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), rotation, destinationArray.data(), destinationArray.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector4::Transform(Vector4 const* sourceArray, size_t sourceLength, size_t sourceIndex, Quaternion const& rotation, Vector4* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (!sourceArray || !destinationArray || sourceLength < sourceIndex + length || destinationLength < destinationIndex + length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto num1 = rotation.X + rotation.X;
|
||||||
|
const auto num2 = rotation.Y + rotation.Y;
|
||||||
|
const auto num3 = rotation.Z + rotation.Z;
|
||||||
|
const auto num4 = rotation.W * num1;
|
||||||
|
const auto num5 = rotation.W * num2;
|
||||||
|
const auto num6 = rotation.W * num3;
|
||||||
|
const auto num7 = rotation.X * num1;
|
||||||
|
const auto num8 = rotation.X * num2;
|
||||||
|
const auto num9 = rotation.X * num3;
|
||||||
|
const auto num10 = rotation.Y * num2;
|
||||||
|
const auto num11 = rotation.Y * num3;
|
||||||
|
const auto num12 = rotation.Z * num3;
|
||||||
|
const auto num13 = 1.0f - num10 - num12;
|
||||||
|
const auto num14 = num8 - num6;
|
||||||
|
const auto num15 = num9 + num5;
|
||||||
|
const auto num16 = num8 + num6;
|
||||||
|
const auto num17 = 1.0f - num7 - num12;
|
||||||
|
const auto num18 = num11 - num4;
|
||||||
|
const auto num19 = num9 - num5;
|
||||||
|
const auto num20 = num11 + num4;
|
||||||
|
const auto num21 = 1.0f - num7 - num10;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
const auto& source = sourceArray[sourceIndex + i];
|
||||||
|
destinationArray[destinationIndex].X = source.X * num13 + source.Y * num14 + source.Z * num15;
|
||||||
|
destinationArray[destinationIndex].Y = source.X * num16 + source.Y * num17 + source.Z * num18;
|
||||||
|
destinationArray[destinationIndex].Z = source.X * num19 + source.Y * num20 + source.Z * num21;
|
||||||
|
destinationArray[destinationIndex].W = source.W;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Vector4::Transform(std::vector<Vector4> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector4>& destinationArray, size_t destinationIndex, size_t length)
|
||||||
|
{
|
||||||
|
if (destinationArray.empty())
|
||||||
|
destinationArray.resize(sourceArray.size());
|
||||||
|
|
||||||
|
return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length);
|
||||||
|
}
|
||||||
}
|
}
|
@ -53,8 +53,9 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline Vector2 Normalize(Vector2 const& value) {
|
static inline Vector2 Normalize(Vector2 const& value) {
|
||||||
const auto normal = 1.0F / value.Length();
|
auto v = value;
|
||||||
return { value.X * normal, value.Y * normal };
|
v.Normalize();
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Vector2 Reflect(Vector2 const& vector, Vector2 const& normal) {
|
static constexpr Vector2 Reflect(Vector2 const& vector, Vector2 const& normal) {
|
||||||
@ -136,14 +137,20 @@ namespace xna {
|
|||||||
static constexpr Vector2 TransformNormal(Vector2 const& normal, Matrix const& matrix);
|
static constexpr Vector2 TransformNormal(Vector2 const& normal, Matrix const& matrix);
|
||||||
static constexpr Vector2 Transform(Vector2 const& value, Quaternion const& rotation);
|
static constexpr Vector2 Transform(Vector2 const& value, Quaternion const& rotation);
|
||||||
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength);
|
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength);
|
||||||
|
static bool Transform(std::vector<Vector2> sourceArray, Matrix const& matrix, std::vector<Vector2>& destinationArray);
|
||||||
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
|
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
|
||||||
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
||||||
|
static bool Transform(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
static bool TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength);
|
static bool TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength);
|
||||||
|
static bool TransformNormal(std::vector<Vector2> const& sourceArray, Matrix const& matrix, std::vector<Vector2>& destinationArray);
|
||||||
static bool TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
|
static bool TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix,
|
||||||
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
||||||
|
static bool TransformNormal(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength);
|
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength);
|
||||||
|
static bool Transform(std::vector<Vector2> const& sourceArray, Quaternion const& rotation, std::vector<Vector2>& destinationArray);
|
||||||
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation,
|
static bool Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation,
|
||||||
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length);
|
||||||
|
static bool Transform(std::vector<Vector2> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector2>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
|
||||||
static constexpr Vector2 Negate(Vector2 const& value) {
|
static constexpr Vector2 Negate(Vector2 const& value) {
|
||||||
return { -value.X, -value.Y };
|
return { -value.X, -value.Y };
|
||||||
@ -260,8 +267,18 @@ namespace xna {
|
|||||||
return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z;
|
return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Normalize();
|
inline void Normalize() {
|
||||||
static Vector3 Normalize(Vector3 const& value);
|
const auto num = 1.0f / Length();
|
||||||
|
X *= num;
|
||||||
|
Y *= num;
|
||||||
|
Z *= num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector3 Normalize(Vector3 const& value) {
|
||||||
|
auto v = value;
|
||||||
|
v.Normalize();
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr Vector3 Cross(Vector3 const& vector1, Vector3 const& vector2) {
|
static constexpr Vector3 Cross(Vector3 const& vector1, Vector3 const& vector2) {
|
||||||
Vector3 vector3;
|
Vector3 vector3;
|
||||||
@ -364,11 +381,17 @@ namespace xna {
|
|||||||
static constexpr Vector3 Transform(Vector3 const& position, Matrix const& matrix);
|
static constexpr Vector3 Transform(Vector3 const& position, Matrix const& matrix);
|
||||||
static constexpr Vector3 TransformNormal(Vector3 const& normal, Matrix const& matrix);
|
static constexpr Vector3 TransformNormal(Vector3 const& normal, Matrix const& matrix);
|
||||||
static constexpr Vector3 Transform(Vector3 const& value, Quaternion const& rotation);
|
static constexpr Vector3 Transform(Vector3 const& value, Quaternion const& rotation);
|
||||||
|
static bool Transform(Vector3 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength);
|
||||||
static bool Transform(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray);
|
static bool Transform(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray);
|
||||||
|
static bool Transform(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length);
|
||||||
static bool Transform(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
static bool Transform(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
static bool TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector3* destinationArray, size_t destionationArrayLength);
|
||||||
static bool TransformNormal(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray);
|
static bool TransformNormal(std::vector<Vector3> const& sourceArray, Matrix const& matrix, std::vector<Vector3>& destinationArray);
|
||||||
|
static bool TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length);
|
||||||
static bool TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
static bool TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
static bool TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation,Vector3* destinationArray, size_t destinationLength);
|
||||||
static bool TransformNormal(std::vector<Vector3> const& sourceArray, Quaternion const& rotation, std::vector<Vector3>& destinationArray);
|
static bool TransformNormal(std::vector<Vector3> const& sourceArray, Quaternion const& rotation, std::vector<Vector3>& destinationArray);
|
||||||
|
static bool TransformNormal(Vector3 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Quaternion const& rotation, Vector3* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length);
|
||||||
static bool TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
static bool TransformNormal(std::vector<Vector3> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector3>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
|
||||||
static constexpr Vector3 Negate(Vector3 const& value)
|
static constexpr Vector3 Negate(Vector3 const& value)
|
||||||
@ -474,12 +497,279 @@ namespace xna {
|
|||||||
|
|
||||||
constexpr Vector4() = default;
|
constexpr Vector4() = default;
|
||||||
|
|
||||||
|
constexpr Vector4(float value):
|
||||||
|
X(value), Y(value), Z(value), W(value){}
|
||||||
|
|
||||||
constexpr Vector4(float X, float Y, float Z, float W)
|
constexpr Vector4(float X, float Y, float Z, float W)
|
||||||
: X(X), Y(Y), Z(Z), W(W) { }
|
: X(X), Y(Y), Z(Z), W(W) { }
|
||||||
|
|
||||||
|
constexpr Vector4(Vector2 value, float Z, float W)
|
||||||
|
: X(value.X), Y(value.Y), Z(Z), W(W) { }
|
||||||
|
|
||||||
|
constexpr Vector4(Vector3 value, float W)
|
||||||
|
: X(value.X), Y(value.Y), Z(value.Z), W(W) { }
|
||||||
|
|
||||||
constexpr bool operator==(const Vector4& other) const {
|
constexpr bool operator==(const Vector4& other) const {
|
||||||
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Vector4 Zero() { return {}; }
|
||||||
|
static Vector4 One() { return { 1 }; }
|
||||||
|
static Vector4 UnitX() { return { 1,0,0,0 }; }
|
||||||
|
static Vector4 UnitY() { return { 0,1,0,0 }; }
|
||||||
|
static Vector4 UnitZ() { return { 0,0,1,0 }; }
|
||||||
|
static Vector4 UnitW() { return { 0,0,0,1 }; }
|
||||||
|
|
||||||
|
float Length() const {
|
||||||
|
return sqrt(LengthSquared());
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr float LengthSquared() const {
|
||||||
|
return (X * X + Y * Y + Z * Z + W * W);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static float Distance(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
return sqrt(DistanceSquared(value1, value2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr float DistanceSquared(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
const auto num1 = value1.X - value2.X;
|
||||||
|
const auto num2 = value1.Y - value2.Y;
|
||||||
|
const auto num3 = value1.Z - value2.Z;
|
||||||
|
const auto num4 = value1.W - value2.W;
|
||||||
|
return num1 * num1 + num2 * num2 + num3 * num3 + num4 * num4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr float Dot(Vector4 const& vector1, Vector4 const& vector2) {
|
||||||
|
return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Normalize() {
|
||||||
|
const auto num = 1.0f / Length();
|
||||||
|
X *= num;
|
||||||
|
Y *= num;
|
||||||
|
Z *= num;
|
||||||
|
W *= num;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static Vector4 Normalize(Vector4 const& vector) {
|
||||||
|
auto v = vector;
|
||||||
|
v.Normalize();
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Min(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X < value2.X ? value1.X : value2.X;
|
||||||
|
vector4.Y = value1.Y < value2.Y ? value1.Y : value2.Y;
|
||||||
|
vector4.Z = value1.Z < value2.Z ? value1.Z : value2.Z;
|
||||||
|
vector4.W = value1.W < value2.W ? value1.W : value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Max(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X > value2.X ? value1.X : value2.X;
|
||||||
|
vector4.Y = value1.Y > value2.Y ? value1.Y : value2.Y;
|
||||||
|
vector4.Z = value1.Z > value2.Z ? value1.Z : value2.Z;
|
||||||
|
vector4.W = value1.W > value2.W ? value1.W : value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 Clamp(Vector4 const& value1, Vector4 const& min, Vector4 const& max) {
|
||||||
|
const auto x = value1.X;
|
||||||
|
const auto num1 = x > max.X ? max.X : x;
|
||||||
|
const auto num2 = num1 < min.X ? min.X : num1;
|
||||||
|
const auto y = value1.Y;
|
||||||
|
const auto num3 = y > max.Y ? max.Y : y;
|
||||||
|
const auto num4 = num3 < min.Y ? min.Y : num3;
|
||||||
|
const auto z = value1.Z;
|
||||||
|
const auto num5 = z > max.Z ? max.Z : z;
|
||||||
|
const auto num6 = num5 < min.Z ? min.Z : num5;
|
||||||
|
const auto w = value1.W;
|
||||||
|
const auto num7 = w > max.W ? max.W : w;
|
||||||
|
const auto num8 = num7 < min.W ? min.W : num7;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = num2;
|
||||||
|
vector4.Y = num4;
|
||||||
|
vector4.Z = num6;
|
||||||
|
vector4.W = num8;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 Lerp(Vector4 const& value1, Vector4 const& value2, float amount) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X + (value2.X - value1.X) * amount;
|
||||||
|
vector4.Y = value1.Y + (value2.Y - value1.Y) * amount;
|
||||||
|
vector4.Z = value1.Z + (value2.Z - value1.Z) * amount;
|
||||||
|
vector4.W = value1.W + (value2.W - value1.W) * amount;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 Barycentric(Vector4 const& value1, Vector4 const& value2, Vector4 const& value3, float amount1, float amount2) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X);
|
||||||
|
vector4.Y = value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y);
|
||||||
|
vector4.Z = value1.Z + amount1 * (value2.Z - value1.Z) + amount2 * (value3.Z - value1.Z);
|
||||||
|
vector4.W = value1.W + amount1 * (value2.W - value1.W) + amount2 * (value3.W - value1.W);
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 SmoothStep(Vector4 const& value1, Vector4 const& value2, float amount) {
|
||||||
|
amount = amount > 1.0F ? 1.0f : (amount < 0.0F ? 0.0f : amount);
|
||||||
|
amount = (amount * amount * (3.0F - 2.0F * amount));
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X + (value2.X - value1.X) * amount;
|
||||||
|
vector4.Y = value1.Y + (value2.Y - value1.Y) * amount;
|
||||||
|
vector4.Z = value1.Z + (value2.Z - value1.Z) * amount;
|
||||||
|
vector4.W = value1.W + (value2.W - value1.W) * amount;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 CatmullRom(Vector4 const& value1, Vector4 const& value2, Vector4 const& value3, Vector4 const& value4, float amount) {
|
||||||
|
const auto num1 = amount * amount;
|
||||||
|
const auto num2 = amount * num1;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = 0.5F * (2.0f * value2.X + (-value1.X + value3.X) * amount + (2.0F * value1.X - 5.0f * value2.X + 4.0f * value3.X - value4.X) * num1 + (-value1.X + 3.0f * value2.X - 3.0f * value3.X + value4.X) * num2);
|
||||||
|
vector4.Y = 0.5F * (2.0f * value2.Y + (-value1.Y + value3.Y) * amount + (2.0F * value1.Y - 5.0f * value2.Y + 4.0f * value3.Y - value4.Y) * num1 + (-value1.Y + 3.0f * value2.Y - 3.0f * value3.Y + value4.Y) * num2);
|
||||||
|
vector4.Z = 0.5F * (2.0f * value2.Z + (-value1.Z + value3.Z) * amount + (2.0F * value1.Z - 5.0f * value2.Z + 4.0f * value3.Z - value4.Z) * num1 + (-value1.Z + 3.0f * value2.Z - 3.0f * value3.Z + value4.Z) * num2);
|
||||||
|
vector4.W = 0.5F * (2.0f * value2.W + (-value1.W + value3.W) * amount + (2.0F * value1.W - 5.0f * value2.W + 4.0f * value3.W - value4.W) * num1 + (-value1.W + 3.0f * value2.W - 3.0f * value3.W + value4.W) * num2);
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector4 Hermite(Vector4 const& value1, Vector4 const& tangent1, Vector4 const& value2, Vector4 const& tangent2, float amount) {
|
||||||
|
const auto num1 = amount * amount;
|
||||||
|
const auto num2 = amount * num1;
|
||||||
|
const auto num3 = (2.0F * num2 - 3.0F * num1 + 1.0F);
|
||||||
|
const auto num4 = (-2.0F * num2 + 3.0F * num1);
|
||||||
|
const auto num5 = num2 - 2.0f * num1 + amount;
|
||||||
|
const auto num6 = num2 - num1;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = (value1.X * num3 + value2.X * num4 + tangent1.X * num5 + tangent2.X * num6);
|
||||||
|
vector4.Y = (value1.Y * num3 + value2.Y * num4 + tangent1.Y * num5 + tangent2.Y * num6);
|
||||||
|
vector4.Z = (value1.Z * num3 + value2.Z * num4 + tangent1.Z * num5 + tangent2.Z * num6);
|
||||||
|
vector4.W = (value1.W * num3 + value2.W * num4 + tangent1.W * num5 + tangent2.W * num6);
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Transform(Vector2 const& position, Matrix const& matrix);
|
||||||
|
static constexpr Vector4 Transform(Vector3 const& position, Matrix const& matrix);
|
||||||
|
static constexpr Vector4 Transform(Vector4 const& vector, Matrix const& matrix);
|
||||||
|
static constexpr Vector4 Transform(Vector2 const& value, Quaternion const& rotation);
|
||||||
|
static constexpr Vector4 Transform(Vector3 const& value, Quaternion const& rotation);
|
||||||
|
static bool Transform(Vector4 const* sourceArray, size_t sourceLength, Matrix const& matrix, Vector4* destinationArray, size_t destinationLength);
|
||||||
|
static bool Transform(std::vector<Vector4> const& sourceArray, size_t sourceLength, Matrix const& matrix, std::vector<Vector4>& destinationArray);
|
||||||
|
static bool Transform(Vector4 const* sourceArray, size_t sourceLength, size_t sourceIndex, Matrix const& matrix, Vector4* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length);
|
||||||
|
static bool Transform(std::vector<Vector4> const& sourceArray, size_t sourceIndex, Matrix const& matrix, std::vector<Vector4>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
static bool Transform(Vector4 const* sourceArray, size_t sourceLength, Quaternion const& rotation, Vector4* destinationArray, size_t destinationLength);
|
||||||
|
static bool Transform(std::vector<Vector4> const& sourceArray, Quaternion const& rotation, std::vector<Vector4>& destinationArray);
|
||||||
|
static bool Transform(Vector4 const* sourceArray, size_t sourceLength, size_t sourceIndex, Quaternion const& rotation, Vector4* destinationArray, size_t destinationLength, size_t destinationIndex, size_t length);
|
||||||
|
static bool Transform(std::vector<Vector4> const& sourceArray, size_t sourceIndex, Quaternion const& rotation, std::vector<Vector4>& destinationArray, size_t destinationIndex, size_t length);
|
||||||
|
|
||||||
|
static constexpr Vector4 Negate(Vector4 const& value) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = -value.X;
|
||||||
|
vector4.Y = -value.Y;
|
||||||
|
vector4.Z = -value.Z;
|
||||||
|
vector4.W = -value.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Add(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X + value2.X;
|
||||||
|
vector4.Y = value1.Y + value2.Y;
|
||||||
|
vector4.Z = value1.Z + value2.Z;
|
||||||
|
vector4.W = value1.W + value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Subtract(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X - value2.X;
|
||||||
|
vector4.Y = value1.Y - value2.Y;
|
||||||
|
vector4.Z = value1.Z - value2.Z;
|
||||||
|
vector4.W = value1.W - value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Multiply(Vector4 const& value1, Vector4 const& value2)
|
||||||
|
{
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X * value2.X;
|
||||||
|
vector4.Y = value1.Y * value2.Y;
|
||||||
|
vector4.Z = value1.Z * value2.Z;
|
||||||
|
vector4.W = value1.W * value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static constexpr Vector4 Multiply(Vector4 const& value1, float scaleFactor)
|
||||||
|
{
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X * scaleFactor;
|
||||||
|
vector4.Y = value1.Y * scaleFactor;
|
||||||
|
vector4.Z = value1.Z * scaleFactor;
|
||||||
|
vector4.W = value1.W * scaleFactor;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Divide(Vector4 const& value1, Vector4 const& value2)
|
||||||
|
{
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X / value2.X;
|
||||||
|
vector4.Y = value1.Y / value2.Y;
|
||||||
|
vector4.Z = value1.Z / value2.Z;
|
||||||
|
vector4.W = value1.W / value2.W;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Vector4 Divide(Vector4 const& value1, float divider)
|
||||||
|
{
|
||||||
|
float num = 1.0f / divider;
|
||||||
|
Vector4 vector4;
|
||||||
|
vector4.X = value1.X * num;
|
||||||
|
vector4.Y = value1.Y * num;
|
||||||
|
vector4.Z = value1.Z * num;
|
||||||
|
vector4.W = value1.W * num;
|
||||||
|
return vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector4 operator-() const {
|
||||||
|
return Vector4::Negate(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator+(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
return Vector4::Add(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator-(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
return Vector4::Subtract(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator*(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
return Vector4::Multiply(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator*(Vector4 const& value, float factor) {
|
||||||
|
return Vector4::Multiply(value, factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator*(float factor, Vector4 const& value) {
|
||||||
|
return Vector4::Multiply(value, factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator/(Vector4 const& value1, Vector4 const& value2) {
|
||||||
|
return Vector4::Divide(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator/(Vector4 const& value, float divider) {
|
||||||
|
return Vector4::Divide(value, divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr Vector4 operator/(float divider, Vector4 const& value) {
|
||||||
|
return Vector4::Divide(value, divider);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
framework/content/defaultreaders.hpp
Normal file
38
framework/content/defaultreaders.hpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef XNA_CONTENT_DEFAULTREADERS_ARRAY_HPP
|
||||||
|
#define XNA_CONTENT_DEFAULTREADERS_ARRAY_HPP
|
||||||
|
|
||||||
|
#include "reader.hpp"
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
template <typename T>
|
||||||
|
class ArrayReader : public ContentTypeReaderT<std::vector<T>> {
|
||||||
|
public:
|
||||||
|
void Initialize(sptr<ContentTypeReaderManager> const& manager) {
|
||||||
|
elementReader = manager->GetTypeReader(typeof<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<std::vector<T>> Read(ContentReader& input, std::vector<T>& existingInstance) override {
|
||||||
|
const auto length = input.ReadInt32();
|
||||||
|
std::vector<T> objArray(length);
|
||||||
|
|
||||||
|
for (size_t index = 0; index < length; ++index)
|
||||||
|
objArray[index] = input.ReadObject<T>(elementReader);
|
||||||
|
|
||||||
|
return objArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
sptr<ContentTypeReaderManager> elementReader = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BooleanReader : public ContentTypeReaderT<bool> {
|
||||||
|
sptr<bool> Read(ContentReader& input, bool& existingInstance) override {
|
||||||
|
auto value = input.ReadBoolean();
|
||||||
|
auto b = New<bool>(value);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -25,6 +25,12 @@ namespace xna {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
sptr<T> ReadObject(T existingInstance);
|
sptr<T> ReadObject(T existingInstance);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
sptr<T> ReadObject(ContentTypeReader& typeReader);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
sptr<T> ReadObject(ContentTypeReader& typeReader, T existingInstance);
|
||||||
|
|
||||||
Vector2 ReadVector2();
|
Vector2 ReadVector2();
|
||||||
Vector3 ReadVector3();
|
Vector3 ReadVector3();
|
||||||
Vector4 ReadVector4();
|
Vector4 ReadVector4();
|
||||||
@ -46,6 +52,9 @@ namespace xna {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
sptr<T> ReadObjectInternal(std::any& existingInstance, xna_error_nullarg);
|
sptr<T> ReadObjectInternal(std::any& existingInstance, xna_error_nullarg);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
sptr<T> ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance, xna_error_nullarg);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
sptr<T> InvokeReader(ContentTypeReader& reader, std::any& existingInstance, xna_error_nullarg);
|
sptr<T> InvokeReader(ContentTypeReader& reader, std::any& existingInstance, xna_error_nullarg);
|
||||||
@ -102,7 +111,6 @@ namespace xna {
|
|||||||
{
|
{
|
||||||
const auto sharedResourceCount = ReadHeader();
|
const auto sharedResourceCount = ReadHeader();
|
||||||
auto obj = ReadObject<T>();
|
auto obj = ReadObject<T>();
|
||||||
//this.ReadSharedResources(sharedResourceCount);
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +126,27 @@ namespace xna {
|
|||||||
{
|
{
|
||||||
return ReadObjectInternal<T>(std::any(existingInstance));
|
return ReadObjectInternal<T>(std::any(existingInstance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline sptr<T> ContentReader::ReadObject(ContentTypeReader& typeReader)
|
||||||
|
{
|
||||||
|
auto obj = std::any();
|
||||||
|
return ReadObjectInternal<T>(typeReader, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline sptr<T> ContentReader::ReadObject(ContentTypeReader& typeReader, T existingInstance)
|
||||||
|
{
|
||||||
|
return ReadObjectInternal<T>(typeReader, std::any(existingInstance));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline sptr<T> ContentReader::ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance, xna_error_ptr_arg)
|
||||||
|
{
|
||||||
|
return typeReader.TargetIsValueType
|
||||||
|
? InvokeReader<T>(typeReader, existingInstance, err)
|
||||||
|
: ReadObjectInternal<T>(existingInstance, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -15,7 +15,7 @@ namespace xna {
|
|||||||
public:
|
public:
|
||||||
virtual Int TypeVersion() { return 0; }
|
virtual Int TypeVersion() { return 0; }
|
||||||
virtual bool CanDeserializeIntoExistingObject() { return false; }
|
virtual bool CanDeserializeIntoExistingObject() { return false; }
|
||||||
virtual void Initialize(sptr<ContentTypeReaderManager>& manager) {}
|
virtual void Initialize(sptr<ContentTypeReaderManager> const& manager) {}
|
||||||
|
|
||||||
sptr<Type> TargetType() { return _targetType; }
|
sptr<Type> TargetType() { return _targetType; }
|
||||||
virtual std::any Read(ContentReader& input, std::any& existingInstance) = 0;
|
virtual std::any Read(ContentReader& input, std::any& existingInstance) = 0;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
||||||
#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
||||||
|
|
||||||
#include "../../content/reader.hpp"
|
|
||||||
#include "../texture-dx.hpp"
|
|
||||||
#include "../../content/manager.hpp"
|
#include "../../content/manager.hpp"
|
||||||
|
#include "../../content/reader.hpp"
|
||||||
#include "../../csharp/type.hpp"
|
#include "../../csharp/type.hpp"
|
||||||
|
#include "../texture-dx.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class Texture2DReader : public ContentTypeReaderT<Texture2D> {
|
class Texture2DReader : public ContentTypeReaderT<Texture2D> {
|
||||||
@ -18,7 +18,10 @@ namespace xna {
|
|||||||
const auto mipMaps = input.ReadInt32();
|
const auto mipMaps = input.ReadInt32();
|
||||||
|
|
||||||
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
|
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
|
||||||
auto device = std::any_cast<sptr<GraphicsDevice>>(a_device);
|
sptr<GraphicsDevice> device = nullptr;
|
||||||
|
|
||||||
|
if(a_device.has_value())
|
||||||
|
device = std::any_cast<sptr<GraphicsDevice>>(a_device);
|
||||||
|
|
||||||
auto texture2D = New<Texture2D>(device, width, height, mipMaps, format);
|
auto texture2D = New<Texture2D>(device, width, height, mipMaps, format);
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ namespace xna {
|
|||||||
auto elementCount = input.ReadInt32();
|
auto elementCount = input.ReadInt32();
|
||||||
std::vector<Byte> data = input.ReadByteBuffer(elementCount);
|
std::vector<Byte> data = input.ReadByteBuffer(elementCount);
|
||||||
|
|
||||||
texture2D->SetData(level, nullptr, data, 0, elementCount);
|
texture2D->SetData(static_cast<Int>(level), nullptr, data, 0, elementCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture2D;
|
return texture2D;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user