WIP organization of library
This commit is contained in:
75
kraken/public/KRAABB.h
Normal file
75
kraken/public/KRAABB.h
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// KRAABB.h
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2012-08-30.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
// Axis aligned bounding box
|
||||
|
||||
#ifndef KRAABB_H
|
||||
#define KRAABB_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "KRVector2.h"
|
||||
#include "KRVector3.h"
|
||||
|
||||
class KRMat4;
|
||||
|
||||
class KRAABB {
|
||||
public:
|
||||
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint);
|
||||
KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix);
|
||||
KRAABB();
|
||||
~KRAABB();
|
||||
|
||||
void scale(const KRVector3 &s);
|
||||
void scale(float s);
|
||||
|
||||
KRVector3 center() const;
|
||||
KRVector3 size() const;
|
||||
float volume() const;
|
||||
bool intersects(const KRAABB& b) const;
|
||||
bool contains(const KRAABB &b) const;
|
||||
bool contains(const KRVector3 &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;
|
||||
void encapsulate(const KRAABB & b);
|
||||
|
||||
KRAABB& operator =(const KRAABB& b);
|
||||
bool operator ==(const KRAABB& b) const;
|
||||
bool operator !=(const KRAABB& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRAABB& b) const;
|
||||
bool operator <(const KRAABB& b) const;
|
||||
|
||||
KRVector3 min;
|
||||
KRVector3 max;
|
||||
|
||||
static KRAABB Infinite();
|
||||
static KRAABB Zero();
|
||||
|
||||
float longest_radius() const;
|
||||
KRVector3 nearestPoint(const KRVector3 & v) const;
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<KRAABB> {
|
||||
public:
|
||||
size_t operator()(const KRAABB &s) const
|
||||
{
|
||||
size_t h1 = hash<KRVector3>()(s.min);
|
||||
size_t h2 = hash<KRVector3>()(s.max);
|
||||
return h1 ^ ( h2 << 1 );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* defined(KRAABB_H) */
|
||||
39
kraken/public/KRFloat.h
Normal file
39
kraken/public/KRFloat.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// KRFloat.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 KRFLOAT_H
|
||||
#define KRFLOAT_H
|
||||
|
||||
namespace KRFloat {
|
||||
float SmoothStep(float a, float b, float t);
|
||||
};
|
||||
|
||||
#endif /* defined(KRFLOAT_H) */
|
||||
111
kraken/public/KRMat4.h
Normal file
111
kraken/public/KRMat4.h
Normal file
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// KRMat4.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.
|
||||
//
|
||||
|
||||
|
||||
#include "KRVector3.h"
|
||||
#include "KRVector4.h"
|
||||
|
||||
#ifndef KRMAT4_H
|
||||
#define KRMAT4_H
|
||||
|
||||
typedef enum {
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
} AXIS;
|
||||
|
||||
class KRQuaternion;
|
||||
|
||||
class KRMat4 {
|
||||
public:
|
||||
|
||||
float c[16]; // Matrix components, in column-major order
|
||||
|
||||
// Default constructor - Creates an identity matrix
|
||||
KRMat4();
|
||||
|
||||
KRMat4(float *pMat);
|
||||
|
||||
KRMat4(const KRVector3 &axis_x, const KRVector3 &axis_y, const KRVector3 &axis_z, const KRVector3 &trans);
|
||||
|
||||
// Destructor
|
||||
~KRMat4();
|
||||
|
||||
// Copy constructor
|
||||
KRMat4(const KRMat4 &m);
|
||||
|
||||
// Overload assignment operator
|
||||
KRMat4& operator=(const KRMat4 &m);
|
||||
|
||||
// Overload comparison operator
|
||||
bool operator==(const KRMat4 &m) const;
|
||||
|
||||
// Overload compound multiply operator
|
||||
KRMat4& operator*=(const KRMat4 &m);
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
// Overload multiply operator
|
||||
//KRMat4& operator*(const KRMat4 &m);
|
||||
KRMat4 operator*(const KRMat4 &m) const;
|
||||
|
||||
float *getPointer();
|
||||
|
||||
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 scale(float x, float y, float z);
|
||||
void scale(const KRVector3 &v);
|
||||
void scale(float s);
|
||||
void rotate(float angle, AXIS axis);
|
||||
void rotate(const KRQuaternion &q);
|
||||
void bias();
|
||||
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 KRMat4 Invert(const KRMat4 &m);
|
||||
static KRMat4 Transpose(const KRMat4 &m);
|
||||
static KRVector3 Dot(const KRMat4 &m, const KRVector3 &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 KRMat4 LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, const KRVector3 &upDirection);
|
||||
|
||||
static KRMat4 Translation(const KRVector3 &v);
|
||||
static KRMat4 Rotation(const KRVector3 &v);
|
||||
static KRMat4 Scaling(const KRVector3 &v);
|
||||
};
|
||||
|
||||
#endif // KRMAT4_H
|
||||
61
kraken/public/KRTriangle3.h
Normal file
61
kraken/public/KRTriangle3.h
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// KRTriangle.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 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 KRTRIANGLE3_H
|
||||
#define KRTRIANGLE3_H
|
||||
|
||||
#include "KRVector3.h"
|
||||
|
||||
class KRTriangle3
|
||||
{
|
||||
public:
|
||||
KRVector3 vert[3];
|
||||
|
||||
KRTriangle3(const KRTriangle3 &tri);
|
||||
KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3);
|
||||
~KRTriangle3();
|
||||
|
||||
KRVector3 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;
|
||||
|
||||
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 containsPoint(const KRVector3 &p) const;
|
||||
KRVector3 closestPointOnTriangle(const KRVector3 &p) const;
|
||||
};
|
||||
|
||||
#endif // KRTRIANGLE3_H
|
||||
112
kraken/public/KRVector2.h
Normal file
112
kraken/public/KRVector2.h
Normal file
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// KRVector2.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 KRVECTOR2
|
||||
#define KRVECTOR2
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector2 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y;
|
||||
};
|
||||
float c[2];
|
||||
};
|
||||
|
||||
KRVector2();
|
||||
KRVector2(float X, float Y);
|
||||
KRVector2(float v);
|
||||
KRVector2(float *v);
|
||||
KRVector2(const KRVector2 &v);
|
||||
~KRVector2();
|
||||
|
||||
// KRVector2 swizzle getters
|
||||
KRVector2 yx() const;
|
||||
|
||||
// KRVector2 swizzle setters
|
||||
void yx(const KRVector2 &v);
|
||||
|
||||
KRVector2& operator =(const KRVector2& b);
|
||||
KRVector2 operator +(const KRVector2& b) const;
|
||||
KRVector2 operator -(const KRVector2& b) const;
|
||||
KRVector2 operator +() const;
|
||||
KRVector2 operator -() const;
|
||||
KRVector2 operator *(const float v) const;
|
||||
KRVector2 operator /(const float v) const;
|
||||
|
||||
KRVector2& operator +=(const KRVector2& b);
|
||||
KRVector2& operator -=(const KRVector2& b);
|
||||
KRVector2& operator *=(const float v);
|
||||
KRVector2& operator /=(const float v);
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRVector2& b) const;
|
||||
bool operator <(const KRVector2& b) const;
|
||||
|
||||
bool operator ==(const KRVector2& b) const;
|
||||
bool operator !=(const KRVector2& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
float sqrMagnitude() const;
|
||||
float magnitude() const;
|
||||
|
||||
void normalize();
|
||||
static KRVector2 Normalize(const KRVector2 &v);
|
||||
|
||||
static float Cross(const KRVector2 &v1, const KRVector2 &v2);
|
||||
|
||||
static float Dot(const KRVector2 &v1, const KRVector2 &v2);
|
||||
static KRVector2 Min();
|
||||
static KRVector2 Max();
|
||||
static KRVector2 Zero();
|
||||
static KRVector2 One();
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<KRVector2> {
|
||||
public:
|
||||
size_t operator()(const KRVector2 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
return h1 ^ ( h2 << 1 );
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
142
kraken/public/KRVector3.h
Normal file
142
kraken/public/KRVector3.h
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// KRVector3.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 KRVECTOR3_H
|
||||
#define KRVECTOR3_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector2;
|
||||
class KRVector4;
|
||||
|
||||
class KRVector3 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y, z;
|
||||
};
|
||||
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();
|
||||
|
||||
// KRVector2 swizzle getters
|
||||
KRVector2 xx() const;
|
||||
KRVector2 xy() const;
|
||||
KRVector2 xz() const;
|
||||
KRVector2 yx() const;
|
||||
KRVector2 yy() const;
|
||||
KRVector2 yz() const;
|
||||
KRVector2 zx() const;
|
||||
KRVector2 zy() const;
|
||||
KRVector2 zz() const;
|
||||
|
||||
// KRVector2 swizzle setters
|
||||
void xy(const KRVector2 &v);
|
||||
void xz(const KRVector2 &v);
|
||||
void yx(const KRVector2 &v);
|
||||
void yz(const KRVector2 &v);
|
||||
void zx(const KRVector2 &v);
|
||||
void zy(const KRVector2 &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;
|
||||
|
||||
KRVector3& operator +=(const KRVector3& b);
|
||||
KRVector3& operator -=(const KRVector3& b);
|
||||
KRVector3& operator *=(const float v);
|
||||
KRVector3& operator /=(const float v);
|
||||
|
||||
bool operator ==(const KRVector3& b) const;
|
||||
bool operator !=(const KRVector3& 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;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
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 normalize();
|
||||
static KRVector3 Normalize(const KRVector3 &v);
|
||||
|
||||
static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &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
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<KRVector3> {
|
||||
public:
|
||||
size_t operator()(const KRVector3 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
size_t h3 = hash<float>()(s.z);
|
||||
return h1 ^ ( h2 << 1 ) ^ (h3 << 2);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif // KRVECTOR3_H
|
||||
103
kraken/public/KRVector4.h
Normal file
103
kraken/public/KRVector4.h
Normal file
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// KRVector4.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 KRVECTOR4_H
|
||||
#define KRVECTOR4_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector3;
|
||||
|
||||
class KRVector4 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y, z, w;
|
||||
};
|
||||
float c[4];
|
||||
};
|
||||
|
||||
KRVector4();
|
||||
KRVector4(float X, float Y, float Z, float W);
|
||||
KRVector4(float v);
|
||||
KRVector4(float *v);
|
||||
KRVector4(const KRVector4 &v);
|
||||
KRVector4(const KRVector3 &v, float W);
|
||||
~KRVector4();
|
||||
|
||||
|
||||
KRVector4& operator =(const KRVector4& b);
|
||||
KRVector4 operator +(const KRVector4& b) const;
|
||||
KRVector4 operator -(const KRVector4& b) const;
|
||||
KRVector4 operator +() const;
|
||||
KRVector4 operator -() const;
|
||||
KRVector4 operator *(const float v) const;
|
||||
KRVector4 operator /(const float v) const;
|
||||
|
||||
KRVector4& operator +=(const KRVector4& b);
|
||||
KRVector4& operator -=(const KRVector4& b);
|
||||
KRVector4& operator *=(const float v);
|
||||
KRVector4& operator /=(const float v);
|
||||
|
||||
bool operator ==(const KRVector4& b) const;
|
||||
bool operator !=(const KRVector4& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRVector4& b) const;
|
||||
bool operator <(const KRVector4& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
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 normalize();
|
||||
static KRVector4 Normalize(const KRVector4 &v);
|
||||
|
||||
static float Dot(const KRVector4 &v1, const KRVector4 &v2);
|
||||
static KRVector4 Min();
|
||||
static KRVector4 Max();
|
||||
static const KRVector4 &Zero();
|
||||
static KRVector4 One();
|
||||
static KRVector4 Forward();
|
||||
static KRVector4 Backward();
|
||||
static KRVector4 Up();
|
||||
static KRVector4 Down();
|
||||
static KRVector4 Left();
|
||||
static KRVector4 Right();
|
||||
static KRVector4 Lerp(const KRVector4 &v1, const KRVector4 &v2, float d);
|
||||
static KRVector4 Slerp(const KRVector4 &v1, const KRVector4 &v2, float d);
|
||||
static void OrthoNormalize(KRVector4 &normal, KRVector4 &tangent); // Gram-Schmidt Orthonormalization
|
||||
};
|
||||
|
||||
#endif // KRVECTOR4_H
|
||||
12
kraken/public/kraken.h
Normal file
12
kraken/public/kraken.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef KRAKEN_H
|
||||
#define KRAKEN_H
|
||||
|
||||
#include "KRFloat.h"
|
||||
#include "KRVector2.h"
|
||||
#include "KRVector3.h"
|
||||
#include "KRVector4.h"
|
||||
#include "KRMat4.h"
|
||||
#include "KRAABB.h"
|
||||
#include "KRTriangle3.h"
|
||||
|
||||
#endif // KRAKEN_H
|
||||
Reference in New Issue
Block a user