render.hh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #ifndef __M1_RENDER_HH_
  9. #define __M1_RENDER_HH_
  10. #include "time/time.hh"
  11. #include "window/window.hh"
  12. #include "window/wmanager.hh"
  13. #include "math/transform.hh"
  14. #include "math/point.hh"
  15. #include "obj3d.hh"
  16. #include "r1_api.hh"
  17. #include "light.hh"
  18. #include "max_object.hh"
  19. #include "player_type.hh"
  20. #include "m1_info.hh"
  21. class m1_utility_state_class;
  22. class m1_utility_window_class : public i4_parent_window_class
  23. {
  24. private:
  25. int grab;
  26. int last_x, last_y, last_but;
  27. i4_float center_x, center_y, scale_x, scale_y;
  28. void calc_params()
  29. //{{{
  30. {
  31. int win_w=width(), win_h=height();
  32. w32 max_dim=win_w > win_h ? win_w : win_h;
  33. center_x=(i4_float)win_w/2.0;
  34. center_y=(i4_float)win_h/2.0;
  35. scale_x = (float)max_dim/win_w;
  36. scale_y = (float)max_dim/win_h;
  37. }
  38. //}}}
  39. friend m1_utility_state_class;
  40. m1_utility_state_class *state;
  41. i4_bool animating;
  42. i4_time_class last_time;
  43. m1_poly_object_class *get_obj() { return m1_info.obj; }
  44. w32 draws_needed;
  45. i4_float focal_length() { return 300; }
  46. i4_window_manager_class *wm;
  47. r1_render_api_class *api;
  48. void drop_files(int t_files, i4_str **filenames);
  49. public:
  50. enum
  51. // Grab Masks for input
  52. {
  53. LEFT_BUTTON = 1,
  54. RIGHT_BUTTON = 2,
  55. MIDDLE_BUTTON = 4,
  56. LEFT_KEY = 8,
  57. RIGHT_KEY = 16,
  58. MIDDLE_KEY = 32,
  59. LEFT = LEFT_BUTTON | LEFT_KEY,
  60. RIGHT = RIGHT_BUTTON | RIGHT_KEY,
  61. MIDDLE = MIDDLE_BUTTON | MIDDLE_KEY,
  62. };
  63. w32 background_color;
  64. i4_angle theta,phi;
  65. i4_float dist, pan_x, pan_y, pan_z;
  66. g1_player_type current_player;
  67. i4_transform_class transform;
  68. char *name() { return "m1_utility_window_class"; }
  69. m1_utility_window_class(w16 window_width,
  70. w16 window_height,
  71. r1_render_api_class *api,
  72. i4_window_manager_class *wm,
  73. i4_float theta,
  74. i4_float phi,
  75. i4_float dist);
  76. void init();
  77. void recenter();
  78. void recalc_view();
  79. i4_bool is_animating() const { return animating; }
  80. void set_animation(i4_bool on) { last_time.get(); animating = on; request_redraw(); }
  81. void get_configuration(i4_float &_theta,
  82. i4_float &_phi,
  83. i4_float &_dist)
  84. //{{{
  85. {
  86. _theta=theta;
  87. _phi=phi;
  88. _dist=dist;
  89. }
  90. //}}}
  91. virtual void receive_event(i4_event *ev);
  92. i4_bool project_point(const i4_3d_point_class &p, r1_vert &v);
  93. void draw_3d_text(i4_3d_point_class p1, const i4_const_str &text,
  94. w32 color,
  95. i4_draw_context_class &context);
  96. void draw_3d_line(i4_3d_point_class p1,i4_3d_point_class p2,i4_color color, i4_bool on_top=i4_F);
  97. void draw_3d_point(i4_3d_point_class p, i4_color color, i4_bool on_top=i4_F);
  98. void draw_plane(const i4_3d_vector &u, const i4_3d_vector &v, w8 color);
  99. void update_object(i4_float time);
  100. void render_object(i4_draw_context_class &context);
  101. virtual void parent_draw(i4_draw_context_class &context);
  102. void set_current_player(g1_player_type player) { current_player=player; }
  103. void pan(i4_float x, i4_float y);
  104. void set_object(const i4_const_str &filename);
  105. void select_poly(int poly_num);
  106. i4_bool find_hit(int mouse_x, int mouse_y);
  107. void xlate_selected(int fromx, int fromy, int tox, int toy);
  108. void set_state(m1_utility_state_class *_state)
  109. //{{{
  110. {
  111. state = _state;
  112. }
  113. //}}}
  114. void restore_state();
  115. };
  116. class m1_utility_state_class
  117. {
  118. public:
  119. i4_float center_x() const;
  120. i4_float center_y() const;
  121. i4_float scale_x() const;
  122. i4_float scale_y() const;
  123. int width() const;
  124. int height() const;
  125. int mouse_x() const;
  126. int mouse_y() const;
  127. int buttons() const;
  128. int last_x() const;
  129. int last_y() const;
  130. virtual i4_bool mouse_down() { return i4_F; }
  131. virtual i4_bool mouse_drag() { return i4_F; }
  132. virtual i4_bool mouse_up() { return i4_F; }
  133. };
  134. extern i4_event_handler_reference_class<m1_utility_window_class> m1_render_window;
  135. inline w32 m1_texture_memory_size() { return 2048*1024; }
  136. #endif
  137. //{{{ Emacs Locals
  138. // Local Variables:
  139. // folded-file: t
  140. // End:
  141. //}}}