OpenGL: 画3条函数曲线

感谢大家支持,超级玛丽的下载次数超过9000了!我最近码OpenGL,这是一个例子。画了三个等价无穷小曲线。主要代码如下:

#include "math01.h"

#define XSTEP (3.14/40)
#define XPOINT 0.02
#define POINTNUM 30

 

void DrawRect(GLfloat x, GLfloat y,GLfloat w, GLfloat h)
{
  glRectf(x,y,x+w,y+h); 
}


void CALLBACK display(void)
{
 int i;

 glColor3f(0.0,0.3,0.0);
 DrawRect(-0.5,-0.5,1.0,1.0);

 // 两条坐标
 glColor3f(0.0,1.0,0.0);
 for(i=0;i0;n--)
 {
  k*=n;
 }
 return k;

}

//e的x次方 麦克劳林级数,没有余项
float E_Exp(float x)
{
 int i;
 float sum=0;

 for(i=0;i<20;i++)
 {
  sum+=Mul(x,i)/Jie(i);
 }
 return sum;

}

#endif

 

//////////////////////////////////////////////////////////////////////////////////

//MFC版 CxxxxxDlg::OnPaint

 

  CPaintDC mydc(this); // device context for painting
  CPen pen1(PS_SOLID, 1, RGB(0,180,50));
  CPen pen2(PS_SOLID, 2, RGB(0,180,50));
  int i;
  float temp;

  mydc.MoveTo(0,350);
  mydc.LineTo(400,350);

  mydc.MoveTo(50,0);
  mydc.LineTo(50,400);
  
  // x取值范围 0, pi/2
  mydc.MoveTo(50,350);
  for(i=0;i<20;i++)
  {
   temp=i*3.14/40;
   mydc.LineTo(50+temp*XSCALE,350-sin(temp)*XSCALE);
  }
  
  mydc.MoveTo(50,350);
  for(i=0;i<20;i++)
  {
   temp=i*3.14/40;
   mydc.LineTo(50+temp*XSCALE,350-temp*XSCALE);
  }

  mydc.MoveTo(50,350);
  for(i=0;i<20;i++)
  {
   temp=i*3.14/40;
   mydc.LineTo(50+temp*XSCALE,350-(E_Exp(temp)-1)*XSCALE);
  }

  mydc.SelectObject(&pen1);
  // 1-cos x
  mydc.MoveTo(50,350);
  for(i=0;i<20;i++)
  {
   temp=i*3.14/40;
   mydc.LineTo(50+temp*XSCALE,350-(1-cos(temp))*XSCALE);
  }

  // squar(x)/2
  mydc.SelectObject(&pen2);
  mydc.MoveTo(50,350);
  for(i=0;i<20;i++)
  {
   temp=i*3.14/40;
   mydc.LineTo(50+temp*XSCALE,350-(temp*temp/2)*XSCALE);
  }
  
  CDialog::OnPaint();


http://blog.csdn.net/programking/article/details/3839866

你可能感兴趣的:(OpenGL)