#ifdef _MSC_VER
#include "..\..\include\oag\OAGSphere.h"
#endif
oag::OAGSphere::OAGSphere(void)
:oag::OAGQuadric(10,10)
,m_dRadius(1)
{
}
//Creates a sphere with numbers for slices and stacks
//@Param dRadius - The radius for the sphere
//@Param slices - The number of subdivisions around the z-axis (similar to lines of longitude).
//@Param stacks - The number of subdivisions along the z-axis (similar to lines of latitude).
oag::OAGSphere::OAGSphere(GLdouble dRadius, GLint nSlices, GLint nStacks)
:oag::OAGQuadric(nSlices, nStacks)
,m_dRadius(dRadius)
{
}
oag::OAGSphere::~OAGSphere(void)
{
}
//Operations
void oag::OAGSphere::OnDraw()
{
::glPushMatrix();
::glColor4ubv( m_Color.GetColor4ubv() );
::glPolygonMode(m_PolygonFace, m_PolygonMode);
::glTranslated( m_position.m_X, m_position.m_Y, m_position.m_Z);
::glScalef( m_scale.m_X, m_scale.m_Y, m_scale.m_Z);
::glRotatef( m_rotation.m_X, 1.0, 0, 0);
::glRotatef( m_rotation.m_Y, 0, 1.0, 0);
::glRotatef( m_rotation.m_Z, 0, 0, 1.0);
::gluQuadricNormals(m_pQuadric, GLU_SMOOTH);
::gluSphere( m_pQuadric, m_dRadius, m_nSlices, m_nStacks);
::glPopMatrix();
}
void oag::OAGSphere::ReadNodeXML(CXmlNode* pNode)
{
oag::OAGQuadric::ReadNodeXML(pNode);
CXmlNode* pNodeSphere = pNode->GetNode("Sphere");
if ( pNodeSphere )
{
CXmlNode* pNodeRadius = pNodeSphere->GetNode("Radius");
if ( pNodeRadius )
m_dRadius = atof( pNodeRadius->GetAttribute("value").c_str() );
}
}
void oag::OAGSphere::SaveNodeXML(CXmlNode* pNode)
{
oag::OAGQuadric::SaveNodeXML( pNode );
CXmlNode* pNodeQuadric = pNode->GetLastChild();
if ( pNodeQuadric )
{
CXmlNode* pNodeSphere = new CXmlNode("Sphere");
pNodeQuadric->AppendChild( pNodeSphere );
char buffer[_CVTBUFSIZE];
CXmlNode* pNodeRadius = new CXmlNode("Radius");
pNodeSphere->AppendChild( pNodeRadius );
_gcvt_s(buffer, _CVTBUFSIZE, m_dRadius, 4 ); pNodeRadius->AddAttribute("value", buffer);
}
}