Torque3D/Engine/source/math/mPoint4.h
marauder2k7 67f12311d4 ISA backends float3 and float4 - cleanup history squash
working for both neon32 and neon64

Update math_backend.cpp

further sse simd additions

avx2 float3 added
added normalize_magnitude
added divide fast to float3 may copy to float4

move static spheremesh to drawSphere (initialize on first use) so platform has a chance to load the math backend

all float3 and float4 functions and isas

completed all options of float3 and float4 functions in isas and math_c
neon still to be done but that will be on mac.

Update math_backend.cpp

mac isa neon update

added float3
restructured the classes to look more like the final version of the x86 classes

linux required changes

Update build-macos-clang.yml

Update build-macos-clang.yml

Revert "Update build-macos-clang.yml"

This reverts commit 29dfc567f4.

Revert "Update build-macos-clang.yml"

This reverts commit 2abad2b4ca.

Update CMakeLists.txt

fix macs stupid build

remove god awful rolling average from frame time tracker....

use intrinsic headers instead

each isa implementation now uses a header for that isa's intrinsic functions these are then used in the impl files. This will make it easier for matrix functions when those are implemented.

fixed comment saying 256 when it should be 512 for avx512

consolidated initializers for function tables

Update neon_intrinsics.h

fixes for some neon intrinsics no idea if this is the best way to do these but they work at least

v_cross is especially messy at the moment we basically just do it as a c math function need to look into getting this done correctly
2026-03-05 18:55:34 +00:00

269 lines
6.7 KiB
C++

//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _MPOINT4_H_
#define _MPOINT4_H_
#ifndef _MMATHFN_H_
#include "math/mMathFn.h"
#endif
#ifndef _MPOINT3_H_
#include "math/mPoint3.h"
#endif
#ifndef _MATH_BACKEND_H_
#include "math/public/math_backend.h"
#endif
//------------------------------------------------------------------------------
/// 4D integer point
///
/// Uses S32 internally. Currently storage only.
class Point4I
{
public:
Point4I() :x(0), y(0), z(0), w(0) {}
Point4I(S32 _x, S32 _y, S32 _z, S32 _w);
void zero(); ///< Zero all values
S32 x;
S32 y;
S32 z;
S32 w;
//-------------------------------------- Public static constants
public:
const static Point4I One;
const static Point4I Zero;
};
//------------------------------------------------------------------------------
/// 4D floating-point point.
///
/// Uses F32 internally.
///
/// Useful for representing quaternions and other 4d beasties.
using math_backend::float4::dispatch::gFloat4;
class Point4F
{
//-------------------------------------- Public data
public:
F32 x; ///< X co-ordinate.
F32 y; ///< Y co-ordinate.
F32 z; ///< Z co-ordinate.
F32 w; ///< W co-ordinate.
public:
Point4F(); ///< Create an uninitialized point.
Point4F(const Point4F&); ///< Copy constructor.
/// Create point from coordinates.
Point4F(F32 _x, F32 _y, F32 _z, F32 _w);
/// Set point's coordinates.
void set(F32 _x, F32 _y, F32 _z, F32 _w);
/// Interpolate from _pt1 to _pt2, based on _factor.
///
/// @param _pt1 Starting point.
/// @param _pt2 Ending point.
/// @param _factor Interpolation factor (0.0 .. 1.0).
void interpolate(const Point4F& _pt1, const Point4F& _pt2, F32 _factor);
void zero();
operator F32*() { return (&x); }
operator const F32*() const { return &x; }
F32 len() const;
Point4F operator/(F32) const;
Point4F operator*(F32) const;
Point4F operator+(const Point4F&) const;
Point4F& operator+=(const Point4F&);
Point4F operator-(const Point4F&) const;
Point4F operator*(const Point4F&) const;
Point4F& operator*=(const Point4F&);
Point4F& operator=(const Point3F&);
Point4F& operator=(const Point4F&);
Point4F& operator/=(F32);
Point3F asPoint3F() const { return Point3F(x,y,z); }
//-------------------------------------- Public static constants
public:
const static Point4F One;
const static Point4F Zero;
};
typedef Point4F Vector4F; ///< Points can be vectors!
//------------------------------------------------------------------------------
//-------------------------------------- Point4I
inline void Point4I::zero()
{
x = y = z = w = 0;
}
//------------------------------------------------------------------------------
//-------------------------------------- Point4F
//
inline Point4F::Point4F()
:x(0.0f), y(0.0f), z(0.0f), w(0.0f)
{
}
inline Point4F::Point4F(const Point4F& _copy)
: x(_copy.x), y(_copy.y), z(_copy.z), w(_copy.w)
{
}
inline Point4F::Point4F(F32 _x, F32 _y, F32 _z, F32 _w)
: x(_x), y(_y), z(_z), w(_w)
{
}
inline void Point4F::set(F32 _x, F32 _y, F32 _z, F32 _w)
{
x = _x;
y = _y;
z = _z;
w = _w;
}
inline F32 Point4F::len() const
{
return gFloat4.length(*this);
}
inline void Point4F::interpolate(const Point4F& _from, const Point4F& _to, F32 _factor)
{
gFloat4.lerp(_from, _to, _factor, *this);
}
inline void Point4F::zero()
{
x = y = z = w = 0.0f;
}
inline Point4F& Point4F::operator=(const Point3F &_vec)
{
x = _vec.x;
y = _vec.y;
z = _vec.z;
w = 1.0f;
return *this;
}
inline Point4F& Point4F::operator=(const Point4F &_vec)
{
x = _vec.x;
y = _vec.y;
z = _vec.z;
w = _vec.w;
return *this;
}
inline Point4F& Point4F::operator/=(F32 scalar)
{
// Prevent division by zero
if (mIsZero(scalar))
return *this;
gFloat4.div_scalar(*this, scalar, *this);
return *this;
}
inline Point4F Point4F::operator+(const Point4F& _add) const
{
Point4F res;
gFloat4.add(*this, _add, res);
return res;
}
inline Point4F& Point4F::operator+=(const Point4F& _add)
{
gFloat4.add(*this, _add, *this);
return *this;
}
inline Point4F Point4F::operator-(const Point4F& _rSub) const
{
Point4F res;
gFloat4.sub(*this, _rSub, res);
return res;
}
inline Point4F Point4F::operator*(const Point4F &_vec) const
{
Point4F res;
gFloat4.mul(*this, _vec, res);
return res;
}
inline Point4F Point4F::operator*(F32 _mul) const
{
Point4F res;
gFloat4.mul_scalar(*this, _mul, res);
return res;
}
inline Point4F Point4F::operator /(F32 t) const
{
Point4F res;
gFloat4.div_scalar(*this, t, res);
return res;
}
inline F32 mDot(const Point4F &p1, const Point4F &p2)
{
return gFloat4.dot(p1, p2);
}
//------------------------------------------------------------------------------
//-------------------------------------- Point4F
inline Point4I::Point4I(S32 _x, S32 _y, S32 _z, S32 _w) : x(_x), y(_y), z(_z), w(_w)
{
}
//-------------------------------------------------------------------
// Non-Member Operators
//-------------------------------------------------------------------
inline Point4F operator*(F32 mul, const Point4F& multiplicand)
{
return multiplicand * mul;
}
inline bool mIsNaN( const Point4F &p )
{
return mIsNaN_F( p.x ) || mIsNaN_F( p.y ) || mIsNaN_F( p.z ) || mIsNaN_F( p.w );
}
#endif // _MPOINT4_H_