/* -*-c++-*- Producer - Copyright (C) 2001-2004  Don Burns
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
 */

// This is a simple example of a Producer::Camera::SceneHandler
#ifndef PRODUCER_EXAMPLES_MYSCENEHANDLER
#define PRODUCER_EXAMPLES_MYSCENEHANDLER

#include <Producer/Camera>
#include <GL/gl.h>
#include <GL/glu.h>

// Use the OpenGL teapot as a sample object to draw
// Borrowed from the glut distribution.
extern void glutSolidTeapot(GLdouble scale);

class MySceneHandler : public Producer::Camera::SceneHandler
{
    public:
        MySceneHandler() : Producer::Camera::SceneHandler(),
            _angle(0.0f),
            _initialized(false) 
        {}

        // Producer::Camera::SceneHandler is pure virtual and
        // requires that the draw() method be implemented in 
        // derived classes.
        virtual void draw( Producer::Camera & camera )
        {
            // Lazy initialize
            if( !_initialized ) init();


            glPushMatrix();
            glRotatef( _angle, 0, 1, 0 );

            // Draw the OpenGL teapot
            glutSolidTeapot(1.0);

            glPopMatrix();

            _angle++;
        }

        // Initialize Graphics state
        void init()
        {
            glEnable( GL_DEPTH_TEST );
            glEnable( GL_LIGHTING );
            glEnable( GL_LIGHT0 );
            glClearColor( 0.2f, 0.2f, 0.4f, 1.0f );

            _initialized = true;
        }

    private:
        float _angle;
        bool _initialized;
};
#endif
