SCM Library
Spherical Cube Map rendering library
 All Classes Files Functions Variables Friends Pages
scm-sphere.hpp
1 // Copyright (C) 2011-2012 Robert Kooima
2 //
3 // LIBSCM is free software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the Free Software
5 // Foundation; either version 2 of the License, or (at your option) any later
6 // version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef SCM_MODEL_HPP
14 #define SCM_MODEL_HPP
15 
16 #include <GL/glew.h>
17 #include <vector>
18 #include <set>
19 
20 #include "scm-scene.hpp"
21 
22 //------------------------------------------------------------------------------
23 
29 
31 {
32 public:
33 
34  scm_sphere(int d, int l);
35  ~scm_sphere();
36 
37  void set_detail(int d);
38  void set_limit (int l);
39 
40  int get_detail() const { return detail; }
41  int get_limit () const { return limit; }
42 
43  void prep(scm_scene *, const double *, int, int, int, bool);
44  void draw(scm_scene *, const double *, int, int, int, int);
45 
46  void set_zoom(double x, double y, double z, double k);
47 
48 private:
49 
50  int detail;
51  int limit;
52 
53  // Zooming state.
54 
55  double zoomv[3];
56  double zoomk;
57 
58  void zoom(double *, const double *);
59 
60  // Data structures and algorithms for handling face adaptive subdivision.
61 
62  std::set<long long> pages;
63 
64  bool is_set (long long i) const { return (pages.find(i) != pages.end()); }
65  void set_page(long long i);
66 
67  void add_page(const double *, int, int, double, double, long long, bool);
68  double view_page(const double *, int, int, double, double, long long, bool);
69  void debug_page(const double *, double, double, long long);
70 
71  bool prep_page(scm_scene *, const double *, int, int, int, long long, bool);
72  void draw_page(scm_scene *, int, int, int, long long);
73 
74  // OpenGL geometry state.
75 
76  void init_arrays(int);
77  void free_arrays();
78 
79  GLsizei count;
80  GLuint vertices;
81  GLuint elements[16];
82 };
83 
84 //------------------------------------------------------------------------------
85 
86 #endif
An scm_scene encapsulates the definition of a sphere and its parameters.
Definition: scm-scene.hpp:40
void set_detail(int d)
Set the geometric detail of the sphere. Each page will be rendered as a d-by-d grid. This value is limited to the range 0 to 256, which ensures that the vertex index count is a 16-bit number. Changing the detail will trigger a regeneration of the sphere's vertex buffer object data, so it should not be done every frame.
Definition: scm-sphere.cpp:70
void prep(scm_scene *, const double *, int, int, int, bool)
Prepare to render the sphere. Perform all visibility and subdivision calculations. Cache the results for use by a subsequent draw call.
Definition: scm-sphere.cpp:102
scm_sphere(int d, int l)
Create a new spherical geometry rendering object. Initialize the necessary OpenGL vertex buffer objec...
Definition: scm-sphere.cpp:45
void set_limit(int l)
Set the subdivision limit in pixels. That is, if the on-screen size of a page exceeds l then it will ...
Definition: scm-sphere.cpp:84
An scm_sphere generates the adaptive rendered geometry of the 3D sphere.
Definition: scm-sphere.hpp:30
~scm_sphere()
Finalize all OpenGL state.
Definition: scm-sphere.cpp:57
void set_zoom(double x, double y, double z, double k)
Set the direction and magnitude of the zoom.
Definition: scm-sphere.cpp:206
void draw(scm_scene *, const double *, int, int, int, int)
Render the sphere using cached visibility and subdivision state.
Definition: scm-sphere.cpp:124