4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Radarsystem
#330389
06/27/10 11:50
06/27/10 11:50
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
OP
Senior Member
|
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:
#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: MasterQ32]
#330476
06/27/10 20:10
06/27/10 20:10
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
OP
Senior Member
|
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]
#331939
07/06/10 19:48
07/06/10 19:48
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
OP
Senior Member
|
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.
#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
Expert
|
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:
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:
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.
|
|
|
Re: Radarsystem
[Re: MasterQ32]
#331991
07/07/10 05:41
07/07/10 05:41
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
OP
Senior Member
|
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.
|
|
|
|