inlib  1.2.0
Public Member Functions
inlib::sg::pick_action Class Reference
Inheritance diagram for inlib::sg::pick_action:
Inheritance graph
[legend]
Collaboration diagram for inlib::sg::pick_action:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 pick_action (std::ostream &a_out, unsigned int a_ww, unsigned int a_wh, float a_l, float a_r, float a_b, float a_t)
virtual ~pick_action ()
void reset ()
void set_done (bool a_value)
bool done () const
void set_node (inlib::sg::node *a_node)
inlib::sg::nodenode () const
void set_area (float a_l, float a_r, float a_b, float a_t)
bool is_inside (float a_x, float a_y) const
bool intersect (float a_bx, float a_by, float a_ex, float a_ey) const
bool intersect (float a_1x, float a_1y, float a_2x, float a_2y, float a_3x, float a_3y) const

Detailed Description

Definition at line 23 of file pick_action.


Constructor & Destructor Documentation

inlib::sg::pick_action::pick_action ( std::ostream &  a_out,
unsigned int  a_ww,
unsigned int  a_wh,
float  a_l,
float  a_r,
float  a_b,
float  a_t 
) [inline]

Definition at line 38 of file pick_action.

  : mtx_action(a_out,a_ww,a_wh)
  ,m_l(a_l)
  ,m_r(a_r)
  ,m_b(a_b)
  ,m_t(a_t)
  ,m_done(false)
  ,m_node(0)
  {
    set_to_pick_ndc(); //OPTIMIZATION
  }
virtual inlib::sg::pick_action::~pick_action ( ) [inline, virtual]

Definition at line 52 of file pick_action.

                        {
    //clear_cbks();
  }

Member Function Documentation

bool inlib::sg::pick_action::done ( ) const [inline]

Definition at line 72 of file pick_action.

{return m_done;}
bool inlib::sg::pick_action::intersect ( float  a_bx,
float  a_by,
float  a_ex,
float  a_ey 
) const [inline]

Definition at line 138 of file pick_action.

                                                     {

    // ortho_clip_line works by testing against a [-1,1]x[-1,1] box.
    // In principle we should receive (because of proj x model matrix
    // mult of world coord points) points in [-1,1]x[-1,1] too.

    float bx,by;
    to_pick_ndc(a_bx,a_by,bx,by);

    float ex,ey;
    to_pick_ndc(a_ex,a_ey,ex,ey);

    //no check on z is done.
    float bz = 0;
    float ez = 0;

    bool toggle;
    bool status = ortho_clip_line(bx,by,bz,ex,ey,ez,false,toggle);

    //if(status) {
    //  std::cout << "debug : inlib::sg::pick_action::intersect :"
    //        << " intersect !"
    //        << std::endl;
    //}

    return status;
  }
bool inlib::sg::pick_action::intersect ( float  a_1x,
float  a_1y,
float  a_2x,
float  a_2y,
float  a_3x,
float  a_3y 
) const [inline]

Definition at line 167 of file pick_action.

                                                     {
    //test a triangle.

    if(is_inside(a_1x,a_1y)) return true;
    if(is_inside(a_2x,a_2y)) return true;
    if(is_inside(a_3x,a_3y)) return true;
    
    // alll points are outside. 

    if(intersect(a_1x,a_1y, a_2x,a_2y)) return true;
    if(intersect(a_2x,a_2y, a_3x,a_3y)) return true;
    if(intersect(a_1x,a_1y, a_3x,a_3y)) return true;

    // no intersection with edges.
    // but the triangle may surround [-1,1]x[-1,1] !

    float x1,y1;
    to_pick_ndc(a_1x,a_1y,x1,y1);
    float x2,y2;
    to_pick_ndc(a_2x,a_2y,x2,y2);
    float x3,y3;
    to_pick_ndc(a_3x,a_3y,x3,y3);

    // test if (0,0) is inside the triangle :    
    inlib::vec2f p1(x1,y1);
    inlib::vec2f p2(x2,y2);
    inlib::vec2f p3(x3,y3);

    //std::cout << "pick_action::intersect : " << std::endl;
    //std::cout << " p1 " << p1[0] << " " << p1[1] << std::endl;
    //std::cout << " p2 " << p2[0] << " " << p2[1] << std::endl;
    //std::cout << " p3 " << p3[0] << " " << p3[1] << std::endl;

    inlib::vec2f o(0,0);

   {float cp2 = (p2-p1).cross(p3-p1);
    if(cp2==0) return false;       // (p1,p2,p3) aligned points.
    float cp1 = (p2-p1).cross( o-p1);
    if(cp1==0) return true;        // o on (p1,p2). We can't pass here.
    if((cp1*cp2)<0) return false;} // o p3 not on same side than (p1,p2)

   {float cp2 = (p3-p2).cross(p1-p2);
    if(cp2==0) return false;       // (p1,p2,p3) aligned points.
    float cp1 = (p3-p2).cross( o-p2);
    if(cp1==0) return true;        // o on (p2,p3). We can't pass here.
    if((cp1*cp2)<0) return false;} // o p1 not on same side than (p2,p3)

   {float cp2 = (p1-p3).cross(p2-p3);
    if(cp2==0) return false;       // (p1,p2,p3) aligned points.
    float cp1 = (p1-p3).cross( o-p3);
    if(cp1==0) return true;        // o on (p3,p1). We can't pass here.
    if((cp1*cp2)<0) return false;} // o p2 not on same side than (p3,p1)

    //std::cout << " (0,0) inside. " << std::endl;

    return true;
  }
bool inlib::sg::pick_action::is_inside ( float  a_x,
float  a_y 
) const [inline]

Definition at line 115 of file pick_action.

                                            {
    //std::cout << "debug : inlib::sg::pick_action::is_inside :"
    //      << " x " << a_x
    //      << " y " << a_y
    //      << std::endl;

    // In principle we should receive (because of proj x model matrix
    // mult of world coord points) point in [-1,1]x[-1,1].

    float x,y;
    to_pick_ndc(a_x,a_y,x,y);

    if(x<-1) return false;
    if(1<x) return false;
    if(y<-1) return false;
    if(1<y) return false;

    //std::cout << "debug : inlib::sg::pick_action::is_inside :"
    //      << " inside !"
    //      << std::endl;

    return true;
  }
inlib::sg::node* inlib::sg::pick_action::node ( ) const [inline]

Definition at line 75 of file pick_action.

{return m_node;}
void inlib::sg::pick_action::reset ( ) [inline]

Reimplemented from inlib::sg::mtx_action.

Definition at line 64 of file pick_action.

               {
    mtx_action::reset();
    m_done = false;
    m_node = 0;
    //clear_cbks();
  }
void inlib::sg::pick_action::set_area ( float  a_l,
float  a_r,
float  a_b,
float  a_t 
) [inline]

Definition at line 103 of file pick_action.

                                            {
    // a_l,a_r,a_b,a_t are in window coordinates (pixels)
    // but handled in floats for intersection computation precision.
    // WARNING : we must have a_t>a_b and a_r>a_l. No check is done for that. 
    m_l = a_l;
    m_r = a_r;
    m_b = a_b;
    m_t = a_t;
    set_to_pick_ndc(); //OPTIMIZATION
  }
void inlib::sg::pick_action::set_done ( bool  a_value) [inline]

Definition at line 71 of file pick_action.

{m_done = a_value;}
void inlib::sg::pick_action::set_node ( inlib::sg::node a_node) [inline]

Definition at line 74 of file pick_action.

{m_node = a_node;}

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines