00001 #include "std/support.H"
00002 #include "disp/ray.H"
00003 #include "geom/fsa.H"
00004 #include "geom/geom.H"
00005 #include "geom/world.H"
00006 #include "manip/manip.H"
00007
00008 using mlib::Wpt;
00009 using mlib::CWpt;
00010 using mlib::Wvec;
00011 using mlib::CWvec;
00012 using mlib::Wline;
00013 using mlib::Wtransf;
00014 using mlib::XYpt;
00015 using mlib::CXYpt;
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 Simple_int::Simple_int(
00026 CEvent &down_ev,
00027 CEvent &move_ev,
00028 CEvent &up_ev
00029 )
00030 {
00031 static Cstr_ptr default_entry_name("Simple_int Entry");
00032 static Cstr_ptr default_move_name ("Simple_int Move");
00033 _entry .set_name(default_entry_name);
00034 _manip_move.set_name(default_move_name);
00035
00036 _manip_move += Arc(move_ev, Cb(&Simple_int::move));
00037 _manip_move += Arc(up_ev, Cb(&Simple_int::up, (State *)-1));
00038 _entry += Arc(down_ev, Cb(&Simple_int::down, &_manip_move));
00039 }
00040
00041 void
00042 Simple_int::add_events(
00043 CEvent &down_ev,
00044 CEvent &move_ev,
00045 CEvent &up_ev
00046 )
00047 {
00048 _manip_move += Arc(move_ev, Cb(&Simple_int::move));
00049 _manip_move += Arc(up_ev, Cb(&Simple_int::up, (State *)-1));
00050 _entry += Arc(down_ev, Cb(&Simple_int::down, &_manip_move));
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 void
00066 Key_int::add_event(
00067 char *k,
00068 State *start
00069 )
00070 {
00071 for (char *c = k; *c; c++) {
00072 Event down_ev(NULL, Evd(*c, KEYD));
00073 Event up_ev (NULL, Evd(*c, KEYU));
00074 _key_down += Arc(up_ev, Cb(&Key_int::up, start));
00075 _entry += Arc(down_ev, Cb(&Key_int::down, &_key_down));
00076 }
00077 }
00078
00079 void
00080 Key_int::add_event(
00081 char k,
00082 State *start
00083 )
00084 {
00085 Event down_ev(NULL, Evd(k, KEYD));
00086 Event up_ev (NULL, Evd(k, KEYU));
00087 _key_down += Arc(up_ev, Cb(&Key_int::up, start));
00088 _entry += Arc(down_ev, Cb(&Key_int::down, &_key_down));
00089 }
00090
00091
00092
00093
00094 FilmTrans::FilmTrans(
00095 CEvent &d,
00096 CEvent &m,
00097 CEvent &u
00098 ):Simple_int(d,m,u), _call_xform_obs(true)
00099 {
00100 _entry .set_name("FilmTrans Entry");
00101 _manip_move.set_name("FilmTrans Move");
00102 }
00103
00104 int
00105 FilmTrans::down(
00106 CEvent &e,
00107 State *&s
00108 )
00109 {
00110 DEVice_buttons *btns=(DEVice_buttons *)e._d;
00111 DEVice_2d *ptr=btns->ptr2d();
00112 RAYhit r(ptr->cur());
00113 GEOMptr geom;
00114
00115 if (e.view()->intersect(r,VIEW::H_TEXT).success() && GEOM::isa(r.geom())) {
00116 geom = ray_geom(r, GEOM::null);
00117 if (geom->interactive(e, s, &r)) {
00118 _obj = 0;
00119 _no_xform = 1;
00120 return 1;
00121 }
00122 }
00123
00124
00125 if (!r.success() || (geom && NO_XFORM_MOD.get(geom))) {
00126 _no_xform = 1;
00127 _obj = geom;
00128 } else {
00129 if (CONSTRAINT.get(geom) == GEOM::SCREEN_WIDGET)
00130 _down_pt = geom->xform();
00131 else _down_pt = r.surf();
00132
00133 _down_norm = r.norm();
00134 _obj = geom;
00135
00136 if (_call_xform_obs)
00137 XFORMobs::notify_xform_obs(_obj, XFORMobs::START);
00138 _no_xform = 0;
00139 }
00140
00141 return 0;
00142 }
00143
00144 int
00145 FilmTrans::move(
00146 CEvent &e,
00147 State *&
00148 )
00149 {
00150 DEVice_2d *ptr=(DEVice_2d *)e._d;
00151 CAMptr cam(e.view()->cam());
00152 if (_obj) {
00153 Wpt cur(Wpt(ptr->cur(),_down_pt));
00154 Wpt old(Wpt(ptr->old(),_down_pt));
00155 _obj->mult_by(Wtransf::translation(cur-old));
00156 if (_call_xform_obs)
00157 XFORMobs::notify_xform_obs(_obj, XFORMobs::MIDDLE);
00158 }
00159
00160 return 0;
00161 }
00162
00163
00164 int
00165 FilmTrans::up(
00166 CEvent &,
00167 State *&
00168 )
00169 {
00170
00171 if (_obj && _call_xform_obs)
00172 XFORMobs::notify_xform_obs(_obj, XFORMobs::END);
00173
00174
00175 _obj = (GEOMptr) 0;
00176
00177 return 0;
00178 }
00179
00180
00181 void
00182 scale_along_normal(
00183 CGEOMptr &obj,
00184 CWpt &scale_cent,
00185 CWpt &down_pt,
00186 CWvec &down_norm,
00187 CXYpt &cur
00188 )
00189 {
00190 Wtransf xf (obj->xform());
00191 Wpt dpt (xf * down_pt);
00192 Wpt spt (xf * scale_cent);
00193 Wvec upv ((xf * down_norm).normalized());
00194
00195 if (upv * (dpt - spt) < 0)
00196 upv = -upv;
00197
00198 if ((cur - XYpt(dpt)).length() < 0.01)
00199 return;
00200
00201 Wpt npt(Wline(dpt,upv).intersect(cur));
00202 Wpt ctr(xf * scale_cent);
00203 double sval(((npt-dpt) * upv) / (dpt-ctr).length());
00204
00205 if ((npt-ctr) * (dpt-ctr) < 0)
00206 return;
00207
00208 Wvec dnorm (fabs(down_norm[0]),fabs(down_norm[1]),
00209 fabs(down_norm[2]));
00210
00211 ((GEOMptr)obj)->set_xform(xf *
00212 Wtransf::scaling(scale_cent,
00213 (dnorm*sval+Wvec(1,1,1))));
00214 }
00215