source: golgotha/src/golg/clip.hh

Last change on this file was 80, checked in by Sam Hocevar, 12 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: 2.6 KB
Line 
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 G1_CLIP_HH
10#define G1_CLIP_HH
11
12#error "don't use this file anymore"
13
14#include "draw_context.hh"
15#include "math/vector.hh"
16#include "poly/poly.hh"
17#include "poly/polyclip.hh"
18
19
20inline i4_float g1_clip_delta() { return 0.001; }
21
22inline w8 g1_calc_clip_code(i4_3d_vector &v, i4_float near_z, i4_float far_z, i4_bool clip_far)
23{
24  float zp = v.z;// + g1_clip_delta();
25
26  w8 clip_code=0;
27
28  if (v.x>zp) 
29    clip_code |= 1;
30  else if (v.x<-(zp))
31    clip_code |= 2;
32 
33  if (v.y>zp ) 
34    clip_code |= 4;
35  else  if (v.y<-(zp))
36    clip_code |= 8;
37 
38  if (v.z<near_z)// + g1_clip_delta())   
39    clip_code |=16;
40  else if (clip_far && v.z>far_z)// - g1_clip_delta())
41    clip_code |=32;
42
43  return clip_code;
44}
45
46
47class g1_3d_clip_helper
48{
49public:
50
51  g1_draw_context_class *context;
52  i4_float cz1,cz2;
53
54
55  g1_3d_clip_helper(g1_draw_context_class *context, i4_float cz1, i4_float cz2)
56    : context(context),
57      cz1(cz1),
58      cz2(cz2)
59  {
60  }
61
62  i4_float intersect(i4_vertex_class *i, i4_vertex_class *j, w32 plane)
63  {
64    switch (plane)
65    {
66      case I4_CLIP_PLANE_Y2 : // bottom
67        return (i->v.y - i->v.z*half_clipy()) /
68          ((j->v.z - i->v.z)*half_clipy() - j->v.y + i->v.y);
69       
70      case I4_CLIP_PLANE_Y1: // top
71        return (- i->v.z*half_clipy() - i->v.y) /
72          ((j->v.z - i->v.z)*half_clipy() + j->v.y - i->v.y);
73
74      case I4_CLIP_PLANE_X2: // right
75        return (i->v.x - i->v.z*half_clipx()) /
76          ((j->v.z - i->v.z)*half_clipx() - j->v.x + i->v.x);
77
78      case I4_CLIP_PLANE_X1: // left
79        return (- i->v.z*half_clipx() - i->v.x) /
80          ((j->v.z - i->v.z)*half_clipx() + j->v.x - i->v.x);
81
82      case I4_CLIP_PLANE_Z2: // far
83        return (cz2 - i->v.z) / (j->v.z - i->v.z);
84
85      case I4_CLIP_PLANE_Z1: // near
86        return (cz1 - i->v.z) / (j->v.z - i->v.z);
87    }
88    return 0;
89  }
90
91  void project(i4_vertex_class *i)
92  {
93    i4_float w = 1.0 / i->v.z;
94    i->px = i->v.x*w + context->center_x;
95    i->py = i->v.y*w + context->center_y;
96  }
97
98};
99
100
101#endif
Note: See TracBrowser for help on using the repository browser.