CodeForge QQ客服 CodeForge 400电话 客服电话 4006316121
首页 » 源代码 » opengl喷泉代码 » AirFountain.cpp

AirFountain.cpp ( 文件浏览 )

文件源自:opengl喷泉代码
  • OrangeCHHC 发布于2014-06-10
  • 浏览次数:278
  • 下载次数:7
  • 下载需 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 RandomAngleAddition,
					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
					StepAngle = AngleOfDeepestStep + GetRandomFloat(RandomAngleAddition);
			
				//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
...
...
(完整源码请下载查看)
			
...
展开> <收缩

下载源码到电脑,阅读使用更方便

3 积分

快速下载
还剩0行未阅读,继续阅读
云测速

源码文件列表

温馨提示: 点击源码文件名可预览文件内容哦 ^_^
...
名称 大小 修改日期
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
云测速

AirFountain.cpp (29.68 MB)

需要 3 积分
您持有 积分

CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了 了解更多

您的积分不足

支付宝优惠套餐快速获取 30 积分

订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。

更多付款方式:网银PayPal

上传代码,免费获取

您本次下载所消耗的积分将转交上传作者。

同一源码,30天内重复下载,只扣除一次积分。

登录 CodeForge

还没有CodeForge账号? 立即注册
关注微博
联系客服

Switch to the English version?

Yes
CodeForge 英文版
No
CodeForge 中文版

完善个人资料,获价值¥30元积分奖励!

^_^"呃 ...

Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧
好的