Minor math library update
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4060
This commit is contained in:
@@ -52,7 +52,7 @@ KRBoundingVolume::KRBoundingVolume(const KRVector3 &corner1, const KRVector3 &co
|
|||||||
m_vertices[7] = KRVector3(corner1.x, corner2.y, corner2.z);
|
m_vertices[7] = KRVector3(corner1.x, corner2.y, corner2.z);
|
||||||
|
|
||||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||||
m_vertices[iVertex] = modelMatrix.dot(m_vertices[iVertex]);
|
m_vertices[iVertex] = KRMat4::Dot(modelMatrix, m_vertices[iVertex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ KRBoundingVolume::KRBoundingVolume(const KRMat4 &matView, GLfloat fov, GLfloat a
|
|||||||
m_vertices[7] = KRVector3(-1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
|
m_vertices[7] = KRVector3(-1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
|
||||||
|
|
||||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||||
m_vertices[iVertex] = invView.dot(m_vertices[iVertex]);
|
m_vertices[iVertex] = KRMat4::Dot(invView, m_vertices[iVertex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +203,9 @@ KRMat4 KRBoundingVolume::calcShadowProj(KRScene *pScene, KRContext *pContext, GL
|
|||||||
shadowvp.invert();
|
shadowvp.invert();
|
||||||
shadowvp.scale(1.0, 1.0, -1.0);
|
shadowvp.scale(1.0, 1.0, -1.0);
|
||||||
|
|
||||||
KRVector3 minPointFrustrum = shadowvp.dot(m_vertices[0]), maxPointFrustrum = minPointFrustrum;
|
KRVector3 minPointFrustrum = KRMat4::Dot(shadowvp, m_vertices[0]), maxPointFrustrum = minPointFrustrum;
|
||||||
for(int iVertex=1; iVertex < 8; iVertex++) {
|
for(int iVertex=1; iVertex < 8; iVertex++) {
|
||||||
KRVector3 v = shadowvp.dot(m_vertices[iVertex]);
|
KRVector3 v = KRMat4::Dot(shadowvp, m_vertices[iVertex]);
|
||||||
if(v.x < minPointFrustrum.x) {
|
if(v.x < minPointFrustrum.x) {
|
||||||
minPointFrustrum.x = v.x;
|
minPointFrustrum.x = v.x;
|
||||||
}
|
}
|
||||||
@@ -227,9 +227,9 @@ KRMat4 KRBoundingVolume::calcShadowProj(KRScene *pScene, KRContext *pContext, GL
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KRVector3 minPointScene = shadowvp.dot(sceneVolume.m_vertices[0]), maxPointScene = minPointScene;
|
KRVector3 minPointScene = KRMat4::Dot(shadowvp, sceneVolume.m_vertices[0]), maxPointScene = minPointScene;
|
||||||
for(int iVertex=1; iVertex < 8; iVertex++) {
|
for(int iVertex=1; iVertex < 8; iVertex++) {
|
||||||
KRVector3 v = shadowvp.dot(sceneVolume.m_vertices[iVertex]);
|
KRVector3 v = KRMat4::Dot(shadowvp, sceneVolume.m_vertices[iVertex]);
|
||||||
if(v.x < minPointScene.x) {
|
if(v.x < minPointScene.x) {
|
||||||
minPointScene.x = v.x;
|
minPointScene.x = v.x;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ KRVector3 KRDirectionalLight::getWorldLightDirection() {
|
|||||||
m.rotate(world_rotation.y, Y_AXIS);
|
m.rotate(world_rotation.y, Y_AXIS);
|
||||||
m.rotate(world_rotation.z, X_AXIS);
|
m.rotate(world_rotation.z, X_AXIS);
|
||||||
m.rotate(-90.0 * d2r, Y_AXIS);
|
m.rotate(-90.0 * d2r, Y_AXIS);
|
||||||
KRVector3 light_direction = m.dot(light_rotation);
|
KRVector3 light_direction = KRMat4::Dot(m, light_rotation);
|
||||||
return light_direction;
|
return light_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
|||||||
matModelToView.invert();
|
matModelToView.invert();
|
||||||
|
|
||||||
KRVector3 light_direction_view_space = getWorldLightDirection();
|
KRVector3 light_direction_view_space = getWorldLightDirection();
|
||||||
light_direction_view_space = matModelToView.dot(light_direction_view_space);
|
light_direction_view_space = KRMat4::Dot(matModelToView, light_direction_view_space);
|
||||||
light_direction_view_space.normalize();
|
light_direction_view_space.normalize();
|
||||||
|
|
||||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, gBufferPass);
|
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, gBufferPass);
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ double const PI = 3.141592653589793f;
|
|||||||
KRMat4 invViewMatrix = viewMatrix;
|
KRMat4 invViewMatrix = viewMatrix;
|
||||||
invViewMatrix.invert();
|
invViewMatrix.invert();
|
||||||
|
|
||||||
KRVector3 cameraPosition = invViewMatrix.dot(KRVector3(0.0,0.0,0.0));
|
KRVector3 cameraPosition = KRMat4::Dot(invViewMatrix, KRVector3(0.0,0.0,0.0));
|
||||||
|
|
||||||
KRVector3 lightDirection(0.0, 0.0, 1.0);
|
KRVector3 lightDirection(0.0, 0.0, 1.0);
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ double const PI = 3.141592653589793f;
|
|||||||
KRMat4 shadowvp;
|
KRMat4 shadowvp;
|
||||||
shadowvp.rotate(sun_pitch, X_AXIS);
|
shadowvp.rotate(sun_pitch, X_AXIS);
|
||||||
shadowvp.rotate(sun_yaw, Y_AXIS);
|
shadowvp.rotate(sun_yaw, Y_AXIS);
|
||||||
lightDirection = shadowvp.dot(lightDirection);
|
lightDirection = KRMat4::Dot(shadowvp, lightDirection);
|
||||||
shadowvp.invert();
|
shadowvp.invert();
|
||||||
|
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ double const PI = 3.141592653589793f;
|
|||||||
vertices[7] = KRVector3(-1.0, 1.0, 1.0);
|
vertices[7] = KRVector3(-1.0, 1.0, 1.0);
|
||||||
|
|
||||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||||
vertices[iVertex] = matInvShadow.dot(vertices[iVertex]);
|
vertices[iVertex] = KRMat4::Dot(matInvShadow, vertices[iVertex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 cameraPosition;
|
KRVector3 cameraPosition;
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
|
|||||||
// Transform location of camera to object space for calculation of specular halfVec
|
// Transform location of camera to object space for calculation of specular halfVec
|
||||||
KRMat4 inverseModelMatrix = m_modelMatrix;
|
KRMat4 inverseModelMatrix = m_modelMatrix;
|
||||||
inverseModelMatrix.invert();
|
inverseModelMatrix.invert();
|
||||||
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
|
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
|
||||||
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
|
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
|
||||||
|
|
||||||
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
|
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,14 @@ KRMat4& KRMat4::operator=(const KRMat4 &m) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float& KRMat4::operator[](unsigned i) {
|
||||||
|
return m_mat[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
float KRMat4::operator[](unsigned i) const {
|
||||||
|
return m_mat[i];
|
||||||
|
}
|
||||||
|
|
||||||
// Overload comparison operator
|
// Overload comparison operator
|
||||||
bool KRMat4::operator==(const KRMat4 &m) {
|
bool KRMat4::operator==(const KRMat4 &m) {
|
||||||
return memcmp(m_mat, m.m_mat, sizeof(GLfloat) * 16) == 0;
|
return memcmp(m_mat, m.m_mat, sizeof(GLfloat) * 16) == 0;
|
||||||
@@ -262,10 +270,10 @@ void KRMat4::transpose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Dot Product */
|
/* Dot Product */
|
||||||
KRVector3 KRMat4::dot(const KRVector3 &v) const {
|
KRVector3 KRMat4::Dot(const KRMat4 &m, const KRVector3 &v) {
|
||||||
return KRVector3(
|
return KRVector3(
|
||||||
v.x * (float)m_mat[0*4 + 0] + v.y * (float)m_mat[1*4 + 0] + v.z * (float)m_mat[2*4 + 0] + (float)m_mat[3*4 + 0],
|
v.x * (float)m[0*4 + 0] + v.y * (float)m[1*4 + 0] + v.z * (float)m[2*4 + 0] + (float)m[3*4 + 0],
|
||||||
v.x * (float)m_mat[0*4 + 1] + v.y * (float)m_mat[1*4 + 1] + v.z * (float)m_mat[2*4 + 1] + (float)m_mat[3*4 + 1],
|
v.x * (float)m[0*4 + 1] + v.y * (float)m[1*4 + 1] + v.z * (float)m[2*4 + 1] + (float)m[3*4 + 1],
|
||||||
v.x * (float)m_mat[0*4 + 2] + v.y * (float)m_mat[1*4 + 2] + v.z * (float)m_mat[2*4 + 2] + (float)m_mat[3*4 + 2]
|
v.x * (float)m[0*4 + 2] + v.y * (float)m[1*4 + 2] + v.z * (float)m[2*4 + 2] + (float)m[3*4 + 2]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ public:
|
|||||||
// Overload compound multiply operator
|
// Overload compound multiply operator
|
||||||
KRMat4& operator*=(const KRMat4 &m);
|
KRMat4& operator*=(const KRMat4 &m);
|
||||||
|
|
||||||
|
float& operator[](unsigned i);
|
||||||
|
float operator[](unsigned i) const;
|
||||||
|
|
||||||
// Overload multiply operator
|
// Overload multiply operator
|
||||||
//KRMat4& operator*(const KRMat4 &m);
|
//KRMat4& operator*(const KRMat4 &m);
|
||||||
KRMat4 operator*(const KRMat4 &m);
|
KRMat4 operator*(const KRMat4 &m);
|
||||||
@@ -96,7 +99,8 @@ public:
|
|||||||
void bias();
|
void bias();
|
||||||
bool invert();
|
bool invert();
|
||||||
void transpose();
|
void transpose();
|
||||||
KRVector3 dot(const KRVector3 &v) const;
|
|
||||||
|
static KRVector3 Dot(const KRMat4 &m, const KRVector3 &v);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KRMAT4_I
|
#endif // KRMAT4_I
|
||||||
@@ -46,10 +46,10 @@ KRMaterial::KRMaterial(const char *szName) : KRResource(szName) {
|
|||||||
m_pSpecularMap = NULL;
|
m_pSpecularMap = NULL;
|
||||||
m_pNormalMap = NULL;
|
m_pNormalMap = NULL;
|
||||||
m_pReflectionMap = NULL;
|
m_pReflectionMap = NULL;
|
||||||
m_ambientColor = KRVector3(0.0f, 0.0f, 0.0f);
|
m_ambientColor = KRVector3::Zero();
|
||||||
m_diffuseColor = KRVector3(1.0f, 1.0f, 1.0f);
|
m_diffuseColor = KRVector3::One();
|
||||||
m_specularColor = KRVector3(1.0f, 1.0f, 1.0f);
|
m_specularColor = KRVector3::One();
|
||||||
m_reflectionColor = KRVector3(1.0f, 1.0f, 1.0f);
|
m_reflectionColor = KRVector3::One();
|
||||||
m_tr = (GLfloat)0.0f;
|
m_tr = (GLfloat)0.0f;
|
||||||
m_ns = (GLfloat)0.0f;
|
m_ns = (GLfloat)0.0f;
|
||||||
m_ambientMap = "";
|
m_ambientMap = "";
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ KRNode::KRNode(std::string name)
|
|||||||
{
|
{
|
||||||
m_pExtents = NULL;
|
m_pExtents = NULL;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
m_localScale = KRVector3(1.0f, 1.0f, 1.0f);
|
m_localScale = KRVector3::One();
|
||||||
m_localRotation = KRVector3(0.0f, 0.0f, 0.0f);
|
m_localRotation = KRVector3::Zero();
|
||||||
m_localTranslation = KRVector3(0.0f, 0.0f, 0.0f);
|
m_localTranslation = KRVector3::Zero();
|
||||||
m_parentNode = NULL;
|
m_parentNode = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
KRMat4 matViewToModel = m_modelMatrix * viewMatrix;
|
KRMat4 matViewToModel = m_modelMatrix * viewMatrix;
|
||||||
matViewToModel.invert();
|
matViewToModel.invert();
|
||||||
|
|
||||||
KRVector3 view_space_light_position = matModelToView2.dot(KRVector3(0.0)); // Origin point of model space is the light source position. No perspective, so no w divide required
|
KRVector3 view_space_light_position = KRMat4::Dot(matModelToView2, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
|
||||||
|
|
||||||
KRBoundingVolume influence_extents = KRBoundingVolume(KRVector3(-1.0), KRVector3(1.0), m_modelMatrix);
|
KRBoundingVolume influence_extents = KRBoundingVolume(KRVector3(-1.0), KRVector3(1.0), m_modelMatrix);
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ KRVector2::KRVector2(const KRVector2 &v) {
|
|||||||
y = v.y;
|
y = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector2 KRVector2::ZeroVector() {
|
KRVector2 KRVector2::Zero() {
|
||||||
return KRVector2(0.0f);
|
return KRVector2(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector2 KRVector2::OneVector() {
|
KRVector2 KRVector2::One() {
|
||||||
return KRVector2(1.0f);
|
return KRVector2(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ public:
|
|||||||
|
|
||||||
static float Dot(const KRVector2 &v1, const KRVector2 &v2);
|
static float Dot(const KRVector2 &v1, const KRVector2 &v2);
|
||||||
|
|
||||||
static KRVector2 ZeroVector();
|
static KRVector2 Zero();
|
||||||
static KRVector2 OneVector();
|
static KRVector2 One();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -47,35 +47,35 @@ KRVector3::KRVector3(const KRVector3 &v) {
|
|||||||
z = v.z;
|
z = v.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::ZeroVector() {
|
KRVector3 KRVector3::Zero() {
|
||||||
return KRVector3(0.0f, 0.0f, 0.0f);
|
return KRVector3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::OneVector() {
|
KRVector3 KRVector3::One() {
|
||||||
return KRVector3(1.0f, 1.0f, 1.0f);
|
return KRVector3(1.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::ForwardVector() {
|
KRVector3 KRVector3::Forward() {
|
||||||
return KRVector3(0.0f, 0.0f, 1.0f);
|
return KRVector3(0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::BackwardVector() {
|
KRVector3 KRVector3::Backward() {
|
||||||
return KRVector3(0.0f, 0.0f, -1.0f);
|
return KRVector3(0.0f, 0.0f, -1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::UpVector() {
|
KRVector3 KRVector3::Up() {
|
||||||
return KRVector3(0.0f, 1.0f, 0.0f);
|
return KRVector3(0.0f, 1.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::DownVector() {
|
KRVector3 KRVector3::Down() {
|
||||||
return KRVector3(0.0f, -1.0f, 0.0f);
|
return KRVector3(0.0f, -1.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::LeftVector() {
|
KRVector3 KRVector3::Left() {
|
||||||
return KRVector3(-1.0f, 0.0f, 0.0f);
|
return KRVector3(-1.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRVector3 KRVector3::RightVector() {
|
KRVector3 KRVector3::Right() {
|
||||||
return KRVector3(1.0f, 0.0f, 0.0f);
|
return KRVector3(1.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,14 +75,14 @@ public:
|
|||||||
|
|
||||||
static float Dot(const KRVector3 &v1, const KRVector3 &v2);
|
static float Dot(const KRVector3 &v1, const KRVector3 &v2);
|
||||||
|
|
||||||
static KRVector3 ZeroVector();
|
static KRVector3 Zero();
|
||||||
static KRVector3 OneVector();
|
static KRVector3 One();
|
||||||
static KRVector3 ForwardVector();
|
static KRVector3 Forward();
|
||||||
static KRVector3 BackwardVector();
|
static KRVector3 Backward();
|
||||||
static KRVector3 UpVector();
|
static KRVector3 Up();
|
||||||
static KRVector3 DownVector();
|
static KRVector3 Down();
|
||||||
static KRVector3 LeftVector();
|
static KRVector3 Left();
|
||||||
static KRVector3 RightVector();
|
static KRVector3 Right();
|
||||||
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
||||||
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
|
||||||
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
|
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
|
||||||
|
|||||||
Reference in New Issue
Block a user