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-4 Setting the hello_world projection...// The camera position, target and up vector for use when creating the view matrixfloat cameraAngle = 45.0f;vec3 camPos = calculateCamPos(4.0f, cameraAngle);vec3 camTarget = vec3(0.0f, 0.0f, 0.0f);vec3 upVector = vec3(0.0f, 1.0f, 0.0f);// Set up the view and projection matrices and multiply them to get the// modelviewprojection matrix.mat4 world = mat4::identity();mat4 proj = mat4::perspective(35.0f, 1.0f, 0.1f, 20.0f);mat4 view = mat4::lookAt(camPos, camTarget, upVector);mat4 wvpMatrix = proj * view;...context->setProgram(helloWorldProgram);glEnable(GL_DEPTH_TEST);6. The do loop checks for keyboard input and either rotates the object or changes the cameraposition. See Example 4-5.Example 4-5 Processing hello_world input and changing the view...do{// Exit the application if escape pressedif (keyboard->getSpecialKeyState(Keyboard::KEY_ESCAPE)){return 0;}// Rotate object or cameraif (keyboard->getSpecialKeyState(Keyboard::KEY_SPACE)){if (keyboard->getSpecialKeyState(Keyboard::KEY_LEFT)){camPos = calculateCamPos(4.0f, ++cameraAngle);view = mat4::lookAt(camPos, camTarget, upVector);}if (keyboard->getSpecialKeyState(Keyboard::KEY_RIGHT)){camPos = calculateCamPos(4.0f, --cameraAngle);view = mat4::lookAt(camPos, camTarget, upVector);}}else{if (keyboard->getSpecialKeyState(Keyboard::KEY_RIGHT)){world *= mat4::rotation(1.0f, vec3(0.0f, 1.0f, 0.0f));}if (keyboard->getSpecialKeyState(Keyboard::KEY_LEFT)){world *= mat4::rotation(-1.0f, vec3(0.0f, 1.0f, 0.0f));ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-4ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!