DI-Guy Graphics API, diguyOsgGraphicsMaterial

diguyOsgGraphicsMaterial.cpp

DI-Guy API Version 12.5.1

This file was automatically generated from diguyOsgGraphicsMaterial.cpp. Do not edit this file directly; the changes will be lost.
Introduction
Materials modify the color and lighting characteristics of meshes. They work in concert with textures to determine the final appearance of visible geometry.

The class diguyOsgGraphicsMaterial is an example of a diguyGraphicsMaterial subclass for an scene graph renderer using the DI-Guy Loader. The example subclass shows how to use the accessors of the diguyGraphicsMaterial class and which virtual functions should be overridden for an scene graph renderer such as Open Scene Graph.

Header files and forward declarations
#include "diguyOsgGraphicsMaterial.h"
Constructor
Description:

Initialize data members of the class to a known state.

Most base class data will not be fully initialized until during the Build Stage, so most base class accessors should not be called here.

diguyOsgGraphicsMaterial::diguyOsgGraphicsMaterial(void* internal_data)
    :
    diguyGraphicsMaterial(internal_data)
{
    /*
     *  Nothing else to do after calling base class constructor and
     *   initializing data members.
     */
}
build
Build Stage

Description:

Override of diguyGraphicsMaterial::build().

The build() function should create renderer objects that will set the proper material state in the scene graph traversal.

This implementation creates an osg::Material object, and initializes it from material properties retrieved using diguyGraphicsMaterial accessors.

void
diguyOsgGraphicsMaterial::build()
{
    float ambient[4];
    float diffuse[4];
    float specular[4];
    float emission[4];
    float shininess;

    get_ambient(ambient);
    get_diffuse(diffuse);
    get_specular(specular);
    get_emission(emission);
    get_shininess(&shininess);

    m_material = new osg::Material;

    m_material->setAmbient(osg::Material::FRONT_AND_BACK,
        osg::Vec4(ambient[0],
            ambient[1],
            ambient[2],
            ambient[3]));
    m_material->setDiffuse(osg::Material::FRONT_AND_BACK,
        osg::Vec4(diffuse[0],
            diffuse[1],
            diffuse[2],
            diffuse[3]));
    m_material->setSpecular(osg::Material::FRONT_AND_BACK,
        osg::Vec4(specular[0],
            specular[1],
            specular[2],
            specular[3]));
    m_material->setEmission(osg::Material::FRONT_AND_BACK,
        osg::Vec4(emission[0],
            emission[1],
            emission[2],
            emission[3]));
    m_material->setShininess(osg::Material::FRONT_AND_BACK,
        shininess);
}
unbuild
Unbuild Stage

Description:

Override of diguyGraphicsMaterial::unbuild().

The unbuild() function should destroy the objects created in the build() function.

This implementation dereferences the osg::Material created in build().

void
diguyOsgGraphicsMaterial::unbuild()
{
    /*
     *  Setting the m_material ref_ptr to NULL dereferences the object it
     *   points to, possibly deleting it.
     */
    m_material = NULL;
}
Create function definition
Create and return an object of a subclass of diguyGraphicsMaterial.

diguyGraphicsMaterial*
diguyOsgGraphicsMaterial_create_func(void* internal_data)
{
    return new diguyOsgGraphicsMaterial(internal_data);
}



Copyright (C) 1992-2012 Boston Dynamics

ALL RIGHTS RESERVED.

These coded instructions, statements, and computer programs contain unpublished proprietary information of Boston Dynamics and are protected by Copyright Laws of the United States. They may not be used, duplicated, or disclosed in any form, in whole or in part, without the prior written consent from Boston Dynamics.

RESTRICTED RIGHTS LEGEND

Use, duplication, or disclosure by the government is subject to restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Sofware clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR, or the DOD or NASA FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, as applicable. Unpublished-rights reserved under the Copyright Laws of the United States.

Contractor/Manufacturer is:

Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.