void SetUpFrame(GLFrame &frame,const M3DVector3f origin, const M3DVector3f forward, const M3DVector3f up) { frame.SetOrigin(origin); frame.SetForwardVector(forward); M3DVector3f side,oUp; m3dCrossProduct3(side,forward,up); m3dCrossProduct3(oUp,side,forward); frame.SetUpVector(oUp); frame.Normalize(); }
void SetUpFrame(GLFrame &cameraFrame,const M3DVector3f origin, const M3DVector3f forward, const M3DVector3f cameraUpDirection) { cameraFrame.SetOrigin(origin); cameraFrame.SetForwardVector(forward); M3DVector3f side,oUp; m3dCrossProduct3(side,forward,cameraUpDirection); m3dCrossProduct3(oUp,side,forward); cameraFrame.SetUpVector(oUp); cameraFrame.Normalize(); };
void KamehamehaRenderer::draw() { m_kkhStatus->currentIntensity = getCurrentIntensity(); if (!m_active) { return; } float t = m_ticker.tick(); m_rctx->modelViewMatrix.PushMatrix(); { float length = getCurrentLength(); float radius = getCurrentRadius(); GLFrame f; f.SetOrigin(XV3toM3D(m_origin + m_forward * length)); f.SetForwardVector(XV3toM3D(-m_forward)); m_rctx->modelViewMatrix.MultMatrix(f); float planeColor[] = { 0.95f, 1.0f, 1.0f, 1.5f }; glUseProgram(s_shaderID); glUniformMatrix4fv(glGetUniformLocation(s_shaderID, "mvMatrix"), 1, GL_FALSE, m_rctx->transform.GetModelViewMatrix()); glUniformMatrix4fv(glGetUniformLocation(s_shaderID, "pMatrix"), 1, GL_FALSE, m_rctx->transform.GetProjectionMatrix()); glUniform4fv(glGetUniformLocation(s_shaderID, "vColor"), 1, planeColor); drawBeam(radius, length); //glutSolidSphere(radius, 64, 64); } m_rctx->modelViewMatrix.PopMatrix(); if (t > m_lifeTime) { m_active = false; } drawIntensityText(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; float yRot = animationTimer.GetElapsedSeconds() * 60.0f; M3DVector3f vCameraPos; M3DVector3f vCameraForward; M3DVector3f vMirrorPos; M3DVector3f vMirrorForward; cameraFrame.GetOrigin(vCameraPos); cameraFrame.GetForwardVector(vCameraForward); // Set position of mirror frame (camera) vMirrorPos[0] = 0.0; vMirrorPos[1] = 0.1f; vMirrorPos[2] = -6.0f; // view pos is actually behind mirror mirrorFrame.SetOrigin(vMirrorPos); // Calculate direction of mirror frame (camera) // Because the position of the mirror is known relative to the origin // find the direction vector by adding the mirror offset to the vector // of the viewer-origin vMirrorForward[0] = vCameraPos[0]; vMirrorForward[1] = vCameraPos[1]; vMirrorForward[2] = (vCameraPos[2] + 5); m3dNormalizeVector3(vMirrorForward); mirrorFrame.SetForwardVector(vMirrorForward); // first render from the mirrors perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); glDrawBuffers(1, fboBuffs); glViewport(0, 0, mirrorTexWidth, mirrorTexHeight); // Draw scene from the perspective of the mirror camera modelViewMatrix.PushMatrix(); M3DMatrix44f mMirrorView; mirrorFrame.GetCameraMatrix(mMirrorView); modelViewMatrix.MultMatrix(mMirrorView); // Flip the mirror camera horizontally for the reflection modelViewMatrix.Scale(-1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(yRot); // Now draw a cylinder representing the viewer M3DVector4f vLightTransformed; modelViewMatrix.GetMatrix(mMirrorView); m3dTransformVector4(vLightTransformed, vLightPos, mMirrorView); modelViewMatrix.Translate(vCameraPos[0],vCameraPos[1]-0.8f,vCameraPos[2]-1.0f); modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vBlue, 0); cylinderBatch.Draw(); modelViewMatrix.PopMatrix(); // Reset FBO. Draw world again from the real cameras perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glDrawBuffers(1, windowBuff); glViewport(0, 0, screenWidth, screenHeight); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(yRot); // Now draw the mirror surfaces modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, -0.4f, -5.0f); if(vCameraPos[2] > -5.0) { glBindTexture(GL_TEXTURE_2D, mirrorTexture); // Reflection shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); } else { // If the camera is behind the mirror, just draw black shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack); } mirrorBatch.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey); mirrorBorderBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
void Display() { static CStopWatch timer; GLfloat yRot = timer.GetElapsedSeconds() * 60.0; M3DVector3f vCameraPosition; M3DVector3f vCameraForward; M3DVector3f vMirrorPosition; M3DVector3f vMirrorForward; void movingCylinder(); cameraFrame.GetOrigin(vCameraPosition); cameraFrame.GetForwardVector(vCameraForward); vMirrorPosition[0] = 0.0f; vMirrorPosition[1] = 0.1f; vMirrorPosition[2] = -20.0f; mirrorFrame.SetOrigin(vMirrorPosition); vMirrorForward[0] = vCameraPosition[0]; vMirrorForward[1] = vCameraPosition[1]; vMirrorForward[2] = (vCameraPosition[2] + 20); m3dNormalizeVector3(vMirrorForward); mirrorFrame.SetForwardVector(vMirrorForward); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fboName); glDrawBuffers(1,fboBuffers); glViewport(0,0,mirrorWidth,mirrorHeight); modelViewMatrix.PushMatrix(); M3DMatrix44f mMirrorView; mirrorFrame.GetCameraMatrix(mMirrorView); modelViewMatrix.MultMatrix(mMirrorView); modelViewMatrix.Scale(-1.0f,1.0f,1.0f); glBindTexture(GL_TEXTURE_2D,textures[0]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite,0); floorBatch.Draw(); drawSun(); drawTorus(yRot); modelViewMatrix.PopMatrix(); glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0); glDrawBuffers(1,windowBuffer); glViewport(0,0,mirrorWidth,mirrorHeight); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); modelViewMatrix.PushMatrix(); glBindTexture(GL_TEXTURE_2D,mirrorTexture); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(),0); mirrorFrontBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); glBindTexture(GL_TEXTURE_2D,textures[0]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite,0); floorBatch.Draw(); drawSun(); drawTorus(yRot); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); //control to moving cylinder movingCylinder(); glutSwapBuffers(); glutPostRedisplay(); }