Message-ID: <361BFA9E.6C32AF71@cue.satnet.net> Date: Wed, 07 Oct 1998 18:34:55 -0500 From: "Ronald Patiņo G" X-Mailer: Mozilla 4.04 [en] (Win95; I) MIME-Version: 1.0 To: "djgpp AT delorie DOT com" Subject: Raycasting help Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Hello . Can somebody help me with this raycaster (1440) 270 | | (960)180 -------o-------- 0 / 360 (0) (1920) | | 90 (480) this is the coordinate sistem i'm using. I'm a bit confused in the type of vars i should use for trig tables. I'm using a 7 * 7 (from 0 to 6) array as a map, only the borders have a 1 number and the rest are 0s , when i run the program the values calculed for the array subindex are mistaken . I'd appreaciate it a lot if you point out the mistakes i'm making . float _sin[1920]; float _cos[1920]; float _tan[1920]; void calc_tables() { double ang,radian; int angle; ang=0.1875; for(angle=0;angle <=angle_360; angulo++) { radian = ang * TO_RAD; _tan[angulo]=(float)tan(radian); _cos[angulo]=(float)cos(radian); _sin[angulo] =(float)sin(radian); ang=+0.1875; } } void xray(double x, double y, int ang_vis) { double vposx; double vposy; double vstepx; double vstepy; double vdistx; int vposmapx; int vposmapy; int wall_found=0; if ((ang_vis > angulo_270 ) || (ang_vis < angulo_90))//right vposx = (x/64) * 64 + 64; else vposx =(x/64) * 64 - 1; vposy = (y + (vposx - x)) * (_tan[ang_vis]); //step if ((ang_vis > angulo_270) || (ang_vis < angulo_90))//right vstepx = 64; else vstepx = -64; vstepy = 64 * _tan[ang_vis]; do { vposmapx = vposx / 64; vposmapy = vposy / 64; if (mapa[vposmapx][vposmapy] != 1) { wall_found = 1; } vposx += vstepx; vposy += vstepy; } while (!wall_found); } void yray(double x, double y, int ang_vis) { double hposx; double hposy; double hstepx; double hstepy; double hdisty; int hposmapx; int hposmapy; int wall_found=0; if ((ang_vis > angulo_180) || (ang_vis < angulo_360)) // up hposy = ((y/64) * 64) - 1; else hposy = ((y/64) * 64) + 64; hposx = (x + (hposy - y)) / _tan[ang_vis]; //calc step if ((ang_vis > angulo_180) || (ang_vis < angulo_360))// up hstepy = -64; else hstepy = 64; hstepx = 64/_tan[ang_vis]; do { hposmapx = hposx/64; hposmapy = hposy/64; if (mapa[hposmapx][hposmapy] !=0) { wall_found = 1; } hposx += hstepx; hposy += hstepx; } while (!wall_found); }