19 #ifndef KJB_CPP_PRIMITIVE_H
20 #define KJB_CPP_PRIMITIVE_H
22 #ifdef KJB_HAVE_OPENGL
45 Quadric(
unsigned int slices = DEFAULT_SLICES,
unsigned int rings = DEFAULT_RINGS);
47 Quadric(
const Quadric& src);
49 Quadric& operator=(
const Quadric& other);
55 void wire_render()
const;
57 void solid_render()
const
59 if(_mesh_dirty) _update_mesh();
61 _generic_render_in_opengl(_solid_list_id);
66 void _generic_render_in_opengl(
unsigned int list_id)
const;
68 static void _quad_error_callback(
unsigned int error_code);
70 void _update_mesh()
const;
72 virtual void _render()
const = 0;
76 static unsigned int _num_instances;
78 mutable unsigned int _solid_list_id;
79 mutable unsigned int _wire_list_id;
81 mutable bool _mesh_dirty;
83 static const unsigned int DEFAULT_SLICES = 30;
84 static const unsigned int DEFAULT_RINGS = 10;
93 class Cylinder :
public Quadric
97 float base_radius = 1,
100 unsigned int slices = DEFAULT_SLICES,
102 unsigned int rings = DEFAULT_RINGS) :
103 Quadric(slices, rings),
104 _base_r(base_radius),
111 Cylinder(
const Cylinder& src) :
113 _base_r(src._base_r),
120 Cylinder& operator=(
const Cylinder& other);
122 void swap(Cylinder&);
124 virtual ~Cylinder(){};
126 void set_base_radius(
float r) {_base_r =
r; _mesh_dirty =
true;}
127 void set_top_radius(
float r) {_top_r =
r; _mesh_dirty =
true;}
128 void set_height(
float h) {_height = h; _mesh_dirty =
true;}
134 virtual void _render()
const;
142 class Static_cylinder :
147 float base_radius = 1,
148 float top_radius = 1,
150 unsigned int slices = DEFAULT_SLICES,
152 unsigned int rings = DEFAULT_RINGS);
154 void wire_render()
const;
156 void solid_render()
const;
159 unsigned int wire_index_;
160 unsigned int solid_index_;
162 static const unsigned int DEFAULT_SLICES = 30;
163 static const unsigned int DEFAULT_RINGS = 10;
169 class Sphere :
public Quadric
172 Sphere(
float radius = 1,
unsigned int slices = DEFAULT_SLICES,
unsigned int rings = DEFAULT_RINGS):
173 Quadric(slices, rings),
180 Sphere(
const Sphere& src):
187 Sphere& operator=(
const Sphere& other);
193 void set_radius(
float r)
195 _r =
r; _mesh_dirty =
true;
201 virtual void _render()
const;
205 class Disk :
public Quadric
208 Disk(
float outer_radius = 1,
unsigned int slices = DEFAULT_SLICES,
unsigned int rings = DEFAULT_RINGS):
209 Quadric(slices, rings),
211 _outer_r(outer_radius)
216 Disk(
float inner_radius,
float outer_radius,
unsigned int slices = DEFAULT_SLICES,
unsigned int rings = DEFAULT_RINGS):
217 Quadric(slices, rings),
218 _inner_r(inner_radius),
219 _outer_r(outer_radius)
225 Disk(
const Disk& src):
227 _inner_r(src._inner_r),
228 _outer_r(src._outer_r)
233 Disk& operator=(
const Disk& other);
239 void set_inner_radius(
float r)
241 _inner_r =
r; _mesh_dirty =
true;
244 void set_outer_radius(
float r)
246 _outer_r =
r; _mesh_dirty =
true;
253 virtual void _render()
const;
278 _length(direction.magnitude()),
281 _dir(direction / _length),
287 double head_length =
std::min(_length, 2 * _width);
288 double head_width = head_length;
291 _shaft_length =
std::max(0.01, _length - head_length);
292 _shaft = Cylinder(_width/2, _width/2, _shaft_length, 10);
293 _head = Cylinder(head_width/2, 0.0, head_length, 10);
295 _shaft_cap = Disk(_width/2);
296 _head_cap = Disk(head_width/2);
301 assert(position.
size() == 3);
307 assert(direction.
size() == 3);
313 _generic_render(Renderer());
316 void solid_render()
const
318 _generic_render(Solid_renderer());
321 void wire_render()
const
323 _generic_render(Wire_renderer());
326 void wire_occlude_render()
const
328 _generic_render(Wire_occlude_renderer());
332 void _generic_render(
const Generic_renderer& renderer)
const;
350 void solid_render()
const;
354 class Ellipse :
public Generic_renderable
358 Ellipse(
double r1,
double r2,
size_t slices = DEFAULT_SLICES);
364 void solid_render()
const;
367 void wire_render()
const;
371 void render_points()
const;
377 static const size_t DEFAULT_SLICES = 32;
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
void swap(Perspective_camera &cam1, Perspective_camera &cam2)
Swap two cameras.
Definition: perspective_camera.h:599
height
Definition: APPgetLargeConnectedEdges.m:33
r
Definition: APPgetLargeConnectedEdges.m:127
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Abstract class to render this object with GL.
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
Int_matrix::Value_type min(const Int_matrix &mat)
Return the minimum value in this matrix.
Definition: l_int_matrix.h:1385
Definition: gr_renderable.h:233
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...