3dPointList.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:4k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPointList.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"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPointList
- IMPLEMENT_DYNAMIC(C3dPointList, CObList)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPointList construction
- C3dPointList::C3dPointList()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPointList Destructor
- C3dPointList::~C3dPointList()
- {
- DeleteAll();
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPointList function implimentation
- void C3dPointList::Remove(C3dPoint* pPoint)
- {
- if (!pPoint) return;
- POSITION pos = CObList::Find(pPoint);
- if (pos) {
- RemoveAt(pos);
- }
- }
- void C3dPointList::Delete(C3dPoint* pPoint)
- {
- if (!pPoint) return;
- Remove(pPoint);
- delete pPoint;
- }
- void C3dPointList::DeleteAll()
- {
- while (!IsEmpty()) {
- C3dPoint* pPoint = (C3dPoint*) RemoveHead();
- delete pPoint;
- }
- }
- void C3dPointList::Display(C3dWorld* pWorld, C3dCamera* pCamera, BOOL bConnectPoints)
- {
- GLfloat fRadius;
- GLfloat fPointColor[4] = { 0.0f, 0.6f, 0.2f, 1.0f }; // Dark Green
- GLfloat fSelectedColor[4] = { 0.9f, 0.9f, 0.0f, 1.0f }; // Yellow
- GLfloat fLineColor[4] = { 0.5f, 0.6f, 0.2f, 1.0f }; // Light Green
- GLfloat fLastOrigin[4];
- BOOL bMoreThanOnePoint = FALSE;
- // Calculate our points' radius. We don't want the point to
- // be too small or too large, so we'll use our cameras'
- // distance from the origin to calculate our point radius.
- fRadius = pCamera->m_fOrigin[Z]/200.0f;
- // Disable lighting calculations
- glDisable(GL_LIGHTING);
- glLineWidth(2.0f);
- // Display all points in our list
- C3dPoint* pPoint = NULL;
- // walk the list
- POSITION Pos = GetHeadPosition();
- while (Pos) {
- pPoint = GetAt(Pos);
- if(pWorld->m_pSelectedPnt == pPoint)
- pPoint->Display(fRadius, fSelectedColor, TRUE);
- else
- pPoint->Display(fRadius, fPointColor, TRUE);
- glColor4fv(fLineColor);
- if(bConnectPoints && bMoreThanOnePoint) {
- glBegin(GL_LINES);
- glVertex3fv(fLastOrigin);
- glVertex3fv(pPoint->m_fOrigin);
- glEnd();
- }
- fLastOrigin[0] = pPoint->m_fOrigin[0];
- fLastOrigin[1] = pPoint->m_fOrigin[1];
- fLastOrigin[2] = pPoint->m_fOrigin[2];
- fLastOrigin[3] = pPoint->m_fOrigin[3];
- bMoreThanOnePoint = TRUE;
- pPoint = GetNext(Pos);
- }
- // Enable lighting calculations
- glEnable(GL_LIGHTING);
- glLineWidth(1.0f);
- }
- C3dPoint* C3dPointList::Find(float x, float y, float z, float test)
- {
- // Find the point within the list that is within the
- // tolerance given by 'test'.
- C3dPoint* pPoint = NULL;
- // walk the list
- POSITION Pos = GetHeadPosition();
- while (Pos) {
- pPoint = GetAt(Pos);
- if(pPoint->HitTest(x, y, z, test))
- return pPoint;
- pPoint = GetNext(Pos);
- }
- return NULL;
- }