Пример #1
0
void YmxExplodeParticleSystem::_ResetParticle(YmxParticle* p)
{
	p->x = m_Center.x;
	p->y = m_Center.y;
	if(m_RGBVariant == 0)
	{
		p->color = m_StartColor;
	}else {
		p->alpha = RESTRICT_RGB(m_StartColorA + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->red   = RESTRICT_RGB(m_StartColorR + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->green = RESTRICT_RGB(m_StartColorG + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->blue  = RESTRICT_RGB(m_StartColorB + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
	}

	float theta = GetRandomFloat(m_StartAngle, m_EndAngle);
	float velocity = m_Velocity + GetRandomFloat(-m_VelocityVariant, m_VelocityVariant);

	float cosValue = CosFastByAngle(theta);
	float sinValue = SinFastByAngle(theta);

	p->velocity.x = velocity * cosValue * m_Delta;
	p->velocity.y = velocity * sinValue * m_Delta;

	p->acceleration.x = (m_Acceleration * cosValue + m_FieldAcceleration.x) * m_Delta;
	p->acceleration.y = (m_Acceleration * sinValue + m_FieldAcceleration.y) * m_Delta;

	p->life = m_ParLife + GetRandomFloat(-m_ParLifeVariant, m_ParLifeVariant);
}
Пример #2
0
void InitPlayerParticle(Particle *p)
{
    *p = (Particle){player.pEmitter.source.position, Vector2Zero(), GetRandomFloat(player.pEmitter.source.minRotation, player.pEmitter.source.maxRotation), 
    GetRandomFloat(player.pEmitter.source.minScale, player.pEmitter.source.maxScale), player.pEmitter.source.aColor, GetRandomFloat(player.pEmitter.source.minDuration, player.pEmitter.source.maxDuration), 0, TRUE};
    
    p->velocity = Vector2Product(GetRandomVector2(player.pEmitter.source.minSpeed, player.pEmitter.source.maxSpeed), player.pEmitter.source.direction);
}
Пример #3
0
void YmxExplodeParticleSystem::_ResetParticle(int index)
{
	m_ParVertexs[index].x = m_Center.x;
	m_ParVertexs[index].y = m_Center.y;
	m_ParVertexs[index].z = m_z;
	m_ParVertexs[index].size = m_StartSize + GetRandomFloat(-m_SizeVariant, m_SizeVariant);
	if(m_RGBVariant == 0)
	{
		m_ParVertexs[index].color = m_StartColor;
	}else {
		m_ParVertexs[index].alpha = RESTRICT_RGB(m_StartColorA + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		m_ParVertexs[index].red   = RESTRICT_RGB(m_StartColorR + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		m_ParVertexs[index].green = RESTRICT_RGB(m_StartColorG + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		m_ParVertexs[index].blue  = RESTRICT_RGB(m_StartColorB + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
	}

	float theta = GetRandomFloat(m_StartAngle, m_EndAngle);
	float velocity = m_Velocity + GetRandomFloat(-m_VelocityVariant, m_VelocityVariant);

	float cosValue = CosFastByAngle(theta);
	float sinValue = SinFastByAngle(theta);

	m_ParAttributes[index].velocity.x = velocity * cosValue * m_Delta;
	m_ParAttributes[index].velocity.y = velocity * sinValue * m_Delta;

	m_ParAttributes[index].acceleration.x = (m_Acceleration * cosValue + m_FieldAcceleration.x) * m_Delta;
	m_ParAttributes[index].acceleration.y = (m_Acceleration * sinValue + m_FieldAcceleration.y) * m_Delta;

	m_ParAttributes[index].life = m_ParLife + GetRandomFloat(-m_ParLifeVariant, m_ParLifeVariant);
}
Пример #4
0
/*
1. 将粒子复活并将其置入粒子源处
2. 获取任意方向,大小在规定范围内的速度,并将其规范化,以便绘制出球形区域
3. 设置粒子的颜色为随机颜色
4. 设置粒子的生命周期为2s
*/
void FIRE::reset_particle(ATTRIBUTE *attribute)
{
	attribute->_alive  = true;
	attribute->_position = _origin;

	D3DXVECTOR3 min = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	D3DXVECTOR3 max = D3DXVECTOR3( 1.0f,  1.0f,  1.0f);
	//获取任意方向的速度
	GetRandomVector(
		&attribute->_velocity,
		&min,
		&max);

	//将速度规范化才能绘制出球形
	D3DXVec3Normalize(
		&attribute->_velocity,
		&attribute->_velocity);

	attribute->_velocity *= 100.0f;
	//将粒子设置为一个随机的颜色
	attribute->_color = D3DXCOLOR(
		GetRandomFloat(0.0f, 1.0f),
		GetRandomFloat(0.0f, 1.0f),
		GetRandomFloat(0.0f, 1.0f),
		1.0f);

	attribute->_age      = 0.0f;
	attribute->_life_time = 2.0f; // lives for 2 seconds
}
Пример #5
0
void ComParticle::Awake()
{
	m_vecParticles.resize(numParticle);

	for (int i = 0; i < numParticle; ++i)
	{
		Attribute* att = new Attribute();
		att->position.y = 0;
		att->velocity.x = GetRandomFloat(-0.01f, 0.01f);
		att->velocity.z = GetRandomFloat(0.01f, 0.02f);
		att->velocity.y = GetRandomFloat(-0.01f, 0.01f);
		// 불은 처음에 노란색 이후 빨간색
		att->color = 0xFFFFFF99;	// 노란색 R - 255	G - 255		B - 153
		//att->color = 0xFFFF0000;	// 빨간색 R - 255	G - 0		B - 0
		att->age = i * 0.1f;
		m_vecParticles[i] = att;
	}

	pDevice9->CreateVertexBuffer(numParticle * sizeof(Particle),
		D3DUSAGE_POINTS | D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		Particle::FVF, D3DPOOL_DEFAULT, &m_VB, 0);

	texture = Assets::GetTexture(L"Resources/particle/snow.png");

	gameObject->transform->SetPosition(0, 0, -1);
}
Пример #6
0
void YmxCometParticleSystem::_ResetParticle(YmxParticle* p)
{
	p->x = m_Position.x;
	p->y = m_Position.y;

	if(m_RGBVariant == 0)
	{
		p->color = m_StartColor;
	}else {
		p->alpha = RESTRICT_RGB(m_StartColorA + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->red   = RESTRICT_RGB(m_StartColorR + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->green = RESTRICT_RGB(m_StartColorG + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
		p->blue  = RESTRICT_RGB(m_StartColorB + GetRandomInteger(-m_RGBVariant, m_RGBVariant));
	}

	float theta = GetRandomFloat(0.0f, 360.0f);
	float sinMulDelta = SinFastByAngle(theta) * m_Delta;
	float cosMulDelta = CosFastByAngle(theta) * m_Delta;

	float velocity = m_Velocity + GetRandomFloat(-m_VelocityVariant, m_VelocityVariant);
	float acceleration = m_Acceleration + GetRandomFloat(-m_AccelerationVariant, m_AccelerationVariant);
	p->velocity.x = velocity * cosMulDelta;
	p->velocity.y = velocity * sinMulDelta;
	p->acceleration.x = acceleration * cosMulDelta;
	p->acceleration.y = acceleration * sinMulDelta;
	p->size = m_StartSize + GetRandomFloat(-m_SizeVariant, m_SizeVariant);
	p->life = m_ParLife + GetRandomFloat(-m_ParLifeVariant, m_ParLifeVariant);
}
Пример #7
0
void GetRandomVectorInUnitCircle(float *u,float *v)
{	// JLM 9/11/98
	do
	{
		*u = GetRandomFloat(-1.0,1.0);
		*v = GetRandomFloat(-1.0,1.0);
	} while ( (*u)*(*u) +  (*v)*(*v) > 1.0);
}
Пример #8
0
void d3d::GetRandomVector(
	  D3DXVECTOR3* out,
	  D3DXVECTOR3* min,
	  D3DXVECTOR3* max)
{
	out->x = GetRandomFloat(min->x, max->x);
	out->y = GetRandomFloat(min->y, max->y);
	out->z = GetRandomFloat(min->z, max->z);
}
Пример #9
0
// Returns a random unit vector on the unit sphere.
void GetRandomVec(D3DXVECTOR3& out)
{
	out.x = GetRandomFloat(-1.0f, 1.0f);
	out.y = GetRandomFloat(-1.0f, 1.0f);
	out.z = GetRandomFloat(-1.0f, 1.0f);

	// Project onto unit sphere.
	D3DXVec3Normalize(&out, &out);
}
Пример #10
0
void YmxSnowParticleSystem::_ResetParticle(YmxParticle* p, bool bOnBordary)
{
	if(bOnBordary) {
		float k = GetRandomFloat(0.0f, 1.0f);

		if(k < m_AppearRatesOnBordary[LEFT])
		{
			p->x = m_BoundingBox.left;
			p->y = GetRandomFloat(m_BoundingBox.top, m_BoundingBox.bottom);
		}
		else if(k < m_AppearRatesOnBordary[RIGHT])
		{
			p->x = m_BoundingBox.right;
			p->y = GetRandomFloat(m_BoundingBox.top, m_BoundingBox.bottom);
		}
		else if(k < m_AppearRatesOnBordary[BOTTOM])
		{
			p->x = GetRandomFloat(m_BoundingBox.left, m_BoundingBox.right);
			p->y = m_BoundingBox.bottom;
		}
		else {
			p->x = GetRandomFloat(m_BoundingBox.left, m_BoundingBox.right);
			p->y = m_BoundingBox.top;
		}
	}
	else {
		p->x = GetRandomFloat(m_BoundingBox.left, m_BoundingBox.right);
		p->y = GetRandomFloat(m_BoundingBox.top, m_BoundingBox.bottom);
	}
	p->velocity.x = GetRandomFloat(m_MinVelocity.x, m_MaxVelocity.x);
	p->velocity.y = GetRandomFloat(m_MinVelocity.y, m_MaxVelocity.y);
	p->color = _GetRandomColor();
}
Пример #11
0
//本函数没错
//设置粒子属性						P245
//在指定的外界体内创建了具有随机xz坐标的雪花粒子,并将粒子的y坐标设为
//外接体高度值,赋予雪花一定向左下飘的速度
void SNOW::reset_particle(ATTRIBUTE *attribute)
{
	attribute->_alive = true;
	GetRandomVector(&attribute->_position,			//设置雪花飘落的速度大小以及方向
		&_box._min,
		&_box._max);

	attribute->_position.y = _box._max.y;
	attribute->_velocity.x = GetRandomFloat(0.0f,1.0f) * (-3.0f);
	attribute->_velocity.y = GetRandomFloat(0.0f,1.0f) * (-10.0f);
	attribute->_velocity.z = 0.0f;

	attribute->_color = WHITE;						//设定雪花的颜色(实际上雪花的颜色是纹理的颜色)
}
Пример #12
0
void PropsDemo::buildGrassFin(GrassVertex* v, WORD* k, int& indexOffset, 
							  D3DXVECTOR3& worldPos, D3DXVECTOR3& scale)
{
	// Only top vertices have non-zero amplitudes: 
	// The bottom vertices are fixed to the ground.
	float amp = GetRandomFloat(0.5f, 1.0f);
	v[0] = GrassVertex(D3DXVECTOR3(-1.0f,-0.5f, 0.0f), D3DXVECTOR2(0.0f, 1.0f), 0.0f);
	v[1] = GrassVertex(D3DXVECTOR3(-1.0f, 0.5f, 0.0f), D3DXVECTOR2(0.0f, 0.0f), amp);
	v[2] = GrassVertex(D3DXVECTOR3( 1.0f, 0.5f, 0.0f), D3DXVECTOR2(1.0f, 0.0f), amp);
	v[3] = GrassVertex(D3DXVECTOR3( 1.0f,-0.5f, 0.0f), D3DXVECTOR2(1.0f, 1.0f), 0.0f);

	// Set indices of fin.
	k[0] = 0 + indexOffset;
	k[1] = 1 + indexOffset;
	k[2] = 2 + indexOffset;
	k[3] = 0 + indexOffset;
	k[4] = 2 + indexOffset;
	k[5] = 3 + indexOffset;

	// Offset the indices by four to have the indices index into
	// the next four elements of the vertex buffer for the next fin.
	indexOffset += 4;

	// Scale the fins and randomize green color intensity.
	for(int i = 0; i < 4; ++i)
	{
		v[i].pos.x *= scale.x;
		v[i].pos.y *= scale.y;
		v[i].pos.z *= scale.z;

		// Generate random offset color (mostly green).
		v[i].colorOffset = D3DXCOLOR(
			GetRandomFloat(0.0f, 0.1f),
			GetRandomFloat(0.0f, 0.2f),
			GetRandomFloat(0.0f, 0.1f),
			0.0f);
	}

	// Add offset so that the bottom of fin touches the ground
	// when placed on terrain.  Otherwise, the fin's center point
	// will touch the ground and only half of the fin will show.
	float heightOver2 = (v[1].pos.y - v[0].pos.y) / 2;
	worldPos.y += heightOver2;

	// Set world center position for the quad.
	v[0].quadPos = worldPos;
	v[1].quadPos = worldPos;
	v[2].quadPos = worldPos;
	v[3].quadPos = worldPos;
}
Пример #13
0
void DecorationMap::GenVBuffers(int32_t patchId)
{
       
    const TerrainGob* terrain = this->GetParent();        
    ImageData* imgdata = GetMaskData();
    int32_t patchCell = terrain->GetPatchDim() - 1;
    int32_t numPatchX  = (terrain->GetNumCols()-1) / patchCell;
    int32_t numPatchY  = (terrain->GetNumRows()-1) / patchCell;    
    float dimx = (float)imgdata->GetWidth() / numPatchX;
    float dimy = (float)imgdata->GetHeight() / numPatchY;

    Bound2di box;

    int32_t px = patchId % numPatchX;
    int32_t py = patchId / numPatchX;
    box.x1 = (int32_t) (px * dimx);
    box.x2 = box.x1 + (int32_t)dimx;
    box.y1 =  (int32_t) (py * dimy);
    box.y2 = box.y1 + (int32_t)dimy;      
        
    float ycol = (float)imgdata->GetHeight();
    float xcol = (float)imgdata->GetWidth();
    float halfu = 1.0f / ( 2.0f * xcol);
    float halfv = 1.0f / (2.0f * ycol);
        
    auto& list = m_listOfVBList[patchId];
    list.clear();    
    srand(7353 + patchId * m_instId);
    for(int32_t y = box.y1; y < box.y2; y++)
    {            
        float v = y / ycol;
        for(int32_t x = box.x1; x < box.x2; x++)
        {
            float u = x / xcol;
            uint8_t r =  *((uint8_t*)imgdata->PixelAt(x,y));
            if(r > 0)
            {                      
                for(int32_t k = 0; k < m_numOfDecoratorsPerTexel; k++)
                {
                    float nu = GetRandomFloat(u-halfu, u+halfu);
                    float nv = GetRandomFloat(v-halfv,v+halfv);                            
                    float2 posn(nu,nv);                        
                    list.push_back(posn);                          
                }                
            }
        }
    }//// for(int32_t y = box.y1; y < box.y2; y++)
}
Пример #14
0
WorldPoint3D Map3D_c::ReflectPoint(WorldPoint3D fromWPt,WorldPoint3D toWPt,WorldPoint3D wp)
{
	WorldPoint3D movedPoint = TurnLEAlongShoreLine(fromWPt, wp, toWPt);	// use length of fromWPt to beached point or to toWPt?
	/*if (!InVerticalMap(movedPoint)) 
	 {
	 movedPoint.z = fromWPt.z;	// try not changing depth
	 if (!InVerticalMap(movedPoint))
	 movedPoint.p = fromWPt.p;	// use original point
	 }*/
	//movedPoint.z = toWPt.z; // attempt the z move
	// code goes here, check mixedLayerDepth?
	if (!InVerticalMap(movedPoint) || movedPoint.z == 0) // these points are supposed to be below the surface
	{
		double depthAtPt = DepthAtPoint(movedPoint.p);	// code goes here, a check on return value
		if (depthAtPt <= 0) 
		{
			OSErr err = 0;
			return fromWPt;	// code goes here, may want to force the point back into map somehow
		}
		//if (depthAtPt==0)
		//movedPoint.z = .1;
		if (movedPoint.z > depthAtPt) movedPoint.z = GetRandomFloat(.9*depthAtPt,.99*depthAtPt);
		//if (movedPoint.z > depthAtPt) movedPoint.z = GetRandomFloat(.7*depthAtPt,.99*depthAtPt);
		//if (movedPoint.z <= 0) movedPoint.z = GetRandomFloat(.01*depthAtPt,.1*depthAtPt);
		if (movedPoint.z <= 0) 
			//movedPoint.z = GetRandomFloat(.01*depthAtPt,.1*depthAtPt);
			movedPoint.z = 0;	// let points surface or resurface (redispersing is taken care of in TRandom3D)
		//movedPoint.z = fromWPt.z;	// try not changing depth
		//if (!InVerticalMap(movedPoint))
		//movedPoint.p = fromWPt.p;	// use original point - code goes here, need to find a z in the map
	}
	return movedPoint;
}
Пример #15
0
	void initParticle(Particle& out)
	{
		// Time particle is created relative to the global running
		// time of the particle system.
		out.initialTime = mTime;

		// Flare lives for 2-4 seconds.
		out.lifeTime   = GetRandomFloat(2.0f, 4.0f);

		// Initial size in pixels.
		out.initialSize  = GetRandomFloat(10.0f, 15.0f);

		// Give a very small initial velocity to give the flares
		// some randomness.
		GetRandomVec(out.initialVelocity);

		// Scalar value used in vertex shader as an amplitude factor.
		out.mass = GetRandomFloat(1.0f, 2.0f);

		// Start color at 50-100% intensity when born for variation.
		out.initialColor = GetRandomFloat(0.5f, 1.0f)*WHITE;

		// Generate random particle on the ring in polar coordinates:
		// random radius and random angle.
		float r = GetRandomFloat(10.0f, 14.0f);
		float t = GetRandomFloat(0, 2.0f*D3DX_PI);

		// Convert to Cartesian coordinates.
		out.initialPos.x = r*cosf(t);
		out.initialPos.y = r*sinf(t);

		// Random depth value in [-1, 1] (depth of the ring)
		out.initialPos.z = GetRandomFloat(-1.0f, 1.0f);
	}
Пример #16
0
//传入当前需要重新设置的墙体的迭代器与所有坦克所在位置
//主坦克,敌方坦克,第三方坦克,注意:第三方坦克为类的成员
void WALL::reset(list<IMFOR_WALL>::iterator index,PROPERTY *pro,TANK *host)
{
	float x,z;
	int sign = 1;
	list<IMFOR_WALL>::iterator i;
	PROPERTY *p;
	x = GetRandomFloat(_box._min.x + 1000,_box._max.x - 1000);
	z = GetRandomFloat(_box._min.z + 1000,_box._max.z - 1000);
	while(1)
	{
		for(i = _imfor.begin();i != _imfor.end();i++)
		{
			if(i != index)
				if((x - i->_position.x) * (x - i->_position.x) + 
					(z - i->_position.z) * (z - i->_position.z) < _distance * 80)
				{
					x = GetRandomFloat(_box._min.x + 1000,_box._max.x - 1000);
					z = GetRandomFloat(_box._min.z + 1000,_box._max.z - 1000);
					i = _imfor.begin();
				}
		}
		//判断是否与第三方坦克位置重复--------------
		
		//是否与敌方坦克所在位置重复
		for(p = pro;p != pro + 8;p++)
			if((x - p->_position.x) * (x - p->_position.x) + 
				(z - p->_position.z) * (z - p->_position.z) < _distance)
				sign = 0;
		if(sign == 1)		//最后,若主坦克也没有与再生点重复,该点可用
			if((x - host->_position.x) * (x - host->_position.x) + 
				(z - host->_position.z) * (z - host->_position.z) > _distance)
			{
				index->_position = D3DXVECTOR3(x,0,z);		//位置
				index->_life = _life_time;					//声明
				index->_mesh->mesh_release();
				sign = (int)GetRandomFloat(0,20) % _random;	//x文件
				index->_mesh->Init(_x_name[sign],4);
				return ;
			}
		sign = 1;
	}
}
Пример #17
0
/////////////////////////////////////
// Class GameObject
TankEnemy::TankEnemy()
{
	m_type = GameObjectType_TankEnemy;
	m_analizeTime = kEnemyAIAnalizeTime;
	m_analizeTimer = GetRandomFloat( 0.0, m_analizeTime);
	m_lastAnalizeX = 0.0;
	m_lastAnalizeY = 0.0;

	m_health = kEnemyHealth;
	m_speed = kEnemySpeed;


	setColor( ConsoleColor_DarkCyan, ConsoleColor_Cyan );
}
Пример #18
0
void WALL::reset_boss(const D3DXVECTOR3 &position)
{
	_boss._run_time = GetRandomFloat(_life_time / 4,_life_time / 2);
	_boss._target = position;
	_boss._look = _boss._target - _boss._position;
	D3DXVec3Normalize(&_boss._look,&_boss._look);	
	_boss._velocity = _boss._look * _boss._mul;
	float angle;
	angle = D3DXVec3Dot(&D3DXVECTOR3(0,0,1),&_boss._look) / D3DXVec3Length(&_boss._look);
	if(_boss._look.x < 0)
		angle = D3DX_PI - acos(angle);
	else 
		angle = D3DX_PI + acos(angle);
	D3DXMatrixRotationAxis(&_boss._rotation,&D3DXVECTOR3(0,1,0),angle);		//记录旋转角度
}
Пример #19
0
//传入的二级指针为X文件提供了随机选择范围
//外界传入随机数的同时,需要将其对char数组的行数取余
//随机数即存储了数组的维数,同时存储了墙体的数量 / 倍数
WALL::WALL(LPDIRECT3DDEVICE9 device,wchar_t (*x_name)[50],BOUNDINGBOX &box,int ran):
			_random(ran),			//取余是为了避免随机数过大
			_distance(10000),		//与墙体发生撞击的距离的平方
			_life_time(500),			//再生墙体的生命值
			_life_cut(1)			//墙体收到打击时生命值的衰减系数
			,_mul(10)
			,_box(box)
			,_x_name(x_name)
			,_device(device)
			,_life_mul(10)
{
	list<IMFOR_WALL>::iterator index;
	IMFOR_WALL wall;
	int j;
	TANK a(device);
	wall._life = _life_time;				//初始化一个虚拟的wall
	wall._position = D3DXVECTOR3(0,0,0);
	wall._mesh = new MESHXFILE(device);
	j = GetRandomFloat(0,_random);
	wall._mesh->Init(x_name[j],4);
	a._position = D3DXVECTOR3(0,0,0);
	PROPERTY enemy[8];				
	for(int i = 0;i < 8;i++)		//虚拟敌方坦克的信息
		enemy[i]._position = D3DXVECTOR3(0,0,0);
	_imfor.push_back(wall);
	index = _imfor.begin();
	reset(index,enemy,&a);
	for(int i = 0;i < _random * _mul - 1;i++)
	{
		_imfor.push_back(wall);
		index++;
		reset(index,enemy,&a);
	}
	//BOSS坦克的信息
	_boss._target = D3DXVECTOR3(0,0,-1);		//目标
	_boss._position = D3DXVECTOR3(5000,5000,5000);		//位置
	_boss._look = D3DXVECTOR3(0,0,-1);			//观察方向
	D3DXMatrixIdentity(&_boss._rotation);
	_boss._mesh = new MESHXFILE(device);		//x文件
	_boss._mesh->Init(x_name[5],BOSS);			//初始化BOSS的x文件与纹理
	_boss._velocity = _boss._look * 0;
	_boss._run_time = 0;
	_boss._run_cut = 1;
	_boss._alive = false;
	_boss._mul = 10;								
	_boss._life = 0;	//初始化生命值
}
Пример #20
0
	void initParticle(Particle& out)
	{
		// Generate at camera.
		out.initialPos = gCamera->pos();

		// Set down a bit so it looks like player is carrying the gun.
		out.initialPos.y -= 3.0f;

		// Fire in camera's look direction.
		float speed = 500.0f;
		out.initialVelocity = speed*gCamera->look();

		out.initialTime      = mTime;
		out.lifeTime        = 4.0f;
		out.initialColor    = WHITE;
		out.initialSize     = GetRandomFloat(80.0f, 90.0f);
		out.mass            = 1.0f;
	}
// Update frame-based values.
void D3D12ExecuteIndirect::OnUpdate()
{
	for (UINT n = 0; n < TriangleCount; n++)
	{
		const float offsetBounds = 2.5f;

		// Animate the triangles.
		m_constantBufferData[n].offset.x += m_constantBufferData[n].velocity.x;
		if (m_constantBufferData[n].offset.x > offsetBounds)
		{
			m_constantBufferData[n].velocity.x = GetRandomFloat(0.01f, 0.02f);
			m_constantBufferData[n].offset.x = -offsetBounds;
		}
	}

	UINT8* destination = m_pCbvDataBegin + (TriangleCount * m_frameIndex * sizeof(ConstantBufferData));
	memcpy(destination, &m_constantBufferData[0], TriangleCount * sizeof(ConstantBufferData));
}
Пример #22
0
void YmxSnowParticleSystem::_AddParticle(bool bOnBordary)
{
	YmxParticle *p = new YmxParticle;
	_ResetParticle(p, bOnBordary);
	p->next = NULL;

	if(m_bSupportPSize)
	{
		p->size = GetRandomFloat(m_MinSize, m_MaxSize);
		p->next = m_Particles;
		m_Particles = p;
	}
	else {
		int index = GetRandomInteger(0, m_psizeNum - 1);
		p->next = m_ParsGroups[index].particles;
		m_ParsGroups[index].particles = p;
	}
	m_Count++;
}
Пример #23
0
	void initParticle(Particle& out)
	{
		// Generate about the origin.
		out.initialPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

		out.initialTime     = mTime;
		out.lifeTime        = GetRandomFloat(4.0f, 5.0f);
		out.initialColor    = WHITE;
		out.initialSize     = GetRandomFloat(8.0f, 12.0f);
		out.mass            = GetRandomFloat(0.8f, 1.2f);

		out.initialVelocity.x = GetRandomFloat(-2.5f, 2.5f);
		out.initialVelocity.y = GetRandomFloat(15.0f, 25.0f);
		out.initialVelocity.z = GetRandomFloat(-2.5f, 2.5f);
	}
Пример #24
0
void Explosion::initParticle(VertexParticle& out)
{
	// Generate about the origin.
	out.psPosition		= m_v3Position;

	out.initialTime     = m_fTime;
	out.lifeTime        = GetRandomFloat(0.5f, 1.0f);
	out.colour			= m_d3cColour;
	out.initialSize     = GetRandomFloat(32.0f, 50.0f);
	out.mass            = GetRandomFloat(0.8f, 1.2f);

	out.initialVelocity.x = GetRandomFloat(-100.0f, 100.0f);
	out.initialVelocity.y = GetRandomFloat(-100.0f, 100.0f);
	out.initialVelocity.z = GetRandomFloat(-100.0f, 100.0f);
}
Пример #25
0
//更新第三方坦克与墙体位置等消息,注意,需要设置发射子弹
void WALL::update(GUN_CHILD *gun,TANK_ENEMY *pro,TANK *host)
{
	if((_boss._position.x - host->_position.x) * (_boss._position.x - host->_position.x) + 
		(_boss._position.z - host->_position.z) * (_boss._position.z - host->_position.z) < (_distance))
	{
		host->_life = 0;
		return;
	}
	//更新墙壁
	list<IMFOR_WALL>::iterator index;
	for(index = _imfor.begin();index != _imfor.end();index++)
	{
		if(index->_life <= 0)			//若墙壁已经打爆,根据现场所有坦克的位置确认新的墙壁的位置
		{	
			int i;
			i = GetRandomFloat(0,13);
			if(i < 4)
			{	
				if(_boss._alive == false)		//打爆墙壁时,若boss不存在,出现
				{	_boss._alive = true;
					_boss._position = index->_position;
					_boss._life = _life_time * _life_mul;
					_boss._run_time = 0;
				}
			}
			else if(i < 5)
			{	
				if(pro->_mul > 1)			//敌方降低
					pro->_mul -= 1;
			}
			else if(i < 7)				//我方坦克速度增加
				host->_mul += 1;
			else 
				tree_or_explore = !tree_or_explore;
			reset(index,pro->_imfor,host);
		}
	}
	if(_boss._alive == true)
		update_boss(host->_position);
}
Пример #26
0
//初始化粒子
void SnowParticle::ResetParticle(Particle* particle)
{
	particle->age = 0.0f;
	particle->isLive = true;
	particle->lifeTime = GetRandomFloat(2.0f, 10.0f);
	particle->color = D3DCOLOR_RGBA(rand() % 255, rand() % 255, rand() % 255, rand() % 255);
	particle->colorFade = D3DXCOLOR(D3DCOLOR_RGBA(0, 0, 0, 0));
	
	D3DXVECTOR3 minVec(0, 50, 0);
	D3DXVECTOR3 maxVec(50, 70, 50);
	D3DXVECTOR3 pos;
	GetRandomVector(&pos, &minVec, &maxVec);
	particle->position = pos;
	particle->initVelocity = D3DXVECTOR3(GetRandomFloat(0, 1.0f),
		GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(0.0f, 1.0f));

	particle->velocity = D3DXVECTOR3(GetRandomFloat(-1.0f, 1.0f),
		GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(-1.0f, 1.0f));

}
SensorData_t* FrameGenerator::GenerateSensorData(SensorData_t* pData)
{
    if (!pData)
    {
        pData = new SensorData_t;
    }

    pData->gpsData.latitude    = GetRandomFloat();
    pData->gpsData.longitude   = GetRandomFloat();
    pData->gpsData.altitude    = GetRandomFloat() / 200;
    pData->gpsData.groundSpeed = GetRandomFloat() / 100;

    pData->rangeFinderData.rangeBack  = GetRandomFloat() / 100;
    pData->rangeFinderData.rangeFront = GetRandomFloat() / 100;

    return pData;
}
Пример #28
0
void FireBall::initParticle(ParticleEmitter::Particle& out)
{
	// Time particle is created relative to the global running
	// time of the particle system.
	out.initialTime = mTime;
    out.age=mTime;

	// Flare lives for 2-4 seconds.
	// original values //out.lifeTime   = GetRandomFloat(2.0f, 8.0f);
	out.lifeTime   = GetRandomFloat(mMinLifeTime, mMaxLifeTime);

	// Initial size in pixels.
	// original values //out.initialSize  = GetRandomFloat(10.0f, 15.0f);
	out.initialSize  = GetRandomFloat(mMinSize, mMaxSize);

	// Give a very small initial velocity to give the flares
	// some randomness.
	GetRandomVec(out.initialVelocity);
    out.initialVelocity.x *= mAccelImpulse.x;
    out.initialVelocity.y *= mAccelImpulse.y;
    out.initialVelocity.z *= mAccelImpulse.z;
    out.initialVelocity.x += mAccelShift.x;
    out.initialVelocity.y += mAccelShift.y;
    out.initialVelocity.z += mAccelShift.z;

	// Scalar value used in vertex shader as an amplitude factor.
	out.mass = GetRandomFloat(1.0f, 2.0f);

	// Start color at 50-100% intensity when born for variation.
	out.initialColor = static_cast<DWORD>(GetRandomFloat(0.5f, 1.0f) *    1.0f);//white;

	V3 temp = mParticleRadius - mInitPos;
    float length = temp.Length();
    V3 tempNormal = temp.Normalize();
	
	//D3DXMATRIX outmtx;
	noMat3 outmtx;
	//D3DXMatrixRotationYawPitchRoll(&outmtx,GetRandomFloat(0.0f,2.0f)*noMath::PI,GetRandomFloat(0.0f,2.0f)*noMath::PI,0.0f);
	noAngles angle(RAD2DEG(GetRandomFloat(0.0f,2.0f)*noMath::PI), RAD2DEG(GetRandomFloat(0.0f,2.0f)*noMath::PI), 0.0f);
	outmtx = angle.ToMat3();
	
	//D3DXVec3TransformCoord(&temp,&temp,&outmtx);	
	temp = outmtx * temp;	
	out.initialPos = mInitPos + (temp * length);
}
Пример #29
0
Vector2 GetRandomVector2(Vector2 a, Vector2 b)
{
    return (Vector2){GetRandomFloat(a.x, b.x), GetRandomFloat(a.y, b.y)};
}
// Update frame-based values.
void D3D12HeterogeneousMultiadapter::OnUpdate()
{
	// Add the oldest timestamp data to our moving average counters.
	// Use the oldest timestamp index to limit CPU waits.
	{
		// The oldest frame is the current frame index and it will always be complete due to the wait in MoveToNextFrame().
		const UINT oldestFrameIndex = m_frameIndex;
		assert(m_frameFenceValues[oldestFrameIndex] <= m_frameFence->GetCompletedValue());

		// Get the timestamp values from the result buffers.
		D3D12_RANGE readRange = {};
		const D3D12_RANGE emptyRange = {};

		UINT64* ppMovingAverage[] = { m_drawTimes, m_blurTimes };
		for (UINT i = 0; i < GraphicsAdaptersCount; i++)
		{
			readRange.Begin = 2 * oldestFrameIndex * sizeof(UINT64);
			readRange.End = readRange.Begin + 2 * sizeof(UINT64);

			void* pData = nullptr;
			ThrowIfFailed(m_timestampResultBuffers[i]->Map(0, &readRange, &pData));

			const UINT64* pTimestamps = reinterpret_cast<UINT64*>(static_cast<UINT8*>(pData) + readRange.Begin);
			const UINT64 timeStampDelta = pTimestamps[1] - pTimestamps[0];

			// Unmap with an empty range (written range).
			m_timestampResultBuffers[i]->Unmap(0, &emptyRange);

			// Calculate the GPU execution time in microseconds.
			const UINT64 gpuTimeUS =  (timeStampDelta * 1000000) / m_directCommandQueueTimestampFrequencies[i];
			ppMovingAverage[i][m_currentTimesIndex] = gpuTimeUS;
		}

		// Move to the next index.
		m_currentTimesIndex = (m_currentTimesIndex + 1) % MovingAverageFrameCount;
	}

	// Dynamically change the workload on the primary adapter. This is a VERY naive implementation.
	// The point here is to show that applications have a choice with how to spend their extra cycles.
	// Note: If copies take longer then you should take that into account as well.
	{
		static UINT64 framesSinceLastUpdate = 0;
		framesSinceLastUpdate++;
		if (framesSinceLastUpdate > MovingAverageFrameCount)
		{
			// Calculate the average draw and blur times for last few frames.
			m_drawTimeMovingAverage = 0;
			m_blurTimeMovingAverage = 0;
			for (UINT i = 0; i < MovingAverageFrameCount; i++)
			{
				m_drawTimeMovingAverage += m_drawTimes[i];
				m_blurTimeMovingAverage += m_blurTimes[i];
			}

			m_drawTimeMovingAverage /= MovingAverageFrameCount;
			m_blurTimeMovingAverage /= MovingAverageFrameCount;
			framesSinceLastUpdate = 0;

			// Adjust the shader blur time to be at least 20ms/frame.
			// Note: This is just done to show that we can reach ~100% utilization of both adapters.
			if (AllowShaderDynamicWorkload)
			{
				const UINT64 desiredBlurPSTimeUS = 20000;	// 20 ms
				if (m_blurTimeMovingAverage < desiredBlurPSTimeUS || m_blurPSLoopCount != 0)
				{
					// Adjust the PS blur time based on the moving average.
					const float timeDelta = (static_cast<float>(desiredBlurPSTimeUS) - static_cast<float>(m_blurTimeMovingAverage)) / static_cast<float>(m_blurTimeMovingAverage);
					if (timeDelta < -.05f || timeDelta > .01f)
					{
						const float stepSize = max(1.0f, m_blurPSLoopCount);
						m_blurPSLoopCount += static_cast<INT>(stepSize * timeDelta);
					}
				}
			}

			// Adjust the render time to be greater than the blur time.
			{
				const UINT64 desiredDrawPSTimeUS = m_blurTimeMovingAverage + static_cast<UINT64>(m_blurTimeMovingAverage * .10f);
				const float timeDelta = (static_cast<float>(desiredDrawPSTimeUS) - static_cast<float>(m_drawTimeMovingAverage)) / static_cast<float>(m_drawTimeMovingAverage);
				if (timeDelta < -.10f || timeDelta > .01f)
				{
					if (AllowDrawDynamicWorkload)
					{
						// Adjust the number of triangles drawn.
						const float stepSize = max(1.0f, m_triangleCount);
						m_triangleCount = min(m_triangleCount + static_cast<INT>(stepSize * timeDelta), MaxTriangleCount);
					}
					else if (AllowShaderDynamicWorkload)
					{
						// Adjust the number of the PS loop count based on the moving average.
						const float stepSize = max(1.0f, m_psLoopCount);
						m_psLoopCount += static_cast<INT>(stepSize * timeDelta);
					}
				}
			}
		}

		// Conditionally update the window's title.
		if (framesSinceLastUpdate % WindowTextUpdateFrequency == 0)
		{
			UpdateWindowTitle();
		}
	}

	// Update the workloads.
	{
		WorkloadConstantBufferData* pWorkloadDst = m_pWorkloadCbvDataBegin + m_frameIndex;
		WorkloadConstantBufferData* pWorkloadSrc = &m_workloadConstantBufferData;
		pWorkloadSrc->loopCount = m_psLoopCount;
		memcpy(pWorkloadDst, pWorkloadSrc, sizeof(WorkloadConstantBufferData));

		WorkloadConstantBufferData* pBlurWorkloadDst = m_pBlurWorkloadCbvDataBegin + m_frameIndex;
		WorkloadConstantBufferData* pBlurWorkloadSrc = &m_blurWorkloadConstantBufferData;
		pBlurWorkloadSrc->loopCount = m_blurPSLoopCount;
		memcpy(pBlurWorkloadDst, pBlurWorkloadSrc, sizeof(WorkloadConstantBufferData));
	}

	// Update the triangles.
	{
		const float offsetBounds = 2.5f;

		for (UINT n = 0; n < m_triangleCount; n++)
		{
			// Animate the triangles.
			m_constantBufferData[n].offset.x += m_constantBufferData[n].velocity.x;
			if (m_constantBufferData[n].offset.x > offsetBounds)
			{
				m_constantBufferData[n].velocity.x = GetRandomFloat(0.01f, 0.02f);
				m_constantBufferData[n].offset.x = -offsetBounds;
			}
		}

		ConstantBufferData* dst = m_pCbvDataBegin + (m_frameIndex * MaxTriangleCount);
		memcpy(dst, &m_constantBufferData[0], m_triangleCount * sizeof(ConstantBufferData));
	}
}