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();
|
2012-01-02 08:49:13 +00:00
|
|
|
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
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
const Vector2 & operator=(Vector2::Arg v);
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2012-01-02 08:49:13 +00:00
|
|
|
const float * ptr() const;
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2012-01-02 08:49:13 +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);
|
2012-01-02 08:49:13 +00:00
|
|
|
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 {
|
2012-01-02 08:49:13 +00:00
|
|
|
float x, y;
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
2012-01-02 08:49:13 +00:00
|
|
|
float component[2];
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
|
|
|
};
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2011-04-06 02:41:15 +00:00
|
|
|
// Helpers to convert vector types. Assume T has x,y members and 2 argument constructor.
|
|
|
|
template <typename T> T to(Vector2::Arg v) { return T(v.x, v.y); }
|
|
|
|
|
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();
|
2012-01-02 08:49:13 +00:00
|
|
|
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
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
const Vector3 & operator=(Vector3::Arg v);
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2010-10-06 02:56:35 +00:00
|
|
|
Vector2 xy() const;
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2012-01-02 08:49:13 +00:00
|
|
|
const float * ptr() const;
|
2007-04-17 08:49:19 +00:00
|
|
|
|
2012-01-02 08:49:13 +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);
|
2012-01-02 08:49:13 +00:00
|
|
|
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 {
|
2012-01-02 08:49:13 +00:00
|
|
|
float x, y, z;
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
2012-01-02 08:49:13 +00:00
|
|
|
float component[3];
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2010-10-21 18:44:10 +00:00
|
|
|
// Helpers to convert vector types. Assume T has x,y,z members and 3 argument constructor.
|
|
|
|
template <typename T> T to(Vector3::Arg v) { return T(v.x, v.y, v.z); }
|
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
|
|
|
|
class NVMATH_CLASS Vector4
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Vector4 const & Arg;
|
|
|
|
|
|
|
|
Vector4();
|
2012-01-02 08:49:13 +00:00
|
|
|
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);
|
2012-01-02 08:49:13 +00:00
|
|
|
Vector4(Vector3::Arg v, float w);
|
2010-05-27 23:19:24 +00:00
|
|
|
Vector4(Vector4::Arg v);
|
|
|
|
// Vector4(const Quaternion & v);
|
|
|
|
|
|
|
|
const Vector4 & operator=(Vector4::Arg v);
|
|
|
|
|
2010-10-06 02:56:35 +00:00
|
|
|
Vector2 xy() const;
|
2011-09-27 17:48:46 +00:00
|
|
|
Vector2 zw() const;
|
2010-10-06 02:56:35 +00:00
|
|
|
Vector3 xyz() const;
|
2010-05-27 23:19:24 +00:00
|
|
|
|
2012-01-02 08:49:13 +00:00
|
|
|
const float * ptr() const;
|
2010-05-27 23:19:24 +00:00
|
|
|
|
2012-01-02 08:49:13 +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);
|
2012-01-02 08:49:13 +00:00
|
|
|
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 {
|
2012-01-02 08:49:13 +00:00
|
|
|
float x, y, z, w;
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
2012-01-02 08:49:13 +00:00
|
|
|
float component[4];
|
2010-05-27 23:19:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-04-06 02:41:15 +00:00
|
|
|
// Helpers to convert vector types. Assume T has x,y,z members and 3 argument constructor.
|
|
|
|
template <typename T> T to(Vector4::Arg v) { return T(v.x, v.y, v.z, v.w); }
|
|
|
|
|
|
|
|
|
2007-04-17 08:49:19 +00:00
|
|
|
} // nv namespace
|
|
|
|
|
|
|
|
#endif // NV_MATH_VECTOR_H
|