Mail Archives: djgpp/1999/03/16/15:50:48
In case it was not clear here is the acutal code I'm tying to display the
results with. Right now I just want a swwep from 5 to 85 degrees, If I can
get this to work the second qudrant shouldn't be that hard.
Thanks
Ringo
// Sonarplt Sonar Plot for mapping a room
// to compile gcc sonarplt.c -lalleg -lm
#include <conio.h> // For the getch() function.
#include <stdio.h>
#include "allegro.h"
#include <math.h>
#include <dos.h>
#define cone 10
void Plot_beam(int angle,int range,int conew,int color);
int main()
{
//screen is 640 W 480 H
int angle;
int range;
allegro_init();
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
clear(screen);
while(!kbhit())
{
textout(screen, font, "Sonar Ranging demo", 280, 470, 2);
line(screen, 1,240, 630,240, 15);
circle(screen, 320,240,10, 15);
range=200;
for(angle=5;angle<85;angle=angle+5)
{
Plot_beam(angle,range,cone,15);
Plot_beam(angle,range,cone,255);
}
}
allegro_exit();
return 0;
}
void
Plot_beam(int angle,int range,int conew,int color)
{
int temprange=0;
double x1,x2,y1,y2;
int xa,xb,ya,yb;
int posangle,negangle;
for(temprange=15;temprange<range;temprange=temprange+15)
{
delay(100);
posangle=angle+(conew/2);
negangle=angle-(conew/2);
x1=temprange*cos(posangle); /* get x & y Co-ords */
y1=temprange*sin(posangle);
x2=temprange*cos(negangle);
y2=temprange*sin(negangle);
xa=abs((int)x1); /* change to ints and get abs */
xb=abs((int)x2); /* abs is to set to first quadrant */
ya=abs((int)y1);
yb=abs((int)y2);
xa=320+xa; /* make origin center of screen*/
xb=320+xb;
ya=240-ya;
yb=240-yb;
line(screen, xa,ya, xb,yb, color); /* draw the lines*/
}
}/* end of Plot beam
- Raw text -