diguyOsgUtil.cpp

DI-Guy API Version 12.5.1

This file was automatically generated from diguyOsgUtil.cpp. Do not edit this file directly; the changes will be lost.
/*
 *  Copyright (C) 1992-2011 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 Software 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.
 */

#include <stdio.h>

#include <libbdilog.h>
#include <diguyAuthorInterface.h>
#include <diguy_vector_classes.h>

#include <osg/BlendFunc>
#include <osg/CullFace>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/LineWidth>
#include <osg/Material>
#include <osg/MatrixTransform>
#include <osg/ShapeDrawable>
#include <osg/StateSet>

#include "diguyOsgUtil.h"
// static
void
diguyOsgUtil::detach_and_null(osg::ref_ptr<osg::MatrixTransform>& child)
{
    if (child == NULL)
        return;

    while (child->getNumParents() > 0)
        child->getParent(0)->removeChild(child);

    child = NULL;
}
// static
void
diguyOsgUtil::detach_and_null(osg::ref_ptr<osg::Geode>& child)
{
    if (child == NULL)
        return;

    while (child->getNumParents() > 0)
        child->getParent(0)->removeChild(child);

    child = NULL;
}
// static
void
diguyOsgUtil::detach_and_null(osg::Geode* geode, osg::ref_ptr<osg::Geometry>& drawable)
{
    if (drawable == NULL)
        return;

    if (geode == NULL)
        return;

    geode->removeDrawable(drawable);
    drawable = NULL;
}
// static
osg::Geometry*
diguyOsgUtil::create_sphere_solid(float radius,
    int num_slices,
    int num_layers,
    const diguyVec4f & color)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_sphere_vertices(radius,
        num_slices,
        num_layers,
        diguyVec3f(0.0f),
        diguyVec3f(0.0f),
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        0,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     *
     *  Long way for now, adding data vertex by vertex.  I'd like to find
     *   the OSG way for simply copying a binary block of data containing
     *   float vertex data into the vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array;
    osg_vertices->reserve(num_vertices);

    float* vptr = &(vertices[0].x);

    for (index=0; index<num_vertices; index++)
    {
        osg_vertices->push_back(osg::Vec3(*vptr, *(vptr+1), *(vptr+2)));
        vptr += 3;
    }

    geometry->setVertexArray(osg_vertices);

    /*
     *  Create osg normals array.
     */
    osg::Vec3Array* osg_normals = new osg::Vec3Array;
    geometry->setNormalArray(osg_normals);
    geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

    float* nptr = &(normals[0].x);

    osg_normals->reserve(num_vertices);

    for (index=0; index<num_vertices; index++)
    {
        osg_normals->push_back(osg::Vec3(*nptr, *(nptr+1), *(nptr+2)));
        nptr += 3;
    }

    /*
     *  Create osg texture indices array.
     */
    // not done yet

    /*
     *  Triangle vertex indices.
     */
    osg::DrawElementsUInt* index_set = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    index_set->reserve(num_indices);
    geometry->addPrimitiveSet(index_set);

    int i;
    for (i=0; i<num_indices; i++)
        index_set->push_back(indices[i]);

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, true);
    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_sphere_wireframe(float radius,
    int num_slices,
    int num_layers,
    const diguyVec4f & color,
    float line_width,
    bool lit)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_sphere_vertices(radius,
        num_slices,
        num_layers,
        diguyVec3f(0.0f),
        diguyVec3f(0.0f),
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        1,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);

    /*
     *  Create osg vertices array.
     *
     *  Long way for now, adding data vertex by vertex.  I'd like to find
     *   the OSG way for simply copying a binary block of data containing
     *   float vertex data into the vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array(num_indices);
    for (index=0; index<num_indices; index++)
    {
        int vertex_index = indices[index];

        float* vptr = &(vertices[vertex_index].x);
        (*osg_vertices)[index].set(vptr[0], vptr[1], vptr[2]);
    }
    geometry->setVertexArray(osg_vertices);

    if (lit)
    {
        osg::Vec3Array* osg_normals = new osg::Vec3Array(num_indices);
        for (index=0; index<num_indices; index++)
        {
            int vertex_index = indices[index];

            float* nptr = &(normals[vertex_index].x);
            (*osg_normals)[index].set(nptr[0], nptr[1], nptr[2]);
        }
        geometry->setNormalArray(osg_normals);
        geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    }

    geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, num_indices));

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, false);

    osg::LineWidth* osg_line_width = new osg::LineWidth;
    osg_line_width->setWidth(line_width);

    state_set->setAttributeAndModes(osg_line_width, osg::StateAttribute::ON);
    state_set->setMode(GL_BLEND, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
    if (!lit)
        state_set->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);

    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_cone_solid(float radius,
    float height,
    int num_slices,
    int num_layers,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_cone_vertices(radius,
        height,
        num_slices,
        num_layers,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        0,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array;
    osg_vertices->reserve(num_vertices);

    osg::Vec3Array* osg_normals = new osg::Vec3Array;
    osg_normals->reserve(num_vertices);

    float* vptr = &(vertices[0].x);
    float* nptr = &(normals[0].x);

    for (index=0; index<num_vertices; index++)
    {
        osg_vertices->push_back(osg::Vec3(*vptr, *(vptr+1), *(vptr+2)));
        vptr += 3;

        osg_normals->push_back(osg::Vec3(*nptr, *(nptr+1), *(nptr+2)));
        nptr += 3;
    }

    geometry->setVertexArray(osg_vertices);
    geometry->setNormalArray(osg_normals);
    geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

    /*
     *  Create osg texture indices array.
     */
    // not done yet

    /*
     *  Triangle vertex indices.
     */
    osg::DrawElementsUInt* index_set = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    index_set->reserve(num_indices);
    geometry->addPrimitiveSet(index_set);

    int i;
    for (i=0; i<num_indices; i++)
        index_set->push_back(indices[i]);

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, true);
    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_cone_wireframe(float radius,
    float height,
    int num_slices,
    int num_layers,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color,
    float line_width,
    bool lit)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_cone_vertices(radius,
        height,
        num_slices,
        num_layers,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        1,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array(num_indices);
    for (index=0; index<num_indices; index++)
    {
        int vertex_index = indices[index];

        float* vptr = &(vertices[vertex_index].x);
        (*osg_vertices)[index].set(vptr[0], vptr[1], vptr[2]);
    }
    geometry->setVertexArray(osg_vertices);

    if (lit)
    {
        osg::Vec3Array* osg_normals = new osg::Vec3Array(num_indices);
        for (index=0; index<num_indices; index++)
        {
            int vertex_index = indices[index];

            float* nptr = &(normals[vertex_index].x);
            (*osg_normals)[index].set(nptr[0], nptr[1], nptr[2]);
        }
        geometry->setNormalArray(osg_normals);
        geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    }

    geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, num_indices));

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, false);

    osg::LineWidth* osg_line_width = new osg::LineWidth;
    osg_line_width->setWidth(line_width);

    state_set->setAttributeAndModes(osg_line_width, osg::StateAttribute::ON);
    state_set->setMode(GL_BLEND, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
    if (!lit)
        state_set->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);

    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_cylinder_solid(float radius,
    float height,
    int num_slices,
    int num_layers,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_cylinder_vertices(radius,
        height,
        num_slices,
        num_layers,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        0,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array;
    osg_vertices->reserve(num_vertices);

    osg::Vec3Array* osg_normals = new osg::Vec3Array;
    osg_normals->reserve(num_vertices);

    float* vptr = &(vertices[0].x);
    float* nptr = &(normals[0].x);

    for (index=0; index<num_vertices; index++)
    {
        osg_vertices->push_back(osg::Vec3(*vptr, *(vptr+1), *(vptr+2)));
        vptr += 3;

        osg_normals->push_back(osg::Vec3(*nptr, *(nptr+1), *(nptr+2)));
        nptr += 3;
    }

    geometry->setVertexArray(osg_vertices);
    geometry->setNormalArray(osg_normals);
    geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

    /*
     *  Create osg texture indices array.
     */
    // not done yet

    /*
     *  Triangle vertex indices.
     */
    osg::DrawElementsUInt* index_set = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    index_set->reserve(num_indices);
    geometry->addPrimitiveSet(index_set);

    int i;
    for (i=0; i<num_indices; i++)
        index_set->push_back(indices[i]);

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, true);
    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_cylinder_wireframe(float radius,
    float height,
    int num_slices,
    int num_layers,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color,
    float line_width,
    bool lit)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_cylinder_vertices(radius,
        height,
        num_slices,
        num_layers,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        1,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array(num_indices);
    for (index=0; index<num_indices; index++)
    {
        int vertex_index = indices[index];

        float* vptr = &(vertices[vertex_index].x);
        (*osg_vertices)[index].set(vptr[0], vptr[1], vptr[2]);
    }
    geometry->setVertexArray(osg_vertices);

    if (lit)
    {
        osg::Vec3Array* osg_normals = new osg::Vec3Array(num_indices);
        for (index=0; index<num_indices; index++)
        {
            int vertex_index = indices[index];

            float* nptr = &(normals[vertex_index].x);
            (*osg_normals)[index].set(nptr[0], nptr[1], nptr[2]);
        }
        geometry->setNormalArray(osg_normals);
        geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    }

    geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, num_indices));

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, false);

    osg::LineWidth* osg_line_width = new osg::LineWidth;
    osg_line_width->setWidth(line_width);

    state_set->setAttributeAndModes(osg_line_width, osg::StateAttribute::ON);
    state_set->setMode(GL_BLEND, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
    if (!lit)
        state_set->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);

    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_box_solid(const diguyVec3f & min,
    const diguyVec3f & max,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_box_vertices(min,
        max,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        0,
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array;
    osg_vertices->reserve(num_vertices);

    osg::Vec3Array* osg_normals = new osg::Vec3Array;
    osg_normals->reserve(num_vertices);

    float* vptr = &(vertices[0].x);
    float* nptr = &(normals[0].x);

    for (index=0; index<num_vertices; index++)
    {
        osg_vertices->push_back(osg::Vec3(*vptr, *(vptr+1), *(vptr+2)));
        vptr += 3;

        osg_normals->push_back(osg::Vec3(*nptr, *(nptr+1), *(nptr+2)));
        nptr += 3;
    }

    geometry->setVertexArray(osg_vertices);
    geometry->setNormalArray(osg_normals);
    geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

    /*
     *  Create osg texture indices array.
     */
    // not done yet

    /*
     *  Triangle vertex indices.
     */
    osg::DrawElementsUInt* index_set = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    index_set->reserve(num_indices);
    geometry->addPrimitiveSet(index_set);

    int i;
    for (i=0; i<num_indices; i++)
        index_set->push_back(indices[i]);

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, true);
    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::Geometry*
diguyOsgUtil::create_box_wireframe(const diguyVec3f & min,
    const diguyVec3f & max,
    const diguyVec3f & position_offset,
    const diguyVec3f & orientation,
    const diguyVec4f & color,
    float line_width,
    bool lit)
{
    int index;
    int num_vertices = 0;

    /*
     *  Generate vertices.
     */
    diguyVec3f* vertices;
    diguyVec3f* normals;
    diguyVec2f* texture_indices;

    int num_indices;
    unsigned int* indices;

    diguyAuthorInterface::generate_box_vertices(min,
        max,
        position_offset,
        orientation,
        &num_vertices,
        &vertices,
        &normals,
        &texture_indices,
        1,                // for_wireframe
        &num_indices,
        &indices);

    /*
     *  Create a geometry drawable object.
     */
    osg::Geometry* geometry = new osg::Geometry;

    geometry->setDataVariance(osg::Object::STATIC);
    geometry->setUseVertexBufferObjects(true);

    /*
     *  Create osg vertices array.
     */
    osg::Vec3Array* osg_vertices = new osg::Vec3Array(num_indices);
    for (index=0; index<num_indices; index++)
    {
        int vertex_index = indices[index];

        float* vptr = &(vertices[vertex_index].x);
        (*osg_vertices)[index].set(vptr[0], vptr[1], vptr[2]);
    }
    geometry->setVertexArray(osg_vertices);

    if (lit)
    {
        osg::Vec3Array* osg_normals = new osg::Vec3Array(num_indices);
        for (index=0; index<num_indices; index++)
        {
            int vertex_index = indices[index];

            float* nptr = &(normals[vertex_index].x);
            (*osg_normals)[index].set(nptr[0], nptr[1], nptr[2]);
        }
        geometry->setNormalArray(osg_normals);
        geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
    }

    geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, num_indices));

    diguyAuthorInterface::delete_generated_vertices(vertices,
        normals,
        texture_indices,
        indices);

    /*
     *  State set.
     */
    osg::StateSet* state_set = create_material_state_set(color, false);

    osg::LineWidth* osg_line_width = new osg::LineWidth;
    osg_line_width->setWidth(line_width);

    state_set->setAttributeAndModes(osg_line_width, osg::StateAttribute::ON);
    state_set->setMode(GL_BLEND, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OFF);
    state_set->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
    if (!lit)
        state_set->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);

    geometry->setStateSet(state_set);

    return geometry;
}
// static
osg::StateSet*
diguyOsgUtil::create_material_state_set(const diguyVec4f & color, bool lit)
{
    osg::Material* material = new osg::Material;

    material->setAmbient(osg::Material::FRONT,  osg::Vec4(color.r, color.g, color.b, color.a));
    material->setDiffuse(osg::Material::FRONT,  osg::Vec4(color.r, color.g, color.b, color.a));
    material->setSpecular(osg::Material::FRONT, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
    material->setEmission(osg::Material::FRONT, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
    material->setShininess(osg::Material::FRONT, 10.0f);

    osg::StateSet* state_set = new osg::StateSet;
    state_set->setAttribute(material);

    if (color.w < 1.0f)
    {
        osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
            osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
        state_set->setAttributeAndModes(bf);

        state_set->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    }
    else
    {
        state_set->setRenderingHint(osg::StateSet::OPAQUE_BIN);
    }

    osg::CullFace* cull = new osg::CullFace;
    cull->setMode(osg::CullFace::BACK);
    state_set->setAttributeAndModes(cull, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);

    return state_set;
}
// static
osg::StateSet*
diguyOsgUtil::create_material_state_set(diguyAuthorVisualMaterial* visual_material)
{
    osg::Material* material = new osg::Material;

    diguyVec4f brush_color = visual_material->get_brush_color();

    material->setAmbient(osg::Material::FRONT,  diguyVec4_to_osgVec4(brush_color));
    material->setDiffuse(osg::Material::FRONT,  diguyVec4_to_osgVec4(brush_color));
    material->setSpecular(osg::Material::FRONT, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
    material->setEmission(osg::Material::FRONT, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
    material->setShininess(osg::Material::FRONT, 10.0f);

    osg::StateSet* state_set = new osg::StateSet;
    state_set->setAttribute(material);

    if (brush_color.w < 1.0f)
    {
        osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
            osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
        state_set->setAttributeAndModes(bf);

        state_set->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    }
    else
    {
        state_set->setRenderingHint(osg::StateSet::OPAQUE_BIN);
    }

    osg::CullFace* cull = new osg::CullFace;
    cull->setMode(osg::CullFace::BACK);
    state_set->setAttributeAndModes(cull, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);

    return state_set;
}
// static
osg::Vec3
diguyOsgUtil::diguyVec3_to_osgVec3(const diguyVec3f & diguy_vec3)
{
    return osg::Vec3(diguy_vec3.x, diguy_vec3.y, diguy_vec3.z);
}
// static
osg::Vec4
diguyOsgUtil::diguyVec4_to_osgVec4(const diguyVec4f & diguy_vec4)
{
    return osg::Vec4(diguy_vec4.x, diguy_vec4.y, diguy_vec4.z, diguy_vec4.w);
}
// static
osg::Quat
diguyOsgUtil::diguy_euler_zxy_radians_to_osgQuat(const diguyVec3f & diguy_euler)
{
    diguyVec4f diguy_quat = diguy_euler.diguy_euler_angles_to_quaternion();
    return osg::Quat(diguy_quat.qx, diguy_quat.qy, diguy_quat.qz, diguy_quat.qw);
}
// static
osg::Quat
diguyOsgUtil::diguy_euler_zxy_degrees_to_osgQuat(const diguyVec3f & diguy_euler)
{
    diguyVec3f diguy_euler_radians(diguy_euler.rz * DIGUY_DEG2RAD,  // yaw
        diguy_euler.rx * DIGUY_DEG2RAD,   // roll
        diguy_euler.ry * DIGUY_DEG2RAD);  // pitch

    diguyVec4f diguy_quat =	diguy_euler_radians.diguy_euler_angles_to_quaternion();
    return osg::Quat(diguy_quat.qx, diguy_quat.qy, diguy_quat.qz, diguy_quat.qw);
}
// static
diguyVec3f
diguyOsgUtil::osgVec3_to_diguyVec3(const osg::Vec3& osg_vec3)
{
    return diguyVec3f(osg_vec3.x(), osg_vec3.y(), osg_vec3.z());
}
// static
diguyVec4f
diguyOsgUtil::osgVec4_to_diguyVec4(const osg::Vec4& osg_vec4)
{
    return diguyVec4f(osg_vec4.x(), osg_vec4.y(), osg_vec4.z(), osg_vec4.w());
}
// static
void
diguyOsgUtil::set_name_from_uid(osg::Object* object, long uid)
{
    char sprintf_temp[128];
    sprintf(sprintf_temp, "%ld", uid);
    object->setName(sprintf_temp);
}



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.