Click here to Skip to main content
15,894,825 members
Articles / Desktop Programming / MFC

OAG Library (OpenGL) Part 1 - Setting Up the Library for an MFC Application

Rate me:
Please Sign up or sign in to vote.
4.40/5 (11 votes)
7 Aug 2011CPOL3 min read 56.3K   56  
OAG is a library written in C++. With this library, you can create OpenGL based applications.
#ifndef OAG_OAGOBJECT_H
#define OAG_OAGOBJECT_H

#include "OAGTree.h"

#ifdef _WIN32
#ifdef _MSC_VER
#include "..\..\..\Common\include\OAGColor.h"
#include "..\..\..\Common\include\OAG2DMath.h"
#include <string.h>
#endif
#endif

class CCamera;

#include "OAGXMLData.h"

namespace oag
{

	class OAGObject : public oag::OAGNode
	{
	public:
		OAGObject(void);
		virtual ~OAGObject(void);

	//Attributes
	protected:
		std::string m_strName;
		bool m_bIsSelected;
		GLenum m_PolygonFace;					//GL_FRONT, GL_BACK or GL_FRONT_AND_BACK
		GLenum m_PolygonMode;					//GL_POINT, GL_LINE or GL_FILL
        oag::OAGColor m_Color;					//object color

	public:
		oag::OAGVector3f	m_position;			// object position
		oag::OAGVector3f	m_scale;			// object scale
		oag::OAGVector3f	m_rotation;			// object rotation
		oag::OAGVector3f	velocity;			// velocity of object
		oag::OAGVector3f	acceleration;		// acceleration
		float				size;				// size of bounding sphere (radius)

	//Operations
	public:
		//Draws the objects and childs
		void Draw();

	public:
		
		//Gets the current color set for the object
		void GetColor(oag::OAGColor &color)					
		{ 
			color.SetColor( m_Color.GetRed(), m_Color.GetGreen(), m_Color.GetBlue(), m_Color.GetAlpha() ); 
		}

		//Gets the current name set for the object
		std::string GetObjectName()
		{ 
			return m_strName; 
		}
		
		//Gets the status for the object selection
		//Return TRUE if the object is selected.
		bool IsSelected()
		{ 
			return m_bIsSelected; 
		}
		
		//Sets the color for the object
		void SetColor(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255)
		{ 
			m_Color.SetColor(red, green, blue, alpha);  
		}
		
		//Sets a for the object
		void SetObjectName(std::string strName)
		{
			m_strName = strName; 
		}
		
		//Selects a polygon rasterization mode.
		//@Param face - The face mode for the polygons		=> GL_FRONT, GL_BACK or GL_FRONT_AND_BACK
		//@Param mode - The way polygons will be rasterized => GL_POINT, GL_LINE or GL_FILL
		void SetPolygonMode(GLenum mode, GLenum face = GL_FRONT_AND_BACK)
		{ 
			m_PolygonMode = mode; m_PolygonFace = face;
		}

		//Sets the position for the object or translate the object.
		void SetPosition(oag::OAGVector3f vector)
		{ 
			m_position = vector;
		}

		//Sets the position for the object or translate the object.
		void SetPosition(float x, float y, float z)
		{ 
			m_position.SetVertex(x, y, z);
		}
		
		//Sets the position for the object or translate the object.
		void SetPosition(CXmlNode* pNode)
		{ 
			if ( pNode )
			{
				CXmlNode* pNodeTranslation = pNode->GetNode("Translation");
				if ( pNodeTranslation )
				{
					float x =  (float)atof ( pNodeTranslation->GetAttribute("x").c_str() );
					float y =  (float)atof ( pNodeTranslation->GetAttribute("y").c_str() );
					float z =  (float)atof ( pNodeTranslation->GetAttribute("z").c_str() );

					SetPosition( x, y, z);
				}
			}
		}

		//Sets the scale for the object
		void SetScale(oag::OAGVector3f vector)	
		{ 
			m_scale = vector; 
		}
		
		//Sets the rotation for the object
		void SetRotation(oag::OAGVector3f vector)
		{ 
			m_rotation = vector;
		}
		
		//Sets the status for the selected object.
		void SetSelected(bool bSelected)
		{
			m_bIsSelected = bSelected;
		}


	//Virtual Operations
	public:
		 
		 //Reads the xmlnode written for the object and loads its data.
		 virtual void ReadNodeXML(CXmlNode* pNode);
		 
		 //Writes the xmlnode for the object with the data.
		 virtual void SaveNodeXML(CXmlNode* pNode);

	protected:
		//Called by funtion Draw. Draws the objects
		virtual void OnDraw(){};


	//Operations for XML
	public:
		CXmlNode* CreateNodeColor();

		//Functions for game engine


	};

};

#endif //OAG_OAGOBJECT_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Brazil Brazil
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.

Comments and Discussions