Warning, /include/Geant4/tools/sg/perspective is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_perspective
0005 #define tools_sg_perspective
0006
0007 #include "base_camera"
0008
0009 #include "../mathf"
0010
0011 namespace tools {
0012 namespace sg {
0013
0014 class perspective : public base_camera {
0015 TOOLS_NODE(perspective,tools::sg::perspective,base_camera)
0016 public:
0017 virtual float near_height() const {
0018 return 2.0f*znear.value()*ftan(height_angle.value()*0.5f);
0019 }
0020 virtual void zoom(float a_fac) {
0021 //for exa :
0022 // a_fac = 0.99f is a zoom in
0023 // a_fac = 1.01f is a zoom out
0024 height_angle.value(height_angle.value()*a_fac);
0025 }
0026 virtual camera_type type() const {return camera_perspective;}
0027 public:
0028 sf<float> height_angle;
0029 public:
0030 virtual const desc_fields& node_desc_fields() const {
0031 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::perspective)
0032 static const desc_fields s_v(parent::node_desc_fields(),1, //WARNING : take care of count.
0033 TOOLS_ARG_FIELD_DESC(height_angle)
0034 );
0035 return s_v;
0036 }
0037 private:
0038 void add_fields(){
0039 add_field(&height_angle);
0040 }
0041 public:
0042 perspective()
0043 :parent()
0044 ,height_angle(fpi()/4.0f) //45 degrees.
0045 {
0046 add_fields();
0047 }
0048 virtual ~perspective(){
0049 }
0050 public:
0051 perspective(const perspective& a_from)
0052 :parent(a_from)
0053 ,height_angle(a_from.height_angle)
0054 {
0055 add_fields();
0056 }
0057 perspective& operator=(const perspective& a_from){
0058 parent::operator=(a_from);
0059 height_angle = a_from.height_angle;
0060 return *this;
0061 }
0062 public: //operators:
0063 bool operator==(const perspective& a_from) const{
0064 if(!parent::operator==(a_from)) return false;
0065 if(height_angle!=a_from.height_angle) return false;
0066 return true;
0067 }
0068 bool operator!=(const perspective& a_from) const {
0069 return !operator==(a_from);
0070 }
0071 public:
0072 void dump(std::ostream& a_out) {
0073 parent::dump(a_out);
0074 a_out << " height_angle " << height_angle.value() << std::endl;
0075 }
0076
0077 protected:
0078 virtual void get_lrbt(unsigned int a_ww,unsigned int a_wh,
0079 float& a_l,float& a_r,float& a_b,float& a_t) {
0080 float aspect = float(a_ww)/float(a_wh);
0081 float hh = near_height()*0.5f;
0082 a_l = -aspect*hh;
0083 a_r = aspect*hh;
0084 a_b = -hh;
0085 a_t = hh;
0086 }
0087 };
0088
0089 inline perspective* cast_perspective(base_camera& a_bcam) {return safe_cast<base_camera,perspective>(a_bcam);}
0090
0091 }}
0092
0093 #endif