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.

Matrix and Vector Operationsmat4 perspective()matn rotation()Creates a 4x4 perspective transform matrix, constructed from the given field ofview, aspect angle, near plane, and far plane.mat4 perspectiveMatrix = mat4::perspective(45.0f, // field4.0f/3.0f, // aspect1.0f, // near plane1000.0f); // far planeThe perspective matrix is typically used with the camera view to create the worldview:mat4 world = mat4::identity(); // could be a translation or rotationmat4 proj = mat4::perspective(30.0f, 1.0f, 0.1f, 20.0f);mat4 view = mat4::lookAt(camPos, camTarget, upVector);mat4 wvpMatrix = proj * view * world;context->setUniformMatrix("WORLD_VIEW_PROJECTION", wvpMatrix);The vertex shader uses the world view to transform each point:attribute vec4 POSITION; // position of a point on the shapeWORLD_VIEW_PROJECTION; // transformation matrix passedvoid main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;}Creates a nxn rotation matrix, calculated based on the passed axis and angleparameters. n is in the range 2 to 4.mat4 matrix = mat4::rotation(45.0, // angle to rotatevec3(1.0f, 0.0f, 0.0f)); // rotation axismatn scale()Creates a nxn scale matrix. n is 3 or 4.mat4 matrix = mat4::scale(2.0f, 2.0f, 2.0f); // x, y, z scale factorsmat4 toMat3()Creates a new matrix from the upper left 3x3 elements of the original matrix.mat4 m1;mat3 m2 = m1.toMat3();mat4 translation()Creates a 4x4 translation matrix. The parameters can be a vector or the x, y, andz translation values:vec3 trans_vec = vec3(2.0f, 3.0f, 4.0f);mat4 matrix = mat4::translation(2.0f, 3.0f, 4.0f);mat4 matrix = mat4::translation(trans_vec);The following vector functions in the MDE library simplify vector operations:vecn crossProduct()vecn length()Returns the cross product of two vectors. For two 3D vectors, the cross productresults in a vector that is perpendicular to both of the original vectors.Returns the length of the vector.vecn scale() Scale the vector by the elements of a vector or by a constant.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. A-3ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!