scalar vector math

This commit is contained in:
Jorijn van der Graaf 2026-02-11 03:01:42 +01:00
commit bb85af197c

View file

@ -209,6 +209,63 @@ namespace Crafter {
}
}
template <typename BT>
constexpr Vector<T, Len, Aligment> operator+(BT b) const {
Vector<T, Len, Aligment> resultVector;
for(std::uint32_t i = 0; i < Len; i++) {
resultVector.v[i] = this->v[i] + b;
}
return resultVector;
}
template <typename BT>
constexpr Vector<T, Len, Aligment> operator-(BT b) const {
Vector<T, Len, Aligment> resultVector;
for(std::uint32_t i = 0; i < Len; i++) {
resultVector.v[i] = this->v[i] - b;
}
return resultVector;
}
template <typename BT>
constexpr Vector<T, Len, Aligment> operator*(BT b) const {
Vector<T, Len, Aligment> resultVector;
for(std::uint32_t i = 0; i < Len; i++) {
resultVector.v[i] = this->v[i] * b;
}
return resultVector;
}
template <typename BT>
constexpr Vector<T, Len, Aligment> operator/(BT b) const {
Vector<T, Len, Aligment> resultVector;
for(std::uint32_t i = 0; i < Len; i++) {
resultVector.v[i] = this->v[i] / b;
}
return resultVector;
}
template <typename BT>
constexpr void operator+=(BT b){
for(std::uint32_t i = 0; i < Len; i++) {
this->v[i] += b;
}
}
template <typename BT>
constexpr void operator-=(BT b){
for(std::uint32_t i = 0; i < Len; i++) {
this->v[i] -= b;
}
}
template <typename BT>
constexpr void operator*=(BT b){
for(std::uint32_t i = 0; i < Len; i++) {
this->v[i] *= b;
}
}
template <typename BT>
constexpr void operator/=(BT b){
for(std::uint32_t i = 0; i < Len; i++) {
this->v[i] /= b;
}
}
constexpr void Normalize() {
float fLength = Length();