updated to latest crafter version
This commit is contained in:
parent
82ba7cf1af
commit
d01d482cd6
7 changed files with 234 additions and 310 deletions
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
Crafter.Math
|
||||
Copyright (C) 2025 Catcrafts
|
||||
Catcrafts.net
|
||||
Crafter®.Math
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
|
@ -18,23 +17,14 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
module;
|
||||
|
||||
#include <type_traits>
|
||||
#include <concepts>
|
||||
#include <immintrin.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
export module Crafter.Math:Vector;
|
||||
import std;
|
||||
|
||||
import :BasicTypes;
|
||||
import :Misc;
|
||||
|
||||
namespace Crafter {
|
||||
template <typename T, uint32_t Len>
|
||||
template <typename T, std::uint32_t Len>
|
||||
struct VectorBase {
|
||||
T v[Len];
|
||||
};
|
||||
|
|
@ -89,7 +79,7 @@ namespace Crafter {
|
|||
VectorBase<T, 4>() = default;
|
||||
};
|
||||
|
||||
export template <typename T, uint32_t Len>
|
||||
export template <typename T, std::uint32_t Len>
|
||||
class Vector : public VectorBase<T, Len> {
|
||||
public:
|
||||
Vector(float x, float y, float z, float w ) requires(std::same_as<T, float> && Len == 4) : VectorBase<T, Len>(x, y, z, w) {
|
||||
|
|
@ -105,16 +95,16 @@ namespace Crafter {
|
|||
|
||||
static Vector<T, Len> QuaternionRotationRollPitchYaw(float Pitch, float Yaw, float Roll) requires(Len == 4) {
|
||||
const float halfpitch = Pitch * 0.5f;
|
||||
float cp = cosf(halfpitch);
|
||||
float sp = sinf(halfpitch);
|
||||
float cp = std::cosf(halfpitch);
|
||||
float sp = std::sinf(halfpitch);
|
||||
|
||||
const float halfyaw = Yaw * 0.5f;
|
||||
float cy = cosf(halfyaw);
|
||||
float sy = sinf(halfyaw);
|
||||
float cy = std::cosf(halfyaw);
|
||||
float sy = std::sinf(halfyaw);
|
||||
|
||||
const float halfroll = Roll * 0.5f;
|
||||
float cr = cosf(halfroll);
|
||||
float sr = sinf(halfroll);
|
||||
float cr = std::cosf(halfroll);
|
||||
float sr = std::sinf(halfroll);
|
||||
|
||||
return Vector<T, Len>(
|
||||
cr * sp * cy + sr * cp * sy,
|
||||
|
|
@ -124,41 +114,41 @@ namespace Crafter {
|
|||
);
|
||||
}
|
||||
|
||||
template <uint32_t Blen>
|
||||
template <std::uint32_t Blen>
|
||||
Vector<T, Len> operator+(Vector<T, Blen> b){
|
||||
Vector<T, Len> resultVector;
|
||||
for(uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
resultVector.v[i] = this->v[i]+b.v[i];
|
||||
}
|
||||
return resultVector;
|
||||
}
|
||||
template <uint32_t Blen>
|
||||
template <std::uint32_t Blen>
|
||||
Vector<T, Len> operator-(Vector<T, Blen> b){
|
||||
Vector<T, Len> resultVector;
|
||||
for(uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
resultVector.v[i] = this->v[i]-b.v[i];
|
||||
}
|
||||
return resultVector;
|
||||
}
|
||||
Vector<T, Len> operator-(){
|
||||
Vector<T, Len> resultVector;
|
||||
for(uint32_t i = 0; i < Len; i++) {
|
||||
for(std::uint32_t i = 0; i < Len; i++) {
|
||||
resultVector.v[i] = -this->v[i];
|
||||
}
|
||||
return resultVector;
|
||||
}
|
||||
template <uint32_t Blen>
|
||||
template <std::uint32_t Blen>
|
||||
Vector<T, Len> operator*(Vector<T, Blen> b){
|
||||
Vector<T, Len> resultVector;
|
||||
for(uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
resultVector.v[i] = this->v[i]*b.v[i];
|
||||
}
|
||||
return resultVector;
|
||||
}
|
||||
template <uint32_t Blen>
|
||||
template <std::uint32_t Blen>
|
||||
Vector<T, Len> operator/(Vector<T, Blen> b){
|
||||
Vector<T, Len> resultVector;
|
||||
for(uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
for(std::uint32_t i = 0; i < std::min(Len, Blen); i++) {
|
||||
resultVector.v[i] = this->v[i]/b.v[i];
|
||||
}
|
||||
return resultVector;
|
||||
|
|
@ -197,7 +187,7 @@ namespace Crafter {
|
|||
float Length()
|
||||
{
|
||||
float Result = LengthSq();
|
||||
return sqrtf(Result);
|
||||
return std::sqrtf(Result);
|
||||
}
|
||||
|
||||
Vector<T, Len> ReciprocalLength() requires(Len == 3) {
|
||||
|
|
@ -209,9 +199,9 @@ namespace Crafter {
|
|||
Vector<T, Len> ReciprocalSqrt() requires(Len == 3)
|
||||
{
|
||||
return Vector<T, Len>(
|
||||
1.f / sqrtf(this->v[0]),
|
||||
1.f / sqrtf(this->v[1]),
|
||||
1.f / sqrtf(this->v[2])
|
||||
1.f / std::sqrtf(this->v[0]),
|
||||
1.f / std::sqrtf(this->v[1]),
|
||||
1.f / std::sqrtf(this->v[2])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +261,14 @@ namespace Crafter {
|
|||
return N * Scale;
|
||||
}
|
||||
|
||||
|
||||
static Vector<T, 4> NegativeMultiplySubtract(Vector<T, 4> a, Vector<T, 4> b, Vector<T, 4> c) requires(Len == 4) {
|
||||
return Vector<T, 4>(
|
||||
c.v[0] - (a.v[0] * b.v[0]),
|
||||
c.v[1] - (a.v[1] * b.v[1]),
|
||||
c.v[2] - (a.v[2] * b.v[2]),
|
||||
c.v[3] - (a.v[3] * b.v[3])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue