home *** CD-ROM | disk | FTP | other *** search
- /*
- ***********************************************************************
- *
- * Full-color (full-gray)
- * (Sub)windows displaying an image in 2D/3D
- *
- * These subwindow create an image view in a OffScreen buffer, which has to
- * be bound later to something on-screen (a window, a dialog user item, etc)
- *
- ***********************************************************************
- */
- #pragma once
-
- #include "ElevationMap.h"
- #include "window.h"
-
-
- struct ViewerPosition
- {
- int xe, ye; // Location of an observation point
- int gx, gy; // Gaze vector (of size |g|=1<<14)
- enum { g_unit = 1<<14 }; // |g|, size of the gaze vector
- ViewerPosition(const int _xe, const int _ye, const int _gx, const int _gy)
- : xe(_xe), ye(_ye), gx(_gx), gy(_gy)
- { assert( gx*gx + gy*gy == g_unit*g_unit ); // Just to test our assumptions
- }
- void dump(void) const; // Dump the contents of it
- };
-
- struct ProjectionParameters
- {
- int ze; // Elevation of the view point
- int beta; // Local coordinates scaling factor
- const int u_sup, v_sup; // Define the view port dimensions
- int Ou, Ov; // Origin of the local coordinate ref Pt
-
- ProjectionParameters(const ScreenRect& bounds, const int _ze, const int _beta);
- ScreenRect q_view_rect(void) const { return ScreenRect(v_sup,u_sup); }
- int q_width(void) const { return u_sup; }
- int q_height(void) const { return v_sup; }
- void dump(void) const; // Dump the contents of it
- };
-
- // Picture view in 2d
- class ImageView : public OffScreenBuffer
- {
- ImageView(const ImageView&); // Left unimplemented: copying/cloning of
- ImageView& operator = (const ImageView&); // ImageView is not allowed
- public:
- ImageView(const ElevationMap& elev_image);
- };
-
-
- // Picture view in 3d
- class ThreeDViewBase : public OffScreenBuffer
- {
- protected:
- const ElevationMap& map; // Image to view
- const ViewerPosition& viewer_pos; // To get the view parameters from
- const ProjectionParameters& projection_parms;
-
- ThreeDViewBase(const ThreeDViewBase&); // Left unimplemented: copying/cloning of
- ThreeDViewBase& operator = (const ThreeDViewBase&); // ThreeDViewBase is not allowed
-
-
- // A class to handle one scanline of the view plane
- class OneViewScanline
- {
- friend class ScanLineAccess; // needed for a member function kludge
-
- OneViewScanline(const OneViewScanline&); // Left unimplemented: copying/cloning of
- OneViewScanline& operator = (const OneViewScanline&); // OneViewScanline is not allowed
-
- public:
- struct ScanPoint { // A scan point at some given u
- int v; // visible elevation (note, PowerPC prefers ints to short)
- int color; // color of a point (taken off the map)
- };
-
- OneViewScanline(const int _width);
- ~OneViewScanline(void);
-
- int q_width(void) const { return width; }
- void print(const card i=0) const; // print a scanline point
-
- private:
- const int width; // width of a scanline
- ScanPoint * const scan_points; // scanpoints of a scanline
-
- };
-
- OneViewScanline scanline1, scanline2; // Two working scanlines
-
- virtual void prepaint(void); // Prepare the buffer (eg, clean it)
- public:
- ThreeDViewBase(const ElevationMap& image_map, const ViewerPosition& viewer_pos,
- const ProjectionParameters& projection_parms);
- void dump(const char title [] = "") const;
- };
-
- template <class LineProjector> class ThreeDView : public ThreeDViewBase
- {
- public:
- ThreeDView(const ElevationMap& image_map, const ViewerPosition& viewer_pos,
- const ProjectionParameters& projection_parms);
- void project(void); // Draw a projection in an offscreen
- // world
- };
-
-