Ejemplo n.º 1
0
/**
 * updates position, velocity, and animation time of particles
 *  - rParticleSet.aabb is also updated
 *
 */
inline void CBE_ParticleSet::UpdateParticles( ParticleSetExtraData& rParticleSet, float dt, AABB3& aabb )
{
//	Vector3 vGravityAccel = m_pStage->GetGravityAccel();
//	float fGravityInfluenceFactor = m_fGravityInfluenceFactor;
	Vector3 vGravityAccel = m_pStage->GetGravityAccel() * m_fGravityInfluenceFactor;

//	AABB3 aabb;
	aabb.Nullify();

	int i, num_particles = rParticleSet.iNumParticles;
	for(i=0; i<num_particles; i++)
	{
		// update velocity
//		rParticleSet.pavVelocity[i] += (vGravityAccel * fGravityInfluenceFactor) * dt;
		rParticleSet.pavVelocity[i] += vGravityAccel * dt;

		// update position
		rParticleSet.pavPosition[i] += rParticleSet.pavVelocity[i] * dt;

		// update animation time
		rParticleSet.pafAnimationTime[i] += dt;

		aabb.AddPoint( rParticleSet.pavPosition[i] );
	}

	const float r = m_fParticleRadius;
	aabb.vMin -= Vector3(r,r,r);
	aabb.vMax += Vector3(r,r,r);

	rParticleSet.aabb = aabb;
}
Ejemplo n.º 2
0
inline void IndexedPolygon::UpdateAABB()
{
	m_AABB.Nullify();

	const size_t num_vertices = m_index.size();
	for( size_t i=0; i<num_vertices; i++ )
	{
		m_AABB.AddPoint( GetVertex(i).m_vPosition );
	}
}
Ejemplo n.º 3
0
	ParticleSetExtraData()
		:
	iNumParticles(0),
	pavPosition(nullptr),
	pavVelocity(nullptr),
	pavOrigDirection(nullptr),
	pafAnimationTime(nullptr),
	pafAnimDuration(nullptr),
	pasPattern(nullptr),
	pafFadeVel(nullptr)
	{
		aabb.Nullify();
	}
Ejemplo n.º 4
0
	// clip trace at the point of contact
void CTriangleMesh::ClipLineSegment( CJL_LineSegment& segment )
{
	Vector3 vStart = segment.vStart;
	Vector3 vEnd;
	if( segment.fFraction == 1.0f )
		vEnd = segment.vGoal;
	else
		vEnd = segment.vEnd;	// the line segment has been already clipped - set the current end point

	static vector<int> s_veciTriList;
	s_veciTriList.resize( 0 );

	AABB3 aabb;
	aabb.Nullify();
	aabb.AddPoint( vStart );
	aabb.AddPoint( vEnd );

	GetIntersectingTriangles( s_veciTriList, aabb );

	size_t i, iNumTris = s_veciTriList.size();

	if( iNumTris == 0 )
		return;	// no intersection

	Vector3 vOrigLineSegment = vEnd - vStart;

	for( i=0; i<iNumTris; i++ )
	{
		IndexedTriangle& tri = GetTriangle( s_veciTriList[i] );
		Triangle triangle( GetVertex( tri.GetIndex(0) ),
			                GetVertex( tri.GetIndex(1) ),
							GetVertex( tri.GetIndex(2) ),
							tri.m_vNormal );

		// check intersection between ray and triangle
		if( triangle.RayIntersect( vStart, vEnd ) )
		{	// found intersection
			// 'vEnd' now represents the intersection point

			// save contact surface
			segment.plane = triangle.GetPlane();

			// record surface material to 'tr'
			segment.iMaterialIndex = tri.m_iMaterialID;
		}
	}

	segment.fFraction *= Vec3Dot( vEnd - vStart, vOrigLineSegment ) / Vec3LengthSq( vOrigLineSegment );
	segment.vEnd = vEnd;
}
Ejemplo n.º 5
0
void CBSPMapData::SetLightsFromLightSourceFaces()
{
	vector<CMapFace> vecTempLightSourceFace;	// temporary buffer to hold light source faces
	size_t i,j;
	size_t iNumInteriorFaces = m_aInteriorFace.size();

	for(i=0; i<iNumInteriorFaces; i++)
	{	// set all the flags of light source faces to false
		m_aInteriorFace[i].m_bFlag = false;
	}

	// cluster light source faces	
	for(i=0; i<iNumInteriorFaces; i++)
	{
		vecTempLightSourceFace.clear();
		CMapFace& rFace1 = m_aInteriorFace[i];

		if( !rFace1.ReadTypeFlag(CMapFace::TYPE_LIGHTSOURCE) )
			continue;	// doesn't emit light by itself

		if( rFace1.m_bFlag == true )
			continue;	// already registered as a light source face

		rFace1.m_bFlag = true;
		vecTempLightSourceFace.push_back( rFace1 );

		// adjacent light source faces are converted into one point light
		SearchAdjacentLightSourceFaces_r( &vecTempLightSourceFace, rFace1, &m_aInteriorFace );

		// convert each cluster of light source faces into a point light
		AABB3 aabb;
		aabb.Nullify();
		for(j=0; j<vecTempLightSourceFace.size(); j++)
			vecTempLightSourceFace[j].AddToAABB( aabb );

		SPointLightDesc light = FindPointLightDesc( rFace1.m_acSurfaceName );
		CPointLight* pPointLight = new CPointLight;
		pPointLight->vPosition = aabb.GetCenterPosition();
		pPointLight->Color.fRed   = light.fRed;
		pPointLight->Color.fGreen = light.fGreen;
		pPointLight->Color.fBlue  = light.fBlue;
		pPointLight->fIntensity   = light.fIntensity;
		pPointLight->fAttenuation0 = light.fAttenuation[0];
		pPointLight->fAttenuation1 = light.fAttenuation[1];
		pPointLight->fAttenuation2 = light.fAttenuation[2];
		m_vecpLight.push_back( pPointLight );
	}
}
Ejemplo n.º 6
0
	void Init( int flag, int num_particles )
	{
		Release();

		iNumParticles = 0;
		aabb.Nullify();

		if( flag & ParticleSetFlag::POSITION )      pavPosition      = new Vector3 [num_particles];
		if( flag & ParticleSetFlag::VELOCITY )      pavVelocity      = new Vector3 [num_particles];
		if( flag & ParticleSetFlag::ORIG_DIR )      pavOrigDirection = new Vector3 [num_particles];
		if( flag & ParticleSetFlag::ANIM_TIME )     pafAnimationTime = new float   [num_particles];
		if( flag & ParticleSetFlag::ANIM_DURATION ) pafAnimDuration  = new float   [num_particles];
		if( flag & ParticleSetFlag::PATTERN )       pasPattern       = new short   [num_particles];
		if( flag & ParticleSetFlag::FADE_VEL )      pafFadeVel       = new float   [num_particles];
//		if( flag & ParticleSetFlag::LOCAL_POSITION )pavLocalPosition = new Vector3 [num_particles];
	}
Ejemplo n.º 7
0
void CBE_NozzleExhaust::UpdateNozzleExhaust( CCopyEntity* pCopyEnt, SBE_ParticleSetExtraData& rParticleSet, float dt )
{
	int i, num_particles = m_MaxNumParticlesPerSet;

//	float dt = fFrameTime;
	AABB3 aabb;
	aabb.Nullify();
//	UpdateParticles( rParticleSet, fFrameTime, aabb );
	float radius = m_fParticleRadius;
	for(i=0; i<num_particles; i++)
	{
		// update animation time
		rParticleSet.pafAnimationTime[i] += dt;

		if( rParticleSet.pafAnimationTime[i] < 0 )
			continue;

		// update velocity
//		rParticleSet.pavVelocity[i] += vGravityAccel * dt;

		// update position
		rParticleSet.pavPosition[i] += rParticleSet.pavVelocity[i] * dt;

		aabb.AddSphere( Sphere(rParticleSet.pavPosition[i],radius) );
	}

	pCopyEnt->world_aabb.MergeAABB( aabb );

	Vector3	vBasePos = Vector3(0,0,0);//pCopyEnt->Position();// + pCopyEnt->GetDirection() * pCopyEnt->f1;
	Vector3 vDir	= Vector3(0,0,1);//pCopyEnt->GetDirection();
	Vector3 vRight	= Vector3(1,0,0);//pCopyEnt->GetRightDirection();
	Vector3	vUp		= Vector3(0,1,0);//pCopyEnt->GetUpDirection();
	float cycle_time = m_fDuration;
	for( i=0; i<num_particles; i++ )
	{
		if( cycle_time <= rParticleSet.pafAnimationTime[i] )
		{
			// set new position & velocity

			CreateNewParticle( pCopyEnt, rParticleSet, i );
//			rParticleSet.pafAnimationTime[i] = 0;
		}
	}
}
Ejemplo n.º 8
0
inline AABB3 GetAABB( const std::vector<IndexedPolygon>& polygon_buffer )
{
	AABB3 aabb;
	aabb.Nullify();

	size_t i, num_pols = polygon_buffer.size();
	size_t j, num_verts;
	for( i=0; i<num_pols; i++ )
	{
		// polygon_buffer[i].Update();
		// aabb.MergeAABB( polygon_buffer[i].GetAABB() );

		num_verts = polygon_buffer[i].m_index.size();
		for( j=0; j<num_verts; j++ )
		{
			aabb.AddPoint( polygon_buffer[i].GetVertex((int)j).m_vPosition );
		}
	}

	return aabb;
}
Ejemplo n.º 9
0
/**
 * updates position, velocity, and animation time of particles
 *  - rParticleSet.aabb is also updated
 *
 */
inline void CBE_ParticleSet::UpdateParticlePositions( ParticleSetExtraData& rParticleSet, float dt, AABB3& aabb )
{
//	AABB3 aabb;
	aabb.Nullify();

	int i, num_particles = rParticleSet.iNumParticles;
	for(i=0; i<num_particles; i++)
	{
		// update position
		rParticleSet.pavPosition[i] += rParticleSet.pavVelocity[i] * dt;

		// update animation time
		rParticleSet.pafAnimationTime[i] += dt;

		aabb.AddPoint( rParticleSet.pavPosition[i] );
	}

	const float r = m_fParticleRadius;
	aabb.vMin -= Vector3(r,r,r);
	aabb.vMax += Vector3(r,r,r);

	rParticleSet.aabb = aabb;
}