📄 stars.cpp
字号:
// Stars.cpp: implementation of the CStars class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MyGame.h"
#include "Stars.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CStars::~CStars()
{
}
CStars::CStars(int starn)
{
cc=0;
S.resize(starn);
C.resize(starn+10);
for(int i=0;i<starn;++i)
{
S[i].v[0]=(drand48()-.5);
S[i].v[1]=(drand48()-.5);
S[i].v[2]=0;
}
float basecolor;
for(i=0;i<starn+10;++i)
{
if(i%10) basecolor=drand48();
C[i].v[0]=C[i].v[1]=C[i].v[2]=basecolor+sin((i%10)*M_PI/10.0);
}
}
int CStars::Draw()
{
glDisable(GL_LIGHTING);
glColor3f(1.0,1.0,1.0);
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_COLOR_ARRAY);
glVertexPointer(3,GL_FLOAT,0,S.begin());
glColorPointer(3,GL_FLOAT,0,&(C[cc]));
glDrawArrays(GL_POINTS,0,S.size());
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_COLOR_ARRAY);
glEnable(GL_LIGHTING);
return S.size();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -