GroundPolyFitter<degree>::GroundPolyFitter(void) :
	nrows(480), ncols(640), pixelToGround(nrows, ncols), allPixels(nrows * ncols)
{
	double pixelPointInit[] = { 0.0, 0.0, 1.0 }; // homogeneous coordinates
	cv::Mat_<double> pixelPoint(3, 1, pixelPointInit);
	cv::Mat_<double> groundPoint(3, 1);

	int i = 0;
	for(int r = 0; r < nrows; r++) {
		for(int c = 0; c < ncols; c++) {
			pixelPoint(1, 1) = (double) r;
			pixelPoint(1, 2) = (double) c;

			groundPoint = homography * pixelPoint;

			double x = groundPoint(1, 1);
			double y = groundPoint(1, 2);
			double scale = groundPoint(1, 3);
			pixelToGround(r, c).setX(x /scale);
			pixelToGround(r, c).setY(y /scale);

			allPixels[i] = RowCol(r, c);
			i++;
		}
	}
}
예제 #2
0
파일: main.c 프로젝트: killerwife/ACMadness
int main() {
   char line[100];
   int points[6], row[6], col[6];
   int i, n, isvalid;

   while (gets(line), strlen(line)) {
      n = sscanf(line, "%d %d %d %d %d %d", points, points+1, points+2,
		 points+3, points+4, points+5);

      for (i=0; i<n; i++) printf("%d ", points[i]);
      qsort(points, n, sizeof(int), Cmp);
      for (i=0; i<n; i++) {
	 RowCol(points[i], row+i, col+i);
      }
      isvalid = (n==3) ? Triangle(row, col) :
	        (n==4) ? Parallelogram(row, col) :
		(n==6) ? Hexagon(row, col) :
	        0;
      printf("are %sthe vertices of %s\n",
	     isvalid ? "" : "not ",
	     !isvalid ? "an acceptable figure" :
	     n==3 ? "a triangle" :
	     n==4 ? "a parallelogram" : "a hexagon");
   }

   return 0;
}
RowCol searchSorted2dArray(const Array2d<T>& a, const T& target) {
    int rows = a.size();
    int cols = a[0].size();

    int top = 0;
    int bottom = rows - 1;
    int left = 0;
    int right = cols - 1;

    int row = bottom;
    int col = left;
    while (row >= top && col <= right) {
        if (a[row][col] < target) {
            ++col;
        } else if (a[row][col] > target) {
            --row;
        } else {
            return RowCol(row, col);
        }
    }
    return RowCol(-1, -1);
}
예제 #4
0
// This method is called from the scheduler to move the
// creatures.  This is where most of the creature logic
// resides.  It's frequency is determined by the creature
// type, and its location relative to the player.
int Creature::CMOVE(int task, int cidx)
{
	int oidx, dir, X, loop;
	bool doRandom = false;
	dodBYTE r, c, rnd, d;
	dodBYTE shA, shB;
	dodSHORT shD, shD2;

	if (FRZFLG == 0)
	{
		// ignore dead creatures
		if (CCBLND[cidx].P_CCUSE == 0)
		{
			return 0;
		}

		// pick up object
		if (
			CCBLND[cidx].creature_id != CRT_SCORPION &&
			CCBLND[cidx].creature_id < CRT_WIZIMG &&
			!(
			  game.CreaturesIgnoreObjects &&
			  CCBLND[cidx].P_CCROW == player.PROW &&
			  CCBLND[cidx].P_CCCOL == player.PCOL
			)
		   )
		{
			object.OFINDF = 0;
			oidx = object.OFIND(RowCol(CCBLND[cidx].P_CCROW,
									   CCBLND[cidx].P_CCCOL));
			if (oidx != -1)
			{
				object.OCBLND[oidx].P_OCPTR = CCBLND[cidx].P_CCOBJ;
				CCBLND[cidx].P_CCOBJ = oidx;
				--object.OCBLND[oidx].P_OCOWN;
				viewer.PUPDAT();
				if (CCBLND[cidx].P_CCROW == player.PROW &&
					CCBLND[cidx].P_CCCOL == player.PCOL)
				{
					viewer.PUPDAT();
					viewer.NEWLUK = 0;
					scheduler.TCBLND[task].next_time = scheduler.curTime +
						CCBLND[cidx].P_CCTAT;
					return 0;
				}
				else
				{
					scheduler.TCBLND[task].next_time = scheduler.curTime +
						CCBLND[cidx].P_CCTMV;
					return 0;
				}
			}
		}

		// attack player
		if (CCBLND[cidx].P_CCROW == player.PROW &&
			CCBLND[cidx].P_CCCOL == player.PCOL)
		{
			// do creature sound
			Mix_PlayChannel(creChannel, creSound[CCBLND[cidx].creature_id], 0);
			while (Mix_Playing(creChannel) == 1)
			{
				if (scheduler.curTime >= scheduler.TCBLND[0].next_time)
				{
					scheduler.CLOCK();
					if (game.AUTFLG && game.demoRestart == false)
					{
						return 0;
					}
				}
				scheduler.curTime = SDL_GetTicks();
			}

			// set player shielding parameters
			shA = 0x80;
			shB = 0x80;

			if (player.PLHAND != -1 && object.OCBLND[player.PLHAND].obj_type == Object::OBJT_SHIELD)
			{
				shD = (((int)shA << 8) | shB);
				shD2 = (((int)object.OCBLND[player.PLHAND].P_OCXX0 << 8) |
						 object.OCBLND[player.PLHAND].P_OCXX1);
				if (shD2 < shD)
				{
					shA = (shD2 >> 8);
					shB = (shD2 & 255);
				}
			}