Esempio n. 1
0
File: aprcl.c Progetto: jpflori/pari
/* jac^floor(N/pk) mod (N, polcyclo(pk)), flexible window */
static GEN
_powpolmod(Cache *C, GEN jac, Red *R, GEN (*_sqr)(GEN, Red *))
{
  const GEN taba = C->aall;
  const GEN tabt = C->tall;
  const long efin = lg(taba)-1, lv = R->lv;
  GEN L, res = jac, pol2 = _sqr(res, R);
  long f;
  pari_sp av0 = avma, av;

  L = cgetg(lv+1, t_VEC); gel(L,1) = res;
  for (f=2; f<=lv; f++) gel(L,f) = _mul(gel(L,f-1), pol2, R);
  av = avma;
  for (f = efin; f >= 1; f--)
  {
    GEN t = gel(L, taba[f]);
    long tf = tabt[f];
    res = (f==efin)? t: _mul(t, res, R);
    while (tf--) {
      res = _sqr(res, R);
      if (gc_needed(av,1)) {
        res = gerepilecopy(av, res);
        if(DEBUGMEM>1) pari_warn(warnmem,"powpolmod: f = %ld",f);
      }
    }
  }
  return gerepilecopy(av0, res);
}
u32	 CLevelGraph::check_position_in_direction_slow	(u32 start_vertex_id, const Fvector2 &start_position, const Fvector2 &finish_position) const
{
	if (!valid_vertex_position(v3d(finish_position)))
		return				(u32(-1));

	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1);
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= start_position;
	dest					= finish_position;
	dir.sub					(dest,start);
	u32						dest_xz = vertex_position(v3d(dest)).xz();
	Fvector2				temp;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	for (;;) {
		const_iterator		I,E;
		begin				(cur_vertex_id,I,E);
		bool				found = false;
		for ( ; I != E; ++I) {
			u32				next_vertex_id = value(cur_vertex_id,I);
			if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id))
				continue;
			CVertex			*v = vertex(next_vertex_id);
			unpack_xz		(v,temp.x,temp.y);
			box.min			= box.max = temp;
			box.grow		(identity);
			if (box.pick_exact(start,dir)) {

				if (dest_xz == v->position().xz()) {
					return	(is_accessible(next_vertex_id) ? next_vertex_id : u32(-1));
				}
				Fvector2		temp;
				temp.add		(box.min,box.max);
				temp.mul		(.5f);
				float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
				if (dist > cur_sqr)
					continue;
				
				if (!is_accessible(next_vertex_id))
					return		(u32(-1));

				cur_sqr			= dist;
				found			= true;
				prev_vertex_id	= cur_vertex_id;
				cur_vertex_id	= next_vertex_id;
				break;
			}
		}
		if (!found) {
			return			(u32(-1));
		}
	}
}
void EmbracePowerGenerator::run(const SpectrumDataSetC32* channeliserOutput,
				SpectrumDataSetStokes* stokes)
{
    typedef std::complex<float> Complex;
    unsigned nSamples = channeliserOutput->nTimeBlocks();
    unsigned nSubbands = channeliserOutput->nSubbands();
    unsigned nChannels = channeliserOutput->nChannels();
    Q_ASSERT( channeliserOutput->nPolarisations() >= 2 );

    stokes->setLofarTimestamp(channeliserOutput->getLofarTimestamp());
    stokes->setBlockRate(channeliserOutput->getBlockRate());
    stokes->resize(nSamples, nSubbands, 2, nChannels); // 2 is because
						       // EMBRACE has
						       // 2, single
						       // pol
						       // directions
						       // rather than
						       // polarizations

    const Complex* dataPolX, *dataPolY;
    float *IX, *IY;
    float powerX, powerY;

    const Complex* dataPolDataBlock = channeliserOutput->data();
    for (unsigned t = 0; t < nSamples; ++t) {
        for (unsigned s = 0; s < nSubbands; ++s) {
            unsigned dataPolIndexX = channeliserOutput->index( s, nSubbands, 
                                                               0,2,
                                                               t, nChannels);
            unsigned dataPolIndexY = channeliserOutput->index( s, nSubbands, 
                                                               1,2,
                                                               t, nChannels);
            dataPolX = &dataPolDataBlock[dataPolIndexX];
            dataPolY = &dataPolDataBlock[dataPolIndexY];

            IX = stokes->spectrumData(t, s, 0);
            IY = stokes->spectrumData(t, s, 1);

            for (unsigned c = 0; c < nChannels; ++c) {
                float Xr = dataPolX[c].real();
                float Xi = dataPolX[c].imag();
                float Yr = dataPolY[c].real();
                float Yi = dataPolY[c].imag();

                powerX = _sqr(Xr) + _sqr(Xi);
                powerY = _sqr(Yr) + _sqr(Yi);

                IX[c] = powerX;
                IY[c] = powerY;
            }
        }
    }
}
Esempio n. 4
0
	IC			remove_too_far_predicate	(const CLevelGraph *graph, const Fvector &position, float radius)
	{
		VERIFY			(graph);
		m_graph			= graph;
		m_position		= position;
		m_radius_sqr	= _sqr(radius);
	}
/**
 * @details
 * Not used?
 */
void StokesGenerator::run(const TimeSeriesDataSetC32* streamData,
        SpectrumDataSetStokes* stokes)
{
    typedef std::complex<float> Complex;
    unsigned nSamples = streamData->nTimeBlocks();
    unsigned nSubbands = streamData->nSubbands();
    unsigned nSamps = streamData->nTimesPerBlock();

    stokes->setLofarTimestamp(streamData->getLofarTimestamp());
    stokes->setBlockRate(streamData->getBlockRate());
    stokes->resize(nSamples * nSamps, nSubbands, 4, 1);

    const Complex* dataPolX, *dataPolY;
    float XxYstarReal;
    float XxYstarImag;
    float *I, *Q, *U, *V;
    float powerX, powerY;

    for (unsigned t = 0; t < nSamples; ++t) {
        for(unsigned s = 0; s < nSubbands; ++s) {
            dataPolX = streamData->timeSeriesData(t, s, 0);
            dataPolY = streamData->timeSeriesData(t, s, 1);
            for(unsigned c = 0; c < nSamps; ++c) {
                I = stokes->spectrumData(t * nSamps + c, s, 0);
                Q = stokes->spectrumData(t * nSamps + c, s, 1);
                U = stokes->spectrumData(t * nSamps + c, s, 2);
                V = stokes->spectrumData(t * nSamps + c, s, 3);
                // NOTE: We have one channel per subband since we are not channelising
                float Xr = dataPolX[c].real();
                float Xi = dataPolX[c].imag();
                float Yr = dataPolY[c].real();
                float Yi = dataPolY[c].imag();
                XxYstarReal = Xr*Yr + Xi*Yi;
                XxYstarImag = Xi*Yr - Xr*Yi;

                powerX = _sqr(Xr) + _sqr(Xi);
                powerY = _sqr(Yr) + _sqr(Yi);

                I[c] = powerX + powerY;
                Q[c] = powerX - powerY;
                U[c] = 2.0f * XxYstarReal;
                V[c] = 2.0f * XxYstarImag;

            }
        }
    }
}
int main(){
    DSG::Sample_Rate(44100);
    DSG::FourierSquare _sqr(220.0,0.0);
    
    DriverInit(&_sqr);
    Pa_Sleep(5000);
    DriverExit();
    return 0;
}
Esempio n. 7
0
void CWallmarksEngine::AddStaticWallmark	(CDB::TRI* pTri, const Fvector* pVerts, const Fvector &contact_point, ref_shader hShader, float sz)
{
	// optimization cheat: don't allow wallmarks more than 50 m from viewer/actor
	if (contact_point.distance_to_sqr(Device.vCameraPosition) > _sqr(100.f))	return;

	// Physics may add wallmarks in parallel with rendering
	lock.Enter				();
	AddWallmark_internal	(pTri,pVerts,contact_point,hShader,sz);
	lock.Leave				();
}
Esempio n. 8
0
void CWallmarksEngine::AddSkeletonWallmark	(const Fmatrix* xf, CKinematics* obj, ref_shader& sh, const Fvector& start, const Fvector& dir, float size)
{	
	if( 0==g_r || ::RImplementation.phase != CRender::PHASE_NORMAL)				return;
	// optimization cheat: don't allow wallmarks more than 50 m from viewer/actor
	if (xf->c.distance_to_sqr(Device.vCameraPosition) > _sqr(50.f))				return;

	VERIFY					(obj&&xf&&(size>EPS_L));
	lock.Enter				();
	obj->AddWallmark		(xf,start,dir,sh,size);
	lock.Leave				();
}
Esempio n. 9
0
void CCoverEvaluatorRandomGame::setup		(GameGraph::_GRAPH_ID game_vertex_id, float max_distance)
{
	inherited::setup		();
	
	m_actuality				= m_actuality && (m_game_vertex_id == game_vertex_id);
	m_game_vertex_id		= game_vertex_id;

	m_start_position		= ai().game_graph().vertex(game_vertex_id)->level_point();
	m_max_distance_sqr		= _sqr(max_distance);
	m_covers.clear			();
}
Esempio n. 10
0
void CAI_Stalker::on_danger_location_remove			(const CDangerLocation &location)
{
	if (!m_best_cover) {
		if (Position().distance_to_sqr(location.position()) <= _sqr(location.m_radius)) {
#ifdef _DEBUG
//			Msg							("* [%6d][%s] on_danger_remove",Device.dwTimeGlobal,*cName());
#endif
			m_best_cover_actual			= false;
		}

		return;
	}

	if (m_best_cover->position().distance_to_sqr(location.position()) <= _sqr(location.m_radius)) {
#ifdef _DEBUG
//		Msg								("* [%6d][%s] on_danger_remove",Device.dwTimeGlobal,*cName());
#endif
		m_best_cover_actual				= false;
	}
}
Esempio n. 11
0
float _nrand(float sigma)
{
#define ONE_OVER_SIGMA_EXP (1.0f / 0.7975f)

	if(sigma == 0) return 0;

	float y;
	do{
		y = -logf(Random.randF());
	}while(Random.randF() > expf(-_sqr(y - 1.0f)*0.5f));
	if(rand() & 0x1)	return y * sigma * ONE_OVER_SIGMA_EXP;
	else				return -y * sigma * ONE_OVER_SIGMA_EXP;
}
Esempio n. 12
0
bool CLevelGraph::neighbour_in_direction	(const Fvector &direction, u32 start_vertex_id) const
{
	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1);
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= v2d(vertex_position(start_vertex_id));
	dir						= v2d(direction);
	dir.normalize_safe		();
	dest					= dir;
	dest.mul				(header().cell_size()*4.f);
	dest.add				(start);
	Fvector2				temp;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	const_iterator			I,E;
	begin					(cur_vertex_id,I,E);
	for ( ; I != E; ++I) {
		u32					next_vertex_id = value(cur_vertex_id,I);
		if ((next_vertex_id == prev_vertex_id) || !is_accessible(next_vertex_id))
			continue;
		unpack_xz			(vertex(next_vertex_id),temp.x,temp.y);
		box.min				= box.max = temp;
		box.grow			(identity);
		if (box.pick_exact(start,dir)) {
			Fvector2		temp;
			temp.add		(box.min,box.max);
			temp.mul		(.5f);
			float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
			if (dist > cur_sqr)
				continue;
			return			(true);
		}
	}
	return					(false);
}
Esempio n. 13
0
bool CAgentLocationManager::suitable	(CAI_Stalker *object, const CCoverPoint *location, bool use_enemy_info) const
{
	CAgentMemberManager::const_iterator	I = this->object().member().members().begin();
	CAgentMemberManager::const_iterator	E = this->object().member().members().end();
	for ( ; I != E; ++I) {
		if ((*I)->object().ID() == object->ID())
			continue;

		if (!(*I)->cover()) {
			if (this->object().member().registered_in_combat(&(*I)->object()))
				continue;

			if ((*I)->object().Position().distance_to_sqr(location->position()) <= _sqr(5.f))
				return					(false);

			continue;
		}

		// check if member cover is too close
		if ((*I)->cover()->m_position.distance_to_sqr(location->position()) <= _sqr(5.f))
			// so member cover is too close
//			if ((*I)->object().Position().distance_to_sqr(location->position()) <= object->Position().distance_to_sqr(location->position()))
			// check if member to its cover is more close than we to our cover
			if ((*I)->object().Position().distance_to_sqr((*I)->cover()->m_position) <= object->Position().distance_to_sqr(location->position()) + 2.f)
				return				(false);
	}

	if (use_enemy_info) {
		CAgentEnemyManager::ENEMIES::const_iterator	I = this->object().enemy().enemies().begin();
		CAgentEnemyManager::ENEMIES::const_iterator	E = this->object().enemy().enemies().end();
		for ( ; I != E; ++I)
			if ((*I).m_enemy_position.distance_to_sqr(location->position()) < _sqr(MIN_SUITABLE_ENEMY_DISTANCE))
				return				(false);
	}

	return							(true);
}
Esempio n. 14
0
void set_qid_val(double **qid_val, int ts) {

  int x1, x2, x3, nqhat=-1;
  int L = LX;
  int Lhp1 = L/2+1;
  double q[4];

  q[0] = 2. * sin( M_PI * (double)ts / (double)T );
  for(x1=0; x1<Lhp1; x1++) {
  for(x2=0; x2<=x1;  x2++) {
  for(x3=0; x3<=x2;  x3++) {
    nqhat++;
    q[1] = 2. * sin( M_PI * (double)x1 / (double)L );
    q[2] = 2. * sin( M_PI * (double)x2 / (double)L );
    q[3] = 2. * sin( M_PI * (double)x3 / (double)L );

    (qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
    (qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
    (qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
    (qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);
  }
  }
  }
}
Esempio n. 15
0
void CLightProjector::setup		(int id)
{
	if (id>=int(cache.size()) || id<0)	{
		// Log		("! CLightProjector::setup - ID out of range");
		return;
	}
	recv&			R			= cache[id];
	float			Rd			= R.O->renderable.visual->getVisData().sphere.R;
	float			dist		= R.C.distance_to	(Device.vCameraPosition)+Rd;
	float			factor		= _sqr(dist/clipD(Rd))*(1-ps_r1_lmodel_lerp) + ps_r1_lmodel_lerp;
	RCache.set_c	(c_xform,	R.UVgen);
	Fvector&	m	= R.UVclamp_min;
	RCache.set_ca	(c_clamp,	0,m.x,m.y,m.z,factor);
	Fvector&	M	= R.UVclamp_max;
	RCache.set_ca	(c_clamp,	1,M.x,M.y,M.z,0);
}
Esempio n. 16
0
void	light::spatial_move			()
{
	switch(flags.type)	{
	case IRender_Light::REFLECTED	:	
	case IRender_Light::POINT		:	
		{
			spatial.sphere.set		(position, range);
		} 
		break;
	case IRender_Light::SPOT		:	
		{
			// minimal enclosing sphere around cone
			VERIFY2						(cone < deg2rad(121.f), "Too large light-cone angle. Maybe you have passed it in 'degrees'?");
			if (cone>=PI_DIV_2)			{
				// obtused-angled
				spatial.sphere.P.mad	(position,direction,range);
				spatial.sphere.R		= range * tanf(cone/2.f);
			} else {
				// acute-angled
				spatial.sphere.R		= range / (2.f * _sqr(_cos(cone/2.f)));
				spatial.sphere.P.mad	(position,direction,spatial.sphere.R);
			}
		}
		break;
	case IRender_Light::OMNIPART	:
		{
			// is it optimal? seems to be...
			//spatial.sphere.P.mad		(position,direction,range);
			//spatial.sphere.R			= range;
			// This is optimal.
			const float fSphereR		= range*RSQRTDIV2;
			spatial.sphere.P.mad		(position,direction,fSphereR);
			spatial.sphere.R			= fSphereR;
		}
		break;
	}

	// update spatial DB
	ISpatial::spatial_move			();

#if (RENDER==R_R2) || (RENDER==R_R3)
	if (flags.bActive) gi_generate	();
	svis.invalidate					();
#endif
}
Esempio n. 17
0
void CPhantom::OnFlyState()
{
	UpdateFlyMedia			();
	if (g_Alive()){
		Fvector vE,vP;
		m_enemy->Center		(vE);
		Center				(vP);
		if (vP.distance_to_sqr(vE)<_sqr(Radius()+m_enemy->Radius())){
			SwitchToState	(stContact);
//			Hit				(1000.f,Fvector().set(0,0,1),this,-1,Fvector().set(0,0,0),100.f,ALife::eHitTypeFireWound);
			float power = 1000.0f;
			float power_critical = 0.0f;
			float impulse = 100.0f;
			SHit HDS(power,power_critical,Fvector().set(0,0,1),this,BI_NONE,Fvector().set(0,0,0),impulse,ALife::eHitTypeFireWound);
			Hit(&HDS);
		}
	}
}
Esempio n. 18
0
r_aabb_ssa		r_pixel_calculator::calculate	(dxRender_Visual* V)	{
	r_aabb_ssa	result			= {0};
	float		area			= float(_sqr(rt_dimensions));

	// 
	u32	id				[6]		;
	for (u32 face=0; face<6; face++)	{
		// setup matrices
		Fmatrix						mProject,mView	;
		Fvector						vFrom			;
		Fbox						aabb			;

		// camera - left-to-right
		mView.build_camera_dir		(vFrom.invert(cmDir[face]).mul(100.f),	cmDir[face],	cmNorm[face])	;
		aabb.xform					(V->vis.box,mView);
		D3DXMatrixOrthoOffCenterLH	( (D3DXMATRIX*)&mProject, aabb.min.x, aabb.max.x, aabb.min.y, aabb.max.y, aabb.min.z, aabb.max.z );
		RCache.set_xform_world		(Fidentity);
		RCache.set_xform_view		(mView);
		RCache.set_xform_project	(mProject);

		// render-0
		Device.Clear				();	// clear-ZB
		RCache.set_Shader			(V->shader);
		V->Render					(1.f);

		// render-1
		RImplementation.HWOCC.occq_begin	(id[face]);
		V->Render							(1.f);
		RImplementation.HWOCC.occq_end		(id[face]);
	}

	// 
	for (u32 it=0; it<6; it++)	{
		float	pixels	= (float)RImplementation.HWOCC.occq_get	(id[it]);
		float	coeff	= clampr(pixels/area,float(0),float(1));
		Msg		("[%d]ssa_c: %1.3f,%f/%f",it,coeff,pixels,area);
		result.ssa	[it]= (u8)clampr(iFloor(coeff*255.f+0.5f),int(0),int(255));
	}

	return result	;
}
Esempio n. 19
0
void CAgentLocationManager::make_suitable	(CAI_Stalker *object, const CCoverPoint *location) const
{
	this->object().member().member(object).cover(location);

	if (!location)
		return;

	CAgentMemberManager::const_iterator	I = this->object().member().members().begin();
	CAgentMemberManager::const_iterator	E = this->object().member().members().end();
	for ( ; I != E; ++I) {
		if ((*I)->object().ID() == object->ID())
			continue;

		if (!(*I)->cover())
			continue;

		// check if member cover is too close
		if ((*I)->cover()->m_position.distance_to_sqr(location->position()) <= _sqr(5.f)) {
//			Msg						("%6d : object [%s] disabled cover for object [%s]",Device.dwFrame,*object->cName(),*(*I)->object().cName());
			(*I)->object().on_cover_blocked	((*I)->cover());
			(*I)->cover						(0);
		}
	}
}
Esempio n. 20
0
void ComputeCylinder(Fcylinder& C, Fobb& B, FvectorVec& V)
{
    if (V.size()<3) 	{ C.invalidate(); return; }
    // pow(area,(3/2))/volume
    // 2*Pi*R*H+2*Pi*R*R
	
//	Fvector axis;
    float max_hI   	= flt_min;
    float min_hI   	= flt_max;
    float max_rI   	= flt_min;
    float max_hJ   	= flt_min;
    float min_hJ   	= flt_max;
    float max_rJ   	= flt_min;
    float max_hK   	= flt_min;
    float min_hK   	= flt_max;
    float max_rK   	= flt_min;
    Fvector axisJ 		= B.m_rotate.j;
    Fvector axisI 		= B.m_rotate.i;
    Fvector axisK 		= B.m_rotate.k;
    Fvector& c			= B.m_translate;
    for (FvectorIt I=V.begin(); I!=V.end(); I++){
        Fvector tmp;
    	Fvector pt		= *I;
    	Fvector pt_c;	pt_c.sub(pt,c);

    	float pI		= axisI.dotproduct(pt);
        min_hI			= _min(min_hI,pI);
        max_hI			= _max(max_hI,pI);
        tmp.mad			(c,axisI,axisI.dotproduct(pt_c));
        max_rI			= _max(max_rI,tmp.distance_to(pt));
        
    	float pJ		= axisJ.dotproduct(pt);
        min_hJ			= _min(min_hJ,pJ);
        max_hJ			= _max(max_hJ,pJ);
        tmp.mad			(c,axisJ,axisJ.dotproduct(pt_c));
        max_rJ			= _max(max_rJ,tmp.distance_to(pt));

    	float pK		= axisK.dotproduct(pt);
        min_hK			= _min(min_hK,pK);
        max_hK			= _max(max_hK,pK);
        tmp.mad			(c,axisK,axisK.dotproduct(pt_c));
        max_rK			= _max(max_rK,tmp.distance_to(pt));
    }

    float hI			= (max_hI-min_hI);
    float hJ			= (max_hJ-min_hJ);
    float hK			= (max_hK-min_hK);
    float vI			= hI*M_PI*_sqr(max_rI);
    float vJ			= hJ*M_PI*_sqr(max_rJ);
    float vK			= hK*M_PI*_sqr(max_rK);
//    vI					= pow(2*M_PI*max_rI*hI+2*M_PI*_sqr(max_rI),3/2)/vI;
//    vJ					= pow(2*M_PI*max_rJ*hJ+2*M_PI*_sqr(max_rJ),3/2)/vJ;
//    vK					= pow(2*M_PI*max_rK*hK+2*M_PI*_sqr(max_rK),3/2)/vK;
    // pow(area,(3/2))/volume
    // 2*Pi*R*H+2*Pi*R*R
    
    if (vI<vJ){
    	if (vI<vK){
        	//vI;
            C.m_direction.set	(axisI);
            C.m_height			= hI;
            C.m_radius			= max_rI;
        }else{
        	// vK
            C.m_direction.set	(axisK);
            C.m_height			= hK;
            C.m_radius			= max_rK;
        }
    }else {
        //vJ < vI
     	if (vJ<vK){
        	// vJ
            C.m_direction.set	(axisJ);
            C.m_height			= hJ;
            C.m_radius			= max_rJ;
        } else {
            //vK
            C.m_direction.set	(axisK);
            C.m_height			= hK;
            C.m_radius			= max_rK;
        }
    }
    
    C.m_center.set		(B.m_translate);
/*
    if (V.size()<3) { B.invalidate(); return; }
    Mgc::Cylinder CYL	= Mgc::ContCylinder(V.size(), (const Mgc::Vector3*) V.begin());
    B.m_center.set		(CYL.Center());
    B.m_direction.set	(CYL.Direction());
    B.m_height			= CYL.Height();
    B.m_radius			= CYL.Radius();
*/
}
#include "../xrEngine/IGame_Persistent.h"

#ifndef MASTER_GOLD
#	include "actor.h"
#	include "ai_debug.h"
#endif // MASTER_GOLD

#define SILENCE
//#define SAVE_OWN_SOUNDS
//#define SAVE_OWN_ITEM_SOUNDS
#define SAVE_NON_ALIVE_OBJECT_SOUNDS
#define SAVE_FRIEND_ITEM_SOUNDS
#define SAVE_FRIEND_SOUNDS
//#define SAVE_VISIBLE_OBJECT_SOUNDS

const float COMBAT_SOUND_PERCEIVE_RADIUS_SQR	= _sqr(5.f);

CSoundMemoryManager::~CSoundMemoryManager		()
{
	clear_delayed_objects	();
#ifdef USE_SELECTED_SOUND
	xr_delete				(m_selected_sound);
#endif
}

void CSoundMemoryManager::Load					(LPCSTR section)
{
}

void CSoundMemoryManager::reinit				()
{
Esempio n. 22
0
int make_H4orbits(int **qid, int **qid_count, double ***qid_val, int *nc) {

  int it, ix, iy, iz, iix, iit, n;
  int i0, i1, i2, i3;
  int isigma0, isigma1, isigma2, isigma3;
  int nqhat = -1;
  int Thp1  = T/2+1;
  int L = LX;
  int Lhp1  = L/2+1;
  int iq[4];
  int iq_perm[4], index_s;
  double q[4], qsq, q4;

  /* Nclasses = 1/4!/2^4 * (L+2)(L+4)(L+6)(L+8)  + the ones with odd t */
  int Nclasses = (L+2)*(L+4)*(L+6)*(L+8)/24/16 + T/4 * (L+2)*(L+4)*(L+6)/6/8;
  fprintf(stdout, "# Nclasses = %d\n", Nclasses);

  fprintf(stdout, "# allocating memory for qid_count\n");
  *qid_count = (int *)calloc(Nclasses, sizeof(int));

  fprintf(stdout, "# allocating memory for qid_val\n");
  *qid_val    = (double **)calloc(4, sizeof(double*));
  *(*qid_val) = (double * )calloc(4 * Nclasses, sizeof(double));
  (*qid_val)[1] = (*qid_val)[0] + Nclasses;
  (*qid_val)[2] = (*qid_val)[1] + Nclasses;
  (*qid_val)[3] = (*qid_val)[2] + Nclasses;

  fprintf(stdout, "# setting new fields to zero\n");
  for(it=0; it<Nclasses; it++) {
    (*qid_count)[it]  =  0;
    (*qid_val)[0][it] = -1.;
    (*qid_val)[1][it] = -1.;
    (*qid_val)[2][it] = -1.;
    (*qid_val)[3][it] = -1.;
  }

  if((*qid) == (int*)NULL) {
    fprintf(stdout, "# allocating memory for qid & setting to zero\n");
    *qid = (int *)calloc(VOLUME, sizeof(int));
    for(ix=0; ix<VOLUME; ix++) (*qid)[ix] = -1;
  }

  /* initialize the permutation tables */
  fprintf(stdout, "# initializing perm tabs\n");
  init_perm_tabs();

  fprintf(stdout, "# starting coordinate loops\n");
  nqhat = -1;
  for(it=0; it<Thp1; it++) {
    if(it%2==1) {
      for(ix=0; ix<Lhp1; ix++) {
        for(iy=0; iy<=ix; iy++) {
        for(iz=0; iz<=iy; iz++) {
          nqhat++;
  	  q[0] = 2. * sin( M_PI * (double)it / (double)T );
	  q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	  q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	  q[3] = 2. * sin( M_PI * (double)iz / (double)L );

          (*qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
          (*qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
          (*qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
          (*qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	  iq[0] = it; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
          fprintf(stdout, "=====================================\n");
          fprintf(stdout, "odd it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d\n", it, ix, iy, iz, nqhat);
*/
          /* go through all permutations */
	  for(n=0; n<6; n++) { 
  	    iq_perm[0] = iq[perm_tab_3[n][0]+1];
	    iq_perm[1] = iq[perm_tab_3[n][1]+1];
	    iq_perm[2] = iq[perm_tab_3[n][2]+1];
/*
            fprintf(stdout, "-------------------------------------\n");
            fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq[0], iq_perm[0], iq_perm[1], iq_perm[2]);
*/
            for(isigma0=0; isigma0<=1; isigma0++) {
              i0 = ( (1-isigma0)*iq[0] + isigma0*(T-iq[0]) ) % T;
            for(isigma1=0; isigma1<=1; isigma1++) {
              i1 = ( (1-isigma1)*iq_perm[0] + isigma1*(L-iq_perm[0]) ) % L;
            for(isigma2=0; isigma2<=1; isigma2++) {
              i2 = ( (1-isigma2)*iq_perm[1] + isigma2*(L-iq_perm[1]) ) % L;
            for(isigma3=0; isigma3<=1; isigma3++) {
              i3 = ( (1-isigma3)*iq_perm[2] + isigma3*(L-iq_perm[2]) ) % L;
  	      index_s = g_ipt[i0][i1][i2][i3];
/*              fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */
  	      if((*qid)[index_s] == -1) {
                (*qid)[index_s] = nqhat;
	        (*qid_count)[nqhat] +=1;
	      }
            }
            }
            }
            }
	  }  /* end of n = 0, ..., 5 */
        }    /* of iz */
        }    /* of iy */
      }      /* of ix */
    }        /* of if it % 2 == 1 */
    else {   /* it is even */
      iit = it / 2;
      for(ix=0; ix<=iit; ix++) {
      for(iy=0; iy<=ix;  iy++) {
      for(iz=0; iz<=iy;  iz++) {
        nqhat++;
	q[0] = 2. * sin( M_PI * (double)it / (double)T );
	q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	q[3] = 2. * sin( M_PI * (double)iz / (double)L );

        (*qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
        (*qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
        (*qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
        (*qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	iq[0] = iit; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
        fprintf(stdout, "=====================================\n");
        fprintf(stdout, "even it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d\n", it, ix, iy, iz, nqhat);
*/
        for(n=0; n<24; n++) {
  	  iq_perm[0] = iq[perm_tab_4[n][0]];
	  iq_perm[1] = iq[perm_tab_4[n][1]];
	  iq_perm[2] = iq[perm_tab_4[n][2]];
	  iq_perm[3] = iq[perm_tab_4[n][3]];
/*
          fprintf(stdout, "-------------------------------------\n");
          fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq_perm[0], iq_perm[1], iq_perm[2], iq_perm[3]);
*/
          for(isigma0=0; isigma0<=1; isigma0++) {
            i0 = ( 2*(1-isigma0)*iq_perm[0] + isigma0*(T-2*iq_perm[0]) ) % T;
          for(isigma1=0; isigma1<=1; isigma1++) {
            i1 = ( (1-isigma1)*iq_perm[1] + isigma1*(L-iq_perm[1]) ) % L;
          for(isigma2=0; isigma2<=1; isigma2++) {
            i2 = ( (1-isigma2)*iq_perm[2] + isigma2*(L-iq_perm[2]) ) % L;
          for(isigma3=0; isigma3<=1; isigma3++) {
            i3 = ( (1-isigma3)*iq_perm[3] + isigma3*(L-iq_perm[3]) ) % L;
  	    index_s = g_ipt[i0][i1][i2][i3];
/*            fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */
  	    if((*qid)[index_s] == -1) {
              (*qid)[index_s] = nqhat;
	      (*qid_count)[nqhat] +=1;
	    }
          }
          }
          }
          }
        }    /* of n = 0, ..., 23  */
      }
      }
      }
    }        /* of else branch in if it % 2 == 1 */
  }          /* of it */
  fprintf(stdout, "# finished coordinate loops\n");

  /************************
   * test: print the lists 
   ************************/
/*
  for(it=0; it<T; it++) {
  for(ix=0; ix<L; ix++) {
  for(iy=0; iy<L; iy++) {
  for(iz=0; iz<L; iz++) {
    index_s = g_ipt[it][ix][iy][iz];
    q[0] = 2. * sin( M_PI * (double)it / (double)T );
    q[1] = 2. * sin( M_PI * (double)ix / (double)L );
    q[2] = 2. * sin( M_PI * (double)iy / (double)L );
    q[3] = 2. * sin( M_PI * (double)iz / (double)L );
    qsq = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
    q4 = q[0]*q[0]*q[0]*q[0] + q[1]*q[1]*q[1]*q[1] + 
         q[2]*q[2]*q[2]*q[2] + q[3]*q[3]*q[3]*q[3]; 

    fprintf(stdout, "t=%3d, x=%3d, y=%3d, z=%3d, qid=%8d\n", it, ix, iy, iz, (*qid)[index_s]);
  }
  }
  }
  }

  fprintf(stdout, "# n\tqid_count\tqid_val\n");
  for(n=0; n<Nclasses; n++) {
    fprintf(stdout, "%5d\t%8d\t%12.5e\t%12.5e\t%12.5e\t%12.5e\n",
      n, (*qid_count)[n], (*qid_val)[0][n], (*qid_val)[1][n],(*qid_val)[2][n],(*qid_val)[3][n]);
  }
*/

  *nc = Nclasses;

  return(0);

}
Esempio n. 23
0
int make_H3orbits(int **qid, int **qid_count, double ***qid_val, int *nc) {

  int it, ix, iy, iz, iix, n;
  int i0, i1, i2, i3;
  int isigma0, isigma1, isigma2, isigma3;
  int nqhat = -1;
  int Thp1  = T/2+1;
  int L = LX;
  int Lhp1  = L/2+1;
  int iq[4];
  int iq_perm[3], index_s;
  double q[4], qsq, q4;

  /* Nclasses = 1/48 * (L+2)(L+4)(L+6) */
  int Nclasses = (L*L*L+12*L*L+44*L+48)/48; 
  fprintf(stdout, "# Nclasses = %d x %d\n", Thp1, Nclasses);

  /* initialize the permutation tables */
  fprintf(stdout, "# initializing perm tabs\n");
  init_perm_tabs();


  fprintf(stdout, "# allocating memory for qid_count\n");
  *qid_count = (int *)calloc(Thp1 * Nclasses, sizeof(int));
  if(*qid_count==(int*)NULL) return(301);

  fprintf(stdout, "# allocating memory for qid_val\n");
  *qid_val = (double **)calloc(4, sizeof(double*));
  (*qid_val)[0] = (double*)calloc(4 * Thp1 * Nclasses, sizeof(double));
  if((*qid_val)[0]==(double*)NULL) return(302);
  (*qid_val)[1] = (*qid_val)[0] + Thp1 * Nclasses;
  (*qid_val)[2] = (*qid_val)[1] + Thp1 * Nclasses;
  (*qid_val)[3] = (*qid_val)[2] + Thp1 * Nclasses;

  fprintf(stdout, "# setting new fields to zero\n");
  for(it=0; it<Thp1*Nclasses; it++) {
    (*qid_count)[it]  =  0;
    (*qid_val)[0][it] = -1.;
    (*qid_val)[1][it] = -1.;
    (*qid_val)[2][it] = -1.;
    (*qid_val)[3][it] = -1.;
  }

  if((*qid) == (int*)NULL) {
    fprintf(stdout, "# allocating memory for qid & setting to zero\n");
    *qid = (int *)calloc(VOLUME, sizeof(int));
    if(*qid==(int*)NULL) return(303);
    for(ix=0; ix<VOLUME; ix++) (*qid)[ix] = -1;
  }

#ifdef _UNDEF
  for(it=0; it<Thp1; it++) {
    nqhat = -1;
    for(ix=0; ix<Lhp1; ix++) {
      for(iy=0; iy<=ix; iy++) {
      for(iz=0; iz<=iy; iz++) {
        nqhat++;
	q[0] = 2. * sin( M_PI * (double)it / (double)T );
	q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	q[3] = 2. * sin( M_PI * (double)iz / (double)L );

        (*qid_val)[0][it*Nclasses+nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
        (*qid_val)[1][it*Nclasses+nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
        (*qid_val)[2][it*Nclasses+nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
        (*qid_val)[3][it*Nclasses+nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	iq[0] = it; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
        fprintf(stdout, "=====================================\n");
        fprintf(stdout, "it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d, id=%3d\n", it, ix, iy, iz, nqhat, it*Nclasses+nqhat);
*/
	for(n=0; n<6; n++) { 
	  iq_perm[0] = iq[perm_tab_3[n][0]+1];
	  iq_perm[1] = iq[perm_tab_3[n][1]+1];
	  iq_perm[2] = iq[perm_tab_3[n][2]+1];
/*          fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq[0], iq_perm[0], iq_perm[1], iq_perm[2]); */
          for(isigma0=0; isigma0<=1; isigma0++) {
            i0 = ( (1-isigma0)*iq[0] + isigma0*(T-iq[0]) ) % T;
          for(isigma1=0; isigma1<=1; isigma1++) {
            i1 = ( (1-isigma1)*iq_perm[0] + isigma1*(L-iq_perm[0]) ) % L;
          for(isigma2=0; isigma2<=1; isigma2++) {
            i2 = ( (1-isigma2)*iq_perm[1] + isigma2*(L-iq_perm[1]) ) % L;
          for(isigma3=0; isigma3<=1; isigma3++) {
            i3 = ( (1-isigma3)*iq_perm[2] + isigma3*(L-iq_perm[2]) ) % L;
	    index_s = g_ipt[i0][i1][i2][i3];

/*            fprintf(stdout, "-------------------------------------\n"); */
/*            fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */

	    if((*qid)[index_s] == -1) {
              (*qid)[index_s] = it*Nclasses + nqhat;
	      (*qid_count)[it*Nclasses+nqhat] +=1;
	    }

          }}}}
	}  
      }   
      } 
    }  
  }   
#endif
  /************************
   * test: print the lists 
   ************************/
/*
  for(it=0; it<T; it++) {
  for(ix=0; ix<L; ix++) {
  for(iy=0; iy<L; iy++) {
  for(iz=0; iz<L; iz++) {
    index_s = g_ipt[it][ix][iy][iz];
    q[0] = 2. * sin( M_PI * (double)it / (double)T );
    q[1] = 2. * sin( M_PI * (double)ix / (double)L );
    q[2] = 2. * sin( M_PI * (double)iy / (double)L );
    q[3] = 2. * sin( M_PI * (double)iz / (double)L );
    qsq = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
    q4 = q[0]*q[0]*q[0]*q[0] + q[1]*q[1]*q[1]*q[1] + 
         q[2]*q[2]*q[2]*q[2] + q[3]*q[3]*q[3]*q[3]; 

    fprintf(stdout, "t=%3d, x=%3d, y=%3d, z=%3d, qid=%8d\n", it, ix, iy, iz, (*qid)[index_s]);
  }
  }
  }
  }



  for(it=0; it<Thp1; it++) {
    for(n=0; n<Nclasses; n++) {
      fprintf(stdout, "t=%3d, n=%5d, qid_count=%8d, qid_val= %12.5e%12.5e%12.5e%12.5e\n",
        it, n, (*qid_count)[it*Nclasses+n], (*qid_val)[0][it*Nclasses+n], (*qid_val)[1][it*Nclasses+n],
        (*qid_val)[2][it*Nclasses+n],(*qid_val)[3][it*Nclasses+n]);
    }
  }
*/
  *nc = Thp1 * Nclasses;

  return(0);

}
Esempio n. 24
0
//
// computes also the global correlation (not used!)
//
double YARPLpDisparity::CorrelationMap(const YARPImageOf<YarpPixelMono>& im1, const YARPImageOf<YarpPixelMono>& im2)
{
	const int border = 2;

	int i,j,pos_i;
	int xi = 0, eta = 0;

	double correl;
	float Cmedia1 = .0f, Cmedia2 = .0f;

	float Cnumeratore = .0f, Cdenom1 = .0f, Cdenom2 = .0f;
	float numeratore = .0f, denom1 = .0f, denom2 = .0f;

	float d1 = .0f, d2 = .0f;

	int count=0;
	int Ccount=0;

	unsigned char **src1p = (unsigned char **)im1.GetArray();
	unsigned char **src2p = (unsigned char **)im2.GetArray();

	for(eta=0; eta<nAng; eta++)
		for(xi=0; xi<nEcc-border; xi++)
		{
			Cmedia1+=src1p[eta][xi];
			Cmedia2+=src2p[eta][xi];
			Ccount++;
		}

	Cmedia1 /= float(Ccount);
	Cmedia2 /= float(Ccount);

	float media1, media2;

	for(eta=0; eta<nAng; eta++)
		for(xi=border; xi<nEcc-border ; xi++)
		{
			media1 = .0; media2 = .0;
			for(j=-border;j<=border;j++)
				for(i=-border;i<=border;i++)
				{
					if (eta + i >= nAng)
						pos_i = eta + i - nAng ;
					else
					if (eta + i <0)
						pos_i = nAng + eta + i;
					else
						pos_i = eta + i;

					media1 += src1p[pos_i][xi+j];
					media2 += src2p[pos_i][xi+j];
				}

			media1 /= _sqr(2*border+1);
			media2 /= _sqr(2*border+1);

			numeratore = .0f;
			denom1 = .0f; 
			denom2 = .0f;

			for(j=-border;j<=border;j++)
				for(i=-border;i<=border;i++)
				{
					if (eta + i >= nAng)
						pos_i = eta +i - nAng;
					else
					if (eta + i <0)
						pos_i = nAng + eta + i;
					else
						pos_i = eta + i;

					d1=src1p[pos_i][xi+j]-media1;
					d2=src2p[pos_i][xi+j]-media2;
					numeratore += (d1*d2);
					denom1 += (d1*d1);
					denom2 += (d2*d2);

					if (i==0 && j==0)
					{
						d1=src1p[pos_i][xi+j]-Cmedia1;
						d2=src2p[pos_i][xi+j]-Cmedia2;
						Cnumeratore += (d1*d2);
						Cdenom1 += (d1*d1);
						Cdenom2 += (d2*d2);
					}
				}

			//
			// Correlation could be 1 for uniform areas.
			//
			correl = 1.0-(double(numeratore)/(denom1+0.00001))*(double(numeratore)/(denom2+0.00001));

			if (correl < 0.0) 
				correl = 0;
			else
			if (correl > 1.0)
				correl = 1;

		    m_corrMap(xi,eta) = (unsigned char)(correl*255.0);
			count++;
		}

	return 1.0-(double(Cnumeratore)/(Cdenom1+0.00001))*(double(Cnumeratore)/(Cdenom2+0.00001));
}
void StokesGenerator::run(const SpectrumDataSetC32* channeliserOutput,
        SpectrumDataSetStokes* stokes)
{
  typedef std::complex<float> Complex;
  unsigned nSamples = channeliserOutput->nTimeBlocks();
  unsigned nSubbands = channeliserOutput->nSubbands();
  unsigned nChannels = channeliserOutput->nChannels();
  Q_ASSERT( channeliserOutput->nPolarisations() >= 2 );
  
  stokes->setLofarTimestamp(channeliserOutput->getLofarTimestamp());
  stokes->setBlockRate(channeliserOutput->getBlockRate());
  stokes->resize(nSamples, nSubbands, _numberOfStokes, nChannels);
  
  const Complex* dataPolDataBlock = channeliserOutput->data();

  for (unsigned t = 0; t < nSamples; ++t) {
#pragma omp parallel for num_threads(4)
    for (unsigned s = 0; s < nSubbands; ++s) {
      const Complex* dataPolX, *dataPolY;
      float *I, *Q, *U, *V;
      float powerX, powerY;
      float XxYstarReal;
      float XxYstarImag;
      
      unsigned dataPolIndexX = channeliserOutput->index( s, nSubbands, 
                                                         0,2,
                                                         t, nChannels);
      unsigned dataPolIndexY = channeliserOutput->index( s, nSubbands, 
                                                         1,2,
                                                         t, nChannels);
      //unsigned indexStokes = stokes->index( s, nSubbands,
      //                                      0,2,
      //                                      t, nChannels );
      //dataPolX = channeliserOutput->spectrumData(t, s, 0);
      //dataPolY = channeliserOutput->spectrumData(t, s, 1);
      dataPolX = &dataPolDataBlock[dataPolIndexX];
      dataPolY = &dataPolDataBlock[dataPolIndexY];
      // TODO speed up
      I = stokes->spectrumData(t, s, 0);
      if (_numberOfStokes == 4){
        Q = stokes->spectrumData(t, s, 1);
        U = stokes->spectrumData(t, s, 2);
        V = stokes->spectrumData(t, s, 3);
      }
      //std::cout << "nSamples=" << nSamples << " t=" << t << " s=" << s;
      //std::cout << "  dataPolIndexX=" << dataPolIndexX;
      //std::cout << "  dataPolIndexY=" << dataPolIndexY << std::endl;
      // std::cout << I << " "<< Q <<" "<< U << " "<< V <<std::endl;
      for (unsigned c = 0; c < nChannels; ++c) {
        float Xr = dataPolX[c].real();
        float Xi = dataPolX[c].imag();
        float Yr = dataPolY[c].real();
        float Yi = dataPolY[c].imag();
        XxYstarReal = Xr*Yr + Xi*Yi;
        XxYstarImag = Xi*Yr - Xr*Yi;
        
        powerX = _sqr(Xr) + _sqr(Xi);
        powerY = _sqr(Yr) + _sqr(Yi);
        
        I[c] = powerX + powerY;
        if (_numberOfStokes == 4){
          Q[c] = powerX - powerY;
          U[c] = 2.0f * XxYstarReal;
          V[c] = 2.0f * XxYstarImag;
        }
      }
    }
  }
}
Esempio n. 26
0
//
// computes also the global correlation (not used!)
//
double YARPLpDisparity::CorrelationMap(const YARPImageOf<YarpPixelRGB>& im1, const YARPImageOf<YarpPixelRGB>& im2)
{
	const int border = 2;

	int i,j,pos_i;
	int xi = 0, eta = 0;

	double correl;
	float Cmedia1r = .0f, Cmedia2r = .0f;
	float Cmedia1g = .0f, Cmedia2g = .0f;
	float Cmedia1b = .0f, Cmedia2b = .0f;

	float Cnumeratore = .0f, Cdenom1 = .0f, Cdenom2 = .0f;
	float numeratore = .0f, denom1 = .0f, denom2 = .0f;

	float d1 = .0f, d2 = .0f;

	int count=0;
	int Ccount=0;

	unsigned char **src1 = (unsigned char **)im1.GetArray();
	unsigned char **src2 = (unsigned char **)im2.GetArray();

	// global average.
	for(eta=0; eta<nAng; eta++)
		for(xi=0; xi<nEcc-border; xi++)
		{
			Cmedia1r += src1[eta][xi*3];
			Cmedia2r += src2[eta][xi*3];
			Cmedia1g += src1[eta][xi*3+1];
			Cmedia2g += src2[eta][xi*3+1];
			Cmedia1b += src1[eta][xi*3+2];
			Cmedia2b += src2[eta][xi*3+2];
			Ccount++;
		}

	Cmedia1r /= float(Ccount);
	Cmedia2r /= float(Ccount);
	Cmedia1g /= float(Ccount);
	Cmedia2g /= float(Ccount);
	Cmedia1b /= float(Ccount);
	Cmedia2b /= float(Ccount);

	float media1r, media2r;
	float media1g, media2g;
	float media1b, media2b;

	// 5 x 5 average and cross-correlation.
	for(eta=0; eta<nAng; eta++)
		for(xi=border; xi<nEcc-border ; xi++)
		{
			media1r = .0; media2r = .0;
			media1g = .0; media2g = .0;
			media1b = .0; media2b = .0;
			for(j=-border;j<=border;j++)
				for(i=-border;i<=border;i++)
				{
					if (eta + i >= nAng)
						pos_i = eta + i - nAng ;
					else
					if (eta + i <0)
						pos_i = nAng + eta + i;
					else
						pos_i = eta + i;

					media1r += src1[pos_i][(xi+j)*3];
					media2r += src2[pos_i][(xi+j)*3];
					media1g += src1[pos_i][(xi+j)*3+1];
					media2g += src2[pos_i][(xi+j)*3+1];
					media1b += src1[pos_i][(xi+j)*3+2];
					media2b += src2[pos_i][(xi+j)*3+2];
				}

			media1r /= _sqr(2*border+1);
			media2r /= _sqr(2*border+1);
			media1g /= _sqr(2*border+1);
			media2g /= _sqr(2*border+1);
			media1b /= _sqr(2*border+1);
			media2b /= _sqr(2*border+1);

			numeratore = .0f;
			denom1 = .0f; 
			denom2 = .0f;

			for(j=-border;j<=border;j++)
				for(i=-border;i<=border;i++)
				{
					if (eta + i >= nAng)
						pos_i = eta +i - nAng;
					else
					if (eta + i <0)
						pos_i = nAng + eta + i;
					else
						pos_i = eta + i;

					d1 = src1[pos_i][(xi+j)*3] - media1r;
					d2 = src2[pos_i][(xi+j)*3] - media2r;
					d1 += src1[pos_i][(xi+j)*3+1] - media1g;
					d2 += src2[pos_i][(xi+j)*3+1] - media2g;
					d1 += src1[pos_i][(xi+j)*3+2] - media1b;
					d2 += src2[pos_i][(xi+j)*3+2] - media2b;
					numeratore += (d1*d2);
					denom1 += (d1*d1);
					denom2 += (d2*d2);

					if (i==0 && j==0)
					{
						d1 = src1[pos_i][(xi+j)*3] - Cmedia1r;
						d2 = src2[pos_i][(xi+j)*3] - Cmedia2r;
						d1 += src1[pos_i][(xi+j)*3+1] - Cmedia1g;
						d2 += src2[pos_i][(xi+j)*3+1] - Cmedia2g;
						d1 += src1[pos_i][(xi+j)*3+2] - Cmedia1b;
						d2 += src2[pos_i][(xi+j)*3+2] - Cmedia2b;
						Cnumeratore += (d1*d2);
						Cdenom1 += (d1*d1);
						Cdenom2 += (d2*d2);
					}
				}

			//
			// Correlation could be 1 for uniform areas.
			//
			correl = 1.0-(double(numeratore)/(denom1+0.00001))*(double(numeratore)/(denom2+0.00001));

			if (correl < 0.0) 
				correl = 0;
			else
			if (correl > 1.0)
				correl = 1;

			if (correl < 80.0 / 255.0)
				//m_corrMap(xi,eta) = (unsigned char)(correl*255.0);
				m_corrMap(xi, eta) = 255;
			else
				m_corrMap(xi, eta) = 0;

			count++;
		}

	return 1.0-(double(Cnumeratore)/(Cdenom1+0.00001))*(double(Cnumeratore)/(Cdenom2+0.00001));
}
Esempio n. 27
0
void CAI_Stalker::update_best_cover_actuality		(const Fvector &position_to_cover_from)
{
	if (!m_best_cover_actual)
		return;

	if (!m_best_cover) {
		m_best_cover_actual = false;
		return;
	}

	if (m_best_cover->m_is_smart_cover) {
		float							value;
		smart_cover::cover const		*cover = static_cast<smart_cover::cover const*>(m_best_cover);
		smart_cover::loophole			*loophole = cover->best_loophole(position_to_cover_from, value, false, movement().current_params().cover() == m_best_cover );
		if (!loophole) {
			m_ce_best->invalidate		();
			m_best_cover_actual			= false;
			return;
		}
	}

	if (m_best_cover->position().distance_to_sqr(position_to_cover_from) < _sqr(MIN_SUITABLE_ENEMY_DISTANCE)) {
		m_best_cover_actual				= false;
#if 0//def _DEBUG
		Msg								("* [%6d][%s] enemy too close",Device.dwTimeGlobal,*cName());
#endif
		return;
	}

	float								cover_value = best_cover_value(position_to_cover_from);
	if (cover_value >= m_best_cover_value + 1.f) {
		m_best_cover_actual				= false;
#if 0//def _DEBUG
		Msg								("* [%6d][%s] cover became too bad",Device.dwTimeGlobal,*cName());
#endif
		return;
	}

//	if (cover_value >= 1.5f*m_best_cover_value) {
//		m_best_cover_actual				= false;
//		Msg								("* [%6d][%s] cover became too bad2",Device.dwTimeGlobal,*cName());
//		return;
//	}

	if (false)//!m_best_cover_can_try_advance)
		return;

	if (m_best_cover_advance_cover == m_best_cover)
		return;

	m_best_cover_advance_cover			= m_best_cover;
	m_best_cover_can_try_advance		= false;

#ifdef _DEBUG
//	Msg									("* [%6d][%s] advance search performed",Device.dwTimeGlobal,*cName());
#endif
#ifdef _DEBUG
	++g_advance_search_count;
#endif
	m_ce_best->setup					(position_to_cover_from,MIN_SUITABLE_ENEMY_DISTANCE,170.f,MIN_SUITABLE_ENEMY_DISTANCE);
	m_best_cover						= ai().cover_manager().best_cover(Position(),10.f,*m_ce_best,CStalkerMovementRestrictor(this,true));
}
Esempio n. 28
0
//---------------------------------------------------------------------
void CPhantom::SwitchToState_internal(EState new_state)
{
	if (new_state!=m_CurState){
		IKinematicsAnimated *K	= smart_cast<IKinematicsAnimated*>(Visual());
		Fmatrix	xform			= XFORM_center	();
		UpdateEvent				= 0;
		// after event
		switch (m_CurState){
		case stBirth:		break;
		case stFly:			break;
		case stContact:{
			SStateData& sdata	= m_state_data[m_CurState];
			PlayParticles		(sdata.particles.c_str(),FALSE,xform);
			Fvector vE,vP;
			m_enemy->Center		(vE);
			Center				(vP);
			if (vP.distance_to_sqr(vE)<_sqr(Radius())){ 
				// hit enemy
				PsyHit			(m_enemy,fContactHit);
			}
			}break;
		case stShoot:{
			SStateData& sdata	= m_state_data[m_CurState];
			PlayParticles		(sdata.particles.c_str(),FALSE,xform);
		}break;
		case stIdle:		break;
		}
		// before event
		switch (new_state){
		case stBirth:{
			SStateData& sdata	= m_state_data[new_state];
			PlayParticles		(sdata.particles.c_str(),TRUE,xform);
			sdata.sound.play_at_pos(0,xform.c);
			K->PlayCycle		(sdata.motion, TRUE, animation_end_callback, this);
		}break;
		case stFly:{
			UpdateEvent.bind	(this,&CPhantom::OnFlyState);
			SStateData& sdata	= m_state_data[new_state];
			m_fly_particles		= PlayParticles(sdata.particles.c_str(),FALSE,xform);
			sdata.sound.play_at_pos(0,xform.c,sm_Looped);
			K->PlayCycle		(sdata.motion);
		}break;
		case stContact:{
			UpdateEvent.bind	(this,&CPhantom::OnDeadState);	
			SStateData& sdata	= m_state_data[new_state];
			sdata.sound.play_at_pos(0,xform.c);
			K->PlayCycle		(sdata.motion, TRUE, animation_end_callback, this);
		}break;
		case stShoot:{
			UpdateEvent.bind	(this,&CPhantom::OnDeadState);	
			SStateData& sdata	= m_state_data[new_state];
			PlayParticles		(sdata.particles.c_str(),TRUE,xform);
			sdata.sound.play_at_pos(0,xform.c);
			K->PlayCycle		(sdata.motion, TRUE, animation_end_callback, this);
		}break;
		case stIdle:{
			UpdateEvent.bind	(this,&CPhantom::OnIdleState);	
			SStateData& sdata	= m_state_data[m_CurState];
			sdata.sound.stop	();
			CParticlesObject::Destroy(m_fly_particles);
		}break;
		}
		m_CurState				= new_state;
	}
}
Esempio n. 29
0
bool CLevelGraph::create_straight_path(u32 start_vertex_id, const Fvector2 &start_point, const Fvector2 &finish_point, xr_vector<Fvector> &tpaOutputPoints, xr_vector<u32> &tpaOutputNodes, bool bAddFirstPoint, bool bClearPath) const
{
	if (!valid_vertex_position(v3d(finish_point)))
		return				(false);

	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = start_vertex_id;
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= start_point;
	dest					= finish_point;
	dir.sub					(dest,start);
	u32						dest_xz = vertex_position(v3d(dest)).xz();
	Fvector2				temp;
	Fvector					pos3d;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	if (bClearPath) {
		tpaOutputPoints.clear	();
		tpaOutputNodes.clear	();
	}
	if (bAddFirstPoint) {
		pos3d				= v3d(start_point);
		pos3d.y				= vertex_plane_y(start_vertex_id,start_point.x,start_point.y);
		tpaOutputPoints.push_back(pos3d);
		tpaOutputNodes.push_back(start_vertex_id);
	}

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	for (;;) {
		const_iterator		I,E;
		begin				(cur_vertex_id,I,E);
		bool				found = false;
		for ( ; I != E; ++I) {
			u32				next_vertex_id = value(cur_vertex_id,I);
			if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id))
				continue;
			CVertex			*v = vertex(next_vertex_id);
			unpack_xz		(v,temp.x,temp.y);
			box.min			= box.max = temp;
			box.grow		(identity);
			if (box.pick_exact(start,dir)) {
				Fvector2		temp;
				temp.add		(box.min,box.max);
				temp.mul		(.5f);
				float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
				if (dist > cur_sqr)
					continue;

				Fvector2		next1, next2;
#ifdef DEBUG
				next1			= next2 = Fvector2().set(0.f,0.f);
#endif
				Fvector			tIntersectPoint;

				switch (I) {
					case 0 : {
						next1		= box.max;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 1 : {
						next1		= box.min;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 2 : {
						next1		= box.min;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					case 3 : {
						next1		= box.max;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					default : NODEFAULT;
				}
				VERIFY			(_valid(next1));
				VERIFY			(_valid(next2));
				u32				dwIntersect = intersect(start_point.x,start_point.y,finish_point.x,finish_point.y,next1.x,next1.y,next2.x,next2.y,&tIntersectPoint.x,&tIntersectPoint.z);
				if (!dwIntersect)
					continue;
				tIntersectPoint.y = vertex_plane_y(vertex(cur_vertex_id),tIntersectPoint.x,tIntersectPoint.z);

				tpaOutputPoints.push_back(tIntersectPoint);
				tpaOutputNodes.push_back(cur_vertex_id);

				if (dest_xz == v->position().xz())
					return		(true);
				
				cur_sqr			= dist;
				found			= true;
				prev_vertex_id	= cur_vertex_id;
				cur_vertex_id	= next_vertex_id;
				break;
			}
		}
		if (!found)
			return				(false);
	}
}