nvidia-texture-tools/src/nvmath/Vector.h

131 lines
3.2 KiB
C
Raw Normal View History

2007-04-17 08:49:19 +00:00
// This code is in the public domain -- castanyo@yahoo.es
2010-05-27 23:19:24 +00:00
#pragma once
2007-04-17 08:49:19 +00:00
#ifndef NV_MATH_VECTOR_H
#define NV_MATH_VECTOR_H
2010-05-27 23:19:24 +00:00
#include "nvmath.h"
2007-04-17 08:49:19 +00:00
namespace nv
{
2010-05-27 23:19:24 +00:00
class NVMATH_CLASS Vector2
{
public:
typedef Vector2 const & Arg;
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
Vector2();
explicit Vector2(float f);
Vector2(float x, float y);
2010-05-27 23:19:24 +00:00
Vector2(Vector2::Arg v);
2007-04-17 08:49:19 +00:00
2012-07-20 16:19:03 +00:00
template <typename T> operator T() const { return T(x, y); }
2010-05-27 23:19:24 +00:00
const Vector2 & operator=(Vector2::Arg v);
2007-04-17 08:49:19 +00:00
const float * ptr() const;
2007-04-17 08:49:19 +00:00
void set(float x, float y);
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
Vector2 operator-() const;
void operator+=(Vector2::Arg v);
void operator-=(Vector2::Arg v);
void operator*=(float s);
2010-05-27 23:19:24 +00:00
void operator*=(Vector2::Arg v);
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
friend bool operator==(Vector2::Arg a, Vector2::Arg b);
friend bool operator!=(Vector2::Arg a, Vector2::Arg b);
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
union {
struct {
float x, y;
2010-05-27 23:19:24 +00:00
};
float component[2];
2010-05-27 23:19:24 +00:00
};
};
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
class NVMATH_CLASS Vector3
{
public:
typedef Vector3 const & Arg;
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
Vector3();
explicit Vector3(float x);
Vector3(float x, float y, float z);
Vector3(Vector2::Arg v, float z);
2010-05-27 23:19:24 +00:00
Vector3(Vector3::Arg v);
2007-04-17 08:49:19 +00:00
2012-07-20 16:19:03 +00:00
template <typename T> operator T() const { return T(x, y, z); }
2010-05-27 23:19:24 +00:00
const Vector3 & operator=(Vector3::Arg v);
2007-04-17 08:49:19 +00:00
Vector2 xy() const;
2007-04-17 08:49:19 +00:00
const float * ptr() const;
2007-04-17 08:49:19 +00:00
void set(float x, float y, float z);
2007-04-17 08:49:19 +00:00
2010-05-27 23:19:24 +00:00
Vector3 operator-() const;
void operator+=(Vector3::Arg v);
void operator-=(Vector3::Arg v);
void operator*=(float s);
void operator/=(float s);
2010-05-27 23:19:24 +00:00
void operator*=(Vector3::Arg v);
friend bool operator==(Vector3::Arg a, Vector3::Arg b);
friend bool operator!=(Vector3::Arg a, Vector3::Arg b);
union {
struct {
float x, y, z;
2010-05-27 23:19:24 +00:00
};
float component[3];
2010-05-27 23:19:24 +00:00
};
};
class NVMATH_CLASS Vector4
{
public:
typedef Vector4 const & Arg;
Vector4();
explicit Vector4(float x);
Vector4(float x, float y, float z, float w);
Vector4(Vector2::Arg v, float z, float w);
2011-09-27 17:48:46 +00:00
Vector4(Vector2::Arg v, Vector2::Arg u);
Vector4(Vector3::Arg v, float w);
2010-05-27 23:19:24 +00:00
Vector4(Vector4::Arg v);
// Vector4(const Quaternion & v);
2012-07-20 16:19:03 +00:00
template <typename T> operator T() const { return T(x, y, z, w); }
2010-05-27 23:19:24 +00:00
const Vector4 & operator=(Vector4::Arg v);
Vector2 xy() const;
2011-09-27 17:48:46 +00:00
Vector2 zw() const;
Vector3 xyz() const;
2010-05-27 23:19:24 +00:00
const float * ptr() const;
2010-05-27 23:19:24 +00:00
void set(float x, float y, float z, float w);
2010-05-27 23:19:24 +00:00
Vector4 operator-() const;
void operator+=(Vector4::Arg v);
void operator-=(Vector4::Arg v);
void operator*=(float s);
2010-05-27 23:19:24 +00:00
void operator*=(Vector4::Arg v);
friend bool operator==(Vector4::Arg a, Vector4::Arg b);
friend bool operator!=(Vector4::Arg a, Vector4::Arg b);
union {
struct {
float x, y, z, w;
2010-05-27 23:19:24 +00:00
};
float component[4];
2010-05-27 23:19:24 +00:00
};
};
2007-04-17 08:49:19 +00:00
} // nv namespace
#endif // NV_MATH_VECTOR_H