BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_VIEW_KERNEL_STAGE_H 00006 #define BALL_VIEW_KERNEL_STAGE_H 00007 00008 #ifndef BALL_MATHS_VECTOR3_H 00009 # include <BALL/MATHS/vector3.h> 00010 #endif 00011 00012 #ifndef BALL_MATHS_QUATERNION_H 00013 # include <BALL/MATHS/quaternion.h> 00014 #endif 00015 00016 #ifndef BALL_MATHS_MATRIX44_H 00017 # include <BALL/MATHS/matrix44.h> 00018 #endif 00019 00020 #ifndef BALL_MATHS_ANGLE_H 00021 # include <BALL/MATHS/angle.h> 00022 #endif 00023 00024 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H 00025 # include <BALL/VIEW/DATATYPE/colorRGBA.h> 00026 #endif 00027 00028 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H 00029 # include <BALL/VIEW/KERNEL/representation.h> 00030 #endif 00031 00032 namespace BALL 00033 { 00034 namespace VIEW 00035 { 00045 class BALL_VIEW_EXPORT LightSource 00046 { 00047 public: 00048 00050 enum Types 00051 { 00052 00056 AMBIENT = 0, 00057 00062 POSITIONAL, 00063 00066 DIRECTIONAL 00067 }; 00068 00072 00075 LightSource(); 00076 00079 LightSource(const LightSource& light_source); 00080 00083 virtual ~LightSource(){} 00084 00086 00089 00091 const Vector3& getPosition() const 00092 { return position_;} 00093 00095 void setPosition(const Vector3& position) 00096 { position_ = position; } 00097 00099 const Vector3& getDirection() const 00100 { return direction_;} 00101 00103 void setDirection(const Vector3& direction) 00104 { direction_ = direction;} 00105 00107 const Vector3& getAttenuation() const 00108 { return attenuation_;} 00109 00111 void setAttenuation(const Vector3& attenuation) 00112 { attenuation_ = attenuation;} 00113 00114 00116 const Angle& getAngle() const 00117 { return angle_;} 00118 00120 void setAngle(const Angle& angle) 00121 { angle_ = angle;} 00122 00126 float getIntensity() const 00127 { return intensity_;} 00128 00132 void setIntensity(float intensity) 00133 { intensity_ = intensity;} 00134 00138 const ColorRGBA& getColor() const 00139 { return color_;} 00140 00144 void setColor(const ColorRGBA& color) 00145 { color_ = color;} 00146 00150 Index getType() const 00151 { return type_;} 00152 00156 void setType(Types type) 00157 { type_ = type;} 00158 00160 void setRelativeToCamera(bool state) 00161 { relative_ = state;} 00162 00164 bool isRelativeToCamera() const 00165 { return relative_;} 00166 00168 LightSource& operator = (const LightSource& light); 00169 00171 bool operator < (const LightSource& light) const; 00172 00174 00177 00179 bool operator == (const LightSource& light_source) const; 00180 00182 00189 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const; 00190 00191 protected: 00192 00193 //_ Position of the light source 00194 Vector3 position_; 00195 00196 //_ Direction of the light cone 00197 Vector3 direction_; 00198 00199 //_ Attenuation parameters of the light 00200 Vector3 attenuation_; 00201 00202 //_ 00203 Vector3 r_position_; 00204 00205 //_ 00206 Vector3 r_direction_; 00207 00208 //_ Angle of the light cone 00209 Angle angle_; 00210 00211 //_ Intensity of the light 00212 float intensity_; 00213 00214 //_ Color of the light 00215 ColorRGBA color_; 00216 00217 //_ Enumeration of types for further usage 00218 Index type_; 00219 00220 //_ Relative to camera 00221 bool relative_; 00222 }; 00223 00224 00228 class BALL_VIEW_EXPORT Camera 00229 { 00230 public: 00231 00233 enum ProjectionMode 00234 { 00235 PERSPECTIVE = 0, 00236 ORTHOGRAPHIC 00237 }; 00238 00242 00244 Camera(); 00245 00247 Camera(const Camera& camera); 00248 00249 Camera(const Vector3& view_point, const Vector3& look_at, const Vector3& look_up_vector, const ProjectionMode& mode = PERSPECTIVE); 00250 00252 virtual ~Camera(){} 00253 00255 Camera& operator = (const Camera& camera); 00256 00258 00261 00263 void moveRight(float translation) 00264 { view_point_ += right_vector_*translation; look_at_ += right_vector_*translation; } 00265 00267 void moveUp(float translation) 00268 { view_point_ += look_up_vector_*translation; look_at_ += look_up_vector_*translation; } 00269 00271 void moveForward(float translation) 00272 { 00273 Vector3 normal_view_vector(view_vector_); 00274 normal_view_vector.normalize(); 00275 view_point_ += normal_view_vector*translation; 00276 look_at_ += normal_view_vector*translation; 00277 } 00278 00280 const Vector3& getViewPoint() const 00281 { return view_point_;} 00282 00284 void setViewPoint(const Vector3& view_point) 00285 { view_point_ = view_point; calculateVectors_();} 00286 00288 const Vector3& getLookAtPosition() const 00289 { return look_at_;} 00290 00292 void setLookAtPosition(const Vector3& look_at) 00293 { look_at_ = look_at; calculateVectors_();} 00294 00296 const Vector3& getLookUpVector() const 00297 { return look_up_vector_;} 00298 00300 void setLookUpVector(const Vector3& look_up_vector) 00301 { look_up_vector_ = look_up_vector; calculateVectors_();} 00302 00304 float getDistance() const 00305 { return view_point_.getDistance(look_at_);} 00306 00308 Vector3 getViewVector() const 00309 { return view_vector_;} 00310 00312 Vector3 getRightVector() const 00313 { return right_vector_;} 00314 00316 void translate(const Vector3& v) 00317 { view_point_ += v; look_at_ += v; calculateVectors_();} 00318 00320 void rotate(const Quaternion& q, const Vector3& origin); 00321 00323 void rotate(const Matrix4x4& mat, const Vector3& origin); 00324 00326 virtual void clear() 00327 { *this = Camera();} 00328 00330 void setProjectionMode(ProjectionMode const& mode) 00331 { projection_mode_ = mode; } 00332 00334 ProjectionMode getProjectionMode() const 00335 { return projection_mode_; } 00336 00338 String toString() const; 00339 00341 bool readFromString(const String& data); 00342 00344 00347 00349 bool operator == (const Camera& camera) const; 00350 00352 bool operator < (const Camera& camera) const; 00353 00355 00362 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const; 00363 00364 protected: 00365 00366 //_ 00367 void calculateVectors_(); 00368 00369 //_ 00370 Vector3 view_point_; 00371 00372 //_ 00373 Vector3 look_at_; 00374 00375 //_ 00376 Vector3 look_up_vector_; 00377 00378 /*_ The viewing vector. 00379 Stored only for better performance in the scene. 00380 */ 00381 Vector3 view_vector_; 00382 00383 /*_ The orthogonal vector to the viewing vector, which is showing to the right. 00384 Stored only for better performance in the scene. 00385 */ 00386 Vector3 right_vector_; 00387 00388 /* The projection mode used by this camera. 00389 */ 00390 ProjectionMode projection_mode_; 00391 }; 00392 00398 class BALL_VIEW_EXPORT Stage 00399 { 00400 public: 00401 00404 class RaytracingMaterial 00405 { 00406 public: 00407 ColorRGBA ambient_color; 00408 float ambient_intensity; 00409 00410 ColorRGBA specular_color; 00411 float specular_intensity; 00412 00413 ColorRGBA reflective_color; 00414 float reflective_intensity; 00415 00416 float shininess; 00417 float transparency; 00418 }; 00419 00423 00426 Stage(); 00427 00429 Stage(const Stage& stage); 00430 00432 virtual ~Stage(){} 00433 00435 virtual void clear(); 00436 00438 00441 00443 virtual const std::list<LightSource>& getLightSources() const 00444 { return light_sources_;} 00445 00447 virtual void addLightSource(const LightSource& light_source); 00448 00450 virtual void removeLightSource(const LightSource& light_source) ; 00451 00453 void clearLightSources(); 00454 00456 virtual Camera& getCamera() 00457 { return camera_;} 00458 00460 virtual const Camera& getCamera() const 00461 { return camera_;} 00462 00465 virtual void setCamera(const Camera& camera) 00466 { camera_ = camera;} 00467 00469 virtual const ColorRGBA& getBackgroundColor() const 00470 { return background_color_;} 00471 00473 virtual void setBackgroundColor(const ColorRGBA& color) 00474 { background_color_ = color;} 00475 00477 virtual const ColorRGBA& getInfoColor() const 00478 { return info_color_;} 00479 00481 virtual void setInfoColor(const ColorRGBA& color) 00482 { info_color_ = color;} 00483 00485 void showCoordinateSystem(bool state) 00486 { show_coordinate_system_ = state;} 00487 00489 bool coordinateSystemEnabled() const 00490 { return show_coordinate_system_;} 00491 00493 void setEyeDistance(float value) 00494 { eye_distance_ = value;} 00495 00497 float getEyeDistance() const 00498 { return eye_distance_;} 00499 00501 void setFocalDistance(float value) 00502 { focal_distance_ = value;} 00503 00505 float getFocalDistance() const 00506 { return focal_distance_;} 00507 00509 void setSwapSideBySideStereo(bool state) 00510 { swap_side_by_side_stereo_ = state;} 00511 00513 bool swapSideBySideStereo() const 00514 { return swap_side_by_side_stereo_;} 00515 00517 float getFogIntensity() const 00518 { return fog_intensity_;} 00519 00521 void setFogIntensity(float value) 00522 { fog_intensity_ = value;} 00523 00525 float getSpecularIntensity() const 00526 { return specular_;} 00527 00529 void setSpecularIntensity(float value) 00530 { specular_ = value;} 00531 00533 float getDiffuseIntensity() const 00534 { return diffuse_;} 00535 00537 void setDiffuseIntensity(float value) 00538 { diffuse_ = value;} 00539 00541 float getAmbientIntensity() const 00542 { return ambient_;} 00543 00545 void setAmbientIntensity(float value) 00546 { ambient_ = value;} 00547 00549 float getShininess() const 00550 { return shininess_;} 00551 00553 void setShininess(float value) 00554 { shininess_ = value;} 00555 00557 00560 00562 bool operator == (const Stage& stage) const; 00563 00571 Vector3 calculateRelativeCoordinates(Vector3 pos) const; 00572 00576 Vector3 calculateAbsoluteCoordinates(Vector3 pos) const; 00577 00579 00586 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const; 00587 00589 RaytracingMaterial& getRTMaterial() { return rt_material_; } 00590 00592 const RaytracingMaterial& getRTMaterial() const { return rt_material_; } 00593 00594 protected: 00595 00596 //_ 00597 ColorRGBA background_color_; 00598 00599 //_ 00600 ColorRGBA info_color_; 00601 00602 //_ 00603 std::list<LightSource> light_sources_; 00604 00605 //_ 00606 Camera camera_; 00607 00608 //_ 00609 bool show_coordinate_system_; 00610 00611 //_ 00612 float fog_intensity_; 00613 00614 //_ 00615 float eye_distance_; 00616 00617 //_ 00618 float focal_distance_; 00619 00620 //_ 00621 bool swap_side_by_side_stereo_; 00622 00623 float specular_; 00624 float diffuse_; 00625 float ambient_; 00626 float shininess_; 00627 00628 // the current default materials used for raytracing 00629 RaytracingMaterial rt_material_; 00630 }; 00631 00632 } // namespace VIEW 00633 } // namespace BALL 00634 00635 #endif // BALL_VIEW_KERNEL_STAGE_H