diff --git a/kraken/KRAABB.cpp b/kraken/KRAABB.cpp index 97c2a8f..b4df08f 100755 --- a/kraken/KRAABB.cpp +++ b/kraken/KRAABB.cpp @@ -6,10 +6,9 @@ // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#include "KRAABB.h" -#include "KRMat4.h" -#include "KRVector2.h" +#include "public/kraken.h" #include "assert.h" +#include "KRHelpers.h" KRAABB::KRAABB() { diff --git a/kraken/KRAudioManager.cpp b/kraken/KRAudioManager.cpp index f6e1560..bcc0ff0 100755 --- a/kraken/KRAudioManager.cpp +++ b/kraken/KRAudioManager.cpp @@ -35,7 +35,6 @@ #include "KRDataBlock.h" #include "KRAudioBuffer.h" #include "KRContext.h" -#include "KRVector2.h" #include "KRCollider.h" #include "KRDSP.h" diff --git a/kraken/KRAudioManager.h b/kraken/KRAudioManager.h index ba4fd96..9bc2190 100755 --- a/kraken/KRAudioManager.h +++ b/kraken/KRAudioManager.h @@ -36,7 +36,6 @@ #include "KRContextObject.h" #include "KRDataBlock.h" -#include "KRMat4.h" #include "KRAudioSource.h" #include "KRDSP.h" diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 1b739da..2e5855c 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -30,7 +30,6 @@ // #include "KREngine-common.h" -#include "KRVector2.h" #include "KRCamera.h" #include "KRStockGeometry.h" #include "KRDirectionalLight.h" diff --git a/kraken/KRCamera.h b/kraken/KRCamera.h index 7a0060a..0bf987e 100755 --- a/kraken/KRCamera.h +++ b/kraken/KRCamera.h @@ -34,9 +34,6 @@ #include "KREngine-common.h" -#include "KRMat4.h" -#include "KRVector2.h" -#include "KRAABB.h" #include "KRShader.h" #include "KRContextObject.h" #include "KRTexture.h" diff --git a/kraken/KRCollider.cpp b/kraken/KRCollider.cpp index 348e00a..56c0c1a 100755 --- a/kraken/KRCollider.cpp +++ b/kraken/KRCollider.cpp @@ -33,7 +33,6 @@ #include "KRCollider.h" #include "KRContext.h" #include "KRMesh.h" -#include "KRQuaternion.h" KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string model_name, unsigned int layer_mask, float audio_occlusion) : KRNode(scene, collider_name) { diff --git a/kraken/KRCollider.h b/kraken/KRCollider.h index cbf106b..25dc740 100755 --- a/kraken/KRCollider.h +++ b/kraken/KRCollider.h @@ -38,8 +38,6 @@ #define KRAKEN_COLLIDER_AUDIO 2 #include "KRMesh.h" -#include "KRMat4.h" -#include "KRVector3.h" #include "KRModel.h" #include "KRCamera.h" #include "KRMeshManager.h" diff --git a/kraken/KRDirectionalLight.cpp b/kraken/KRDirectionalLight.cpp index 647e84a..b4ee8fd 100755 --- a/kraken/KRDirectionalLight.cpp +++ b/kraken/KRDirectionalLight.cpp @@ -11,8 +11,6 @@ #include "KRDirectionalLight.h" #include "KRShader.h" #include "KRContext.h" -#include "KRMat4.h" -#include "KRQuaternion.h" #include "assert.h" #include "KRStockGeometry.h" diff --git a/kraken/KRDirectionalLight.h b/kraken/KRDirectionalLight.h index 037c9d5..4c99365 100755 --- a/kraken/KRDirectionalLight.h +++ b/kraken/KRDirectionalLight.h @@ -10,7 +10,6 @@ #define KREngine_KRDirectionalLight_h #include "KRLight.h" -#include "KRMat4.h" class KRDirectionalLight : public KRLight { diff --git a/kraken/KREngine-common.h b/kraken/KREngine-common.h index 446ae35..76954a6 100755 --- a/kraken/KREngine-common.h +++ b/kraken/KREngine-common.h @@ -11,9 +11,8 @@ #ifndef KRENGINE_COMMON_H #define KRENGINE_COMMON_H -float const PI = 3.141592653589793f; -float const D2R = PI * 2 / 360; - +#include "public/kraken.h" +#include "KRHelpers.h" #include #include @@ -224,20 +223,14 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n" #endif -#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) - typedef enum { STREAM_LEVEL_OUT, STREAM_LEVEL_IN_LQ, STREAM_LEVEL_IN_HQ } kraken_stream_level; -#include "KRVector4.h" -#include "KRVector3.h" -#include "KRVector2.h" #include "KRBehavior.h" #endif + +using namespace kraken; diff --git a/kraken/KRFloat.cpp b/kraken/KRFloat.cpp index cc72083..bb5317d 100755 --- a/kraken/KRFloat.cpp +++ b/kraken/KRFloat.cpp @@ -6,10 +6,10 @@ // Copyright (c) 2013 Kearwood Software. All rights reserved. // -#include "KRFloat.h" +#include "public\kraken.h" -float KRFloat::SmoothStep(float a, float b, float t) +float kraken::SmoothStep(float a, float b, float t) { float d = (3.0 * t * t - 2.0 * t * t * t); return a * (1.0f - d) + b * d; -} \ No newline at end of file +} diff --git a/kraken/KRHitInfo.h b/kraken/KRHitInfo.h index e02feed..e2242dd 100755 --- a/kraken/KRHitInfo.h +++ b/kraken/KRHitInfo.h @@ -32,7 +32,9 @@ #ifndef KRHITINFO_H #define KRHITINFO_H -#include "KRVector3.h" +#include "public/kraken.h" + +using namespace kraken; class KRNode; @@ -51,7 +53,6 @@ public: KRHitInfo& operator =(const KRHitInfo& b); - private: KRNode *m_node; KRVector3 m_position; diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index bdc85e9..302e580 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -11,8 +11,6 @@ #include "KRLight.h" #include "KRNode.h" -#include "KRMat4.h" -#include "KRVector3.h" #include "KRCamera.h" #include "KRContext.h" diff --git a/kraken/KRMat4.cpp b/kraken/KRMat4.cpp index 6e686c0..708c62e 100755 --- a/kraken/KRMat4.cpp +++ b/kraken/KRMat4.cpp @@ -31,8 +31,7 @@ #include "KREngine-common.h" -#include "KRMat4.h" -#include "KRQuaternion.h" +#include "public/KRMat4.h" KRMat4::KRMat4() { // Default constructor - Initialize with an identity matrix @@ -418,11 +417,6 @@ KRMat4 KRMat4::Transpose(const KRMat4 &m) return matTranspose; } -void KRMat4::setUniform(GLint location) const -{ - if(location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, c)); -} - KRMat4 KRMat4::Translation(const KRVector3 &v) { KRMat4 m; diff --git a/kraken/KRMaterial.h b/kraken/KRMaterial.h index d15a2a6..68045ce 100755 --- a/kraken/KRMaterial.h +++ b/kraken/KRMaterial.h @@ -36,8 +36,6 @@ #include "KRShader.h" #include "KRCamera.h" #include "KRResource.h" -#include "KRVector2.h" -#include "KRVector3.h" #include "KRScene.h" #include "KRBone.h" diff --git a/kraken/KRMesh.cpp b/kraken/KRMesh.cpp index a87737f..057087f 100755 --- a/kraken/KRMesh.cpp +++ b/kraken/KRMesh.cpp @@ -34,8 +34,6 @@ #include "KRMesh.h" -#include "KRVector3.h" -#include "KRTriangle3.h" #include "KRShader.h" #include "KRShaderManager.h" #include "KRContext.h" diff --git a/kraken/KRMesh.h b/kraken/KRMesh.h index eb4b58a..814c4d8 100755 --- a/kraken/KRMesh.h +++ b/kraken/KRMesh.h @@ -30,14 +30,14 @@ // #include "KREngine-common.h" -#include "KRVector2.h" -#include "KRMat4.h" #include "KRContext.h" #include "KRBone.h" #include "KRMeshManager.h" #include "KREngine-common.h" +using namespace kraken; + #define MAX_VBO_SIZE 65535 #define KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX 4 #define KRENGINE_MAX_NAME_LENGTH 256 @@ -55,8 +55,6 @@ class KRMaterial; class KRNode; -class KRTriangle3; - class KRMesh : public KRResource { diff --git a/kraken/KRModel.cpp b/kraken/KRModel.cpp index eca9f20..1e524fd 100755 --- a/kraken/KRModel.cpp +++ b/kraken/KRModel.cpp @@ -34,7 +34,6 @@ #include "KRModel.h" #include "KRContext.h" #include "KRMesh.h" -#include "KRQuaternion.h" KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, KRVector3 rim_color, float rim_power) : KRNode(scene, instance_name) { m_lightMap = light_map; @@ -80,7 +79,7 @@ tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent) e->SetAttribute("lod_min_coverage", m_min_lod_coverage); e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); - m_rim_color.setXMLAttribute("rim_color", e, KRVector3::Zero()); + kraken::setXMLAttribute("rim_color", e, m_rim_color, KRVector3::Zero()); e->SetAttribute("rim_power", m_rim_power); return e; } diff --git a/kraken/KRModel.h b/kraken/KRModel.h index 95e1ee3..03ce05b 100755 --- a/kraken/KRModel.h +++ b/kraken/KRModel.h @@ -29,16 +29,12 @@ // or implied, of Kearwood Gilbert. // - - #include "KREngine-common.h" #ifndef KRMODEL_H #define KRMODEL_H #include "KRMesh.h" -#include "KRMat4.h" -#include "KRVector3.h" #include "KRModel.h" #include "KRCamera.h" #include "KRMeshManager.h" diff --git a/kraken/KRNode.cpp b/kraken/KRNode.cpp index e78992f..a78c30f 100755 --- a/kraken/KRNode.cpp +++ b/kraken/KRNode.cpp @@ -18,8 +18,6 @@ #include "KRCollider.h" #include "KRParticleSystem.h" #include "KRParticleSystemNewtonian.h" -#include "KRAABB.h" -#include "KRQuaternion.h" #include "KRBone.h" #include "KRLocator.h" #include "KRAudioSource.h" @@ -125,17 +123,15 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { tinyxml2::XMLElement *e = doc->NewElement(getElementName().c_str()); tinyxml2::XMLNode *n = parent->InsertEndChild(e); e->SetAttribute("name", m_name.c_str()); - m_localTranslation.setXMLAttribute("translate", e, KRVector3::Zero()); - m_localScale.setXMLAttribute("scale", e, KRVector3::One()); - (m_localRotation * (180.0f / M_PI)).setXMLAttribute("rotate", e, KRVector3::Zero()); - - - m_rotationOffset.setXMLAttribute("rotate_offset", e, KRVector3::Zero()); - m_scalingOffset.setXMLAttribute("scale_offset", e, KRVector3::Zero()); - m_rotationPivot.setXMLAttribute("rotate_pivot", e, KRVector3::Zero()); - m_scalingPivot.setXMLAttribute("scale_pivot", e, KRVector3::Zero()); - (m_preRotation * (180.0f / M_PI)).setXMLAttribute("pre_rotate", e, KRVector3::Zero()); - (m_postRotation * (180.0f / M_PI)).setXMLAttribute("post_rotate", e, KRVector3::Zero()); + kraken::setXMLAttribute("translate", e, m_localTranslation, KRVector3::Zero()); + kraken::setXMLAttribute("scale", e, m_localScale, KRVector3::One()); + kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / M_PI)), KRVector3::Zero()); + kraken::setXMLAttribute("rotate_offset", e, m_rotationOffset, KRVector3::Zero()); + kraken::setXMLAttribute("scale_offset", e, m_scalingOffset, KRVector3::Zero()); + kraken::setXMLAttribute("rotate_pivot", e, m_rotationPivot, KRVector3::Zero()); + kraken::setXMLAttribute("scale_pivot", e, m_scalingPivot, KRVector3::Zero()); + kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / M_PI)), KRVector3::Zero()); + kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / M_PI)), KRVector3::Zero()); for(std::set::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) { KRNode *child = (*itr); @@ -146,21 +142,19 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { void KRNode::loadXML(tinyxml2::XMLElement *e) { m_name = e->Attribute("name"); - m_localTranslation.getXMLAttribute("translate", e, KRVector3::Zero()); - m_localScale.getXMLAttribute("scale", e, KRVector3::One()); - m_localRotation.getXMLAttribute("rotate", e, KRVector3::Zero()); + m_localTranslation = kraken::getXMLAttribute("translate", e, KRVector3::Zero()); + m_localScale = kraken::getXMLAttribute("scale", e, KRVector3::One()); + m_localRotation = kraken::getXMLAttribute("rotate", e, KRVector3::Zero()); m_localRotation *= M_PI / 180.0f; // Convert degrees to radians - m_preRotation.getXMLAttribute("pre_rotate", e, KRVector3::Zero()); + m_preRotation = kraken::getXMLAttribute("pre_rotate", e, KRVector3::Zero()); m_preRotation *= M_PI / 180.0f; // Convert degrees to radians - m_postRotation.getXMLAttribute("post_rotate", e, KRVector3::Zero()); + m_postRotation = kraken::getXMLAttribute("post_rotate", e, KRVector3::Zero()); m_postRotation *= M_PI / 180.0f; // Convert degrees to radians - - m_rotationOffset.getXMLAttribute("rotate_offset", e, KRVector3::Zero()); - m_scalingOffset.getXMLAttribute("scale_offset", e, KRVector3::Zero()); - m_rotationPivot.getXMLAttribute("rotate_pivot", e, KRVector3::Zero()); - m_scalingPivot.getXMLAttribute("scale_pivot", e, KRVector3::Zero()); - + m_rotationOffset = kraken::getXMLAttribute("rotate_offset", e, KRVector3::Zero()); + m_scalingOffset = kraken::getXMLAttribute("scale_offset", e, KRVector3::Zero()); + m_rotationPivot = kraken::getXMLAttribute("rotate_pivot", e, KRVector3::Zero()); + m_scalingPivot = kraken::getXMLAttribute("scale_pivot", e, KRVector3::Zero()); m_initialLocalTranslation = m_localTranslation; m_initialLocalScale = m_localScale; @@ -434,7 +428,7 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { rim_power = 0.0f; } KRVector3 rim_color = KRVector3::Zero(); - rim_color.getXMLAttribute("rim_color", e, KRVector3::Zero()); + rim_color = kraken::getXMLAttribute("rim_color", e, KRVector3::Zero()); new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera, rim_color, rim_power); } else if(strcmp(szElementName, "collider") == 0) { new_node = new KRCollider(scene, szName, e->Attribute("mesh"), 65535, 1.0f); diff --git a/kraken/KRNode.h b/kraken/KRNode.h index 9ff6287..e29c5b4 100755 --- a/kraken/KRNode.h +++ b/kraken/KRNode.h @@ -10,20 +10,24 @@ #define KRNODE_H #include "KRResource.h" -#include "KRVector3.h" #include "KRViewport.h" #include "KROctreeNode.h" #include "KRBehavior.h" +using namespace kraken; + +namespace kraken { +class KRMat4; +class KRAABB; +} // namespace kraken class KRCamera; class KRShaderManager; class KRMeshManager; class KRMaterialManager; -class KRMat4; class KRTextureManager; class KRContext; class KRScene; -class KRAABB; + class KRNode; class KRPointLight; class KRSpotLight; diff --git a/kraken/KROctree.h b/kraken/KROctree.h index 7e7edff..3374f47 100755 --- a/kraken/KROctree.h +++ b/kraken/KROctree.h @@ -11,7 +11,6 @@ #include "KREngine-common.h" #include "KROctreeNode.h" -#include "KRMat4.h" #include "KRHitInfo.h" class KRNode; diff --git a/kraken/KROctreeNode.h b/kraken/KROctreeNode.h index 84eb549..eb1fe8a 100755 --- a/kraken/KROctreeNode.h +++ b/kraken/KROctreeNode.h @@ -10,8 +10,6 @@ #define KROCTREENODE_H #include "KREngine-common.h" -#include "KRVector3.h" -#include "KRAABB.h" #include "KRHitInfo.h" class KRNode; diff --git a/kraken/KRParticleSystemNewtonian.cpp b/kraken/KRParticleSystemNewtonian.cpp index cc8ed83..3dc6d86 100755 --- a/kraken/KRParticleSystemNewtonian.cpp +++ b/kraken/KRParticleSystemNewtonian.cpp @@ -6,8 +6,9 @@ // Copyright (c) 2012 Kearwood Software. All rights reserved. // + +#include "KREngine-common.h" #include "KRParticleSystemNewtonian.h" -#include "KRAABB.h" #include "KRTexture.h" #include "KRContext.h" diff --git a/kraken/KRPointLight.cpp b/kraken/KRPointLight.cpp index ab8087c..d809482 100755 --- a/kraken/KRPointLight.cpp +++ b/kraken/KRPointLight.cpp @@ -9,8 +9,6 @@ #include "KREngine-common.h" #include "KRPointLight.h" -#include "KRMat4.h" -#include "KRVector3.h" #include "KRCamera.h" #include "KRContext.h" #include "KRStockGeometry.h" diff --git a/kraken/KRPointLight.h b/kraken/KRPointLight.h index f3ff0ec..395a32d 100755 --- a/kraken/KRPointLight.h +++ b/kraken/KRPointLight.h @@ -10,7 +10,6 @@ #define KRPOINTLIGHT_H #include "KRLight.h" -#include "KRMat4.h" class KRPointLight : public KRLight { diff --git a/kraken/KRQuaternion.cpp b/kraken/KRQuaternion.cpp index c6eabf8..9eece12 100755 --- a/kraken/KRQuaternion.cpp +++ b/kraken/KRQuaternion.cpp @@ -29,8 +29,11 @@ // or implied, of Kearwood Gilbert. // -#include "KRQuaternion.h" -#include "KRVector3.h" +#include "public/kraken.h" + +#include "KRHelpers.h" + +namespace kraken { KRQuaternion::KRQuaternion() { m_val[0] = 1.0; @@ -358,3 +361,5 @@ KRQuaternion KRQuaternion::Slerp(const KRQuaternion &a, const KRQuaternion &b, f return (c * sin((1.0f - t) * halftheta) + b * sin(t * halftheta)) / sin(halftheta); } + +} // namespace kraken diff --git a/kraken/KRResource+fbx.cpp b/kraken/KRResource+fbx.cpp index d84192f..8e77c6f 100755 --- a/kraken/KRResource+fbx.cpp +++ b/kraken/KRResource+fbx.cpp @@ -22,7 +22,6 @@ #include "KRSpotLight.h" #include "KRNode.h" #include "KRScene.h" -#include "KRQuaternion.h" #include "KRBone.h" #include "KRLocator.h" #include "KRBundle.h" diff --git a/kraken/KRScene.cpp b/kraken/KRScene.cpp index e825b69..8acb613 100755 --- a/kraken/KRScene.cpp +++ b/kraken/KRScene.cpp @@ -30,8 +30,6 @@ // #include "KREngine-common.h" -#include "KRVector3.h" -#include "KRMat4.h" #include "KRLight.h" @@ -41,7 +39,6 @@ #include "KRDirectionalLight.h" #include "KRSpotLight.h" #include "KRPointLight.h" -#include "KRQuaternion.h" #include "KRAudioManager.h" const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10; diff --git a/kraken/KRScene.h b/kraken/KRScene.h index 1ddb757..d5c36c9 100755 --- a/kraken/KRScene.h +++ b/kraken/KRScene.h @@ -35,7 +35,6 @@ #include "KREngine-common.h" #include "KRModel.h" -#include "KRMat4.h" #include "KRMesh.h" #include "KRCamera.h" #include "KRMeshManager.h" diff --git a/kraken/KRShader.h b/kraken/KRShader.h index 11ae7ac..9cfad0e 100755 --- a/kraken/KRShader.h +++ b/kraken/KRShader.h @@ -36,7 +36,6 @@ #include "KREngine-common.h" #include "KRShader.h" -#include "KRMat4.h" #include "KRCamera.h" #include "KRNode.h" #include "KRViewport.h" diff --git a/kraken/KRSprite.cpp b/kraken/KRSprite.cpp index 5f65a4f..f41af7b 100755 --- a/kraken/KRSprite.cpp +++ b/kraken/KRSprite.cpp @@ -11,8 +11,6 @@ #include "KRSprite.h" #include "KRNode.h" -#include "KRMat4.h" -#include "KRVector3.h" #include "KRCamera.h" #include "KRContext.h" diff --git a/kraken/KRTriangle3.cpp b/kraken/KRTriangle3.cpp index c60c764..e965fb2 100755 --- a/kraken/KRTriangle3.cpp +++ b/kraken/KRTriangle3.cpp @@ -6,21 +6,87 @@ // Copyright (c) 2014 Kearwood Software. All rights reserved. // -#include "KRTriangle3.h" -#include "KRVector3.h" +#include "public/kraken.h" + +using namespace kraken; + +namespace { + bool _intersectSphere(const KRVector3 &start, const KRVector3 &dir, const KRVector3 &sphere_center, float sphere_radius, float &distance) + { + // dir must be normalized + + // From: http://archive.gamedev.net/archive/reference/articles/article1026.html + + // TODO - Move to another class? + KRVector3 Q = sphere_center - start; + float c = Q.magnitude(); + float v = KRVector3::Dot(Q, dir); + float d = sphere_radius * sphere_radius - (c * c - v * v); + + + + if (d < 0.0) { + // No intersection + return false; + } + + // Return the distance to the [first] intersecting point + + distance = v - sqrt(d); + if (distance < 0.0f) { + return false; + } + return true; + + } + + bool _sameSide(const KRVector3 &p1, const KRVector3 &p2, const KRVector3 &a, const KRVector3 &b) + { + // TODO - Move to KRVector3 class? + // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle + + KRVector3 cp1 = KRVector3::Cross(b - a, p1 - a); + KRVector3 cp2 = KRVector3::Cross(b - a, p2 - a); + if (KRVector3::Dot(cp1, cp2) >= 0) return true; + return false; + } + + KRVector3 _closestPointOnLine(const KRVector3 &a, const KRVector3 &b, const KRVector3 &p) + { + // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle + + // Determine t (the length of the vector from ‘a’ to ‘p’) + + KRVector3 c = p - a; + KRVector3 V = KRVector3::Normalize(b - a); + float d = (a - b).magnitude(); + float t = KRVector3::Dot(V, c); + + // Check to see if ‘t’ is beyond the extents of the line segment + + if (t < 0) return a; + if (t > d) return b; + + // Return the point between ‘a’ and ‘b’ + + return a + V * t; + } +} // anonymous namespace + +namespace kraken { KRTriangle3::KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3) { - m_c[0] = v1; - m_c[1] = v2; - m_c[2] = v3; + vert[0] = v1; + vert[1] = v2; + vert[2] = v3; } KRTriangle3::KRTriangle3(const KRTriangle3 &tri) { - m_c[0] = tri[0]; - m_c[1] = tri[1]; - m_c[3] = tri[3]; + vert[0] = tri[0]; + vert[1] = tri[1]; + vert[3] = tri[3]; } @@ -31,31 +97,31 @@ KRTriangle3::~KRTriangle3() bool KRTriangle3::operator ==(const KRTriangle3& b) const { - return m_c[0] == b[0] && m_c[1] == b[1] && m_c[2] == b[2]; + return vert[0] == b[0] && vert[1] == b[1] && vert[2] == b[2]; } bool KRTriangle3::operator !=(const KRTriangle3& b) const { - return m_c[0] != b[0] || m_c[1] != b[1] || m_c[2] != b[2]; + return vert[0] != b[0] || vert[1] != b[1] || vert[2] != b[2]; } KRTriangle3& KRTriangle3::operator =(const KRTriangle3& b) { - m_c[0] = b[0]; - m_c[1] = b[1]; - m_c[3] = b[3]; + vert[0] = b[0]; + vert[1] = b[1]; + vert[3] = b[3]; return *this; } -KRVector3& KRTriangle3::operator[](unsigned i) +KRVector3& KRTriangle3::operator[](unsigned int i) { - return m_c[i]; + return vert[i]; } -KRVector3 KRTriangle3::operator[](unsigned i) const +KRVector3 KRTriangle3::operator[](unsigned int i) const { - return m_c[i]; + return vert[i]; } @@ -68,13 +134,13 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector float r, a, b; // params to calc ray-plane intersect // get triangle edge vectors and plane normal - u = m_c[1] - m_c[0]; - v = m_c[2] - m_c[0]; + u = vert[1] - vert[0]; + v = vert[2] - vert[0]; n = KRVector3::Cross(u, v); // cross product if (n == KRVector3::Zero()) // triangle is degenerate return false; // do not deal with this case - w0 = start - m_c[0]; + w0 = start - vert[0]; a = -KRVector3::Dot(n, w0); b = KRVector3::Dot(n,dir); if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane @@ -99,7 +165,7 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector uu = KRVector3::Dot(u,u); uv = KRVector3::Dot(u,v); vv = KRVector3::Dot(v,v); - w = plane_hit_point - m_c[0]; + w = plane_hit_point - vert[0]; wu = KRVector3::Dot(w,u); wv = KRVector3::Dot(w,v); D = uv * uv - uu * vv; @@ -120,78 +186,17 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector KRVector3 KRTriangle3::calculateNormal() const { - KRVector3 v1 = m_c[1] - m_c[0]; - KRVector3 v2 = m_c[2] - m_c[0]; + KRVector3 v1 = vert[1] - vert[0]; + KRVector3 v2 = vert[2] - vert[0]; return KRVector3::Normalize(KRVector3::Cross(v1, v2)); } -bool _intersectSphere(const KRVector3 &start, const KRVector3 &dir, const KRVector3 &sphere_center, float sphere_radius, float &distance) -{ - // dir must be normalized - - // From: http://archive.gamedev.net/archive/reference/articles/article1026.html - - // TODO - Move to another class? - KRVector3 Q = sphere_center - start; - float c = Q.magnitude(); - float v = KRVector3::Dot(Q, dir); - float d = sphere_radius * sphere_radius - (c * c - v * v); - - - - if(d < 0.0) { - // No intersection - return false; - } - - // Return the distance to the [first] intersecting point - - distance = v - sqrt(d); - if(distance < 0.0f) { - return false; - } - return true; - -} - -bool _sameSide(const KRVector3 &p1, const KRVector3 &p2, const KRVector3 &a, const KRVector3 &b) -{ - // TODO - Move to KRVector3 class? - // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle - - KRVector3 cp1 = KRVector3::Cross(b - a, p1 - a); - KRVector3 cp2 = KRVector3::Cross(b - a, p2 - a); - if(KRVector3::Dot(cp1, cp2) >= 0) return true; - return false; -} - -KRVector3 _closestPointOnLine(const KRVector3 &a, const KRVector3 &b, const KRVector3 &p) -{ - // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle - - // Determine t (the length of the vector from ‘a’ to ‘p’) - - KRVector3 c = p - a; - KRVector3 V = KRVector3::Normalize(b - a); - float d = (a - b).magnitude(); - float t = KRVector3::Dot(V, c); - - // Check to see if ‘t’ is beyond the extents of the line segment - - if (t < 0) return a; - if (t > d) return b; - - // Return the point between ‘a’ and ‘b’ - - return a + V * t; -} - KRVector3 KRTriangle3::closestPointOnTriangle(const KRVector3 &p) const { - KRVector3 a = m_c[0]; - KRVector3 b = m_c[1]; - KRVector3 c = m_c[2]; + KRVector3 a = vert[0]; + KRVector3 b = vert[1]; + KRVector3 c = vert[2]; KRVector3 Rab = _closestPointOnLine(a, b, p); KRVector3 Rbc = _closestPointOnLine(b, c, p); @@ -218,7 +223,7 @@ bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float KRVector3 tri_normal = calculateNormal(); - float d = KRVector3::Dot(tri_normal, m_c[0]); + float d = KRVector3::Dot(tri_normal, vert[0]); float e = KRVector3::Dot(tri_normal, start) - radius; float cotangent_distance = e - d; @@ -277,10 +282,10 @@ bool KRTriangle3::containsPoint(const KRVector3 &p) const // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle const float SMALL_NUM = 0.00000001f; // anything that avoids division overflow - // KRVector3 A = m_c[0], B = m_c[1], C = m_c[2]; - if (_sameSide(p, m_c[0], m_c[1], m_c[2]) && _sameSide(p, m_c[1], m_c[0], m_c[2]) && _sameSide(p, m_c[2], m_c[0], m_c[1])) { - KRVector3 vc1 = KRVector3::Cross(m_c[0] - m_c[1], m_c[0] - m_c[2]); - if(fabs(KRVector3::Dot(m_c[0] - p, vc1)) <= SMALL_NUM) { + // KRVector3 A = vert[0], B = vert[1], C = vert[2]; + if (_sameSide(p, vert[0], vert[1], vert[2]) && _sameSide(p, vert[1], vert[0], vert[2]) && _sameSide(p, vert[2], vert[0], vert[1])) { + KRVector3 vc1 = KRVector3::Cross(vert[0] - vert[1], vert[0] - vert[2]); + if(fabs(KRVector3::Dot(vert[0] - p, vc1)) <= SMALL_NUM) { return true; } } @@ -290,9 +295,9 @@ bool KRTriangle3::containsPoint(const KRVector3 &p) const // From: http://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx - KRVector3 A = m_c[0]; - KRVector3 B = m_c[1]; - KRVector3 C = m_c[2]; + KRVector3 A = vert[0]; + KRVector3 B = vert[1]; + KRVector3 C = vert[2]; KRVector3 P = p; // Prepare our barycentric variables @@ -323,5 +328,4 @@ bool KRTriangle3::containsPoint(const KRVector3 &p) const return (r + t <= 1); } - - +} // namespace kraken diff --git a/kraken/KRVector2.cpp b/kraken/KRVector2.cpp index 6219db4..57be144 100755 --- a/kraken/KRVector2.cpp +++ b/kraken/KRVector2.cpp @@ -6,9 +6,9 @@ // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#include "KREngine-common.h" +#include "public/kraken.h" -#include "KRVector2.h" +namespace kraken { KRVector2::KRVector2() { x = 0.0; @@ -212,7 +212,4 @@ float KRVector2::Dot(const KRVector2 &v1, const KRVector2 &v2) { return v1.x * v2.x + v1.y * v2.y; } -void KRVector2::setUniform(GLint location) const -{ - if(location != -1) GLDEBUG(glUniform2f(location, x, y)); -} +} // namepsace kraken diff --git a/kraken/KRVector3.cpp b/kraken/KRVector3.cpp index 05e700a..3724b3f 100755 --- a/kraken/KRVector3.cpp +++ b/kraken/KRVector3.cpp @@ -30,7 +30,7 @@ // #include "KREngine-common.h" -#include "KRVector3.h" +#include "public/kraken.h" const KRVector3 KRVECTOR3_ZERO(0.0f, 0.0f, 0.0f); @@ -412,35 +412,3 @@ bool KRVector3::operator <(const KRVector3& b) const return false; } } - -void KRVector3::setUniform(GLint location) const -{ - if(location != -1) GLDEBUG(glUniform3f(location, x, y, z)); -} - -void KRVector3::setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value) -{ - // TODO - Increase number of digits after the decimal in floating point format (6 -> 12?) - // FINDME, TODO - This needs optimization... - if(*this != default_value) { - e->SetAttribute((base_name + "_x").c_str(), x); - e->SetAttribute((base_name + "_y").c_str(), y); - e->SetAttribute((base_name + "_z").c_str(), z); - } -} - -void KRVector3::getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value) -{ - float new_x = 0.0f; - float new_y = 0.0f; - float new_z = 0.0f; - if(e->QueryFloatAttribute((base_name + "_x").c_str(), &new_x) == tinyxml2::XML_SUCCESS - && e->QueryFloatAttribute((base_name + "_y").c_str(), &new_y) == tinyxml2::XML_SUCCESS - && e->QueryFloatAttribute((base_name + "_z").c_str(), &new_z) == tinyxml2::XML_SUCCESS) { - x = new_x; - y = new_y; - z = new_z; - } else { - *this = default_value; - } -} diff --git a/kraken/KRVector4.cpp b/kraken/KRVector4.cpp index a5d8b61..9520e2a 100755 --- a/kraken/KRVector4.cpp +++ b/kraken/KRVector4.cpp @@ -31,6 +31,8 @@ #include "public/kraken.h" +namespace kraken { + const KRVector4 KRVECTOR4_ZERO(0.0f, 0.0f, 0.0f, 0.0f); //default constructor @@ -297,3 +299,5 @@ bool KRVector4::operator <(const KRVector4& b) const if(w != b.w) return w < b.w; return false; } + +} // namespace kraken diff --git a/kraken/public/KRAABB.h b/kraken/public/KRAABB.h index 1fa5bd2..659d9a6 100644 --- a/kraken/public/KRAABB.h +++ b/kraken/public/KRAABB.h @@ -16,6 +16,8 @@ #include "KRVector2.h" #include "KRVector3.h" +namespace kraken { + class KRMat4; class KRAABB { @@ -58,14 +60,16 @@ public: KRVector3 nearestPoint(const KRVector3 & v) const; }; +} // namespace kraken + namespace std { template<> - struct hash { + struct hash { public: - size_t operator()(const KRAABB &s) const + size_t operator()(const kraken::KRAABB &s) const { - size_t h1 = hash()(s.min); - size_t h2 = hash()(s.max); + size_t h1 = hash()(s.min); + size_t h2 = hash()(s.max); return h1 ^ ( h2 << 1 ); } }; diff --git a/kraken/public/KRFloat.h b/kraken/public/KRFloat.h index 1915533..79b231b 100644 --- a/kraken/public/KRFloat.h +++ b/kraken/public/KRFloat.h @@ -32,8 +32,10 @@ #ifndef KRFLOAT_H #define KRFLOAT_H -namespace KRFloat { +namespace kraken { + float SmoothStep(float a, float b, float t); -}; + +}; // namespace kraken #endif /* defined(KRFLOAT_H) */ diff --git a/kraken/public/KRMat4.h b/kraken/public/KRMat4.h index ab802ce..2822e4d 100644 --- a/kraken/public/KRMat4.h +++ b/kraken/public/KRMat4.h @@ -36,6 +36,8 @@ #ifndef KRMAT4_H #define KRMAT4_H +namespace kraken { + typedef enum { X_AXIS, Y_AXIS, @@ -108,4 +110,6 @@ class KRMat4 { static KRMat4 Scaling(const KRVector3 &v); }; +} // namespace kraken + #endif // KRMAT4_H \ No newline at end of file diff --git a/kraken/KRQuaternion.h b/kraken/public/KRQuaternion.h old mode 100755 new mode 100644 similarity index 93% rename from kraken/KRQuaternion.h rename to kraken/public/KRQuaternion.h index 5b0c65c..3a86b97 --- a/kraken/KRQuaternion.h +++ b/kraken/public/KRQuaternion.h @@ -32,10 +32,9 @@ #ifndef KRQUATERNION_H #define KRQUATERNION_H -#include "KREngine-common.h" -#include "KRMat4.h" +#include "KRVector3.h" -class KRVector3; +namespace kraken { class KRQuaternion { public: @@ -47,13 +46,13 @@ public: ~KRQuaternion(); KRQuaternion& operator =( const KRQuaternion& p ); - KRQuaternion operator +(const KRQuaternion &v) const; - KRQuaternion operator -(const KRQuaternion &v) const; + KRQuaternion operator +(const KRQuaternion &v) const; + KRQuaternion operator -(const KRQuaternion &v) const; KRQuaternion operator +() const; KRQuaternion operator -() const; KRQuaternion operator *(const KRQuaternion &v); - KRQuaternion operator *(float num) const; + KRQuaternion operator *(float num) const; KRQuaternion operator /(float num) const; KRQuaternion& operator +=(const KRQuaternion& v); @@ -86,4 +85,6 @@ private: float m_val[4]; }; -#endif \ No newline at end of file +} // namespace kraken + +#endif // KRQUATERNION_H diff --git a/kraken/public/KRTriangle3.h b/kraken/public/KRTriangle3.h index de34fb5..89575f4 100644 --- a/kraken/public/KRTriangle3.h +++ b/kraken/public/KRTriangle3.h @@ -34,6 +34,8 @@ #include "KRVector3.h" +namespace kraken { + class KRTriangle3 { public: @@ -58,4 +60,6 @@ public: KRVector3 closestPointOnTriangle(const KRVector3 &p) const; }; +} // namespace kraken + #endif // KRTRIANGLE3_H diff --git a/kraken/public/KRVector2.h b/kraken/public/KRVector2.h index 43b0d95..c7f71da 100644 --- a/kraken/public/KRVector2.h +++ b/kraken/public/KRVector2.h @@ -34,6 +34,8 @@ #include // for hash<> +namespace kraken { + class KRVector2 { public: @@ -95,18 +97,20 @@ public: static KRVector2 One(); }; +} // namespace kraken + namespace std { - template<> - struct hash { - public: - size_t operator()(const KRVector2 &s) const - { - size_t h1 = hash()(s.x); - size_t h2 = hash()(s.y); - return h1 ^ ( h2 << 1 ); - } - }; -}; + template<> + struct hash { + public: + size_t operator()(const kraken::KRVector2 &s) const + { + size_t h1 = hash()(s.x); + size_t h2 = hash()(s.y); + return h1 ^ (h2 << 1); + } + }; +} +#endif // KRVECTOR2_H -#endif diff --git a/kraken/public/KRVector3.h b/kraken/public/KRVector3.h index 25880c4..5d712ca 100644 --- a/kraken/public/KRVector3.h +++ b/kraken/public/KRVector3.h @@ -34,8 +34,9 @@ #include // for hash<> -class KRVector2; -class KRVector4; +#include "KRVector4.h" + +namespace kraken { class KRVector3 { @@ -125,18 +126,20 @@ public: static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization }; +} // namespace kraken + namespace std { - template<> - struct hash { - public: - size_t operator()(const KRVector3 &s) const - { - size_t h1 = hash()(s.x); - size_t h2 = hash()(s.y); - size_t h3 = hash()(s.z); - return h1 ^ ( h2 << 1 ) ^ (h3 << 2); - } - }; -}; + template<> + struct hash { + public: + size_t operator()(const kraken::KRVector3 &s) const + { + size_t h1 = hash()(s.x); + size_t h2 = hash()(s.y); + size_t h3 = hash()(s.z); + return h1 ^ (h2 << 1) ^ (h3 << 2); + } + }; +} #endif // KRVECTOR3_H diff --git a/kraken/public/KRVector4.h b/kraken/public/KRVector4.h index 08f0dc4..51621c3 100644 --- a/kraken/public/KRVector4.h +++ b/kraken/public/KRVector4.h @@ -34,6 +34,8 @@ #include // for hash<> +namespace kraken { + class KRVector3; class KRVector4 { @@ -100,4 +102,21 @@ public: static void OrthoNormalize(KRVector4 &normal, KRVector4 &tangent); // Gram-Schmidt Orthonormalization }; +} // namespace kraken + +namespace std { + template<> + struct hash { + public: + size_t operator()(const kraken::KRVector4 &s) const + { + size_t h1 = hash()(s.x); + size_t h2 = hash()(s.y); + size_t h3 = hash()(s.z); + size_t h4 = hash()(s.w); + return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3); + } + }; +} + #endif // KRVECTOR4_H diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 2561c84..c3e01ba 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -6,6 +6,7 @@ #include "KRVector3.h" #include "KRVector4.h" #include "KRMat4.h" +#include "KRQuaternion.h" #include "KRAABB.h" #include "KRTriangle3.h" diff --git a/kraken_win/kraken.vcxproj b/kraken_win/kraken.vcxproj index 9ea1ae5..ef85542 100755 --- a/kraken_win/kraken.vcxproj +++ b/kraken_win/kraken.vcxproj @@ -73,11 +73,15 @@ .lib $(SolutionDir)\build\output\$(Platform)\$(Configuration)\ build\intermediate\$(Platform)\$(Configuration)\ + C:\Program Files\Autodesk\FBX\FBX SDK\2018.1.1\include;$(IncludePath) + C:\Program Files\Autodesk\FBX\FBX SDK\2018.1.1\lib\vs2015\x64\release;$(LibraryPath) .lib $(SolutionDir)\build\output\$(Platform)\$(Configuration)\ build\intermediate\$(Platform)\$(Configuration)\ + C:\Program Files\Autodesk\FBX\FBX SDK\2018.1.1\include;$(IncludePath) + C:\Program Files\Autodesk\FBX\FBX SDK\2018.1.1\lib\vs2015\x64\release;$(LibraryPath) @@ -146,6 +150,7 @@ + @@ -198,7 +203,6 @@ - @@ -224,13 +228,12 @@ - + - @@ -245,7 +248,6 @@ - @@ -266,13 +268,18 @@ - - - - + + + + + + + + + diff --git a/kraken_win/kraken.vcxproj.filters b/kraken_win/kraken.vcxproj.filters index 0234575..be1b06d 100755 --- a/kraken_win/kraken.vcxproj.filters +++ b/kraken_win/kraken.vcxproj.filters @@ -16,12 +16,12 @@ {1ccb2d2f-3dba-4fa4-a77f-5aef119ca916} - - {218ed471-6978-45cb-9a64-c25d07ecdcc1} - {b1389da0-01b5-4d0b-bb62-bf912979a845} + + {4ebfb66f-4752-486a-bfcf-8b438e8ad64b} + @@ -249,41 +249,20 @@ Source Files + + Header Files + Header Files - - Header Files - Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files - - Header Files - Header Files @@ -491,5 +470,35 @@ Header Files + + Header Files + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + + + Header Files\public + \ No newline at end of file