inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_ghost 00005 #define inlib_sg_ghost 00006 00007 // To have a non visible picking area. 00008 // Used to do the bottom "meta zone" in ioda. 00009 00010 #include "node" 00011 #include "cbks" 00012 00013 #include "pick_action" 00014 #include "sf" 00015 #include "../mat4f" 00016 00017 namespace inlib { 00018 namespace sg { 00019 00020 class ghost : public node, public cbks { 00021 public: 00022 static const std::string& s_class() { 00023 static const std::string s_v("inlib::sg::ghost"); 00024 return s_v; 00025 } 00026 public: 00027 virtual void* cast(const std::string& a_class) const { 00028 if(void* p = inlib::cmp_cast<ghost>(this,a_class)) return p; 00029 return inlib::sg::node::cast(a_class); 00030 } 00031 public: 00032 inlib::sg::sf<float> width; 00033 inlib::sg::sf<float> height; 00034 private: 00035 void add_fields(){ 00036 add_field(&width); 00037 add_field(&height); 00038 } 00039 public: //node 00040 virtual node* copy() const {return new ghost(*this);} 00041 virtual const std::string& s_cls() const {return s_class();} 00042 public: 00043 //render is empty. 00044 virtual void pick(inlib::sg::pick_action& a_action) { 00045 if(width.value()<=0) return; 00046 if(height.value()<=0) return; 00047 00048 inlib::mat4f mtx = a_action.projection_matrix(); 00049 mtx *= a_action.model_matrix(); 00050 00051 float xb = -width.value()*0.5f; 00052 float xe = width.value()*0.5f; 00053 float yb = -height.value()*0.5f; 00054 float ye = height.value()*0.5f; 00055 00056 float p1x,p1y,p2x,p2y,p3x,p3y; 00057 {p1x = xb; 00058 p1y = yb; 00059 mtx.mul_2f(p1x,p1y); 00060 00061 p2x = xe; 00062 p2y = yb; 00063 mtx.mul_2f(p2x,p2y); 00064 00065 p3x = xe; 00066 p3y = ye; 00067 mtx.mul_2f(p3x,p3y); 00068 00069 if(a_action.intersect(p1x,p1y,p2x,p2y,p3x,p3y)) { 00070 a_action.set_done(true); 00071 a_action.set_node(this); 00072 return; 00073 }} 00074 00075 {p1x = xe; 00076 p1y = ye; 00077 mtx.mul_2f(p1x,p1y); 00078 00079 p2x = xb; 00080 p2y = ye; 00081 mtx.mul_2f(p2x,p2y); 00082 00083 p3x = xb; 00084 p3y = yb; 00085 mtx.mul_2f(p3x,p3y); 00086 00087 if(a_action.intersect(p1x,p1y,p2x,p2y,p3x,p3y)) { 00088 a_action.set_done(true); 00089 a_action.set_node(this); 00090 return; 00091 }} 00092 } 00093 public: 00094 ghost() 00095 : node(),cbks() 00096 ,width(1) 00097 ,height(1) 00098 { 00099 add_fields(); 00100 } 00101 virtual ~ghost(){} 00102 public: 00103 ghost(const ghost& a_from) 00104 : node(a_from),cbks(a_from) 00105 ,width(a_from.width) 00106 ,height(a_from.height) 00107 { 00108 add_fields(); 00109 } 00110 ghost& operator=(const ghost& a_from){ 00111 node::operator=(a_from); 00112 cbks::operator=(a_from); 00113 width = a_from.width; 00114 height = a_from.height; 00115 return *this; 00116 } 00117 }; 00118 00119 }} 00120 00121 #endif