port from perforce
This commit is contained in:
147
4kgfx/vecmath.h
Normal file
147
4kgfx/vecmath.h
Normal file
@@ -0,0 +1,147 @@
|
||||
#pragma once
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
float pi();
|
||||
void* memcpy(void* dest, const void* source, size_t size);
|
||||
void memclear(void* dest, size_t size);
|
||||
size_t strlen(const char* string);
|
||||
|
||||
float pow(float x, float y);
|
||||
float sqrt(float x);
|
||||
float sin(float x);
|
||||
float cos(float x);
|
||||
float fabs(float x);
|
||||
float smoothstep(float x, float a, float b);
|
||||
float exp2(float f);
|
||||
float tan(float f);
|
||||
unsigned long ftol(float x);
|
||||
long _ftol2_sse(float x);
|
||||
float min(float a, float b);
|
||||
float max(float a, float b);
|
||||
}
|
||||
|
||||
struct __declspec(align(16)) vec4
|
||||
{
|
||||
union
|
||||
{
|
||||
struct __declspec(align(16))
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
__declspec(align(16)) float m[4];
|
||||
};
|
||||
|
||||
vec4();
|
||||
vec4(const vec4& arg);
|
||||
vec4(float X, float Y, float Z, float W = 0.0f);
|
||||
vec4(float a);
|
||||
vec4(const float* arg);
|
||||
vec4(const __m128& arg);
|
||||
|
||||
int ToInt32() const;
|
||||
operator __m128() const;
|
||||
float& operator[](int i);
|
||||
vec4 operator + (const vec4& arg) const;
|
||||
vec4 operator + (float arg) const;
|
||||
void operator += (const vec4& arg);
|
||||
void operator += (float arg);
|
||||
vec4 operator - (const vec4& arg) const;
|
||||
vec4 operator - (float arg) const;
|
||||
void operator -= (const vec4& arg);
|
||||
void operator -= (float arg);
|
||||
vec4 operator * (const vec4& arg) const;
|
||||
vec4 operator * (float arg) const;
|
||||
void operator *= (const vec4& arg);
|
||||
void operator *= (float arg);
|
||||
vec4 operator / (float arg) const;
|
||||
void operator /= (float arg);
|
||||
vec4 operator -() const;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(align(16)) Quaternion
|
||||
{
|
||||
union
|
||||
{
|
||||
struct __declspec(align(16))
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
__declspec(align(16)) float m[4];
|
||||
};
|
||||
|
||||
Quaternion();
|
||||
Quaternion(const Quaternion& arg);
|
||||
Quaternion(const float* M);
|
||||
operator __m128() const;
|
||||
Quaternion(float X, float Y, float Z, float W, bool ab_Rotation = false);
|
||||
Quaternion(const __m128& arg);
|
||||
operator float*();
|
||||
Quaternion operator * (const Quaternion& arg) const;
|
||||
Quaternion operator -() const;
|
||||
void operator *= (const Quaternion& arg);
|
||||
void operator += (const Quaternion& arg);
|
||||
void rotate (const Quaternion& arg);
|
||||
float lengthSquared() const;
|
||||
float length() const;
|
||||
void normalize();
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(align(16)) Matrix
|
||||
{
|
||||
union
|
||||
{
|
||||
struct __declspec(align(16))
|
||||
{
|
||||
vec4 r1;
|
||||
vec4 r2;
|
||||
vec4 r3;
|
||||
vec4 r4;
|
||||
};
|
||||
__declspec(align(16)) float m[16];
|
||||
};
|
||||
|
||||
Matrix();
|
||||
Matrix(const Matrix& arg);
|
||||
Matrix(const vec4& R1, const vec4& R2, const vec4& R3, const vec4& R4);
|
||||
Matrix(const float* M);
|
||||
Matrix(const Quaternion& aQuaternion);
|
||||
float& operator[](int i);
|
||||
vec4 operator * (const vec4& arg) const;
|
||||
Matrix operator * (const Matrix& arg) const;
|
||||
void operator *= (const Matrix& arg);
|
||||
static Matrix rotateX(float af_Rad);
|
||||
static Matrix rotateY(float af_Rad);
|
||||
static Matrix rotateZ(float af_Rad);
|
||||
static Matrix scale(float s);
|
||||
static Matrix scale(const vec4& s);
|
||||
static Matrix translate(const vec4& aTranslation);
|
||||
static Matrix Perspective(float fov, float aspect, float near, float far);
|
||||
static Matrix LookAt(vec4& eye, vec4& center, vec4& up);
|
||||
void transpose();
|
||||
float Determinante2x2(float a1, float a2, float b1, float b2);
|
||||
float Determinante3x3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3);
|
||||
void inverse();
|
||||
};
|
||||
|
||||
__inline vec4 align(vec4& arg);
|
||||
__inline Quaternion align(Quaternion& arg);
|
||||
__inline Matrix align(Matrix& arg);
|
||||
float dot(const vec4& arg1, const vec4& arg2);
|
||||
float length(vec4& arg);
|
||||
vec4 normalize(vec4 const& arg);
|
||||
vec4 mix(vec4& arg1, vec4& arg2, float t);
|
||||
vec4 clamp(vec4& arg, float lo, float hi);
|
||||
float clamp(float arg, float lo, float hi);
|
||||
vec4 reflect(vec4& arg1, vec4& arg2);
|
||||
vec4 cross(vec4& a, vec4& b);
|
||||
Reference in New Issue
Block a user