From 514b7e7ad0b3a86ed1acfc7e3a7e8546089bd0c9 Mon Sep 17 00:00:00 2001 From: Kearwood Kip Gilbert Date: Sat, 29 Jul 2017 17:54:27 -0700 Subject: [PATCH] /s/KRMat4/Matrix4/g --- kraken/KRAABB.cpp | 4 +- kraken/KRAmbientZone.cpp | 2 +- kraken/KRAudioManager.cpp | 8 +- kraken/KRAudioManager.h | 2 +- kraken/KRAudioSource.cpp | 2 +- kraken/KRBone.cpp | 6 +- kraken/KRBone.h | 6 +- kraken/KRCamera.cpp | 20 +- kraken/KRCollider.cpp | 24 +- kraken/KRDirectionalLight.cpp | 26 +- kraken/KREngine.h | 2 +- kraken/KRHelpers.cpp | 2 +- kraken/KRHelpers.h | 2 +- kraken/KRLight.cpp | 10 +- kraken/KRMat4.cpp | 445 ------------------------------ kraken/KRMaterial.cpp | 14 +- kraken/KRMaterial.h | 2 +- kraken/KRMesh.cpp | 16 +- kraken/KRMesh.h | 10 +- kraken/KRModel.cpp | 4 +- kraken/KRModel.h | 2 +- kraken/KRNode.cpp | 168 +++++------ kraken/KRNode.h | 22 +- kraken/KRPointLight.cpp | 4 +- kraken/KRQuaternion.cpp | 4 +- kraken/KRResource+fbx.cpp | 6 +- kraken/KRResource+obj.cpp | 2 +- kraken/KRReverbZone.cpp | 2 +- kraken/KRScene.cpp | 4 +- kraken/KRShader.cpp | 28 +- kraken/KRShader.h | 6 +- kraken/KRShaderManager.cpp | 4 +- kraken/KRShaderManager.h | 4 +- kraken/KRViewport.cpp | 34 +-- kraken/KRViewport.h | 26 +- kraken/public/KRAABB.h | 4 +- kraken/public/KRMat4.h | 115 -------- kraken/public/KRQuaternion.h | 2 +- kraken/public/kraken.h | 2 +- kraken_win/kraken.vcxproj | 4 +- kraken_win/kraken.vcxproj.filters | 12 +- 41 files changed, 251 insertions(+), 811 deletions(-) delete mode 100755 kraken/KRMat4.cpp delete mode 100644 kraken/public/KRMat4.h diff --git a/kraken/KRAABB.cpp b/kraken/KRAABB.cpp index 78a8442..e0c8af4 100755 --- a/kraken/KRAABB.cpp +++ b/kraken/KRAABB.cpp @@ -22,10 +22,10 @@ KRAABB::KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint) max = maxPoint; } -KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix) +KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix) { for(int iCorner=0; iCorner<8; iCorner++) { - Vector3 sourceCornerVertex = KRMat4::DotWDiv(modelMatrix, Vector3( + Vector3 sourceCornerVertex = Matrix4::DotWDiv(modelMatrix, Vector3( (iCorner & 1) == 0 ? corner1.x : corner2.x, (iCorner & 2) == 0 ? corner1.y : corner2.y, (iCorner & 4) == 0 ? corner1.z : corner2.z)); diff --git a/kraken/KRAmbientZone.cpp b/kraken/KRAmbientZone.cpp index 6d89f62..f86e477 100755 --- a/kraken/KRAmbientZone.cpp +++ b/kraken/KRAmbientZone.cpp @@ -94,7 +94,7 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector &point bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES; if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { - KRMat4 sphereModelMatrix = getModelMatrix(); + Matrix4 sphereModelMatrix = getModelMatrix(); 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); diff --git a/kraken/KRAudioManager.cpp b/kraken/KRAudioManager.cpp index f07bef3..879bcbd 100755 --- a/kraken/KRAudioManager.cpp +++ b/kraken/KRAudioManager.cpp @@ -1218,12 +1218,12 @@ void KRAudioManager::makeCurrentContext() initAudio(); } -void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix) +void KRAudioManager::setListenerOrientationFromModelMatrix(const Matrix4 &modelMatrix) { setListenerOrientation( - 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) + Matrix4::Dot(modelMatrix, Vector3(0.0, 0.0, 0.0)), + Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3(0.0, 0.0, -1.0)) - m_listener_position), + Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3(0.0, 1.0, 0.0)) - m_listener_position) ); } diff --git a/kraken/KRAudioManager.h b/kraken/KRAudioManager.h index 3d0b000..e1b7d90 100755 --- a/kraken/KRAudioManager.h +++ b/kraken/KRAudioManager.h @@ -106,7 +106,7 @@ public: KRScene *getListenerScene(); void setListenerScene(KRScene *scene); void setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up); - void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix); + void setListenerOrientationFromModelMatrix(const Matrix4 &modelMatrix); Vector3 &getListenerForward(); Vector3 &getListenerPosition(); Vector3 &getListenerUp(); diff --git a/kraken/KRAudioSource.cpp b/kraken/KRAudioSource.cpp index 0df2473..2a02ac2 100755 --- a/kraken/KRAudioSource.cpp +++ b/kraken/KRAudioSource.cpp @@ -178,7 +178,7 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector &point bool bVisualize = false; if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { - KRMat4 sphereModelMatrix = getModelMatrix(); + Matrix4 sphereModelMatrix = getModelMatrix(); 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); diff --git a/kraken/KRBone.cpp b/kraken/KRBone.cpp index 77fc6f9..781a3e8 100755 --- a/kraken/KRBone.cpp +++ b/kraken/KRBone.cpp @@ -48,7 +48,7 @@ void KRBone::render(KRCamera *pCamera, std::vector &point_lights bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES; if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { - KRMat4 sphereModelMatrix = getModelMatrix(); + Matrix4 sphereModelMatrix = getModelMatrix(); // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); @@ -87,11 +87,11 @@ void KRBone::render(KRCamera *pCamera, std::vector &point_lights } -void KRBone::setBindPose(const KRMat4 &pose) +void KRBone::setBindPose(const Matrix4 &pose) { m_bind_pose = pose; } -const KRMat4 &KRBone::getBindPose() +const Matrix4 &KRBone::getBindPose() { return m_bind_pose; } diff --git a/kraken/KRBone.h b/kraken/KRBone.h index 71a6b31..9cc8f85 100755 --- a/kraken/KRBone.h +++ b/kraken/KRBone.h @@ -24,10 +24,10 @@ public: void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); - void setBindPose(const KRMat4 &pose); - const KRMat4 &getBindPose(); + void setBindPose(const Matrix4 &pose); + const Matrix4 &getBindPose(); private: - KRMat4 m_bind_pose; + Matrix4 m_bind_pose; }; diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 48522ea..8e2eb6f 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -108,13 +108,13 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend KRScene &scene = getScene(); - KRMat4 modelMatrix = getModelMatrix(); - KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, Vector3::Zero()), KRMat4::Dot(modelMatrix, Vector3::Forward()), Vector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, Vector3::Up()))); + Matrix4 modelMatrix = getModelMatrix(); + Matrix4 viewMatrix = Matrix4::LookAt(Matrix4::Dot(modelMatrix, Vector3::Zero()), Matrix4::Dot(modelMatrix, Vector3::Forward()), Vector3::Normalize(Matrix4::DotNoTranslate(modelMatrix, Vector3::Up()))); - //KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix()); + //Matrix4 viewMatrix = Matrix4::Invert(getModelMatrix()); settings.setViewportSize(Vector2(m_backingWidth, m_backingHeight)); - KRMat4 projectionMatrix; + Matrix4 projectionMatrix; projectionMatrix.perspective(settings.perspective_fov, settings.m_viewportSize.x / settings.m_viewportSize.y, settings.perspective_nearz, settings.perspective_farz); m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix); m_viewport.setLODBias(settings.getLODBias()); @@ -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, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getShaderManager()->selectShader("sky_box", *this, std::vector(), std::vector(), std::vector(), 0, m_viewport, Matrix4(), 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, Vector4::Zero()); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); @@ -477,7 +477,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f); for(unordered_map::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { - KRMat4 matModel = KRMat4(); + Matrix4 matModel = Matrix4(); 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, Vector3::Zero(), 0.0f, Vector4::Zero())) { @@ -695,7 +695,7 @@ void KRCamera::renderPost() 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); 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); + getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, Matrix4(), 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); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture); @@ -717,10 +717,10 @@ void KRCamera::renderPost() // KRShader *blitShader = m_pContext->getShaderManager()->getShader("simple_blit", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); // // for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) { -// KRMat4 viewMatrix = KRMat4(); +// Matrix4 viewMatrix = Matrix4(); // 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(), Vector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); +// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, Matrix4()), shadowViewports, Matrix4(), 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, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, Matrix4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::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 b62ede4..5c32b50 100755 --- a/kraken/KRCollider.cpp +++ b/kraken/KRCollider.cpp @@ -98,17 +98,17 @@ bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitin loadModel(); if(m_models.size()) { if(getBounds().intersectsLine(v0, v1)) { - Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - Vector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); + Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0); + Vector3 v1_model_space = Matrix4::Dot(getInverseModelMatrix(), v1); KRHitInfo hitinfo_model_space; if(hitinfo.didHit()) { - 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()); + Vector3 hit_position_model_space = Matrix4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); + hitinfo_model_space = KRHitInfo(hit_position_model_space, Matrix4::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)) { - 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); + Vector3 hit_position_world_space = Matrix4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); + hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); return true; } } @@ -123,17 +123,17 @@ bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitin loadModel(); if(m_models.size()) { if(getBounds().intersectsRay(v0, dir)) { - Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); - Vector3 dir_model_space = Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir)); + Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0); + Vector3 dir_model_space = Vector3::Normalize(Matrix4::DotNoTranslate(getInverseModelMatrix(), dir)); KRHitInfo hitinfo_model_space; if(hitinfo.didHit()) { - 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()); + Vector3 hit_position_model_space = Matrix4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); + hitinfo_model_space = KRHitInfo(hit_position_model_space, Vector3::Normalize(Matrix4::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)) { - 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); + Vector3 hit_position_world_space = Matrix4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); + hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); return true; } } diff --git a/kraken/KRDirectionalLight.cpp b/kraken/KRDirectionalLight.cpp index 85ad09f..2074e07 100755 --- a/kraken/KRDirectionalLight.cpp +++ b/kraken/KRDirectionalLight.cpp @@ -29,7 +29,7 @@ std::string KRDirectionalLight::getElementName() { } Vector3 KRDirectionalLight::getWorldLightDirection() { - return KRMat4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); + return Matrix4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); } Vector3 KRDirectionalLight::getLocalLightDirection() { @@ -52,7 +52,7 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor float max_depth = 1.0f; */ - KRAABB worldSpacefrustrumSliceBounds = KRAABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(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), Matrix4::Invert(viewport.getViewProjectionMatrix())); worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection()); @@ -60,24 +60,24 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor 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(); +// Matrix4 matShadowView = Matrix4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp); +// Matrix4 matShadowProjection = Matrix4(); // matShadowProjection.scale(0.001, 0.001, 0.001); - KRMat4 matShadowView = KRMat4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp); - KRMat4 matShadowProjection = KRMat4(); - KRAABB shadowSpaceFrustrumSliceBounds = KRAABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, KRMat4::Invert(matShadowProjection)); - KRAABB shadowSpaceSceneBounds = KRAABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, KRMat4::Invert(matShadowProjection)); + Matrix4 matShadowView = Matrix4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp); + Matrix4 matShadowProjection = Matrix4(); + KRAABB shadowSpaceFrustrumSliceBounds = KRAABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection)); + KRAABB shadowSpaceSceneBounds = KRAABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, Matrix4::Invert(matShadowProjection)); if(shadowSpaceSceneBounds.min.z < shadowSpaceFrustrumSliceBounds.min.z) shadowSpaceFrustrumSliceBounds.min.z = shadowSpaceSceneBounds.min.z; // Include any potential shadow casters that are outside the view frustrum matShadowProjection.scale(1.0f / shadowSpaceFrustrumSliceBounds.size().x, 1.0f / shadowSpaceFrustrumSliceBounds.size().y, 1.0f / shadowSpaceFrustrumSliceBounds.size().z); - KRMat4 matBias; + Matrix4 matBias; matBias.bias(); matShadowProjection *= matBias; KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection); - KRAABB prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix())); - KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix())); + KRAABB prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix())); + KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::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; @@ -101,12 +101,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector & std::vector this_light; this_light.push_back(this); - KRMat4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix(); + Matrix4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix(); matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.invert(); Vector3 light_direction_view_space = getWorldLightDirection(); - light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space); + light_direction_view_space = Matrix4::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); diff --git a/kraken/KREngine.h b/kraken/KREngine.h index f29004b..1fa71fd 100755 --- a/kraken/KREngine.h +++ b/kraken/KREngine.h @@ -30,7 +30,7 @@ // // #include "KRTextureManager.h" -#include "KRMat4.h" +#include "Matrix4.h" #include "Vector3.h" #include "KRMesh.h" #include "KRScene.h" diff --git a/kraken/KRHelpers.cpp b/kraken/KRHelpers.cpp index 4483240..5511a86 100644 --- a/kraken/KRHelpers.cpp +++ b/kraken/KRHelpers.cpp @@ -19,7 +19,7 @@ void SetUniform(GLint location, const Vector4 &v) if (location != -1) GLDEBUG(glUniform4f(location, v.x, v.y, v.z, v.w)); } -void SetUniform(GLint location, const KRMat4 &v) +void SetUniform(GLint location, const Matrix4 &v) { if (location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, v.c)); } diff --git a/kraken/KRHelpers.h b/kraken/KRHelpers.h index d3eaccd..e58510a 100644 --- a/kraken/KRHelpers.h +++ b/kraken/KRHelpers.h @@ -20,7 +20,7 @@ namespace kraken { void SetUniform(GLint location, const Vector2 &v); void SetUniform(GLint location, const Vector3 &v); void SetUniform(GLint location, const Vector4 &v); - void SetUniform(GLint location, const KRMat4 &v); + void SetUniform(GLint location, const Matrix4 &v); 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); diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index 10042e1..9982695 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -198,7 +198,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light GLDEBUG(glEnable(GL_DEPTH_TEST)); GLDEBUG(glDepthRangef(0.0, 1.0)); - KRMat4 particleModelMatrix; + Matrix4 particleModelMatrix; particleModelMatrix.scale(particle_range); // Scale the box symetrically to ensure that we don't have an uneven distribution of particles for different angles of the view frustrum particleModelMatrix.translate(viewport.getCameraPosition()); @@ -223,7 +223,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::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), Vector3::Zero())); + pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::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, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, Matrix4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) { int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5; float slice_near = -pCamera->settings.getPerspectiveNearZ(); @@ -277,7 +277,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light if(m_flareTexture.size() && m_flareSize > 0.0f) { - KRMat4 occlusion_test_sphere_matrix = KRMat4(); + Matrix4 occlusion_test_sphere_matrix = Matrix4(); occlusion_test_sphere_matrix.scale(m_localScale * m_flareOcclusionSize); occlusion_test_sphere_matrix.translate(m_localTranslation); if(m_parentNode) { @@ -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, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero()); getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true); diff --git a/kraken/KRMat4.cpp b/kraken/KRMat4.cpp deleted file mode 100755 index 5ccb5af..0000000 --- a/kraken/KRMat4.cpp +++ /dev/null @@ -1,445 +0,0 @@ -// -// KRMat4.cpp -// KREngine -// -// Copyright 2012 Kearwood Gilbert. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation are those of the -// authors and should not be interpreted as representing official policies, either expressed -// or implied, of Kearwood Gilbert. -// - -#include "KREngine-common.h" - -#include "public/KRMat4.h" - -KRMat4::KRMat4() { - // Default constructor - Initialize with an identity matrix - static const float IDENTITY_MATRIX[] = { - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 - }; - memcpy(c, IDENTITY_MATRIX, sizeof(float) * 16); - -} - -KRMat4::KRMat4(float *pMat) { - memcpy(c, pMat, sizeof(float) * 16); -} - -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; - c[8] = axis_z.x; c[9] = axis_z.y; c[10] = axis_z.z; c[11] = 0.0f; - c[12] = trans.x; c[13] = trans.y; c[14] = trans.z; c[15] = 1.0f; -} - -KRMat4::~KRMat4() { - -} - -float *KRMat4::getPointer() { - return c; -} - -// Copy constructor -KRMat4::KRMat4(const KRMat4 &m) { - memcpy(c, m.c, sizeof(float) * 16); -} - -KRMat4& KRMat4::operator=(const KRMat4 &m) { - if(this != &m) { // Prevent self-assignment. - memcpy(c, m.c, sizeof(float) * 16); - } - return *this; -} - -float& KRMat4::operator[](unsigned i) { - return c[i]; -} - -float KRMat4::operator[](unsigned i) const { - return c[i]; -} - -// Overload comparison operator -bool KRMat4::operator==(const KRMat4 &m) const { - return memcmp(c, m.c, sizeof(float) * 16) == 0; -} - -// Overload compound multiply operator -KRMat4& KRMat4::operator*=(const KRMat4 &m) { - float temp[16]; - - int x,y; - - for (x=0; x < 4; x++) - { - for(y=0; y < 4; y++) - { - temp[y + (x*4)] = (c[x*4] * m.c[y]) + - (c[(x*4)+1] * m.c[y+4]) + - (c[(x*4)+2] * m.c[y+8]) + - (c[(x*4)+3] * m.c[y+12]); - } - } - - memcpy(c, temp, sizeof(float) << 4); - return *this; -} - -// Overload multiply operator -KRMat4 KRMat4::operator*(const KRMat4 &m) const { - KRMat4 ret = *this; - ret *= m; - return ret; -} - - -/* Generate a perspective view matrix using a field of view angle fov, - * window aspect ratio, near and far clipping planes */ -void KRMat4::perspective(float fov, float aspect, float nearz, float farz) { - - memset(c, 0, sizeof(float) * 16); - - float range= tan(fov * 0.5) * nearz; - c[0] = (2 * nearz) / ((range * aspect) - (-range * aspect)); - c[5] = (2 * nearz) / (2 * range); - c[10] = -(farz + nearz) / (farz - nearz); - c[11] = -1; - c[14] = -(2 * farz * nearz) / (farz - nearz); - /* - float range= atan(fov / 20.0f) * nearz; - float r = range * aspect; - float t = range * 1.0; - - c[0] = nearz / r; - c[5] = nearz / t; - c[10] = -(farz + nearz) / (farz - nearz); - c[11] = -(2.0 * farz * nearz) / (farz - nearz); - c[14] = -1.0; - */ -} - -/* Perform translation operations on a matrix */ -void KRMat4::translate(float x, float y, float z) { - KRMat4 newMatrix; // Create new identity matrix - - newMatrix.c[12] = x; - newMatrix.c[13] = y; - newMatrix.c[14] = z; - - *this *= newMatrix; -} - -void KRMat4::translate(const Vector3 &v) -{ - translate(v.x, v.y, v.z); -} - -/* Rotate a matrix by an angle on a X, Y, or Z axis */ -void KRMat4::rotate(float angle, AXIS axis) { - const int cos1[3] = { 5, 0, 0 }; // cos(angle) - const int cos2[3] = { 10, 10, 5 }; // cos(angle) - const int sin1[3] = { 9, 2, 4 }; // -sin(angle) - const int sin2[3] = { 6, 8, 1 }; // sin(angle) - - /* - X_AXIS: - - 1, 0, 0, 0 - 0, cos(angle), -sin(angle), 0 - 0, sin(angle), cos(angle), 0 - 0, 0, 0, 1 - - Y_AXIS: - - cos(angle), 0, -sin(angle), 0 - 0, 1, 0, 0 - sin(angle), 0, cos(angle), 0 - 0, 0, 0, 1 - - Z_AXIS: - - cos(angle), -sin(angle), 0, 0 - sin(angle), cos(angle), 0, 0 - 0, 0, 1, 0 - 0, 0, 0, 1 - - */ - - KRMat4 newMatrix; // Create new identity matrix - - newMatrix.c[cos1[axis]] = cos(angle); - newMatrix.c[sin1[axis]] = -sin(angle); - newMatrix.c[sin2[axis]] = -newMatrix.c[sin1[axis]]; - newMatrix.c[cos2[axis]] = newMatrix.c[cos1[axis]]; - - *this *= newMatrix; -} - -void KRMat4::rotate(const KRQuaternion &q) -{ - *this *= q.rotationMatrix(); -} - -/* Scale matrix by separate x, y, and z amounts */ -void KRMat4::scale(float x, float y, float z) { - KRMat4 newMatrix; // Create new identity matrix - - newMatrix.c[0] = x; - newMatrix.c[5] = y; - newMatrix.c[10] = z; - - *this *= newMatrix; -} - -void KRMat4::scale(const Vector3 &v) { - scale(v.x, v.y, v.z); -} - -/* Scale all dimensions equally */ -void KRMat4::scale(float s) { - scale(s,s,s); -} - - // Initialize with a bias matrix -void KRMat4::bias() { - static const float BIAS_MATRIX[] = { - 0.5, 0.0, 0.0, 0.0, - 0.0, 0.5, 0.0, 0.0, - 0.0, 0.0, 0.5, 0.0, - 0.5, 0.5, 0.5, 1.0 - }; - memcpy(c, BIAS_MATRIX, sizeof(float) * 16); -} - - -/* Generate an orthographic view matrix */ -void KRMat4::ortho(float left, float right, float top, float bottom, float nearz, float farz) { - memset(c, 0, sizeof(float) * 16); - c[0] = 2.0f / (right - left); - c[5] = 2.0f / (bottom - top); - c[10] = -1.0f / (farz - nearz); - c[11] = -nearz / (farz - nearz); - c[15] = 1.0f; -} - -/* Replace matrix with its inverse */ -bool KRMat4::invert() { - // Based on gluInvertMatrix implementation - - float inv[16], det; - int i; - - inv[0] = c[5]*c[10]*c[15] - c[5]*c[11]*c[14] - c[9]*c[6]*c[15] - + c[9]*c[7]*c[14] + c[13]*c[6]*c[11] - c[13]*c[7]*c[10]; - inv[4] = -c[4]*c[10]*c[15] + c[4]*c[11]*c[14] + c[8]*c[6]*c[15] - - c[8]*c[7]*c[14] - c[12]*c[6]*c[11] + c[12]*c[7]*c[10]; - inv[8] = c[4]*c[9]*c[15] - c[4]*c[11]*c[13] - c[8]*c[5]*c[15] - + c[8]*c[7]*c[13] + c[12]*c[5]*c[11] - c[12]*c[7]*c[9]; - inv[12] = -c[4]*c[9]*c[14] + c[4]*c[10]*c[13] + c[8]*c[5]*c[14] - - c[8]*c[6]*c[13] - c[12]*c[5]*c[10] + c[12]*c[6]*c[9]; - inv[1] = -c[1]*c[10]*c[15] + c[1]*c[11]*c[14] + c[9]*c[2]*c[15] - - c[9]*c[3]*c[14] - c[13]*c[2]*c[11] + c[13]*c[3]*c[10]; - inv[5] = c[0]*c[10]*c[15] - c[0]*c[11]*c[14] - c[8]*c[2]*c[15] - + c[8]*c[3]*c[14] + c[12]*c[2]*c[11] - c[12]*c[3]*c[10]; - inv[9] = -c[0]*c[9]*c[15] + c[0]*c[11]*c[13] + c[8]*c[1]*c[15] - - c[8]*c[3]*c[13] - c[12]*c[1]*c[11] + c[12]*c[3]*c[9]; - inv[13] = c[0]*c[9]*c[14] - c[0]*c[10]*c[13] - c[8]*c[1]*c[14] - + c[8]*c[2]*c[13] + c[12]*c[1]*c[10] - c[12]*c[2]*c[9]; - inv[2] = c[1]*c[6]*c[15] - c[1]*c[7]*c[14] - c[5]*c[2]*c[15] - + c[5]*c[3]*c[14] + c[13]*c[2]*c[7] - c[13]*c[3]*c[6]; - inv[6] = -c[0]*c[6]*c[15] + c[0]*c[7]*c[14] + c[4]*c[2]*c[15] - - c[4]*c[3]*c[14] - c[12]*c[2]*c[7] + c[12]*c[3]*c[6]; - inv[10] = c[0]*c[5]*c[15] - c[0]*c[7]*c[13] - c[4]*c[1]*c[15] - + c[4]*c[3]*c[13] + c[12]*c[1]*c[7] - c[12]*c[3]*c[5]; - inv[14] = -c[0]*c[5]*c[14] + c[0]*c[6]*c[13] + c[4]*c[1]*c[14] - - c[4]*c[2]*c[13] - c[12]*c[1]*c[6] + c[12]*c[2]*c[5]; - inv[3] = -c[1]*c[6]*c[11] + c[1]*c[7]*c[10] + c[5]*c[2]*c[11] - - c[5]*c[3]*c[10] - c[9]*c[2]*c[7] + c[9]*c[3]*c[6]; - inv[7] = c[0]*c[6]*c[11] - c[0]*c[7]*c[10] - c[4]*c[2]*c[11] - + c[4]*c[3]*c[10] + c[8]*c[2]*c[7] - c[8]*c[3]*c[6]; - inv[11] = -c[0]*c[5]*c[11] + c[0]*c[7]*c[9] + c[4]*c[1]*c[11] - - c[4]*c[3]*c[9] - c[8]*c[1]*c[7] + c[8]*c[3]*c[5]; - inv[15] = c[0]*c[5]*c[10] - c[0]*c[6]*c[9] - c[4]*c[1]*c[10] - + c[4]*c[2]*c[9] + c[8]*c[1]*c[6] - c[8]*c[2]*c[5]; - - det = c[0]*inv[0] + c[1]*inv[4] + c[2]*inv[8] + c[3]*inv[12]; - - if (det == 0) { - return false; - } - - det = 1.0 / det; - - for (i = 0; i < 16; i++) { - c[i] = inv[i] * det; - } - - return true; -} - -void KRMat4::transpose() { - float trans[16]; - for(int x=0; x<4; x++) { - for(int y=0; y<4; y++) { - trans[x + y * 4] = c[y + x * 4]; - } - } - memcpy(c, trans, sizeof(float) * 16); -} - -/* 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] - ); -} - -Vector4 KRMat4::Dot4(const KRMat4 &m, const Vector4 &v) { -#ifdef KRAKEN_USE_ARM_NEON - - Vector4 d; - asm volatile ( - "vld1.32 {d0, d1}, [%1] \n\t" //Q0 = v - "vld1.32 {d18, d19}, [%0]! \n\t" //Q1 = m - "vld1.32 {d20, d21}, [%0]! \n\t" //Q2 = m+4 - "vld1.32 {d22, d23}, [%0]! \n\t" //Q3 = m+8 - "vld1.32 {d24, d25}, [%0]! \n\t" //Q4 = m+12 - - "vmul.f32 q13, q9, d0[0] \n\t" //Q5 = Q1*Q0[0] - "vmla.f32 q13, q10, d0[1] \n\t" //Q5 += Q1*Q0[1] - "vmla.f32 q13, q11, d1[0] \n\t" //Q5 += Q2*Q0[2] - "vmla.f32 q13, q12, d1[1] \n\t" //Q5 += Q3*Q0[3] - - "vst1.32 {d26, d27}, [%2] \n\t" //Q4 = m+12 - : /* no output registers */ - : "r"(m.c), "r"(v.c), "r"(d.c) - : "q0", "q9", "q10","q11", "q12", "q13", "memory" - ); - return d; -#else - return Vector4( - 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], - v.c[0] * m.c[3] + v.c[1] * m.c[7] + v.c[2] * m.c[11] + m.c[15] - ); -#endif -} - -// Dot product without including translation; useful for transforming normals and tangents -Vector3 KRMat4::DotNoTranslate(const KRMat4 &m, const Vector3 &v) -{ - 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] - ); -} - -/* Dot Product, returning w component as if it were a Vector4 (This will be deprecated once Vector4 is implemented instead*/ -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 */ -Vector3 KRMat4::DotWDiv(const KRMat4 &m, const Vector3 &v) { - Vector4 r = Dot4(m, Vector4(v, 1.0f)); - return Vector3(r) / r.w; -} - -KRMat4 KRMat4::LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection) -{ - KRMat4 matLookat; - Vector3 lookat_z_axis = lookAtPos - cameraPos; - lookat_z_axis.normalize(); - Vector3 lookat_x_axis = Vector3::Cross(upDirection, lookat_z_axis); - lookat_x_axis.normalize(); - 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; - matLookat.getPointer()[2] = lookat_z_axis.x; - - matLookat.getPointer()[4] = lookat_x_axis.y; - matLookat.getPointer()[5] = lookat_y_axis.y; - matLookat.getPointer()[6] = lookat_z_axis.y; - - matLookat.getPointer()[8] = lookat_x_axis.z; - matLookat.getPointer()[9] = lookat_y_axis.z; - matLookat.getPointer()[10] = lookat_z_axis.z; - - 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; -} - -KRMat4 KRMat4::Invert(const KRMat4 &m) -{ - KRMat4 matInvert = m; - matInvert.invert(); - return matInvert; -} - -KRMat4 KRMat4::Transpose(const KRMat4 &m) -{ - KRMat4 matTranspose = m; - matTranspose.transpose(); - return matTranspose; -} - -KRMat4 KRMat4::Translation(const Vector3 &v) -{ - KRMat4 m; - m[12] = v.x; - m[13] = v.y; - m[14] = v.z; -// m.translate(v); - return m; -} - -KRMat4 KRMat4::Rotation(const Vector3 &v) -{ - KRMat4 m; - m.rotate(v.x, X_AXIS); - m.rotate(v.y, Y_AXIS); - m.rotate(v.z, Z_AXIS); - return m; -} - -KRMat4 KRMat4::Scaling(const Vector3 &v) -{ - KRMat4 m; - m.scale(v); - return m; -} - diff --git a/kraken/KRMaterial.cpp b/kraken/KRMaterial.cpp index 90f8d9c..dfb9ade 100755 --- a/kraken/KRMaterial.cpp +++ b/kraken/KRMaterial.cpp @@ -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 Vector3 &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 Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage) { bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap; getTextures(); @@ -345,12 +345,12 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh //printf("%s - delta translation: %.4f %.4f %.4f\n", bone->getName().c_str(), translation.x - initialTranslation.x, translation.y - initialTranslation.y, translation.z - initialTranslation.z); // printf("%s - delta scale: %.4f %.4f %.4f\n", bone->getName().c_str(), scale.x - initialScale.x, scale.y - initialScale.y, scale.z - initialScale.z); - KRMat4 skin_bone_bind_pose = bind_poses[bone_index]; - KRMat4 active_mat = bone->getActivePoseMatrix(); - KRMat4 inv_bind_mat = bone->getInverseBindPoseMatrix(); - KRMat4 inv_bind_mat2 = KRMat4::Invert(bind_poses[bone_index]); - KRMat4 t = (inv_bind_mat * active_mat); - KRMat4 t2 = inv_bind_mat2 * bone->getModelMatrix(); + Matrix4 skin_bone_bind_pose = bind_poses[bone_index]; + Matrix4 active_mat = bone->getActivePoseMatrix(); + Matrix4 inv_bind_mat = bone->getInverseBindPoseMatrix(); + Matrix4 inv_bind_mat2 = Matrix4::Invert(bind_poses[bone_index]); + Matrix4 t = (inv_bind_mat * active_mat); + Matrix4 t2 = inv_bind_mat2 * bone->getModelMatrix(); for(int i=0; i < 16; i++) { *bone_mat_component++ = t[i]; } diff --git a/kraken/KRMaterial.h b/kraken/KRMaterial.h index 2a5af2d..0b627ce 100755 --- a/kraken/KRMaterial.h +++ b/kraken/KRMaterial.h @@ -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 Vector3 &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 Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f); bool needsVertexTangents(); diff --git a/kraken/KRMesh.cpp b/kraken/KRMesh.cpp index f20eb57..721c678 100755 --- a/kraken/KRMesh.cpp +++ b/kraken/KRMesh.cpp @@ -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 Vector3 &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 Matrix4 &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) { @@ -288,7 +288,7 @@ void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vect if(pMaterial != NULL && pMaterial == (*mat_itr)) { if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { - std::vector bone_bind_poses; + std::vector bone_bind_poses; for(int i=0; i < bones.size(); i++) { bone_bind_poses.push_back(getBoneBindPose(i)); } @@ -1093,9 +1093,9 @@ char *KRMesh::getBoneName(int bone_index) return getBone(bone_index)->szName; } -KRMat4 KRMesh::getBoneBindPose(int bone_index) +Matrix4 KRMesh::getBoneBindPose(int bone_index) { - return KRMat4(getBone(bone_index)->bind_pose); + return Matrix4(getBone(bone_index)->bind_pose); } KRMesh::model_format_t KRMesh::getModelFormat() const @@ -1184,7 +1184,7 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, KRHitInfo &hitinf } -bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const +bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const { m_pData->lock(); @@ -1236,7 +1236,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const V return hit_found; } -bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo) +bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo) { Vector3 dir = Vector3::Normalize(v1 - v0); @@ -1245,7 +1245,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const V 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])); + KRTriangle3 world_tri = KRTriangle3(Matrix4::Dot(model_to_world, tri[0]), Matrix4::Dot(model_to_world, tri[1]), Matrix4::Dot(model_to_world, tri[2])); if(world_tri.sphereCast(start, dir, radius, new_hit_point, new_hit_distance)) { if((!hitinfo.didHit() || hitinfo.getDistance() > new_hit_distance) && new_hit_distance <= (v1 - v0).magnitude()) { @@ -1259,7 +1259,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const V distance_v0 /= distance_total; distance_v1 /= distance_total; distance_v2 /= distance_total; - 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)))); + Vector3 normal = Vector3::Normalize(Matrix4::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; diff --git a/kraken/KRMesh.h b/kraken/KRMesh.h index f329ae9..6d515cd 100755 --- a/kraken/KRMesh.h +++ b/kraken/KRMesh.h @@ -108,11 +108,11 @@ public: std::vector material_names; std::vector bone_names; std::vector > bone_indexes; - std::vector bone_bind_poses; + std::vector bone_bind_poses; 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 Vector3 &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 Matrix4 &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; @@ -206,14 +206,14 @@ public: int getBoneCount(); char *getBoneName(int bone_index); - KRMat4 getBoneBindPose(int bone_index); + Matrix4 getBoneBindPose(int bone_index); model_format_t getModelFormat() 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; + bool sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const; static int GetLODCoverage(const std::string &name); @@ -231,7 +231,7 @@ private: void getMaterials(); 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); + static bool sphereCast(const Matrix4 &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; diff --git a/kraken/KRModel.cpp b/kraken/KRModel.cpp index 4964609..85b7f24 100755 --- a/kraken/KRModel.cpp +++ b/kraken/KRModel.cpp @@ -196,9 +196,9 @@ void KRModel::render(KRCamera *pCamera, std::vector &point_light m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP); } - KRMat4 matModel = getModelMatrix(); + Matrix4 matModel = getModelMatrix(); if(m_faces_camera) { - Vector3 model_center = KRMat4::Dot(matModel, Vector3::Zero()); + Vector3 model_center = Matrix4::Dot(matModel, Vector3::Zero()); Vector3 camera_pos = viewport.getCameraPosition(); matModel = KRQuaternion(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; } diff --git a/kraken/KRModel.h b/kraken/KRModel.h index 4d64ba7..4d45808 100755 --- a/kraken/KRModel.h +++ b/kraken/KRModel.h @@ -84,7 +84,7 @@ private: bool m_faces_camera; - KRMat4 m_boundsCachedMat; + Matrix4 m_boundsCachedMat; KRAABB m_boundsCached; diff --git a/kraken/KRNode.cpp b/kraken/KRNode.cpp index 5ced6ed..0f4a981 100755 --- a/kraken/KRNode.cpp +++ b/kraken/KRNode.cpp @@ -58,9 +58,9 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getCont m_bindPoseMatrixValid = false; m_activePoseMatrixValid = false; m_inverseBindPoseMatrixValid = false; - m_modelMatrix = KRMat4(); - m_bindPoseMatrix = KRMat4(); - m_activePoseMatrix = KRMat4(); + m_modelMatrix = Matrix4(); + m_bindPoseMatrix = Matrix4(); + m_activePoseMatrix = Matrix4(); m_lod_visible = LOD_VISIBILITY_HIDDEN; m_scale_compensation = false; m_boundsValid = false; @@ -203,7 +203,7 @@ void KRNode::setLocalTranslation(const Vector3 &v, bool set_original) { void KRNode::setWorldTranslation(const Vector3 &v) { if(m_parentNode) { - setLocalTranslation(KRMat4::Dot(m_parentNode->getInverseModelMatrix(), v)); + setLocalTranslation(Matrix4::Dot(m_parentNode->getInverseModelMatrix(), v)); } else { setLocalTranslation(v); } @@ -227,7 +227,7 @@ void KRNode::setWorldRotation(const Vector3 &v) void KRNode::setWorldScale(const Vector3 &v) { if(m_parentNode) { - setLocalScale(KRMat4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v)); + setLocalScale(Matrix4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v)); } else { setLocalScale(v); } @@ -383,7 +383,7 @@ const Vector3 KRNode::getWorldTranslation() { } const Vector3 KRNode::getWorldScale() { - return KRMat4::DotNoTranslate(getModelMatrix(), m_localScale); + return Matrix4::DotNoTranslate(getModelMatrix(), m_localScale); } std::string KRNode::getElementName() { @@ -523,11 +523,11 @@ void KRNode::invalidateBindPoseMatrix() } } -const KRMat4 &KRNode::getModelMatrix() +const Matrix4 &KRNode::getModelMatrix() { if(!m_modelMatrixValid) { - m_modelMatrix = KRMat4(); + m_modelMatrix = Matrix4(); bool parent_is_bone = false; if(dynamic_cast(m_parentNode)) { @@ -538,40 +538,40 @@ const KRMat4 &KRNode::getModelMatrix() // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 - m_modelMatrix = KRMat4::Translation(-m_scalingPivot) - * KRMat4::Scaling(m_localScale) - * KRMat4::Translation(m_scalingPivot) - * KRMat4::Translation(m_scalingOffset) - * KRMat4::Translation(-m_rotationPivot) + m_modelMatrix = Matrix4::Translation(-m_scalingPivot) + * Matrix4::Scaling(m_localScale) + * Matrix4::Translation(m_scalingPivot) + * Matrix4::Translation(m_scalingOffset) + * Matrix4::Translation(-m_rotationPivot) //* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix() - * KRMat4::Rotation(m_postRotation) - * KRMat4::Rotation(m_localRotation) - * KRMat4::Rotation(m_preRotation) - * KRMat4::Translation(m_rotationPivot) - * KRMat4::Translation(m_rotationOffset); + * Matrix4::Rotation(m_postRotation) + * Matrix4::Rotation(m_localRotation) + * Matrix4::Rotation(m_preRotation) + * Matrix4::Translation(m_rotationPivot) + * Matrix4::Translation(m_rotationOffset); if(m_parentNode) { m_modelMatrix.rotate(m_parentNode->getWorldRotation()); - m_modelMatrix.translate(KRMat4::Dot(m_parentNode->getModelMatrix(), m_localTranslation)); + m_modelMatrix.translate(Matrix4::Dot(m_parentNode->getModelMatrix(), m_localTranslation)); } else { m_modelMatrix.translate(m_localTranslation); } } else { // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 - m_modelMatrix = KRMat4::Translation(-m_scalingPivot) - * KRMat4::Scaling(m_localScale) - * KRMat4::Translation(m_scalingPivot) - * KRMat4::Translation(m_scalingOffset) - * KRMat4::Translation(-m_rotationPivot) + m_modelMatrix = Matrix4::Translation(-m_scalingPivot) + * Matrix4::Scaling(m_localScale) + * Matrix4::Translation(m_scalingPivot) + * Matrix4::Translation(m_scalingOffset) + * Matrix4::Translation(-m_rotationPivot) //* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix() - * KRMat4::Rotation(m_postRotation) - * KRMat4::Rotation(m_localRotation) - * KRMat4::Rotation(m_preRotation) - * KRMat4::Translation(m_rotationPivot) - * KRMat4::Translation(m_rotationOffset) - * KRMat4::Translation(m_localTranslation); + * Matrix4::Rotation(m_postRotation) + * Matrix4::Rotation(m_localRotation) + * Matrix4::Rotation(m_preRotation) + * Matrix4::Translation(m_rotationPivot) + * Matrix4::Translation(m_rotationOffset) + * Matrix4::Translation(m_localTranslation); if(m_parentNode) { m_modelMatrix *= m_parentNode->getModelMatrix(); @@ -584,10 +584,10 @@ const KRMat4 &KRNode::getModelMatrix() return m_modelMatrix; } -const KRMat4 &KRNode::getBindPoseMatrix() +const Matrix4 &KRNode::getBindPoseMatrix() { if(!m_bindPoseMatrixValid) { - m_bindPoseMatrix = KRMat4(); + m_bindPoseMatrix = Matrix4(); bool parent_is_bone = false; if(dynamic_cast(m_parentNode)) { @@ -595,22 +595,22 @@ const KRMat4 &KRNode::getBindPoseMatrix() } if(getScaleCompensation() && parent_is_bone) { - m_bindPoseMatrix = KRMat4::Translation(-m_initialScalingPivot) - * KRMat4::Scaling(m_initialLocalScale) - * KRMat4::Translation(m_initialScalingPivot) - * KRMat4::Translation(m_initialScalingOffset) - * KRMat4::Translation(-m_initialRotationPivot) + m_bindPoseMatrix = Matrix4::Translation(-m_initialScalingPivot) + * Matrix4::Scaling(m_initialLocalScale) + * Matrix4::Translation(m_initialScalingPivot) + * Matrix4::Translation(m_initialScalingOffset) + * Matrix4::Translation(-m_initialRotationPivot) //* (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix() - * KRMat4::Rotation(m_initialPostRotation) - * KRMat4::Rotation(m_initialLocalRotation) - * KRMat4::Rotation(m_initialPreRotation) - * KRMat4::Translation(m_initialRotationPivot) - * KRMat4::Translation(m_initialRotationOffset); + * Matrix4::Rotation(m_initialPostRotation) + * Matrix4::Rotation(m_initialLocalRotation) + * Matrix4::Rotation(m_initialPreRotation) + * Matrix4::Translation(m_initialRotationPivot) + * Matrix4::Translation(m_initialRotationOffset); //m_bindPoseMatrix.translate(m_localTranslation); if(m_parentNode) { m_bindPoseMatrix.rotate(m_parentNode->getBindPoseWorldRotation()); - m_bindPoseMatrix.translate(KRMat4::Dot(m_parentNode->getBindPoseMatrix(), m_localTranslation)); + m_bindPoseMatrix.translate(Matrix4::Dot(m_parentNode->getBindPoseMatrix(), m_localTranslation)); } else { m_bindPoseMatrix.translate(m_localTranslation); } @@ -618,18 +618,18 @@ const KRMat4 &KRNode::getBindPoseMatrix() // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 - m_bindPoseMatrix = KRMat4::Translation(-m_initialScalingPivot) - * KRMat4::Scaling(m_initialLocalScale) - * KRMat4::Translation(m_initialScalingPivot) - * KRMat4::Translation(m_initialScalingOffset) - * KRMat4::Translation(-m_initialRotationPivot) + m_bindPoseMatrix = Matrix4::Translation(-m_initialScalingPivot) + * Matrix4::Scaling(m_initialLocalScale) + * Matrix4::Translation(m_initialScalingPivot) + * Matrix4::Translation(m_initialScalingOffset) + * Matrix4::Translation(-m_initialRotationPivot) // * (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix() - * KRMat4::Rotation(m_initialPostRotation) - * KRMat4::Rotation(m_initialLocalRotation) - * KRMat4::Rotation(m_initialPreRotation) - * KRMat4::Translation(m_initialRotationPivot) - * KRMat4::Translation(m_initialRotationOffset) - * KRMat4::Translation(m_initialLocalTranslation); + * Matrix4::Rotation(m_initialPostRotation) + * Matrix4::Rotation(m_initialLocalRotation) + * Matrix4::Rotation(m_initialPreRotation) + * Matrix4::Translation(m_initialRotationPivot) + * Matrix4::Translation(m_initialRotationOffset) + * Matrix4::Translation(m_initialLocalTranslation); if(m_parentNode && parent_is_bone) { @@ -643,11 +643,11 @@ const KRMat4 &KRNode::getBindPoseMatrix() return m_bindPoseMatrix; } -const KRMat4 &KRNode::getActivePoseMatrix() +const Matrix4 &KRNode::getActivePoseMatrix() { if(!m_activePoseMatrixValid) { - m_activePoseMatrix = KRMat4(); + m_activePoseMatrix = Matrix4(); bool parent_is_bone = false; if(dynamic_cast(m_parentNode)) { @@ -655,38 +655,38 @@ const KRMat4 &KRNode::getActivePoseMatrix() } if(getScaleCompensation() && parent_is_bone) { - m_activePoseMatrix= KRMat4::Translation(-m_scalingPivot) - * KRMat4::Scaling(m_localScale) - * KRMat4::Translation(m_scalingPivot) - * KRMat4::Translation(m_scalingOffset) - * KRMat4::Translation(-m_rotationPivot) - * KRMat4::Rotation(m_postRotation) - * KRMat4::Rotation(m_localRotation) - * KRMat4::Rotation(m_preRotation) - * KRMat4::Translation(m_rotationPivot) - * KRMat4::Translation(m_rotationOffset); + m_activePoseMatrix= Matrix4::Translation(-m_scalingPivot) + * Matrix4::Scaling(m_localScale) + * Matrix4::Translation(m_scalingPivot) + * Matrix4::Translation(m_scalingOffset) + * Matrix4::Translation(-m_rotationPivot) + * Matrix4::Rotation(m_postRotation) + * Matrix4::Rotation(m_localRotation) + * Matrix4::Rotation(m_preRotation) + * Matrix4::Translation(m_rotationPivot) + * Matrix4::Translation(m_rotationOffset); if(m_parentNode) { m_activePoseMatrix.rotate(m_parentNode->getActivePoseWorldRotation()); - m_activePoseMatrix.translate(KRMat4::Dot(m_parentNode->getActivePoseMatrix(), m_localTranslation)); + m_activePoseMatrix.translate(Matrix4::Dot(m_parentNode->getActivePoseMatrix(), m_localTranslation)); } else { m_activePoseMatrix.translate(m_localTranslation); } } else { // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 - m_activePoseMatrix = KRMat4::Translation(-m_scalingPivot) - * KRMat4::Scaling(m_localScale) - * KRMat4::Translation(m_scalingPivot) - * KRMat4::Translation(m_scalingOffset) - * KRMat4::Translation(-m_rotationPivot) - * KRMat4::Rotation(m_postRotation) - * KRMat4::Rotation(m_localRotation) - * KRMat4::Rotation(m_preRotation) - * KRMat4::Translation(m_rotationPivot) - * KRMat4::Translation(m_rotationOffset) - * KRMat4::Translation(m_localTranslation); + m_activePoseMatrix = Matrix4::Translation(-m_scalingPivot) + * Matrix4::Scaling(m_localScale) + * Matrix4::Translation(m_scalingPivot) + * Matrix4::Translation(m_scalingOffset) + * Matrix4::Translation(-m_rotationPivot) + * Matrix4::Rotation(m_postRotation) + * Matrix4::Rotation(m_localRotation) + * Matrix4::Rotation(m_preRotation) + * Matrix4::Translation(m_rotationPivot) + * Matrix4::Translation(m_rotationOffset) + * Matrix4::Translation(m_localTranslation); if(m_parentNode && parent_is_bone) { @@ -725,18 +725,18 @@ const KRQuaternion KRNode::getActivePoseWorldRotation() { return world_rotation; } -const KRMat4 &KRNode::getInverseModelMatrix() +const Matrix4 &KRNode::getInverseModelMatrix() { if(!m_inverseModelMatrixValid) { - m_inverseModelMatrix = KRMat4::Invert(getModelMatrix()); + m_inverseModelMatrix = Matrix4::Invert(getModelMatrix()); } return m_inverseModelMatrix; } -const KRMat4 &KRNode::getInverseBindPoseMatrix() +const Matrix4 &KRNode::getInverseBindPoseMatrix() { if(!m_inverseBindPoseMatrixValid ) { - m_inverseBindPoseMatrix = KRMat4::Invert(getBindPoseMatrix()); + m_inverseBindPoseMatrix = Matrix4::Invert(getBindPoseMatrix()); m_inverseBindPoseMatrixValid = true; } return m_inverseBindPoseMatrix; @@ -919,12 +919,12 @@ KRNode::LodVisibility KRNode::getLODVisibility() const Vector3 KRNode::localToWorld(const Vector3 &local_point) { - return KRMat4::Dot(getModelMatrix(), local_point); + return Matrix4::Dot(getModelMatrix(), local_point); } const Vector3 KRNode::worldToLocal(const Vector3 &world_point) { - return KRMat4::Dot(getInverseModelMatrix(), world_point); + return Matrix4::Dot(getInverseModelMatrix(), world_point); } void KRNode::addBehavior(KRBehavior *behavior) diff --git a/kraken/KRNode.h b/kraken/KRNode.h index d083a8c..2ddadbe 100755 --- a/kraken/KRNode.h +++ b/kraken/KRNode.h @@ -17,7 +17,7 @@ using namespace kraken; namespace kraken { -class KRMat4; +class Matrix4; class KRAABB; } // namespace kraken class KRCamera; @@ -125,11 +125,11 @@ public: virtual KRAABB getBounds(); void invalidateBounds() const; - const KRMat4 &getModelMatrix(); - const KRMat4 &getInverseModelMatrix(); - const KRMat4 &getBindPoseMatrix(); - const KRMat4 &getActivePoseMatrix(); - const KRMat4 &getInverseBindPoseMatrix(); + const Matrix4 &getModelMatrix(); + const Matrix4 &getInverseModelMatrix(); + const Matrix4 &getBindPoseMatrix(); + const Matrix4 &getActivePoseMatrix(); + const Matrix4 &getInverseBindPoseMatrix(); enum node_attribute_type { KRENGINE_NODE_ATTRIBUTE_NONE, @@ -219,11 +219,11 @@ private: long m_lastRenderFrame; void invalidateModelMatrix(); void invalidateBindPoseMatrix(); - KRMat4 m_modelMatrix; - KRMat4 m_inverseModelMatrix; - KRMat4 m_bindPoseMatrix; - KRMat4 m_activePoseMatrix; - KRMat4 m_inverseBindPoseMatrix; + Matrix4 m_modelMatrix; + Matrix4 m_inverseModelMatrix; + Matrix4 m_bindPoseMatrix; + Matrix4 m_activePoseMatrix; + Matrix4 m_inverseBindPoseMatrix; bool m_modelMatrixValid; bool m_inverseModelMatrixValid; bool m_bindPoseMatrixValid; diff --git a/kraken/KRPointLight.cpp b/kraken/KRPointLight.cpp index aca0362..f26f2c6 100755 --- a/kraken/KRPointLight.cpp +++ b/kraken/KRPointLight.cpp @@ -57,13 +57,13 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &point_ float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); - KRMat4 sphereModelMatrix = KRMat4(); + Matrix4 sphereModelMatrix = Matrix4(); sphereModelMatrix.scale(influence_radius); sphereModelMatrix.translate(light_position.x, light_position.y, light_position.z); if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum - Vector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position); + Vector3 view_light_position = Matrix4::Dot(viewport.getViewMatrix(), light_position); bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ()); diff --git a/kraken/KRQuaternion.cpp b/kraken/KRQuaternion.cpp index e90ba87..2765588 100755 --- a/kraken/KRQuaternion.cpp +++ b/kraken/KRQuaternion.cpp @@ -279,8 +279,8 @@ void KRQuaternion::conjugate() { m_val[3] = -m_val[3]; } -KRMat4 KRQuaternion::rotationMatrix() const { - KRMat4 matRotate; +Matrix4 KRQuaternion::rotationMatrix() const { + Matrix4 matRotate; /* Vector3 euler = eulerXYZ(); diff --git a/kraken/KRResource+fbx.cpp b/kraken/KRResource+fbx.cpp index 95cd010..ceeec90 100755 --- a/kraken/KRResource+fbx.cpp +++ b/kraken/KRResource+fbx.cpp @@ -1300,12 +1300,12 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe /* FbxMatrix fbx_bind_pose_matrix; - KRMat4 bind_pose; + Matrix4 bind_pose; PoseList pose_list; FbxArray pose_indices; if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) { fbx_bind_pose_matrix = (*pose_list)[0].GetMatrix(pose_indices[0]); - bind_pose = KRMat4( + bind_pose = Matrix4( Vector3(fbx_bind_pose_matrix.GetColumn(0).mData), Vector3(fbx_bind_pose_matrix.GetColumn(1).mData), Vector3(fbx_bind_pose_matrix.GetColumn(2).mData), @@ -1317,7 +1317,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe FbxAMatrix link_matrix; cluster->GetTransformLinkMatrix(link_matrix); - mi.bone_bind_poses.push_back(KRMat4( + mi.bone_bind_poses.push_back(Matrix4( Vector3(link_matrix.GetColumn(0).mData), Vector3(link_matrix.GetColumn(1).mData), Vector3(link_matrix.GetColumn(2).mData), diff --git a/kraken/KRResource+obj.cpp b/kraken/KRResource+obj.cpp index 61cd85f..e044b44 100755 --- a/kraken/KRResource+obj.cpp +++ b/kraken/KRResource+obj.cpp @@ -321,7 +321,7 @@ std::vector KRResource::LoadObj(KRContext &context, const std::str // TODO: Bones not yet supported for OBJ // std::vector bone_names; -// std::vector bone_bind_poses; +// std::vector bone_bind_poses; // std::vector > bone_indexes; // std::vector > bone_weights; // diff --git a/kraken/KRReverbZone.cpp b/kraken/KRReverbZone.cpp index 58f4fb1..741efbb 100755 --- a/kraken/KRReverbZone.cpp +++ b/kraken/KRReverbZone.cpp @@ -93,7 +93,7 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector &point_ bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES; if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { - KRMat4 sphereModelMatrix = getModelMatrix(); + Matrix4 sphereModelMatrix = getModelMatrix(); 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); diff --git a/kraken/KRScene.cpp b/kraken/KRScene.cpp index 925a6cc..9e65df6 100755 --- a/kraken/KRScene.cpp +++ b/kraken/KRScene.cpp @@ -274,10 +274,10 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi - KRMat4 matModel = KRMat4(); + Matrix4 matModel = Matrix4(); matModel.scale(octreeBounds.size() * 0.5f); matModel.translate(octreeBounds.center()); - KRMat4 mvpmatrix = matModel * viewport.getViewProjectionMatrix(); + Matrix4 mvpmatrix = matModel * viewport.getViewProjectionMatrix(); getContext().getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f); diff --git a/kraken/KRShader.cpp b/kraken/KRShader.cpp index 1c323e0..22f046a 100755 --- a/kraken/KRShader.cpp +++ b/kraken/KRShader.cpp @@ -332,7 +332,7 @@ void KRShader::setUniform(int location, const Vector4 &value) } } -void KRShader::setUniform(int location, const KRMat4 &value) +void KRShader::setUniform(int location, const Matrix4 &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 Vector3 &rim_color, float rim_power, const Vector4 &fade_color) { +bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &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 Vector4 &fade_color) { if(m_iProgram == 0) { return false; } @@ -405,7 +405,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE); } - KRMat4 matBias; + Matrix4 matBias; matBias.translate(1.0, 1.0, 1.0); matBias.scale(0.5); for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) { @@ -413,11 +413,11 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & } if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) { - KRMat4 inverseModelMatrix = matModel; + Matrix4 inverseModelMatrix = matModel; inverseModelMatrix.invert(); // Bind the light direction vector - Vector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); + Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); lightDirObject.normalize(); setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); } @@ -433,38 +433,38 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) { - KRMat4 inverseModelMatrix = matModel; + Matrix4 inverseModelMatrix = matModel; inverseModelMatrix.invert(); if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) { // Transform location of camera to object space for calculation of specular halfVec - Vector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, viewport.getCameraPosition()); + Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, viewport.getCameraPosition()); setUniform(KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE, cameraPosObject); } } if(m_uniforms[KRENGINE_UNIFORM_MVP] != -1 || m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) { // Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram - KRMat4 mvpMatrix = matModel * viewport.getViewProjectionMatrix(); + Matrix4 mvpMatrix = matModel * viewport.getViewProjectionMatrix(); setUniform(KRENGINE_UNIFORM_MVP, mvpMatrix); if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) { - setUniform(KRShader::KRENGINE_UNIFORM_INVMVP, KRMat4::Invert(mvpMatrix)); + setUniform(KRShader::KRENGINE_UNIFORM_INVMVP, Matrix4::Invert(mvpMatrix)); } } if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1 || m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1 || m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_VIEW] != -1) { - KRMat4 matModelView = matModel * viewport.getViewMatrix(); + Matrix4 matModelView = matModel * viewport.getViewMatrix(); setUniform(KRENGINE_UNIFORM_MODEL_VIEW, matModelView); if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) { - 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 + Vector3 view_space_model_origin = Matrix4::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); } if(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1) { - KRMat4 matModelViewInverseTranspose = matModelView; + Matrix4 matModelViewInverseTranspose = matModelView; matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.invert(); setUniform(KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE, matModelViewInverseTranspose); @@ -472,7 +472,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & } if(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE] != -1) { - KRMat4 matModelInverseTranspose = matModel; + Matrix4 matModelInverseTranspose = matModel; matModelInverseTranspose.transpose(); matModelInverseTranspose.invert(); setUniform(KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE, matModelInverseTranspose); @@ -483,7 +483,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & } if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] != -1) { - KRMat4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();; + Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();; // Remove the translation matInvMVPNoTranslate.getPointer()[3] = 0; matInvMVPNoTranslate.getPointer()[7] = 0; diff --git a/kraken/KRShader.h b/kraken/KRShader.h index bdedb49..93182e3 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 Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &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 Vector4 &fade_color); enum { KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0, @@ -142,7 +142,7 @@ public: std::vector m_uniform_value_vector2; std::vector m_uniform_value_vector3; std::vector m_uniform_value_vector4; - std::vector m_uniform_value_mat4; + std::vector m_uniform_value_mat4; char m_szKey[256]; @@ -152,7 +152,7 @@ public: void setUniform(int location, const Vector2 &value); void setUniform(int location, const Vector3 &value); void setUniform(int location, const Vector4 &value); - void setUniform(int location, const KRMat4 &value); + void setUniform(int location, const Matrix4 &value); private: GLuint m_iProgram; diff --git a/kraken/KRShaderManager.cpp b/kraken/KRShaderManager.cpp index 3015193..157f89d 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 Vector3 &rim_color, float rim_power, const Vector4 &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 Matrix4 &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 Vector4 &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 Vector3 &rim_color, float rim_power, const Vector4 &fade_color) +bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &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 Vector4 &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 3125fd6..e456b24 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 Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &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 Vector4 &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 Vector4 &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 Matrix4 &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 Vector4 &fade_color); long getShaderHandlesUsed(); diff --git a/kraken/KRViewport.cpp b/kraken/KRViewport.cpp index df9e5ee..72cfb9a 100755 --- a/kraken/KRViewport.cpp +++ b/kraken/KRViewport.cpp @@ -15,13 +15,13 @@ KRViewport::KRViewport() { m_size = Vector2::One(); - m_matProjection = KRMat4(); - m_matView = KRMat4(); + m_matProjection = Matrix4(); + m_matView = Matrix4(); m_lodBias = 0.0f; calculateDerivedValues(); } -KRViewport::KRViewport(const Vector2 &size, const KRMat4 &matView, const KRMat4 &matProjection) +KRViewport::KRViewport(const Vector2 &size, const Matrix4 &matView, const Matrix4 &matProjection) { m_size = size; m_matView = matView; @@ -53,12 +53,12 @@ const Vector2 &KRViewport::getSize() const return m_size; } -const KRMat4 &KRViewport::getViewMatrix() const +const Matrix4 &KRViewport::getViewMatrix() const { return m_matView; } -const KRMat4 &KRViewport::getProjectionMatrix() const +const Matrix4 &KRViewport::getProjectionMatrix() const { return m_matProjection; } @@ -68,29 +68,29 @@ void KRViewport::setSize(const Vector2 &size) m_size = size; } -void KRViewport::setViewMatrix(const KRMat4 &matView) +void KRViewport::setViewMatrix(const Matrix4 &matView) { m_matView = matView; calculateDerivedValues(); } -void KRViewport::setProjectionMatrix(const KRMat4 &matProjection) +void KRViewport::setProjectionMatrix(const Matrix4 &matProjection) { m_matProjection = matProjection; calculateDerivedValues(); } -const KRMat4 &KRViewport::KRViewport::getViewProjectionMatrix() const +const Matrix4 &KRViewport::KRViewport::getViewProjectionMatrix() const { return m_matViewProjection; } -const KRMat4 &KRViewport::getInverseViewMatrix() const +const Matrix4 &KRViewport::getInverseViewMatrix() const { return m_matInverseView; } -const KRMat4 &KRViewport::getInverseProjectionMatrix() const +const Matrix4 &KRViewport::getInverseProjectionMatrix() const { return m_matInverseProjection; } @@ -118,10 +118,10 @@ const int *KRViewport::getBackToFrontOrder() const 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, 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)); + m_matInverseView = Matrix4::Invert(m_matView); + m_matInverseProjection = Matrix4::Invert(m_matProjection); + m_cameraPosition = Matrix4::Dot(m_matInverseView, Vector3::Zero()); + m_cameraDirection = Matrix4::Dot(m_matInverseView, Vector3(0.0, 0.0, 1.0)) - Matrix4::Dot(m_matInverseView, Vector3(0.0, 0.0, 0.0)); for(int i=0; i<8; i++) { m_frontToBackOrder[i] = i; @@ -177,7 +177,7 @@ float KRViewport::coverage(const KRAABB &b) const Vector3 nearest_point = b.nearestPoint(getCameraPosition()); float distance = (nearest_point - getCameraPosition()).magnitude(); - Vector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance); + Vector3 v = Matrix4::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++) { - 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)); + Vector3 screen_pos = Matrix4::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(); @@ -226,7 +226,7 @@ bool KRViewport::visible(const KRAABB &b) const (iCorner & 2) == 0 ? b.min.y : b.max.y, (iCorner & 4) == 0 ? b.min.z : b.max.z, 1.0f); - Vector4 cornerVertex = KRMat4::Dot4(m_matViewProjection, sourceCornerVertex); + Vector4 cornerVertex = Matrix4::Dot4(m_matViewProjection, sourceCornerVertex); if(cornerVertex.x < -cornerVertex.w) { outside_count[0]++; diff --git a/kraken/KRViewport.h b/kraken/KRViewport.h index 249cad0..2773cdd 100755 --- a/kraken/KRViewport.h +++ b/kraken/KRViewport.h @@ -16,22 +16,22 @@ class KRLight; class KRViewport { public: KRViewport(); - KRViewport(const Vector2 &size, const KRMat4 &matView, const KRMat4 &matProjection); + KRViewport(const Vector2 &size, const Matrix4 &matView, const Matrix4 &matProjection); ~KRViewport(); const Vector2 &getSize() const; - const KRMat4 &getViewMatrix() const; - const KRMat4 &getProjectionMatrix() const; - const KRMat4 &getViewProjectionMatrix() const; - const KRMat4 &getInverseViewMatrix() const; - const KRMat4 &getInverseProjectionMatrix() const; + const Matrix4 &getViewMatrix() const; + const Matrix4 &getProjectionMatrix() const; + const Matrix4 &getViewProjectionMatrix() const; + const Matrix4 &getInverseViewMatrix() const; + const Matrix4 &getInverseProjectionMatrix() const; const Vector3 &getCameraDirection() const; const Vector3 &getCameraPosition() const; const int *getFrontToBackOrder() const; const int *getBackToFrontOrder() const; void setSize(const Vector2 &size); - void setViewMatrix(const KRMat4 &matView); - void setProjectionMatrix(const KRMat4 &matProjection); + void setViewMatrix(const Matrix4 &matView); + void setProjectionMatrix(const Matrix4 &matProjection); float getLODBias() const; void setLODBias(float lod_bias); @@ -48,15 +48,15 @@ public: private: Vector2 m_size; - KRMat4 m_matView; - KRMat4 m_matProjection; + Matrix4 m_matView; + Matrix4 m_matProjection; float m_lodBias; // Derived values - KRMat4 m_matViewProjection; - KRMat4 m_matInverseView; - KRMat4 m_matInverseProjection; + Matrix4 m_matViewProjection; + Matrix4 m_matInverseView; + Matrix4 m_matInverseProjection; Vector3 m_cameraDirection; Vector3 m_cameraPosition; diff --git a/kraken/public/KRAABB.h b/kraken/public/KRAABB.h index dd1bec8..ab82174 100644 --- a/kraken/public/KRAABB.h +++ b/kraken/public/KRAABB.h @@ -18,12 +18,12 @@ namespace kraken { -class KRMat4; +class Matrix4; class KRAABB { public: KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint); - KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix); + KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix); KRAABB(); ~KRAABB(); diff --git a/kraken/public/KRMat4.h b/kraken/public/KRMat4.h deleted file mode 100644 index 119b05b..0000000 --- a/kraken/public/KRMat4.h +++ /dev/null @@ -1,115 +0,0 @@ -// -// KRMat4.h -// Kraken -// -// Copyright 2017 Kearwood Gilbert. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation are those of the -// authors and should not be interpreted as representing official policies, either expressed -// or implied, of Kearwood Gilbert. -// - - -#include "Vector3.h" -#include "Vector4.h" - -#ifndef KRAKEN_MATRIX4_H -#define KRAKEN_MATRIX4_H - -namespace kraken { - -typedef enum { - X_AXIS, - Y_AXIS, - Z_AXIS -} AXIS; - -class KRQuaternion; - -class KRMat4 { -public: - - float c[16]; // Matrix components, in column-major order - - // Default constructor - Creates an identity matrix - KRMat4(); - - KRMat4(float *pMat); - - KRMat4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans); - - // Destructor - ~KRMat4(); - - // Copy constructor - KRMat4(const KRMat4 &m); - - // Overload assignment operator - KRMat4& operator=(const KRMat4 &m); - - // Overload comparison operator - bool operator==(const KRMat4 &m) const; - - // Overload compound multiply operator - KRMat4& operator*=(const KRMat4 &m); - - float& operator[](unsigned i); - float operator[](unsigned i) const; - - // Overload multiply operator - //KRMat4& operator*(const KRMat4 &m); - KRMat4 operator*(const KRMat4 &m) const; - - float *getPointer(); - - void perspective(float fov, float aspect, float nearz, float farz); - void ortho(float left, float right, float top, float bottom, float nearz, float farz); - void translate(float x, float y, float z); - void translate(const Vector3 &v); - void scale(float x, float y, float z); - void scale(const Vector3 &v); - void scale(float s); - void rotate(float angle, AXIS axis); - void rotate(const KRQuaternion &q); - void bias(); - bool invert(); - void transpose(); - - 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 Vector3 Dot(const KRMat4 &m, const Vector3 &v); - static Vector4 Dot4(const KRMat4 &m, const Vector4 &v); - static float DotW(const KRMat4 &m, const Vector3 &v); - static Vector3 DotWDiv(const KRMat4 &m, const Vector3 &v); - - static KRMat4 LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection); - - static KRMat4 Translation(const Vector3 &v); - static KRMat4 Rotation(const Vector3 &v); - static KRMat4 Scaling(const Vector3 &v); -}; - -} // namespace kraken - -#endif // KRAKEN_MATRIX4_H diff --git a/kraken/public/KRQuaternion.h b/kraken/public/KRQuaternion.h index 7366752..8e0f4b7 100644 --- a/kraken/public/KRQuaternion.h +++ b/kraken/public/KRQuaternion.h @@ -69,7 +69,7 @@ public: void setEulerXYZ(const Vector3 &euler); void setEulerZYX(const Vector3 &euler); Vector3 eulerXYZ() const; - KRMat4 rotationMatrix() const; + Matrix4 rotationMatrix() const; void normalize(); static KRQuaternion Normalize(const KRQuaternion &v1); diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 6839eeb..3efce16 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -5,7 +5,7 @@ #include "vector2.h" #include "vector3.h" #include "vector4.h" -#include "KRMat4.h" +#include "Matrix4.h" #include "KRQuaternion.h" #include "KRAABB.h" #include "KRTriangle3.h" diff --git a/kraken_win/kraken.vcxproj b/kraken_win/kraken.vcxproj index 2a06e26..1d008c2 100755 --- a/kraken_win/kraken.vcxproj +++ b/kraken_win/kraken.vcxproj @@ -156,7 +156,7 @@ - + @@ -274,7 +274,7 @@ - + diff --git a/kraken_win/kraken.vcxproj.filters b/kraken_win/kraken.vcxproj.filters index 1810bae..2f47495 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 + @@ -473,9 +473,6 @@ Header Files - - Header Files\public - Header Files\public @@ -500,5 +497,8 @@ Header Files\public + + Header Files\public + \ No newline at end of file