WIP organization of library
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// KRFloat.h
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2013-05-03.
|
||||
// Copyright (c) 2013 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef KRFLOAT_H
|
||||
#define KRFLOAT_H
|
||||
|
||||
namespace KRFloat {
|
||||
float SmoothStep(float a, float b, float t);
|
||||
};
|
||||
|
||||
#endif /* defined(KRFLOAT_H) */
|
||||
50
kraken/KRHelpers.cpp
Normal file
50
kraken/KRHelpers.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRHelpers.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
void SetUniform(GLint location, const KRVector2 &v)
|
||||
{
|
||||
if (location != -1) GLDEBUG(glUniform2f(location, v.x, v.y));
|
||||
}
|
||||
|
||||
void SetUniform(GLint location, const KRVector3 &v)
|
||||
{
|
||||
if (location != -1) GLDEBUG(glUniform3f(location, v.x, v.y, v.z));
|
||||
}
|
||||
|
||||
void SetUniform(GLint location, const KRVector4 &v)
|
||||
{
|
||||
if (location != -1) GLDEBUG(glUniform4f(location, v.x, v.y, v.z, v.w));
|
||||
}
|
||||
|
||||
void SetUniform(GLint location, const KRMat4 &v)
|
||||
{
|
||||
if (location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, v.c));
|
||||
}
|
||||
|
||||
void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &value, const KRVector3 &default_value)
|
||||
{
|
||||
// TODO - Increase number of digits after the decimal in floating point format (6 -> 12?)
|
||||
// FINDME, TODO - This needs optimization...
|
||||
if (value != default_value) {
|
||||
e->SetAttribute((base_name + "_x").c_str(), value.x);
|
||||
e->SetAttribute((base_name + "_y").c_str(), value.y);
|
||||
e->SetAttribute((base_name + "_z").c_str(), value.z);
|
||||
}
|
||||
}
|
||||
|
||||
const KRVector3 getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value)
|
||||
{
|
||||
KRVector3 value;
|
||||
if (e->QueryFloatAttribute((base_name + "_x").c_str(), &value.x) == tinyxml2::XML_SUCCESS
|
||||
&& e->QueryFloatAttribute((base_name + "_y").c_str(), &value.y) == tinyxml2::XML_SUCCESS
|
||||
&& e->QueryFloatAttribute((base_name + "_z").c_str(), &value.z) == tinyxml2::XML_SUCCESS) {
|
||||
return value;
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
29
kraken/KRHelpers.h
Normal file
29
kraken/KRHelpers.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef KRHELPERS_H
|
||||
#define KRHELPERS_H
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <GL/glew.h>
|
||||
#include "../3rdparty/tinyxml2/tinyxml2.h"
|
||||
#endif
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#define KRCLAMP(x, min, max) (KRMAX(KRMIN(x, max), min))
|
||||
#define KRALIGN(x) ((x + 3) & ~0x03)
|
||||
|
||||
float const PI = 3.141592653589793f;
|
||||
float const D2R = PI * 2 / 360;
|
||||
|
||||
namespace kraken {
|
||||
void SetUniform(GLint location, const KRVector2 &v);
|
||||
void SetUniform(GLint location, const KRVector3 &v);
|
||||
void SetUniform(GLint location, const KRVector4 &v);
|
||||
void SetUniform(GLint location, const KRMat4 &v);
|
||||
|
||||
void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const KRVector3 &value, const KRVector3 &default_value);
|
||||
const KRVector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const KRVector3 &default_value);
|
||||
} // namespace kraken
|
||||
|
||||
#endif
|
||||
@@ -29,8 +29,7 @@
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRVector4.h"
|
||||
#include "public/kraken.h"
|
||||
|
||||
const KRVector4 KRVECTOR4_ZERO(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
@@ -298,8 +297,3 @@ bool KRVector4::operator <(const KRVector4& b) const
|
||||
if(w != b.w) return w < b.w;
|
||||
return false;
|
||||
}
|
||||
|
||||
void KRVector4::setUniform(GLint location) const
|
||||
{
|
||||
if(location != -1) GLDEBUG(glUniform4f(location, x, y, z, w));
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
|
||||
#define KRENGINE_SWAP_INT(x,y) {int t;t=x;x=y;y=t;}
|
||||
|
||||
#include "KRVector2.h"
|
||||
#include "KRMat4.h"
|
||||
#include "KRViewport.h"
|
||||
#include "KRLight.h"
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRViewport.h"
|
||||
|
||||
KRViewport::KRViewport()
|
||||
{
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
#define KRENGINE_KRVIEWPORT_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRVector2.h"
|
||||
#include "KRMat4.h"
|
||||
#include "KRAABB.h"
|
||||
|
||||
class KRLight;
|
||||
|
||||
|
||||
4
kraken/KRAABB.h → kraken/public/KRAABB.h
Executable file → Normal file
4
kraken/KRAABB.h → kraken/public/KRAABB.h
Executable file → Normal file
@@ -11,10 +11,12 @@
|
||||
#ifndef KRAABB_H
|
||||
#define KRAABB_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "KRVector2.h"
|
||||
#include "KRVector3.h"
|
||||
|
||||
class KRMat4;
|
||||
class KRVector2;
|
||||
|
||||
class KRAABB {
|
||||
public:
|
||||
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) */
|
||||
29
kraken/KRMat4.h → kraken/public/KRMat4.h
Executable file → Normal file
29
kraken/KRMat4.h → kraken/public/KRMat4.h
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRMat4.h
|
||||
// KREngine
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -33,21 +33,8 @@
|
||||
#include "KRVector3.h"
|
||||
#include "KRVector4.h"
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#ifndef KRMAT4_I
|
||||
#define KRMAT4_I
|
||||
|
||||
|
||||
#define EMPTY_MATRIX4 { 0.0, 0.0, 0.0, 0.0,\
|
||||
0.0, 0.0, 0.0, 0.0,\
|
||||
0.0, 0.0, 0.0, 0.0,\
|
||||
0.0, 0.0, 0.0, 0.0 }
|
||||
|
||||
#define IDENTITY_MATRIX4 { 1.0, 0.0, 0.0, 0.0,\
|
||||
0.0, 1.0, 0.0, 0.0,\
|
||||
0.0, 0.0, 1.0, 0.0,\
|
||||
0.0, 0.0, 0.0, 1.0 }
|
||||
#ifndef KRMAT4_H
|
||||
#define KRMAT4_H
|
||||
|
||||
typedef enum {
|
||||
X_AXIS,
|
||||
@@ -58,14 +45,10 @@ typedef enum {
|
||||
class KRQuaternion;
|
||||
|
||||
class KRMat4 {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
float c[16]; // Matrix components, in column-major order
|
||||
|
||||
|
||||
|
||||
// Default constructor - Creates an identity matrix
|
||||
KRMat4();
|
||||
|
||||
@@ -123,8 +106,6 @@ class KRMat4 {
|
||||
static KRMat4 Translation(const KRVector3 &v);
|
||||
static KRMat4 Rotation(const KRVector3 &v);
|
||||
static KRMat4 Scaling(const KRVector3 &v);
|
||||
|
||||
void setUniform(GLint location) const;
|
||||
};
|
||||
|
||||
#endif // KRMAT4_I
|
||||
#endif // KRMAT4_H
|
||||
10
kraken/KRTriangle3.h → kraken/public/KRTriangle3.h
Executable file → Normal file
10
kraken/KRTriangle3.h → kraken/public/KRTriangle3.h
Executable file → Normal file
@@ -37,6 +37,8 @@
|
||||
class KRTriangle3
|
||||
{
|
||||
public:
|
||||
KRVector3 vert[3];
|
||||
|
||||
KRTriangle3(const KRTriangle3 &tri);
|
||||
KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3);
|
||||
~KRTriangle3();
|
||||
@@ -46,18 +48,14 @@ public:
|
||||
bool operator ==(const KRTriangle3& b) const;
|
||||
bool operator !=(const KRTriangle3& b) const;
|
||||
KRTriangle3& operator =(const KRTriangle3& b);
|
||||
KRVector3& operator[](unsigned i);
|
||||
KRVector3 operator[](unsigned i) const;
|
||||
|
||||
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;
|
||||
private:
|
||||
|
||||
KRVector3 m_c[3];
|
||||
};
|
||||
|
||||
#endif // KRTRIANGLE3_H
|
||||
12
kraken/KRVector2.h → kraken/public/KRVector2.h
Executable file → Normal file
12
kraken/KRVector2.h → kraken/public/KRVector2.h
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRVector2.h
|
||||
// KREngine
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef KRVECTOR2
|
||||
#define KRVECTOR2
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector2 {
|
||||
|
||||
@@ -93,12 +93,6 @@ public:
|
||||
static KRVector2 Max();
|
||||
static KRVector2 Zero();
|
||||
static KRVector2 One();
|
||||
|
||||
void setUniform(GLint location) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
namespace std {
|
||||
21
kraken/KRVector3.h → kraken/public/KRVector3.h
Executable file → Normal file
21
kraken/KRVector3.h → kraken/public/KRVector3.h
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRVector3.h
|
||||
// KREngine
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -29,10 +29,10 @@
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#ifndef KRVECTOR3
|
||||
#define KRVECTOR3
|
||||
#ifndef KRVECTOR3_H
|
||||
#define KRVECTOR3_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector2;
|
||||
class KRVector4;
|
||||
@@ -48,13 +48,13 @@ public:
|
||||
};
|
||||
|
||||
KRVector3();
|
||||
KRVector3(float X, float Y, float Z);
|
||||
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();
|
||||
~KRVector3();
|
||||
|
||||
// KRVector2 swizzle getters
|
||||
KRVector2 xx() const;
|
||||
@@ -123,11 +123,6 @@ public:
|
||||
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
|
||||
|
||||
void setUniform(GLint location) const;
|
||||
|
||||
void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value);
|
||||
void getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value);
|
||||
};
|
||||
|
||||
namespace std {
|
||||
@@ -144,4 +139,4 @@ namespace std {
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KRVECTOR3_H
|
||||
15
kraken/KRVector4.h → kraken/public/KRVector4.h
Executable file → Normal file
15
kraken/KRVector4.h → kraken/public/KRVector4.h
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRVector4.h
|
||||
// KREngine
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -32,7 +32,7 @@
|
||||
#ifndef KRVECTOR4_H
|
||||
#define KRVECTOR4_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include <functional> // for hash<>
|
||||
|
||||
class KRVector3;
|
||||
|
||||
@@ -47,12 +47,12 @@ public:
|
||||
};
|
||||
|
||||
KRVector4();
|
||||
KRVector4(float X, float Y, float Z, float W);
|
||||
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();
|
||||
|
||||
|
||||
KRVector4& operator =(const KRVector4& b);
|
||||
@@ -83,7 +83,6 @@ public:
|
||||
|
||||
void normalize();
|
||||
static KRVector4 Normalize(const KRVector4 &v);
|
||||
|
||||
|
||||
static float Dot(const KRVector4 &v1, const KRVector4 &v2);
|
||||
static KRVector4 Min();
|
||||
@@ -99,8 +98,6 @@ public:
|
||||
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
|
||||
|
||||
void setUniform(GLint location) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
#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