// SceneGraph.h // NKU CSC 480/580 - Kirby // ------------------------------------------------------------------ // A first attempt at a scene graph. Bare bones. // // Node // TransformationNode // EnvironmentNode // LightNode // AppearanceNode // MaterialNode // ArtifactNode // GlutSphere // GlutTeapot // Mesh // // This version only has an implicitly recursive render() function. // ------------------------------------------------------------------ #ifndef SCENEGRAPH_H #define SCENEGRAPH_H #include "Geometry.h" #include using namespace std ; using namespace csc480 ; // Node // ---- class Node // A base class for all nodes. // Concrete: may be used as a group node. { public: Node() : _next( NULL ), _child( NULL ) {} virtual ~Node() {} void addChild( Node* pc ) { pc->_next= _child ; _child= pc ; } virtual void render() const { renderChildren() ; } void renderChildren() const { for ( const Node* p= _child ; p ; p= p->_next ) p->render() ; } private: Node *_child, *_next ; } ; // TransformationNode // ------------------ class TransformationNode : public Node // A node representing an arbitrary homogeneous transformation. { public: TransformationNode() ; void set( const Vector3& axis, double angle, double scale, const Vector3& trans ) ; void set( const double m[16] ) ; virtual void render() const ; private: double _m[16] ; // OpenGL's column-major order } ; // EnvironmentNode // --------------- class EnvironmentNode : public Node { public: EnvironmentNode() ; } ; // LightNode // --------- class LightNode : public EnvironmentNode { public: LightNode() ; void setPosition( const Point3& pt, double w =0 ) ; void setAmbientColor( float r, float g, float b, float a =1 ) ; void setDiffuseColor( float r, float g, float b, float a =1 ) ; void lightsOn( bool on ) ; virtual void render() const ; private: bool _isOn ; int _id ; // OpenGL light id is (GL_LIGHT0 + _id) static int _lightCount ; // # of lights created so far } ; // AppearanceNode // -------------- class AppearanceNode : public Node { public: AppearanceNode() ; } ; // MaterialNode // ------------ class MaterialNode : public AppearanceNode { public: MaterialNode() ; void setColor( float r, float g, float b, float a =1 ) ; virtual void render() const ; private: float _color[4] ; } ; // ArtifactNode // ------------ class ArtifactNode : public Node { public: ArtifactNode() ; virtual const Point3& getCenter() const = 0 ; virtual const Vector3& getUpVec() const = 0 ; virtual double getRadius() const = 0 ; virtual double getBaseDepth() const = 0 ; } ; // GlutSphere (immutable) // ---------------------- class GlutSphere : public ArtifactNode { public: GlutSphere() ; virtual const Point3& getCenter() const ; virtual const Vector3& getUpVec() const ; virtual double getRadius() const ; virtual double getBaseDepth() const ; virtual void render() const ; private: const Point3 _center ; const Vector3 _upVec ; int _id ; // display list ID } ; #endif