Exemplo n.º 1
0
void eff_expl_smoke2 () {
	set(me, TRANSLUCENT | ZNEAR | PASSABLE | LIGHT);
	my.roll = random(360);
	my.alpha = 100;
	my.scale_x = 0.2;
	my.scale_y = 0.7;
	my.skill1 = random(3)+2;
	vec_fill(my.blue, 30);
	while(my.alpha > 0) {
		if(my.alpha > 93 ) {
			vec_for_angle(vecEffectsTemp, vector( my.roll,0,0));
			vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt+90, 0));
			vec_normalize(vecEffectsTemp, time_step * (my.alpha/my.skill1) * 0.4);
			vec_add(my.x, vecEffectsTemp);
			my.scale_y += vec_length(vecEffectsTemp)/46;
			my.alpha -= time_step * 3;
			} else {
			vec_for_angle(vecEffectsTemp, vector(my.roll, 0, 0));
			vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt+90, 0));
			vec_normalize(vecEffectsTemp, time_step * (my.alpha/(my.skill1*2)));
			vec_add(my.x, vecEffectsTemp);
			
			my.scale_y += vec_length(vecEffectsTemp) / 5000;
			
			my.alpha -= time_step * 9;
		}
		wait(1);
	}
	ent_remove(me);
	return;
}
Exemplo n.º 2
0
void eff_expl_flash_2() {
	set(me, BRIGHT | TRANSLUCENT | ZNEAR | PASSABLE);
	my.blue = 150;
	my.green = 235;
	my.red = 255;
	my.alpha = 0;
	my.roll = random(360);
	vec_fill(my.scale_x, 3);
	vec_for_angle(vecEffectsTemp, vector( my.roll, 0, 0));
	vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt+90, 0));
	vec_normalize(vecEffectsTemp, 40);
	vec_add(vecEffectsTemp, my.x);
	vec_set(my.x, vecEffectsTemp);
	
	while(my.alpha < 100) {
		if (my.lightrange < 1000 ) my.lightrange += 2000 * time_step;
		my.alpha += time_step * (random(20)+20);
		my.roll += time_step * sign(ang(my.roll));
		vec_normalize ( my.blue, 150 + random(105) );
		wait(1);
	}
	ent_create("explSmoke02.tga", my.x, eff_expl_smoke);
	while(my.alpha > 0) {
		if (my.lightrange > 0) my.lightrange -= 500 * time_step;
		my.alpha -= time_step * 20;
		my.roll += time_step * sign(ang(my.roll))*5;
		wait(1);
	}
	while (my.lightrange > 0) {
		my.lightrange -= 500 * time_step;
		wait(1);
	}
	ent_remove(me);	
}
Exemplo n.º 3
0
void p_eff_expl_particle(PARTICLE *p) {
	p.bmap = bmapExplParticle;
	p.angle = random(360);
	
	vec_for_angle(vecEffectsTemp, vector(p.angle, 0, 0 ));
	vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt-90, 0));
	vec_normalize(vecEffectsTemp, 10+random(50));
	vec_add(p.x, vecEffectsTemp);
	if (random(2) > 1) {
		vec_set(vecEffectsTemp, vector( 1, 0, 0 ));
		vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt+90, 0));
		vec_normalize(vecEffectsTemp, 10+random(5));
		vec_set(p.vel_x, vecEffectsTemp);
	}
	p.vel_z *= random(1);
	p.size = 5 ;
	p.alpha = 50 ;
	p.flags |= TRANSLUCENT | MOVE;
	p.event = p_eff_expl_particle_fade;
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------------------------------------
// View <-> Sphere BUGGY
//-----------------------------------------------------------------------------------------------------------
int sc_physics_intersectViewSphere(VIEW* inView,VECTOR* inPos,var inRadius)
{
	
	VECTOR vcTemp1,vcTemp2,vcTemp3;
	vec_zero(vcTemp1);
	vec_zero(vcTemp2);
	vec_zero(vcTemp3);
	
	var vTemp1=0;
	var vTemp2=0;
	var vTemp3=0;
	
	vec_for_angle(vcTemp1,inView.pan);
	vec_diff(vcTemp2,inPos,inView.x);
	
	vTemp1=vec_dot(vcTemp1,vcTemp2);
	
	vec_set(vcTemp3,inView.x);
	vec_scale(vcTemp1,vTemp1);
	vec_add(vcTemp3,vcTemp1);
	
	vec_diff(vcTemp1,inPos,vcTemp3);
	vTemp2=vec_length(vcTemp1);
	
	vTemp1=tanv(atanv( sqrt(2) * tanv(inView.arc/2) ))*vTemp1;
	
	return (vTemp2-vTemp1>inRadius);
	
	
	/*
	VECTOR viewDir;
	vec_for_angle(viewDir, inView.pan);
	//vec_scale(viewDir, 5);
	return sc_physics_intersectConeSphere (inView.x, viewDir, inView.arc, inPos, inRadius );
	*/
}
Exemplo n.º 5
0
int sc_physics_intersectViewView(VIEW* view1, VIEW* view2)
{
	return 0;
	if(view1 == NULL || view2 == NULL) return 0;
	
	VECTOR vecDir;
	VECTOR pos;
	VECTOR normalX;
	VECTOR normalY;
	VECTOR normalZ;
	VECTOR boxSize;
	VECTOR tempAngle;
	vec_zero(vecDir);
	vec_zero(pos);
	vec_zero(normalX);
	vec_zero(normalY);
	vec_zero(normalZ);
	vec_zero(boxSize);
	vec_zero(tempAngle);
	
	
	//view 1 obb ------------------------------------------------------------------------------------------
	//get view direction
	vec_for_angle(vecDir, view1.pan);
	//set object distance to view
	vec_scale(vecDir, view1.clip_far/2);
	
	//set position
	vec_set(pos, view1.x);
	vec_add(pos, vecDir);
	
	//set normals
	//X
	vec_for_angle(normalX, view1.pan);
	//Y
	vec_set(tempAngle, view1.pan);
	ang_rotate(tempAngle, vector(90,0,0));
	vec_for_angle(normalY, tempAngle);
	//Z
	vec_set(tempAngle, view1.pan);
	ang_rotate(tempAngle, vector(0,90,0));
	vec_for_angle(normalZ, tempAngle);
	
	boxSize.x = view1.clip_far/2; //half-depth
	boxSize.y = tanv(view1.arc/2) * view1.clip_far; //half-width
	boxSize.z = boxSize.y * view1.aspect; //height
	//Hfar = 2 * tan(fov / 2) * farDist
	//Wfar = Hfar * ratio
	
	SC_OBB* obb1 = sc_physics_createOBB( pos, normalX, normalY, normalZ , boxSize );
	
	//-----------------------------------------------------------------------------------------------------

	vec_zero(vecDir);
	vec_zero(pos);
	vec_zero(normalX);
	vec_zero(normalY);
	vec_zero(normalZ);
	vec_zero(boxSize);
	vec_zero(tempAngle);
	
	//view 2 obb ------------------------------------------------------------------------------------------
	//get view direction
	vec_for_angle(vecDir, view2.pan);
	//set object distance to view
	vec_scale(vecDir, view2.clip_far/2);
	
	//set position
	vec_set(pos, view2.x);
	vec_add(pos, vecDir);
	
	//set normals
	//X
	vec_for_angle(normalX, view2.pan);
	//Y
	vec_set(tempAngle, view2.pan);
	ang_rotate(tempAngle, vector(90,0,0));
	vec_for_angle(normalY, tempAngle);
	//Z
	vec_set(tempAngle, view2.pan);
	ang_rotate(tempAngle, vector(0,90,0));
	vec_for_angle(normalZ, tempAngle);
	
	//set size
	boxSize.x = view2.clip_far/2; //half-depth
	boxSize.y = tanv(view2.arc/2) * view2.clip_far; //half-width
	boxSize.z = boxSize.y * view2.aspect; //height
	//Hfar = 2 * tanv(fov / 2) * farDist
	//Wfar = Hfar * ratio
	
	SC_OBB* obb2 = sc_physics_createOBB( pos, normalX, normalY, normalZ , boxSize );
	
	//check if views intersect
	int res = sc_physics_intersectOBBOBB(obb1, obb2);
	//sys_free(obb1);
	//sys_free(obb2);
	ptr_remove(obb1);
	ptr_remove(obb2);
	
	return res;
}
Exemplo n.º 6
0
void sc_light_updateSpotMtx(ENTITY* inLight)
{
	SC_OBJECT* ObjData = (SC_OBJECT*)(inLight.SC_SKILL);
	
	
	float fTexAdj[16] =
	{ 0.5, 0.0, 0.0, 0.0,
		0.0,-0.5,	0.0, 0.0,
		0.0, 0.0, 1.0, 0.0,
	0.0, 0.0, 0.0, 1.0 };
	
	fTexAdj[12] = 0.5 + ((float)0.5/(float)256);
	fTexAdj[13] = 0.5 + ((float)0.5/(float)256);
	
	
	VECTOR lightDir;

	//lightDir = malloc(sizeof(VECTOR));
	if(inLight.tilt > 89.9 && inLight.tilt < 90.1 || inLight.tilt < -89.9 && inLight.tilt > -90.1)
	{
		vec_set(lightDir, inLight.pan);
		lightDir.y += 0.2;
		vec_for_angle(lightDir,lightDir);
	}
	else vec_for_angle(lightDir, inLight.pan);
	
	sc_skill(inLight, SC_OBJECT_LIGHT_DIR, lightDir);
	//if(lightDir.y == -90) lightDir.y = 80; //might have to comment this in again (?)
	
	/*
	//if spotlight has a shadowview attached
	if(ObjData.light.view != NULL)
	{
		D3DXMATRIX matView_, matProj_;
		view_to_matrix(ObjData.light.view, &matView_, &matProj_);
		mat_multiply(&matView_, &matProj_);
		mat_multiply(&matView_, fTexAdj);
		sc_skill(inLight, SC_OBJECT_LIGHT_MATRIX, &matView_);
		
		ptr_remove(matView_);
		ptr_remove(matProj_);
		return;
	}
	*/
	
	
	//create lightViewMatrix
	D3DXVECTOR3 vEyePt;
	D3DXVECTOR3 vLookatPt;
	D3DXVECTOR3 vUpVec;
	//vEyePt = sys_malloc(sizeof(D3DXVECTOR3));
	//vLookatPt = sys_malloc(sizeof(D3DXVECTOR3));
	//vUpVec = sys_malloc(sizeof(D3DXVECTOR3));
	
	vEyePt.x = inLight.x;
	vEyePt.y = inLight.z;
	vEyePt.z = inLight.y;
	vLookatPt.x = inLight.x + lightDir.x;	
	vLookatPt.y = inLight.z + lightDir.z;
	vLookatPt.z = inLight.y + lightDir.y;
	vUpVec.x = 0;
	vUpVec.y = 1;
	vUpVec.z = 0;

	D3DXMATRIX mtxLightView;
	//mtxLightView = sys_malloc(sizeof(D3DXMATRIX));
	D3DXMatrixLookAtLH( &mtxLightView, vEyePt, vLookatPt, vUpVec);
	
	//create lightProjectionMatrix
	D3DXMATRIX mtxLightProj;
	D3DXMatrixPerspectiveFovLH(&mtxLightProj, 	(((float)ObjData.light.arc/(float)180))*SC_PI, (float)1, (float)1, (float)ObjData.light.range );
	
	
	//pass projection matrix to light	
	D3DXMATRIX mtxLightWorldViewProj;
	//mtxLightWorldViewProj = sys_malloc(sizeof(D3DXMATRIX));
	mat_set(&mtxLightWorldViewProj, &mtxLightView);
	mat_multiply(&mtxLightWorldViewProj, &mtxLightProj);
	mat_multiply(&mtxLightWorldViewProj, fTexAdj);
	
	sc_skill(inLight, SC_OBJECT_LIGHT_MATRIX, &mtxLightWorldViewProj);
	
	/*
	//this lags like hell
	sys_free(vEyePt);
	sys_free(vLookatPt);
	sys_free(vUpVec);
	sys_free(mtxLightView);
	sys_free(mtxLightProj);
	sys_free(mtxLightWorldViewProj);
	*/
	
	//better
	ptr_remove(vEyePt);
	ptr_remove(vLookatPt);
	ptr_remove(vUpVec);
	ptr_remove(mtxLightView);
	ptr_remove(mtxLightProj);
	ptr_remove(mtxLightWorldViewProj);
}
Exemplo n.º 7
0
void sc_lights_frmSun(SC_SCREEN* screen)
{
	if(screen.views.sun != NULL)
	{
		if(
		screen.settings.lights.sunPos.x == 0
		&& screen.settings.lights.sunPos.y == 0
		&& screen.settings.lights.sunPos.z == 0
		) //global sun
		{
			VECTOR distantSunPos;
			vec_for_angle(distantSunPos, sun_angle);
			vec_scale(distantSunPos, 9999999);
			screen.materials.sun.skill1 = floatv(distantSunPos.x);
			screen.materials.sun.skill2 = floatv(distantSunPos.y);
			screen.materials.sun.skill3 = floatv(distantSunPos.z);
		}
		else //local sun
		{
			screen.materials.sun.skill1 = floatv(screen.settings.lights.sunPos.x);
			screen.materials.sun.skill2 = floatv(screen.settings.lights.sunPos.y);
			screen.materials.sun.skill3 = floatv(screen.settings.lights.sunPos.z);
		}
		
		screen.materials.sun.skill4 = floatv(0); //local sun lightrange (not used)
		
		//sun color
		screen.materials.sun.skill5 = floatv(sun_color.red/255);
		screen.materials.sun.skill6 = floatv(sun_color.green/255);
		screen.materials.sun.skill7 = floatv(sun_color.blue/255);
		screen.materials.sun.skill8 = floatv(screen.views.main.clip_far);
		
		
		
		
		
		
		#ifndef SC_A7
			// PSSM main loop
			if(screen.settings.lights.sunPssmSplits>0 && screen.settings.lights.sunShadows == 1)
			{
				// update the views _after_ the camera was updated!
				//	proc_mode = PROC_LATE;
				
				// set up the split distances and the shadow view
				sc_lights_pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight, screen.settings.lights.sunShadowRange);
				//pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight);
				//pssm_viewcpy(screen.views.main, screen.views.sun);
				
				// set up the split view transformation matrices
				D3DXMATRIX matSplit[4];
				int i=0;
				for(i=0; i<screen.settings.lights.sunPssmSplits; i++) 
				{
					// look from the sun onto the scene			
					screen.views.sunShadowDepth[i]->pan = 180 + sun_angle.pan;
					screen.views.sunShadowDepth[i]->tilt = -sun_angle.tilt;
					vec_set(screen.views.sunShadowDepth[i]->x,sun_pos);
					
					// calculate the split view clipping borders and transformation matrix			
					view_to_split(screen.views.main, pssm_splitdist[i],pssm_splitdist[i+1], screen.views.sunShadowDepth[i], &matSplit[i]);
					LPD3DXEFFECT fx = screen.views.sunShadowDepth[i]->material->d3deffect;
					if(fx) fx->SetMatrix("matSplitViewProj",&matSplit[i]);
					
					// create a texture matrix from the split view proj matrix			
					D3DXMatrixMultiply(&matSplit[i],&matSplit[i],pssm_texscale(screen.settings.lights.sunShadowResolution));
					
					#ifdef DEBUG_PSSM		
						DEBUG_BMAP(screen.views.sunShadowDepth[i]->bmap,300 + i*220,0.2);
						var pssm_fps = 16/time_frame;
						DEBUG_VAR(pssm_fps,200);
						DEBUG_VAR(pssm_splitdist[i+1],220 + i*20);
					#endif
					//set depthmapshader maxDepth	
					screen.views.sunShadowDepth[i].material.skill4 = floatv(screen.views.sunShadowDepth[i].clip_far);
				}
				
				//put matrices to world space
				//mat_multiply(matSplit[0], matViewInv);
				// use a DX function to copy the 4 texture matrices to the shadow shader
				LPD3DXEFFECT fx = screen.views.sun->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				//same for shadowEdge acceleration
				LPD3DXEFFECT fx = screen.views.sunEdge->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				//and for the actual shadow view
				LPD3DXEFFECT fx = screen.views.sunShadow->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				screen.views.sun.material.skill4 = floatv(screen.views.sunShadowDepth[0].clip_far);
				
				#ifdef DEBUG_PSSM		
					DEBUG_BMAP(screen.views.sun->bmap,20,0.2);
				#endif
			}
		#endif
		
		
	}
}