Click here to Skip to main content
15,891,828 members
Articles / Multimedia / OpenGL

Modified version of lib3ds reader of .3ds format

Rate me:
Please Sign up or sign in to vote.
4.78/5 (15 votes)
4 Oct 2012CPOL3 min read 42.8K   2.9K   23  
In this article I present version of lib3ds reader for C++ language
#include "Lib3ds_camera.h"

#include <math.h>

Lib3ds_camera::Lib3ds_camera()
{
}

/*!
 * Return a new Lib3dsCamera object.
 *
 * Object is initialized with the given name and fov=45.  All other
 * values are 0.
 *
 * \param name Name of this camera.  Must not be NULL.  Must be < 64 characters.
 *
 * \return Lib3dsCamera object or NULL on failure.
 */
Lib3dsCamera Lib3ds_camera::lib3ds_camera_new(QString name)
{
    Lib3dsCamera camera;

    memset(&camera.setting, 0, sizeof(Lib3dsCamera_setting));

    camera.name = name;

    camera.setting.fov = 45.0f;

    return camera;
}


/*!
 * Read a camera definition from a file.
 *
 * This function is called by lib3ds_file_read(), and you probably
 * don't want to call it directly.
 *
 * \param camera A Lib3dsCamera to be filled in.
 * \param io A Lib3dsIo object previously set up by the caller.
 *
 * \see lib3ds_file_read
 */
bool Lib3ds_camera::lib3ds_camera_read(Lib3dsCamera *camera)
{
    Lib3dsChunk c;
    uint16_t chunk;

    if(!lib3ds_chunk_read_start(&c, CHK_N_CAMERA))
    {
        return false;
    }

    {
        int i;
        for (i = 0; i < 3; ++i)
        {
            camera->setting.position[i] = lib3ds_io_read_float();
        }
        for (i = 0; i < 3; ++i)
        {
            camera->setting.target[i] = lib3ds_io_read_float();
        }
    }
    camera->setting.roll = lib3ds_io_read_float();
    {
        float s;

        s = lib3ds_io_read_float();

        if (fabs(s) < LIB3DS_EPSILON)
        {
            camera->setting.fov = 45.0;
        }
        else
        {
            camera->setting.fov = 2400.0f / s;
        }
    }
    lib3ds_chunk_read_tell(&c);

    while ((chunk = lib3ds_chunk_read_next(&c)) != 0)
    {
        switch (chunk)
        {
            case CHK_CAM_SEE_CONE:
            {
                camera->setting.see_cone = TRUE;
            }
            break;

            case CHK_CAM_RANGES:
            {
                camera->setting.near_range = lib3ds_io_read_float();
                camera->setting.far_range = lib3ds_io_read_float();
            }
            break;

            default:
                lib3ds_chunk_unknown(chunk);
        }
    }

    lib3ds_chunk_read_end(&c);

    return true;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions