const bool Test_Matrix_OrthographicMatrix() { const TMatrix4d kAd = OrthographicMatrix(TMatrix4d(), 2.0, 2.0, 4.0, 3.0); const TMatrix4d kBd = OrthographicMatrix(TMatrix4d(), -1.0, 1.0, -1.0, 1.0, 4.0, 3.0); const bool kbPass_d = Equal(kAd, kBd, 0.01); const TMatrix4f kAf = OrthographicMatrix(TMatrix4f(), 2.0f, 2.0f, 4.0f, 3.0f); const TMatrix4f kBf = OrthographicMatrix(TMatrix4f(), -1.0f, 1.0f, -1.0f, 1.0f, 4.0f, 3.0f); const bool kbPass_f = Equal(kAf, kBf, 0.01f); return(kbPass_d && kbPass_f); }
// TODO: this could probably be made tighter Mat4 CreateDirLightVPMatrix(const FrustumCorners& frustumCorners, const Vec3& lightDir) { Mat4 lightViewMatrix = glm::lookAt(Vec3(0.0f), -lightDir, Vec3(0.0f, -1.0f, 0.0f)); Vec4 transf = lightViewMatrix * frustumCorners[0]; float maxZ = transf.z, minZ = transf.z; float maxX = transf.x, minX = transf.x; float maxY = transf.y, minY = transf.y; for (uint32_t i = 1; i < 8; ++i) { transf = lightViewMatrix * frustumCorners[i]; if (transf.z > maxZ) maxZ = transf.z; if (transf.z < minZ) minZ = transf.z; if (transf.x > maxX) maxX = transf.x; if (transf.x < minX) minX = transf.x; if (transf.y > maxY) maxY = transf.y; if (transf.y < minY) minY = transf.y; } lightViewMatrix[3][0] = -(minX + maxX) * 0.5f; lightViewMatrix[3][1] = -(minY + maxY) * 0.5f; lightViewMatrix[3][2] = -(minZ + maxZ) * 0.5f; Vec3 halfExtents((maxX - minX) * 0.5, (maxY - minY) * 0.5, (maxZ - minZ) * 0.5); return OrthographicMatrix(-halfExtents.x, halfExtents.x, halfExtents.y, -halfExtents.y, halfExtents.z, -halfExtents.z) * lightViewMatrix; }
void CCube::RenderCube(const GLfloat* asize) { static double dOff[3] = {-1.0f, -1.0f, -.5f}; static const double dMin[3] = {-1.0f, -1.0f, -.5f}; static const double dMax[3] = {2.0f, 1.5f, 1.0f}; static const double dFactor[3] = {.01f, .01f, .01f}; static bool bDec[3] = { false, false, false}; InitCamera(); glLineWidth(3); diffuse[0] = diffuse[1] = diffuse[2] = 0.8 + scaleAll; specular[0] = specular[1] = specular[2] = 1.0; glPushMatrix(); // light matrix OrthographicMatrix(); // get an appropriate lOffset if available - we want at least 100 points + 2 for "padding" long lOffset = 0; if (sm && sm->bSensorFound) { if (sm->lOffset > MAX_PLOT_POINTS+2) { // note the two point "padding" so we are reading the latest value that isn't in use by the sensor (i.e. writing) lOffset = sm->lOffset-2; } } if (bIsQCNLive) { glTranslatef(asize[E_DX], asize[E_DZ], 0.0);//Jesse Lawrence Changed - X & Z MOTIONS (Y IS SIZE) } else { glTranslatef(-.50 + dOff[0], dOff[1], dOff[2]); } for (int i = 0; i < 3; i++) { if (dOff[i]>dMax[i]) { bDec[i] = true; } else if (dOff[i]<dMin[i]) { bDec[i] = false; } dOff[i] += (dFactor[i] * (bDec[i] ? -1.0 : 1.0)); } glRotatef(rot.x, rot.y, rot.y/3.0f, 0.0); rot.x += rotationSpeed * 1.9134f; rot.y += rotationSpeed * 2.1234f; glPushMatrix(); //glTranslatef(0.0f, 0.0f,-7.0f); // Translate Into The Screen 7.0 Units //glRotatef(rotqube,0.0f,1.0f,0.0f); // Rotate The cube around the Y axis //glRotatef(rotqube,1.0f,1.0f,1.0f); if (bIsQCNLive) { float asize_all = asize[E_DY];//Jesse Lawrence Added - Constant size for all dimensions glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(blue); // Color Green glVertex3f( asize_all, asize_all, -asize_all); // Top Right Of The Quad (Top) glVertex3f(-asize_all, asize_all,-asize_all); // Top Left Of The Quad (Top) glVertex3f(-asize_all, asize_all, asize_all); // Bottom Left Of The Quad (Top) glVertex3f( asize_all, asize_all, asize_all); // Bottom Right Of The Quad (Top) glEnd(); // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at // DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP); // x-axis is green glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(blue); // Color Yellow glVertex3f( asize_all,-asize_all, asize_all); // Top Right Of The Quad (Bottom) glVertex3f(-asize_all,-asize_all, asize_all); // Top Left Of The Quad (Bottom) glVertex3f(-asize_all,-asize_all,-asize_all); // Bottom Left Of The Quad (Bottom) glVertex3f( asize_all,-asize_all,-asize_all); // Bottom Right Of The Quad (Bottom) glEnd(); // DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM); // y-axis is yellow glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(orange); // Color Blue glVertex3f( asize_all, asize_all, asize_all); // Top Right Of The Quad (Front) glVertex3f(-asize_all, asize_all, asize_all); // Top Left Of The Quad (Front) glVertex3f(-asize_all,-asize_all, asize_all); // Bottom Left Of The Quad (Front) glVertex3f( asize_all,-asize_all, asize_all); // Bottom Right Of The Quad (Front) glEnd(); // DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT); // z-axis is blue glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(green); // Color Red glVertex3f( asize_all,-asize_all,-asize_all); // Top Right Of The Quad (Back) glVertex3f(-asize_all,-asize_all,-asize_all); // Top Left Of The Quad (Back) glVertex3f(-asize_all, asize_all,-asize_all); // Bottom Left Of The Quad (Back) glVertex3f( asize_all, asize_all,-asize_all); // Bottom Right Of The Quad (Back) glEnd(); // DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK); // fsig/significance is red glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(green); // Color Cyan glVertex3f(-asize_all, asize_all, asize_all); // Top Right Of The Quad (Left) glVertex3f(-asize_all, asize_all,-asize_all); // Top Left Of The Quad (Left) glVertex3f(-asize_all,-asize_all,-asize_all); // Bottom Left Of The Quad (Left) glVertex3f(-asize_all,-asize_all, asize_all); // Bottom Right Of The Quad (Left) glEnd(); // DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT); // magnitude glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(orange); // Color Magenta glVertex3f( asize_all, asize_all,-asize_all); // Top Right Of The Quad (Right) glVertex3f( asize_all, asize_all, asize_all); // Top Left Of The Quad (Right) glVertex3f( asize_all,-asize_all, asize_all); // Bottom Left Of The Quad (Right) glVertex3f( asize_all,-asize_all,-asize_all); // Bottom Right Of The Quad (Right) glEnd(); // DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT); // variance } else { // screensaver mode glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(green); // Color Green glVertex3f( asize[E_DX], asize[E_DY], -asize[E_DZ]); // Top Right Of The Quad (Top) glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]); // Top Left Of The Quad (Top) glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]); // Bottom Left Of The Quad (Top) glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]); // Bottom Right Of The Quad (Top) glEnd(); // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP); // x-axis is green glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(yellow); // Color Yellow glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]); // Top Right Of The Quad (Bottom) glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]); // Top Left Of The Quad (Bottom) glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Bottom Left Of The Quad (Bottom) glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Bottom Right Of The Quad (Bottom) glEnd(); DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM); // y-axis is yellow glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(blue); // Color Blue glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]); // Top Right Of The Quad (Front) glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]); // Top Left Of The Quad (Front) glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]); // Bottom Left Of The Quad (Front) glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]); // Bottom Right Of The Quad (Front) glEnd(); DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT); // z-axis is blue glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(red); // Color Red glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Top Right Of The Quad (Back) glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Top Left Of The Quad (Back) glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]); // Bottom Left Of The Quad (Back) glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]); // Bottom Right Of The Quad (Back) glEnd(); DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK); // fsig/significance is red glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(cyan); // Color Cyan glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]); // Top Right Of The Quad (Left) glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]); // Top Left Of The Quad (Left) glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Bottom Left Of The Quad (Left) glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]); // Bottom Right Of The Quad (Left) glEnd(); DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT); // magnitude glBegin(GL_QUADS); // Draw The Cube Using quads glColor4fv(magenta); // Color Magenta glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]); // Top Right Of The Quad (Right) glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]); // Top Left Of The Quad (Right) glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]); // Bottom Left Of The Quad (Right) glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]); // Bottom Right Of The Quad (Right) glEnd(); DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT); // variance } glPopMatrix(); glPopMatrix(); // rotation matrix glFlush(); }