Home » Source Code » OpenGL fountain codes » AirFountain.cpp

## AirFountain.cpp ( File view )

• By OrangeCHHC 2014-06-10
• View(s)：278
• Point(s)： 3
```			#include "AirFountain.h"
#include "stdlib.h"
#include <math.h>

#define RandomFactor 2.0

GLfloat GetRandomFloat(GLfloat range)
{

return (GLfloat)rand() / (GLfloat)RAND_MAX * range * RandomFactor;

}

void CDrop::SetConstantSpeed(SF3dVector NewSpeed)
{

ConstantSpeed = NewSpeed;

}

void CDrop::SetAccFactor (GLfloat NewAccFactor)
{

AccFactor = NewAccFactor;

}

void CDrop::SetTime(GLfloat NewTime)
{

time = NewTime;

}

void CDrop::GetNewPosition(SF3dVector * PositionVertex, float dtime, CPool * pPool, CAirFountain * pAirFountain)
{

SF3dVector Position;
time += dtime*20.0f;

if (time > 0.0f)
{

Position.x = ConstantSpeed.x * time;
Position.y = ConstantSpeed.y * time - AccFactor * time * time;
Position.z = ConstantSpeed.z * time;
PositionVertex->x = Position.x;
PositionVertex->y = Position.y;
PositionVertex->z = Position.z;
if (Position.y < 0.0)
{

/*the drop has fallen into the water. The problem is now, that we cannot
set time to 0.0, because if there are more "DropsPerRay" than "TimeNeeded" (See InitFountain())
several drops would be seen as one. Check it out.
*/
time = time - int(time);
if (time > 0.0) time -= 1.0;

//The drop creates a little wave in the pool:
int OscillatorX = (int)((Position.x+pAirFountain->Position.x)/pPool->GetOscillatorDistance());
int OscillatorZ = (int)((Position.z+pAirFountain->Position.z)/pPool->GetOscillatorDistance());
pPool->AffectOscillator(OscillatorX,
OscillatorZ,
-0.1);  //change this to make the waves stronger/weaker

}

}
else
{

PositionVertex->x = 0.0;
PositionVertex->y = 0.0;
PositionVertex->z = 0.0;

}

}

/********************************************************************/

void CAirFountain::Initialize(GLint Steps, GLint RaysPerStep, GLint DropsPerRay,
GLfloat AngleOfDeepestStep,
GLfloat AngleOfHighestStep,
GLfloat AccFactor)
{

//This function needn't be and isn't speed optimized

m_NumDropsComplete = Steps*RaysPerStep*DropsPerRay;

FountainDrops = new CDrop [ m_NumDropsComplete ];
FountainVertices = new SF3dVector [ m_NumDropsComplete ];
SF3dVector NewSpeed;
GLfloat DropAccFactor; //different from AccFactor because of the random change
GLfloat TimeNeeded;
GLfloat StepAngle; //Angle, which the ray gets out of the fountain with
GLfloat RayAngle;	//Angle you see when you look down on the fountain
GLint i,j,k;
for (k = 0; k <Steps; k++)
{

for (j = 0; j < RaysPerStep; j++)
{

for (i = 0; i < DropsPerRay; i++)
{

DropAccFactor = AccFactor + GetRandomFloat(0.005);
if (Steps > 1)
StepAngle = AngleOfDeepestStep + (AngleOfHighestStep-AngleOfDeepestStep)
* GLfloat(k) / (Steps-1) + GetRandomFloat(RandomAngleAddition);
else

//This is the speed caused by the step:
NewSpeed.x = cos ( StepAngle * PI / 180.0) * (0.2+0.04*k);
NewSpeed.y = sin ( StepAngle * PI / 180.0) * (0.2+0.04*k);
//This is the speed caused by the ray:

RayAngle = (GLfloat)j / (GL
...
...
```
...
Expand＞ ＜Close

Point(s): 3

0 lines left, continue to read

## File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
AirFountain.cpp4.71 kB08-05-03|10:55
AirFountain.h1.11 kB08-05-03|10:21
Because0.00 B27871648|71%
camera.cpp1.88 kB07-05-03|09:41
camera.h1.24 kB09-06-14|19:54
AirFountain.obj11.87 kB18-11-13|21:50
AirFountain.sbr0.00 B18-11-13|21:50
camera.obj25.64 kB18-11-13|21:50
camera.sbr0.00 B18-11-13|21:50
Desktop_.ini8.00 B06-02-07|09:21
FountainWater.bsc4.75 MB10-06-14|01:01
FountainWater.exe348.09 kB10-06-14|01:00
FountainWater.ilk721.05 kB10-06-14|01:00
FountainWater.pch4.50 MB09-06-14|20:48
FountainWater.pdb1.00 MB10-06-14|01:00
main.obj40.61 kB10-06-14|01:00
main.sbr0.00 B10-06-14|01:01
pool.obj32.55 kB09-06-14|20:46
pool.sbr0.00 B09-06-14|20:46
textures.obj13.02 kB18-11-13|21:50
textures.sbr0.00 B18-11-13|21:50
vc60.idb321.00 kB10-06-14|12:25
vc60.pdb148.00 kB10-06-14|01:00
vectors.obj8.91 kB18-11-13|21:50
vectors.sbr0.00 B18-11-13|21:50
Desktop_.ini8.00 B06-02-07|09:21
FountainWater.dsp4.67 kB04-06-09|08:44
FountainWater.dsw549.00 B07-05-03|00:28
FountainWater.exe84.00 kB08-05-03|10:57
FountainWater.htm2.63 kB06-02-07|12:24
FountainWater.ncb177.00 kB10-06-14|12:26
FountainWater.opt151.50 kB10-06-14|12:26
FountainWater.plg1.54 kB10-06-14|01:01
GLglut.h20.39 kB11-11-13|09:22
glut.dll166.00 kB18-08-98|16:25
glut.h20.94 kB18-08-98|16:24
glut.lib77.79 kB18-08-98|16:25
glut32.dll166.00 kB18-08-98|16:25
glut32.lib78.03 kB18-08-98|16:25
ground.bmp192.05 kB07-05-03|10:59
main.cpp17.44 kB10-06-14|01:00
pool.cpp7.82 kB09-06-14|20:46
pool.h855.00 B09-06-14|19:54
rock.bmp192.05 kB08-05-03|11:00
sky.bmp468.80 kB28-06-13|22:51
textures.cpp921.00 B07-05-03|10:55
textures.h257.00 B16-06-00|16:31
vectors.cpp1.61 kB23-02-03|14:06
Vectors.h904.00 B09-06-14|19:54
water.bmp192.05 kB07-05-03|10:49
Debug0.00 B10-06-14|01:00
OpenGL喷泉0.00 B10-06-14|12:26
...
• Sent successfully!
• OpenGL喷泉.rar
• 3 point

### AirFountain.cpp (29.68 MB)

Need 3 point

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

Don't have an account？ Register now
Need any help?
Mail to: support@codeforge.com

### 切换到中文版？

CodeForge Chinese Version
CodeForge English Version

### ^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!

### Warm tip!

Favorite by Ctrl+D