Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 7th_zorro), 923 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Radarsystem #330389
06/27/10 11:50
06/27/10 11:50
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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);
	}
}



Last edited by Razoron; 06/27/10 16:25.
Re: Radarsystem [Re: Razoron] #330435
06/27/10 16:59
06/27/10 16:59
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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?

Re: Radarsystem [Re: Razoron] #330455
06/27/10 18:31
06/27/10 18:31
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
for which use is the variable "drawoffset"?


Visit my site: www.masterq32.de
Re: Radarsystem [Re: MasterQ32] #330476
06/27/10 20:10
06/27/10 20:10
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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.

Last edited by Razoron; 06/27/10 20:11.
Re: Radarsystem [Re: Razoron] #331567
07/05/10 06:17
07/05/10 06:17
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
BAMP

Re: Radarsystem [Re: Razoron] #331939
07/06/10 19:48
07/06/10 19:48
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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?

Re: Radarsystem [Re: Razoron] #331951
07/06/10 20:23
07/06/10 20:23
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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

Last edited by Richi007; 07/06/10 20:23.

Visit my site: www.masterq32.de
Re: Radarsystem [Re: MasterQ32] #331991
07/07/10 05:41
07/07/10 05:41
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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.


Re: Radarsystem [Re: Razoron] #332024
07/07/10 10:24
07/07/10 10:24
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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.)


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Radarsystem [Re: Superku] #332067
07/07/10 14:36
07/07/10 14:36
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
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?

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1