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(); }
void UltraEyeRenderer::drawHenshinInstruction() { XuSkeletonJointInfo jrh, jh, jre; m_henshinDetector->getUserDetector()->getSkeletonJointInfo(XU_SKEL_RIGHT_HAND, &jrh); m_henshinDetector->getUserDetector()->getSkeletonJointInfo(XU_SKEL_HEAD, &jh); m_henshinDetector->getUserDetector()->getSkeletonJointInfo(XU_SKEL_RIGHT_ELBOW, &jre); if (!isConfident(jrh) || !isConfident(jh) || !isConfident(jre)) return; const float CIRCLE_RADIUS = 100; XV3 fv(m_henshinDetector->getUserDetector()->getForwardVector()); XV3 uv(m_henshinDetector->getUserDetector()->getUpVector()); XV3 armDirection((jrh.position - jre.position).normalize()); XV3 adjustedRightHand(jrh.position + armDirection * 30); // slightly move to the fingertip side XV3 adjustedHead(jh.position + fv * 100); // slightly move forward XV3 arrowTip(adjustedRightHand.interpolate(adjustedHead, 0.95f)); XV3 arrowBottom(adjustedRightHand.interpolate(adjustedHead, 0.0f)); float len = (arrowTip - arrowBottom).magnitude(); XV3 triangleBottom(arrowBottom.interpolate(arrowTip, 0.8f)); XV3 triangleOpening = (arrowTip - arrowBottom).cross(armDirection).normalize() * len * 0.1f; XV3 arrowPlaneNorm = (arrowTip - arrowBottom).cross(triangleOpening).normalize(); XV3 triangleEnd1(triangleBottom + triangleOpening); XV3 triangleEnd2(triangleBottom - triangleOpening); float maxAlpha = cramp((len - 50.0f) / 150.0f, 0, 1); float blinkSpeed = 1000.0f / std::max(len - 100.0f, 100.f); m_phase += m_ticker.tick() * blinkSpeed; float alpha = square(std::sin(m_phase)) * maxAlpha; M3DVector4f arrowColor = { 0.7f, 0.0f, 0.0f, alpha }; m_rctx->shaderMan->UseStockShader(GLT_SHADER_FLAT, m_rctx->transform.GetModelViewProjectionMatrix(), arrowColor); const float THICKNESS = 2; glDisable(GL_DEPTH_TEST); glLineWidth(getPointSize() * THICKNESS); glPointSize(getPointSize() * THICKNESS); glBegin(GL_LINES); if (len > CIRCLE_RADIUS) { glVertex3fv(XV3toM3D(arrowBottom + (arrowTip - arrowBottom).normalize() * CIRCLE_RADIUS)); glVertex3fv(XV3toM3D(arrowTip)); } glVertex3fv(XV3toM3D(arrowTip)); glVertex3fv(XV3toM3D(triangleEnd1)); glVertex3fv(XV3toM3D(arrowTip)); glVertex3fv(XV3toM3D(triangleEnd2)); glEnd(); glBegin(GL_LINE_LOOP); XV3 r0((arrowTip - arrowBottom).normalize() * CIRCLE_RADIUS); GLFrame f; f.SetForwardVector(0, 0, 1); // invert Z const int SEGMENTS = 24; const float STEP_ANGLE = float(M_PI * 2 / SEGMENTS); for (int i = 0; i < SEGMENTS; i++) { f.RotateLocal(STEP_ANGLE, arrowPlaneNorm.X, arrowPlaneNorm.Y, arrowPlaneNorm.Z); M3DVector3f r; f.TransformPoint(XV3toM3D(r0), r); glVertex3fv(XV3toM3D(arrowBottom + r)); } glEnd(); if (m_isNewUser) { XV3 p(-0.95f, 0.80f, 0.0f), s(0.001f, 0.0015f, 1.0f); renderStrokeText(m_rctx, "Put your Ultra Eye On! Now!", p, s, 3.0f, arrowColor); } glEnable(GL_DEPTH_TEST); }
void renderScene() { //Colours: static GLfloat vDarkRed[] = {0.0f, 0.396f, 0.702f, 1.0f}; static GLfloat vDarkGrey[] = {0.2f, 0.2f, 0.2f, 1.0f}; static CStopWatch inputTimer; //Clear buffers glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //Beginning push: modelViewStack.PushMatrix(); //Camera matrix: M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); modelViewStack.Rotate(-15.0f, 1.0f, 0.0f, 0.0f); if (screenshot) { cameraFrame.SetForwardVector(0, 0, -1); cameraFrame.SetUpVector(0, 1, 0); cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); } //Light source: static M3DVector4f vAmbient = {0.1f, 0.1f, 0.1f, 1.0f}; static M3DVector4f vLightPos = {4.0f, -6.5f, 10.0f, 1.0f}; static M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); //Draw floor and grid: glEnable(GL_MULTISAMPLE); cRoom.draw(shaderManager, tPipeline, modelViewStack); // Highlight grid hlGrid.draw(shaderManager, tPipeline, modelViewStack); //Draw desks: stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient); //Draw polygon version of desks glDisable(GL_MULTISAMPLE); //Disable multisampling (to use AA) glEnable(GL_BLEND); //Enable blending glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonOffset(-1.0f, -1.0f); glEnable(GL_POLYGON_OFFSET_LINE); //Render wireframe in front of polygon glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //Wireframe mode glEnable(GL_LINE_SMOOTH); //Enable AA stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient, vDarkGrey); //Draw wireframe version of desks //Reset stuff as they were before: glDisable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); //End cam push: modelViewStack.PopMatrix(); //End pop: modelViewStack.PopMatrix(); if (!screenshot) { newDeskButton.draw(W_WIDTH, W_HEIGHT); removeDeskButton.draw(W_WIDTH, W_HEIGHT); exportButton.draw(W_WIDTH, W_HEIGHT); } glutSwapBuffers(); if (screenshot) { char name[38]; sprintf(name, "Exports/screenshot%d.tga", expCounter); gltWriteTGA(name); counterSaver(); modelViewStack.PopMatrix(); screenshot = false; } glutPostRedisplay(); handleInput(inputTimer); }
/////////////////////////////////////////////////////////////////////////////// // 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(); }