/**
	trace ray from (x1,y1) to (x2,y2) whatever the obstacles.
*/
void traceRayRGBA(SDL_Surface * image, int x1, int y1, int x2, int y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
	//lineRGBA(image, x1, y1, x2, y2, 255 , 255 , 255 , 255); // nearly equivalent (small algorithmic differences)

	Uint32 pixelColor = SDL_MapRGB( image->format, r, g, b );
	
	if ( abs(x1-x2) > abs (y1-y2) )
	{
		int it;
		
		double dy = double(y1-y2) / double(x1-x2);

		if ( (x1-x2) < 0 )
		{
			it=1;
		}
		else
		{
			it=-1;
			dy=-dy;
		}
		
		double yReal = y1;
		
		for ( int x = x1 ; x != x2 ; x = x + it )
		{
			putPixel32secure( image, x, (int)(yReal+0.5) , pixelColor );
			yReal += dy;
		}
	}
	else
	{
		int it;
		
		double dx = double(x1-x2) / double(y1-y2);

		if ( (y1-y2) < 0 )
		{
			it=1;
		}
		else
		{
			it=-1;
			dx=-dx;
		}
		
		double xReal = x1;
		
		for ( int y = y1 ; y != y2 ; y = y + it )
		{
			putPixel32secure( image, (int)(xReal+0.5), y , pixelColor );
			xReal += dx;
		}
	}

}
Beispiel #2
0
void InspectorAgent::show() // display on screen
{    
    //Show the dot
	int r,g,b;

	r = rand() % 255 ;
	g = rand() % 255 ;
	b = rand() % 255 ;

	int x = _x - gCamera.x;
	int y = _y - gCamera.y;
	
	
	int dx = 4;
	int dy = 4;

	for ( int i = -2 ; i < +3 ; i++ )
		putPixel32secure( gScreen, x + i , y , SDL_MapRGB( gScreen->format, r, g, b ) );
	for ( int j = -2 ; j < +3 ; j++ )
		putPixel32secure( gScreen, x , y + j, SDL_MapRGB( gScreen->format, r, g, b ) );

	for ( int i = x - dx ; i != x + dx + 1 ; i++ )
	{
		putPixel32secure( gScreen, i , y - dy , SDL_MapRGB( gScreen->format, r, g, b ) );
		putPixel32secure( gScreen, i, y + dy , SDL_MapRGB( gScreen->format, r, g, b ) );
	}

	for ( int j = y - dy ; j != y + dy + 1 ; j++ )
	{
		putPixel32secure( gScreen, x - dx, j , SDL_MapRGB( gScreen->format, r, g, b ) );
		putPixel32secure( gScreen, x + dx, j , SDL_MapRGB( gScreen->format, r, g, b ) );
	}


/*
	for ( int xTmp = -2 ; xTmp < +3 ; xTmp++ )
		putPixel32( gScreen, _x - gCamera.x + xTmp , _y - gCamera.y , SDL_MapRGB( gScreen->format, r, g, b ) );
	for ( int yTmp = -2 ; yTmp < +3 ; yTmp++ )
		putPixel32( gScreen, _x - gCamera.x , _y - gCamera.y + yTmp, SDL_MapRGB( gScreen->format, r, g, b ) );
*/
	
	// alternative: "apply_surface( _x - gCamera.x, _y - gCamera.y, gAgentMask, gScreen );"
}
Beispiel #3
0
/**
 * Display agent on screen. Add information caption if needed.
 *
 * (render mode only)
 */
void RobotAgent::show() // display on screen
{
	//Show the dot

	if (gNiceRendering) {
		if (gUseOrganisms && _connectToOthers == POSITIVE) {
			apply_surface(_x - gCamera.x, _y - gCamera.y, gAgentPositiveMaskImage, gScreen);
		} else if (gUseOrganisms && _connectToOthers == NEGATIVE) {
			apply_surface(_x - gCamera.x, _y - gCamera.y, gAgentNegativeMaskImage, gScreen);
		} else {
			apply_surface(_x - gCamera.x, _y - gCamera.y, gAgentMaskImage, gScreen); // OPTIONAL (agent is already visible/registered through the environment image -- but: may be useful for image capture
		}
	}

	if(gRenderRobotId){
		std::string str = "";
		str += boost::lexical_cast<std::string > (this->_wm->_agentId);
		RenderTextToSurface(str, _x + (gAgentWidth / 4) - gCamera.x, _y - gCamera.y, gScreen);
	}

	if (getWorldModel()->getRobotLED_status() == true) {
		int dx = 1;
		int dy = 1;
		int xcenter = (int)(_wm->_xReal + 0.5);
		int ycenter = (int)(_wm->_yReal + 0.5);
		int r = getWorldModel()->getRobotLED_redValue();
		int g = getWorldModel()->getRobotLED_greenValue();
		int b = getWorldModel()->getRobotLED_blueValue();

		for (int xTmp = xcenter - dx; xTmp != xcenter + dx + 1; xTmp++)
			for (int yTmp = ycenter - dy - 1; yTmp != ycenter + dy; yTmp++) {
				putPixel32secure(gScreen, xTmp - gCamera.x, yTmp + dy - gCamera.y, SDL_MapRGB(gScreen->format, r, g, b));
			}
	}


	if (_wm->_agentId == gAgentIndexFocus && gUserCommandMode) // && _iterations%10 < 5)
	{
		int dx = 10;
		int dy = 10;
		int xcenter = (int) _wm->_xReal + 0.5;
		int ycenter = (int) _wm->_yReal + 0.5;
		int r = 255.0 * ranf();
		int g = 255.0 * ranf();
		int b = 255.0 * ranf();

		for (int xTmp = xcenter - dx; xTmp != xcenter + dx + 1; xTmp++) {
			putPixel32secure(gScreen, xTmp - gCamera.x, ycenter - dy - gCamera.y, SDL_MapRGB(gScreen->format, r, g, b));
			putPixel32secure(gScreen, xTmp - gCamera.x, ycenter + dy - gCamera.y, SDL_MapRGB(gScreen->format, r, g, b));
		}

		for (int yTmp = ycenter - dy; yTmp != ycenter + dy + 1; yTmp++) {
			putPixel32secure(gScreen, xcenter - dx - gCamera.x, yTmp - gCamera.y, SDL_MapRGB(gScreen->format, r, g, b));
			putPixel32secure(gScreen, xcenter + dx - gCamera.x, yTmp - gCamera.y, SDL_MapRGB(gScreen->format, r, g, b));
		}

		//			for ( int xTmp = (int)_wm->_xReal - dx ; xTmp != (int)_wm->_xReal + dx + 1 ; xTmp++ )
		//				for ( int yTmp = (int)_wm->_yReal - dy ; yTmp != (int)_wm->_yReal + dy + 1 ; yTmp++ )
		//						putPixel32secure( gScreen, xTmp - gCamera.x, yTmp - gCamera.y , SDL_MapRGB( gScreen->format, 0xFF, 0x00, ranf() ) );
	}


	if (gDisplaySensors == true) {
		// * show orientation

		int xOrientationMarker = (int) (_wm->_xReal + 0.5) + gAgentWidth / 2 * cos(_wm->_agentAbsoluteOrientation * M_PI / 180);
		int yOrientationMarker = (int) (_wm->_yReal + 0.5) + gAgentWidth / 2 * sin(_wm->_agentAbsoluteOrientation * M_PI / 180);

		if (_wm->_agentId == gAgentIndexFocus && gUserCommandMode) {
			int g, b;
			g = b = (32 * _iterations % 256) > 128 ? 0 : 255;
			for (int xTmp = -2; xTmp != 3; xTmp++)
				for (int yTmp = -2; yTmp != 3; yTmp++)
					putPixel32secure(gScreen, xOrientationMarker - gCamera.x + xTmp, yOrientationMarker - gCamera.y + yTmp, SDL_MapRGB(gScreen->format, 0x00, b, g));
		} else {
			for (int xTmp = -2; xTmp != 3; xTmp++)
				for (int yTmp = -2; yTmp != 3; yTmp++)
					putPixel32secure(gScreen, xOrientationMarker - gCamera.x + xTmp, yOrientationMarker - gCamera.y + yTmp, SDL_MapRGB(gScreen->format, 0xFF, 0x00, 0x00));
		}

		// * show sensors

		for (int i = 0; i < _wm->_sensorCount; i++) {
			// Warning: the following is a repetition of code already in the move method (sensor ray casting) in order to display it (coordinates are not stored)
			double x1 = (_wm->_xReal + _wm->_sensors[i][1] * cos(_wm->_sensors[i][2] + _wm->_agentAbsoluteOrientation * M_PI / 180));
			double y1 = (_wm->_yReal + _wm->_sensors[i][1] * sin(_wm->_sensors[i][2] + _wm->_agentAbsoluteOrientation * M_PI / 180));
			double x2 = (_wm->_xReal + _wm->_sensors[i][3] * cos(_wm->_sensors[i][4] + _wm->_agentAbsoluteOrientation * M_PI / 180));
			double y2 = (_wm->_yReal + _wm->_sensors[i][3] * sin(_wm->_sensors[i][4] + _wm->_agentAbsoluteOrientation * M_PI / 180));

			// sensor ray casting is also performed in the move method -- this time we dont store data (already done). -- this one is only used to *display* the ray.
			/*_sensors[i][5] = */castSensorRay(gEnvironmentImage, x1, y1, &x2, &y2, _wm->getSensorMaximumDistanceValue(i)); // x2 and y2 are overriden with collision coordinate if ray hits object.

			// display on screen
			if (_wm->_sensors[i][5] < _wm->getSensorMaximumDistanceValue(i) - 1) //gSensorRange-1 )
				traceRayRGBA(gScreen, int(x1 + 0.5) - gCamera.x, int(y1 + 0.5) - gCamera.y, int(x2 + 0.5) - gCamera.x, int(y2 + 0.5) - gCamera.y, 255, 0, 0, 255);
			else
				traceRayRGBA(gScreen, int(x1 + 0.5) - gCamera.x, int(y1 + 0.5) - gCamera.y, int(x2 + 0.5) - gCamera.x, int(y2 + 0.5) - gCamera.y, 0, 0, 255, 255);
		}
	}


	// caption for storyzones

	if (gDisplayZoneCaption) {
		Uint32 pixel = getPixel32(gZoneImage, _x + gAgentWidth / 2, _y + gAgentHeight / 2);
		if (pixel != SDL_MapRGB(gZoneImage->format, 0x00, 0x00, 0x00)) // check if there's a "story" to display
		{
			// extract story index (if any)
			Uint8 r, g, b;
			SDL_GetRGB(pixel, gZoneImage->format, &r, &g, &b);
			int storyId = r; // assume the red component holds the story index.

			if (storyId >= 0 && storyId < 256 && gZoneCaptionImage[storyId] != NULL && gZoneStatus[storyId]) // security check: story exists?
			{
				// display story caption

				//set caption position
				int xCaption = 0, yCaption = 0;
				if (_x < gAreaWidth / 2)
					xCaption = _x - gCamera.x + 40;
				else
					xCaption = _x - gCamera.x - gZoneCaptionImage[storyId]->w - 40;
				if (_y < gAreaHeight / 2)
					yCaption = _y - gCamera.y + 40;
				else
					yCaption = _y - gCamera.y - gZoneCaptionImage[storyId]->h - 40;

				//display caption
				apply_surface(xCaption, yCaption, gZoneCaptionImage[storyId], gScreen);

				// update story flags (if needed)
				if (storyId >= 100 && storyId < 200 && storyId % 10 == 0) // key story, btw 100 and 199: activate story flag of the 9 next sub-stories
				{
					for (int i = 1; i != 10; i++)
						gZoneStatus[storyId + i] = true;
				} else
					if (storyId >= 200 && storyId < 256 && storyId % 10 != 9) // sub-story, btw 200 and 299: activate the next story flag (if not last)
					{
						gZoneStatus[storyId + 1] = true;
					}
			}
		}
	}
}