home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / 3DENGINE.ZIP / Objdraw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-04  |  1.7 KB  |  63 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "raycast.h"
  4. #include "objdraw.h"
  5. #include "trig.h"
  6.  
  7. // Function to draw a texture mapped polygon defined by
  8. // polytype parameter POLY clipped against a viewport with
  9. // upper lefthand coordinates of LEFTX,LEFTY and lower
  10. // righthand coordinates of RIGHTX,RIGHTY.
  11.  
  12. extern unsigned int dist[320];
  13.  
  14. void drawobject(objtype *obj,unsigned int distance, char *litelevel, unsigned char *bitmap)
  15. {
  16.   unsigned int bptr,sptr,sline;
  17.   unsigned long line;
  18.  
  19.   long fix_wincrement=(float)obj->wbit/obj->wdraw*SHIFT_MULT;
  20.   long fix_hincrement=(float)obj->hbit/obj->hdraw*SHIFT_MULT;
  21.   int sx=obj->screenx;
  22.   int sy=obj->screeny;
  23.   unsigned long column=0;
  24.   for (unsigned int x=0; x<obj->hdraw; x++) {
  25.      column+=fix_wincrement;
  26.      if ((sx >= VIEWPORT_LEFT) & (sx <= VIEWPORT_RIGHT)) {
  27.         int vert_offset=VIEWPORT_TOP-sy;
  28.         if (vert_offset>0) {
  29.             line=((long)vert_offset*fix_hincrement)+VIEWPORT_TOP;
  30.             sptr=(VIEWPORT_TOP <<8)+(VIEWPORT_TOP << 6)+sx;
  31.             bptr=(column>>16)+(((long)vert_offset*fix_hincrement)>>16)*obj->wbit;
  32.             sline=VIEWPORT_TOP;
  33.         }
  34.         else {
  35.           line=0;
  36.           sptr=(sy <<8)+(sy << 6)+sx;
  37.           bptr=column>>16;
  38.           sline=sy;
  39.         }
  40.         unsigned int lastline=line>>16;
  41.         if (((sx)>=VIEWPORT_LEFT) && ((sx)<=VIEWPORT_RIGHT)) {
  42.           if (distance<dist[sx]) {
  43.              for (unsigned int y=lastline; y<obj->wdraw; y++) {
  44.                 int b=bitmap[bptr];
  45.                 if (b&&((line>>16)<=VIEWPORT_BOT))
  46.                   screen_buffer[sptr]=litelevel[b];
  47.                 line+=fix_hincrement;
  48.                 int adv=(line>>16)-lastline;
  49.                 if (adv) {
  50.                   bptr+=obj->wbit*adv;
  51.                   lastline=line>>16;
  52.                 }
  53.                 sptr+=320;
  54.                 sline++;
  55.                 if (sline>VIEWPORT_BOT) break;
  56.              }
  57.           }
  58.         }
  59.      }
  60.      sx++;
  61.   }
  62. }
  63.