void HandleSfxForObject(DISPLAYBLOCK *dispPtr)
{
	STRATEGYBLOCK *sbPtr = dispPtr->ObStrategyBlock;

	if (dispPtr->SpecialFXFlags & SFXFLAG_ONFIRE)
	{
		HandleObjectOnFire(dispPtr);
	}

	if (sbPtr)
	{
		if(sbPtr->I_SBtype == I_BehaviourNetCorpse)
		{
			NETCORPSEDATABLOCK *corpseDataPtr = (NETCORPSEDATABLOCK *)sbPtr->SBdataptr;
		
			if(!( (dispPtr->SpecialFXFlags & SFXFLAG_MELTINGINTOGROUND)&&(dispPtr->ObFlags2 < ONE_FIXED) )
				&& corpseDataPtr->This_Death->Electrical && ((FastRandom()&255)==0))	
			{
				VECTORCH velocity;
				velocity.vx = (FastRandom()&2047)-1024;
				velocity.vy = (FastRandom()&2047)-1024;
				velocity.vz = (FastRandom()&2047)-1024;
				MakeParticle(&dispPtr->ObWorld,&velocity,PARTICLE_SPARK);	
				velocity.vx = (FastRandom()&2047)-1024;
				velocity.vy = (FastRandom()&2047)-1024;
				velocity.vz = (FastRandom()&2047)-1024;
				MakeParticle(&dispPtr->ObWorld,&velocity,PARTICLE_SPARK);	
				MakeLightElement(&dispPtr->ObWorld,LIGHTELEMENT_ELECTRICAL_SPARKS);
				
			}
		}
		
	}
}
Example #2
0
void MonteCarlo(collector *C, int NMC, REAL emean, REAL estdv, REAL sigma, REAL angle, REAL azimuth) {
    particle	    *P;
    trace	    *T;
    int		    NF;
    unsigned int seed;
    NF = 0;
#if DEBUG
    printf("entering MonteCarlo for %d samples and storing into %lx (%d)\n",
	   NMC, (long unsigned int) C, C->NTOTAL);
#endif
/* create the trace and particle */
    fast_srand(&seed);
    T = alloc_trace();
    P = (particle *) malloc(sizeof(particle));
/* the Monte Carlo loop */
//what is sigma??
    if (sigma > AS_REAL(0.0)) {
	while (NF++ < NMC) {
	    MakeParticle(P, normal(emean, estdv,&seed), angle+normal(AS_REAL(0.0), sigma,&seed), azimuth+normal(AS_REAL(0.0), sigma,&seed), &seed);
	    reset_trace(T);
	    while (P->energy > AS_REAL(0.0)) {
		proton_event(P, T, &seed); //stepping()
	    }
	    if (TRACE) dump_trace(stdout, T, P);
	    collect(C, P, T); //Hits collection
	}
    } else {
	while (NF++ < NMC) {
	    MakeParticle(P, normal(emean, estdv,&seed), angle, azimuth, &seed);
	    reset_trace(T);
	    while (P->energy > AS_REAL(0.0)) {
		proton_event(P, T, &seed);
	    }
	    if (TRACE) dump_trace(stdout, T, P);
	    collect(C, P, T);
	}
    }
}
Example #3
0
// Each splash adds new particles to the particle emitter.
void SplashEmitter::DoStartingTasks()
{
    int splashes;

    if (m_nextSplashIsSmall) splashes = 6;
    else splashes = 12;

    for (int i = 0; i < splashes; ++i)
    {
        m_nextParticlePos = (m_nextParticlePos + 1) % m_maxParticles;
        MakeParticle(m_nextParticlePos);
    }
    ExtendTimeStampForStop();
}
void CSampleRigidParticlesAndTerrain::InititialisePhysics()
{
	neV3 gravity; gravity.Set(0.0f, -8.0f, 0.0f);

	neSimulatorSizeInfo sizeInfo;

	sizeInfo.rigidParticleCount = NUMBER_OF_PARTICLES;
	sizeInfo.animatedBodiesCount = WALL_NUMBER;
	sizeInfo.geometriesCount = NUMBER_OF_PARTICLES * GEOMETRY_PER_BODY + WALL_NUMBER;

	{ //dont need any of these
		sizeInfo.rigidBodiesCount = 0;
		sizeInfo.constraintsCount = 0;
	}

	s32 totalBody = NUMBER_OF_PARTICLES + WALL_NUMBER;
	sizeInfo.overlappedPairsCount = totalBody * (totalBody - 1) / 2;

	sim = neSimulator::CreateSimulator(sizeInfo, &all, &gravity);

	neV3 position;

	position.SetZero();

	for (s32 j = 0; j < NUMBER_OF_PARTICLES; j++)
	{
		position.Set(0.0f, 2.0f * j + 20.0f, 0.0f);
		//position.Set(13.5f, 20.0f, 1.5f);

		MakeParticle(position, j);	
	}

	//SetUpTerrain

	terrainRender.SetGraphicMesh(L"model\\landscape2.x");
	terrainRender.SetDiffuseColor(D3DXCOLOR(0.1f,0.5f,0.1f,1.0f));

	LPD3DXMESH lpterrainD3Dmesh = terrainRender.mMesh.GetMesh();

	neTriangleMesh triMesh;

	triMesh.vertexCount = lpterrainD3Dmesh->GetNumVertices();

	triMesh.triangleCount = lpterrainD3Dmesh->GetNumFaces();	

	neV3 * verts = new neV3[triMesh.vertexCount];

	//
	DWORD dwFVF			= lpterrainD3Dmesh->GetFVF();
	DWORD dwOptions		= lpterrainD3Dmesh->GetOptions();
	DWORD dwNumFaces	= lpterrainD3Dmesh->GetNumFaces();
	DWORD dwNumVertices = lpterrainD3Dmesh->GetNumVertices();
	DWORD dwBytes		= lpterrainD3Dmesh->GetNumBytesPerVertex();

	LPDIRECT3DVERTEXBUFFER9 pVB;
	lpterrainD3Dmesh->GetVertexBuffer(&pVB);

	byte* pBuffer;
	pVB->Lock(0, 0, (void**)&pBuffer, 0);

	byte* pPointer = pBuffer;

	for (int i = 0;i< triMesh.vertexCount;i++)
	{
		if (dwFVF & D3DFVF_XYZ)
		{
			D3DVECTOR *d3dvector;
			d3dvector = (D3DVECTOR*)pPointer;
			verts[i].Set(d3dvector->x,d3dvector->y,d3dvector->z);
			pPointer += sizeof(D3DVECTOR);
		}
		//if (dwFVF & D3DFVF_NORMAL)
		//{
		//	//don't care the NORMAL data
		//	pPointer += sizeof(D3DVECTOR);
		//}
		//if (dwFVF & D3DFVF_TEX1)
		//{
		//	pPointer += 8;
		//}
		pPointer += dwBytes - sizeof(D3DVECTOR);
		

	}


	pVB->Unlock();
	pVB->Release();

	//

	triMesh.vertices = verts;

	neTriangle * tri = new neTriangle[triMesh.triangleCount];

	s32 * triindex = new s32[triMesh.triangleCount * 3];

	//

	LPDIRECT3DINDEXBUFFER9 pIB;
	lpterrainD3Dmesh->GetIndexBuffer(&pIB);

	D3DINDEXBUFFER_DESC kDesc;
	pIB->GetDesc(&kDesc);

	dwBytes = 0;
	if (kDesc.Format & D3DFMT_INDEX16)
	{
		dwBytes = 2 * sizeof(byte);
	}
	else if (kDesc.Format & D3DFMT_INDEX32)
	{
		dwBytes = 4 * sizeof(byte);
	}

	pIB->Lock(0, 0, (void**)&pBuffer, 0);

	pPointer = pBuffer;
	while ((pPointer - pBuffer) < kDesc.Size)
	{
		if (dwBytes == 2*sizeof(byte))
		{
			//16bit
			triindex[(pPointer-pBuffer)/dwBytes] = *((s16*)pPointer);
		}
		else if (dwBytes == 4*sizeof(byte))
		{
			//32bit
			triindex[(pPointer-pBuffer)/dwBytes] = *((s32*)pPointer);
		}
		pPointer += dwBytes;
	}

	pIB->Unlock();
	pIB->Release();


	

	//

	for (s32 i = 0; i < triMesh.triangleCount; i++)
	{
		tri[i].indices[0] = triindex[i * 3];
		tri[i].indices[1] = triindex[i * 3 + 1];
		tri[i].indices[2] = triindex[i * 3 + 2];
		tri[i].materialID = 0;
		tri[i].flag = neTriangle::NE_TRI_TRIANGLE;
		//tri[i].flag = neTriangle::NE_TRI_HEIGHT_MAP;
	}
	triMesh.triangles = tri;

	sim->SetTerrainMesh(&triMesh);

	//SetUpRoom

	ground = sim->CreateAnimatedBody();

	neGeometry * geom = ground->AddGeometry();	 

	geom->SetBoxSize(gFloor.boxSize);

	ground->UpdateBoundingInfo();

	ground->SetPos(gFloor.pos);

	groundRender.SetGraphicBox(gFloor.boxSize[0], gFloor.boxSize[1], gFloor.boxSize[2]);


}
void HandleObjectOnFire(DISPLAYBLOCK *dispPtr)
{
	int objectIsDisappearing;
	extern int NormalFrameTime;
	int noRequired = 1;
	int i;
	VECTORCH velocity;
	
	if (!dispPtr->ObShape) return;

	if (dispPtr->ObShapeData->shaperadius<=LocalDetailLevels.AlienEnergyViewThreshold) return;

	#if 1
	{
		DYNAMICSBLOCK *dynPtr;
		STRATEGYBLOCK *sbPtr;
		
	   	sbPtr = dispPtr->ObStrategyBlock;
		LOCALASSERT(sbPtr);
		dynPtr = sbPtr->DynPtr;
		LOCALASSERT(sbPtr);

		
		velocity.vx = DIV_FIXED((dynPtr->Position.vx-dynPtr->PrevPosition.vx)*3,NormalFrameTime*4);
		velocity.vy = DIV_FIXED((dynPtr->Position.vy-dynPtr->PrevPosition.vy)*3,NormalFrameTime*4);
		velocity.vz = DIV_FIXED((dynPtr->Position.vz-dynPtr->PrevPosition.vz)*3,NormalFrameTime*4);

		if (dispPtr==sbPtr->SBdptr)	noRequired = 5;

	}
	#else
	velocity.vx = 0;
	velocity.vy = 0;
	velocity.vz = 0;
	#endif
	
	objectIsDisappearing = ( (dispPtr->SpecialFXFlags & SFXFLAG_MELTINGINTOGROUND) &&(dispPtr->ObFlags2 <= ONE_FIXED) )	;

	for (i=0; i<noRequired; i++)
	{
		VECTORCH position;
		position.vx = dispPtr->ObWorld.vx+(FastRandom()&255)-128;
		position.vy = dispPtr->ObWorld.vy+(FastRandom()&255)-128;
		position.vz = dispPtr->ObWorld.vz+(FastRandom()&255)-128;
		#if 0
		MakeParticle(&(position), &velocity, PARTICLE_NONCOLLIDINGFLAME);
		#else
		if (objectIsDisappearing)
		{
			if ((FastRandom()&65535) < dispPtr->ObFlags2)
				MakeParticle(&(position), &velocity, PARTICLE_FIRE);
		}
		else
		{
			MakeParticle(&(position), &velocity, PARTICLE_FIRE);
		}

		if (FastRandom()&65535 > 32768)
		{
			MakeParticle(&(position), &velocity, PARTICLE_IMPACTSMOKE);
		}
		#endif
	}

}