Game Development Community

Radar Gui Need Help

by Andrea Barolo · in Torque Game Engine · 05/11/2007 (4:33 am) · 6 replies

Hello to everyone !! Im doing y first steps on OpenGL programing ad Im trying to draw a realistic rotationg radar swept on the screen for a gui that Im buildong !! To do this I put my method on dgl.cc file and the code I wrote is this :

void dglDrawRadar(const Point2I &center, const S32 radius, const ColorI &color, const U32 spin){

	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  
	// glBlendFunc(GL_ONE, GL_ONE);

	glShadeModel (GL_SMOOTH);
	glClearColor (0.0, 0.0, 0.0, 0.0);

	glBegin(GL_TRIANGLE_FAN);
	glColor4ub(color.red, color.green, color.blue, color.alpha);
	glVertex3f(center.x + 0.5,center.y +0.5,0.0);
    U32 U = 0;
	for (int i=0+ spin; i <= 360+ spin; i+=3)
	{
		float degInRad = mDegToRad((F32)i);
		
		glVertex3f(center.x + sin(degInRad)*radius+ 0.5,center.y + cos(degInRad)*radius+0.5,0.0);
		glColor4ub((U<255)?U:color.red,color.green,color.blue,color.alpha);
		U++;

	}

	glEnd();
}


If you continualy change the spin variable with a value between 0 and 360 you can se the swept rotating !!
The problem IS the color !!! I cannot obtain the right color smooth.
So, is there someone can help me ?
Than you

#1
05/14/2007 (7:07 am)
EUREKA !!! I have made it !!
This is the code to have a good spinning rardar with color smoothing !!! like this edu.let.unicas.it/museworld/images/radar.jpg

this is te code:
void dglDrawRadar(const Point2I &center, const S32 radius, const ColorI &color, const U32 spin){

	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
	// glBlendFunc(GL_ONE, GL_ONE);

	glShadeModel (GL_SMOOTH);
	glClearColor (0.0, 0.0, 0.0, 0.0);

	glBegin(GL_TRIANGLE_FAN);
	glColor4ub(color.red, color.green, color.blue, color.alpha);
	glVertex3f(center.x + 0.5,center.y +0.5,0.0);
    U32 U = 255;
	for (int i=0+ spin; i <= 360+ spin; i+=3)
	{
		float degInRad = mDegToRad((F32)i);
		
		glVertex3f(center.x + sin(degInRad)*radius+ 0.5,center.y + cos(degInRad)*radius+0.5,0.0);
		glColor4ub((U>color.red)?U:color.red,(U>color.green)?U:color.green,(U>color.blue)?U:color.blue,color.alpha);
		
		if(U>0)
		  U-=5;

	}

	glEnd();
}

I you have any suggestions please tell me !!
#2
05/14/2007 (7:35 am)
Very Nice...
#3
05/14/2007 (7:50 am)
Can you make a resource for it & make it track players/ai? btw: its [url] and not [link] for links. :)
#4
05/14/2007 (4:36 pm)
@andrea: great work on getting this to work, think it might come in useful

@mb: certainly possible to get it to track player positions. would work nicely too.
#5
05/15/2007 (1:50 am)
Yes , when I'll have time I'll do for sure, I have also a clock gui and a counter gui to post !!!
In the meantime you can can easily integrate it to the existing radar gui :

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2270

Add my code to the dgl.cc and dgl.h files like the dgl dglDrawBitmapRotated added function.
then call my function into the onRender method of the guiRadarCtrl class in this way :


dglDrawRadar(<<
>> , <<>>,ColorI(200,20,20,80),mRadarSpin);

and use this after the draw radar call:

mRadarSpin = (mRadarSpin==1)?360:mRadarSpin-1;


you then must initialize mRadarSpin = 360 into the constructor of the class !!


It should work for now !!! I hope to have time to put all to a resorce asap.

Feel free to make corrections and suggestions: this is a resource I whant to shere to everyone and I hope someone come to improve it because these are my first steps on openGL programming !!!
#6
05/15/2007 (12:49 pm)
Yeah I've used the radar gui resource in the past it works well, if you get round to coding then perhaps the addition of some form of alerts to the radar... for example to highlight objective locations, items to pickup, etc could be useful.