File: MySceneHandler

package info (click to toggle)
openscenegraph 1.2.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 26,924 kB
  • ctags: 25,229
  • sloc: cpp: 239,326; ansic: 2,178; sh: 1,990; yacc: 548; perl: 237; makefile: 227; lex: 151
file content (70 lines) | stat: -rw-r--r-- 1,747 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//C++ header file - Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.

// 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();

			// Clear the Camera's RenderSurface ProjectionRect
			camera.clear();
			
			// Apply the Projection parameters
			camera.applyLens();

			// Place the Camera into the world
			camera.setViewByLookat( 0.0f, 0.0f, 4.0f,   /// Position of the eye
							0.0f, 0.0f, 0.0f,   /// Point the eye is looking at
							0.0f, 1.0f, 0.0f ); /// Up

			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