Results 1 to 2 of 2

Thread: Enhancing the Sprite Batcher to 3D

  1. #1
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default Enhancing the Sprite Batcher to 3D

    I want to be able to use CL_Sprite, CL_Image, CL_Font in a 3d environment.

    For example, Draw "Hello World" at an angle above an object in the distance.

    To do this, I modify the modelview matrix to reposition the model view, so you can draw the image as normal

    The problem is that the CL_SpriteRenderBatch does not handle the Z direction in the model view matrix.

    This was intentional, to make the batch rendering as fast as possible.

    My initial idea was do:

    In: void CL_SpriteRenderBatch::modelview_changed(const CL_Mat4f &new_modelview)
    Add: modelview_2d = modelview.is_2d();

    Add function:
    inline CL_Vec3f CL_SpriteRenderBatch::to_position_3d(float x, float y) const
    {
    return CL_Vec3f(
    modelview.matrix[0*4+0]*x + modelview.matrix[1*4+0]*y modelview.matrix[3*4+0],
    modelview.matrix[0*4+1]*x + modelview.matrix[1*4+1]*y modelview.matrix[3*4+1],
    modelview.matrix[0*4+2]*x + modelview.matrix[1*4+2]*y modelview.matrix[3*4+2]);
    }

    (This is an optimised version of "modelview * CL_Vec4f(x, y, 0.0f, 1.0f)" )

    And in CL_SpriteRenderBatch::draw_image() etc
    Add:
    if (modelview_2d)
    {
    vertices[position+0].position = to_position(dest.left, dest.top);
    ...etc
    }
    else
    {
    vertices[position+0].position = to_position_3d(dest.left, dest.top);
    ...etc
    }

    But it has been argued, that the extra "if (modelview_2d)" comparision would be a significant slow-down when 10000's of calls are made to the function.

    Alternatives

    Create a CL_Image_3d(float x, float y, float z) that natively batches via a Render3DBatcher. Thus avoiding continiously modifing the rotation matrix

    Inherit the existing CL_Sprite to form CL_Sprite3D to contain support for drawing an batching to a 3d environment.

    The same with CL_Font ... Create a CL_Font3D

    But should this be contained within the ClanLib library, or in the external application?

    Any thoughts?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have had second thoughts about drawing sprites, images and font to a 3d environment.

    Although, the above suggestion should work, In practice, it is not the most optimum method. This is because the ModelView matrix would need positioning (in the application) before each draw. This would be very slow in a complex environment.

    I now recommend the following.

    External to clanlib, create the following:
    Port the clanDisplay/2D code to Display/3D code. Adding the “z” position to each function (Including CL_Draw, CL_Sprite, CL_Font (all types) and CL_Image).

    If that is successful, it can either be incorporated into clanDisplay (as clanDisplay/3D), or as a clan3D library (external or internal to the main clanlib source packages).

    In the future, we could look at generic model classes - Unless there is a license with a friendly licence out there already to do it. Note Ogre3d has changed their license http://www.ogre3d.org/2009/03/06/lgp...ng-now-simpler

Similar Threads

  1. Potential Graphic Batcher Pitfalls (0.9)
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 04-22-2009, 09:33 AM
  2. sprite question?
    By Mahdi in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-07-2008, 12:18 PM
  3. Speed of Sprite
    By Nikitto46 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 01-09-2008, 06:33 PM
  4. sprite constructor
    By Krux in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-21-2007, 06:52 AM
  5. Sprite patch for 0.8
    By Trigve in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-19-2007, 12:41 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •