"Fossies" - the Fresh Open Source Software Archive

Member "veusz-3.1/veusz/helpers/src/threed/scene.h" (29 Aug 2019, 3600 Bytes) of package /linux/privat/veusz-3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "scene.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.0.1_vs_3.1.

    1 // -*-c++-*-
    2 
    3 //    Copyright (C) 2015 Jeremy S. Sanders
    4 //    Email: Jeremy Sanders <jeremy@jeremysanders.net>
    5 //
    6 //    This program is free software; you can redistribute it and/or modify
    7 //    it under the terms of the GNU General Public License as published by
    8 //    the Free Software Foundation; either version 2 of the License, or
    9 //    (at your option) any later version.
   10 //
   11 //    This program is distributed in the hope that it will be useful,
   12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 //    GNU General Public License for more details.
   15 //
   16 //    You should have received a copy of the GNU General Public License along
   17 //    with this program; if not, write to the Free Software Foundation, Inc.,
   18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19 /////////////////////////////////////////////////////////////////////////////
   20 
   21 #ifndef SCENE_H
   22 #define SCENE_H
   23 
   24 #include <vector>
   25 #include <QtGui/QPainter>
   26 #include "mmaths.h"
   27 #include "objects.h"
   28 #include "camera.h"
   29 
   30 class Scene
   31 {
   32 public:
   33   enum RenderMode {RENDER_PAINTERS, RENDER_BSP};
   34 
   35 private:
   36   // internal light color and position
   37   struct Light
   38   {
   39     Vec3 posn;
   40     double r, g, b;
   41   };
   42 
   43   // if passed to drawing routine, this is called after drawing each
   44   // fragment
   45   class DrawCallback
   46   {
   47   public:
   48     DrawCallback() {};
   49     virtual void drawnFragment(const Fragment& frag) = 0;
   50     virtual ~DrawCallback();
   51   };
   52 
   53 public:
   54   Scene(RenderMode _mode)
   55     : mode(_mode)
   56   {
   57   }
   58 
   59   // add a light to a list
   60   void addLight(Vec3 posn, QColor col, double intensity);
   61 
   62   // render scene to painter in coordinate range given
   63   // (if scale<=0 then automatic scaling)
   64   void render(Object* root,
   65               QPainter* painter, const Camera& cam,
   66               double x1, double y1, double x2, double y2, double scale);
   67 
   68   // find widget id of pixel painted by drawing scene at (x, y)
   69   unsigned long idPixel(Object* root, QPainter* painter, const Camera& cam,
   70                         double x1, double y1, double x2, double y2, double scale,
   71                         double scaling, int x, int y);
   72 
   73 public:
   74   // last screen matrix
   75   Mat3 screenM;
   76 
   77 private:
   78   // calculate lighting norms for triangles
   79   void calcLighting();
   80   void calcLightingTriangle(Fragment& frag);
   81   void calcLightingLine(Fragment& frag);
   82 
   83   // compute projected coordinates
   84   void projectFragments(const Camera& cam);
   85 
   86   void doDrawing(QPainter* painter, const Mat3& screenM, double linescale,
   87                  const Camera& cam, DrawCallback* callback=0);
   88 
   89   void drawPath(QPainter* painter, const Fragment& frag,
   90                 QPointF pt1, QPointF pt2, QPointF pt3,
   91                 double linescale, double distscale);
   92 
   93   // different rendering modes
   94   void renderPainters(const Camera& cam);
   95   void renderBSP(const Camera& cam);
   96 
   97   // render scene to painter in coordinate range given
   98   // (if scale<=0 then automatic scaling)
   99   void render_internal(Object* root,
  100                        QPainter* painter, const Camera& cam,
  101                        double x1, double y1, double x2, double y2, double scale,
  102                        DrawCallback* callback=0);
  103 
  104   // create pens/brushes
  105   QPen lineProp2QPen(const Fragment& frag, double linescale) const;
  106   QColor surfaceProp2QColor(const Fragment& frag) const;
  107   QBrush surfaceProp2QBrush(const Fragment& frag) const;
  108   QPen surfaceProp2QPen(const Fragment& frag) const;
  109 
  110 private:
  111   RenderMode mode;
  112   FragmentVector fragments;
  113   std::vector<unsigned> draworder;
  114   std::vector<Light> lights;
  115 };
  116 
  117 #endif