/s/KRMat4/Matrix4/g

This commit is contained in:
Kearwood Kip Gilbert
2017-07-29 17:54:27 -07:00
parent 1d98f314b2
commit 514b7e7ad0
41 changed files with 251 additions and 811 deletions

View File

@@ -22,10 +22,10 @@ KRAABB::KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint)
max = 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++) { 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 & 1) == 0 ? corner1.x : corner2.x,
(iCorner & 2) == 0 ? corner1.y : corner2.y, (iCorner & 2) == 0 ? corner1.y : corner2.y,
(iCorner & 4) == 0 ? corner1.z : corner2.z)); (iCorner & 4) == 0 ? corner1.z : corner2.z));

View File

@@ -94,7 +94,7 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES; bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES;
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { 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); 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);

View File

@@ -1218,12 +1218,12 @@ void KRAudioManager::makeCurrentContext()
initAudio(); initAudio();
} }
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix) void KRAudioManager::setListenerOrientationFromModelMatrix(const Matrix4 &modelMatrix)
{ {
setListenerOrientation( setListenerOrientation(
KRMat4::Dot(modelMatrix, Vector3(0.0, 0.0, 0.0)), Matrix4::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(Matrix4::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) Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3(0.0, 1.0, 0.0)) - m_listener_position)
); );
} }

View File

@@ -106,7 +106,7 @@ public:
KRScene *getListenerScene(); KRScene *getListenerScene();
void setListenerScene(KRScene *scene); void setListenerScene(KRScene *scene);
void setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up); void setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up);
void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix); void setListenerOrientationFromModelMatrix(const Matrix4 &modelMatrix);
Vector3 &getListenerForward(); Vector3 &getListenerForward();
Vector3 &getListenerPosition(); Vector3 &getListenerPosition();
Vector3 &getListenerUp(); Vector3 &getListenerUp();

View File

@@ -178,7 +178,7 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
bool bVisualize = false; bool bVisualize = false;
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { 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); 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);

View File

@@ -48,7 +48,7 @@ void KRBone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES; bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES;
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
KRMat4 sphereModelMatrix = getModelMatrix(); Matrix4 sphereModelMatrix = getModelMatrix();
// Enable additive blending // Enable additive blending
GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glEnable(GL_BLEND));
@@ -87,11 +87,11 @@ void KRBone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights
} }
void KRBone::setBindPose(const KRMat4 &pose) void KRBone::setBindPose(const Matrix4 &pose)
{ {
m_bind_pose = pose; m_bind_pose = pose;
} }
const KRMat4 &KRBone::getBindPose() const Matrix4 &KRBone::getBindPose()
{ {
return m_bind_pose; return m_bind_pose;
} }

View File

@@ -24,10 +24,10 @@ public:
void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
void setBindPose(const KRMat4 &pose); void setBindPose(const Matrix4 &pose);
const KRMat4 &getBindPose(); const Matrix4 &getBindPose();
private: private:
KRMat4 m_bind_pose; Matrix4 m_bind_pose;
}; };

View File

@@ -108,13 +108,13 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
KRScene &scene = getScene(); KRScene &scene = getScene();
KRMat4 modelMatrix = getModelMatrix(); Matrix4 modelMatrix = getModelMatrix();
KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, Vector3::Zero()), KRMat4::Dot(modelMatrix, Vector3::Forward()), Vector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, Vector3::Up()))); 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)); 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); 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 = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
m_viewport.setLODBias(settings.getLODBias()); m_viewport.setLODBias(settings.getLODBias());
@@ -312,7 +312,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
} }
if(m_pSkyBoxTexture) { if(m_pSkyBoxTexture) {
getContext().getShaderManager()->selectShader("sky_box", *this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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); 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); m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
for(unordered_map<KRAABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { for(unordered_map<KRAABB, int>::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.scale((*itr).first.size() * 0.5f);
matModel.translate((*itr).first.center()); matModel.translate((*itr).first.center());
if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) { if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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; Vector3 rim_color;
getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color); getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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, 0, compositeDepthTexture);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture); 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); // 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++) { // for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
// KRMat4 viewMatrix = KRMat4(); // Matrix4 viewMatrix = Matrix4();
// viewMatrix.scale(0.20, 0.20, 0.20); // viewMatrix.scale(0.20, 0.20, 0.20);
// viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0); // 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->getTextureManager()->selectTexture(1, NULL);
// m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES); // m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES);
// m_pContext->getTextureManager()->_setActiveTexture(0); // m_pContext->getTextureManager()->_setActiveTexture(0);
@@ -879,7 +879,7 @@ void KRCamera::renderPost()
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero()); getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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); m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI);

View File

@@ -98,17 +98,17 @@ bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitin
loadModel(); loadModel();
if(m_models.size()) { if(m_models.size()) {
if(getBounds().intersectsLine(v0, v1)) { if(getBounds().intersectsLine(v0, v1)) {
Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0);
Vector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); Vector3 v1_model_space = Matrix4::Dot(getInverseModelMatrix(), v1);
KRHitInfo hitinfo_model_space; KRHitInfo hitinfo_model_space;
if(hitinfo.didHit()) { if(hitinfo.didHit()) {
Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); Vector3 hit_position_model_space = Matrix4::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()); 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)) { 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()); Vector3 hit_position_world_space = Matrix4::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); hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
return true; return true;
} }
} }
@@ -123,17 +123,17 @@ bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitin
loadModel(); loadModel();
if(m_models.size()) { if(m_models.size()) {
if(getBounds().intersectsRay(v0, dir)) { if(getBounds().intersectsRay(v0, dir)) {
Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0);
Vector3 dir_model_space = Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir)); Vector3 dir_model_space = Vector3::Normalize(Matrix4::DotNoTranslate(getInverseModelMatrix(), dir));
KRHitInfo hitinfo_model_space; KRHitInfo hitinfo_model_space;
if(hitinfo.didHit()) { if(hitinfo.didHit()) {
Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); Vector3 hit_position_model_space = Matrix4::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()); 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)) { 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()); Vector3 hit_position_world_space = Matrix4::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); hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
return true; return true;
} }
} }

View File

@@ -29,7 +29,7 @@ std::string KRDirectionalLight::getElementName() {
} }
Vector3 KRDirectionalLight::getWorldLightDirection() { Vector3 KRDirectionalLight::getWorldLightDirection() {
return KRMat4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); return Matrix4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection());
} }
Vector3 KRDirectionalLight::getLocalLightDirection() { Vector3 KRDirectionalLight::getLocalLightDirection() {
@@ -52,7 +52,7 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
float max_depth = 1.0f; 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); worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection()); Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection());
@@ -60,24 +60,24 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
Vector3 shadowUp(0.0, 1.0, 0.0); 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 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); // Matrix4 matShadowView = Matrix4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp);
// KRMat4 matShadowProjection = KRMat4(); // Matrix4 matShadowProjection = Matrix4();
// matShadowProjection.scale(0.001, 0.001, 0.001); // matShadowProjection.scale(0.001, 0.001, 0.001);
KRMat4 matShadowView = KRMat4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp); Matrix4 matShadowView = Matrix4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp);
KRMat4 matShadowProjection = KRMat4(); Matrix4 matShadowProjection = Matrix4();
KRAABB shadowSpaceFrustrumSliceBounds = KRAABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, KRMat4::Invert(matShadowProjection)); KRAABB shadowSpaceFrustrumSliceBounds = KRAABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection));
KRAABB shadowSpaceSceneBounds = KRAABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, KRMat4::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 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); matShadowProjection.scale(1.0f / shadowSpaceFrustrumSliceBounds.size().x, 1.0f / shadowSpaceFrustrumSliceBounds.size().y, 1.0f / shadowSpaceFrustrumSliceBounds.size().z);
KRMat4 matBias; Matrix4 matBias;
matBias.bias(); matBias.bias();
matShadowProjection *= matBias; matShadowProjection *= matBias;
KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection); 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 prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix())); KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(newShadowViewport.getViewProjectionMatrix()));
minimumShadowBounds.scale(1.0f / KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); 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 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; m_shadowViewports[iShadow] = newShadowViewport;
@@ -101,12 +101,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &
std::vector<KRDirectionalLight *> this_light; std::vector<KRDirectionalLight *> this_light;
this_light.push_back(this); this_light.push_back(this);
KRMat4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix(); Matrix4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix();
matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.transpose();
matModelViewInverseTranspose.invert(); matModelViewInverseTranspose.invert();
Vector3 light_direction_view_space = getWorldLightDirection(); Vector3 light_direction_view_space = getWorldLightDirection();
light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space); light_direction_view_space = Matrix4::Dot(matModelViewInverseTranspose, light_direction_view_space);
light_direction_view_space.normalize(); light_direction_view_space.normalize();
KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);

View File

@@ -30,7 +30,7 @@
// //
// #include "KRTextureManager.h" // #include "KRTextureManager.h"
#include "KRMat4.h" #include "Matrix4.h"
#include "Vector3.h" #include "Vector3.h"
#include "KRMesh.h" #include "KRMesh.h"
#include "KRScene.h" #include "KRScene.h"

View File

@@ -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)); 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)); if (location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, v.c));
} }

View File

@@ -20,7 +20,7 @@ namespace kraken {
void SetUniform(GLint location, const Vector2 &v); void SetUniform(GLint location, const Vector2 &v);
void SetUniform(GLint location, const Vector3 &v); void SetUniform(GLint location, const Vector3 &v);
void SetUniform(GLint location, const Vector4 &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); 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); const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value);

View File

@@ -198,7 +198,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
GLDEBUG(glEnable(GL_DEPTH_TEST)); GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthRangef(0.0, 1.0)); 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.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()); particleModelMatrix.translate(viewport.getCameraPosition());
@@ -223,7 +223,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &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())) { 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_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); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size);
KRDataBlock particle_index_data; KRDataBlock particle_index_data;
@@ -256,7 +256,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &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); 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; int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
float slice_near = -pCamera->settings.getPerspectiveNearZ(); float slice_near = -pCamera->settings.getPerspectiveNearZ();
@@ -277,7 +277,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
if(m_flareTexture.size() && m_flareSize > 0.0f) { 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.scale(m_localScale * m_flareOcclusionSize);
occlusion_test_sphere_matrix.translate(m_localTranslation); occlusion_test_sphere_matrix.translate(m_localTranslation);
if(m_parentNode) { if(m_parentNode) {
@@ -449,7 +449,7 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera)
// Use shader program // Use shader program
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero()); getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 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); getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);

View File

@@ -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;
}

View File

@@ -302,7 +302,7 @@ void KRMaterial::getTextures()
} }
} }
bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &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<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &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; bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap;
getTextures(); getTextures();
@@ -345,12 +345,12 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &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 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); // 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]; Matrix4 skin_bone_bind_pose = bind_poses[bone_index];
KRMat4 active_mat = bone->getActivePoseMatrix(); Matrix4 active_mat = bone->getActivePoseMatrix();
KRMat4 inv_bind_mat = bone->getInverseBindPoseMatrix(); Matrix4 inv_bind_mat = bone->getInverseBindPoseMatrix();
KRMat4 inv_bind_mat2 = KRMat4::Invert(bind_poses[bone_index]); Matrix4 inv_bind_mat2 = Matrix4::Invert(bind_poses[bone_index]);
KRMat4 t = (inv_bind_mat * active_mat); Matrix4 t = (inv_bind_mat * active_mat);
KRMat4 t2 = inv_bind_mat2 * bone->getModelMatrix(); Matrix4 t2 = inv_bind_mat2 * bone->getModelMatrix();
for(int i=0; i < 16; i++) { for(int i=0; i < 16; i++) {
*bone_mat_component++ = t[i]; *bone_mat_component++ = t[i];
} }

View File

@@ -82,7 +82,7 @@ public:
bool isTransparent(); bool isTransparent();
const std::string &getName() const; const std::string &getName() const;
bool bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &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<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &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(); bool needsVertexTangents();

View File

@@ -254,7 +254,7 @@ kraken_stream_level KRMesh::getStreamLevel()
return stream_level; return stream_level;
} }
void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage) { void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage) {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //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) { 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 != NULL && pMaterial == (*mat_itr)) {
if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
std::vector<KRMat4> bone_bind_poses; std::vector<Matrix4> bone_bind_poses;
for(int i=0; i < bones.size(); i++) { for(int i=0; i < bones.size(); i++) {
bone_bind_poses.push_back(getBoneBindPose(i)); bone_bind_poses.push_back(getBoneBindPose(i));
} }
@@ -1093,9 +1093,9 @@ char *KRMesh::getBoneName(int bone_index)
return getBone(bone_index)->szName; 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 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(); m_pData->lock();
@@ -1236,7 +1236,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const V
return hit_found; 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); 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; Vector3 new_hit_point;
float new_hit_distance; 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(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()) { 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_v0 /= distance_total;
distance_v1 /= distance_total; distance_v1 /= distance_total;
distance_v2 /= 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); hitinfo = KRHitInfo(new_hit_point, world_tri.calculateNormal(), new_hit_distance);
return true; return true;

View File

@@ -108,11 +108,11 @@ public:
std::vector<std::string> material_names; std::vector<std::string> material_names;
std::vector<std::string> bone_names; std::vector<std::string> bone_names;
std::vector<std::vector<int> > bone_indexes; std::vector<std::vector<int> > bone_indexes;
std::vector<KRMat4> bone_bind_poses; std::vector<Matrix4> bone_bind_poses;
std::vector<std::vector<float> > bone_weights; std::vector<std::vector<float> > bone_weights;
} mesh_info; } mesh_info;
void render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f); void render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
std::string m_lodBaseName; std::string m_lodBaseName;
@@ -206,14 +206,14 @@ public:
int getBoneCount(); int getBoneCount();
char *getBoneName(int bone_index); char *getBoneName(int bone_index);
KRMat4 getBoneBindPose(int bone_index); Matrix4 getBoneBindPose(int bone_index);
model_format_t getModelFormat() const; model_format_t getModelFormat() const;
bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const; bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const;
bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo) const; bool 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); static int GetLODCoverage(const std::string &name);
@@ -231,7 +231,7 @@ private:
void getMaterials(); 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 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) 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<KRMaterial *> m_materials; vector<KRMaterial *> m_materials;

View File

@@ -196,9 +196,9 @@ void KRModel::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP); m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP);
} }
KRMat4 matModel = getModelMatrix(); Matrix4 matModel = getModelMatrix();
if(m_faces_camera) { 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(); Vector3 camera_pos = viewport.getCameraPosition();
matModel = KRQuaternion(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; matModel = KRQuaternion(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
} }

View File

@@ -84,7 +84,7 @@ private:
bool m_faces_camera; bool m_faces_camera;
KRMat4 m_boundsCachedMat; Matrix4 m_boundsCachedMat;
KRAABB m_boundsCached; KRAABB m_boundsCached;

View File

@@ -58,9 +58,9 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getCont
m_bindPoseMatrixValid = false; m_bindPoseMatrixValid = false;
m_activePoseMatrixValid = false; m_activePoseMatrixValid = false;
m_inverseBindPoseMatrixValid = false; m_inverseBindPoseMatrixValid = false;
m_modelMatrix = KRMat4(); m_modelMatrix = Matrix4();
m_bindPoseMatrix = KRMat4(); m_bindPoseMatrix = Matrix4();
m_activePoseMatrix = KRMat4(); m_activePoseMatrix = Matrix4();
m_lod_visible = LOD_VISIBILITY_HIDDEN; m_lod_visible = LOD_VISIBILITY_HIDDEN;
m_scale_compensation = false; m_scale_compensation = false;
m_boundsValid = false; m_boundsValid = false;
@@ -203,7 +203,7 @@ void KRNode::setLocalTranslation(const Vector3 &v, bool set_original) {
void KRNode::setWorldTranslation(const Vector3 &v) void KRNode::setWorldTranslation(const Vector3 &v)
{ {
if(m_parentNode) { if(m_parentNode) {
setLocalTranslation(KRMat4::Dot(m_parentNode->getInverseModelMatrix(), v)); setLocalTranslation(Matrix4::Dot(m_parentNode->getInverseModelMatrix(), v));
} else { } else {
setLocalTranslation(v); setLocalTranslation(v);
} }
@@ -227,7 +227,7 @@ void KRNode::setWorldRotation(const Vector3 &v)
void KRNode::setWorldScale(const Vector3 &v) void KRNode::setWorldScale(const Vector3 &v)
{ {
if(m_parentNode) { if(m_parentNode) {
setLocalScale(KRMat4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v)); setLocalScale(Matrix4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v));
} else { } else {
setLocalScale(v); setLocalScale(v);
} }
@@ -383,7 +383,7 @@ const Vector3 KRNode::getWorldTranslation() {
} }
const Vector3 KRNode::getWorldScale() { const Vector3 KRNode::getWorldScale() {
return KRMat4::DotNoTranslate(getModelMatrix(), m_localScale); return Matrix4::DotNoTranslate(getModelMatrix(), m_localScale);
} }
std::string KRNode::getElementName() { std::string KRNode::getElementName() {
@@ -523,11 +523,11 @@ void KRNode::invalidateBindPoseMatrix()
} }
} }
const KRMat4 &KRNode::getModelMatrix() const Matrix4 &KRNode::getModelMatrix()
{ {
if(!m_modelMatrixValid) { if(!m_modelMatrixValid) {
m_modelMatrix = KRMat4(); m_modelMatrix = Matrix4();
bool parent_is_bone = false; bool parent_is_bone = false;
if(dynamic_cast<KRBone *>(m_parentNode)) { if(dynamic_cast<KRBone *>(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 // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1
m_modelMatrix = KRMat4::Translation(-m_scalingPivot) m_modelMatrix = Matrix4::Translation(-m_scalingPivot)
* KRMat4::Scaling(m_localScale) * Matrix4::Scaling(m_localScale)
* KRMat4::Translation(m_scalingPivot) * Matrix4::Translation(m_scalingPivot)
* KRMat4::Translation(m_scalingOffset) * Matrix4::Translation(m_scalingOffset)
* KRMat4::Translation(-m_rotationPivot) * Matrix4::Translation(-m_rotationPivot)
//* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix() //* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix()
* KRMat4::Rotation(m_postRotation) * Matrix4::Rotation(m_postRotation)
* KRMat4::Rotation(m_localRotation) * Matrix4::Rotation(m_localRotation)
* KRMat4::Rotation(m_preRotation) * Matrix4::Rotation(m_preRotation)
* KRMat4::Translation(m_rotationPivot) * Matrix4::Translation(m_rotationPivot)
* KRMat4::Translation(m_rotationOffset); * Matrix4::Translation(m_rotationOffset);
if(m_parentNode) { if(m_parentNode) {
m_modelMatrix.rotate(m_parentNode->getWorldRotation()); 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 { } else {
m_modelMatrix.translate(m_localTranslation); m_modelMatrix.translate(m_localTranslation);
} }
} else { } else {
// WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1
m_modelMatrix = KRMat4::Translation(-m_scalingPivot) m_modelMatrix = Matrix4::Translation(-m_scalingPivot)
* KRMat4::Scaling(m_localScale) * Matrix4::Scaling(m_localScale)
* KRMat4::Translation(m_scalingPivot) * Matrix4::Translation(m_scalingPivot)
* KRMat4::Translation(m_scalingOffset) * Matrix4::Translation(m_scalingOffset)
* KRMat4::Translation(-m_rotationPivot) * Matrix4::Translation(-m_rotationPivot)
//* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix() //* (KRQuaternion(m_postRotation) * KRQuaternion(m_localRotation) * KRQuaternion(m_preRotation)).rotationMatrix()
* KRMat4::Rotation(m_postRotation) * Matrix4::Rotation(m_postRotation)
* KRMat4::Rotation(m_localRotation) * Matrix4::Rotation(m_localRotation)
* KRMat4::Rotation(m_preRotation) * Matrix4::Rotation(m_preRotation)
* KRMat4::Translation(m_rotationPivot) * Matrix4::Translation(m_rotationPivot)
* KRMat4::Translation(m_rotationOffset) * Matrix4::Translation(m_rotationOffset)
* KRMat4::Translation(m_localTranslation); * Matrix4::Translation(m_localTranslation);
if(m_parentNode) { if(m_parentNode) {
m_modelMatrix *= m_parentNode->getModelMatrix(); m_modelMatrix *= m_parentNode->getModelMatrix();
@@ -584,10 +584,10 @@ const KRMat4 &KRNode::getModelMatrix()
return m_modelMatrix; return m_modelMatrix;
} }
const KRMat4 &KRNode::getBindPoseMatrix() const Matrix4 &KRNode::getBindPoseMatrix()
{ {
if(!m_bindPoseMatrixValid) { if(!m_bindPoseMatrixValid) {
m_bindPoseMatrix = KRMat4(); m_bindPoseMatrix = Matrix4();
bool parent_is_bone = false; bool parent_is_bone = false;
if(dynamic_cast<KRBone *>(m_parentNode)) { if(dynamic_cast<KRBone *>(m_parentNode)) {
@@ -595,22 +595,22 @@ const KRMat4 &KRNode::getBindPoseMatrix()
} }
if(getScaleCompensation() && parent_is_bone) { if(getScaleCompensation() && parent_is_bone) {
m_bindPoseMatrix = KRMat4::Translation(-m_initialScalingPivot) m_bindPoseMatrix = Matrix4::Translation(-m_initialScalingPivot)
* KRMat4::Scaling(m_initialLocalScale) * Matrix4::Scaling(m_initialLocalScale)
* KRMat4::Translation(m_initialScalingPivot) * Matrix4::Translation(m_initialScalingPivot)
* KRMat4::Translation(m_initialScalingOffset) * Matrix4::Translation(m_initialScalingOffset)
* KRMat4::Translation(-m_initialRotationPivot) * Matrix4::Translation(-m_initialRotationPivot)
//* (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix() //* (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix()
* KRMat4::Rotation(m_initialPostRotation) * Matrix4::Rotation(m_initialPostRotation)
* KRMat4::Rotation(m_initialLocalRotation) * Matrix4::Rotation(m_initialLocalRotation)
* KRMat4::Rotation(m_initialPreRotation) * Matrix4::Rotation(m_initialPreRotation)
* KRMat4::Translation(m_initialRotationPivot) * Matrix4::Translation(m_initialRotationPivot)
* KRMat4::Translation(m_initialRotationOffset); * Matrix4::Translation(m_initialRotationOffset);
//m_bindPoseMatrix.translate(m_localTranslation); //m_bindPoseMatrix.translate(m_localTranslation);
if(m_parentNode) { if(m_parentNode) {
m_bindPoseMatrix.rotate(m_parentNode->getBindPoseWorldRotation()); 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 { } else {
m_bindPoseMatrix.translate(m_localTranslation); 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 // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1
m_bindPoseMatrix = KRMat4::Translation(-m_initialScalingPivot) m_bindPoseMatrix = Matrix4::Translation(-m_initialScalingPivot)
* KRMat4::Scaling(m_initialLocalScale) * Matrix4::Scaling(m_initialLocalScale)
* KRMat4::Translation(m_initialScalingPivot) * Matrix4::Translation(m_initialScalingPivot)
* KRMat4::Translation(m_initialScalingOffset) * Matrix4::Translation(m_initialScalingOffset)
* KRMat4::Translation(-m_initialRotationPivot) * Matrix4::Translation(-m_initialRotationPivot)
// * (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix() // * (KRQuaternion(m_initialPostRotation) * KRQuaternion(m_initialLocalRotation) * KRQuaternion(m_initialPreRotation)).rotationMatrix()
* KRMat4::Rotation(m_initialPostRotation) * Matrix4::Rotation(m_initialPostRotation)
* KRMat4::Rotation(m_initialLocalRotation) * Matrix4::Rotation(m_initialLocalRotation)
* KRMat4::Rotation(m_initialPreRotation) * Matrix4::Rotation(m_initialPreRotation)
* KRMat4::Translation(m_initialRotationPivot) * Matrix4::Translation(m_initialRotationPivot)
* KRMat4::Translation(m_initialRotationOffset) * Matrix4::Translation(m_initialRotationOffset)
* KRMat4::Translation(m_initialLocalTranslation); * Matrix4::Translation(m_initialLocalTranslation);
if(m_parentNode && parent_is_bone) { if(m_parentNode && parent_is_bone) {
@@ -643,11 +643,11 @@ const KRMat4 &KRNode::getBindPoseMatrix()
return m_bindPoseMatrix; return m_bindPoseMatrix;
} }
const KRMat4 &KRNode::getActivePoseMatrix() const Matrix4 &KRNode::getActivePoseMatrix()
{ {
if(!m_activePoseMatrixValid) { if(!m_activePoseMatrixValid) {
m_activePoseMatrix = KRMat4(); m_activePoseMatrix = Matrix4();
bool parent_is_bone = false; bool parent_is_bone = false;
if(dynamic_cast<KRBone *>(m_parentNode)) { if(dynamic_cast<KRBone *>(m_parentNode)) {
@@ -655,38 +655,38 @@ const KRMat4 &KRNode::getActivePoseMatrix()
} }
if(getScaleCompensation() && parent_is_bone) { if(getScaleCompensation() && parent_is_bone) {
m_activePoseMatrix= KRMat4::Translation(-m_scalingPivot) m_activePoseMatrix= Matrix4::Translation(-m_scalingPivot)
* KRMat4::Scaling(m_localScale) * Matrix4::Scaling(m_localScale)
* KRMat4::Translation(m_scalingPivot) * Matrix4::Translation(m_scalingPivot)
* KRMat4::Translation(m_scalingOffset) * Matrix4::Translation(m_scalingOffset)
* KRMat4::Translation(-m_rotationPivot) * Matrix4::Translation(-m_rotationPivot)
* KRMat4::Rotation(m_postRotation) * Matrix4::Rotation(m_postRotation)
* KRMat4::Rotation(m_localRotation) * Matrix4::Rotation(m_localRotation)
* KRMat4::Rotation(m_preRotation) * Matrix4::Rotation(m_preRotation)
* KRMat4::Translation(m_rotationPivot) * Matrix4::Translation(m_rotationPivot)
* KRMat4::Translation(m_rotationOffset); * Matrix4::Translation(m_rotationOffset);
if(m_parentNode) { if(m_parentNode) {
m_activePoseMatrix.rotate(m_parentNode->getActivePoseWorldRotation()); 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 { } else {
m_activePoseMatrix.translate(m_localTranslation); m_activePoseMatrix.translate(m_localTranslation);
} }
} else { } else {
// WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1 // WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost * Rp-1 * Soff * Sp * S * Sp-1
m_activePoseMatrix = KRMat4::Translation(-m_scalingPivot) m_activePoseMatrix = Matrix4::Translation(-m_scalingPivot)
* KRMat4::Scaling(m_localScale) * Matrix4::Scaling(m_localScale)
* KRMat4::Translation(m_scalingPivot) * Matrix4::Translation(m_scalingPivot)
* KRMat4::Translation(m_scalingOffset) * Matrix4::Translation(m_scalingOffset)
* KRMat4::Translation(-m_rotationPivot) * Matrix4::Translation(-m_rotationPivot)
* KRMat4::Rotation(m_postRotation) * Matrix4::Rotation(m_postRotation)
* KRMat4::Rotation(m_localRotation) * Matrix4::Rotation(m_localRotation)
* KRMat4::Rotation(m_preRotation) * Matrix4::Rotation(m_preRotation)
* KRMat4::Translation(m_rotationPivot) * Matrix4::Translation(m_rotationPivot)
* KRMat4::Translation(m_rotationOffset) * Matrix4::Translation(m_rotationOffset)
* KRMat4::Translation(m_localTranslation); * Matrix4::Translation(m_localTranslation);
if(m_parentNode && parent_is_bone) { if(m_parentNode && parent_is_bone) {
@@ -725,18 +725,18 @@ const KRQuaternion KRNode::getActivePoseWorldRotation() {
return world_rotation; return world_rotation;
} }
const KRMat4 &KRNode::getInverseModelMatrix() const Matrix4 &KRNode::getInverseModelMatrix()
{ {
if(!m_inverseModelMatrixValid) { if(!m_inverseModelMatrixValid) {
m_inverseModelMatrix = KRMat4::Invert(getModelMatrix()); m_inverseModelMatrix = Matrix4::Invert(getModelMatrix());
} }
return m_inverseModelMatrix; return m_inverseModelMatrix;
} }
const KRMat4 &KRNode::getInverseBindPoseMatrix() const Matrix4 &KRNode::getInverseBindPoseMatrix()
{ {
if(!m_inverseBindPoseMatrixValid ) { if(!m_inverseBindPoseMatrixValid ) {
m_inverseBindPoseMatrix = KRMat4::Invert(getBindPoseMatrix()); m_inverseBindPoseMatrix = Matrix4::Invert(getBindPoseMatrix());
m_inverseBindPoseMatrixValid = true; m_inverseBindPoseMatrixValid = true;
} }
return m_inverseBindPoseMatrix; return m_inverseBindPoseMatrix;
@@ -919,12 +919,12 @@ KRNode::LodVisibility KRNode::getLODVisibility()
const Vector3 KRNode::localToWorld(const Vector3 &local_point) 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) 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) void KRNode::addBehavior(KRBehavior *behavior)

View File

@@ -17,7 +17,7 @@
using namespace kraken; using namespace kraken;
namespace kraken { namespace kraken {
class KRMat4; class Matrix4;
class KRAABB; class KRAABB;
} // namespace kraken } // namespace kraken
class KRCamera; class KRCamera;
@@ -125,11 +125,11 @@ public:
virtual KRAABB getBounds(); virtual KRAABB getBounds();
void invalidateBounds() const; void invalidateBounds() const;
const KRMat4 &getModelMatrix(); const Matrix4 &getModelMatrix();
const KRMat4 &getInverseModelMatrix(); const Matrix4 &getInverseModelMatrix();
const KRMat4 &getBindPoseMatrix(); const Matrix4 &getBindPoseMatrix();
const KRMat4 &getActivePoseMatrix(); const Matrix4 &getActivePoseMatrix();
const KRMat4 &getInverseBindPoseMatrix(); const Matrix4 &getInverseBindPoseMatrix();
enum node_attribute_type { enum node_attribute_type {
KRENGINE_NODE_ATTRIBUTE_NONE, KRENGINE_NODE_ATTRIBUTE_NONE,
@@ -219,11 +219,11 @@ private:
long m_lastRenderFrame; long m_lastRenderFrame;
void invalidateModelMatrix(); void invalidateModelMatrix();
void invalidateBindPoseMatrix(); void invalidateBindPoseMatrix();
KRMat4 m_modelMatrix; Matrix4 m_modelMatrix;
KRMat4 m_inverseModelMatrix; Matrix4 m_inverseModelMatrix;
KRMat4 m_bindPoseMatrix; Matrix4 m_bindPoseMatrix;
KRMat4 m_activePoseMatrix; Matrix4 m_activePoseMatrix;
KRMat4 m_inverseBindPoseMatrix; Matrix4 m_inverseBindPoseMatrix;
bool m_modelMatrixValid; bool m_modelMatrixValid;
bool m_inverseModelMatrixValid; bool m_inverseModelMatrixValid;
bool m_bindPoseMatrixValid; bool m_bindPoseMatrixValid;

View File

@@ -57,13 +57,13 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); 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.scale(influence_radius);
sphereModelMatrix.translate(light_position.x, light_position.y, light_position.z); sphereModelMatrix.translate(light_position.x, light_position.y, light_position.z);
if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum 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()); bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());

View File

@@ -279,8 +279,8 @@ void KRQuaternion::conjugate() {
m_val[3] = -m_val[3]; m_val[3] = -m_val[3];
} }
KRMat4 KRQuaternion::rotationMatrix() const { Matrix4 KRQuaternion::rotationMatrix() const {
KRMat4 matRotate; Matrix4 matRotate;
/* /*
Vector3 euler = eulerXYZ(); Vector3 euler = eulerXYZ();

View File

@@ -1300,12 +1300,12 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
/* /*
FbxMatrix fbx_bind_pose_matrix; FbxMatrix fbx_bind_pose_matrix;
KRMat4 bind_pose; Matrix4 bind_pose;
PoseList pose_list; PoseList pose_list;
FbxArray<int> pose_indices; FbxArray<int> pose_indices;
if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) { if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) {
fbx_bind_pose_matrix = (*pose_list)[0].GetMatrix(pose_indices[0]); 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(0).mData),
Vector3(fbx_bind_pose_matrix.GetColumn(1).mData), Vector3(fbx_bind_pose_matrix.GetColumn(1).mData),
Vector3(fbx_bind_pose_matrix.GetColumn(2).mData), Vector3(fbx_bind_pose_matrix.GetColumn(2).mData),
@@ -1317,7 +1317,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
FbxAMatrix link_matrix; FbxAMatrix link_matrix;
cluster->GetTransformLinkMatrix(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(0).mData),
Vector3(link_matrix.GetColumn(1).mData), Vector3(link_matrix.GetColumn(1).mData),
Vector3(link_matrix.GetColumn(2).mData), Vector3(link_matrix.GetColumn(2).mData),

View File

@@ -321,7 +321,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
// TODO: Bones not yet supported for OBJ // TODO: Bones not yet supported for OBJ
// std::vector<std::string> bone_names; // std::vector<std::string> bone_names;
// std::vector<KRMat4> bone_bind_poses; // std::vector<Matrix4> bone_bind_poses;
// std::vector<std::vector<int> > bone_indexes; // std::vector<std::vector<int> > bone_indexes;
// std::vector<std::vector<float> > bone_weights; // std::vector<std::vector<float> > bone_weights;
// //

View File

@@ -93,7 +93,7 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES; bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES;
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { 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); 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);

View File

@@ -274,10 +274,10 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
KRMat4 matModel = KRMat4(); Matrix4 matModel = Matrix4();
matModel.scale(octreeBounds.size() * 0.5f); matModel.scale(octreeBounds.size() * 0.5f);
matModel.translate(octreeBounds.center()); 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); getContext().getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);

View File

@@ -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) { if(m_uniforms[location] != -1) {
int value_index = m_uniform_value_index[location]; 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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) {
if(m_iProgram == 0) { if(m_iProgram == 0) {
return false; 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); m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE);
} }
KRMat4 matBias; Matrix4 matBias;
matBias.translate(1.0, 1.0, 1.0); matBias.translate(1.0, 1.0, 1.0);
matBias.scale(0.5); matBias.scale(0.5);
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) { 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) { if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) {
KRMat4 inverseModelMatrix = matModel; Matrix4 inverseModelMatrix = matModel;
inverseModelMatrix.invert(); inverseModelMatrix.invert();
// Bind the light direction vector // Bind the light direction vector
Vector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
lightDirObject.normalize(); lightDirObject.normalize();
setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); 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) { if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) {
KRMat4 inverseModelMatrix = matModel; Matrix4 inverseModelMatrix = matModel;
inverseModelMatrix.invert(); inverseModelMatrix.invert();
if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) { if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) {
// Transform location of camera to object space for calculation of specular halfVec // 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); setUniform(KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE, cameraPosObject);
} }
} }
if(m_uniforms[KRENGINE_UNIFORM_MVP] != -1 || m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) { 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 // 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); setUniform(KRENGINE_UNIFORM_MVP, mvpMatrix);
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) { 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) { 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); setUniform(KRENGINE_UNIFORM_MODEL_VIEW, matModelView);
if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) { 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); setUniform(KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN, view_space_model_origin);
} }
if(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1) { if(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1) {
KRMat4 matModelViewInverseTranspose = matModelView; Matrix4 matModelViewInverseTranspose = matModelView;
matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.transpose();
matModelViewInverseTranspose.invert(); matModelViewInverseTranspose.invert();
setUniform(KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE, matModelViewInverseTranspose); 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) { if(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE] != -1) {
KRMat4 matModelInverseTranspose = matModel; Matrix4 matModelInverseTranspose = matModel;
matModelInverseTranspose.transpose(); matModelInverseTranspose.transpose();
matModelInverseTranspose.invert(); matModelInverseTranspose.invert();
setUniform(KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE, matModelInverseTranspose); 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) { if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] != -1) {
KRMat4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();; Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();;
// Remove the translation // Remove the translation
matInvMVPNoTranslate.getPointer()[3] = 0; matInvMVPNoTranslate.getPointer()[3] = 0;
matInvMVPNoTranslate.getPointer()[7] = 0; matInvMVPNoTranslate.getPointer()[7] = 0;

View File

@@ -46,7 +46,7 @@ public:
virtual ~KRShader(); virtual ~KRShader();
const char *getKey() const; const char *getKey() const;
bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
enum { enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0, KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0,
@@ -142,7 +142,7 @@ public:
std::vector<Vector2> m_uniform_value_vector2; std::vector<Vector2> m_uniform_value_vector2;
std::vector<Vector3> m_uniform_value_vector3; std::vector<Vector3> m_uniform_value_vector3;
std::vector<Vector4> m_uniform_value_vector4; std::vector<Vector4> m_uniform_value_vector4;
std::vector<KRMat4> m_uniform_value_mat4; std::vector<Matrix4> m_uniform_value_mat4;
char m_szKey[256]; char m_szKey[256];
@@ -152,7 +152,7 @@ public:
void setUniform(int location, const Vector2 &value); void setUniform(int location, const Vector2 &value);
void setUniform(int location, const Vector3 &value); void setUniform(int location, const Vector3 &value);
void setUniform(int location, const Vector4 &value); void setUniform(int location, const Vector4 &value);
void setUniform(int location, const KRMat4 &value); void setUniform(int location, const Matrix4 &value);
private: private:
GLuint m_iProgram; GLuint m_iProgram;

View File

@@ -245,13 +245,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
return pShader; return pShader;
} }
bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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); 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); 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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color)
{ {
if(pShader) { if(pShader) {
return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color); return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color);

View File

@@ -60,9 +60,9 @@ public:
KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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); KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&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(); long getShaderHandlesUsed();

View File

@@ -15,13 +15,13 @@
KRViewport::KRViewport() KRViewport::KRViewport()
{ {
m_size = Vector2::One(); m_size = Vector2::One();
m_matProjection = KRMat4(); m_matProjection = Matrix4();
m_matView = KRMat4(); m_matView = Matrix4();
m_lodBias = 0.0f; m_lodBias = 0.0f;
calculateDerivedValues(); 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_size = size;
m_matView = matView; m_matView = matView;
@@ -53,12 +53,12 @@ const Vector2 &KRViewport::getSize() const
return m_size; return m_size;
} }
const KRMat4 &KRViewport::getViewMatrix() const const Matrix4 &KRViewport::getViewMatrix() const
{ {
return m_matView; return m_matView;
} }
const KRMat4 &KRViewport::getProjectionMatrix() const const Matrix4 &KRViewport::getProjectionMatrix() const
{ {
return m_matProjection; return m_matProjection;
} }
@@ -68,29 +68,29 @@ void KRViewport::setSize(const Vector2 &size)
m_size = size; m_size = size;
} }
void KRViewport::setViewMatrix(const KRMat4 &matView) void KRViewport::setViewMatrix(const Matrix4 &matView)
{ {
m_matView = matView; m_matView = matView;
calculateDerivedValues(); calculateDerivedValues();
} }
void KRViewport::setProjectionMatrix(const KRMat4 &matProjection) void KRViewport::setProjectionMatrix(const Matrix4 &matProjection)
{ {
m_matProjection = matProjection; m_matProjection = matProjection;
calculateDerivedValues(); calculateDerivedValues();
} }
const KRMat4 &KRViewport::KRViewport::getViewProjectionMatrix() const const Matrix4 &KRViewport::KRViewport::getViewProjectionMatrix() const
{ {
return m_matViewProjection; return m_matViewProjection;
} }
const KRMat4 &KRViewport::getInverseViewMatrix() const const Matrix4 &KRViewport::getInverseViewMatrix() const
{ {
return m_matInverseView; return m_matInverseView;
} }
const KRMat4 &KRViewport::getInverseProjectionMatrix() const const Matrix4 &KRViewport::getInverseProjectionMatrix() const
{ {
return m_matInverseProjection; return m_matInverseProjection;
} }
@@ -118,10 +118,10 @@ const int *KRViewport::getBackToFrontOrder() const
void KRViewport::calculateDerivedValues() void KRViewport::calculateDerivedValues()
{ {
m_matViewProjection = m_matView * m_matProjection; m_matViewProjection = m_matView * m_matProjection;
m_matInverseView = KRMat4::Invert(m_matView); m_matInverseView = Matrix4::Invert(m_matView);
m_matInverseProjection = KRMat4::Invert(m_matProjection); m_matInverseProjection = Matrix4::Invert(m_matProjection);
m_cameraPosition = KRMat4::Dot(m_matInverseView, Vector3::Zero()); m_cameraPosition = Matrix4::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_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++) { for(int i=0; i<8; i++) {
m_frontToBackOrder[i] = i; m_frontToBackOrder[i] = i;
@@ -177,7 +177,7 @@ float KRViewport::coverage(const KRAABB &b) const
Vector3 nearest_point = b.nearestPoint(getCameraPosition()); Vector3 nearest_point = b.nearestPoint(getCameraPosition());
float distance = (nearest_point - getCameraPosition()).magnitude(); 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; float screen_depth = distance / 1000.0f;
@@ -189,7 +189,7 @@ float KRViewport::coverage(const KRAABB &b) const
Vector2 screen_max; Vector2 screen_max;
// Loop through all corners and transform them to screen space // Loop through all corners and transform them to screen space
for(int i=0; i<8; i++) { 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) { if(i==0) {
screen_min = screen_pos.xy(); screen_min = screen_pos.xy();
screen_max = 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 & 2) == 0 ? b.min.y : b.max.y,
(iCorner & 4) == 0 ? b.min.z : b.max.z, 1.0f); (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) { if(cornerVertex.x < -cornerVertex.w) {
outside_count[0]++; outside_count[0]++;

View File

@@ -16,22 +16,22 @@ class KRLight;
class KRViewport { class KRViewport {
public: public:
KRViewport(); KRViewport();
KRViewport(const Vector2 &size, const KRMat4 &matView, const KRMat4 &matProjection); KRViewport(const Vector2 &size, const Matrix4 &matView, const Matrix4 &matProjection);
~KRViewport(); ~KRViewport();
const Vector2 &getSize() const; const Vector2 &getSize() const;
const KRMat4 &getViewMatrix() const; const Matrix4 &getViewMatrix() const;
const KRMat4 &getProjectionMatrix() const; const Matrix4 &getProjectionMatrix() const;
const KRMat4 &getViewProjectionMatrix() const; const Matrix4 &getViewProjectionMatrix() const;
const KRMat4 &getInverseViewMatrix() const; const Matrix4 &getInverseViewMatrix() const;
const KRMat4 &getInverseProjectionMatrix() const; const Matrix4 &getInverseProjectionMatrix() const;
const Vector3 &getCameraDirection() const; const Vector3 &getCameraDirection() const;
const Vector3 &getCameraPosition() const; const Vector3 &getCameraPosition() const;
const int *getFrontToBackOrder() const; const int *getFrontToBackOrder() const;
const int *getBackToFrontOrder() const; const int *getBackToFrontOrder() const;
void setSize(const Vector2 &size); void setSize(const Vector2 &size);
void setViewMatrix(const KRMat4 &matView); void setViewMatrix(const Matrix4 &matView);
void setProjectionMatrix(const KRMat4 &matProjection); void setProjectionMatrix(const Matrix4 &matProjection);
float getLODBias() const; float getLODBias() const;
void setLODBias(float lod_bias); void setLODBias(float lod_bias);
@@ -48,15 +48,15 @@ public:
private: private:
Vector2 m_size; Vector2 m_size;
KRMat4 m_matView; Matrix4 m_matView;
KRMat4 m_matProjection; Matrix4 m_matProjection;
float m_lodBias; float m_lodBias;
// Derived values // Derived values
KRMat4 m_matViewProjection; Matrix4 m_matViewProjection;
KRMat4 m_matInverseView; Matrix4 m_matInverseView;
KRMat4 m_matInverseProjection; Matrix4 m_matInverseProjection;
Vector3 m_cameraDirection; Vector3 m_cameraDirection;
Vector3 m_cameraPosition; Vector3 m_cameraPosition;

View File

@@ -18,12 +18,12 @@
namespace kraken { namespace kraken {
class KRMat4; class Matrix4;
class KRAABB { class KRAABB {
public: public:
KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint); 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();
~KRAABB(); ~KRAABB();

View File

@@ -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

View File

@@ -69,7 +69,7 @@ public:
void setEulerXYZ(const Vector3 &euler); void setEulerXYZ(const Vector3 &euler);
void setEulerZYX(const Vector3 &euler); void setEulerZYX(const Vector3 &euler);
Vector3 eulerXYZ() const; Vector3 eulerXYZ() const;
KRMat4 rotationMatrix() const; Matrix4 rotationMatrix() const;
void normalize(); void normalize();
static KRQuaternion Normalize(const KRQuaternion &v1); static KRQuaternion Normalize(const KRQuaternion &v1);

View File

@@ -5,7 +5,7 @@
#include "vector2.h" #include "vector2.h"
#include "vector3.h" #include "vector3.h"
#include "vector4.h" #include "vector4.h"
#include "KRMat4.h" #include "Matrix4.h"
#include "KRQuaternion.h" #include "KRQuaternion.h"
#include "KRAABB.h" #include "KRAABB.h"
#include "KRTriangle3.h" #include "KRTriangle3.h"

View File

@@ -156,7 +156,7 @@
<ClCompile Include="..\kraken\KRLocator.cpp" /> <ClCompile Include="..\kraken\KRLocator.cpp" />
<ClCompile Include="..\kraken\KRLODGroup.cpp" /> <ClCompile Include="..\kraken\KRLODGroup.cpp" />
<ClCompile Include="..\kraken\KRLODSet.cpp" /> <ClCompile Include="..\kraken\KRLODSet.cpp" />
<ClCompile Include="..\kraken\KRMat4.cpp" /> <ClCompile Include="..\kraken\matrix4.cpp" />
<ClCompile Include="..\kraken\KRMaterial.cpp" /> <ClCompile Include="..\kraken\KRMaterial.cpp" />
<ClCompile Include="..\kraken\KRMaterialManager.cpp" /> <ClCompile Include="..\kraken\KRMaterialManager.cpp" />
<ClCompile Include="..\kraken\KRMesh.cpp" /> <ClCompile Include="..\kraken\KRMesh.cpp" />
@@ -274,7 +274,7 @@
<ClInclude Include="..\kraken\public\KRAABB.h" /> <ClInclude Include="..\kraken\public\KRAABB.h" />
<ClInclude Include="..\kraken\public\kraken.h" /> <ClInclude Include="..\kraken\public\kraken.h" />
<ClInclude Include="..\kraken\public\scalar.h" /> <ClInclude Include="..\kraken\public\scalar.h" />
<ClInclude Include="..\kraken\public\KRMat4.h" /> <ClInclude Include="..\kraken\public\matrix4.h" />
<ClInclude Include="..\kraken\public\KRQuaternion.h" /> <ClInclude Include="..\kraken\public\KRQuaternion.h" />
<ClInclude Include="..\kraken\public\KRTriangle3.h" /> <ClInclude Include="..\kraken\public\KRTriangle3.h" />
<ClInclude Include="..\kraken\public\vector2.h" /> <ClInclude Include="..\kraken\public\vector2.h" />

View File

@@ -30,9 +30,6 @@
<ClCompile Include="..\3rdparty\forsyth\forsyth.cpp"> <ClCompile Include="..\3rdparty\forsyth\forsyth.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\kraken\KRMat4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kraken\KRFloat.cpp"> <ClCompile Include="..\kraken\KRFloat.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@@ -252,6 +249,9 @@
<ClCompile Include="..\kraken\vector4.cpp"> <ClCompile Include="..\kraken\vector4.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\kraken\matrix4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h"> <ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h">
@@ -473,9 +473,6 @@
<ClInclude Include="..\kraken\KRHelpers.h"> <ClInclude Include="..\kraken\KRHelpers.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\kraken\public\KRMat4.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\kraken\public\kraken.h"> <ClInclude Include="..\kraken\public\kraken.h">
<Filter>Header Files\public</Filter> <Filter>Header Files\public</Filter>
</ClInclude> </ClInclude>
@@ -500,5 +497,8 @@
<ClInclude Include="..\kraken\public\scalar.h"> <ClInclude Include="..\kraken\public\scalar.h">
<Filter>Header Files\public</Filter> <Filter>Header Files\public</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\kraken\public\matrix4.h">
<Filter>Header Files\public</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>