Radarsystem

Posted By: Razoron

Radarsystem - 06/27/10 11:50

I'm currently working on a Radarsystem.
Note, that this is a multiplayer project.
If create a game with 2 players (2 planes), the Radarsystem is working correctly.
But if I create a game with 3 players, just one plane is shown correctly, the others are shown somewhere wrong.
Here is the code:
Code:
#define PROP_X (screen_size.x/1280)
#define PROP_Y (screen_size.y/1024)

void RadarMainLoop()
{
	int i;
	VECTOR draw;
	VECTOR drawoffset;
	PANEL*radarplanepan[30];
	while(ent_MyPlane==NULL)
	{
		wait(1);
	}
	while(enet_ent_globpointer(ent_MyPlane)==ANET_ERROR)
	{
		wait(30);
	}
	wait(-1);
	for(i=0;i<20;i++)
	{
		if(ent_Plane[i]!=NULL)
		{
			if(enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR)
			{
				radarplanepan[i]=pan_create(NULL,51);
				radarplanepan[i].bmap=img_hud_radarplane;
			}
		}
	}
	while(s_radar_active==TRUE)
	{
		for(i=0;i<20;i++)
		{
			if(ent_Plane[i]!=NULL)
			{
				if((abs(ent_Plane[i].x)+abs(ent_Plane[i].y)<=5000) && enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR && ent_Plane[i]!=ent_MyPlane)
				{
					draw.x=ent_MyPlane.x-ent_Plane[i].x;
					draw.x=draw.x/19.53;
					draw.y=ent_MyPlane.y-ent_Plane[i].y;
					draw.y=draw.y/19.53;
					draw.z=0;
					vec_set(drawoffset,vector(-8,-8,0));
					vec_rotate(drawoffset,ent_MyPlane.pan+180);
					vec_rotate(draw,ent_MyPlane.pan+180);
					draw.x+=(1024-8*PROP_X)*PROP_X;
					draw.y+=(768-8*PROP_Y)*PROP_Y;
					radarplanepan[i].pos_x=draw.x;
					radarplanepan[i].pos_y=draw.y;
					radarplanepan[i].angle=ent_Plane[i].pan;
					mgs=draw.x;
					parachutes=draw.y;
					set(radarplanepan[i],SHOW);
				}
			}
		}
		wait(1);
	}
}


Posted By: Razoron

Re: Radarsystem - 06/27/10 16:59

Okay, there is something wrong with the angle, that the distance to the middlepoint of the radar rotates. The radar is rotating with your airplane.
The distance is correct, but the angle is wrong. Didn't I use vec_rotate correctly?
Posted By: MasterQ32

Re: Radarsystem - 06/27/10 18:31

for which use is the variable "drawoffset"?
Posted By: Razoron

Re: Radarsystem - 06/27/10 20:10

Okay, ich schreibs mal in Deutsch, ist schwierig in Englisch auszudrücken. Also, wenn ein Flugzeug an einer bestimmten Position im Radar wäre, würde genau an dem Punkt das PANEL mit dem Pfeil, der für das Flugzeug steht, sein. Aber da das Bild von dem Pfeil 16*16 Pixel groß ist, wäre der Pfeil 8 Pixel zu weit an der X-Achse und 8 Pixel zu weit an der Y-Achse. Deshalb muss man das PANEL etwas verschieben. Das ist zwar nur ein kleiner Genauigkeitsfehler, aber wenn ich das weg lasse, ist der Fehler auch noch da. Von da her kann es nichts damit zu tun haben.
Posted By: Razoron

Re: Radarsystem - 07/05/10 06:17

BAMP
Posted By: Razoron

Re: Radarsystem - 07/06/10 19:48

BUUAH, ich raste gleich aus. Ich mach nicht weiter, bis ich das Problem gefunden habe. Also nochmal ein paar News und einen auskommtierten Code.
Es geht jetzt doch bei keinem Flugzeug, auch nicht bei 2. Es hat wohl durch irgendeinen Zufall mal der Winkel gestimmt.
Code:
#define PROP_X (screen_size.x/1280)
#define PROP_Y (screen_size.y/1024)

void RadarMainLoop()
{
	int i; //Loop integer
	VECTOR draw; //The point, where the plane symbol should be drawn on the radar
	VECTOR drawoffset; //The Symbol of the plane is 16*16 pixel big. So the position has to be corrected.
	VECTOR temp; //Temporary vector
	while(ent_MyPlane==NULL) //As long my plane doesn't exists, wait
	{
		wait(1);
	}
	while(enet_ent_globpointer(ent_MyPlane)==ANET_ERROR) //As long my plane isn't a global plane
	{
		wait(30);
	}
	wait(-1); //Wait for other planes
	for(i=0;i<20;i++) //20 loops
	{
		if(ent_Plane[i]!=NULL) //Tests all Planes if they are aviable and if they are aviable, create a panel and a bmap for the symbol
		{
			if(enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR) //Check again
			{
				radarplanepan[i]=pan_create(NULL,51); //Create panel for symbol
				radarplanepan[i].bmap=img_hud_radarplane; //Create the image for the symbol
			}
		}
	}
	while(s_radar_active==TRUE) //As long the radar is active
	{
		for(i=0;i<20;i++) //Loop threw all aviable planes and update their position on the radar
		{
			if(ent_Plane[i]!=NULL) //Check if the Plane REALLY exists, else it would crash
			{
				if(((abs(ent_Plane[i].x)-abs(ent_MyPlane.x))+(abs(ent_Plane[i].y)-abs(ent_MyPlane.y)))<=5000 && enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR && ent_Plane[i]!=ent_MyPlane)
				//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
				//If the distance to the plane and my plane is smaller than 5000 quants and the plane really exists,
				//draw the plane on the radar.
				{
					draw.x=ent_MyPlane.x-ent_Plane[i].x;//The difference of the x position of my plane and the other one
					draw.x=draw.x/39.0625; //Make it proportional to the screen and radar.
					//The radar has a radius of 128, that means 5000/128=39.0625
					draw.y=ent_MyPlane.y-ent_Plane[i].y;
					draw.y=draw.y/39.0625;
					draw.z=0;//We don't need the Z value, it's on the screen
					vec_set(drawoffset,vector(8,8,0)); //Set the offset because the symbol is 16*16 pixel big and the draw position would be on the top left corner. It should be in the middel of the symbol.
					vec_rotate(drawoffset,camera.pan); //Rotate the offset with the camera. The radar is rotating with the plane
					vec_rotate(draw,camera.pan+180); //Rotate the draw position with the camera. The radar is rotating with the plane
					draw.x+=(896-drawoffset.x*PROP_X)*PROP_X; //Add the radar position, subtract the offset and make it proportional to the screen resolution
					draw.y+=(640-drawoffset.y*PROP_Y)*PROP_Y; //Same here
					radarplanepan[i].pos_x=draw.x; //Set the panel position to the draw position
					radarplanepan[i].pos_y=draw.y; //Same
					radarplanepan[i].angle=ent_Plane[i].pan; //Set the angle of the panel to the in which direction the plane is looking at
					set(radarplanepan[i],SHOW); //Show the symbol
				}
				else //If the plane is toofar away or whatever
				{
					reset(radarplanepan[i],SHOW);	//Hide the symbol
				}
			}
		}
		wait(1); //Would freeze the engine
	}
}


I hope somebody can help me. Or should I move it to unanswered questions?
Posted By: MasterQ32

Re: Radarsystem - 07/06/10 20:23

du könntest auch ein PANEL in jeder action eines Flugzeugs machen, die sich dann aktualisiert, wenn dein Radar aktiv ist. So hab ich meine Radarprobleme gelöst.
Der Code sollte dann auch bei multiplayer funktionieren, da man ja feststellen kann, ob das Flugzeug ein spieler oder der Spieler ist. Außerdem könnten so auch Flugzeuge später beitreten und trotzdem auf dem Radar angezeigt werden.

Hier könnte auch ein Fehler sein:
Code:
vec_set(drawoffset,vector(8,8,0));
vec_rotate(drawoffset,camera.pan);

warum vec_rotate?
das panel kann wird um einen internen Offset gedreht werden. Du brauchst blos das offset ungedreht abziehen.
Beispiel aus dem Manual:
Code:
PANEL* pan;
// rotate a panel about its center
function pan_rotate(p)
{
  pan = p; // set the panel pointer from the function parameter
  pan.center_x = pan.size_x * 0.5; // set the rotation center at the panel center
  pan.center_y = pan.size_y * 0.5;
  while (pan.angle < 360)          // one full rotation
  { 
     pan.angle += 10*time_step;
     wait(1);
     pan = p; // local variables are preserved during wait(), global pointers aren't
  }
  pan.angle = 0; 
}



EDIT: Hoffentlich hilfts
Posted By: Razoron

Re: Radarsystem - 07/07/10 05:41

Danke für deine Mühe, bloß das einzige Problem ist der Winkel. Das Radar dreht sich mit dem Flugzeug mit, das bedeutet, wenn man ein Flugzeug direkt vor einem sieht, muss es auch direkt gearde vor einem auf dem Radar zu sehen sein.
Hier ist das der Fall. Der Abstand stimmt, der Winkel nicht. Und ich meine nicht den Winkel, mit dem der Pfeil rotiert ist, das ist fürs erste egal.
Ich meine den Winkel, mit dem draw rotiert wird.

Posted By: Superku

Re: Radarsystem - 07/07/10 10:24

Ich hab 2006 mal eines programmiert, ist dementsprechend nicht sonderlich toll geschrieben und in C-Script, aber vllt hilft es dir ja weiter:

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=62250&page=1

(Der Download-Link ist down, weiß ich, aber im selben Post steht der Code, den ich meine. Du solltest vllt besser den Code nehmen, den ich im ca. 11. Post schrieb.)
Posted By: Razoron

Re: Radarsystem - 07/07/10 14:36

Werde ich warscheinlich mal ausprobieren. Aber ich wollte das ja ganz anders machen. Nichts in die Funktion einarbeiten. Da kommt es meistens bei Multplayerspielen zu irgendwelchen Fehlern. Das hatt ich schon oft...
Versteht irgendwer den Code nicht?
Posted By: Superku

Re: Radarsystem - 07/07/10 14:40

Das ist ja egal, den Code kannst du ja über alle Objekte iterieren. Ich habe dir den geschickt, damit du gucken kannst, wie ich damals die Position samt Rotation berechnete.
Posted By: Razoron

Re: Radarsystem - 07/07/10 15:16

Hm, okay ich hab ihn jetzt soweit einigermaßen verstanden. laugh
Sag mir nur mal, was skill97 ist. Du hast das mit Sinus und Kosinus gelöst. laugh
Posted By: Superku

Re: Radarsystem - 07/07/10 15:17

skill97 ist einfach nur ein temporärer pan-Wert, gesetzt durch
"vec_to_angle(my.skill97,temp);"
Posted By: Razoron

Re: Radarsystem - 07/08/10 08:42

Okay, Winkel und Positionen gehen jetzt richtig.
Es gibt aber immer noch ein Problem mit der größe der Pfeile.
Sie sind 16*16 Pixel groß. Hier das Problem:
Der korrekte Punkt, an dem sich das Flugzeug befindet:

Und wenn man jetzt den Pfeil an dem Punkt als Panel anbringt, stimmt das nicht:

Das kann man aber ganz einfach, da der Pfeil genau 16*16 Pixel groß ist, die pos_x und die pos_y um 8 verkleinern.
Aber was ist, wenn man jetzt den Pfeil noch rotiert?

Wie kann man das lösen?
Ich weiß, die Bilder sind hübsch grin.

EDIT: Ihr wisst immer noch nicht, was ich meine?
Ich möchte es SO haben:

oder helt bei einer Drehung so:

Posted By: Superku

Re: Radarsystem - 07/08/10 11:16

pan.center_x = pan.size_x * 0.5; // set the rotation center at the panel center
pan.center_y = pan.size_y * 0.5;


Aus dem Manual.
Posted By: Razoron

Re: Radarsystem - 07/08/10 12:25

Danke, es geht. Ich dachte center_x/y macht was anderes.
Posted By: Razoron

Re: Radarsystem - 07/10/10 12:07

Okay, es gibt noch ein Problem:
Wenn ich das Flugzeug drehe, ist die Laufbahn bei einer Drehung des Symbols oval.
Wenn die Flugzeuge Schnauze zu Schnauze gerichtet sind, also aufeinander gucken, bewegst sich das symbol fast nur noch auf der X-Achse, wenn sie Flügel zu Flügel gerichtet sind, also nebeneinander stehen, bewehst sich das Symbol fast nur auch der Y-Achse. Dazwischen ist die Laufbahn bei einer Drehung kreisrund, wie es sein soll.

EDIT: Ach ja, hier nochmal der Code. Nicht über die Kommentare nachdenken, die sind alt.
Code:
draw.x=ent_MyPlane.x-ent_Plane[i].x;//The difference of the x position of my plane and the other one
					draw.x=-(draw.x/7.8125); //Make it proportional to the screen and radar.
					//The radar has a radius of 128, that means 5000/128=39.0625
					draw.y=ent_MyPlane.y-ent_Plane[i].y;
					draw.y=-abs(draw.y/7.8125);
					draw.z=0;//We don't need the Z value, it's on the screen
					vec_set(temp,ent_Plane[i].x);
					vec_sub(temp,ent_MyPlane.x);
					vec_to_angle(temp2,temp);
					vec_set(drawoffset,vector(8,8,0)); //Set the offset because the symbol is 16*16 pixel big and the draw position would be on the top left corner. It should be in the middel of the symbol.
					draw.x*=sin(camera.pan-temp2.pan);
					draw.y*=cos(camera.pan-temp2.pan);
					mgs=sin(camera.pan-temp2.pan);
					parachutes=draw.x;
					draw.x+=896*PROP_X; //Add the radar position, subtract the offset and make it proportional to the screen resolution
					draw.y+=640*PROP_Y; //Same here


© 2024 lite-C Forums