Ads

Tweets
    follow me on Twitter
    Loading..
    Loading..
    « OpenGL ES Sprite Engine Work in Progress | Main | Link pages ported, new iPhone links added »
    Friday
    12Jun2009

    Math Library Release

    I've been working on OpenGL ES tutorials for a while and I always hit the same wall: a lack of vector and matrix support. For DirectX there's D3DXVECTOR4 and D3DXMATRIX which make it much easier to get started. For OpenGL you have some support via the matrix stack and glOrthof/glRotatef/etc. but OpenGL ES 2.0 takes even that away from you.

    Several years ago I wrote a math library that included everything from sine and cosine to transformations. It's overkill for simple 3D mathematics and a lot of it is organized in preparation to create a ray tracer. MathLib is what I use for all of my own OpenGL rendering, though, and does a good enough job for most cases.

    To give back to the community and save myself some sanity moving forward I've decided to release the MathLib part of my code library under the MIT license. Download it, check it out, and try it out. I'll release source code that shows how it's used with OpenGL ES shortly.

    [EDIT: here's a quick example on how to use the library's transformations with OpenGL]

    glMatrixMode(GL_PROJECTION);

    Transform4f ortho(Transform4f::Orthographic(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f));

    Matrix4x4f mat(ortho.GetTransform());

    glLoadMatrixf((float*)mat);

    glMatrixMode(GL_MODELVIEW);

    Transform4f rot(Transform4f::RotateZ(rotation * 0.0174532925f));

    mat = rot.GetTransform();

    glLoadMatrixf((float*)mat);

     

    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    Reader Comments

    There are no comments for this journal entry. To create a new comment, use the form below.

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>