translate.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "lisp/li_init.hh"
  9. #include "m1_info.hh"
  10. #include "max_object.hh"
  11. #include "render.hh"
  12. class m1_translate_state_class : public m1_utility_state_class
  13. {
  14. public:
  15. virtual i4_bool mouse_drag()
  16. {
  17. g1_quad_object_class *obj=m1_info.obj;
  18. if (obj)
  19. {
  20. // get translation
  21. i4_3d_vector point,ray;
  22. i4_float px,py;
  23. px = (i4_float(last_x())-center_x())/(center_x()*scale_x());
  24. py = (i4_float(last_y())-center_y())/(center_y()*scale_y());
  25. m1_render_window->transform.inverse_transform(i4_3d_vector(px,py,1.0), point);
  26. px = (i4_float(mouse_x())-center_x())/(center_x()*scale_x());
  27. py = (i4_float(mouse_y())-center_y())/(center_y()*scale_y());
  28. m1_render_window->transform.inverse_transform(i4_3d_vector(px,py,1.0), ray);
  29. ray -= point;
  30. g1_vert_class *src_vert = obj->get_verts(m1_info.current_animation, m1_info.current_frame);
  31. for (int i=0; i<obj->num_vertex; i++)
  32. {
  33. if (i==m1_info.preselect_point)
  34. src_vert[i].v += ray;
  35. }
  36. return i4_T;
  37. }
  38. return i4_F;
  39. }
  40. };
  41. static m1_translate_state_class translate;
  42. li_object *m1_translate(li_object *o, li_environment *env)
  43. {
  44. if (m1_info.obj && m1_info.preselect_point)
  45. m1_render_window->set_state(&translate);
  46. return 0;
  47. }
  48. li_automatic_add_function(m1_translate, "translate_point");