BALL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
stage.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_VIEW_KERNEL_STAGE_H
6 #define BALL_VIEW_KERNEL_STAGE_H
7 
8 #ifndef BALL_MATHS_VECTOR3_H
9 # include <BALL/MATHS/vector3.h>
10 #endif
11 
12 #ifndef BALL_MATHS_QUATERNION_H
13 # include <BALL/MATHS/quaternion.h>
14 #endif
15 
16 #ifndef BALL_MATHS_MATRIX44_H
17 # include <BALL/MATHS/matrix44.h>
18 #endif
19 
20 #ifndef BALL_MATHS_ANGLE_H
21 # include <BALL/MATHS/angle.h>
22 #endif
23 
24 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H
26 #endif
27 
28 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H
30 #endif
31 
32 namespace BALL
33 {
34  namespace VIEW
35  {
46  {
47  public:
48 
50  enum Types
51  {
52 
56  AMBIENT = 0,
57 
63 
66  DIRECTIONAL
67  };
68 
72 
75  LightSource();
76 
79  LightSource(const LightSource& light_source);
80 
83  virtual ~LightSource(){}
84 
86 
89 
91  const Vector3& getPosition() const
92  { return position_;}
93 
95  void setPosition(const Vector3& position)
96  { position_ = position; }
97 
99  const Vector3& getDirection() const
100  { return direction_;}
101 
103  void setDirection(const Vector3& direction)
104  { direction_ = direction;}
105 
107  const Vector3& getAttenuation() const
108  { return attenuation_;}
109 
111  void setAttenuation(const Vector3& attenuation)
112  { attenuation_ = attenuation;}
113 
114 
116  const Angle& getAngle() const
117  { return angle_;}
118 
120  void setAngle(const Angle& angle)
121  { angle_ = angle;}
122 
126  float getIntensity() const
127  { return intensity_;}
128 
132  void setIntensity(float intensity)
133  { intensity_ = intensity;}
134 
138  const ColorRGBA& getColor() const
139  { return color_;}
140 
144  void setColor(const ColorRGBA& color)
145  { color_ = color;}
146 
150  Index getType() const
151  { return type_;}
152 
156  void setType(Types type)
157  { type_ = type;}
158 
160  void setRelativeToCamera(bool state)
161  { relative_ = state;}
162 
164  bool isRelativeToCamera() const
165  { return relative_;}
166 
168  LightSource& operator = (const LightSource& light);
169 
171  bool operator < (const LightSource& light) const;
172 
174 
177 
179  bool operator == (const LightSource& light_source) const;
180 
182 
189  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
190 
191  protected:
192 
193  //_ Position of the light source
195 
196  //_ Direction of the light cone
198 
199  //_ Attenuation parameters of the light
201 
202  //_
204 
205  //_
207 
208  //_ Angle of the light cone
210 
211  //_ Intensity of the light
212  float intensity_;
213 
214  //_ Color of the light
216 
217  //_ Enumeration of types for further usage
219 
220  //_ Relative to camera
221  bool relative_;
222  };
223 
224 
229  {
230  public:
231 
234  {
235  PERSPECTIVE = 0,
236  ORTHOGRAPHIC
237  };
238 
242 
244  Camera();
245 
247  Camera(const Camera& camera);
248 
249  Camera(const Vector3& view_point, const Vector3& look_at, const Vector3& look_up_vector, const ProjectionMode& mode = PERSPECTIVE);
250 
252  virtual ~Camera(){}
253 
255  Camera& operator = (const Camera& camera);
256 
258 
261 
263  void moveRight(float translation)
264  { view_point_ += right_vector_*translation; look_at_ += right_vector_*translation; }
265 
267  void moveUp(float translation)
268  { view_point_ += look_up_vector_*translation; look_at_ += look_up_vector_*translation; }
269 
271  void moveForward(float translation)
272  {
273  Vector3 normal_view_vector(view_vector_);
274  normal_view_vector.normalize();
275  view_point_ += normal_view_vector*translation;
276  look_at_ += normal_view_vector*translation;
277  }
278 
280  const Vector3& getViewPoint() const
281  { return view_point_;}
282 
284  void setViewPoint(const Vector3& view_point)
285  { view_point_ = view_point; calculateVectors_();}
286 
288  const Vector3& getLookAtPosition() const
289  { return look_at_;}
290 
292  void setLookAtPosition(const Vector3& look_at)
293  { look_at_ = look_at; calculateVectors_();}
294 
296  const Vector3& getLookUpVector() const
297  { return look_up_vector_;}
298 
300  void setLookUpVector(const Vector3& look_up_vector)
301  { look_up_vector_ = look_up_vector; calculateVectors_();}
302 
304  float getDistance() const
305  { return view_point_.getDistance(look_at_);}
306 
308  Vector3 getViewVector() const
309  { return view_vector_;}
310 
312  Vector3 getRightVector() const
313  { return right_vector_;}
314 
316  void translate(const Vector3& v)
317  { view_point_ += v; look_at_ += v; calculateVectors_();}
318 
320  void rotate(const Quaternion& q, const Vector3& origin);
321 
323  void rotate(const Matrix4x4& mat, const Vector3& origin);
324 
326  virtual void clear()
327  { *this = Camera();}
328 
330  void setProjectionMode(ProjectionMode const& mode)
331  { projection_mode_ = mode; }
332 
334  ProjectionMode getProjectionMode() const
335  { return projection_mode_; }
336 
338  String toString() const;
339 
341  bool readFromString(const String& data);
342 
344 
347 
349  bool operator == (const Camera& camera) const;
350 
352  bool operator < (const Camera& camera) const;
353 
355 
362  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
363 
364  protected:
365 
366  //_
367  void calculateVectors_();
368 
369  //_
371 
372  //_
374 
375  //_
377 
378  /*_ The viewing vector.
379  Stored only for better performance in the scene.
380  */
382 
383  /*_ The orthogonal vector to the viewing vector, which is showing to the right.
384  Stored only for better performance in the scene.
385  */
387 
388  /* The projection mode used by this camera.
389  */
391  };
392 
399  {
400  public:
401 
405  {
406  public:
409 
412 
415 
416  float shininess;
418  };
419 
423 
426  Stage();
427 
429  Stage(const Stage& stage);
430 
432  virtual ~Stage(){}
433 
435  virtual void clear();
436 
438 
441 
443  virtual const std::list<LightSource>& getLightSources() const
444  { return light_sources_;}
445 
447  virtual void addLightSource(const LightSource& light_source);
448 
450  virtual void removeLightSource(const LightSource& light_source) ;
451 
453  void clearLightSources();
454 
456  virtual Camera& getCamera()
457  { return camera_;}
458 
460  virtual const Camera& getCamera() const
461  { return camera_;}
462 
465  virtual void setCamera(const Camera& camera)
466  { camera_ = camera;}
467 
469  virtual const ColorRGBA& getBackgroundColor() const
470  { return background_color_;}
471 
473  virtual void setBackgroundColor(const ColorRGBA& color)
474  { background_color_ = color;}
475 
477  virtual const ColorRGBA& getInfoColor() const
478  { return info_color_;}
479 
481  virtual void setInfoColor(const ColorRGBA& color)
482  { info_color_ = color;}
483 
485  void showCoordinateSystem(bool state)
486  { show_coordinate_system_ = state;}
487 
489  bool coordinateSystemEnabled() const
490  { return show_coordinate_system_;}
491 
493  void setEyeDistance(float value)
494  { eye_distance_ = value;}
495 
497  float getEyeDistance() const
498  { return eye_distance_;}
499 
501  void setFocalDistance(float value)
502  { focal_distance_ = value;}
503 
505  float getFocalDistance() const
506  { return focal_distance_;}
507 
509  void setSwapSideBySideStereo(bool state)
510  { swap_side_by_side_stereo_ = state;}
511 
513  bool swapSideBySideStereo() const
514  { return swap_side_by_side_stereo_;}
515 
517  float getFogIntensity() const
518  { return fog_intensity_;}
519 
521  void setFogIntensity(float value)
522  { fog_intensity_ = value;}
523 
525  float getSpecularIntensity() const
526  { return specular_;}
527 
529  void setSpecularIntensity(float value)
530  { specular_ = value;}
531 
533  float getDiffuseIntensity() const
534  { return diffuse_;}
535 
537  void setDiffuseIntensity(float value)
538  { diffuse_ = value;}
539 
541  float getAmbientIntensity() const
542  { return ambient_;}
543 
545  void setAmbientIntensity(float value)
546  { ambient_ = value;}
547 
549  float getShininess() const
550  { return shininess_;}
551 
553  void setShininess(float value)
554  { shininess_ = value;}
555 
557 
560 
562  bool operator == (const Stage& stage) const;
563 
571  Vector3 calculateRelativeCoordinates(Vector3 pos) const;
572 
576  Vector3 calculateAbsoluteCoordinates(Vector3 pos) const;
577 
579 
586  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
587 
589  RaytracingMaterial& getRTMaterial() { return rt_material_; }
590 
592  const RaytracingMaterial& getRTMaterial() const { return rt_material_; }
593 
594  protected:
595 
596  //_
598 
599  //_
601 
602  //_
603  std::list<LightSource> light_sources_;
604 
605  //_
607 
608  //_
610 
611  //_
613 
614  //_
616 
617  //_
619 
620  //_
622 
623  float specular_;
624  float diffuse_;
625  float ambient_;
626  float shininess_;
627 
628  // the current default materials used for raytracing
630  };
631 
632  } // namespace VIEW
633 } // namespace BALL
634 
635 #endif // BALL_VIEW_KERNEL_STAGE_H