stage.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: stage.h,v 1.19.16.1 2007/03/25 21:26:04 oliver Exp $
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_DATATYPE_LIST_H
00030 # include <BALL/DATATYPE/list.h>
00031 #endif
00032 
00033 #ifndef  BALL_VIEW_KERNEL_REPRESENTATION_H
00034 # include <BALL/VIEW/KERNEL/representation.h>
00035 #endif
00036 
00037 namespace BALL
00038 {
00039   namespace VIEW
00040   {
00050     class BALL_VIEW_EXPORT LightSource
00051     {
00052       public:
00053 
00055       enum Types
00056       {
00057 
00061         AMBIENT = 0,
00062 
00067         POSITIONAL,
00068 
00071         DIRECTIONAL
00072       };
00073 
00077 
00080       LightSource();
00081 
00084       LightSource(const LightSource& light_source);
00085 
00088       virtual ~LightSource(){}
00089 
00091 
00094 
00096       const Vector3& getPosition() const
00097         { return position_;}
00098 
00100       void setPosition(const Vector3& position)
00101         { position_ = position; }
00102 
00104       const Vector3& getDirection() const
00105         { return direction_;}
00106 
00108       void setDirection(const Vector3& direction)
00109         { direction_ = direction;}
00110   
00112       const Vector3& getAttenuation() const
00113         { return attenuation_;}
00114 
00116       void setAttenuation(const Vector3& attenuation)
00117         { attenuation_ = attenuation;}
00118 
00119 
00121       const Angle& getAngle() const
00122         { return angle_;}
00123 
00125       void setAngle(const Angle& angle)
00126         { angle_ = angle;}
00127       
00131       float getIntensity() const
00132         { return intensity_;}
00133 
00137       void setIntensity(float intensity)
00138         { intensity_ = intensity;}
00139         
00143       const ColorRGBA& getColor() const
00144         { return color_;}
00145 
00149       void setColor(const ColorRGBA& color)
00150         { color_ = color;}
00151       
00155       Index getType() const
00156         { return type_;}
00157 
00161       void setType(Types type)
00162         { type_ = type;}
00163 
00165       void setRelativeToCamera(bool state)
00166         { relative_ = state;}
00167 
00169       bool isRelativeToCamera() const
00170         { return relative_;}
00171 
00173       LightSource& operator = (const LightSource& light);
00174 
00176       bool operator < (const LightSource& light) const;
00177 
00179 
00182       
00184       bool operator == (const LightSource& light_source) const;
00185 
00187       
00194       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00195 
00196       protected:
00197 
00198       //_ Position of the light source
00199       Vector3     position_;
00200 
00201       //_ Direction of the light cone
00202       Vector3     direction_;
00203       
00204       //_ Attenuation parameters of the light 
00205       Vector3     attenuation_;
00206 
00207       //_
00208       Vector3     r_position_;
00209 
00210       //_
00211       Vector3     r_direction_;
00212 
00213       //_ Angle of the light cone
00214       Angle       angle_;
00215 
00216       //_ Intensity of the light
00217       float       intensity_;
00218 
00219       //_ Color of the light
00220       ColorRGBA   color_;
00221 
00222       //_ Enumeration of types for further usage
00223       Index       type_;
00224 
00225       //_ Relative to camera
00226       bool        relative_;
00227     };
00228         
00229 
00233     class BALL_VIEW_EXPORT Camera
00234     {
00235       public:
00236 
00240       
00242       Camera();
00243 
00245       Camera(const Camera& camera);
00246 
00247       Camera(const Vector3& view_point, const Vector3& look_at, const Vector3& look_up_vector);
00248 
00250       virtual ~Camera(){}
00251 
00253       Camera& operator = (const Camera& camera);
00254 
00256 
00259 
00261       void moveRight(float translation)
00262         { view_point_ += right_vector_*translation; look_at_ += right_vector_*translation; }
00263 
00265       void moveUp(float translation)
00266         { view_point_ += look_up_vector_*translation; look_at_ += look_up_vector_*translation; }
00267 
00269       void moveForward(float translation)
00270       { 
00271         Vector3 normal_view_vector(view_vector_);
00272         normal_view_vector.normalize();
00273         view_point_ += normal_view_vector*translation; 
00274         look_at_ += normal_view_vector*translation; 
00275       }
00276 
00278       const Vector3& getViewPoint() const
00279         { return view_point_;}
00280 
00282       void setViewPoint(const Vector3& view_point) 
00283         { view_point_ = view_point; calculateVectors_();}
00284 
00286       const Vector3& getLookAtPosition() const
00287         { return look_at_;}
00288 
00290       void setLookAtPosition(const Vector3& look_at) 
00291         { look_at_ = look_at; calculateVectors_();}
00292 
00294       const Vector3& getLookUpVector() const
00295         { return look_up_vector_;}
00296 
00298       void setLookUpVector(const Vector3& look_up_vector) 
00299         { look_up_vector_ = look_up_vector; calculateVectors_();}
00300 
00302       float getDistance() const
00303         { return view_point_.getDistance(look_at_);}
00304 
00306       Vector3 getViewVector() const
00307         { return view_vector_;}
00308 
00310       Vector3 getRightVector() const
00311         { return right_vector_;}
00312       
00314       void translate(const Vector3& v) 
00315         { view_point_ += v; look_at_ += v; calculateVectors_();}
00316 
00318       void rotate(const Quaternion& q, const Vector3& origin);
00319       
00321       void rotate(const Matrix4x4& mat, const Vector3& origin);
00322 
00324       virtual void clear()
00325         { *this = Camera();}
00326 
00328       String toString() const;
00329 
00331       bool readFromString(const String& data);
00332 
00334 
00337       
00339       bool operator == (const Camera& camera) const;
00340 
00342       bool operator < (const Camera& camera) const;
00343 
00345   
00352       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00353 
00354       protected:
00355 
00356       //_
00357       void calculateVectors_();
00358 
00359       //_
00360       Vector3           view_point_;
00361 
00362       //_
00363       Vector3           look_at_;
00364 
00365       //_
00366       Vector3           look_up_vector_;
00367 
00368       /*_ The viewing vector.
00369           Stored only for better performance in the scene.
00370       */
00371       Vector3           view_vector_;
00372   
00373       /*_ The orthogonal vector to the viewing vector, which is showing to the right.
00374           Stored only for better performance in the scene.
00375       */
00376       Vector3           right_vector_;
00377     };
00378 
00384     class BALL_VIEW_EXPORT Stage
00385     {
00386       public:
00387 
00390       class RaytracingMaterial
00391       {
00392         public:
00393           ColorRGBA ambient_color;
00394           float     ambient_intensity;
00395 
00396           ColorRGBA specular_color;
00397           float     specular_intensity;
00398 
00399           ColorRGBA reflective_color;
00400           float     reflective_intensity;
00401 
00402           float     shininess;  
00403           float     transparency;
00404       };
00405 
00409 
00412       Stage();
00413       
00415       Stage(const Stage& stage);
00416 
00418       virtual ~Stage(){}
00419 
00421       virtual void clear();
00422 
00424 
00427       
00429       virtual const List<LightSource>& getLightSources() const
00430         { return light_sources_;}
00431 
00433       virtual void addLightSource(const LightSource& light_source);
00434 
00436       virtual void removeLightSource(const LightSource& light_source) ;
00437 
00439       void clearLightSources();
00440       
00442       virtual Camera& getCamera() 
00443         { return camera_;}
00444 
00446       virtual const Camera& getCamera() const
00447         { return camera_;}
00448 
00451       virtual void setCamera(const Camera& camera)
00452         { camera_ = camera;}
00453 
00455       virtual const ColorRGBA& getBackgroundColor() const
00456         { return background_color_;}
00457 
00459       virtual void setBackgroundColor(const ColorRGBA& color)
00460         { background_color_ = color;}
00461       
00463       virtual const ColorRGBA& getInfoColor() const
00464         { return info_color_;}
00465 
00467       virtual void setInfoColor(const ColorRGBA& color)
00468         { info_color_ = color;}
00469 
00471       void showCoordinateSystem(bool state)
00472         { show_coordinate_system_ = state;}
00473 
00475       bool coordinateSystemEnabled() const
00476         { return show_coordinate_system_;}
00477 
00479       void setEyeDistance(float value) 
00480         { eye_distance_ = value;}
00481 
00483       float getEyeDistance() const
00484         { return eye_distance_;}
00485         
00487       void setFocalDistance(float value) 
00488         { focal_distance_ = value;}
00489 
00491       float getFocalDistance() const
00492         { return focal_distance_;}
00493 
00495       void setSwapSideBySideStereo(bool state)
00496         { swap_side_by_side_stereo_ = state;}
00497 
00499       bool swapSideBySideStereo() const
00500         { return swap_side_by_side_stereo_;}
00501 
00503       float getFogIntensity() const
00504         { return fog_intensity_;}
00505 
00507       void setFogIntensity(float value)
00508         { fog_intensity_ = value;}
00509         
00511       float getSpecularIntensity() const
00512         { return specular_;}
00513 
00515       void setSpecularIntensity(float value)
00516         { specular_ = value;}
00517           
00519       float getDiffuseIntensity() const
00520         { return diffuse_;}
00521 
00523       void setDiffuseIntensity(float value)
00524         { diffuse_ = value;}
00525           
00527       float getAmbientIntensity() const
00528         { return ambient_;}
00529 
00531       void setAmbientIntensity(float value)
00532         { ambient_ = value;}
00533           
00535       float getShininess() const
00536         { return shininess_;}
00537 
00539       void setShininess(float value)
00540         { shininess_ = value;}
00541       
00543 
00546       
00548       bool operator == (const Stage& stage) const;
00549 
00557       Vector3 calculateRelativeCoordinates(Vector3 pos) const;
00558 
00562       Vector3 calculateAbsoluteCoordinates(Vector3 pos) const;
00563 
00565       
00572       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00573 
00575       RaytracingMaterial& getRTMaterial() { return rt_material_; }
00576 
00578       const RaytracingMaterial& getRTMaterial() const { return rt_material_; }
00579 
00580       protected:
00581 
00582       //_
00583       ColorRGBA           background_color_;
00584 
00585       //_
00586       ColorRGBA           info_color_;
00587 
00588       //_
00589       List<LightSource>   light_sources_;
00590 
00591       //_
00592       Camera              camera_;
00593 
00594       //_
00595       bool                show_coordinate_system_;
00596 
00597       //_
00598       float               fog_intensity_;
00599 
00600       //_
00601       float               eye_distance_;
00602       
00603       //_
00604       float               focal_distance_;
00605 
00606       //_
00607       bool                swap_side_by_side_stereo_;
00608 
00609       float               specular_;
00610       float               diffuse_;
00611       float               ambient_;
00612       float               shininess_;
00613 
00614       // the current default materials used for raytracing
00615       RaytracingMaterial  rt_material_;
00616     };
00617 
00618   } // namespace VIEW
00619 } // namespace BALL
00620 
00621 #endif // BALL_VIEW_KERNEL_STAGE_H