From 95ff5243c55a666e8ca1005c3faf8380a7de36fa Mon Sep 17 00:00:00 2001 From: Kearwood Kip Gilbert Date: Sat, 29 Jul 2017 01:24:49 -0700 Subject: [PATCH] /s/KRVector3/Vector3/g --- kraken/KRAABB.cpp | 52 +++--- kraken/KRAmbientZone.cpp | 12 +- kraken/KRAmbientZone.h | 2 +- kraken/KRAudioManager.cpp | 50 +++--- kraken/KRAudioManager.h | 14 +- kraken/KRAudioSource.cpp | 2 +- kraken/KRBone.cpp | 4 +- kraken/KRCamera.cpp | 14 +- kraken/KRCollider.cpp | 34 ++-- kraken/KRCollider.h | 6 +- kraken/KRDirectionalLight.cpp | 22 +-- kraken/KRDirectionalLight.h | 4 +- kraken/KREngine.h | 2 +- kraken/KRHelpers.cpp | 8 +- kraken/KRHelpers.h | 6 +- kraken/KRHitInfo.cpp | 14 +- kraken/KRHitInfo.h | 12 +- kraken/KRLODGroup.cpp | 18 +- kraken/KRLight.cpp | 20 +-- kraken/KRLight.h | 6 +- kraken/KRMat4.cpp | 42 ++--- kraken/KRMaterial.cpp | 36 ++-- kraken/KRMaterial.h | 18 +- kraken/KRMaterialManager.cpp | 16 +- kraken/KRMesh.cpp | 96 +++++----- kraken/KRMesh.h | 36 ++-- kraken/KRMeshCube.cpp | 28 +-- kraken/KRMeshManager.h | 6 +- kraken/KRMeshQuad.cpp | 8 +- kraken/KRMeshSphere.cpp | 22 +-- kraken/KRModel.cpp | 16 +- kraken/KRModel.h | 8 +- kraken/KRNode.cpp | 202 ++++++++++----------- kraken/KRNode.h | 104 +++++------ kraken/KROctree.cpp | 8 +- kraken/KROctree.h | 6 +- kraken/KROctreeNode.cpp | 14 +- kraken/KROctreeNode.h | 6 +- kraken/KRParticleSystemNewtonian.cpp | 6 +- kraken/KRPointLight.cpp | 30 ++-- kraken/KRQuaternion.cpp | 30 ++-- kraken/KRRenderSettings.cpp | 6 +- kraken/KRRenderSettings.h | 6 +- kraken/KRResource+fbx.cpp | 68 +++---- kraken/KRResource+obj.cpp | 22 +-- kraken/KRReverbZone.cpp | 12 +- kraken/KRReverbZone.h | 2 +- kraken/KRScene.cpp | 16 +- kraken/KRScene.h | 6 +- kraken/KRShader.cpp | 10 +- kraken/KRShader.h | 6 +- kraken/KRShaderManager.cpp | 4 +- kraken/KRShaderManager.h | 4 +- kraken/KRSpotLight.cpp | 2 +- kraken/KRSprite.cpp | 4 +- kraken/KRTriangle3.cpp | 126 ++++++------- kraken/KRVector4.cpp | 2 +- kraken/KRViewport.cpp | 14 +- kraken/KRViewport.h | 8 +- kraken/public/KRAABB.h | 30 ++-- kraken/public/KRMat4.h | 24 +-- kraken/public/KRQuaternion.h | 14 +- kraken/public/KRTriangle3.h | 20 +-- kraken/public/KRVector4.h | 4 +- kraken/public/kraken.h | 2 +- kraken/public/vector2.h | 116 ++++++++++++ kraken/public/{KRVector3.h => vector3.h} | 93 +++++----- kraken/vector2.cpp | 215 +++++++++++++++++++++++ kraken/{KRVector3.cpp => vector3.cpp} | 170 +++++++++--------- kraken_win/kraken.vcxproj | 4 +- kraken_win/kraken.vcxproj.filters | 12 +- 71 files changed, 1197 insertions(+), 865 deletions(-) create mode 100644 kraken/public/vector2.h rename kraken/public/{KRVector3.h => vector3.h} (60%) create mode 100644 kraken/vector2.cpp rename kraken/{KRVector3.cpp => vector3.cpp} (59%) mode change 100755 => 100644 diff --git a/kraken/KRAABB.cpp b/kraken/KRAABB.cpp index b4df08f..78a8442 100755 --- a/kraken/KRAABB.cpp +++ b/kraken/KRAABB.cpp @@ -12,20 +12,20 @@ KRAABB::KRAABB() { - min = KRVector3::Min(); - max = KRVector3::Max(); + min = Vector3::Min(); + max = Vector3::Max(); } -KRAABB::KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint) +KRAABB::KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint) { min = minPoint; max = maxPoint; } -KRAABB::KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix) +KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix) { for(int iCorner=0; iCorner<8; iCorner++) { - KRVector3 sourceCornerVertex = KRMat4::DotWDiv(modelMatrix, KRVector3( + Vector3 sourceCornerVertex = KRMat4::DotWDiv(modelMatrix, Vector3( (iCorner & 1) == 0 ? corner1.x : corner2.x, (iCorner & 2) == 0 ? corner1.y : corner2.y, (iCorner & 4) == 0 ? corner1.z : corner2.z)); @@ -68,34 +68,34 @@ bool KRAABB::operator !=(const KRAABB& b) const return min != b.min || max != b.max; } -KRVector3 KRAABB::center() const +Vector3 KRAABB::center() const { return (min + max) * 0.5f; } -KRVector3 KRAABB::size() const +Vector3 KRAABB::size() const { return max - min; } float KRAABB::volume() const { - KRVector3 s = size(); + Vector3 s = size(); return s.x * s.y * s.z; } -void KRAABB::scale(const KRVector3 &s) +void KRAABB::scale(const Vector3 &s) { - KRVector3 prev_center = center(); - KRVector3 prev_size = size(); - KRVector3 new_scale = KRVector3(prev_size.x * s.x, prev_size.y * s.y, prev_size.z * s.z) * 0.5f; + Vector3 prev_center = center(); + Vector3 prev_size = size(); + Vector3 new_scale = Vector3(prev_size.x * s.x, prev_size.y * s.y, prev_size.z * s.z) * 0.5f; min = prev_center - new_scale; max = prev_center + new_scale; } void KRAABB::scale(float s) { - scale(KRVector3(s)); + scale(Vector3(s)); } bool KRAABB::operator >(const KRAABB& b) const @@ -139,19 +139,19 @@ bool KRAABB::contains(const KRAABB &b) const return b.min.x >= min.x && b.min.y >= min.y && b.min.z >= min.z && b.max.x <= max.x && b.max.y <= max.y && b.max.z <= max.z; } -bool KRAABB::contains(const KRVector3 &v) const +bool KRAABB::contains(const Vector3 &v) const { return v.x >= min.x && v.x <= max.x && v.y >= min.y && v.y <= max.y && v.z >= min.z && v.z <= max.z; } KRAABB KRAABB::Infinite() { - return KRAABB(KRVector3::Min(), KRVector3::Max()); + return KRAABB(Vector3::Min(), Vector3::Max()); } KRAABB KRAABB::Zero() { - return KRAABB(KRVector3::Zero(), KRVector3::Zero()); + return KRAABB(Vector3::Zero(), Vector3::Zero()); } float KRAABB::longest_radius() const @@ -162,9 +162,9 @@ float KRAABB::longest_radius() const } -bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const +bool KRAABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const { - KRVector3 dir = KRVector3::Normalize(v2 - v1); + Vector3 dir = Vector3::Normalize(v2 - v1); float length = (v2 - v1).magnitude(); // EZ cases: if the ray starts inside the box, or ends inside @@ -178,7 +178,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const return true ; // the algorithm says, find 3 t's, - KRVector3 t ; + Vector3 t ; // LARGEST t is the only one we need to test if it's on the face. for(int i = 0 ; i < 3 ; i++) { @@ -193,7 +193,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const if(t[1] > t[mi]) mi = 1; if(t[2] > t[mi]) mi = 2; if(t[mi] >= 0 && t[mi] <= length) { - KRVector3 pt = v1 + dir * t[mi]; + Vector3 pt = v1 + dir * t[mi]; // check it's in the box in other 2 dimensions int o1 = ( mi + 1 ) % 3 ; // i=0: o1=1, o2=2, i=1: o1=2,o2=0 etc. @@ -205,7 +205,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const return false ; // the ray did not hit the box. } -bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const +bool KRAABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const { /* Fast Ray-Box Intersection @@ -222,8 +222,8 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const } quadrant[3]; bool inside = true; - KRVector3 maxT; - KRVector3 coord; + Vector3 maxT; + Vector3 coord; double candidatePlane[3]; // Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view) @@ -281,7 +281,7 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const return true; /* ray hits box */ } -bool KRAABB::intersectsSphere(const KRVector3 ¢er, float radius) const +bool KRAABB::intersectsSphere(const Vector3 ¢er, float radius) const { // Arvo's Algorithm @@ -328,7 +328,7 @@ void KRAABB::encapsulate(const KRAABB & b) if(b.max.z > max.z) max.z = b.max.z; } -KRVector3 KRAABB::nearestPoint(const KRVector3 & v) const +Vector3 KRAABB::nearestPoint(const Vector3 & v) const { - return KRVector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z)); + return Vector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z)); } diff --git a/kraken/KRAmbientZone.cpp b/kraken/KRAmbientZone.cpp index a172208..ad9b387 100755 --- a/kraken/KRAmbientZone.cpp +++ b/kraken/KRAmbientZone.cpp @@ -98,7 +98,7 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector &point KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); @@ -139,17 +139,17 @@ void KRAmbientZone::setGradientDistance(float gradient_distance) KRAABB KRAmbientZone::getBounds() { // Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box - return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); + return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix()); } -float KRAmbientZone::getContainment(const KRVector3 &pos) +float KRAmbientZone::getContainment(const Vector3 &pos) { KRAABB bounds = getBounds(); if(bounds.contains(pos)) { - KRVector3 size = bounds.size(); - KRVector3 diff = pos - bounds.center(); + Vector3 size = bounds.size(); + Vector3 diff = pos - bounds.center(); diff = diff * 2.0f; - diff = KRVector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); + diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); float d = diff.magnitude(); if(m_gradient_distance <= 0.0f) { diff --git a/kraken/KRAmbientZone.h b/kraken/KRAmbientZone.h index ff16337..b5d3eb5 100755 --- a/kraken/KRAmbientZone.h +++ b/kraken/KRAmbientZone.h @@ -37,7 +37,7 @@ public: virtual KRAABB getBounds(); - float getContainment(const KRVector3 &pos); + float getContainment(const Vector3 &pos); private: std::string m_zone; diff --git a/kraken/KRAudioManager.cpp b/kraken/KRAudioManager.cpp index aad12d7..f07bef3 100755 --- a/kraken/KRAudioManager.cpp +++ b/kraken/KRAudioManager.cpp @@ -1221,28 +1221,28 @@ void KRAudioManager::makeCurrentContext() void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix) { setListenerOrientation( - KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, 0.0)), - KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, -1.0)) - m_listener_position), - KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 1.0, 0.0)) - m_listener_position) + KRMat4::Dot(modelMatrix, Vector3(0.0, 0.0, 0.0)), + Vector3::Normalize(KRMat4::Dot(modelMatrix, Vector3(0.0, 0.0, -1.0)) - m_listener_position), + Vector3::Normalize(KRMat4::Dot(modelMatrix, Vector3(0.0, 1.0, 0.0)) - m_listener_position) ); } -KRVector3 &KRAudioManager::getListenerForward() +Vector3 &KRAudioManager::getListenerForward() { return m_listener_forward; } -KRVector3 &KRAudioManager::getListenerPosition() +Vector3 &KRAudioManager::getListenerPosition() { return m_listener_position; } -KRVector3 &KRAudioManager::getListenerUp() +Vector3 &KRAudioManager::getListenerUp() { return m_listener_up; } -void KRAudioManager::setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up) +void KRAudioManager::setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up) { m_listener_position = position; m_listener_forward = forward; @@ -1459,14 +1459,14 @@ void KRAudioManager::startFrame(float deltaTime) m_prev_mapped_sources.clear(); m_mapped_sources.swap(m_prev_mapped_sources); - KRVector3 listener_right = KRVector3::Cross(m_listener_forward, m_listener_up); + Vector3 listener_right = Vector3::Cross(m_listener_forward, m_listener_up); std::set active_sources = m_activeAudioSources; for(std::set::iterator itr=active_sources.begin(); itr != active_sources.end(); itr++) { KRAudioSource *source = *itr; - KRVector3 source_world_position = source->getWorldTranslation(); - KRVector3 diff = source_world_position - m_listener_position; + Vector3 source_world_position = source->getWorldTranslation(); + Vector3 diff = source_world_position - m_listener_position; float distance = diff.magnitude(); float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor()); @@ -1475,14 +1475,14 @@ void KRAudioManager::startFrame(float deltaTime) if(gain > 0.0f) { - KRVector3 source_listener_space = KRVector3( - KRVector3::Dot(listener_right, diff), - KRVector3::Dot(m_listener_up, diff), - KRVector3::Dot(m_listener_forward, diff) + Vector3 source_listener_space = Vector3( + Vector3::Dot(listener_right, diff), + Vector3::Dot(m_listener_up, diff), + Vector3::Dot(m_listener_forward, diff) ); - KRVector3 source_dir = KRVector3::Normalize(source_listener_space); + Vector3 source_dir = Vector3::Normalize(source_listener_space); @@ -1699,13 +1699,13 @@ void KRAudioManager::renderITD() float head_radius = 0.7431f; // 0.74ft = 22cm float half_max_itd_time = head_radius / speed_of_sound / 2.0f; // half of ITD time (Interaural time difference) when audio source is directly 90 degrees azimuth to one ear. - // KRVector3 m_listener_position; - // KRVector3 m_listener_forward; - // KRVector3 m_listener_up; + // Vector3 m_listener_position; + // Vector3 m_listener_forward; + // Vector3 m_listener_up; - KRVector3 listener_right = KRVector3::Cross(m_listener_forward, m_listener_up); - KRVector3 listener_right_ear = m_listener_position + listener_right * head_radius / 2.0f; - KRVector3 listener_left_ear = m_listener_position - listener_right * head_radius / 2.0f; + Vector3 listener_right = Vector3::Cross(m_listener_forward, m_listener_up); + Vector3 listener_right_ear = m_listener_position + listener_right * head_radius / 2.0f; + Vector3 listener_left_ear = m_listener_position - listener_right * head_radius / 2.0f; // Get a pointer to the dataBuffer of the AudioBufferList @@ -1739,10 +1739,10 @@ void KRAudioManager::renderITD() // ----====---- Render direct / HRTF audio ----====---- for(std::set::iterator itr=m_activeAudioSources.begin(); itr != m_activeAudioSources.end(); itr++) { KRAudioSource *source = *itr; - KRVector3 listener_to_source = source->getWorldTranslation() - m_listener_position; - KRVector3 right_ear_to_source = source->getWorldTranslation() - listener_right_ear; - KRVector3 left_ear_to_source = source->getWorldTranslation() - listener_left_ear; - KRVector3 source_direction = KRVector3::Normalize(listener_to_source); + Vector3 listener_to_source = source->getWorldTranslation() - m_listener_position; + Vector3 right_ear_to_source = source->getWorldTranslation() - listener_right_ear; + Vector3 left_ear_to_source = source->getWorldTranslation() - listener_left_ear; + Vector3 source_direction = Vector3::Normalize(listener_to_source); float right_ear_distance = right_ear_to_source.magnitude(); float left_ear_distance = left_ear_to_source.magnitude(); float right_itd_time = right_ear_distance / speed_of_sound; diff --git a/kraken/KRAudioManager.h b/kraken/KRAudioManager.h index 04b9683..3d0b000 100755 --- a/kraken/KRAudioManager.h +++ b/kraken/KRAudioManager.h @@ -105,11 +105,11 @@ public: // Listener position and orientation KRScene *getListenerScene(); void setListenerScene(KRScene *scene); - void setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up); + void setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up); void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix); - KRVector3 &getListenerForward(); - KRVector3 &getListenerPosition(); - KRVector3 &getListenerUp(); + Vector3 &getListenerForward(); + Vector3 &getListenerPosition(); + Vector3 &getListenerUp(); // Global audio gain / attenuation @@ -166,9 +166,9 @@ private: float m_global_ambient_gain; float m_global_gain; - KRVector3 m_listener_position; - KRVector3 m_listener_forward; - KRVector3 m_listener_up; + Vector3 m_listener_position; + Vector3 m_listener_forward; + Vector3 m_listener_up; unordered_map m_sounds; diff --git a/kraken/KRAudioSource.cpp b/kraken/KRAudioSource.cpp index 4495280..8024fc6 100755 --- a/kraken/KRAudioSource.cpp +++ b/kraken/KRAudioSource.cpp @@ -182,7 +182,7 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector &point KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRBone.cpp b/kraken/KRBone.cpp index 4ca2f5d..af93922 100755 --- a/kraken/KRBone.cpp +++ b/kraken/KRBone.cpp @@ -36,7 +36,7 @@ void KRBone::loadXML(tinyxml2::XMLElement *e) } KRAABB KRBone::getBounds() { - return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); // Only required for bone debug visualization + return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization } void KRBone::render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) @@ -63,7 +63,7 @@ void KRBone::render(KRCamera *pCamera, std::vector &point_lights KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { std::vector sphereModels = getContext().getMeshManager()->getModel("__sphere"); if(sphereModels.size()) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index b659649..bc40227 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -109,7 +109,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend KRScene &scene = getScene(); KRMat4 modelMatrix = getModelMatrix(); - KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, KRVector3::Zero()), KRMat4::Dot(modelMatrix, KRVector3::Forward()), KRVector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, KRVector3::Up()))); + KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, Vector3::Zero()), KRMat4::Dot(modelMatrix, Vector3::Forward()), Vector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, Vector3::Up()))); //KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix()); @@ -119,7 +119,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix); m_viewport.setLODBias(settings.getLODBias()); - KRVector3 vecCameraDirection = m_viewport.getCameraDirection(); + Vector3 vecCameraDirection = m_viewport.getCameraDirection(); scene.updateOctree(m_viewport); @@ -312,7 +312,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend } if(m_pSkyBoxTexture) { - getContext().getShaderManager()->selectShader("sky_box", *this, std::vector(), std::vector(), std::vector(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, KRVector3::Zero(), 0.0f, KRVector4::Zero()); + getContext().getShaderManager()->selectShader("sky_box", *this, std::vector(), std::vector(), std::vector(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, KRVector4::Zero()); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); @@ -480,7 +480,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend KRMat4 matModel = KRMat4(); matModel.scale((*itr).first.size() * 0.5f); matModel.translate((*itr).first.center()); - if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero())) { GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); } } @@ -694,7 +694,7 @@ void KRCamera::renderPost() GLDEBUG(glDisable(GL_DEPTH_TEST)); KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - KRVector3 rim_color; + Vector3 rim_color; getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture); @@ -720,7 +720,7 @@ void KRCamera::renderPost() // KRMat4 viewMatrix = KRMat4(); // viewMatrix.scale(0.20, 0.20, 0.20); // viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0); -// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); +// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), Vector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); // m_pContext->getTextureManager()->selectTexture(1, NULL); // m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES); // m_pContext->getTextureManager()->_setActiveTexture(0); @@ -879,7 +879,7 @@ void KRCamera::renderPost() GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero()); + getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero()); m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI); diff --git a/kraken/KRCollider.cpp b/kraken/KRCollider.cpp index 56c0c1a..e0ac077 100755 --- a/kraken/KRCollider.cpp +++ b/kraken/KRCollider.cpp @@ -92,23 +92,23 @@ KRAABB KRCollider::getBounds() { } } -bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { if(layer_mask & m_layer_mask ) { // Only test if layer masks have a common bit set loadModel(); if(m_models.size()) { if(getBounds().intersectsLine(v0, v1)) { - KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - KRVector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); + Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); + Vector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); KRHitInfo hitinfo_model_space; if(hitinfo.didHit()) { - KRVector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); + Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); hitinfo_model_space = KRHitInfo(hit_position_model_space, KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode()); } if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) { - KRVector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); - hitinfo = KRHitInfo(hit_position_world_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); + Vector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); + hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); return true; } } @@ -117,23 +117,23 @@ bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &h return false; } -bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set loadModel(); if(m_models.size()) { if(getBounds().intersectsRay(v0, dir)) { - KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - KRVector3 dir_model_space = KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir)); + Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); + Vector3 dir_model_space = Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir)); KRHitInfo hitinfo_model_space; if(hitinfo.didHit()) { - KRVector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); - hitinfo_model_space = KRHitInfo(hit_position_model_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode()); + Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); + hitinfo_model_space = KRHitInfo(hit_position_model_space, Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode()); } if(m_models[0]->rayCast(v0_model_space, dir_model_space, hitinfo_model_space)) { - KRVector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); - hitinfo = KRHitInfo(hit_position_world_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); + Vector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); + hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); return true; } } @@ -142,14 +142,14 @@ bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &h return false; } -bool KRCollider::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRCollider::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) { if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set loadModel(); if(m_models.size()) { KRAABB sphereCastBounds = KRAABB( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions - KRVector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), - KRVector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius) + Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), + Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius) ); if(getBounds().intersects(sphereCastBounds)) { @@ -198,7 +198,7 @@ void KRCollider::render(KRCamera *pCamera, std::vector &point_li KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRCollider.h b/kraken/KRCollider.h index 25dc740..9892a05 100755 --- a/kraken/KRCollider.h +++ b/kraken/KRCollider.h @@ -57,9 +57,9 @@ public: virtual void loadXML(tinyxml2::XMLElement *e); virtual KRAABB getBounds(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); - bool rayCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); - bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); + bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); unsigned int getLayerMask(); void setLayerMask(unsigned int layer_mask); diff --git a/kraken/KRDirectionalLight.cpp b/kraken/KRDirectionalLight.cpp index f8eb00d..5e7ccd2 100755 --- a/kraken/KRDirectionalLight.cpp +++ b/kraken/KRDirectionalLight.cpp @@ -28,12 +28,12 @@ std::string KRDirectionalLight::getElementName() { return "directional_light"; } -KRVector3 KRDirectionalLight::getWorldLightDirection() { +Vector3 KRDirectionalLight::getWorldLightDirection() { return KRMat4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); } -KRVector3 KRDirectionalLight::getLocalLightDirection() { - return KRVector3::Up(); //&KRF HACK changed from KRVector3::Forward(); - to compensate for the way Maya handles post rotation. +Vector3 KRDirectionalLight::getLocalLightDirection() { + return Vector3::Up(); //&KRF HACK changed from Vector3::Forward(); - to compensate for the way Maya handles post rotation. } @@ -52,13 +52,13 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor float max_depth = 1.0f; */ - KRAABB worldSpacefrustrumSliceBounds = KRAABB(KRVector3(-1.0f, -1.0f, -1.0f), KRVector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix())); + KRAABB worldSpacefrustrumSliceBounds = KRAABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix())); worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); - KRVector3 shadowLook = -KRVector3::Normalize(getWorldLightDirection()); + Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection()); - KRVector3 shadowUp(0.0, 1.0, 0.0); - if(KRVector3::Dot(shadowUp, shadowLook) > 0.99f) shadowUp = KRVector3(0.0, 0.0, 1.0); // Ensure shadow look direction is not parallel with the shadowUp direction + Vector3 shadowUp(0.0, 1.0, 0.0); + if(Vector3::Dot(shadowUp, shadowLook) > 0.99f) shadowUp = Vector3(0.0, 0.0, 1.0); // Ensure shadow look direction is not parallel with the shadowUp direction // KRMat4 matShadowView = KRMat4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp); // KRMat4 matShadowProjection = KRMat4(); @@ -76,8 +76,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor matShadowProjection *= matBias; KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection); - KRAABB prevShadowBounds = KRAABB(-KRVector3::One(), KRVector3::One(), KRMat4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix())); - KRAABB minimumShadowBounds = KRAABB(-KRVector3::One(), KRVector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix())); + KRAABB prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix())); + KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix())); minimumShadowBounds.scale(1.0f / KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); if(!prevShadowBounds.contains(minimumShadowBounds) || !shadowValid[iShadow] || true) { // FINDME, HACK - Re-generating the shadow map every frame. This should only be needed if the shadow contains non-static geometry m_shadowViewports[iShadow] = newShadowViewport; @@ -105,12 +105,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector & matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.invert(); - KRVector3 light_direction_view_space = getWorldLightDirection(); + Vector3 light_direction_view_space = getWorldLightDirection(); light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space); light_direction_view_space.normalize(); KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector(), this_light, std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector(), this_light, std::vector(), 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector(), this_light, std::vector(), 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space); pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); diff --git a/kraken/KRDirectionalLight.h b/kraken/KRDirectionalLight.h index 4c99365..05f7de7 100755 --- a/kraken/KRDirectionalLight.h +++ b/kraken/KRDirectionalLight.h @@ -19,8 +19,8 @@ public: virtual ~KRDirectionalLight(); virtual std::string getElementName(); - KRVector3 getLocalLightDirection(); - KRVector3 getWorldLightDirection(); + Vector3 getLocalLightDirection(); + Vector3 getWorldLightDirection(); virtual void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); virtual KRAABB getBounds(); diff --git a/kraken/KREngine.h b/kraken/KREngine.h index 97c6a3a..f29004b 100755 --- a/kraken/KREngine.h +++ b/kraken/KREngine.h @@ -31,7 +31,7 @@ // #include "KRTextureManager.h" #include "KRMat4.h" -#include "KRVector3.h" +#include "Vector3.h" #include "KRMesh.h" #include "KRScene.h" #include "KRContext.h" diff --git a/kraken/KRHelpers.cpp b/kraken/KRHelpers.cpp index 641d17b..6215972 100644 --- a/kraken/KRHelpers.cpp +++ b/kraken/KRHelpers.cpp @@ -9,7 +9,7 @@ void SetUniform(GLint location, const Vector2 &v) if (location != -1) GLDEBUG(glUniform2f(location, v.x, v.y)); } -void SetUniform(GLint location, const KRVector3 &v) +void SetUniform(GLint location, const Vector3 &v) { if (location != -1) GLDEBUG(glUniform3f(location, v.x, v.y, v.z)); } @@ -24,7 +24,7 @@ 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) +void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value) { // TODO - Increase number of digits after the decimal in floating point format (6 -> 12?) // FINDME, TODO - This needs optimization... @@ -35,9 +35,9 @@ void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, cons } } -const KRVector3 getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value) +const Vector3 getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const Vector3 &default_value) { - KRVector3 value; + Vector3 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) { diff --git a/kraken/KRHelpers.h b/kraken/KRHelpers.h index a498729..6ea3558 100644 --- a/kraken/KRHelpers.h +++ b/kraken/KRHelpers.h @@ -18,12 +18,12 @@ float const D2R = PI * 2 / 360; namespace kraken { void SetUniform(GLint location, const Vector2 &v); - void SetUniform(GLint location, const KRVector3 &v); + void SetUniform(GLint location, const Vector3 &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); + void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value); + const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value); } // namespace kraken #endif \ No newline at end of file diff --git a/kraken/KRHitInfo.cpp b/kraken/KRHitInfo.cpp index b0b376e..0a42323 100755 --- a/kraken/KRHitInfo.cpp +++ b/kraken/KRHitInfo.cpp @@ -34,13 +34,13 @@ KRHitInfo::KRHitInfo() { - m_position = KRVector3::Zero(); - m_normal = KRVector3::Zero(); + m_position = Vector3::Zero(); + m_normal = Vector3::Zero(); m_distance = 0.0f; m_node = NULL; } -KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance, KRNode *node) +KRHitInfo::KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node) { m_position = position; m_normal = normal; @@ -48,7 +48,7 @@ KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const f m_node = node; } -KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance) +KRHitInfo::KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance) { m_position = position; m_normal = normal; @@ -63,15 +63,15 @@ KRHitInfo::~KRHitInfo() bool KRHitInfo::didHit() const { - return m_normal != KRVector3::Zero(); + return m_normal != Vector3::Zero(); } -KRVector3 KRHitInfo::getPosition() const +Vector3 KRHitInfo::getPosition() const { return m_position; } -KRVector3 KRHitInfo::getNormal() const +Vector3 KRHitInfo::getNormal() const { return m_normal; } diff --git a/kraken/KRHitInfo.h b/kraken/KRHitInfo.h index e2242dd..efd4d5c 100755 --- a/kraken/KRHitInfo.h +++ b/kraken/KRHitInfo.h @@ -41,12 +41,12 @@ class KRNode; class KRHitInfo { public: KRHitInfo(); - KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance); - KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance, KRNode *node); + KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance); + KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node); ~KRHitInfo(); - KRVector3 getPosition() const; - KRVector3 getNormal() const; + Vector3 getPosition() const; + Vector3 getNormal() const; float getDistance() const; KRNode *getNode() const; bool didHit() const; @@ -55,8 +55,8 @@ public: private: KRNode *m_node; - KRVector3 m_position; - KRVector3 m_normal; + Vector3 m_position; + Vector3 m_normal; float m_distance; }; diff --git a/kraken/KRLODGroup.cpp b/kraken/KRLODGroup.cpp index e3cbe52..c392f12 100755 --- a/kraken/KRLODGroup.cpp +++ b/kraken/KRLODGroup.cpp @@ -14,7 +14,7 @@ KRLODGroup::KRLODGroup(KRScene &scene, std::string name) : KRNode(scene, name) { m_min_distance = 0.0f; m_max_distance = 0.0f; - m_reference = KRAABB(KRVector3::Zero(), KRVector3::Zero()); + m_reference = KRAABB(Vector3::Zero(), Vector3::Zero()); m_use_world_units = true; } @@ -71,7 +71,7 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e) z = 0.0f; } - m_reference.min = KRVector3(x,y,z); + m_reference.min = Vector3(x,y,z); x=0.0f; y=0.0f; z=0.0f; if(e->QueryFloatAttribute("reference_max_x", &x) != tinyxml2::XML_SUCCESS) { @@ -83,7 +83,7 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e) if(e->QueryFloatAttribute("reference_max_z", &z) != tinyxml2::XML_SUCCESS) { z = 0.0f; } - m_reference.max = KRVector3(x,y,z); + m_reference.max = Vector3(x,y,z); m_use_world_units = true; if(e->QueryBoolAttribute("use_world_units", &m_use_world_units) != tinyxml2::XML_SUCCESS) { @@ -114,19 +114,19 @@ KRNode::LodVisibility KRLODGroup::calcLODVisibility(const KRViewport &viewport) float sqr_distance; float sqr_prestream_distance; - KRVector3 world_camera_position = viewport.getCameraPosition(); - KRVector3 local_camera_position = worldToLocal(world_camera_position); - KRVector3 local_reference_point = m_reference.nearestPoint(local_camera_position); + Vector3 world_camera_position = viewport.getCameraPosition(); + Vector3 local_camera_position = worldToLocal(world_camera_position); + Vector3 local_reference_point = m_reference.nearestPoint(local_camera_position); if(m_use_world_units) { - KRVector3 world_reference_point = localToWorld(local_reference_point); + Vector3 world_reference_point = localToWorld(local_reference_point); sqr_distance = (world_camera_position - world_reference_point).sqrMagnitude() * (lod_bias * lod_bias); sqr_prestream_distance = getContext().KRENGINE_PRESTREAM_DISTANCE * getContext().KRENGINE_PRESTREAM_DISTANCE; } else { sqr_distance = (local_camera_position - local_reference_point).sqrMagnitude() * (lod_bias * lod_bias); - KRVector3 world_reference_point = localToWorld(local_reference_point); - sqr_prestream_distance = worldToLocal(KRVector3::Normalize(world_reference_point - world_camera_position) * getContext().KRENGINE_PRESTREAM_DISTANCE).sqrMagnitude(); // TODO, FINDME - Optimize with precalc? + Vector3 world_reference_point = localToWorld(local_reference_point); + sqr_prestream_distance = worldToLocal(Vector3::Normalize(world_reference_point - world_camera_position) * getContext().KRENGINE_PRESTREAM_DISTANCE).sqrMagnitude(); // TODO, FINDME - Optimize with precalc? } diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index 68e6574..e7d9e1d 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -26,7 +26,7 @@ KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name) { m_intensity = 1.0f; m_dust_particle_intensity = 1.0f; - m_color = KRVector3::One(); + m_color = Vector3::One(); m_flareTexture = ""; m_pFlareTexture = NULL; m_flareSize = 0.0; @@ -86,7 +86,7 @@ void KRLight::loadXML(tinyxml2::XMLElement *e) { if(e->QueryFloatAttribute("color_b", &z) != tinyxml2::XML_SUCCESS) { z = 1.0; } - m_color = KRVector3(x,y,z); + m_color = Vector3(x,y,z); if(e->QueryFloatAttribute("intensity", &m_intensity) != tinyxml2::XML_SUCCESS) { m_intensity = 100.0; @@ -156,11 +156,11 @@ float KRLight::getIntensity() { return m_intensity; } -const KRVector3 &KRLight::getColor() { +const Vector3 &KRLight::getColor() { return m_color; } -void KRLight::setColor(const KRVector3 &color) { +void KRLight::setColor(const Vector3 &color) { m_color = color; } @@ -220,10 +220,10 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); - pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), KRVector3::Zero())); + pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), Vector3::Zero())); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size); KRDataBlock particle_index_data; @@ -256,7 +256,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES); - if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, KRVector4::Zero())) { int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5; float slice_near = -pCamera->settings.getPerspectiveNearZ(); @@ -284,7 +284,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix(); } - if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery)); #if TARGET_OS_IPHONE @@ -332,7 +332,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light // Render light flare on transparency pass KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE); @@ -449,7 +449,7 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera) // Use shader program KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP, KRVector3::Zero(), 0.0f, KRVector4::Zero()); + getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, KRVector4::Zero()); getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true); diff --git a/kraken/KRLight.h b/kraken/KRLight.h index 247a5d4..65e3d2e 100755 --- a/kraken/KRLight.h +++ b/kraken/KRLight.h @@ -34,8 +34,8 @@ public: float getIntensity(); void setDecayStart(float decayStart); float getDecayStart(); - const KRVector3 &getColor(); - void setColor(const KRVector3 &color); + const Vector3 &getColor(); + void setColor(const Vector3 &color); void setFlareTexture(std::string flare_texture); void setFlareSize(float flare_size); @@ -54,7 +54,7 @@ protected: float m_intensity; float m_decayStart; - KRVector3 m_color; + Vector3 m_color; std::string m_flareTexture; KRTexture *m_pFlareTexture; diff --git a/kraken/KRMat4.cpp b/kraken/KRMat4.cpp index 708c62e..0998070 100755 --- a/kraken/KRMat4.cpp +++ b/kraken/KRMat4.cpp @@ -49,7 +49,7 @@ KRMat4::KRMat4(float *pMat) { memcpy(c, pMat, sizeof(float) * 16); } -KRMat4::KRMat4(const KRVector3 &axis_x, const KRVector3 &axis_y, const KRVector3 &axis_z, const KRVector3 &trans) +KRMat4::KRMat4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans) { c[0] = axis_x.x; c[1] = axis_x.y; c[2] = axis_x.z; c[3] = 0.0f; c[4] = axis_y.x; c[5] = axis_y.y; c[6] = axis_y.z; c[7] = 0.0f; @@ -155,7 +155,7 @@ void KRMat4::translate(float x, float y, float z) { *this *= newMatrix; } -void KRMat4::translate(const KRVector3 &v) +void KRMat4::translate(const Vector3 &v) { translate(v.x, v.y, v.z); } @@ -217,7 +217,7 @@ void KRMat4::scale(float x, float y, float z) { *this *= newMatrix; } -void KRMat4::scale(const KRVector3 &v) { +void KRMat4::scale(const Vector3 &v) { scale(v.x, v.y, v.z); } @@ -313,9 +313,9 @@ void KRMat4::transpose() { memcpy(c, trans, sizeof(float) * 16); } -/* Dot Product, returning KRVector3 */ -KRVector3 KRMat4::Dot(const KRMat4 &m, const KRVector3 &v) { - return KRVector3( +/* Dot Product, returning Vector3 */ +Vector3 KRMat4::Dot(const KRMat4 &m, const Vector3 &v) { + return Vector3( v.c[0] * m.c[0] + v.c[1] * m.c[4] + v.c[2] * m.c[8] + m.c[12], v.c[0] * m.c[1] + v.c[1] * m.c[5] + v.c[2] * m.c[9] + m.c[13], v.c[0] * m.c[2] + v.c[1] * m.c[6] + v.c[2] * m.c[10] + m.c[14] @@ -355,9 +355,9 @@ KRVector4 KRMat4::Dot4(const KRMat4 &m, const KRVector4 &v) { } // Dot product without including translation; useful for transforming normals and tangents -KRVector3 KRMat4::DotNoTranslate(const KRMat4 &m, const KRVector3 &v) +Vector3 KRMat4::DotNoTranslate(const KRMat4 &m, const Vector3 &v) { - return KRVector3( + return Vector3( v.x * m.c[0] + v.y * m.c[4] + v.z * m.c[8], v.x * m.c[1] + v.y * m.c[5] + v.z * m.c[9], v.x * m.c[2] + v.y * m.c[6] + v.z * m.c[10] @@ -365,24 +365,24 @@ KRVector3 KRMat4::DotNoTranslate(const KRMat4 &m, const KRVector3 &v) } /* Dot Product, returning w component as if it were a KRVector4 (This will be deprecated once KRVector4 is implemented instead*/ -float KRMat4::DotW(const KRMat4 &m, const KRVector3 &v) { +float KRMat4::DotW(const KRMat4 &m, const Vector3 &v) { return v.x * m.c[0*4 + 3] + v.y * m.c[1*4 + 3] + v.z * m.c[2*4 + 3] + m.c[3*4 + 3]; } /* Dot Product followed by W-divide */ -KRVector3 KRMat4::DotWDiv(const KRMat4 &m, const KRVector3 &v) { +Vector3 KRMat4::DotWDiv(const KRMat4 &m, const Vector3 &v) { KRVector4 r = Dot4(m, KRVector4(v, 1.0f)); - return KRVector3(r) / r.w; + return Vector3(r) / r.w; } -KRMat4 KRMat4::LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, const KRVector3 &upDirection) +KRMat4 KRMat4::LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection) { KRMat4 matLookat; - KRVector3 lookat_z_axis = lookAtPos - cameraPos; + Vector3 lookat_z_axis = lookAtPos - cameraPos; lookat_z_axis.normalize(); - KRVector3 lookat_x_axis = KRVector3::Cross(upDirection, lookat_z_axis); + Vector3 lookat_x_axis = Vector3::Cross(upDirection, lookat_z_axis); lookat_x_axis.normalize(); - KRVector3 lookat_y_axis = KRVector3::Cross(lookat_z_axis, lookat_x_axis); + Vector3 lookat_y_axis = Vector3::Cross(lookat_z_axis, lookat_x_axis); matLookat.getPointer()[0] = lookat_x_axis.x; matLookat.getPointer()[1] = lookat_y_axis.x; @@ -396,9 +396,9 @@ KRMat4 KRMat4::LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, co matLookat.getPointer()[9] = lookat_y_axis.z; matLookat.getPointer()[10] = lookat_z_axis.z; - matLookat.getPointer()[12] = -KRVector3::Dot(lookat_x_axis, cameraPos); - matLookat.getPointer()[13] = -KRVector3::Dot(lookat_y_axis, cameraPos); - matLookat.getPointer()[14] = -KRVector3::Dot(lookat_z_axis, cameraPos); + matLookat.getPointer()[12] = -Vector3::Dot(lookat_x_axis, cameraPos); + matLookat.getPointer()[13] = -Vector3::Dot(lookat_y_axis, cameraPos); + matLookat.getPointer()[14] = -Vector3::Dot(lookat_z_axis, cameraPos); return matLookat; } @@ -417,7 +417,7 @@ KRMat4 KRMat4::Transpose(const KRMat4 &m) return matTranspose; } -KRMat4 KRMat4::Translation(const KRVector3 &v) +KRMat4 KRMat4::Translation(const Vector3 &v) { KRMat4 m; m[12] = v.x; @@ -427,7 +427,7 @@ KRMat4 KRMat4::Translation(const KRVector3 &v) return m; } -KRMat4 KRMat4::Rotation(const KRVector3 &v) +KRMat4 KRMat4::Rotation(const Vector3 &v) { KRMat4 m; m.rotate(v.x, X_AXIS); @@ -436,7 +436,7 @@ KRMat4 KRMat4::Rotation(const KRVector3 &v) return m; } -KRMat4 KRMat4::Scaling(const KRVector3 &v) +KRMat4 KRMat4::Scaling(const Vector3 &v) { KRMat4 m; m.scale(v); diff --git a/kraken/KRMaterial.cpp b/kraken/KRMaterial.cpp index 7d67182..186b624 100755 --- a/kraken/KRMaterial.cpp +++ b/kraken/KRMaterial.cpp @@ -44,10 +44,10 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont m_pNormalMap = NULL; m_pReflectionMap = NULL; m_pReflectionCube = NULL; - m_ambientColor = KRVector3::Zero(); - m_diffuseColor = KRVector3::One(); - m_specularColor = KRVector3::One(); - m_reflectionColor = KRVector3::Zero(); + m_ambientColor = Vector3::Zero(); + m_diffuseColor = Vector3::One(); + m_specularColor = Vector3::One(); + m_reflectionColor = Vector3::Zero(); m_tr = (GLfloat)1.0f; m_ns = (GLfloat)0.0f; m_ambientMap = ""; @@ -186,19 +186,19 @@ KRMaterial::alpha_mode_type KRMaterial::getAlphaMode() { return m_alpha_mode; } -void KRMaterial::setAmbient(const KRVector3 &c) { +void KRMaterial::setAmbient(const Vector3 &c) { m_ambientColor = c; } -void KRMaterial::setDiffuse(const KRVector3 &c) { +void KRMaterial::setDiffuse(const Vector3 &c) { m_diffuseColor = c; } -void KRMaterial::setSpecular(const KRVector3 &c) { +void KRMaterial::setSpecular(const Vector3 &c) { m_specularColor = c; } -void KRMaterial::setReflection(const KRVector3 &c) { +void KRMaterial::setReflection(const Vector3 &c) { m_reflectionColor = c; } @@ -302,7 +302,7 @@ void KRMaterial::getTextures() } } -bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, float lod_coverage) { +bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage) { bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap; getTextures(); @@ -310,7 +310,7 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh Vector2 default_scale = Vector2::One(); Vector2 default_offset = Vector2::Zero(); - bool bHasReflection = m_reflectionColor != KRVector3::Zero(); + bool bHasReflection = m_reflectionColor != Vector3::Zero(); bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->settings.bEnableDiffuseMap; bool bNormalMap = m_pNormalMap != NULL && pCamera->settings.bEnableNormalMap; bool bSpecMap = m_pSpecularMap != NULL && pCamera->settings.bEnableSpecMap; @@ -334,12 +334,12 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh for(int bone_index=0; bone_index < bones.size(); bone_index++) { KRBone *bone = bones[bone_index]; -// KRVector3 initialRotation = bone->getInitialLocalRotation(); -// KRVector3 rotation = bone->getLocalRotation(); -// KRVector3 initialTranslation = bone->getInitialLocalTranslation(); -// KRVector3 translation = bone->getLocalTranslation(); -// KRVector3 initialScale = bone->getInitialLocalScale(); -// KRVector3 scale = bone->getLocalScale(); +// Vector3 initialRotation = bone->getInitialLocalRotation(); +// Vector3 rotation = bone->getLocalRotation(); +// Vector3 initialTranslation = bone->getInitialLocalTranslation(); +// Vector3 translation = bone->getLocalTranslation(); +// Vector3 initialScale = bone->getInitialLocalScale(); +// Vector3 scale = bone->getLocalScale(); // //printf("%s - delta rotation: %.4f %.4f %.4f\n", bone->getName().c_str(), (rotation.x - initialRotation.x) * 180.0 / M_PI, (rotation.y - initialRotation.y) * 180.0 / M_PI, (rotation.z - initialRotation.z) * 180.0 / M_PI); //printf("%s - delta translation: %.4f %.4f %.4f\n", bone->getName().c_str(), translation.x - initialTranslation.x, translation.y - initialTranslation.y, translation.z - initialTranslation.z); @@ -365,14 +365,14 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) { // We pre-multiply the light color with the material color in the forward renderer - pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, KRVector3(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z)); + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z)); } else { pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor); } if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) { // We pre-multiply the light color with the material color in the forward renderer - pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, KRVector3(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z)); + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z)); } else { pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor); } diff --git a/kraken/KRMaterial.h b/kraken/KRMaterial.h index c683475..2a5af2d 100755 --- a/kraken/KRMaterial.h +++ b/kraken/KRMaterial.h @@ -69,10 +69,10 @@ public: void setReflectionMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset); void setReflectionCube(std::string texture_name); void setNormalMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset); - void setAmbient(const KRVector3 &c); - void setDiffuse(const KRVector3 &c); - void setSpecular(const KRVector3 &c); - void setReflection(const KRVector3 &c); + void setAmbient(const Vector3 &c); + void setDiffuse(const Vector3 &c); + void setSpecular(const Vector3 &c); + void setReflection(const Vector3 &c); void setTransparency(GLfloat a); void setShininess(GLfloat s); void setAlphaMode(alpha_mode_type blend_mode); @@ -82,7 +82,7 @@ public: bool isTransparent(); const std::string &getName() const; - bool bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, float lod_coverage = 0.0f); + bool bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f); bool needsVertexTangents(); @@ -116,10 +116,10 @@ private: Vector2 m_normalMapScale; Vector2 m_normalMapOffset; - KRVector3 m_ambientColor; // Ambient rgb - KRVector3 m_diffuseColor; // Diffuse rgb - KRVector3 m_specularColor; // Specular rgb - KRVector3 m_reflectionColor; // Reflection rgb + Vector3 m_ambientColor; // Ambient rgb + Vector3 m_diffuseColor; // Diffuse rgb + Vector3 m_specularColor; // Specular rgb + Vector3 m_reflectionColor; // Reflection rgb //GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb //GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb diff --git a/kraken/KRMaterialManager.cpp b/kraken/KRMaterialManager.cpp index a4eb890..944f783 100755 --- a/kraken/KRMaterialManager.cpp +++ b/kraken/KRMaterialManager.cpp @@ -162,49 +162,49 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) { char *pScan2 = szSymbol[1]; float r = strtof(pScan2, &pScan2); if(cSymbols == 2) { - pMaterial->setAmbient(KRVector3(r, r, r)); + pMaterial->setAmbient(Vector3(r, r, r)); } else if(cSymbols == 4) { pScan2 = szSymbol[2]; float g = strtof(pScan2, &pScan2); pScan2 = szSymbol[3]; float b = strtof(pScan2, &pScan2); - pMaterial->setAmbient(KRVector3(r, g, b)); + pMaterial->setAmbient(Vector3(r, g, b)); } } else if(strcmp(szSymbol[0], "kd") == 0) { char *pScan2 = szSymbol[1]; float r = strtof(pScan2, &pScan2); if(cSymbols == 2) { - pMaterial->setDiffuse(KRVector3(r, r, r)); + pMaterial->setDiffuse(Vector3(r, r, r)); } else if(cSymbols == 4) { pScan2 = szSymbol[2]; float g = strtof(pScan2, &pScan2); pScan2 = szSymbol[3]; float b = strtof(pScan2, &pScan2); - pMaterial->setDiffuse(KRVector3(r, g, b)); + pMaterial->setDiffuse(Vector3(r, g, b)); } } else if(strcmp(szSymbol[0], "ks") == 0) { char *pScan2 = szSymbol[1]; float r = strtof(pScan2, &pScan2); if(cSymbols == 2) { - pMaterial->setSpecular(KRVector3(r, r, r)); + pMaterial->setSpecular(Vector3(r, r, r)); } else if(cSymbols == 4) { pScan2 = szSymbol[2]; float g = strtof(pScan2, &pScan2); pScan2 = szSymbol[3]; float b = strtof(pScan2, &pScan2); - pMaterial->setSpecular(KRVector3(r, g, b)); + pMaterial->setSpecular(Vector3(r, g, b)); } } else if(strcmp(szSymbol[0], "kr") == 0) { char *pScan2 = szSymbol[1]; float r = strtof(pScan2, &pScan2); if(cSymbols == 2) { - pMaterial->setReflection(KRVector3(r, r, r)); + pMaterial->setReflection(Vector3(r, r, r)); } else if(cSymbols == 4) { pScan2 = szSymbol[2]; float g = strtof(pScan2, &pScan2); pScan2 = szSymbol[3]; float b = strtof(pScan2, &pScan2); - pMaterial->setReflection(KRVector3(r, g, b)); + pMaterial->setReflection(Vector3(r, g, b)); } } else if(strcmp(szSymbol[0], "tr") == 0) { char *pScan2 = szSymbol[1]; diff --git a/kraken/KRMesh.cpp b/kraken/KRMesh.cpp index e9cdb0c..f20eb57 100755 --- a/kraken/KRMesh.cpp +++ b/kraken/KRMesh.cpp @@ -159,8 +159,8 @@ void KRMesh::loadPack(KRDataBlock *data) { m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8); m_pIndexBaseData->lock(); - m_minPoint = KRVector3(ph.minx, ph.miny, ph.minz); - m_maxPoint = KRVector3(ph.maxx, ph.maxy, ph.maxz); + m_minPoint = Vector3(ph.minx, ph.miny, ph.minz); + m_maxPoint = Vector3(ph.maxx, ph.maxy, ph.maxz); updateAttributeOffsets(); } @@ -254,7 +254,7 @@ kraken_stream_level KRMesh::getStreamLevel() return stream_level; } -void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const KRVector3 &rim_color, float rim_power, float lod_coverage) { +void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const Vector3 &rim_color, float rim_power, float lod_coverage) { //fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { @@ -532,7 +532,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool bool use_short_uvb = true; if(use_short_vertexes) { - for(std::vector::const_iterator itr=mi.vertices.begin(); itr != mi.vertices.end(); itr++) { + for(std::vector::const_iterator itr=mi.vertices.begin(); itr != mi.vertices.end(); itr++) { if(fabsf((*itr).x) > 1.0f || fabsf((*itr).y) > 1.0f || fabsf((*itr).z) > 1.0f) { use_short_vertexes = false; } @@ -638,7 +638,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool memset(getVertexData(), 0, m_vertex_size * mi.vertices.size()); for(int iVertex=0; iVertex < mi.vertices.size(); iVertex++) { - KRVector3 source_vertex = mi.vertices[iVertex]; + Vector3 source_vertex = mi.vertices[iVertex]; setVertexPosition(iVertex, source_vertex); if(mi.bone_names.size()) { for(int bone_weight_index=0; bone_weight_index iVertex) { - setVertexNormal(iVertex, KRVector3::Normalize(mi.normals[iVertex])); + setVertexNormal(iVertex, Vector3::Normalize(mi.normals[iVertex])); } if(mi.tangents.size() > iVertex) { - setVertexTangent(iVertex, KRVector3::Normalize(mi.tangents[iVertex])); + setVertexTangent(iVertex, Vector3::Normalize(mi.tangents[iVertex])); } } @@ -697,19 +697,19 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool if(calculate_normals || calculate_tangents) { // NOTE: This will not work properly if the vertices are already indexed for(int iVertex=0; iVertex < mi.vertices.size(); iVertex+= 3) { - KRVector3 p1 = getVertexPosition(iVertex); - KRVector3 p2 = getVertexPosition(iVertex+1); - KRVector3 p3 = getVertexPosition(iVertex+2); - KRVector3 v1 = p2 - p1; - KRVector3 v2 = p3 - p1; + Vector3 p1 = getVertexPosition(iVertex); + Vector3 p2 = getVertexPosition(iVertex+1); + Vector3 p3 = getVertexPosition(iVertex+2); + Vector3 v1 = p2 - p1; + Vector3 v2 = p3 - p1; // -- Calculate normal if missing -- if(calculate_normals) { - KRVector3 first_normal = getVertexNormal(iVertex); + Vector3 first_normal = getVertexNormal(iVertex); if(first_normal.x == 0.0f && first_normal.y == 0.0f && first_normal.z == 0.0f) { // Note - We don't take into consideration smoothing groups or smoothing angles when generating normals; all generated normals represent flat shaded polygons - KRVector3 normal = KRVector3::Cross(v1, v2); + Vector3 normal = Vector3::Cross(v1, v2); normal.normalize(); setVertexNormal(iVertex, normal); @@ -720,7 +720,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool // -- Calculate tangent vector for normal mapping -- if(calculate_tangents) { - KRVector3 first_tangent = getVertexTangent(iVertex); + Vector3 first_tangent = getVertexTangent(iVertex); if(first_tangent.x == 0.0f && first_tangent.y == 0.0f && first_tangent.z == 0.0f) { Vector2 uv0 = getVertexUVA(iVertex); @@ -731,7 +731,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool Vector2 st2 = Vector2(uv2.x - uv0.x, uv2.y - uv0.y); double coef = 1/ (st1.x * st2.y - st2.x * st1.y); - KRVector3 tangent( + Vector3 tangent( coef * ((v1.x * st2.y) + (v2.x * -st1.y)), coef * ((v1.y * st2.y) + (v2.y * -st1.y)), coef * ((v1.z * st2.y) + (v2.z * -st1.y)) @@ -762,11 +762,11 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool optimize(); } -KRVector3 KRMesh::getMinPoint() const { +Vector3 KRMesh::getMinPoint() const { return m_minPoint; } -KRVector3 KRMesh::getMaxPoint() const { +Vector3 KRMesh::getMaxPoint() const { return m_maxPoint; } @@ -857,39 +857,39 @@ int KRMesh::getVertexCount(int submesh) const return getSubmesh(submesh)->vertex_count; } -KRVector3 KRMesh::getVertexPosition(int index) const +Vector3 KRMesh::getVertexPosition(int index) const { if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]); - return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); + return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); } else if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); + return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); } else { - return KRVector3::Zero(); + return Vector3::Zero(); } } -KRVector3 KRMesh::getVertexNormal(int index) const +Vector3 KRMesh::getVertexNormal(int index) const { if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) { short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]); - return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); + return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); } else if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL])); + return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL])); } else { - return KRVector3::Zero(); + return Vector3::Zero(); } } -KRVector3 KRMesh::getVertexTangent(int index) const +Vector3 KRMesh::getVertexTangent(int index) const { if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) { short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]); - return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); + return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); } else if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) { - return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT])); + return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT])); } else { - return KRVector3::Zero(); + return Vector3::Zero(); } } @@ -917,7 +917,7 @@ Vector2 KRMesh::getVertexUVB(int index) const } } -void KRMesh::setVertexPosition(int index, const KRVector3 &v) +void KRMesh::setVertexPosition(int index, const Vector3 &v) { if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]); @@ -932,7 +932,7 @@ void KRMesh::setVertexPosition(int index, const KRVector3 &v) } } -void KRMesh::setVertexNormal(int index, const KRVector3 &v) +void KRMesh::setVertexNormal(int index, const Vector3 &v) { if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) { short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]); @@ -947,7 +947,7 @@ void KRMesh::setVertexNormal(int index, const KRVector3 &v) } } -void KRMesh::setVertexTangent(int index, const KRVector3 & v) +void KRMesh::setVertexTangent(int index, const Vector3 & v) { if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) { short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]); @@ -1104,9 +1104,9 @@ KRMesh::model_format_t KRMesh::getModelFormat() const return f; } -bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTriangle3 &tri, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo) +bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo) { - KRVector3 hit_point; + Vector3 hit_point; if(tri.rayCast(start, dir, hit_point)) { // ---===--- hit_point is in triangle ---===--- @@ -1122,7 +1122,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTrian distance_v0 /= distance_total; distance_v1 /= distance_total; distance_v2 /= distance_total; - KRVector3 normal = KRVector3::Normalize(tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)); + Vector3 normal = Vector3::Normalize(tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)); hitinfo = KRHitInfo(hit_point, normal, new_hit_distance); return true; @@ -1138,7 +1138,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTrian } -bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, KRHitInfo &hitinfo) const +bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, KRHitInfo &hitinfo) const { m_pData->lock(); bool hit_found = false; @@ -1184,7 +1184,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, KRHitInfo &hi } -bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo) const +bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const { m_pData->lock(); @@ -1236,13 +1236,13 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const return hit_found; } -bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo) +bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo) { - KRVector3 dir = KRVector3::Normalize(v1 - v0); - KRVector3 start = v0; + Vector3 dir = Vector3::Normalize(v1 - v0); + Vector3 start = v0; - KRVector3 new_hit_point; + Vector3 new_hit_point; float new_hit_distance; KRTriangle3 world_tri = KRTriangle3(KRMat4::Dot(model_to_world, tri[0]), KRMat4::Dot(model_to_world, tri[1]), KRMat4::Dot(model_to_world, tri[2])); @@ -1259,7 +1259,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const distance_v0 /= distance_total; distance_v1 /= distance_total; distance_v2 /= distance_total; - KRVector3 normal = KRVector3::Normalize(KRMat4::DotNoTranslate(model_to_world, (tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)))); + Vector3 normal = Vector3::Normalize(KRMat4::DotNoTranslate(model_to_world, (tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)))); */ hitinfo = KRHitInfo(new_hit_point, world_tri.calculateNormal(), new_hit_distance); return true; @@ -1269,11 +1269,11 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const return false; } -bool KRMesh::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const +bool KRMesh::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const { m_pData->lock(); KRHitInfo new_hitinfo; - KRVector3 dir = KRVector3::Normalize(v1 - v0); + Vector3 dir = Vector3::Normalize(v1 - v0); if(rayCast(v0, dir, new_hitinfo)) { if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) { // The hit was between v1 and v2 @@ -1333,11 +1333,11 @@ void KRMesh::convertToIndexed() for(int i=0; i < vertex_count; i++) { - KRVector3 vertex_position = getVertexPosition(source_index); + Vector3 vertex_position = getVertexPosition(source_index); Vector2 vertex_uva = getVertexUVA(source_index); Vector2 vertex_uvb = getVertexUVB(source_index); - KRVector3 vertex_normal = getVertexNormal(source_index); - KRVector3 vertex_tangent = getVertexTangent(source_index); + Vector3 vertex_normal = getVertexNormal(source_index); + Vector3 vertex_tangent = getVertexTangent(source_index); std::vector vertex_bone_indexes; if(has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES)) { vertex_bone_indexes.push_back(getBoneIndex(source_index, 0)); diff --git a/kraken/KRMesh.h b/kraken/KRMesh.h index 4a3d6a7..f329ae9 100755 --- a/kraken/KRMesh.h +++ b/kraken/KRMesh.h @@ -96,13 +96,13 @@ public: typedef struct { model_format_t format; - std::vector vertices; + std::vector vertices; std::vector<__uint16_t> vertex_indexes; std::vector > vertex_index_bases; std::vector uva; std::vector uvb; - std::vector normals; - std::vector tangents; + std::vector normals; + std::vector tangents; std::vector submesh_starts; std::vector submesh_lengths; std::vector material_names; @@ -112,7 +112,7 @@ public: std::vector > bone_weights; } mesh_info; - void render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const KRVector3 &rim_color, float rim_power, float lod_coverage = 0.0f); + void render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f); std::string m_lodBaseName; @@ -131,8 +131,8 @@ public: GLfloat getMaxDimension(); - KRVector3 getMinPoint() const; - KRVector3 getMaxPoint() const; + Vector3 getMinPoint() const; + Vector3 getMaxPoint() const; class Submesh { public: @@ -185,17 +185,17 @@ public: int getSubmeshCount() const; int getVertexCount(int submesh) const; int getTriangleVertexIndex(int submesh, int index) const; - KRVector3 getVertexPosition(int index) const; - KRVector3 getVertexNormal(int index) const; - KRVector3 getVertexTangent(int index) const; + Vector3 getVertexPosition(int index) const; + Vector3 getVertexNormal(int index) const; + Vector3 getVertexTangent(int index) const; Vector2 getVertexUVA(int index) const; Vector2 getVertexUVB(int index) const; int getBoneIndex(int index, int weight_index) const; float getBoneWeight(int index, int weight_index) const; - void setVertexPosition(int index, const KRVector3 &v); - void setVertexNormal(int index, const KRVector3 &v); - void setVertexTangent(int index, const KRVector3 & v); + void setVertexPosition(int index, const Vector3 &v); + void setVertexNormal(int index, const Vector3 &v); + void setVertexTangent(int index, const Vector3 & v); void setVertexUVA(int index, const Vector2 &v); void setVertexUVB(int index, const Vector2 &v); void setBoneIndex(int index, int weight_index, int bone_index); @@ -211,9 +211,9 @@ public: model_format_t getModelFormat() const; - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const; - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const; - bool sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo) const; + bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const; + bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo) const; + bool sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const; static int GetLODCoverage(const std::string &name); @@ -230,8 +230,8 @@ private: void getSubmeshes(); void getMaterials(); - static bool rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTriangle3 &tri, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo); - static bool sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo); + static bool rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo); + static bool sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo); int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model) vector m_materials; @@ -240,7 +240,7 @@ private: bool m_hasTransparency; - KRVector3 m_minPoint, m_maxPoint; + Vector3 m_minPoint, m_maxPoint; diff --git a/kraken/KRMeshCube.cpp b/kraken/KRMeshCube.cpp index e4f433d..87b7cb3 100755 --- a/kraken/KRMeshCube.cpp +++ b/kraken/KRMeshCube.cpp @@ -38,20 +38,20 @@ KRMeshCube::KRMeshCube(KRContext &context) : KRMesh(context, "__cube") KRMesh::mesh_info mi; - mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); + mi.vertices.push_back(Vector3(1.0, 1.0, 1.0)); + mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0)); + mi.vertices.push_back(Vector3(1.0,-1.0, 1.0)); + mi.vertices.push_back(Vector3(-1.0,-1.0, 1.0)); + mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0)); + mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0)); + mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0)); + mi.vertices.push_back(Vector3(1.0, 1.0, 1.0)); + mi.vertices.push_back(Vector3(1.0, 1.0,-1.0)); + mi.vertices.push_back(Vector3(1.0,-1.0, 1.0)); + mi.vertices.push_back(Vector3(1.0,-1.0,-1.0)); + mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0)); + mi.vertices.push_back(Vector3(1.0, 1.0,-1.0)); + mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0)); mi.submesh_starts.push_back(0); diff --git a/kraken/KRMeshManager.h b/kraken/KRMeshManager.h index 83210e9..3a65397 100755 --- a/kraken/KRMeshManager.h +++ b/kraken/KRMeshManager.h @@ -127,7 +127,7 @@ public: GLfloat x; GLfloat y; GLfloat z; - } KRVector3D; + } Vector3D; typedef struct { GLfloat u; @@ -135,12 +135,12 @@ public: } TexCoord; typedef struct { - KRVector3D vertex; + Vector3D vertex; TexCoord uva; } RandomParticleVertexData; typedef struct { - KRVector3D vertex; + Vector3D vertex; } VolumetricLightingVertexData; diff --git a/kraken/KRMeshQuad.cpp b/kraken/KRMeshQuad.cpp index b7eea7d..be1e173 100755 --- a/kraken/KRMeshQuad.cpp +++ b/kraken/KRMeshQuad.cpp @@ -38,10 +38,10 @@ KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad") KRMesh::mesh_info mi; - mi.vertices.push_back(KRVector3(-1.0f, -1.0f, 0.0f)); - mi.vertices.push_back(KRVector3(1.0f, -1.0f, 0.0f)); - mi.vertices.push_back(KRVector3(-1.0f, 1.0f, 0.0f)); - mi.vertices.push_back(KRVector3(1.0f, 1.0f, 0.0f)); + mi.vertices.push_back(Vector3(-1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(Vector3(1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(Vector3(-1.0f, 1.0f, 0.0f)); + mi.vertices.push_back(Vector3(1.0f, 1.0f, 0.0f)); mi.uva.push_back(Vector2(0.0f, 0.0f)); mi.uva.push_back(Vector2(1.0f, 0.0f)); diff --git a/kraken/KRMeshSphere.cpp b/kraken/KRMeshSphere.cpp index 9278154..9e491f3 100755 --- a/kraken/KRMeshSphere.cpp +++ b/kraken/KRMeshSphere.cpp @@ -52,25 +52,25 @@ KRMeshSphere::KRMeshSphere(KRContext &context) : KRMesh(context, "__sphere") ~Facet3() { } - KRVector3 p1; - KRVector3 p2; - KRVector3 p3; + Vector3 p1; + Vector3 p2; + Vector3 p3; }; std::vector f = std::vector(facet_count); int i,it; float a; - KRVector3 p[6] = { - KRVector3(0,0,1), - KRVector3(0,0,-1), - KRVector3(-1,-1,0), - KRVector3(1,-1,0), - KRVector3(1,1,0), - KRVector3(-1,1,0) + Vector3 p[6] = { + Vector3(0,0,1), + Vector3(0,0,-1), + Vector3(-1,-1,0), + Vector3(1,-1,0), + Vector3(1,1,0), + Vector3(-1,1,0) }; - KRVector3 pa,pb,pc; + Vector3 pa,pb,pc; int nt = 0,ntold; /* Create the level 0 object */ diff --git a/kraken/KRModel.cpp b/kraken/KRModel.cpp index 1e524fd..4964609 100755 --- a/kraken/KRModel.cpp +++ b/kraken/KRModel.cpp @@ -35,7 +35,7 @@ #include "KRContext.h" #include "KRMesh.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) { +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, Vector3 rim_color, float rim_power) : KRNode(scene, instance_name) { m_lightMap = light_map; m_pLightMap = NULL; m_model_name = model_name; @@ -79,12 +79,12 @@ 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"); - kraken::setXMLAttribute("rim_color", e, m_rim_color, KRVector3::Zero()); + kraken::setXMLAttribute("rim_color", e, m_rim_color, Vector3::Zero()); e->SetAttribute("rim_power", m_rim_power); return e; } -void KRModel::setRimColor(const KRVector3 &rim_color) +void KRModel::setRimColor(const Vector3 &rim_color) { m_rim_color = rim_color; } @@ -94,7 +94,7 @@ void KRModel::setRimPower(float rim_power) m_rim_power = rim_power; } -KRVector3 KRModel::getRimColor() +Vector3 KRModel::getRimColor() { return m_rim_color; } @@ -198,9 +198,9 @@ void KRModel::render(KRCamera *pCamera, std::vector &point_light KRMat4 matModel = getModelMatrix(); if(m_faces_camera) { - KRVector3 model_center = KRMat4::Dot(matModel, KRVector3::Zero()); - KRVector3 camera_pos = viewport.getCameraPosition(); - matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; + Vector3 model_center = KRMat4::Dot(matModel, Vector3::Zero()); + Vector3 camera_pos = viewport.getCameraPosition(); + matModel = KRQuaternion(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; } pModel->render(getName(), pCamera, point_lights, directional_lights, spot_lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel], m_rim_color, m_rim_power, lod_coverage); @@ -247,7 +247,7 @@ KRAABB KRModel::getBounds() { if(m_faces_camera) { KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); float max_dimension = normal_bounds.longest_radius(); - return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); + return KRAABB(normal_bounds.center()-Vector3(max_dimension), normal_bounds.center() + Vector3(max_dimension)); } else { if(!(m_boundsCachedMat == getModelMatrix())) { diff --git a/kraken/KRModel.h b/kraken/KRModel.h index 03ce05b..4d64ba7 100755 --- a/kraken/KRModel.h +++ b/kraken/KRModel.h @@ -47,7 +47,7 @@ class KRModel : public KRNode { public: - 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 = KRVector3::Zero(), float rim_power = 0.0f); + 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, Vector3 rim_color = Vector3::Zero(), float rim_power = 0.0f); virtual ~KRModel(); virtual std::string getElementName(); @@ -57,9 +57,9 @@ public: virtual KRAABB getBounds(); - void setRimColor(const KRVector3 &rim_color); + void setRimColor(const Vector3 &rim_color); void setRimPower(float rim_power); - KRVector3 getRimColor(); + Vector3 getRimColor(); float getRimPower(); void setLightMap(const std::string &name); @@ -88,7 +88,7 @@ private: KRAABB m_boundsCached; - KRVector3 m_rim_color; + Vector3 m_rim_color; float m_rim_power; }; diff --git a/kraken/KRNode.cpp b/kraken/KRNode.cpp index a78c30f..5ced6ed 100755 --- a/kraken/KRNode.cpp +++ b/kraken/KRNode.cpp @@ -28,28 +28,28 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext()) { m_name = name; - m_localScale = KRVector3::One(); - m_localRotation = KRVector3::Zero(); - m_localTranslation = KRVector3::Zero(); + m_localScale = Vector3::One(); + m_localRotation = Vector3::Zero(); + m_localTranslation = Vector3::Zero(); m_initialLocalTranslation = m_localTranslation; m_initialLocalScale = m_localScale; m_initialLocalRotation = m_localRotation; - m_rotationOffset = KRVector3::Zero(); - m_scalingOffset = KRVector3::Zero(); - m_rotationPivot = KRVector3::Zero(); - m_scalingPivot = KRVector3::Zero(); - m_preRotation = KRVector3::Zero(); - m_postRotation = KRVector3::Zero(); + m_rotationOffset = Vector3::Zero(); + m_scalingOffset = Vector3::Zero(); + m_rotationPivot = Vector3::Zero(); + m_scalingPivot = Vector3::Zero(); + m_preRotation = Vector3::Zero(); + m_postRotation = Vector3::Zero(); - m_initialRotationOffset = KRVector3::Zero(); - m_initialScalingOffset = KRVector3::Zero(); - m_initialRotationPivot = KRVector3::Zero(); - m_initialScalingPivot = KRVector3::Zero(); - m_initialPreRotation = KRVector3::Zero(); - m_initialPostRotation = KRVector3::Zero(); + m_initialRotationOffset = Vector3::Zero(); + m_initialScalingOffset = Vector3::Zero(); + m_initialRotationPivot = Vector3::Zero(); + m_initialScalingPivot = Vector3::Zero(); + m_initialPreRotation = Vector3::Zero(); + m_initialPostRotation = Vector3::Zero(); m_parentNode = NULL; m_pScene = &scene; @@ -123,15 +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()); - 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()); + kraken::setXMLAttribute("translate", e, m_localTranslation, Vector3::Zero()); + kraken::setXMLAttribute("scale", e, m_localScale, Vector3::One()); + kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / M_PI)), Vector3::Zero()); + kraken::setXMLAttribute("rotate_offset", e, m_rotationOffset, Vector3::Zero()); + kraken::setXMLAttribute("scale_offset", e, m_scalingOffset, Vector3::Zero()); + kraken::setXMLAttribute("rotate_pivot", e, m_rotationPivot, Vector3::Zero()); + kraken::setXMLAttribute("scale_pivot", e, m_scalingPivot, Vector3::Zero()); + kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / M_PI)), Vector3::Zero()); + kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / M_PI)), Vector3::Zero()); for(std::set::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) { KRNode *child = (*itr); @@ -142,19 +142,19 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { void KRNode::loadXML(tinyxml2::XMLElement *e) { m_name = e->Attribute("name"); - 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_localTranslation = kraken::getXMLAttribute("translate", e, Vector3::Zero()); + m_localScale = kraken::getXMLAttribute("scale", e, Vector3::One()); + m_localRotation = kraken::getXMLAttribute("rotate", e, Vector3::Zero()); m_localRotation *= M_PI / 180.0f; // Convert degrees to radians - m_preRotation = kraken::getXMLAttribute("pre_rotate", e, KRVector3::Zero()); + m_preRotation = kraken::getXMLAttribute("pre_rotate", e, Vector3::Zero()); m_preRotation *= M_PI / 180.0f; // Convert degrees to radians - m_postRotation = kraken::getXMLAttribute("post_rotate", e, KRVector3::Zero()); + m_postRotation = kraken::getXMLAttribute("post_rotate", e, Vector3::Zero()); m_postRotation *= M_PI / 180.0f; // Convert degrees to radians - 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_rotationOffset = kraken::getXMLAttribute("rotate_offset", e, Vector3::Zero()); + m_scalingOffset = kraken::getXMLAttribute("scale_offset", e, Vector3::Zero()); + m_rotationPivot = kraken::getXMLAttribute("rotate_pivot", e, Vector3::Zero()); + m_scalingPivot = kraken::getXMLAttribute("scale_pivot", e, Vector3::Zero()); m_initialLocalTranslation = m_localTranslation; m_initialLocalScale = m_localScale; @@ -191,7 +191,7 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) { } } -void KRNode::setLocalTranslation(const KRVector3 &v, bool set_original) { +void KRNode::setLocalTranslation(const Vector3 &v, bool set_original) { m_localTranslation = v; if(set_original) { m_initialLocalTranslation = v; @@ -200,7 +200,7 @@ void KRNode::setLocalTranslation(const KRVector3 &v, bool set_original) { invalidateModelMatrix(); } -void KRNode::setWorldTranslation(const KRVector3 &v) +void KRNode::setWorldTranslation(const Vector3 &v) { if(m_parentNode) { setLocalTranslation(KRMat4::Dot(m_parentNode->getInverseModelMatrix(), v)); @@ -210,21 +210,21 @@ void KRNode::setWorldTranslation(const KRVector3 &v) } -void KRNode::setWorldRotation(const KRVector3 &v) +void KRNode::setWorldRotation(const Vector3 &v) { if(m_parentNode) { setLocalRotation((KRQuaternion(v) * -m_parentNode->getWorldRotation()).eulerXYZ()); - setPreRotation(KRVector3::Zero()); - setPostRotation(KRVector3::Zero()); + setPreRotation(Vector3::Zero()); + setPostRotation(Vector3::Zero()); } else { setLocalRotation(v); - setPreRotation(KRVector3::Zero()); - setPostRotation(KRVector3::Zero()); + setPreRotation(Vector3::Zero()); + setPostRotation(Vector3::Zero()); } } -void KRNode::setWorldScale(const KRVector3 &v) +void KRNode::setWorldScale(const Vector3 &v) { if(m_parentNode) { setLocalScale(KRMat4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v)); @@ -233,7 +233,7 @@ void KRNode::setWorldScale(const KRVector3 &v) } } -void KRNode::setLocalScale(const KRVector3 &v, bool set_original) { +void KRNode::setLocalScale(const Vector3 &v, bool set_original) { m_localScale = v; if(set_original) { m_initialLocalScale = v; @@ -242,7 +242,7 @@ void KRNode::setLocalScale(const KRVector3 &v, bool set_original) { invalidateModelMatrix(); } -void KRNode::setLocalRotation(const KRVector3 &v, bool set_original) { +void KRNode::setLocalRotation(const Vector3 &v, bool set_original) { m_localRotation = v; if(set_original) { m_initialLocalRotation = v; @@ -252,7 +252,7 @@ void KRNode::setLocalRotation(const KRVector3 &v, bool set_original) { } -void KRNode::setRotationOffset(const KRVector3 &v, bool set_original) +void KRNode::setRotationOffset(const Vector3 &v, bool set_original) { m_rotationOffset = v; if(set_original) { @@ -262,7 +262,7 @@ void KRNode::setRotationOffset(const KRVector3 &v, bool set_original) invalidateModelMatrix(); } -void KRNode::setScalingOffset(const KRVector3 &v, bool set_original) +void KRNode::setScalingOffset(const Vector3 &v, bool set_original) { m_scalingOffset = v; if(set_original) { @@ -272,7 +272,7 @@ void KRNode::setScalingOffset(const KRVector3 &v, bool set_original) invalidateModelMatrix(); } -void KRNode::setRotationPivot(const KRVector3 &v, bool set_original) +void KRNode::setRotationPivot(const Vector3 &v, bool set_original) { m_rotationPivot = v; if(set_original) { @@ -281,7 +281,7 @@ void KRNode::setRotationPivot(const KRVector3 &v, bool set_original) } invalidateModelMatrix(); } -void KRNode::setScalingPivot(const KRVector3 &v, bool set_original) +void KRNode::setScalingPivot(const Vector3 &v, bool set_original) { m_scalingPivot = v; if(set_original) { @@ -290,7 +290,7 @@ void KRNode::setScalingPivot(const KRVector3 &v, bool set_original) } invalidateModelMatrix(); } -void KRNode::setPreRotation(const KRVector3 &v, bool set_original) +void KRNode::setPreRotation(const Vector3 &v, bool set_original) { m_preRotation = v; if(set_original) { @@ -299,7 +299,7 @@ void KRNode::setPreRotation(const KRVector3 &v, bool set_original) } invalidateModelMatrix(); } -void KRNode::setPostRotation(const KRVector3 &v, bool set_original) +void KRNode::setPostRotation(const Vector3 &v, bool set_original) { m_postRotation = v; if(set_original) { @@ -309,80 +309,80 @@ void KRNode::setPostRotation(const KRVector3 &v, bool set_original) invalidateModelMatrix(); } -const KRVector3 &KRNode::getRotationOffset() +const Vector3 &KRNode::getRotationOffset() { return m_rotationOffset; } -const KRVector3 &KRNode::getScalingOffset() +const Vector3 &KRNode::getScalingOffset() { return m_scalingOffset; } -const KRVector3 &KRNode::getRotationPivot() +const Vector3 &KRNode::getRotationPivot() { return m_rotationPivot; } -const KRVector3 &KRNode::getScalingPivot() +const Vector3 &KRNode::getScalingPivot() { return m_scalingPivot; } -const KRVector3 &KRNode::getPreRotation() +const Vector3 &KRNode::getPreRotation() { return m_preRotation; } -const KRVector3 &KRNode::getPostRotation() +const Vector3 &KRNode::getPostRotation() { return m_postRotation; } -const KRVector3 &KRNode::getInitialRotationOffset() +const Vector3 &KRNode::getInitialRotationOffset() { return m_initialRotationOffset; } -const KRVector3 &KRNode::getInitialScalingOffset() +const Vector3 &KRNode::getInitialScalingOffset() { return m_initialScalingOffset; } -const KRVector3 &KRNode::getInitialRotationPivot() +const Vector3 &KRNode::getInitialRotationPivot() { return m_initialRotationPivot; } -const KRVector3 &KRNode::getInitialScalingPivot() +const Vector3 &KRNode::getInitialScalingPivot() { return m_initialScalingPivot; } -const KRVector3 &KRNode::getInitialPreRotation() +const Vector3 &KRNode::getInitialPreRotation() { return m_initialPreRotation; } -const KRVector3 &KRNode::getInitialPostRotation() +const Vector3 &KRNode::getInitialPostRotation() { return m_initialPostRotation; } -const KRVector3 &KRNode::getLocalTranslation() { +const Vector3 &KRNode::getLocalTranslation() { return m_localTranslation; } -const KRVector3 &KRNode::getLocalScale() { +const Vector3 &KRNode::getLocalScale() { return m_localScale; } -const KRVector3 &KRNode::getLocalRotation() { +const Vector3 &KRNode::getLocalRotation() { return m_localRotation; } -const KRVector3 &KRNode::getInitialLocalTranslation() { +const Vector3 &KRNode::getInitialLocalTranslation() { return m_initialLocalTranslation; } -const KRVector3 &KRNode::getInitialLocalScale() { +const Vector3 &KRNode::getInitialLocalScale() { return m_initialLocalScale; } -const KRVector3 &KRNode::getInitialLocalRotation() { +const Vector3 &KRNode::getInitialLocalRotation() { return m_initialLocalRotation; } -const KRVector3 KRNode::getWorldTranslation() { - return localToWorld(KRVector3::Zero()); +const Vector3 KRNode::getWorldTranslation() { + return localToWorld(Vector3::Zero()); } -const KRVector3 KRNode::getWorldScale() { +const Vector3 KRNode::getWorldScale() { return KRMat4::DotNoTranslate(getModelMatrix(), m_localScale); } @@ -427,8 +427,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { if(e->QueryFloatAttribute("rim_power", &rim_power) != tinyxml2::XML_SUCCESS) { rim_power = 0.0f; } - KRVector3 rim_color = KRVector3::Zero(); - rim_color = kraken::getXMLAttribute("rim_color", e, KRVector3::Zero()); + Vector3 rim_color = Vector3::Zero(); + rim_color = kraken::getXMLAttribute("rim_color", e, Vector3::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); @@ -768,87 +768,87 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v) //printf("%s - ", m_name.c_str()); switch(attrib) { case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X: - setLocalTranslation(KRVector3(v, m_localTranslation.y, m_localTranslation.z)); + setLocalTranslation(Vector3(v, m_localTranslation.y, m_localTranslation.z)); break; case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y: - setLocalTranslation(KRVector3(m_localTranslation.x, v, m_localTranslation.z)); + setLocalTranslation(Vector3(m_localTranslation.x, v, m_localTranslation.z)); break; case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z: - setLocalTranslation(KRVector3(m_localTranslation.x, m_localTranslation.y, v)); + setLocalTranslation(Vector3(m_localTranslation.x, m_localTranslation.y, v)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_X: - setLocalScale(KRVector3(v, m_localScale.y, m_localScale.z)); + setLocalScale(Vector3(v, m_localScale.y, m_localScale.z)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_Y: - setLocalScale(KRVector3(m_localScale.x, v, m_localScale.z)); + setLocalScale(Vector3(m_localScale.x, v, m_localScale.z)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_Z: - setLocalScale(KRVector3(m_localScale.x, m_localScale.y, v)); + setLocalScale(Vector3(m_localScale.x, m_localScale.y, v)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_X: - setLocalRotation(KRVector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z)); + setLocalRotation(Vector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_Y: - setLocalRotation(KRVector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z)); + setLocalRotation(Vector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_Z: - setLocalRotation(KRVector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD)); + setLocalRotation(Vector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD)); break; case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_X: - setPreRotation(KRVector3(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z)); + setPreRotation(Vector3(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Y: - setPreRotation(KRVector3(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z)); + setPreRotation(Vector3(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Z: - setPreRotation(KRVector3(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD)); + setPreRotation(Vector3(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD)); break; case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_X: - setPostRotation(KRVector3(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z)); + setPostRotation(Vector3(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Y: - setPostRotation(KRVector3(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z)); + setPostRotation(Vector3(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z)); break; case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Z: - setPostRotation(KRVector3(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD)); + setPostRotation(Vector3(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_X: - setRotationPivot(KRVector3(v, m_rotationPivot.y, m_rotationPivot.z)); + setRotationPivot(Vector3(v, m_rotationPivot.y, m_rotationPivot.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Y: - setRotationPivot(KRVector3(m_rotationPivot.x, v, m_rotationPivot.z)); + setRotationPivot(Vector3(m_rotationPivot.x, v, m_rotationPivot.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Z: - setRotationPivot(KRVector3(m_rotationPivot.x, m_rotationPivot.y, v)); + setRotationPivot(Vector3(m_rotationPivot.x, m_rotationPivot.y, v)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_X: - setScalingPivot(KRVector3(v, m_scalingPivot.y, m_scalingPivot.z)); + setScalingPivot(Vector3(v, m_scalingPivot.y, m_scalingPivot.z)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Y: - setScalingPivot(KRVector3(m_scalingPivot.x, v, m_scalingPivot.z)); + setScalingPivot(Vector3(m_scalingPivot.x, v, m_scalingPivot.z)); break; case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Z: - setScalingPivot(KRVector3(m_scalingPivot.x, m_scalingPivot.y, v)); + setScalingPivot(Vector3(m_scalingPivot.x, m_scalingPivot.y, v)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_X: - setRotationOffset(KRVector3(v, m_rotationOffset.y, m_rotationOffset.z)); + setRotationOffset(Vector3(v, m_rotationOffset.y, m_rotationOffset.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Y: - setRotationOffset(KRVector3(m_rotationOffset.x, v, m_rotationOffset.z)); + setRotationOffset(Vector3(m_rotationOffset.x, v, m_rotationOffset.z)); break; case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Z: - setRotationOffset(KRVector3(m_rotationOffset.x, m_rotationOffset.y, v)); + setRotationOffset(Vector3(m_rotationOffset.x, m_rotationOffset.y, v)); break; case KRENGINE_NODE_SCALE_OFFSET_X: - setScalingOffset(KRVector3(v, m_scalingOffset.y, m_scalingOffset.z)); + setScalingOffset(Vector3(v, m_scalingOffset.y, m_scalingOffset.z)); break; case KRENGINE_NODE_SCALE_OFFSET_Y: - setScalingOffset(KRVector3(m_scalingOffset.x, v, m_scalingOffset.z)); + setScalingOffset(Vector3(m_scalingOffset.x, v, m_scalingOffset.z)); break; case KRENGINE_NODE_SCALE_OFFSET_Z: - setScalingOffset(KRVector3(m_scalingOffset.x, m_scalingOffset.y, v)); + setScalingOffset(Vector3(m_scalingOffset.x, m_scalingOffset.y, v)); break; } } @@ -917,12 +917,12 @@ KRNode::LodVisibility KRNode::getLODVisibility() return m_lod_visible; } -const KRVector3 KRNode::localToWorld(const KRVector3 &local_point) +const Vector3 KRNode::localToWorld(const Vector3 &local_point) { return KRMat4::Dot(getModelMatrix(), local_point); } -const KRVector3 KRNode::worldToLocal(const KRVector3 &world_point) +const Vector3 KRNode::worldToLocal(const Vector3 &world_point) { return KRMat4::Dot(getInverseModelMatrix(), world_point); } diff --git a/kraken/KRNode.h b/kraken/KRNode.h index e29c5b4..d083a8c 100755 --- a/kraken/KRNode.h +++ b/kraken/KRNode.h @@ -74,54 +74,54 @@ public: const std::set &getChildren(); KRNode *getParent(); - void setLocalTranslation(const KRVector3 &v, bool set_original = false); - void setLocalScale(const KRVector3 &v, bool set_original = false); - void setLocalRotation(const KRVector3 &v, bool set_original = false); + void setLocalTranslation(const Vector3 &v, bool set_original = false); + void setLocalScale(const Vector3 &v, bool set_original = false); + void setLocalRotation(const Vector3 &v, bool set_original = false); - void setRotationOffset(const KRVector3 &v, bool set_original = false); - void setScalingOffset(const KRVector3 &v, bool set_original = false); - void setRotationPivot(const KRVector3 &v, bool set_original = false); - void setScalingPivot(const KRVector3 &v, bool set_original = false); - void setPreRotation(const KRVector3 &v, bool set_original = false); - void setPostRotation(const KRVector3 &v, bool set_original = false); + void setRotationOffset(const Vector3 &v, bool set_original = false); + void setScalingOffset(const Vector3 &v, bool set_original = false); + void setRotationPivot(const Vector3 &v, bool set_original = false); + void setScalingPivot(const Vector3 &v, bool set_original = false); + void setPreRotation(const Vector3 &v, bool set_original = false); + void setPostRotation(const Vector3 &v, bool set_original = false); - const KRVector3 &getRotationOffset(); - const KRVector3 &getScalingOffset(); - const KRVector3 &getRotationPivot(); - const KRVector3 &getScalingPivot(); - const KRVector3 &getPreRotation(); - const KRVector3 &getPostRotation(); + const Vector3 &getRotationOffset(); + const Vector3 &getScalingOffset(); + const Vector3 &getRotationPivot(); + const Vector3 &getScalingPivot(); + const Vector3 &getPreRotation(); + const Vector3 &getPostRotation(); - const KRVector3 &getInitialRotationOffset(); - const KRVector3 &getInitialScalingOffset(); - const KRVector3 &getInitialRotationPivot(); - const KRVector3 &getInitialScalingPivot(); - const KRVector3 &getInitialPreRotation(); - const KRVector3 &getInitialPostRotation(); + const Vector3 &getInitialRotationOffset(); + const Vector3 &getInitialScalingOffset(); + const Vector3 &getInitialRotationPivot(); + const Vector3 &getInitialScalingPivot(); + const Vector3 &getInitialPreRotation(); + const Vector3 &getInitialPostRotation(); - const KRVector3 &getLocalTranslation(); - const KRVector3 &getLocalScale(); - const KRVector3 &getLocalRotation(); + const Vector3 &getLocalTranslation(); + const Vector3 &getLocalScale(); + const Vector3 &getLocalRotation(); - const KRVector3 &getInitialLocalTranslation(); - const KRVector3 &getInitialLocalScale(); - const KRVector3 &getInitialLocalRotation(); + const Vector3 &getInitialLocalTranslation(); + const Vector3 &getInitialLocalScale(); + const Vector3 &getInitialLocalRotation(); - const KRVector3 getWorldTranslation(); - const KRVector3 getWorldScale(); + const Vector3 getWorldTranslation(); + const Vector3 getWorldScale(); const KRQuaternion getWorldRotation(); const KRQuaternion getBindPoseWorldRotation(); const KRQuaternion getActivePoseWorldRotation(); - const KRVector3 localToWorld(const KRVector3 &local_point); - const KRVector3 worldToLocal(const KRVector3 &world_point); + const Vector3 localToWorld(const Vector3 &local_point); + const Vector3 worldToLocal(const Vector3 &world_point); - void setWorldTranslation(const KRVector3 &v); - void setWorldScale(const KRVector3 &v); - void setWorldRotation(const KRVector3 &v); + void setWorldTranslation(const Vector3 &v); + void setWorldScale(const Vector3 &v); + void setWorldRotation(const Vector3 &v); virtual KRAABB getBounds(); void invalidateBounds() const; @@ -186,27 +186,27 @@ public: virtual void setLODVisibility(LodVisibility lod_visibility); protected: - KRVector3 m_localTranslation; - KRVector3 m_localScale; - KRVector3 m_localRotation; + Vector3 m_localTranslation; + Vector3 m_localScale; + Vector3 m_localRotation; - KRVector3 m_rotationOffset; - KRVector3 m_scalingOffset; - KRVector3 m_rotationPivot; - KRVector3 m_scalingPivot; - KRVector3 m_preRotation; - KRVector3 m_postRotation; + Vector3 m_rotationOffset; + Vector3 m_scalingOffset; + Vector3 m_rotationPivot; + Vector3 m_scalingPivot; + Vector3 m_preRotation; + Vector3 m_postRotation; - KRVector3 m_initialLocalTranslation; - KRVector3 m_initialLocalScale; - KRVector3 m_initialLocalRotation; + Vector3 m_initialLocalTranslation; + Vector3 m_initialLocalScale; + Vector3 m_initialLocalRotation; - KRVector3 m_initialRotationOffset; - KRVector3 m_initialScalingOffset; - KRVector3 m_initialRotationPivot; - KRVector3 m_initialScalingPivot; - KRVector3 m_initialPreRotation; - KRVector3 m_initialPostRotation; + Vector3 m_initialRotationOffset; + Vector3 m_initialScalingOffset; + Vector3 m_initialRotationPivot; + Vector3 m_initialScalingPivot; + Vector3 m_initialPreRotation; + Vector3 m_initialPostRotation; LodVisibility m_lod_visible; diff --git a/kraken/KROctree.cpp b/kraken/KROctree.cpp index 641407f..b4bc9de 100755 --- a/kraken/KROctree.cpp +++ b/kraken/KROctree.cpp @@ -41,7 +41,7 @@ void KROctree::add(KRNode *pNode) bool bInsideRoot = false; while(!bInsideRoot) { KRAABB rootBounds = m_pRootNode->getBounds(); - KRVector3 rootSize = rootBounds.size(); + Vector3 rootSize = rootBounds.size(); if(nodeBounds.min.x < rootBounds.min.x || nodeBounds.min.y < rootBounds.min.y || nodeBounds.min.z < rootBounds.min.z) { m_pRootNode = new KROctreeNode(NULL, KRAABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode); } else if(nodeBounds.max.x > rootBounds.max.x || nodeBounds.max.y > rootBounds.max.y || nodeBounds.max.z > rootBounds.max.z) { @@ -97,7 +97,7 @@ std::set &KROctree::getOuterSceneNodes() } -bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctree::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; std::vector outer_colliders; @@ -118,7 +118,7 @@ bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hit return hit_found; } -bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctree::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; for(std::set::iterator outer_nodes_itr=m_outerSceneNodes.begin(); outer_nodes_itr != m_outerSceneNodes.end(); outer_nodes_itr++) { @@ -133,7 +133,7 @@ bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hit return hit_found; } -bool KROctree::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctree::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; std::vector outer_colliders; diff --git a/kraken/KROctree.h b/kraken/KROctree.h index 3374f47..1e60fc3 100755 --- a/kraken/KROctree.h +++ b/kraken/KROctree.h @@ -27,9 +27,9 @@ public: KROctreeNode *getRootNode(); std::set &getOuterSceneNodes(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); - bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); + bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); + bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); private: KROctreeNode *m_pRootNode; diff --git a/kraken/KROctreeNode.cpp b/kraken/KROctreeNode.cpp index 2b62c8a..5924a72 100755 --- a/kraken/KROctreeNode.cpp +++ b/kraken/KROctreeNode.cpp @@ -97,14 +97,14 @@ void KROctreeNode::add(KRNode *pNode) KRAABB KROctreeNode::getChildBounds(int iChild) { - KRVector3 center = m_bounds.center(); + Vector3 center = m_bounds.center(); return KRAABB( - KRVector3( + Vector3( (iChild & 1) == 0 ? m_bounds.min.x : center.x, (iChild & 2) == 0 ? m_bounds.min.y : center.y, (iChild & 4) == 0 ? m_bounds.min.z : center.z), - KRVector3( + Vector3( (iChild & 1) == 0 ? center.x : m_bounds.max.x, (iChild & 2) == 0 ? center.y : m_bounds.max.y, (iChild & 4) == 0 ? center.z : m_bounds.max.z) @@ -196,7 +196,7 @@ std::set &KROctreeNode::getSceneNodes() } -bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctreeNode::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; if(hitinfo.didHit() && v1 != hitinfo.getPosition()) { @@ -224,7 +224,7 @@ bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo return hit_found; } -bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctreeNode::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; if(hitinfo.didHit()) { @@ -252,7 +252,7 @@ bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo return hit_found; } -bool KROctreeNode::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KROctreeNode::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) { bool hit_found = false; /* @@ -264,7 +264,7 @@ bool KROctreeNode::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float ra } else { */ - KRAABB swept_bounds = KRAABB(KRVector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), KRVector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)); + KRAABB swept_bounds = KRAABB(Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)); // FINDME, TODO - Investigate AABB - swept sphere intersections or OBB - AABB intersections: "if(getBounds().intersectsSweptSphere(v0, v1, radius)) {" if(getBounds().intersects(swept_bounds)) { diff --git a/kraken/KROctreeNode.h b/kraken/KROctreeNode.h index eb1fe8a..72e1cf4 100755 --- a/kraken/KROctreeNode.h +++ b/kraken/KROctreeNode.h @@ -47,9 +47,9 @@ public: bool m_occlusionTested; bool m_activeQuery; - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); - bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); + bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); + bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); private: diff --git a/kraken/KRParticleSystemNewtonian.cpp b/kraken/KRParticleSystemNewtonian.cpp index 3dc6d86..72dca96 100755 --- a/kraken/KRParticleSystemNewtonian.cpp +++ b/kraken/KRParticleSystemNewtonian.cpp @@ -41,7 +41,7 @@ tinyxml2::XMLElement *KRParticleSystemNewtonian::saveXML( tinyxml2::XMLNode *par KRAABB KRParticleSystemNewtonian::getBounds() { - return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); + return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix()); } void KRParticleSystemNewtonian::physicsUpdate(float deltaTime) @@ -76,8 +76,8 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vectorgetShaderManager()->getShader("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - KRVector3 rim_color; KRVector4 fade_color; - if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + Vector3 rim_color; KRVector4 fade_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f); KRDataBlock index_data; diff --git a/kraken/KRPointLight.cpp b/kraken/KRPointLight.cpp index d809482..516b67e 100755 --- a/kraken/KRPointLight.cpp +++ b/kraken/KRPointLight.cpp @@ -36,7 +36,7 @@ KRAABB KRPointLight::getBounds() { if(influence_radius < m_flareOcclusionSize) { influence_radius = m_flareOcclusionSize; } - return KRAABB(KRVector3(-influence_radius), KRVector3(influence_radius), getModelMatrix()); + return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix()); } void KRPointLight::render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) @@ -53,7 +53,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &point_ std::vector this_light; this_light.push_back(this); - KRVector3 light_position = getLocalTranslation(); + Vector3 light_position = getLocalTranslation(); float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); @@ -63,12 +63,12 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &point_ if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum - KRVector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position); + Vector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position); bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ()); KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector(), std::vector(), 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector(), std::vector(), 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); @@ -146,25 +146,25 @@ void KRPointLight::generateMesh() { ~Facet3() { } - KRVector3 p1; - KRVector3 p2; - KRVector3 p3; + Vector3 p1; + Vector3 p2; + Vector3 p3; }; std::vector f = std::vector(facet_count); int i,it; float a; - KRVector3 p[6] = { - KRVector3(0,0,1), - KRVector3(0,0,-1), - KRVector3(-1,-1,0), - KRVector3(1,-1,0), - KRVector3(1,1,0), - KRVector3(-1,1,0) + Vector3 p[6] = { + Vector3(0,0,1), + Vector3(0,0,-1), + Vector3(-1,-1,0), + Vector3(1,-1,0), + Vector3(1,1,0), + Vector3(-1,1,0) }; - KRVector3 pa,pb,pc; + Vector3 pa,pb,pc; int nt = 0,ntold; /* Create the level 0 object */ diff --git a/kraken/KRQuaternion.cpp b/kraken/KRQuaternion.cpp index 9eece12..e90ba87 100755 --- a/kraken/KRQuaternion.cpp +++ b/kraken/KRQuaternion.cpp @@ -64,17 +64,17 @@ KRQuaternion& KRQuaternion::operator =( const KRQuaternion& p ) { return *this; } -KRQuaternion::KRQuaternion(const KRVector3 &euler) { +KRQuaternion::KRQuaternion(const Vector3 &euler) { setEulerZYX(euler); } -KRQuaternion::KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector) { +KRQuaternion::KRQuaternion(const Vector3 &from_vector, const Vector3 &to_vector) { - KRVector3 a = KRVector3::Cross(from_vector, to_vector); + Vector3 a = Vector3::Cross(from_vector, to_vector); m_val[0] = a[0]; m_val[1] = a[1]; m_val[2] = a[2]; - m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + KRVector3::Dot(from_vector, to_vector); + m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + Vector3::Dot(from_vector, to_vector); normalize(); } @@ -82,14 +82,14 @@ KRQuaternion::~KRQuaternion() { } -void KRQuaternion::setEulerXYZ(const KRVector3 &euler) +void KRQuaternion::setEulerXYZ(const Vector3 &euler) { - *this = KRQuaternion::FromAngleAxis(KRVector3(1.0f, 0.0f, 0.0f), euler.x) - * KRQuaternion::FromAngleAxis(KRVector3(0.0f, 1.0f, 0.0f), euler.y) - * KRQuaternion::FromAngleAxis(KRVector3(0.0f, 0.0f, 1.0f), euler.z); + *this = KRQuaternion::FromAngleAxis(Vector3(1.0f, 0.0f, 0.0f), euler.x) + * KRQuaternion::FromAngleAxis(Vector3(0.0f, 1.0f, 0.0f), euler.y) + * KRQuaternion::FromAngleAxis(Vector3(0.0f, 0.0f, 1.0f), euler.z); } -void KRQuaternion::setEulerZYX(const KRVector3 &euler) { +void KRQuaternion::setEulerZYX(const Vector3 &euler) { // ZYX Order! float c1 = cos(euler[0] * 0.5f); float c2 = cos(euler[1] * 0.5f); @@ -112,22 +112,22 @@ float &KRQuaternion::operator [](unsigned i) { return m_val[i]; } -KRVector3 KRQuaternion::eulerXYZ() const { +Vector3 KRQuaternion::eulerXYZ() const { double a2 = 2 * (m_val[0] * m_val[2] - m_val[1] * m_val[3]); if(a2 <= -0.99999) { - return KRVector3( + return Vector3( 2.0 * atan2(m_val[1], m_val[0]), -PI * 0.5f, 0 ); } else if(a2 >= 0.99999) { - return KRVector3( + return Vector3( 2.0 * atan2(m_val[1], m_val[0]), PI * 0.5f, 0 ); } else { - return KRVector3( + return Vector3( atan2(2 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]), (1 - 2 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]))), asin(a2), atan2(2 * (m_val[0] * m_val[3] + m_val[1] * m_val[2]), (1 - 2 * (m_val[2] * m_val[2] + m_val[3] * m_val[3]))) @@ -283,7 +283,7 @@ KRMat4 KRQuaternion::rotationMatrix() const { KRMat4 matRotate; /* - KRVector3 euler = eulerXYZ(); + Vector3 euler = eulerXYZ(); matRotate.rotate(euler.x, X_AXIS); matRotate.rotate(euler.y, Y_AXIS); @@ -309,7 +309,7 @@ KRMat4 KRQuaternion::rotationMatrix() const { } -KRQuaternion KRQuaternion::FromAngleAxis(const KRVector3 &axis, float angle) +KRQuaternion KRQuaternion::FromAngleAxis(const Vector3 &axis, float angle) { float ha = angle * 0.5f; float sha = sin(ha); diff --git a/kraken/KRRenderSettings.cpp b/kraken/KRRenderSettings.cpp index 50ecee6..6266632 100755 --- a/kraken/KRRenderSettings.cpp +++ b/kraken/KRRenderSettings.cpp @@ -33,8 +33,8 @@ KRRenderSettings::KRRenderSettings() bEnableDeferredLighting = false; max_anisotropy = 4.0f; - ambient_intensity = KRVector3::Zero(); - light_intensity = KRVector3::One(); + ambient_intensity = Vector3::Zero(); + light_intensity = Vector3::One(); perspective_fov = 45.0 * D2R; perspective_nearz = 0.3f; // was 0.05f @@ -67,7 +67,7 @@ KRRenderSettings::KRRenderSettings() fog_near = 50.0f; fog_far = 500.0f; fog_density = 0.0005f; - fog_color = KRVector3(0.45, 0.45, 0.5); + fog_color = Vector3(0.45, 0.45, 0.5); fog_type = 0; dust_particle_intensity = 0.25f; diff --git a/kraken/KRRenderSettings.h b/kraken/KRRenderSettings.h index 429969d..b9c18d6 100755 --- a/kraken/KRRenderSettings.h +++ b/kraken/KRRenderSettings.h @@ -45,8 +45,8 @@ public: bool bEnableDiffuse; bool bEnableSpecular; bool bEnableDeferredLighting; - KRVector3 light_intensity; - KRVector3 ambient_intensity; + Vector3 light_intensity; + Vector3 ambient_intensity; float perspective_fov; int dof_quality; @@ -76,7 +76,7 @@ public: float fog_near; float fog_far; float fog_density; - KRVector3 fog_color; + Vector3 fog_color; int fog_type; // 0 = no fog, 1 = linear, 2 = exponential, 3 = exponential squared float dust_particle_intensity; diff --git a/kraken/KRResource+fbx.cpp b/kraken/KRResource+fbx.cpp index b9df160..95cd010 100755 --- a/kraken/KRResource+fbx.cpp +++ b/kraken/KRResource+fbx.cpp @@ -590,7 +590,7 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG // Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp) int node_has_n_points = 0; // this will be 3 if the node_frame_key_position is complete after the import animated properties loop - KRVector3 node_key_frame_position = KRVector3(0.0, 0.0, 0.0); + Vector3 node_key_frame_position = Vector3(0.0, 0.0, 0.0); // ADDED 3, 2013 by Peter to store the key frame (start location) of an animation // the x, y, z translation position of the animation will be extracted from the curves // as they are added to the animation layer in the loop below .. @@ -917,22 +917,22 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG // do we store it as node_local or store it as the world translation? or somewhere else ?? // - KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp - KRVector3 node_rotation = KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI; - KRVector3 node_scale = KRVector3(local_scale[0], local_scale[1], local_scale[2]); + Vector3 node_translation = Vector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp + Vector3 node_rotation = Vector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI; + Vector3 node_scale = Vector3(local_scale[0], local_scale[1], local_scale[2]); - KRVector3 node_rotation_offset = KRVector3(rotation_offset[0], rotation_offset[1], rotation_offset[2]); - KRVector3 node_scaling_offset = KRVector3(scaling_offset[0], scaling_offset[1], scaling_offset[2]); - KRVector3 node_rotation_pivot = KRVector3(rotation_pivot[0], rotation_pivot[1], rotation_pivot[2]); - KRVector3 node_scaling_pivot = KRVector3(scaling_pivot[0], scaling_pivot[1], scaling_pivot[2]); - KRVector3 node_pre_rotation, node_post_rotation; + Vector3 node_rotation_offset = Vector3(rotation_offset[0], rotation_offset[1], rotation_offset[2]); + Vector3 node_scaling_offset = Vector3(scaling_offset[0], scaling_offset[1], scaling_offset[2]); + Vector3 node_rotation_pivot = Vector3(rotation_pivot[0], rotation_pivot[1], rotation_pivot[2]); + Vector3 node_scaling_pivot = Vector3(scaling_pivot[0], scaling_pivot[1], scaling_pivot[2]); + Vector3 node_pre_rotation, node_post_rotation; if(rotation_active) { - node_pre_rotation = KRVector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI; - node_post_rotation = KRVector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI; + node_pre_rotation = Vector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI; + node_post_rotation = Vector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI; //&KRF HACK removing this line (above) to prevent the post rotation from corrupting the default light values; the FBX is importing a post rotation and setting it to -90 degrees } else { - node_pre_rotation = KRVector3::Zero(); - node_post_rotation = KRVector3::Zero(); + node_pre_rotation = Vector3::Zero(); + node_post_rotation = Vector3::Zero(); } // printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]); @@ -1115,15 +1115,15 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { // Ambient Color lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Ambient; - new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); + new_material->setAmbient(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse; - new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); + new_material->setDiffuse(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Specular Color (unique to Phong materials) lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular; - new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); + new_material->setSpecular(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive Color //lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Emissive; @@ -1155,18 +1155,18 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { //lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection; // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken - new_material->setReflection(KRVector3(/*lKFbxDouble3.Get()[0] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[1] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[2] * */lKFbxDouble1.Get())); + new_material->setReflection(Vector3(/*lKFbxDouble3.Get()[0] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[1] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[2] * */lKFbxDouble1.Get())); } else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) { // We found a Lambert material. // Ambient Color lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient; - new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); + new_material->setAmbient(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse; - new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); + new_material->setDiffuse(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive //lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Emissive; @@ -1306,10 +1306,10 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) { fbx_bind_pose_matrix = (*pose_list)[0].GetMatrix(pose_indices[0]); bind_pose = KRMat4( - KRVector3(fbx_bind_pose_matrix.GetColumn(0).mData), - KRVector3(fbx_bind_pose_matrix.GetColumn(1).mData), - KRVector3(fbx_bind_pose_matrix.GetColumn(2).mData), - KRVector3(fbx_bind_pose_matrix.GetColumn(3).mData) + Vector3(fbx_bind_pose_matrix.GetColumn(0).mData), + Vector3(fbx_bind_pose_matrix.GetColumn(1).mData), + Vector3(fbx_bind_pose_matrix.GetColumn(2).mData), + Vector3(fbx_bind_pose_matrix.GetColumn(3).mData) ); fprintf(stderr, "Found bind pose(s)!\n"); } @@ -1318,10 +1318,10 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe FbxAMatrix link_matrix; cluster->GetTransformLinkMatrix(link_matrix); mi.bone_bind_poses.push_back(KRMat4( - KRVector3(link_matrix.GetColumn(0).mData), - KRVector3(link_matrix.GetColumn(1).mData), - KRVector3(link_matrix.GetColumn(2).mData), - KRVector3(link_matrix.GetColumn(3).mData) + Vector3(link_matrix.GetColumn(0).mData), + Vector3(link_matrix.GetColumn(1).mData), + Vector3(link_matrix.GetColumn(2).mData), + Vector3(link_matrix.GetColumn(3).mData) )); int cluster_control_point_count = cluster->GetControlPointIndicesCount(); @@ -1381,11 +1381,11 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe // std::vector > bone_weights; // std::vector > bone_indexes; // -// std::vector vertices; +// std::vector vertices; // std::vector uva; // std::vector uvb; -// std::vector normals; -// std::vector tangents; +// std::vector normals; +// std::vector tangents; // std::vector submesh_lengths; // std::vector submesh_starts; // std::vector material_names; @@ -1434,7 +1434,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe // ----====---- Read Vertex Position ----====---- int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex); FbxVector4 v = control_points[lControlPointIndex]; - mi.vertices.push_back(KRVector3(v[0], v[1], v[2])); + mi.vertices.push_back(Vector3(v[0], v[1], v[2])); if(mi.bone_names.size() > 0) { control_point_weight_info_t &weight_info = control_point_weights[lControlPointIndex]; @@ -1484,7 +1484,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe FbxVector4 new_normal; if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) { - mi.normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2])); + mi.normals.push_back(Vector3(new_normal[0], new_normal[1], new_normal[2])); } /* @@ -1513,7 +1513,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe } } if(l == 0) { - mi.tangents.push_back(KRVector3(new_tangent[0], new_tangent[1], new_tangent[2])); + mi.tangents.push_back(Vector3(new_tangent[0], new_tangent[1], new_tangent[2])); } } @@ -1715,7 +1715,7 @@ KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) { } if(new_light) { - new_light->setColor(KRVector3(light_color[0], light_color[1], light_color[2])); + new_light->setColor(Vector3(light_color[0], light_color[1], light_color[2])); new_light->setIntensity(light_intensity); new_light->setDecayStart(light_decaystart); } diff --git a/kraken/KRResource+obj.cpp b/kraken/KRResource+obj.cpp index 664bc52..61cd85f 100755 --- a/kraken/KRResource+obj.cpp +++ b/kraken/KRResource+obj.cpp @@ -101,9 +101,9 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str int *pFaces = (int *)malloc(sizeof(int) * (cFaces + 1)); assert(pFaces != NULL); - std::vector indexed_vertices; + std::vector indexed_vertices; std::vector indexed_uva; - std::vector indexed_normals; + std::vector indexed_normals; int *pFace = pFaces; int *pMaterialFaces = pFace++; @@ -154,7 +154,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str y = strtof(pChar, &pChar); pChar = szSymbol[3]; z = strtof(pChar, &pChar); - indexed_vertices.push_back(KRVector3(x,y,z)); + indexed_vertices.push_back(Vector3(x,y,z)); } else if(strcmp(szSymbol[0], "vt") == 0) { // Vertex Texture UV Coordinate (vt) char *pChar = szSymbol[1]; @@ -173,7 +173,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str y = strtof(pChar, &pChar); pChar = szSymbol[3]; z = strtof(pChar, &pChar); - indexed_normals.push_back(KRVector3(x,y,z)); + indexed_normals.push_back(Vector3(x,y,z)); } else if(strcmp(szSymbol[0], "f") == 0) { // Face (f) int cFaceVertices = cSymbols - 1; @@ -249,10 +249,10 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str int *pMaterialEndFace = pFace + *pFace++; while(pFace < pMaterialEndFace && iVertex < cVertexData) { int cFaceVertexes = *pFace; - KRVector3 firstFaceVertex; - KRVector3 prevFaceVertex; - KRVector3 firstFaceNormal; - KRVector3 prevFaceNormal; + Vector3 firstFaceVertex; + Vector3 prevFaceVertex; + Vector3 firstFaceNormal; + Vector3 prevFaceNormal; Vector2 firstFaceUva; Vector2 prevFaceUva; for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) { @@ -268,14 +268,14 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str mi.uva.push_back(prevFaceUva); mi.normals.push_back(prevFaceNormal); } - KRVector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]]; + Vector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]]; Vector2 new_uva; if(pFace[iFaceVertex*3+2] >= 0) { new_uva = indexed_uva[pFace[iFaceVertex*3+2]]; } - KRVector3 normal; + Vector3 normal; if(pFace[iFaceVertex*3+3] >= 0){ - KRVector3 normal = indexed_normals[pFace[iFaceVertex*3+3]]; + Vector3 normal = indexed_normals[pFace[iFaceVertex*3+3]]; } mi.vertices.push_back(vertex); diff --git a/kraken/KRReverbZone.cpp b/kraken/KRReverbZone.cpp index 77200bd..21ce563 100755 --- a/kraken/KRReverbZone.cpp +++ b/kraken/KRReverbZone.cpp @@ -97,7 +97,7 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector &point_ KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); @@ -138,17 +138,17 @@ void KRReverbZone::setGradientDistance(float gradient_distance) KRAABB KRReverbZone::getBounds() { // Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box - return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); + return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix()); } -float KRReverbZone::getContainment(const KRVector3 &pos) +float KRReverbZone::getContainment(const Vector3 &pos) { KRAABB bounds = getBounds(); if(bounds.contains(pos)) { - KRVector3 size = bounds.size(); - KRVector3 diff = pos - bounds.center(); + Vector3 size = bounds.size(); + Vector3 diff = pos - bounds.center(); diff = diff * 2.0f; - diff = KRVector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); + diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); float d = diff.magnitude(); if(m_gradient_distance <= 0.0f) { diff --git a/kraken/KRReverbZone.h b/kraken/KRReverbZone.h index 4d1c117..798d2bc 100755 --- a/kraken/KRReverbZone.h +++ b/kraken/KRReverbZone.h @@ -37,7 +37,7 @@ public: virtual KRAABB getBounds(); - float getContainment(const KRVector3 &pos); + float getContainment(const Vector3 &pos); private: std::string m_zone; diff --git a/kraken/KRScene.cpp b/kraken/KRScene.cpp index 8acb613..607a967 100755 --- a/kraken/KRScene.cpp +++ b/kraken/KRScene.cpp @@ -208,7 +208,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi bool in_viewport = false; if(renderPass == KRNode::RENDER_PASS_PRESTREAM) { // When pre-streaming, objects are streamed in behind and in-front of the camera - KRAABB viewportExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + KRVector3(pCamera->settings.getPerspectiveFarZ())); + KRAABB viewportExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveFarZ())); in_viewport = octreeBounds.intersects(viewportExtents); } else { in_viewport = viewport.visible(pOctreeNode->getBounds()); @@ -227,7 +227,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi if(!bVisible) { // Assume bounding boxes are visible without occlusion test queries if the camera is inside the box. // The near clipping plane of the camera is taken into consideration by expanding the match area - KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + KRVector3(pCamera->settings.getPerspectiveNearZ())); + KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveNearZ())); bVisible = octreeBounds.intersects(cameraExtents); if(bVisible) { // Record the frame number in which the camera was within the bounds @@ -298,7 +298,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi GLDEBUG(glDepthMask(GL_FALSE)); } - if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero())) { GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); m_pContext->getMeshManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14); } @@ -565,7 +565,7 @@ void KRScene::addDefaultLights() { KRDirectionalLight *light1 = new KRDirectionalLight(*this, "default_light1"); - light1->setLocalRotation((KRQuaternion(KRVector3(0.0, M_PI * 0.10, 0.0)) * KRQuaternion(KRVector3(0.0, 0.0, -M_PI * 0.15))).eulerXYZ()); + light1->setLocalRotation((KRQuaternion(Vector3(0.0, M_PI * 0.10, 0.0)) * KRQuaternion(Vector3(0.0, 0.0, -M_PI * 0.15))).eulerXYZ()); m_pRootNode->addChild(light1); } @@ -574,22 +574,22 @@ KRAABB KRScene::getRootOctreeBounds() if(m_nodeTree.getRootNode()) { return m_nodeTree.getRootNode()->getBounds(); } else { - return KRAABB(-KRVector3::One(), KRVector3::One()); + return KRAABB(-Vector3::One(), Vector3::One()); } } -bool KRScene::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRScene::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) { return m_nodeTree.lineCast(v0, v1, hitinfo, layer_mask); } -bool KRScene::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRScene::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) { return m_nodeTree.rayCast(v0, dir, hitinfo, layer_mask); } -bool KRScene::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) +bool KRScene::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) { return m_nodeTree.sphereCast(v0, v1, radius, hitinfo, layer_mask); } diff --git a/kraken/KRScene.h b/kraken/KRScene.h index d5c36c9..e63d56b 100755 --- a/kraken/KRScene.h +++ b/kraken/KRScene.h @@ -65,9 +65,9 @@ public: kraken_stream_level getStreamLevel(); - bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); - bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); - bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); + bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); + bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); + bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); void renderFrame(GLint defaultFBO, float deltaTime, int width, int height); void render(KRCamera *pCamera, unordered_map &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame); diff --git a/kraken/KRShader.cpp b/kraken/KRShader.cpp index 811a7ea..77b0189 100755 --- a/kraken/KRShader.cpp +++ b/kraken/KRShader.cpp @@ -295,7 +295,7 @@ void KRShader::setUniform(int location, const Vector2 &value) } } } -void KRShader::setUniform(int location, const KRVector3 &value) +void KRShader::setUniform(int location, const Vector3 &value) { if(m_uniforms[location] != -1) { int value_index = m_uniform_value_index[location]; @@ -351,7 +351,7 @@ void KRShader::setUniform(int location, const KRMat4 &value) } } -bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) { +bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color) { if(m_iProgram == 0) { return false; } @@ -417,7 +417,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & inverseModelMatrix.invert(); // Bind the light direction vector - KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); + Vector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); lightDirObject.normalize(); setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); } @@ -438,7 +438,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) { // Transform location of camera to object space for calculation of specular halfVec - KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, viewport.getCameraPosition()); + Vector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, viewport.getCameraPosition()); setUniform(KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE, cameraPosObject); } } @@ -459,7 +459,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) { - KRVector3 view_space_model_origin = KRMat4::Dot(matModelView, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required + Vector3 view_space_model_origin = KRMat4::Dot(matModelView, Vector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required setUniform(KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN, view_space_model_origin); } diff --git a/kraken/KRShader.h b/kraken/KRShader.h index e9af40c..29e2bc5 100755 --- a/kraken/KRShader.h +++ b/kraken/KRShader.h @@ -46,7 +46,7 @@ public: virtual ~KRShader(); const char *getKey() const; - bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); + bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color); enum { KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0, @@ -140,7 +140,7 @@ public: std::vector m_uniform_value_float; std::vector m_uniform_value_int; std::vector m_uniform_value_vector2; - std::vector m_uniform_value_vector3; + std::vector m_uniform_value_vector3; std::vector m_uniform_value_vector4; std::vector m_uniform_value_mat4; @@ -150,7 +150,7 @@ public: void setUniform(int location, float value); void setUniform(int location, int value); void setUniform(int location, const Vector2 &value); - void setUniform(int location, const KRVector3 &value); + void setUniform(int location, const Vector3 &value); void setUniform(int location, const KRVector4 &value); void setUniform(int location, const KRMat4 &value); diff --git a/kraken/KRShaderManager.cpp b/kraken/KRShaderManager.cpp index 9431a35..e170c10 100755 --- a/kraken/KRShaderManager.cpp +++ b/kraken/KRShaderManager.cpp @@ -245,13 +245,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p return pShader; } -bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) +bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color) { KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f); return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power, fade_color); } -bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) +bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color) { if(pShader) { return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color); diff --git a/kraken/KRShaderManager.h b/kraken/KRShaderManager.h index 895ae0d..68b9823 100755 --- a/kraken/KRShaderManager.h +++ b/kraken/KRShaderManager.h @@ -60,9 +60,9 @@ public: KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); - bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); + bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color); - bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); + bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color); long getShaderHandlesUsed(); diff --git a/kraken/KRSpotLight.cpp b/kraken/KRSpotLight.cpp index f8018c5..1ef2449 100755 --- a/kraken/KRSpotLight.cpp +++ b/kraken/KRSpotLight.cpp @@ -55,7 +55,7 @@ KRAABB KRSpotLight::getBounds() { if(influence_radius < m_flareOcclusionSize) { influence_radius = m_flareOcclusionSize; } - return KRAABB(KRVector3(-influence_radius), KRVector3(influence_radius), getModelMatrix()); + return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix()); } diff --git a/kraken/KRSprite.cpp b/kraken/KRSprite.cpp index f41af7b..4ec18d3 100755 --- a/kraken/KRSprite.cpp +++ b/kraken/KRSprite.cpp @@ -77,7 +77,7 @@ float KRSprite::getSpriteAlpha() const } KRAABB KRSprite::getBounds() { - return KRAABB(-KRVector3::One() * 0.5f, KRVector3::One() * 0.5f, getModelMatrix()); + return KRAABB(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix()); } @@ -128,7 +128,7 @@ void KRSprite::render(KRCamera *pCamera, std::vector &point_ligh // Render light sprite on transparency pass KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha); m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE); m_pContext->getMeshManager()->bindVBO(&m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f); diff --git a/kraken/KRTriangle3.cpp b/kraken/KRTriangle3.cpp index e965fb2..44cec0e 100755 --- a/kraken/KRTriangle3.cpp +++ b/kraken/KRTriangle3.cpp @@ -11,16 +11,16 @@ using namespace kraken; namespace { - bool _intersectSphere(const KRVector3 &start, const KRVector3 &dir, const KRVector3 &sphere_center, float sphere_radius, float &distance) + bool _intersectSphere(const Vector3 &start, const Vector3 &dir, const Vector3 &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; + Vector3 Q = sphere_center - start; float c = Q.magnitude(); - float v = KRVector3::Dot(Q, dir); + float v = Vector3::Dot(Q, dir); float d = sphere_radius * sphere_radius - (c * c - v * v); @@ -40,27 +40,27 @@ namespace { } - bool _sameSide(const KRVector3 &p1, const KRVector3 &p2, const KRVector3 &a, const KRVector3 &b) + bool _sameSide(const Vector3 &p1, const Vector3 &p2, const Vector3 &a, const Vector3 &b) { - // TODO - Move to KRVector3 class? + // TODO - Move to Vector3 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; + Vector3 cp1 = Vector3::Cross(b - a, p1 - a); + Vector3 cp2 = Vector3::Cross(b - a, p2 - a); + if (Vector3::Dot(cp1, cp2) >= 0) return true; return false; } - KRVector3 _closestPointOnLine(const KRVector3 &a, const KRVector3 &b, const KRVector3 &p) + Vector3 _closestPointOnLine(const Vector3 &a, const Vector3 &b, const Vector3 &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); + Vector3 c = p - a; + Vector3 V = Vector3::Normalize(b - a); float d = (a - b).magnitude(); - float t = KRVector3::Dot(V, c); + float t = Vector3::Dot(V, c); // Check to see if ‘t’ is beyond the extents of the line segment @@ -75,7 +75,7 @@ namespace { namespace kraken { -KRTriangle3::KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3) +KRTriangle3::KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) { vert[0] = v1; vert[1] = v2; @@ -114,35 +114,35 @@ KRTriangle3& KRTriangle3::operator =(const KRTriangle3& b) return *this; } -KRVector3& KRTriangle3::operator[](unsigned int i) +Vector3& KRTriangle3::operator[](unsigned int i) { return vert[i]; } -KRVector3 KRTriangle3::operator[](unsigned int i) const +Vector3 KRTriangle3::operator[](unsigned int i) const { return vert[i]; } -bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector3 &hit_point) const +bool KRTriangle3::rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const { // algorithm based on Dan Sunday's implementation at http://geomalgorithms.com/a06-_intersect-2.html const float SMALL_NUM = 0.00000001; // anything that avoids division overflow - KRVector3 u, v, n; // triangle vectors - KRVector3 w0, w; // ray vectors + Vector3 u, v, n; // triangle vectors + Vector3 w0, w; // ray vectors float r, a, b; // params to calc ray-plane intersect // get triangle edge vectors and plane normal u = vert[1] - vert[0]; v = vert[2] - vert[0]; - n = KRVector3::Cross(u, v); // cross product - if (n == KRVector3::Zero()) // triangle is degenerate + n = Vector3::Cross(u, v); // cross product + if (n == Vector3::Zero()) // triangle is degenerate return false; // do not deal with this case w0 = start - vert[0]; - a = -KRVector3::Dot(n, w0); - b = KRVector3::Dot(n,dir); + a = -Vector3::Dot(n, w0); + b = Vector3::Dot(n,dir); if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane if (a == 0) return false; // ray lies in triangle plane @@ -158,16 +158,16 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector // for a segment, also test if (r > 1.0) => no intersect - KRVector3 plane_hit_point = start + dir * r; // intersect point of ray and plane + Vector3 plane_hit_point = start + dir * r; // intersect point of ray and plane // is plane_hit_point inside triangle? float uu, uv, vv, wu, wv, D; - uu = KRVector3::Dot(u,u); - uv = KRVector3::Dot(u,v); - vv = KRVector3::Dot(v,v); + uu = Vector3::Dot(u,u); + uv = Vector3::Dot(u,v); + vv = Vector3::Dot(v,v); w = plane_hit_point - vert[0]; - wu = KRVector3::Dot(w,u); - wv = KRVector3::Dot(w,v); + wu = Vector3::Dot(w,u); + wv = Vector3::Dot(w,v); D = uv * uv - uu * vv; // get and test parametric coords @@ -184,23 +184,23 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector return true; } -KRVector3 KRTriangle3::calculateNormal() const +Vector3 KRTriangle3::calculateNormal() const { - KRVector3 v1 = vert[1] - vert[0]; - KRVector3 v2 = vert[2] - vert[0]; + Vector3 v1 = vert[1] - vert[0]; + Vector3 v2 = vert[2] - vert[0]; - return KRVector3::Normalize(KRVector3::Cross(v1, v2)); + return Vector3::Normalize(Vector3::Cross(v1, v2)); } -KRVector3 KRTriangle3::closestPointOnTriangle(const KRVector3 &p) const +Vector3 KRTriangle3::closestPointOnTriangle(const Vector3 &p) const { - KRVector3 a = vert[0]; - KRVector3 b = vert[1]; - KRVector3 c = vert[2]; + Vector3 a = vert[0]; + Vector3 b = vert[1]; + Vector3 c = vert[2]; - KRVector3 Rab = _closestPointOnLine(a, b, p); - KRVector3 Rbc = _closestPointOnLine(b, c, p); - KRVector3 Rca = _closestPointOnLine(c, a, p); + Vector3 Rab = _closestPointOnLine(a, b, p); + Vector3 Rbc = _closestPointOnLine(b, c, p); + Vector3 Rca = _closestPointOnLine(c, a, p); // return closest [Rab, Rbc, Rca] to p; float sd_Rab = (p - Rab).sqrMagnitude(); @@ -216,21 +216,21 @@ KRVector3 KRTriangle3::closestPointOnTriangle(const KRVector3 &p) const } } -bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float radius, KRVector3 &hit_point, float &hit_distance) const +bool KRTriangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const { // Dir must be normalized const float SMALL_NUM = 0.001f; // anything that avoids division overflow - KRVector3 tri_normal = calculateNormal(); + Vector3 tri_normal = calculateNormal(); - float d = KRVector3::Dot(tri_normal, vert[0]); - float e = KRVector3::Dot(tri_normal, start) - radius; + float d = Vector3::Dot(tri_normal, vert[0]); + float e = Vector3::Dot(tri_normal, start) - radius; float cotangent_distance = e - d; - KRVector3 plane_intersect; + Vector3 plane_intersect; float plane_intersect_distance; - float denom = KRVector3::Dot(tri_normal, dir); + float denom = Vector3::Dot(tri_normal, dir); if(denom > -SMALL_NUM) { return false; // dir is co-planar with the triangle or going in the direction of the normal; no intersection @@ -261,7 +261,7 @@ bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float return true; } else { // Triangle does not contain point, cast ray back to sphere from closest point on triangle edge or vertice - KRVector3 closest_point = closestPointOnTriangle(plane_intersect); + Vector3 closest_point = closestPointOnTriangle(plane_intersect); float reverse_hit_distance; if(_intersectSphere(closest_point, -dir, start, radius, reverse_hit_distance)) { // Reverse cast hit sphere @@ -276,16 +276,16 @@ bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float } -bool KRTriangle3::containsPoint(const KRVector3 &p) const +bool KRTriangle3::containsPoint(const Vector3 &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 = vert[0], B = vert[1], C = vert[2]; + // Vector3 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) { + Vector3 vc1 = Vector3::Cross(vert[0] - vert[1], vert[0] - vert[2]); + if(fabs(Vector3::Dot(vert[0] - p, vc1)) <= SMALL_NUM) { return true; } } @@ -295,28 +295,28 @@ 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 = vert[0]; - KRVector3 B = vert[1]; - KRVector3 C = vert[2]; - KRVector3 P = p; + Vector3 A = vert[0]; + Vector3 B = vert[1]; + Vector3 C = vert[2]; + Vector3 P = p; // Prepare our barycentric variables - KRVector3 u = B - A; - KRVector3 v = C - A; - KRVector3 w = P - A; + Vector3 u = B - A; + Vector3 v = C - A; + Vector3 w = P - A; - KRVector3 vCrossW = KRVector3::Cross(v, w); - KRVector3 vCrossU = KRVector3::Cross(v, u); + Vector3 vCrossW = Vector3::Cross(v, w); + Vector3 vCrossU = Vector3::Cross(v, u); // Test sign of r - if (KRVector3::Dot(vCrossW, vCrossU) < 0) + if (Vector3::Dot(vCrossW, vCrossU) < 0) return false; - KRVector3 uCrossW = KRVector3::Cross(u, w); - KRVector3 uCrossV = KRVector3::Cross(u, v); + Vector3 uCrossW = Vector3::Cross(u, w); + Vector3 uCrossV = Vector3::Cross(u, v); // Test sign of t - if (KRVector3::Dot(uCrossW, uCrossV) < 0) + if (Vector3::Dot(uCrossW, uCrossV) < 0) return false; // At this point, we know that r and t and both > 0. diff --git a/kraken/KRVector4.cpp b/kraken/KRVector4.cpp index 9520e2a..cda6b53 100755 --- a/kraken/KRVector4.cpp +++ b/kraken/KRVector4.cpp @@ -51,7 +51,7 @@ KRVector4::KRVector4(const KRVector4 &v) { w = v.w; } -KRVector4::KRVector4(const KRVector3 &v, float W) { +KRVector4::KRVector4(const Vector3 &v, float W) { x = v.x; y = v.y; z = v.z; diff --git a/kraken/KRViewport.cpp b/kraken/KRViewport.cpp index ca73832..05963b8 100755 --- a/kraken/KRViewport.cpp +++ b/kraken/KRViewport.cpp @@ -95,12 +95,12 @@ const KRMat4 &KRViewport::getInverseProjectionMatrix() const return m_matInverseProjection; } -const KRVector3 &KRViewport::getCameraDirection() const +const Vector3 &KRViewport::getCameraDirection() const { return m_cameraDirection; } -const KRVector3 &KRViewport::getCameraPosition() const +const Vector3 &KRViewport::getCameraPosition() const { return m_cameraPosition; } @@ -120,8 +120,8 @@ void KRViewport::calculateDerivedValues() m_matViewProjection = m_matView * m_matProjection; m_matInverseView = KRMat4::Invert(m_matView); m_matInverseProjection = KRMat4::Invert(m_matProjection); - m_cameraPosition = KRMat4::Dot(m_matInverseView, KRVector3::Zero()); - m_cameraDirection = KRMat4::Dot(m_matInverseView, KRVector3(0.0, 0.0, 1.0)) - KRMat4::Dot(m_matInverseView, KRVector3(0.0, 0.0, 0.0)); + m_cameraPosition = KRMat4::Dot(m_matInverseView, Vector3::Zero()); + m_cameraDirection = KRMat4::Dot(m_matInverseView, Vector3(0.0, 0.0, 1.0)) - KRMat4::Dot(m_matInverseView, Vector3(0.0, 0.0, 0.0)); for(int i=0; i<8; i++) { m_frontToBackOrder[i] = i; @@ -174,10 +174,10 @@ float KRViewport::coverage(const KRAABB &b) const if(!visible(b)) { return 0.0f; // Culled out by view frustrum } else { - KRVector3 nearest_point = b.nearestPoint(getCameraPosition()); + Vector3 nearest_point = b.nearestPoint(getCameraPosition()); float distance = (nearest_point - getCameraPosition()).magnitude(); - KRVector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance); + Vector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance); float screen_depth = distance / 1000.0f; @@ -189,7 +189,7 @@ float KRViewport::coverage(const KRAABB &b) const Vector2 screen_max; // Loop through all corners and transform them to screen space for(int i=0; i<8; i++) { - KRVector3 screen_pos = KRMat4::DotWDiv(m_matViewProjection, KRVector3(i & 1 ? b.min.x : b.max.x, i & 2 ? b.min.y : b.max.y, i & 4 ? b.min.z : b.max.z)); + Vector3 screen_pos = KRMat4::DotWDiv(m_matViewProjection, Vector3(i & 1 ? b.min.x : b.max.x, i & 2 ? b.min.y : b.max.y, i & 4 ? b.min.z : b.max.z)); if(i==0) { screen_min = screen_pos.xy(); screen_max = screen_pos.xy(); diff --git a/kraken/KRViewport.h b/kraken/KRViewport.h index e3b1951..249cad0 100755 --- a/kraken/KRViewport.h +++ b/kraken/KRViewport.h @@ -25,8 +25,8 @@ public: const KRMat4 &getViewProjectionMatrix() const; const KRMat4 &getInverseViewMatrix() const; const KRMat4 &getInverseProjectionMatrix() const; - const KRVector3 &getCameraDirection() const; - const KRVector3 &getCameraPosition() const; + const Vector3 &getCameraDirection() const; + const Vector3 &getCameraPosition() const; const int *getFrontToBackOrder() const; const int *getBackToFrontOrder() const; void setSize(const Vector2 &size); @@ -57,8 +57,8 @@ private: KRMat4 m_matViewProjection; KRMat4 m_matInverseView; KRMat4 m_matInverseProjection; - KRVector3 m_cameraDirection; - KRVector3 m_cameraPosition; + Vector3 m_cameraDirection; + Vector3 m_cameraPosition; int m_frontToBackOrder[8]; int m_backToFrontOrder[8]; diff --git a/kraken/public/KRAABB.h b/kraken/public/KRAABB.h index e623f7d..b267ae4 100644 --- a/kraken/public/KRAABB.h +++ b/kraken/public/KRAABB.h @@ -14,7 +14,7 @@ #include // 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()(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/KRMat4.h b/kraken/public/KRMat4.h index 2822e4d..6c8dbcc 100644 --- a/kraken/public/KRMat4.h +++ b/kraken/public/KRMat4.h @@ -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 diff --git a/kraken/public/KRQuaternion.h b/kraken/public/KRQuaternion.h index 3a86b97..595b869 100644 --- a/kraken/public/KRQuaternion.h +++ b/kraken/public/KRQuaternion.h @@ -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); diff --git a/kraken/public/KRTriangle3.h b/kraken/public/KRTriangle3.h index 89575f4..a97849d 100644 --- a/kraken/public/KRTriangle3.h +++ b/kraken/public/KRTriangle3.h @@ -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 diff --git a/kraken/public/KRVector4.h b/kraken/public/KRVector4.h index 51621c3..3db0ed0 100644 --- a/kraken/public/KRVector4.h +++ b/kraken/public/KRVector4.h @@ -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(); diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 07abc4c..638ef66 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -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" diff --git a/kraken/public/vector2.h b/kraken/public/vector2.h new file mode 100644 index 0000000..f190210 --- /dev/null +++ b/kraken/public/vector2.h @@ -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 // 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 { + public: + size_t operator()(const kraken::Vector2 &s) const + { + size_t h1 = hash()(s.x); + size_t h2 = hash()(s.y); + return h1 ^ (h2 << 1); + } + }; +} + +#endif // KRAKEN_VECTOR2_H + diff --git a/kraken/public/KRVector3.h b/kraken/public/vector3.h similarity index 60% rename from kraken/public/KRVector3.h rename to kraken/public/vector3.h index d2b3733..059b9d5 100644 --- a/kraken/public/KRVector3.h +++ b/kraken/public/vector3.h @@ -1,5 +1,5 @@ // -// KRVector3.h +// Vector3.h // Kraken // // Copyright 2017 Kearwood Gilbert. All rights reserved. @@ -34,11 +34,12 @@ #include // 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 { + struct hash { public: - size_t operator()(const kraken::KRVector3 &s) const + size_t operator()(const kraken::Vector3 &s) const { size_t h1 = hash()(s.x); size_t h2 = hash()(s.y); diff --git a/kraken/vector2.cpp b/kraken/vector2.cpp new file mode 100644 index 0000000..7bd1cfd --- /dev/null +++ b/kraken/vector2.cpp @@ -0,0 +1,215 @@ +// +// Vector2.cpp +// KREngine +// +// Created by Kearwood Gilbert on 12-03-22. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include "public/kraken.h" + +namespace kraken { + +Vector2::Vector2() { + x = 0.0; + y = 0.0; +} + +Vector2::Vector2(float X, float Y) { + x = X; + y = Y; +} + +Vector2::Vector2(float v) { + x = v; + y = v; +} + +Vector2::Vector2(float *v) { + x = v[0]; + y = v[1]; +} + +Vector2::Vector2(const Vector2 &v) { + x = v.x; + y = v.y; +} + + +// Vector2 swizzle getters +Vector2 Vector2::yx() const +{ + return Vector2(y,x); +} + +// Vector2 swizzle setters +void Vector2::yx(const Vector2 &v) +{ + y = v.x; + x = v.y; +} + +Vector2 Vector2::Min() { + return Vector2(-std::numeric_limits::max()); +} + +Vector2 Vector2::Max() { + return Vector2(std::numeric_limits::max()); +} + +Vector2 Vector2::Zero() { + return Vector2(0.0f); +} + +Vector2 Vector2::One() { + return Vector2(1.0f); +} + +Vector2::~Vector2() { + +} + +Vector2& Vector2::operator =(const Vector2& b) { + x = b.x; + y = b.y; + return *this; +} + +Vector2 Vector2::operator +(const Vector2& b) const { + return Vector2(x + b.x, y + b.y); +} + +Vector2 Vector2::operator -(const Vector2& b) const { + return Vector2(x - b.x, y - b.y); +} + +Vector2 Vector2::operator +() const { + return *this; +} + +Vector2 Vector2::operator -() const { + return Vector2(-x, -y); +} + +Vector2 Vector2::operator *(const float v) const { + return Vector2(x * v, y * v); +} + +Vector2 Vector2::operator /(const float v) const { + float inv_v = 1.0f / v; + return Vector2(x * inv_v, y * inv_v); +} + +Vector2& Vector2::operator +=(const Vector2& b) { + x += b.x; + y += b.y; + return *this; +} + +Vector2& Vector2::operator -=(const Vector2& b) { + x -= b.x; + y -= b.y; + return *this; +} + + + +Vector2& Vector2::operator *=(const float v) { + x *= v; + y *= v; + return *this; +} + +Vector2& Vector2::operator /=(const float v) { + float inv_v = 1.0f / v; + x *= inv_v; + y *= inv_v; + return *this; +} + + +bool Vector2::operator ==(const Vector2& b) const { + return x == b.x && y == b.y; +} + +bool Vector2::operator !=(const Vector2& b) const { + return x != b.x || y != b.y; +} + +bool Vector2::operator >(const Vector2& b) const +{ + // Comparison operators are implemented to allow insertion into sorted containers such as std::set + if(x > b.x) { + return true; + } else if(x < b.x) { + return false; + } else if(y > b.y) { + return true; + } else { + return false; + } +} + +bool Vector2::operator <(const Vector2& b) const +{ + // Comparison operators are implemented to allow insertion into sorted containers such as std::set + if(x < b.x) { + return true; + } else if(x > b.x) { + return false; + } else if(y < b.y) { + return true; + } else { + return false; + } +} + +float& Vector2::operator[] (unsigned i) { + switch(i) { + case 0: + return x; + case 1: + default: + return y; + } +} + +float Vector2::operator[](unsigned i) const { + switch(i) { + case 0: + return x; + case 1: + default: + return y; + } +} + +void Vector2::normalize() { + float inv_magnitude = 1.0f / sqrtf(x * x + y * y); + x *= inv_magnitude; + y *= inv_magnitude; +} + +float Vector2::sqrMagnitude() const { + return x * x + y * y; +} + +float Vector2::magnitude() const { + return sqrtf(x * x + y * y); +} + + +Vector2 Vector2::Normalize(const Vector2 &v) { + float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y); + return Vector2(v.x * inv_magnitude, v.y * inv_magnitude); +} + +float Vector2::Cross(const Vector2 &v1, const Vector2 &v2) { + return v1.x * v2.y - v1.y * v2.x; +} + +float Vector2::Dot(const Vector2 &v1, const Vector2 &v2) { + return v1.x * v2.x + v1.y * v2.y; +} + +} // namepsace kraken diff --git a/kraken/KRVector3.cpp b/kraken/vector3.cpp old mode 100755 new mode 100644 similarity index 59% rename from kraken/KRVector3.cpp rename to kraken/vector3.cpp index d5f528b..f0c1354 --- a/kraken/KRVector3.cpp +++ b/kraken/vector3.cpp @@ -1,5 +1,5 @@ // -// KRVector3.cpp +// Vector3.cpp // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -32,182 +32,182 @@ #include "KREngine-common.h" #include "public/kraken.h" -const KRVector3 KRVECTOR3_ZERO(0.0f, 0.0f, 0.0f); +const Vector3 Vector3_ZERO(0.0f, 0.0f, 0.0f); //default constructor -KRVector3::KRVector3() +Vector3::Vector3() { x = 0.0f; y = 0.0f; z = 0.0f; } -KRVector3::KRVector3(const KRVector3 &v) { +Vector3::Vector3(const Vector3 &v) { x = v.x; y = v.y; z = v.z; } -KRVector3::KRVector3(const KRVector4 &v) { +Vector3::Vector3(const KRVector4 &v) { x = v.x; y = v.y; z = v.z; } -KRVector3::KRVector3(float *v) { +Vector3::Vector3(float *v) { x = v[0]; y = v[1]; z = v[2]; } -KRVector3::KRVector3(double *v) { +Vector3::Vector3(double *v) { x = (float)v[0]; y = (float)v[1]; z = (float)v[2]; } -Vector2 KRVector3::xx() const +Vector2 Vector3::xx() const { return Vector2(x,x); } -Vector2 KRVector3::xy() const +Vector2 Vector3::xy() const { return Vector2(x,y); } -Vector2 KRVector3::xz() const +Vector2 Vector3::xz() const { return Vector2(x,z); } -Vector2 KRVector3::yx() const +Vector2 Vector3::yx() const { return Vector2(y,x); } -Vector2 KRVector3::yy() const +Vector2 Vector3::yy() const { return Vector2(y,y); } -Vector2 KRVector3::yz() const +Vector2 Vector3::yz() const { return Vector2(y,z); } -Vector2 KRVector3::zx() const +Vector2 Vector3::zx() const { return Vector2(z,x); } -Vector2 KRVector3::zy() const +Vector2 Vector3::zy() const { return Vector2(z,y); } -Vector2 KRVector3::zz() const +Vector2 Vector3::zz() const { return Vector2(z,z); } -void KRVector3::xy(const Vector2 &v) +void Vector3::xy(const Vector2 &v) { x = v.x; y = v.y; } -void KRVector3::xz(const Vector2 &v) +void Vector3::xz(const Vector2 &v) { x = v.x; z = v.y; } -void KRVector3::yx(const Vector2 &v) +void Vector3::yx(const Vector2 &v) { y = v.x; x = v.y; } -void KRVector3::yz(const Vector2 &v) +void Vector3::yz(const Vector2 &v) { y = v.x; z = v.y; } -void KRVector3::zx(const Vector2 &v) +void Vector3::zx(const Vector2 &v) { z = v.x; x = v.y; } -void KRVector3::zy(const Vector2 &v) +void Vector3::zy(const Vector2 &v) { z = v.x; y = v.y; } -KRVector3 KRVector3::Min() { - return KRVector3(-std::numeric_limits::max()); +Vector3 Vector3::Min() { + return Vector3(-std::numeric_limits::max()); } -KRVector3 KRVector3::Max() { - return KRVector3(std::numeric_limits::max()); +Vector3 Vector3::Max() { + return Vector3(std::numeric_limits::max()); } -const KRVector3 &KRVector3::Zero() { - return KRVECTOR3_ZERO; +const Vector3 &Vector3::Zero() { + return Vector3_ZERO; } -KRVector3 KRVector3::One() { - return KRVector3(1.0f, 1.0f, 1.0f); +Vector3 Vector3::One() { + return Vector3(1.0f, 1.0f, 1.0f); } -KRVector3 KRVector3::Forward() { - return KRVector3(0.0f, 0.0f, 1.0f); +Vector3 Vector3::Forward() { + return Vector3(0.0f, 0.0f, 1.0f); } -KRVector3 KRVector3::Backward() { - return KRVector3(0.0f, 0.0f, -1.0f); +Vector3 Vector3::Backward() { + return Vector3(0.0f, 0.0f, -1.0f); } -KRVector3 KRVector3::Up() { - return KRVector3(0.0f, 1.0f, 0.0f); +Vector3 Vector3::Up() { + return Vector3(0.0f, 1.0f, 0.0f); } -KRVector3 KRVector3::Down() { - return KRVector3(0.0f, -1.0f, 0.0f); +Vector3 Vector3::Down() { + return Vector3(0.0f, -1.0f, 0.0f); } -KRVector3 KRVector3::Left() { - return KRVector3(-1.0f, 0.0f, 0.0f); +Vector3 Vector3::Left() { + return Vector3(-1.0f, 0.0f, 0.0f); } -KRVector3 KRVector3::Right() { - return KRVector3(1.0f, 0.0f, 0.0f); +Vector3 Vector3::Right() { + return Vector3(1.0f, 0.0f, 0.0f); } -void KRVector3::scale(const KRVector3 &v) +void Vector3::scale(const Vector3 &v) { x *= v.x; y *= v.y; z *= v.z; } -KRVector3 KRVector3::Scale(const KRVector3 &v1, const KRVector3 &v2) +Vector3 Vector3::Scale(const Vector3 &v1, const Vector3 &v2) { - return KRVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); + return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); } -KRVector3 KRVector3::Lerp(const KRVector3 &v1, const KRVector3 &v2, float d) { +Vector3 Vector3::Lerp(const Vector3 &v1, const Vector3 &v2, float d) { return v1 + (v2 - v1) * d; } -KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float d) { +Vector3 Vector3::Slerp(const Vector3 &v1, const Vector3 &v2, float d) { // From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/ // Dot product - the cosine of the angle between 2 vectors. - float dot = KRVector3::Dot(v1, v2); + float dot = Vector3::Dot(v1, v2); // Clamp it to be in the range of Acos() if(dot < -1.0f) dot = -1.0f; if(dot > 1.0f) dot = 1.0f; @@ -215,74 +215,74 @@ KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float d) { // And multiplying that by percent returns the angle between // start and the final result. float theta = acos(dot)*d; - KRVector3 RelativeVec = v2 - v1*dot; + Vector3 RelativeVec = v2 - v1*dot; RelativeVec.normalize(); // Orthonormal basis // The final result. return ((v1*cos(theta)) + (RelativeVec*sin(theta))); } -void KRVector3::OrthoNormalize(KRVector3 &normal, KRVector3 &tangent) { +void Vector3::OrthoNormalize(Vector3 &normal, Vector3 &tangent) { // Gram-Schmidt Orthonormalization normal.normalize(); - KRVector3 proj = normal * Dot(tangent, normal); + Vector3 proj = normal * Dot(tangent, normal); tangent = tangent - proj; tangent.normalize(); } -KRVector3::KRVector3(float v) { +Vector3::Vector3(float v) { x = v; y = v; z = v; } -KRVector3::KRVector3(float X, float Y, float Z) +Vector3::Vector3(float X, float Y, float Z) { x = X; y = Y; z = Z; } -KRVector3::~KRVector3() +Vector3::~Vector3() { } -KRVector3& KRVector3::operator =(const KRVector3& b) { +Vector3& Vector3::operator =(const Vector3& b) { x = b.x; y = b.y; z = b.z; return *this; } -KRVector3& KRVector3::operator =(const KRVector4 &b) { +Vector3& Vector3::operator =(const KRVector4 &b) { x = b.x; y = b.y; z = b.z; return *this; } -KRVector3 KRVector3::operator +(const KRVector3& b) const { - return KRVector3(x + b.x, y + b.y, z + b.z); +Vector3 Vector3::operator +(const Vector3& b) const { + return Vector3(x + b.x, y + b.y, z + b.z); } -KRVector3 KRVector3::operator -(const KRVector3& b) const { - return KRVector3(x - b.x, y - b.y, z - b.z); +Vector3 Vector3::operator -(const Vector3& b) const { + return Vector3(x - b.x, y - b.y, z - b.z); } -KRVector3 KRVector3::operator +() const { +Vector3 Vector3::operator +() const { return *this; } -KRVector3 KRVector3::operator -() const { - return KRVector3(-x, -y, -z); +Vector3 Vector3::operator -() const { + return Vector3(-x, -y, -z); } -KRVector3 KRVector3::operator *(const float v) const { - return KRVector3(x * v, y * v, z * v); +Vector3 Vector3::operator *(const float v) const { + return Vector3(x * v, y * v, z * v); } -KRVector3 KRVector3::operator /(const float v) const { +Vector3 Vector3::operator /(const float v) const { float inv_v = 1.0f / v; - return KRVector3(x * inv_v, y * inv_v, z * inv_v); + return Vector3(x * inv_v, y * inv_v, z * inv_v); } -KRVector3& KRVector3::operator +=(const KRVector3& b) { +Vector3& Vector3::operator +=(const Vector3& b) { x += b.x; y += b.y; z += b.z; @@ -290,7 +290,7 @@ KRVector3& KRVector3::operator +=(const KRVector3& b) { return *this; } -KRVector3& KRVector3::operator -=(const KRVector3& b) { +Vector3& Vector3::operator -=(const Vector3& b) { x -= b.x; y -= b.y; z -= b.z; @@ -298,7 +298,7 @@ KRVector3& KRVector3::operator -=(const KRVector3& b) { return *this; } -KRVector3& KRVector3::operator *=(const float v) { +Vector3& Vector3::operator *=(const float v) { x *= v; y *= v; z *= v; @@ -306,7 +306,7 @@ KRVector3& KRVector3::operator *=(const float v) { return *this; } -KRVector3& KRVector3::operator /=(const float v) { +Vector3& Vector3::operator /=(const float v) { float inv_v = 1.0f / v; x *= inv_v; y *= inv_v; @@ -315,15 +315,15 @@ KRVector3& KRVector3::operator /=(const float v) { return *this; } -bool KRVector3::operator ==(const KRVector3& b) const { +bool Vector3::operator ==(const Vector3& b) const { return x == b.x && y == b.y && z == b.z; } -bool KRVector3::operator !=(const KRVector3& b) const { +bool Vector3::operator !=(const Vector3& b) const { return x != b.x || y != b.y || z != b.z; } -float& KRVector3::operator[](unsigned i) { +float& Vector3::operator[](unsigned i) { switch(i) { case 0: return x; @@ -335,7 +335,7 @@ float& KRVector3::operator[](unsigned i) { } } -float KRVector3::operator[](unsigned i) const { +float Vector3::operator[](unsigned i) const { switch(i) { case 0: return x; @@ -347,37 +347,37 @@ float KRVector3::operator[](unsigned i) const { } } -float KRVector3::sqrMagnitude() const { +float Vector3::sqrMagnitude() const { // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function) return x * x + y * y + z * z; } -float KRVector3::magnitude() const { +float Vector3::magnitude() const { return sqrtf(x * x + y * y + z * z); } -void KRVector3::normalize() { +void Vector3::normalize() { float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z); x *= inv_magnitude; y *= inv_magnitude; z *= inv_magnitude; } -KRVector3 KRVector3::Normalize(const KRVector3 &v) { +Vector3 Vector3::Normalize(const Vector3 &v) { float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); - return KRVector3(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude); + return Vector3(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude); } -KRVector3 KRVector3::Cross(const KRVector3 &v1, const KRVector3 &v2) { - return KRVector3(v1.y * v2.z - v1.z * v2.y, +Vector3 Vector3::Cross(const Vector3 &v1, const Vector3 &v2) { + return Vector3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); } -float KRVector3::Dot(const KRVector3 &v1, const KRVector3 &v2) { +float Vector3::Dot(const Vector3 &v1, const Vector3 &v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } -bool KRVector3::operator >(const KRVector3& b) const +bool Vector3::operator >(const Vector3& b) const { // Comparison operators are implemented to allow insertion into sorted containers such as std::set if(x > b.x) { @@ -395,7 +395,7 @@ bool KRVector3::operator >(const KRVector3& b) const } } -bool KRVector3::operator <(const KRVector3& b) const +bool Vector3::operator <(const Vector3& b) const { // Comparison operators are implemented to allow insertion into sorted containers such as std::set if(x < b.x) { diff --git a/kraken_win/kraken.vcxproj b/kraken_win/kraken.vcxproj index c962a6c..708a34c 100755 --- a/kraken_win/kraken.vcxproj +++ b/kraken_win/kraken.vcxproj @@ -196,7 +196,7 @@ - + @@ -278,7 +278,7 @@ - + diff --git a/kraken_win/kraken.vcxproj.filters b/kraken_win/kraken.vcxproj.filters index 704daef..44118bb 100755 --- a/kraken_win/kraken.vcxproj.filters +++ b/kraken_win/kraken.vcxproj.filters @@ -30,9 +30,6 @@ Source Files - - Source Files - Source Files @@ -252,6 +249,9 @@ Source Files + + Source Files + @@ -479,9 +479,6 @@ Header Files\public - - Header Files\public - Header Files\public @@ -500,5 +497,8 @@ Header Files\public + + Header Files\public + \ No newline at end of file