00001
00002
00003
00004
00005
00006 #ifndef BALL_VIEW_KERNEL_STAGE_H
00007 #define BALL_VIEW_KERNEL_STAGE_H
00008
00009 #ifndef BALL_MATHS_VECTOR3_H
00010 # include <BALL/MATHS/vector3.h>
00011 #endif
00012
00013 #ifndef BALL_MATHS_QUATERNION_H
00014 # include <BALL/MATHS/quaternion.h>
00015 #endif
00016
00017 #ifndef BALL_MATHS_MATRIX44_H
00018 # include <BALL/MATHS/matrix44.h>
00019 #endif
00020
00021 #ifndef BALL_MATHS_ANGLE_H
00022 # include <BALL/MATHS/angle.h>
00023 #endif
00024
00025 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H
00026 # include <BALL/VIEW/DATATYPE/colorRGBA.h>
00027 #endif
00028
00029 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H
00030 # include <BALL/VIEW/KERNEL/representation.h>
00031 #endif
00032
00033 namespace BALL
00034 {
00035 namespace VIEW
00036 {
00046 class BALL_VIEW_EXPORT LightSource
00047 {
00048 public:
00049
00051 enum Types
00052 {
00053
00057 AMBIENT = 0,
00058
00063 POSITIONAL,
00064
00067 DIRECTIONAL
00068 };
00069
00073
00076 LightSource();
00077
00080 LightSource(const LightSource& light_source);
00081
00084 virtual ~LightSource(){}
00085
00087
00090
00092 const Vector3& getPosition() const
00093 { return position_;}
00094
00096 void setPosition(const Vector3& position)
00097 { position_ = position; }
00098
00100 const Vector3& getDirection() const
00101 { return direction_;}
00102
00104 void setDirection(const Vector3& direction)
00105 { direction_ = direction;}
00106
00108 const Vector3& getAttenuation() const
00109 { return attenuation_;}
00110
00112 void setAttenuation(const Vector3& attenuation)
00113 { attenuation_ = attenuation;}
00114
00115
00117 const Angle& getAngle() const
00118 { return angle_;}
00119
00121 void setAngle(const Angle& angle)
00122 { angle_ = angle;}
00123
00127 float getIntensity() const
00128 { return intensity_;}
00129
00133 void setIntensity(float intensity)
00134 { intensity_ = intensity;}
00135
00139 const ColorRGBA& getColor() const
00140 { return color_;}
00141
00145 void setColor(const ColorRGBA& color)
00146 { color_ = color;}
00147
00151 Index getType() const
00152 { return type_;}
00153
00157 void setType(Types type)
00158 { type_ = type;}
00159
00161 void setRelativeToCamera(bool state)
00162 { relative_ = state;}
00163
00165 bool isRelativeToCamera() const
00166 { return relative_;}
00167
00169 LightSource& operator = (const LightSource& light);
00170
00172 bool operator < (const LightSource& light) const;
00173
00175
00178
00180 bool operator == (const LightSource& light_source) const;
00181
00183
00190 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00191
00192 protected:
00193
00194
00195 Vector3 position_;
00196
00197
00198 Vector3 direction_;
00199
00200
00201 Vector3 attenuation_;
00202
00203
00204 Vector3 r_position_;
00205
00206
00207 Vector3 r_direction_;
00208
00209
00210 Angle angle_;
00211
00212
00213 float intensity_;
00214
00215
00216 ColorRGBA color_;
00217
00218
00219 Index type_;
00220
00221
00222 bool relative_;
00223 };
00224
00225
00229 class BALL_VIEW_EXPORT Camera
00230 {
00231 public:
00232
00234 enum ProjectionMode
00235 {
00236 PERSPECTIVE = 0,
00237 ORTHOGRAPHIC
00238 };
00239
00243
00245 Camera();
00246
00248 Camera(const Camera& camera);
00249
00250 Camera(const Vector3& view_point, const Vector3& look_at, const Vector3& look_up_vector, const ProjectionMode& mode = PERSPECTIVE);
00251
00253 virtual ~Camera(){}
00254
00256 Camera& operator = (const Camera& camera);
00257
00259
00262
00264 void moveRight(float translation)
00265 { view_point_ += right_vector_*translation; look_at_ += right_vector_*translation; }
00266
00268 void moveUp(float translation)
00269 { view_point_ += look_up_vector_*translation; look_at_ += look_up_vector_*translation; }
00270
00272 void moveForward(float translation)
00273 {
00274 Vector3 normal_view_vector(view_vector_);
00275 normal_view_vector.normalize();
00276 view_point_ += normal_view_vector*translation;
00277 look_at_ += normal_view_vector*translation;
00278 }
00279
00281 const Vector3& getViewPoint() const
00282 { return view_point_;}
00283
00285 void setViewPoint(const Vector3& view_point)
00286 { view_point_ = view_point; calculateVectors_();}
00287
00289 const Vector3& getLookAtPosition() const
00290 { return look_at_;}
00291
00293 void setLookAtPosition(const Vector3& look_at)
00294 { look_at_ = look_at; calculateVectors_();}
00295
00297 const Vector3& getLookUpVector() const
00298 { return look_up_vector_;}
00299
00301 void setLookUpVector(const Vector3& look_up_vector)
00302 { look_up_vector_ = look_up_vector; calculateVectors_();}
00303
00305 float getDistance() const
00306 { return view_point_.getDistance(look_at_);}
00307
00309 Vector3 getViewVector() const
00310 { return view_vector_;}
00311
00313 Vector3 getRightVector() const
00314 { return right_vector_;}
00315
00317 void translate(const Vector3& v)
00318 { view_point_ += v; look_at_ += v; calculateVectors_();}
00319
00321 void rotate(const Quaternion& q, const Vector3& origin);
00322
00324 void rotate(const Matrix4x4& mat, const Vector3& origin);
00325
00327 virtual void clear()
00328 { *this = Camera();}
00329
00331 void setProjectionMode(ProjectionMode const& mode)
00332 { projection_mode_ = mode; }
00333
00335 ProjectionMode getProjectionMode() const
00336 { return projection_mode_; }
00337
00339 String toString() const;
00340
00342 bool readFromString(const String& data);
00343
00345
00348
00350 bool operator == (const Camera& camera) const;
00351
00353 bool operator < (const Camera& camera) const;
00354
00356
00363 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00364
00365 protected:
00366
00367
00368 void calculateVectors_();
00369
00370
00371 Vector3 view_point_;
00372
00373
00374 Vector3 look_at_;
00375
00376
00377 Vector3 look_up_vector_;
00378
00379
00380
00381
00382 Vector3 view_vector_;
00383
00384
00385
00386
00387 Vector3 right_vector_;
00388
00389
00390
00391 ProjectionMode projection_mode_;
00392 };
00393
00399 class BALL_VIEW_EXPORT Stage
00400 {
00401 public:
00402
00405 class RaytracingMaterial
00406 {
00407 public:
00408 ColorRGBA ambient_color;
00409 float ambient_intensity;
00410
00411 ColorRGBA specular_color;
00412 float specular_intensity;
00413
00414 ColorRGBA reflective_color;
00415 float reflective_intensity;
00416
00417 float shininess;
00418 float transparency;
00419 };
00420
00424
00427 Stage();
00428
00430 Stage(const Stage& stage);
00431
00433 virtual ~Stage(){}
00434
00436 virtual void clear();
00437
00439
00442
00444 virtual const std::list<LightSource>& getLightSources() const
00445 { return light_sources_;}
00446
00448 virtual void addLightSource(const LightSource& light_source);
00449
00451 virtual void removeLightSource(const LightSource& light_source) ;
00452
00454 void clearLightSources();
00455
00457 virtual Camera& getCamera()
00458 { return camera_;}
00459
00461 virtual const Camera& getCamera() const
00462 { return camera_;}
00463
00466 virtual void setCamera(const Camera& camera)
00467 { camera_ = camera;}
00468
00470 virtual const ColorRGBA& getBackgroundColor() const
00471 { return background_color_;}
00472
00474 virtual void setBackgroundColor(const ColorRGBA& color)
00475 { background_color_ = color;}
00476
00478 virtual const ColorRGBA& getInfoColor() const
00479 { return info_color_;}
00480
00482 virtual void setInfoColor(const ColorRGBA& color)
00483 { info_color_ = color;}
00484
00486 void showCoordinateSystem(bool state)
00487 { show_coordinate_system_ = state;}
00488
00490 bool coordinateSystemEnabled() const
00491 { return show_coordinate_system_;}
00492
00494 void setEyeDistance(float value)
00495 { eye_distance_ = value;}
00496
00498 float getEyeDistance() const
00499 { return eye_distance_;}
00500
00502 void setFocalDistance(float value)
00503 { focal_distance_ = value;}
00504
00506 float getFocalDistance() const
00507 { return focal_distance_;}
00508
00510 void setSwapSideBySideStereo(bool state)
00511 { swap_side_by_side_stereo_ = state;}
00512
00514 bool swapSideBySideStereo() const
00515 { return swap_side_by_side_stereo_;}
00516
00518 float getFogIntensity() const
00519 { return fog_intensity_;}
00520
00522 void setFogIntensity(float value)
00523 { fog_intensity_ = value;}
00524
00526 float getSpecularIntensity() const
00527 { return specular_;}
00528
00530 void setSpecularIntensity(float value)
00531 { specular_ = value;}
00532
00534 float getDiffuseIntensity() const
00535 { return diffuse_;}
00536
00538 void setDiffuseIntensity(float value)
00539 { diffuse_ = value;}
00540
00542 float getAmbientIntensity() const
00543 { return ambient_;}
00544
00546 void setAmbientIntensity(float value)
00547 { ambient_ = value;}
00548
00550 float getShininess() const
00551 { return shininess_;}
00552
00554 void setShininess(float value)
00555 { shininess_ = value;}
00556
00558
00561
00563 bool operator == (const Stage& stage) const;
00564
00572 Vector3 calculateRelativeCoordinates(Vector3 pos) const;
00573
00577 Vector3 calculateAbsoluteCoordinates(Vector3 pos) const;
00578
00580
00587 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00588
00590 RaytracingMaterial& getRTMaterial() { return rt_material_; }
00591
00593 const RaytracingMaterial& getRTMaterial() const { return rt_material_; }
00594
00595 protected:
00596
00597
00598 ColorRGBA background_color_;
00599
00600
00601 ColorRGBA info_color_;
00602
00603
00604 std::list<LightSource> light_sources_;
00605
00606
00607 Camera camera_;
00608
00609
00610 bool show_coordinate_system_;
00611
00612
00613 float fog_intensity_;
00614
00615
00616 float eye_distance_;
00617
00618
00619 float focal_distance_;
00620
00621
00622 bool swap_side_by_side_stereo_;
00623
00624 float specular_;
00625 float diffuse_;
00626 float ambient_;
00627 float shininess_;
00628
00629
00630 RaytracingMaterial rt_material_;
00631 };
00632
00633 }
00634 }
00635
00636 #endif // BALL_VIEW_KERNEL_STAGE_H