// // Base class for scene item handling // // Copyright (C) J. Belson 2001.12.06 // // $Author: jon $ : $Date: 2003/05/30 17:50:43 $ // #ifndef _HANDLER_BASE_H_ #define _HANDLER_BASE_H_ #include "fcolour.h" #include "frustrum.h" #include "hfield.h" #include "matrix.h" #include "point2d.h" #include "point3d.h" #include "progress.h" #include "renderer.h" #include "settings.h" #include "vector2d.h" #include "vector3d.h" #include "zbuffer.h" #include "render_info.h" struct point_info { const point3d& point; bool height_valid; float height; point_info(point3d& p) : point(p) { height_valid = false; } }; /** * Abstract base for classes which render height fields */ class handler_base { private: // Has user cancelled? bool cancelled; protected: point3d viewpoint; // View position matrix camera; // Camera transformation matrix vector3d light; // Position of sun float threshold; int scene_width, scene_height; int map_width; float offset_x, offset_y; float scale_x, scale_y; float distance; // Distance to projection plane const render_info& rinfo; fcolour water_colour; // Base water colour float fov; frustrum view_frustrum; enum { DEFAULT_DISTANCE = 10 }; // Rendering options bool textures; bool shadows; bool reflections; bool atmospherics; bool backface_cull; bool frustrum_cull; settings* my_settings; void set_cancelled(void); // Recursively subdivide according to camera position void subdivide(float x, float y, float size, float h1, float h2, float h3, float h4); // Calculate height for specified point virtual float get_height(float x, float y) = 0; virtual void process_patch(const point3d& p1, const point3d& p2, const point3d& p3, const point3d& p4) = 0; // Calculate the reflection of vector '-v' from a surface with normal 'n' vector3d get_reflection(const vector3d& n, const vector3d& v); void transform(/*vector3d* norm,*/ point3d* points, int num_points); void transform_normals(triangle3d* tri, int num_tri); void perspective(point3d* points3d, point2d* points2d, int num_points); // Is this polygon facing us? bool check_backface(const vector3d& n, const vector3d& v); // Does point lie within viewing frustrum? bool check_frustrum(const point3d& p); public: handler_base(int w, int h, const render_info& info); virtual ~handler_base(); virtual void render(void) = 0; // Set camera position and viewing direction void set_camera(const point3d& p, const matrix& m); void set_textures(bool b); void set_shadows(bool b); void set_reflections(bool b); void set_atmospherics(bool b); //void set_detail(int detail); void set_progress(progress* p); void set_threshold(float thresh); // Set distance to projection plane void set_distance(float dist); virtual void set_heightfield(hfield* hf); }; #endif // _HANDLER_BASE_H_