/** * \brief Returns all nonzero points in image into x- and y-coordinate sets */ void getPointsFromImageHough(int *Px, int *Py, int *numPoints) { unsigned char* rawROI = NULL; int ssize; cvGetRawData(zeta, &rawROI, &ssize, NULL); int num = cvCountNonZero(zeta); num = 0; int i,j; for (j = max_of_2(0,yGuess - height); j < min_of_2(height, yGuess + height); j++){ for (i = max_of_2(0, xGuess - width); i < min_of_2(width, xGuess + width); i++){ if (rawROI[i+j*width] != 0){ Px[num] = i; Py[num] = j; num++; } } } *numPoints = num; }
/*! * \brief Processes using Hough Transform and outputs solutions and time taken to file */ void runHoughTransform(int fileType) { int *Px, *Py, count = 1; int numPoints = 0; initializeHough(&Px, &Py); do { totalProcessingTime = 0; printf("Running frame %d...\n", count); filterFrame(); getPointsFromImageHough(Px, Py, &numPoints); gettimeofday(&t0, 0); do_hough(Px, Py, numPoints, hough_array, 0, width, height); gettimeofday(&t1, 0); float deltaTime = (t1.tv_usec - t0.tv_usec); printf("Took %f microseconds to process\n", deltaTime); totalProcessingTime += deltaTime; //fprintf("Frame(%d) Solution(%f, %f) Time(%f) Method(1)", count, xGuess, yGuess, deltaTime); findIntersectionFirstFrame(slope[0], slope[1], yIntercept[0], yIntercept[1]); xGuess = min_of_2(width,xGuess); yGuess = min_of_2(height,yGuess); xGuess = max_of_2(0,xGuess); yGuess = max_of_2(0,yGuess); if ((xGuess*yGuess) ==0) {xGuess=width/2; yGuess=height/2;} printf("Found intersection (%f, %f)\n", xGuess, yGuess); fprintf(oFile, "%d, %f, %f, %f, ", count, xGuess, yGuess, totalProcessingTime); fprintf(oFile, "%f, %f, %f, %f, %d \n", slope[0], yIntercept[0],slope[1], yIntercept[1], 1 ); fflush(stream); updateDisplay(); count++; grabNextFrame(fileType, count); if(count > 46) break; } while(frame); free(Px); free(Py); }
/* ----------------------------------------------------------------------------- Function: Parameters: Returns: Notes: ----------------------------------------------------------------------------- */ PUBLIC void fire_lead( player_t *self ) { entity_t *closest; int damage; int dx, dy, dist; int d1, shot_dist, n; switch( self->weapon ) { case WEAPON_PISTOL: Sound_StartSound( NULL, 0, CHAN_WEAPON, Sound_RegisterSound( "sfx/012.wav" ), 1, ATTN_NORM, 0 ); break; case WEAPON_AUTO: Sound_StartSound( NULL, 0, CHAN_WEAPON, Sound_RegisterSound( "sfx/011.wav" ), 1, ATTN_NORM, 0 ); break; case WEAPON_CHAIN: Sound_StartSound( NULL, 0, CHAN_WEAPON, Sound_RegisterSound( "sfx/013.wav" ), 1, ATTN_NORM, 0 ); break; } self->madenoise = true; dist = 0x7fffffffl; closest = NULL; for( n = 0 ; n < NumGuards; ++n ) { if( Guards[ n ].flags & FL_SHOOTABLE ) // && Guards[n].flags&FL_VISABLE { shot_dist = Point2LineDist( Guards[ n ].x - self->position.origin[ 0 ], Guards[ n ].y - self->position.origin[ 1 ], self->position.angle ); if( shot_dist > (2 * TILEGLOBAL / 3) ) { continue; // miss } d1 = LineLen2Point( Guards[ n ].x - self->position.origin[ 0 ], Guards[ n ].y - self->position.origin[ 1 ], self->position.angle ); if( d1 < 0 || d1 > dist ) { continue; } if( ! Level_CheckLine( Guards[ n ].x, Guards[ n ].y, Player.position.origin[0], Player.position.origin[1], r_world ) ) { //if( ! CheckLine( &Guards[ n ] ) ) continue; // obscured } dist = d1; closest = &Guards[ n ]; } } if( ! closest ) // missed { r_trace_t trace; trace.a = NormalizeAngle( self->position.angle - DEG2FINE( 2 ) + rand() % (DEG2FINE( 4 ) ) ); trace.x = self->position.origin[ 0 ]; trace.y = self->position.origin[ 1 ]; trace.flags = TRACE_BULLET; trace.tile_vis = NULL; R_Trace( &trace, r_world ); if( trace.flags & TRACE_HIT_DOOR ) { Sound_StartSound( NULL, 0, CHAN_AUTO, Sound_RegisterSound( "lsfx/028.wav" ), 1, ATTN_NORM, 0 ); } return; } // hit something dx = ABS( closest->tilex - self->tilex ); dy = ABS( closest->tiley - self->tiley ); dist = max_of_2( dx, dy ); if( dist < 2 ) { damage = US_RndT() / 4; } else if( dist < 4 ) { damage = US_RndT() / 6; } else { if( US_RndT() / 12 < dist ) { return; // missed } damage = US_RndT() / 6; } A_DamageActor( closest, damage ); }