STARS.CPP
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 1k
Category:

OpenCV

Development Platform:

Visual C++

  1. // Stars.cpp: implementation of the CStars class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "MyGame.h"
  6. #include "Stars.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. #ifndef M_PI
  13. #define M_PI 3.14159265358979323846
  14. #endif
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. CStars::~CStars()
  19. {
  20. }
  21. CStars::CStars(int starn)
  22. {
  23. cc=0;
  24. S.resize(starn);
  25. C.resize(starn+10);
  26. for(int i=0;i<starn;++i)
  27. {
  28. S[i].v[0]=(drand48()-.5);
  29. S[i].v[1]=(drand48()-.5);
  30. S[i].v[2]=0;
  31. }
  32. float basecolor;
  33. for(i=0;i<starn+10;++i)
  34. {
  35. if(i%10) basecolor=drand48();
  36. C[i].v[0]=C[i].v[1]=C[i].v[2]=basecolor+sin((i%10)*M_PI/10.0);
  37. }
  38. }
  39. int CStars::Draw()
  40. {
  41. glDisable(GL_LIGHTING);
  42. glColor3f(1.0,1.0,1.0);
  43. glEnableClientState (GL_VERTEX_ARRAY);
  44. glEnableClientState (GL_COLOR_ARRAY);
  45. glVertexPointer(3,GL_FLOAT,0,S.begin());
  46. glColorPointer(3,GL_FLOAT,0,&(C[cc]));
  47. glDrawArrays(GL_POINTS,0,S.size());
  48. glDisableClientState (GL_VERTEX_ARRAY);
  49. glDisableClientState (GL_COLOR_ARRAY);
  50. glEnable(GL_LIGHTING);
  51. return S.size();
  52. };