android - Projection Matrix or not? (OpenGL ES 2.0) -
is necessary use projection matrix so:
matrix.frustumm(mprojmatrix, 0, -ratio, ratio, -1, 1, 3, 7); , matrix.setlookatm(mvmatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // calculate projection , view transformation , store results in mmvpmatrix matrix.multiplymm(mmvpmatrix, 0, mprojmatrix, 0, mvmatrix, 0);
i'm having no end of trouble doing simple 2d (sprite) rotation around z axis.
the success i've had far manipulate rotation matrix (rotate , translate) , pass directly vertex shader.
it's not perfect , carries shearing/skewing/distortion @ least allows me move 'pivot'/centre point of quad. if put above lines in whole thing breaks , kinds of odd results.
what actual purpose of lines above (i have read android docs dont understand them) , necessary? people write opengl apps without them?
thanks!!
opengl c api many frameworks wrap functions other functions make life easier. example, in opengl es 2.0 must create , pass matrices opengl. opengl not provide tools build , calculate these matrixes. many other libraries exist matrix creation you, , pass these constructed matrixes opengl -- or function may pass matrix opengl you, after making calculation. depends on library.
you can not use these frameworks , yourself, great way learn math in 3d graphics -- , math key in area.
i'm sure have direct access opengl api in android, choosing use library perhaps android provides natively (similar how apple provides glkit, recent addition frameworks ios). doesn't mean must use library, might provide faster development if know library doing.
in case, 3 functions above appear pretty generic matrix/graphics utilities. have frustrum function sets projection in 3d space. have lookat function determines view of camera -- looking , camera while looks there.
and have matrix multiplication function, since in end matrices must combined before applied vertices of 3d object.
it's important understand typical modelview matrix include camera orientation/location include rotation , scaling of object. sending modelview based on camera (from lookat) not enough, unless want object remain @ center of screen, no rotation.
if expand math goes matrix multiplication, might typical setup:
frustum * camera * translation * rotation * vertices
those middle three, camera, translation, rotation, combined modelview, multiply particular matrix, multiply modelview frustum projection matrix, , whole result can applied vertices.
you must careful order of matrix multiplication. multiplying frustum modelview not same multiplying modelview frustum.
now mention skewing, distortion, etc. 1 possible reason viewport. i'm sure somewhere in api option set viewport's height , width, height , width of screen. if set differently, improper aspect ratio , skewing see. 1 possible explanation. or parameters frustum aren't quite right, since affect things skew also.
Comments
Post a Comment