📄 graphicengine.h
字号:
/*********************************************************************************** In the name of Almighty ** ** GraphicEngine.h : Robocup 3D Soccer Simulation Team Zigorat ** ** Date: 06/02/1386 ** Author: Mahdi Hamdarsi ** Comments: This file contains class definitions for Acthandler which handles ** command sending to simulation server ** ***********************************************************************************//*! \file GraphicEngine.h<pre><b>File:</b> GraphicEngine.h<b>Project:</b> Robocup Soccer Simulation Team: Zigorat<b>Authors:</b> Mahdi Hamdarsi<b>Created:</b> 06/02/1386<b>Last Revision:</b> $ID$<b>Contents:</b> This file contains a powerfull interface to use OpenGL/MESA libraries to implement 3D Objects<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>06/02/1386 Mahdi Initial version created</pre>*/#ifndef _GRAPHIC_ENGINE_#define _GRAPHIC_ENGINE_#include <GL/glu.h>#include <deque> // Needed for deque, a container of objects#include "Geometry.h" // Needed for VecPositionusing namespace std;const int MAX_LIGHTING = 8; /*!< Maximum number of lights in scene *//*********************************************************************************************//*************************************** Class TRGBA ***************************************//*********************************************************************************************//*! TRGBA is a class to handle color materials */class TRGBA{ public: TRGBA( int iRed = 255, int iGreen = 255, int iBlue = 255, int iAlpha = 255 ); GLfloat m_Red; /*!< Red component of color */ GLfloat m_Green; /*!< Green component of color */ GLfloat m_Blue; /*!< Blue component of color */ GLfloat m_Alpha; /*!< Alpha component of color */};const TRGBA COLOR_WHITE = TRGBA( 255, 255, 255 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_LIGHT_GREY = TRGBA( 204, 204, 204 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_DARK_GREY = TRGBA( 102, 102, 102 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_RED = TRGBA( 255, 0, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_LIGHT_RED = TRGBA( 255, 0, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_GREEN = TRGBA( 0, 122, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_LIGHT_GREEN = TRGBA( 0, 255, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_BLUE = TRGBA( 0, 0, 255 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_LIGHT_BLUE = TRGBA( 255, 0, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_YELLOW = TRGBA( 255, 255, 0 ); /*!< Global onstant that says how red color is. */const TRGBA COLOR_BLACK = TRGBA( 0, 0, 0 ); /*!< Global onstant that says how red color is. *//*********************************************************************************************//************************************ Class TOpenGLDrawing *********************************//*********************************************************************************************//*! This class eases the operation of drawing in OpenGL/MESA library */class TOpenGLDrawing{ public: static void drawSphere ( double radius, bool solid = true, int num_slices = -1 ); static void drawCube ( double edge_size, bool solid = true ); static void drawBox ( double length, double width, double height, bool solid = true ); static void changeDiffuseColor ( const TRGBA & color ); static void changeSpecularColor( const TRGBA & color );};/*********************************************************************************************//************************************ Class TOpenGLCamera **********************************//*********************************************************************************************//*! This class contains an encapsulation of camera concept in a typical OpenGL/MESA framework */class TOpenGLCamera{ protected: VecPosition m_Position; VecPosition m_Direction; VecPosition m_UpDirection; void updateCamera ( ) const; public: TOpenGLCamera ( ); ~ TOpenGLCamera ( ); VecPosition getPosition ( ) const; bool setPosition ( double dx = 0, double dy = 0, double dz = 0 ); bool setPosition ( const VecPosition & pos ); VecPosition getDirection ( ) const; bool setDirection ( double dx = 0, double dy = 0, double dz = 0 ); bool setDirection ( const VecPosition & pos ); VecPosition getUpDirection ( ) const; bool setUpDirection ( double dx = 0, double dy = 0, double dz = 0 ); bool setUpDirection ( const VecPosition & pos ); void forceUpdate ( ) const;};/*********************************************************************************************//*********************************** Class TOpenGLLight ************************************//*********************************************************************************************//*! This class contains an encapsulation of light sources in a typical OpenGL/MESA framework */class TOpenGLLight{ protected: VecPosition m_LightPosition; /*!< Light source position */ VecPosition m_LightDirecton; /*!< Direction which ligth is litting */ GLenum m_ID; /*!< Light identifier */ bool m_Enabled; /*!< Is this light enabled? */ bool updateLighting ( ); public: TOpenGLLight ( GLenum id = GL_LIGHT0, bool en = false ); ~ TOpenGLLight ( ); VecPosition getLightPosition ( ) const; bool setLightPosition ( const VecPosition & pos ); bool setLightPosition ( double dx = 0, double dy = 0, double dz = 0 ); VecPosition getLightDirection ( ) const; bool setLightDirection ( const VecPosition & pos ); bool setLightDirection ( double dx = 0, double dy = 0, double dz = 0 ); GLenum getID ( ) const; bool setID ( const GLenum &id ); bool getEnabled ( ) const; bool setEnabled ( const bool & en ); bool forceUpdate ( );};/*********************************************************************************************//********************************** Class TOpenGLObject ************************************//*********************************************************************************************/const int OBJECT_UNKNOWN = -1; /*!< Represents an unknown object *//*! This class should be the base class for anything that is going to be rendered in this library, it provides a virtual method called 'render' which is the place where the object renders itself, and a mechanism for the object to store & initialize itself from a stream. */class TOpenGLObject{ protected: int m_GlobalID; /*!< The global identifier of this object */ VecPosition m_Position; /*!< The position of this object */ VecPosition m_Direction; /*!< Current direction of the object */ TRGBA m_DiffuseColor; /*!< Current diffuse color of object */ TRGBA m_SpecularColor; /*!< Current specular color of object */ public: TOpenGLObject ( ); virtual ~ TOpenGLObject ( ); int getGlobalID ( ) const; bool setGlobalID ( const int & gid ); VecPosition getPosition ( ) const; virtual bool setPosition ( const VecPosition & pos ); VecPosition getDirection ( ) const; virtual bool setDirection ( const VecPosition & dir ); TRGBA getDiffuseColor ( ) const; bool setDiffuseColor ( const TRGBA & color ); TRGBA getSpecularColor ( ) const; bool setSpecularColor ( const TRGBA & color ); virtual bool update ( ) = 0; virtual bool render ( ) = 0;};typedef TOpenGLObject * POpenGLObject;/*********************************************************************************************//*********************************** Class TOpenGLQuadric **********************************//*********************************************************************************************//*! This class represents quadratic objects in OpenGL library */class TOpenGLQuadric : public TOpenGLObject
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -