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 #ifdef TOOLS_MEM
0047 mem::increment(s_class().c_str());
0048 #endif
0049 add_fields();
0050 }
0051 virtual ~perspective(){
0052 #ifdef TOOLS_MEM
0053 mem::decrement(s_class().c_str());
0054 #endif
0055 }
0056 public:
0057 perspective(const perspective& a_from)
0058 :parent(a_from)
0059 ,height_angle(a_from.height_angle)
0060 {
0061 #ifdef TOOLS_MEM
0062 mem::increment(s_class().c_str());
0063 #endif
0064 add_fields();
0065 }
0066 perspective& operator=(const perspective& a_from){
0067 parent::operator=(a_from);
0068 height_angle = a_from.height_angle;
0069 return *this;
0070 }
0071 public: //operators:
0072 bool operator==(const perspective& a_from) const{
0073 if(!parent::operator==(a_from)) return false;
0074 if(height_angle!=a_from.height_angle) return false;
0075 return true;
0076 }
0077 bool operator!=(const perspective& a_from) const {
0078 return !operator==(a_from);
0079 }
0080 public:
0081 void dump(std::ostream& a_out) {
0082 parent::dump(a_out);
0083 a_out << " height_angle " << height_angle.value() << std::endl;
0084 }
0085
0086 protected:
0087 virtual void get_lrbt(unsigned int a_ww,unsigned int a_wh,
0088 float& a_l,float& a_r,float& a_b,float& a_t) {
0089 float aspect = float(a_ww)/float(a_wh);
0090 float hh = near_height()*0.5f;
0091 a_l = -aspect*hh;
0092 a_r = aspect*hh;
0093 a_b = -hh;
0094 a_t = hh;
0095 }
0096 };
0097
0098 inline perspective* cast_perspective(base_camera& a_bcam) {return safe_cast<base_camera,perspective>(a_bcam);}
0099
0100 }}
0101
0102 #endif