/s/KRVector3/Vector3/g
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "Vector2.h"
|
||||
#include "KRVector3.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
@@ -22,24 +22,24 @@ class KRMat4;
|
||||
|
||||
class KRAABB {
|
||||
public:
|
||||
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint);
|
||||
KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix);
|
||||
KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint);
|
||||
KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix);
|
||||
KRAABB();
|
||||
~KRAABB();
|
||||
|
||||
void scale(const KRVector3 &s);
|
||||
void scale(const Vector3 &s);
|
||||
void scale(float s);
|
||||
|
||||
KRVector3 center() const;
|
||||
KRVector3 size() const;
|
||||
Vector3 center() const;
|
||||
Vector3 size() const;
|
||||
float volume() const;
|
||||
bool intersects(const KRAABB& b) const;
|
||||
bool contains(const KRAABB &b) const;
|
||||
bool contains(const KRVector3 &v) const;
|
||||
bool contains(const Vector3 &v) const;
|
||||
|
||||
bool intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const;
|
||||
bool intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const;
|
||||
bool intersectsSphere(const KRVector3 ¢er, float radius) const;
|
||||
bool intersectsLine(const Vector3 &v1, const Vector3 &v2) const;
|
||||
bool intersectsRay(const Vector3 &v1, const Vector3 &dir) const;
|
||||
bool intersectsSphere(const Vector3 ¢er, float radius) const;
|
||||
void encapsulate(const KRAABB & b);
|
||||
|
||||
KRAABB& operator =(const KRAABB& b);
|
||||
@@ -50,14 +50,14 @@ public:
|
||||
bool operator >(const KRAABB& b) const;
|
||||
bool operator <(const KRAABB& b) const;
|
||||
|
||||
KRVector3 min;
|
||||
KRVector3 max;
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
|
||||
static KRAABB Infinite();
|
||||
static KRAABB Zero();
|
||||
|
||||
float longest_radius() const;
|
||||
KRVector3 nearestPoint(const KRVector3 & v) const;
|
||||
Vector3 nearestPoint(const Vector3 & v) const;
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
@@ -68,8 +68,8 @@ namespace std {
|
||||
public:
|
||||
size_t operator()(const kraken::KRAABB &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::KRVector3>()(s.min);
|
||||
size_t h2 = hash<kraken::KRVector3>()(s.max);
|
||||
size_t h1 = hash<kraken::Vector3>()(s.min);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.max);
|
||||
return h1 ^ ( h2 << 1 );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
//
|
||||
|
||||
|
||||
#include "KRVector3.h"
|
||||
#include "Vector3.h"
|
||||
#include "KRVector4.h"
|
||||
|
||||
#ifndef KRMAT4_H
|
||||
@@ -56,7 +56,7 @@ class KRMat4 {
|
||||
|
||||
KRMat4(float *pMat);
|
||||
|
||||
KRMat4(const KRVector3 &axis_x, const KRVector3 &axis_y, const KRVector3 &axis_z, const KRVector3 &trans);
|
||||
KRMat4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans);
|
||||
|
||||
// Destructor
|
||||
~KRMat4();
|
||||
@@ -85,9 +85,9 @@ class KRMat4 {
|
||||
void perspective(float fov, float aspect, float nearz, float farz);
|
||||
void ortho(float left, float right, float top, float bottom, float nearz, float farz);
|
||||
void translate(float x, float y, float z);
|
||||
void translate(const KRVector3 &v);
|
||||
void translate(const Vector3 &v);
|
||||
void scale(float x, float y, float z);
|
||||
void scale(const KRVector3 &v);
|
||||
void scale(const Vector3 &v);
|
||||
void scale(float s);
|
||||
void rotate(float angle, AXIS axis);
|
||||
void rotate(const KRQuaternion &q);
|
||||
@@ -95,19 +95,19 @@ class KRMat4 {
|
||||
bool invert();
|
||||
void transpose();
|
||||
|
||||
static KRVector3 DotNoTranslate(const KRMat4 &m, const KRVector3 &v); // Dot product without including translation; useful for transforming normals and tangents
|
||||
static Vector3 DotNoTranslate(const KRMat4 &m, const Vector3 &v); // Dot product without including translation; useful for transforming normals and tangents
|
||||
static KRMat4 Invert(const KRMat4 &m);
|
||||
static KRMat4 Transpose(const KRMat4 &m);
|
||||
static KRVector3 Dot(const KRMat4 &m, const KRVector3 &v);
|
||||
static Vector3 Dot(const KRMat4 &m, const Vector3 &v);
|
||||
static KRVector4 Dot4(const KRMat4 &m, const KRVector4 &v);
|
||||
static float DotW(const KRMat4 &m, const KRVector3 &v);
|
||||
static KRVector3 DotWDiv(const KRMat4 &m, const KRVector3 &v);
|
||||
static float DotW(const KRMat4 &m, const Vector3 &v);
|
||||
static Vector3 DotWDiv(const KRMat4 &m, const Vector3 &v);
|
||||
|
||||
static KRMat4 LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, const KRVector3 &upDirection);
|
||||
static KRMat4 LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection);
|
||||
|
||||
static KRMat4 Translation(const KRVector3 &v);
|
||||
static KRMat4 Rotation(const KRVector3 &v);
|
||||
static KRMat4 Scaling(const KRVector3 &v);
|
||||
static KRMat4 Translation(const Vector3 &v);
|
||||
static KRMat4 Rotation(const Vector3 &v);
|
||||
static KRMat4 Scaling(const Vector3 &v);
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef KRQUATERNION_H
|
||||
#define KRQUATERNION_H
|
||||
|
||||
#include "KRVector3.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
@@ -41,8 +41,8 @@ public:
|
||||
KRQuaternion();
|
||||
KRQuaternion(float w, float x, float y, float z);
|
||||
KRQuaternion(const KRQuaternion& p);
|
||||
KRQuaternion(const KRVector3 &euler);
|
||||
KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector);
|
||||
KRQuaternion(const Vector3 &euler);
|
||||
KRQuaternion(const Vector3 &from_vector, const Vector3 &to_vector);
|
||||
~KRQuaternion();
|
||||
|
||||
KRQuaternion& operator =( const KRQuaternion& p );
|
||||
@@ -66,9 +66,9 @@ public:
|
||||
float& operator [](unsigned i);
|
||||
float operator [](unsigned i) const;
|
||||
|
||||
void setEulerXYZ(const KRVector3 &euler);
|
||||
void setEulerZYX(const KRVector3 &euler);
|
||||
KRVector3 eulerXYZ() const;
|
||||
void setEulerXYZ(const Vector3 &euler);
|
||||
void setEulerZYX(const Vector3 &euler);
|
||||
Vector3 eulerXYZ() const;
|
||||
KRMat4 rotationMatrix() const;
|
||||
|
||||
void normalize();
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
void conjugate();
|
||||
static KRQuaternion Conjugate(const KRQuaternion &v1);
|
||||
|
||||
static KRQuaternion FromAngleAxis(const KRVector3 &axis, float angle);
|
||||
static KRQuaternion FromAngleAxis(const Vector3 &axis, float angle);
|
||||
static KRQuaternion Lerp(const KRQuaternion &a, const KRQuaternion &b, float t);
|
||||
static KRQuaternion Slerp(const KRQuaternion &a, const KRQuaternion &b, float t);
|
||||
static float Dot(const KRQuaternion &v1, const KRQuaternion &v2);
|
||||
|
||||
@@ -32,32 +32,32 @@
|
||||
#ifndef KRTRIANGLE3_H
|
||||
#define KRTRIANGLE3_H
|
||||
|
||||
#include "KRVector3.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class KRTriangle3
|
||||
{
|
||||
public:
|
||||
KRVector3 vert[3];
|
||||
Vector3 vert[3];
|
||||
|
||||
KRTriangle3(const KRTriangle3 &tri);
|
||||
KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3);
|
||||
KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
|
||||
~KRTriangle3();
|
||||
|
||||
KRVector3 calculateNormal() const;
|
||||
Vector3 calculateNormal() const;
|
||||
|
||||
bool operator ==(const KRTriangle3& b) const;
|
||||
bool operator !=(const KRTriangle3& b) const;
|
||||
KRTriangle3& operator =(const KRTriangle3& b);
|
||||
KRVector3& operator[](unsigned int i);
|
||||
KRVector3 operator[](unsigned int i) const;
|
||||
Vector3& operator[](unsigned int i);
|
||||
Vector3 operator[](unsigned int i) const;
|
||||
|
||||
bool rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector3 &hit_point) const;
|
||||
bool sphereCast(const KRVector3 &start, const KRVector3 &dir, float radius, KRVector3 &hit_point, float &hit_distance) const;
|
||||
bool rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const;
|
||||
bool sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const;
|
||||
|
||||
bool containsPoint(const KRVector3 &p) const;
|
||||
KRVector3 closestPointOnTriangle(const KRVector3 &p) const;
|
||||
bool containsPoint(const Vector3 &p) const;
|
||||
Vector3 closestPointOnTriangle(const Vector3 &p) const;
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class KRVector3;
|
||||
class Vector3;
|
||||
|
||||
class KRVector4 {
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
KRVector4(float v);
|
||||
KRVector4(float *v);
|
||||
KRVector4(const KRVector4 &v);
|
||||
KRVector4(const KRVector3 &v, float W);
|
||||
KRVector4(const Vector3 &v, float W);
|
||||
~KRVector4();
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "KRFloat.h"
|
||||
#include "vector2.h"
|
||||
#include "KRVector3.h"
|
||||
#include "vector3.h"
|
||||
#include "KRVector4.h"
|
||||
#include "KRMat4.h"
|
||||
#include "KRQuaternion.h"
|
||||
|
||||
116
kraken/public/vector2.h
Normal file
116
kraken/public/vector2.h
Normal file
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// vector2.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2017 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_VECTOR2_H
|
||||
#define KRAKEN_VECTOR2_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Vector2 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y;
|
||||
};
|
||||
float c[2];
|
||||
};
|
||||
|
||||
Vector2();
|
||||
Vector2(float X, float Y);
|
||||
Vector2(float v);
|
||||
Vector2(float *v);
|
||||
Vector2(const Vector2 &v);
|
||||
~Vector2();
|
||||
|
||||
// Vector2 swizzle getters
|
||||
Vector2 yx() const;
|
||||
|
||||
// Vector2 swizzle setters
|
||||
void yx(const Vector2 &v);
|
||||
|
||||
Vector2& operator =(const Vector2& b);
|
||||
Vector2 operator +(const Vector2& b) const;
|
||||
Vector2 operator -(const Vector2& b) const;
|
||||
Vector2 operator +() const;
|
||||
Vector2 operator -() const;
|
||||
Vector2 operator *(const float v) const;
|
||||
Vector2 operator /(const float v) const;
|
||||
|
||||
Vector2& operator +=(const Vector2& b);
|
||||
Vector2& operator -=(const Vector2& b);
|
||||
Vector2& operator *=(const float v);
|
||||
Vector2& operator /=(const float v);
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const Vector2& b) const;
|
||||
bool operator <(const Vector2& b) const;
|
||||
|
||||
bool operator ==(const Vector2& b) const;
|
||||
bool operator !=(const Vector2& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
float sqrMagnitude() const;
|
||||
float magnitude() const;
|
||||
|
||||
void normalize();
|
||||
static Vector2 Normalize(const Vector2 &v);
|
||||
|
||||
static float Cross(const Vector2 &v1, const Vector2 &v2);
|
||||
|
||||
static float Dot(const Vector2 &v1, const Vector2 &v2);
|
||||
static Vector2 Min();
|
||||
static Vector2 Max();
|
||||
static Vector2 Zero();
|
||||
static Vector2 One();
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Vector2> {
|
||||
public:
|
||||
size_t operator()(const kraken::Vector2 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // KRAKEN_VECTOR2_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// KRVector3.h
|
||||
// Vector3.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2017 Kearwood Gilbert. All rights reserved.
|
||||
@@ -34,11 +34,12 @@
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "Vector2.h"
|
||||
#include "KRVector4.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class KRVector3 {
|
||||
class Vector3 {
|
||||
|
||||
public:
|
||||
union {
|
||||
@@ -48,14 +49,14 @@ public:
|
||||
float c[3];
|
||||
};
|
||||
|
||||
KRVector3();
|
||||
KRVector3(float X, float Y, float Z);
|
||||
KRVector3(float v);
|
||||
KRVector3(float *v);
|
||||
KRVector3(double *v);
|
||||
KRVector3(const KRVector3 &v);
|
||||
KRVector3(const KRVector4 &v);
|
||||
~KRVector3();
|
||||
Vector3();
|
||||
Vector3(float X, float Y, float Z);
|
||||
Vector3(float v);
|
||||
Vector3(float *v);
|
||||
Vector3(double *v);
|
||||
Vector3(const Vector3 &v);
|
||||
Vector3(const KRVector4 &v);
|
||||
~Vector3();
|
||||
|
||||
// Vector2 swizzle getters
|
||||
Vector2 xx() const;
|
||||
@@ -76,26 +77,26 @@ public:
|
||||
void zx(const Vector2 &v);
|
||||
void zy(const Vector2 &v);
|
||||
|
||||
KRVector3& operator =(const KRVector3& b);
|
||||
KRVector3& operator =(const KRVector4& b);
|
||||
KRVector3 operator +(const KRVector3& b) const;
|
||||
KRVector3 operator -(const KRVector3& b) const;
|
||||
KRVector3 operator +() const;
|
||||
KRVector3 operator -() const;
|
||||
KRVector3 operator *(const float v) const;
|
||||
KRVector3 operator /(const float v) const;
|
||||
Vector3& operator =(const Vector3& b);
|
||||
Vector3& operator =(const KRVector4& b);
|
||||
Vector3 operator +(const Vector3& b) const;
|
||||
Vector3 operator -(const Vector3& b) const;
|
||||
Vector3 operator +() const;
|
||||
Vector3 operator -() const;
|
||||
Vector3 operator *(const float v) const;
|
||||
Vector3 operator /(const float v) const;
|
||||
|
||||
KRVector3& operator +=(const KRVector3& b);
|
||||
KRVector3& operator -=(const KRVector3& b);
|
||||
KRVector3& operator *=(const float v);
|
||||
KRVector3& operator /=(const float v);
|
||||
Vector3& operator +=(const Vector3& b);
|
||||
Vector3& operator -=(const Vector3& b);
|
||||
Vector3& operator *=(const float v);
|
||||
Vector3& operator /=(const float v);
|
||||
|
||||
bool operator ==(const KRVector3& b) const;
|
||||
bool operator !=(const KRVector3& b) const;
|
||||
bool operator ==(const Vector3& b) const;
|
||||
bool operator !=(const Vector3& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRVector3& b) const;
|
||||
bool operator <(const KRVector3& b) const;
|
||||
bool operator >(const Vector3& b) const;
|
||||
bool operator <(const Vector3& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
@@ -103,36 +104,36 @@ public:
|
||||
float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||
float magnitude() const;
|
||||
|
||||
void scale(const KRVector3 &v);
|
||||
void scale(const Vector3 &v);
|
||||
void normalize();
|
||||
static KRVector3 Normalize(const KRVector3 &v);
|
||||
static Vector3 Normalize(const Vector3 &v);
|
||||
|
||||
static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &v2);
|
||||
static Vector3 Cross(const Vector3 &v1, const Vector3 &v2);
|
||||
|
||||
static float Dot(const KRVector3 &v1, const KRVector3 &v2);
|
||||
static KRVector3 Min();
|
||||
static KRVector3 Max();
|
||||
static const KRVector3 &Zero();
|
||||
static KRVector3 One();
|
||||
static KRVector3 Forward();
|
||||
static KRVector3 Backward();
|
||||
static KRVector3 Up();
|
||||
static KRVector3 Down();
|
||||
static KRVector3 Left();
|
||||
static KRVector3 Right();
|
||||
static KRVector3 Scale(const KRVector3 &v1, const KRVector3 &v2);
|
||||
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
||||
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
||||
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
|
||||
static float Dot(const Vector3 &v1, const Vector3 &v2);
|
||||
static Vector3 Min();
|
||||
static Vector3 Max();
|
||||
static const Vector3 &Zero();
|
||||
static Vector3 One();
|
||||
static Vector3 Forward();
|
||||
static Vector3 Backward();
|
||||
static Vector3 Up();
|
||||
static Vector3 Down();
|
||||
static Vector3 Left();
|
||||
static Vector3 Right();
|
||||
static Vector3 Scale(const Vector3 &v1, const Vector3 &v2);
|
||||
static Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float d);
|
||||
static Vector3 Slerp(const Vector3 &v1, const Vector3 &v2, float d);
|
||||
static void OrthoNormalize(Vector3 &normal, Vector3 &tangent); // Gram-Schmidt Orthonormalization
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::KRVector3> {
|
||||
struct hash<kraken::Vector3> {
|
||||
public:
|
||||
size_t operator()(const kraken::KRVector3 &s) const
|
||||
size_t operator()(const kraken::Vector3 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
Reference in New Issue
Block a user