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 Constructing Custom Shaders6.7 Performing matrix transformations in the shadersThis section describes how the matrix and vector values defined in the draw loop are modifiedand rendered in the shaders.6.7.1 Example of a simple world-view transformationThe application code in Example 6-23 calculates the camera position, camera target, camera upvector, world, projection, view, and world view projection:Example 6-23 Simple projection matrices in the application codestatic const float PI = 3.14159265;/*** define a function that calculates the camera position given an angle and a radius.* This function enables the camera to rotate around the scene object.*/inline vec3 calculateCamPos(float radius, float angle){float angleRad = angle / 180 * PI;return vec3(radius * cos(angleRad), 2.0f, radius * sin(angleRad));}int main(int argc, char * argv[]){...// Initialize the demo engine classes and load the shader code...// Set up the geometry of the cube by specifying values for the vertex buffer....// The camera position, target and up vector used for 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.// No requirement to change the position, rotation, or// scaling of the cube we don't need a world matrix.mat4 world = mat4::identity();// projection matrix for matrixmat4 proj = mat4::perspective(30.0f, 1.0f, 0.1f, 20.0f);// use lookAt to create the view from camera to targetmat4 view = mat4::lookAt(camPos, camTarget, upVector);...// modify the view to use perspectivemat4 wvpMatrix = proj * view;The application code in Example 6-24 on page 6-19 uses lookAt() and rotate() to modify theworld-view projection matrix and pass it to the vertex shader:ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-18ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!