Ejemplo n.º 1
0
// Utility: return the walkability value of a tile
uchar j1PathFinding::GetTileAt(const iPoint& pos) const
{
	if(CheckBoundaries(pos))
		return map[(pos.y*width) + pos.x];

	return INVALID_WALK_CODE;
}
Ejemplo n.º 2
0
void Player::updateET(uint32_t milliseconds)
{
	// Check if dead
	if (mNumLives < 0)
	{
		SpriteManager::GetInstance()->endGame();
		return;
	}

	// Update shot timer
	if (!mCanShoot)
	{
		mShotTimer += milliseconds;
		switch (currentWeapon) {
		case NORMAL:
			if (mShotTimer >= NORMAL_SHOT_RATE)
			{
				mCanShoot = true;
			}
			break;
		case QUICK:
			if (mShotTimer >= QUICK_SHOT_RATE)
			{
				mCanShoot = true;
			}
			break;
		case SPREAD:
			if (mShotTimer >= SPREAD_SHOT_RATE)
			{
				mCanShoot = true;
			}
			break;
		case HOMING:
			if (mShotTimer >= HOMING_SHOT_RATE)
			{
				mCanShoot = true;
			}
			break;
		default:
			mCanShoot = false;
			break;
		}
	}

	// Check for movement input if able to move
	if (mCanMove)
	{
		CheckForUserInput();
	}

	CheckBoundaries();
}
Ejemplo n.º 3
0
void CPUTracker::ComputeRadialProfile(float* dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, bool crp, bool* pBoundaryHit, bool normalize)
{
	bool boundaryHit = CheckBoundaries(center, maxradius);
	if (pBoundaryHit) *pBoundaryHit = boundaryHit;

	ImageData imgData (srcImage, width,height);
	if (crp) {
		ComputeCRP(dst, radialSteps, angularSteps, minradius, maxradius, center, &imgData, mean);
	}
	else {
		::ComputeRadialProfile(dst, radialSteps, angularSteps, minradius, maxradius, center, &imgData, mean, normalize);
	}
}
 //--
 void
 LooseOctreeNode::CheckCollisions(ISpatialObject* pObject)
 {        
     
     // [rad] Check if the object is completely outside the boundary
     // for this node
     //if(!CheckContains(pObject))
     if(!CheckBoundaries(pObject))
     {
         // [rad] Object is outside of this node
         return;
     }
     
     // [rad] Check children recursively
     for(int i = 0; i < 8; i++)
     {
         if(m_pChildren[i])
         {
             m_pChildren[i]->CheckCollisions(pObject);
         }
     }   
     
     
     // [rad] Check all objects in this node
     ISpatialObject* pIter = m_pObjects;
     while(pIter)
     {
         // [rad] Skip self check
         if(pIter != pObject)
         {
             if(pIter->VCheckCollision(pObject))
             {
                 // [rad] Mark both as in collision
                 pObject->VCollisionOn();
                 pIter->VCollisionOn();
             }
         }
         
         pIter = pIter->VGetNext();
     }
 }
Ejemplo n.º 5
0
/*

- Compute quadrants
- Build interpolated profile from ZLUT
- Align X & Y against profile with FFT

Difference with QI: No mirroring of profile, instead of mirror we use ZLUT profile

*/
vector3f CPUTracker::QuadrantAlign(vector3f pos, int beadIndex, int angularStepsPerQuadrant, bool& boundaryHit)
{
	float* zlut = GetRadialZLUT(beadIndex);
	int res=zlut_res;
	complex_t* profile = ALLOCA_ARRAY(complex_t, res*2);
	complex_t* concat0 = ALLOCA_ARRAY(complex_t, res*2);
	complex_t* concat1 = concat0 + res;

	memset(concat0, 0, sizeof(complex_t)*res*2);

	int zp0 = clamp( (int)pos.z, 0, zlut_planes - 1);
	int zp1 = clamp( (int)pos.z + 1, 0, zlut_planes - 1);

	float* zlut0 = &zlut[ res * zp0 ];
	float* zlut1 = &zlut[ res * zp1 ];
	float frac = pos.z - (int)pos.z;
	for (int r=0;r<zlut_res;r++) {
	// Interpolate plane
		double zlutValue = Lerp(zlut0[r], zlut1[r], frac);
		concat0[res-r-1] = concat1[r] = zlutValue;
	}
//	WriteComplexImageAsCSV("qa_zlutprof.txt", concat0, res,2);
	qa_fft_forward->transform(concat0, profile);

	scalar_t* buf = ALLOCA_ARRAY(scalar_t, res*4);
	scalar_t* q0=buf, *q1=buf+res, *q2=buf+res*2, *q3=buf+res*3;

	boundaryHit = CheckBoundaries(vector2f(pos.x,pos.y), zlut_maxradius);
	for (int q=0;q<4;q++) {
		scalar_t *quadrantProfile = buf+q*res;
		ComputeQuadrantProfile(quadrantProfile, res, angularStepsPerQuadrant, q, zlut_minradius, zlut_maxradius, vector2f(pos.x,pos.y));
		NormalizeRadialProfile(quadrantProfile, res);
	}
	
	//WriteImageAsCSV("qa_qdr.txt" , buf, res,4);
	
	float pixelsPerProfLen = (zlut_maxradius-zlut_minradius)/zlut_res;
	boundaryHit = false;

	// Build Ix = [ qL(-r)  qR(r) ]
	// qL = q1 + q2   (concat0)
	// qR = q0 + q3   (concat1)
	for(int r=0;r<res;r++) {
		concat0[res-r-1] = q1[r]+q2[r];
		concat1[r] = q0[r]+q3[r];
	}

	scalar_t offsetX = QuadrantAlign_ComputeOffset(concat0, profile, res, 0);

	// Build Iy = [ qB(-r)  qT(r) ]
	// qT = q0 + q1
	// qB = q2 + q3
	for(int r=0;r<res;r++) {
		concat1[r] = q0[r]+q1[r];
		concat0[res-r-1] = q2[r]+q3[r];
	}
		
	scalar_t offsetY = QuadrantAlign_ComputeOffset(concat0, profile, res, 1);

	return vector3f(pos.x + offsetX * pixelsPerProfLen, pos.y + offsetY * pixelsPerProfLen, pos.z);
}
Ejemplo n.º 6
0
vector2f CPUTracker::ComputeQI(vector2f initial, int iterations, int radialSteps, int angularStepsPerQ, 
	float angStepIterationFactor, float minRadius, float maxRadius, bool& boundaryHit, float* radialWeights)
{
	int nr=radialSteps;
#ifdef _DEBUG
	std::copy(srcImage, srcImage+width*height, debugImage);
	maxImageValue = *std::max_element(srcImage,srcImage+width*height);
#endif

	if (angularStepsPerQ != quadrantDirs.size()) {
		quadrantDirs.resize(angularStepsPerQ);
		for (int j=0;j<angularStepsPerQ;j++) {
			float ang = 0.5*3.141593f*(j+0.5f)/(float)angularStepsPerQ;
			quadrantDirs[j] = vector2f( cosf(ang), sinf(ang) );
		}
	}

	AllocateQIFFTs(radialSteps);

	scalar_t* buf = (scalar_t*)ALLOCA(sizeof(scalar_t)*nr*4);
	scalar_t* q0=buf, *q1=buf+nr, *q2=buf+nr*2, *q3=buf+nr*3;
	complex_t* concat0 = (complex_t*)ALLOCA(sizeof(complex_t)*nr*2);
	complex_t* concat1 = concat0 + nr;

	vector2f center = initial;

	float pixelsPerProfLen = (maxRadius-minRadius)/radialSteps;
	boundaryHit = false;

	float angsteps = angularStepsPerQ / powf(angStepIterationFactor, iterations);
	
	for (int k=0;k<iterations;k++){
		// check bounds
		boundaryHit = CheckBoundaries(center, maxRadius);

		for (int q=0;q<4;q++) {
			ComputeQuadrantProfile(buf+q*nr, nr, angsteps, q, minRadius, maxRadius, center, radialWeights);
		}
#ifdef QI_DEBUG
		cmp_cpu_qi_prof.assign (buf,buf+4*nr);
#endif

		// Build Ix = [ qL(-r)  qR(r) ]
		// qL = q1 + q2   (concat0)
		// qR = q0 + q3   (concat1)
		for(int r=0;r<nr;r++) {
			concat0[nr-r-1] = q1[r]+q2[r];
			concat1[r] = q0[r]+q3[r];
		}

		scalar_t offsetX = QI_ComputeOffset(concat0, nr, 0);

		// Build Iy = [ qB(-r)  qT(r) ]
		// qT = q0 + q1
		// qB = q2 + q3
		for(int r=0;r<nr;r++) {
			concat1[r] = q0[r]+q1[r];
			concat0[nr-r-1] = q2[r]+q3[r];
		}
		
		scalar_t offsetY = QI_ComputeOffset(concat0, nr, 1);

#ifdef QI_DBG_EXPORT
		std::copy(concat0, concat0+nr*2,tmp.begin()+nr*2);
		WriteComplexImageAsCSV("cpuprofxy.txt", &tmp[0], nr, 4);
		dbgprintf("[%d] OffsetX: %f, OffsetY: %f\n", k, offsetX, offsetY);
#endif

		center.x += offsetX * pixelsPerProfLen;
		center.y += offsetY * pixelsPerProfLen;

		angsteps *= angStepIterationFactor;
	}

	return center;
}
Ejemplo n.º 7
0
vector2f CPUTracker::ComputeXCorInterpolated(vector2f initial, int iterations, int profileWidth, bool& boundaryHit)
{
	// extract the image
	vector2f pos = initial;

	if (!xcorBuffer)
		xcorBuffer = new XCor1DBuffer(xcorw);

	if (xcorw < profileWidth)
		profileWidth = xcorw;

#ifdef _DEBUG
	std::copy(srcImage, srcImage+width*height, debugImage);
	maxImageValue = *std::max_element(srcImage,srcImage+width*height);
#endif

	if (xcorw > width || xcorw > height) {
		boundaryHit = true;
		return initial;
	}

	complex_t* prof = (complex_t*)ALLOCA(sizeof(complex_t)*xcorw);
	complex_t* prof_rev = (complex_t*)ALLOCA(sizeof(complex_t)*xcorw);
	scalar_t* prof_autocor = (scalar_t*)ALLOCA(sizeof(scalar_t)*xcorw);

	boundaryHit = false;
	for (int k=0;k<iterations;k++) {
		boundaryHit = CheckBoundaries(pos, XCorScale*xcorw/2);

		float xmin = pos.x - XCorScale * xcorw/2;
		float ymin = pos.y - XCorScale * xcorw/2;

		// generate X position xcor array (summing over y range)
		for (int x=0;x<xcorw;x++) {
			scalar_t s = 0.0f;
			int n=0;
			for (int y=0;y<profileWidth;y++) {
				scalar_t xp = x * XCorScale + xmin;
				scalar_t yp = pos.y + XCorScale * (y - profileWidth/2);
				bool outside;
				s += Interpolate(srcImage, width, height, xp, yp, &outside);
				n += outside?0:1;
				MARKPIXELI(xp, yp);
			}
			if (n >0) s/=n;
			else s=0;
			prof [x] = s;
			prof_rev [xcorw-x-1] = s;
		}

		xcorBuffer->XCorFFTHelper(prof, prof_rev, prof_autocor);
		scalar_t offsetX = ComputeMaxInterp<scalar_t,QI_LSQFIT_NWEIGHTS>::Compute(prof_autocor, xcorw, QIWeights) - (scalar_t)xcorw/2;

		// generate Y position xcor array (summing over x range)
		for (int y=0;y<xcorw;y++) {
			scalar_t s = 0.0f; 
			int n=0;
			for (int x=0;x<profileWidth;x++) {
				scalar_t xp = pos.x + XCorScale * (x - profileWidth/2);
				scalar_t yp = y * XCorScale + ymin;
				bool outside;
				s += Interpolate(srcImage,width,height, xp, yp, &outside);
				n += outside?0:1;
				MARKPIXELI(xp,yp);
			}
			if (n >0) s/=n;
			else s=0;
			prof[y] = s;
			prof_rev [xcorw-y-1] =s;
		}

		xcorBuffer->XCorFFTHelper(prof,prof_rev, prof_autocor);
		//WriteImageAsCSV("xcorautoconv.txt",&xcorBuffer->Y_result[0],xcorBuffer->Y_result.size(),1);
		scalar_t offsetY = ComputeMaxInterp<scalar_t, QI_LSQFIT_NWEIGHTS>::Compute(prof_autocor, xcorw, QIWeights) - (scalar_t)xcorw/2;

		pos.x += (offsetX - 1) * XCorScale * 0.5f;
		pos.y += (offsetY - 1) * XCorScale * 0.5f;
	}

	return pos;
}