3dPointList.cpp
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:4k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // 3dPointList.cpp : implementation file
  3. //
  4. // glOOP (OpenGL Object Oriented Programming library)
  5. // Copyright (c) Craig Fahrnbach 1997, 1998
  6. //
  7. // OpenGL is a registered trademark of Silicon Graphics
  8. //
  9. //
  10. // This program is provided for educational and personal use only and
  11. // is provided without guarantee or warrantee expressed or implied.
  12. //
  13. // Commercial use is strickly prohibited without written permission
  14. // from ImageWare Development.
  15. //
  16. // This program is -not- in the public domain.
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "glOOP.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. //////////////////////////////////////////////////////////////////
  27. // C3dPointList
  28. IMPLEMENT_DYNAMIC(C3dPointList, CObList)
  29. /////////////////////////////////////////////////////////////////////////////
  30. // C3dPointList construction
  31. C3dPointList::C3dPointList()
  32. {
  33. // TODO: add construction code here,
  34. // Place all significant initialization in InitInstance
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. // C3dPointList Destructor
  38. C3dPointList::~C3dPointList()
  39. {
  40. DeleteAll();
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // C3dPointList function implimentation
  44. void C3dPointList::Remove(C3dPoint* pPoint)
  45. {
  46. if (!pPoint) return;
  47. POSITION pos = CObList::Find(pPoint);
  48. if (pos) {
  49. RemoveAt(pos);
  50. }
  51. }
  52. void C3dPointList::Delete(C3dPoint* pPoint)
  53. {
  54. if (!pPoint) return;
  55. Remove(pPoint);
  56. delete pPoint;
  57. }
  58. void C3dPointList::DeleteAll()
  59. {
  60. while (!IsEmpty()) {
  61. C3dPoint* pPoint = (C3dPoint*) RemoveHead();
  62. delete pPoint;
  63. }
  64. }
  65. void C3dPointList::Display(C3dWorld* pWorld, C3dCamera* pCamera, BOOL bConnectPoints)
  66. {
  67. GLfloat fRadius;
  68. GLfloat fPointColor[4]   = { 0.0f, 0.6f, 0.2f, 1.0f }; // Dark Green
  69. GLfloat fSelectedColor[4] = { 0.9f, 0.9f, 0.0f, 1.0f }; // Yellow
  70. GLfloat fLineColor[4]   = { 0.5f, 0.6f, 0.2f, 1.0f }; // Light Green
  71. GLfloat fLastOrigin[4];
  72. BOOL bMoreThanOnePoint = FALSE;
  73. // Calculate our points' radius.  We don't want the point to
  74. // be too small or too large, so we'll use our cameras' 
  75. // distance from the origin to calculate our point radius.
  76. fRadius = pCamera->m_fOrigin[Z]/200.0f;
  77. // Disable lighting calculations
  78. glDisable(GL_LIGHTING);
  79. glLineWidth(2.0f);
  80. // Display all points in our list
  81. C3dPoint* pPoint = NULL;
  82. // walk the list
  83. POSITION Pos = GetHeadPosition();
  84. while (Pos) {
  85. pPoint = GetAt(Pos);
  86. if(pWorld->m_pSelectedPnt == pPoint)
  87. pPoint->Display(fRadius, fSelectedColor, TRUE);
  88. else
  89. pPoint->Display(fRadius, fPointColor, TRUE);
  90. glColor4fv(fLineColor);
  91. if(bConnectPoints && bMoreThanOnePoint) {
  92. glBegin(GL_LINES);
  93. glVertex3fv(fLastOrigin);
  94. glVertex3fv(pPoint->m_fOrigin);
  95. glEnd();
  96. }
  97. fLastOrigin[0] = pPoint->m_fOrigin[0];
  98. fLastOrigin[1] = pPoint->m_fOrigin[1];
  99. fLastOrigin[2] = pPoint->m_fOrigin[2];
  100. fLastOrigin[3] = pPoint->m_fOrigin[3];
  101. bMoreThanOnePoint = TRUE;
  102. pPoint = GetNext(Pos);
  103. }
  104. // Enable lighting calculations
  105. glEnable(GL_LIGHTING);
  106. glLineWidth(1.0f);
  107. }
  108. C3dPoint* C3dPointList::Find(float x, float y, float z, float test)
  109. {
  110. // Find the point within the list that is within the 
  111. // tolerance given by 'test'.  
  112. C3dPoint* pPoint = NULL;
  113. // walk the list
  114. POSITION Pos = GetHeadPosition();
  115. while (Pos) {
  116. pPoint = GetAt(Pos);
  117. if(pPoint->HitTest(x, y, z, test))
  118. return pPoint;
  119. pPoint = GetNext(Pos);
  120. }
  121. return NULL;
  122. }