13.07.2015 Views

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial on Drawing 3D ShapesExample 4-24 Set the camera, projection, view, and world for the teapot...// The camera position, target and up vector for use when creating the view matrixfloat cameraAngle = 0.0f;vec3 camPos = calculateCamPos(75.0f, cameraAngle);vec3 camTarget = vec3(0.0f, 0.0f, 0.0f);vec3 upVector = vec3(0.0f, 0.0f, 1.0f);// Set up the view, projection and world matrices and multiply them to get the// modelviewprojection and modelview matrices.mat4 view = mat4::lookAt(camPos, camTarget, upVector);mat4 proj = mat4::perspective(60.0f, 4.0f/3.0f, 1.0f, 500.0f);mat4 world = mat4::rotation(90.0f, vec3(0.0f, 0.0f, 1.0f));mat4 wvpMatrix = proj * view * world;bool perVertexLighting = true;vec3 lightPosition(75.0f, 75.0f, 0.0f);// Enable depth testglEnable(GL_DEPTH_TEST);...6. Example 4-25 shows the part of the draw loop that reacts to keyboard input to change thecamera, view, and lighting:Example 4-25 Use the to keyboard input to change the teapot view, camera, and lighting...do{// Exit the application if escape key pressedif (keyboard->getSpecialKeyState(Keyboard::KEY_ESCAPE)){return 0;}// toggle lighting model if UP key is pressedstatic float time = timer->getTime();if (keyboard->getSpecialKeyState(Keyboard::KEY_UP)){perVertexLighting = !perVertexLighting;}if (perVertexLighting){context->setProgram(perVertexLightingProgram);}else{context->setProgram(perFragmentLightingProgram);}// Rotate object or cameraif (keyboard->getSpecialKeyState(Keyboard::KEY_SPACE)){if (keyboard->getSpecialKeyState(Keyboard::KEY_LEFT)){ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-19ID070710Non-Confidential - Draft - Beta

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!