3dObjectSphere.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:5k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dObjectSphere.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #include "3dObjectDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dObjectSphere
- IMPLEMENT_DYNAMIC(C3dObjectSphere, C3dObject)
- /////////////////////////////////////////////////////////////////////////////
- // C3dObjectSphere construction
- C3dObjectSphere::C3dObjectSphere()
- {
- // Set the attributes to default values..
- m_iType = SHAPE_OBJECT;
- m_szName.Format("Sphere %u", nSphereObjects++);
- m_fRadius = 1.0f;
- m_iNumMajor = 20;
- m_iNumMinor = 20;
- // Create a quadratic object used to draw our object
- m_pQuad = gluNewQuadric();
- ASSERT(m_pQuad);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dObjectSphere Destructor
- C3dObjectSphere::~C3dObjectSphere()
- {
- if(m_pQuad)
- gluDeleteQuadric(m_pQuad);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dObjectSphere Methods or virtual function implimentation
- void C3dObjectSphere::AddAttributePage(C3dWorld* pWorld, LPVOID pSht)
- {
- C3dObjectPropSheet* pSheet = (C3dObjectPropSheet*)pSht;
- ASSERT(pSheet);
- // Add the page to the property sheet
- pSheet->AddPage(&pSheet->m_SpherePage);
- // Save the address of this object in the page
- pSheet->m_SpherePage.m_pObject = this;
- }
- void C3dObjectSphere::GetShapeBounds(C3dBoundingBox* pBox)
- {
- // Calculate the bounds of the shape
- pBox->m_fMax[X] = m_fRadius;
- pBox->m_fMax[Y] = m_fRadius;
- pBox->m_fMax[Z] = m_fRadius;
- pBox->m_fMin[X] = -m_fRadius;
- pBox->m_fMin[Y] = -m_fRadius;
- pBox->m_fMin[Z] = -m_fRadius;
- }
- int C3dObjectSphere::LoadBitMapImage(CImageList* pList)
- {
- CBitmap bitmap;
- // If the image index has been stored in this object,
- // return the index.
- if(m_iBMImage > -1)
- return m_iBMImage;
- // If the image index for this object type has been
- // created, store the index for this object and
- // return the index.
- if( iObjectSphereBMImage > -1) {
- m_iBMImage = iObjectSphereBMImage;
- return m_iBMImage;
- }
- // The image index for this object type has not been
- // loaded and the object image index has not been
- // stored.
- //
- // Load the bitmap for the non-selected light
- bitmap.LoadBitmap(IDB_OBJECT_SPHERE);
- m_iBMImage = pList->Add(&bitmap, (COLORREF)0xFFFFFF);
- bitmap.DeleteObject();
- // Load the bitmap for the non-selected light
- bitmap.LoadBitmap(IDB_OBJECT_SPHERE_SELECTED);
- pList->Add(&bitmap, (COLORREF)0xFFFFFF);
- bitmap.DeleteObject();
- iObjectSphereBMImage = m_iBMImage;
- return m_iBMImage;
- }
- void C3dObjectSphere::Serialize(CArchive& ar, int iVersion)
- {
- CString szBuffer;
- if (ar.IsStoring())
- {
- // Save the Object Class header...
- szBuffer.Format("n%sC3dObjectSphere {n", szIndent);
- ar.WriteString(szBuffer);
- // Save the this objects' specific data...
- szBuffer.Format("%stRadius < %f >n", szIndent, m_fRadius);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stMajorSlices < %d >n", szIndent, m_iNumMajor);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stMinorSlices < %d >n", szIndent, m_iNumMinor);
- ar.WriteString(szBuffer);
- // Save the base class object data...
- C3dObject::Serialize(ar, iVersion);
- szBuffer.Format("%s}n", szIndent); // end of object def
- ar.WriteString(szBuffer);
- }
- else
- {
- if(iVersion < 102)
- // Read the base class object data...
- C3dObject::Serialize(ar, iVersion);
- // Read the derived class data..
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft(); // Remove leading white spaces
- sscanf(szBuffer, "Radius < %f >n", &m_fRadius);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "MajorSlices < %d >n", &m_iNumMajor);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "MinorSlices < %d >n", &m_iNumMinor);
- if(iVersion < 102)
- // Read all child objects...
- LoadChildObjects(ar, iVersion);
- else
- // Read the base class object data...
- C3dObject::Serialize(ar, iVersion);
- }
- }
- void C3dObjectSphere::Build(C3dWorld* pWorld, C3dCamera* pCamera)
- {
- // Compile and build the list
- glNewList(m_iDisplayLists, GL_COMPILE_AND_EXECUTE);
- // Display the quadric object.
- gluSphere(m_pQuad, (GLdouble)m_fRadius, m_iNumMajor, m_iNumMinor);
- glEndList();
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dObjectSphere function implimentation