資源簡介
這是一個在VC6上實現的一個粒子系統,該系統用粒子模擬瀑布水流,系統產生很多粒子,粒子自由下落,打在地面的平面上又濺起再下落。每個粒子都有初速度和運動方向,粒子是用OpenGL的小球模擬的,粒子運動是用OpenGL的回調函數glutIdleFunc(animation)的animation()函數實現的。
代碼片段和文件信息
/*
模擬瀑布的粒子系統
*/
#include?
#include?
#include?
#include?
//?variables?to?keep?track?of?the?current?rotation?on?each?axis
GLfloat?camPitch?=?0.0?camYaw?=?1.0?camRadius?=?12.0;
int?mxmy;?//?used?to?calculate?mouse?displacement
int?mdown;?//?is?a?button?down?
int?buttonDown;?//?if?so?which?button?
char?*outfile?=?“windowDump.raw“;
typedef?GLfloat?point3[3];
GLfloat?t=0.0;????????//?parameter?for?the?family?of?functions
#define?HOWMANY?1000000
#define?ToUpdate?100
int?WIDTH?=?500;
int?HEIGHT?=?500;
static??GLubyte?bufImage[500][500][3];
float?particles[HOWMANY][7];
GLfloat?white[]?=?{1.0?1.0?1.0?1.0};
GLfloat?yellow[]=?{1.0?1.0?0.0?1.0};
GLfloat?mat_shininess[]={?30.0?};
//?function?prototypes?follow
GLfloat?XX(?int?);
GLfloat?ZZ(?int?);
void?myinit(?void?);
float?tweak(float);
void?particlesInit(int);
void?update(int);
void?drawParticle(int);
void?waterfall(void);
//void?surface(?void?);
void?display(?void?);
void?reshape(?int?int?);
void?keyboard(unsigned?char?int?int?);
void?animate(?void?);
void?saveWindow(char?*?int?int);
//?initialize?OpenGL?and?all?necessary?global?variables
void?myinit(void)
{
????????int?i;
GLfloat?light_pos0[]={??0.0?10.0?10.0??1.0?};?//?first?light?over?z-axis
????????GLfloat?light_col0[]={??1.0??0.0??0.0??1.0?};?//?and?red
????????GLfloat?amb_color0[]={??0.3??0.0??0.0??1.0?};?//?even?ambiently
????????
????????GLfloat?light_pos1[]={??5.0?10.0?-7.26?1.0?};?//?second?light?back/right
????????GLfloat?light_col1[]={??0.0??1.0??0.0??1.0?};?//?and?green
????????GLfloat?amb_color1[]={??0.0??0.3??0.0??1.0?};?//?even?ambiently
????????
????????GLfloat?light_pos2[]={?-5.0?10.0?-7.26?1.0?};?//?third?light?back/left
????????GLfloat?light_col2[]={??0.0??0.0??1.0??1.0?};?//?and?blue
????????GLfloat?amb_color2[]={??0.0??0.0??0.3??1.0?};?//?even?ambiently
????????
//??????set?up?overall?light?data
????????GLfloat?mat_specular[]??={?0.8?0.8?0.8?1.0?};
????????glClearColor(?0.0?0.0?1.0?0.0?);
????????glShadeModel(GL_SMOOTH);?//?use?gourand?shading
????????glMaterialfv(GL_FRONT_AND_BACK?GL_SPECULAR?mat_specular?);
????????
????????glLightfv(GL_LIGHT0?GL_POSITION?light_pos0?);?//?light?0
????????glLightfv(GL_LIGHT0?GL_AMBIENT?amb_color0?);
????????glLightfv(GL_LIGHT0?GL_SPECULAR?light_col0?);
????????glLightfv(GL_LIGHT0?GL_DIFFUSE?light_col0?);
????????
????????glLightfv(GL_LIGHT1?GL_POSITION?light_pos1?);?//?light?1
????????glLightfv(GL_LIGHT1?GL_AMBIENT?amb_color1?);
????????glLightfv(GL_LIGHT1?GL_SPECULAR?light_col1?);
????????glLightfv(GL_LIGHT1?GL_DIFFUSE?light_col1?);
????????
????????glLightfv(GL_LIGHT2?GL_POSITION?light_pos2?);?//?light?2
????????glLightfv(GL_LIGHT2?GL_AMBIENT?amb_color2?);
????????glLightfv(GL_LIGHT2?GL_SPECULAR?light_col2?);
????????glLightfv(GL_LIGHT2?GL_DIFFUSE?light_col2?);
????????
????????glLig
- 上一篇:進程調度的設計與實現圖形界面實現源代碼
- 下一篇:點云數據濾波------數學形態學
評論
共有 條評論