home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / z_buffer.h < prev   
C/C++ Source or Header  |  1992-10-20  |  2KB  |  68 lines

  1. /*
  2.  * Z_Buffer.h - class definition for zBuffer renderer.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #ifndef Z_Buffer_H
  19. # define Z_Buffer_H
  20.  
  21. #include <stdio.h>
  22. #include "Vector.h"
  23. #include "ViewTransform.h"
  24. #include "Color.h"
  25. #include "Polygon.h"
  26.  
  27. //___________________________________________________________ Z_Buffer
  28. class EdgeList;
  29.  
  30. class Z_Buffer
  31. {
  32. public:
  33.   Z_Buffer(ViewTransform* v, const rcString& msg, const rcString& oname);
  34.   ~Z_Buffer();
  35.  
  36.   void renderTriangle(const Color&, const Vector&, const Vector&, const Vector&);
  37.   void renderRectangle(const Color&, 
  38.                const Vector&, const Vector&, const Vector&, const Vector&);
  39.   void renderPolygon(const Color&, Polygon*);
  40.  
  41.   void writePixmap();
  42.   long primitives() const;
  43.  
  44. private:
  45.   void addEdge(const Vector&, const Vector&);
  46.   void render();
  47.   void calculateColor(const Color&, const Vector&, const Vector&);
  48.  
  49. private:
  50.   rcString remark;     // remark for the ppm-File
  51.   ViewTransform* view; // view transformation to apply
  52.   int resX, resY;      // screen resolution
  53.   FILE* outfile;       
  54.  
  55.   EdgeList** yBuckets;
  56.   float* zBuffer;
  57.   unsigned char* pixmap;
  58.   float R, G, B;       // current color
  59.   int ymin, ymax;      // height of current polygon
  60.   long numPrimitives;  // number of primitives already drawn
  61. };
  62.  
  63. inline long Z_Buffer::primitives() const {
  64.   return numPrimitives;
  65. }
  66.  
  67. #endif // Z_Buffer_H
  68.