source: golgotha/src/render/r1_clip.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 4.0 KB
RevLine 
[80]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
9#ifndef R1_CLIP_HH
10#define R1_CLIP_HH
11
12#include "r1_vert.hh"
13#include "error/error.hh"
14#include "tex_id.hh"
15
16class r1_render_api_class;
17class i4_draw_context_class;
18
19struct r1_clip_vert_array
20{
21  int buf_size;
22  int total;
23  r1_vert *buf;
24
25  r1_vert *add()
26  {
27    I4_ASSERT(total<buf_size, "clip array full");
28    total++;
29    return buf+total-1;
30  }
31
32  r1_clip_vert_array(int buf_size, r1_vert *buf, int total) : total(total), buf_size(buf_size),
33    buf(buf) { ; }
34};
35
36// clips a a polygon, returns an array indexs to new verts (contained in the orignal v array)
37int *r1_clip(r1_clip_vert_array *v_array,
38             int *src, int t_src,             // indexes into vertex array for initial verts
39             int *dst1, int *dst2,            // destination index arrays
40             int &t_dst,
41             float center_x, float center_y,
42             i4_bool clip_code_and_project_done);
43
44void r1_clip_render_lines(int t_lines, r1_vert *verts,
45                          float center_x, float center_y,
46                          r1_render_api_class *api);
47
48void r1_clip_clear_area(int x1, int y1, int x2, int y2, w32 color, float z,
49                        i4_draw_context_class &context,
50                        r1_render_api_class *api);
51
52/// clips to window dimensions, but leaves clip list to the z buffer
53void r1_clip_render_textured_rect(float x1, float y1, float x2, float y2, float z, float a,
54                                  int win_width, int win_height,
55                                  r1_texture_handle handle,
56                                  int frame,
57                                  r1_render_api_class *api,
58                                  float s1=0, float t1=0,
59                                  float s2=1, float t2=1);
60                                 
61inline i4_float r1_clip_delta() { return 0.001; }
62
63extern i4_float r1_near_clip_z;
64extern i4_float r1_far_clip_z;
65
66inline w8 r1_calc_outcode(i4_3d_vector &v)
67{
68  w8 clip_code = 0;
69
70  if (v.x>(v.z))    clip_code |= 1;
71  else
72  if (v.x<-(v.z))   clip_code |= 2; 
73 
74  if (v.y>(v.z))    clip_code |= 4;
75  else
76  if (v.y<-(v.z))   clip_code |= 8;
77 
78  if (v.z<r1_near_clip_z)     clip_code |=16;
79  else if (v.z>r1_far_clip_z) clip_code |=32;
80
81  return clip_code;
82}
83
84inline w8 r1_calc_ortho_outcode(i4_3d_vector &v)
85{
86  w8 clip_code = 0;
87
88  if (v.x>1.0)    clip_code |= 1;
89  else
90  if (v.x<-1.0)   clip_code |= 2; 
91 
92  if (v.y>1.0)    clip_code |= 4;
93  else
94  if (v.y<-1.0)   clip_code |= 8;
95 
96  if (v.z<r1_near_clip_z)     clip_code |=16;
97  else if (v.z>r1_far_clip_z) clip_code |=32; 
98 
99  return clip_code;
100}
101
102enum {R1_CLIP_NO_CALC_OUTCODE=1, R1_CLIP_ORTHO=128, R1_CLIP_PROJECT_CLIPPED_POINTS=2};
103
104inline w8 r1_calc_outcode(r1_vert *v)
105{
106  w8 clip_code=0;
107
108  if (v->v.x>(v->v.z))    clip_code |= 1;
109  else
110  if (v->v.x<-(v->v.z))   clip_code |= 2; 
111 
112  if (v->v.y>(v->v.z))    clip_code |= 4;
113  else
114  if (v->v.y<-(v->v.z))   clip_code |= 8;
115 
116  if (v->v.z<r1_near_clip_z)     clip_code |=16;
117  else if (v->v.z>r1_far_clip_z) clip_code |=32; 
118 
119  v->outcode = clip_code;
120
121  return clip_code;
122}
123
124inline w8 r1_calc_ortho_outcode(r1_vert *v)
125{
126  w8 clip_code=0;
127
128  if (v->v.x>1.0)    clip_code |= 1;
129  else
130  if (v->v.x<-1.0)   clip_code |= 2;
131 
132  if (v->v.y>1.0)    clip_code |= 4;
133  else
134  if (v->v.y<-1.0)   clip_code |= 8;
135 
136  if (v->v.z<r1_near_clip_z)     clip_code |=16;
137  else if (v->v.z>r1_far_clip_z) clip_code |=32; 
138 
139  v->outcode = clip_code;
140
141  return clip_code;
142}
143
144#endif
Note: See TracBrowser for help on using the repository browser.