1 package com.insanityengine.ghia.libograf;
2
3 import java.awt.*;
4 import java.awt.image.*;
5 import java.awt.event.*;
6 import java.applet.*;
7
8 import com.insanityengine.ghia.m3.*;
9
10 /***
11 *
12 * <P>
13 * Typical zbuffer crap
14 * </P>
15 *
16 * @author BrianHammond
17 *
18 * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/libograf/ZeeBuffer.java,v 1.4 2005/03/19 17:50:02 brian Exp $
19 *
20 */
21
22 public class ZeeBuffer {
23
24 /***
25 *
26 * Constructor
27 *
28 */
29 public ZeeBuffer() {}
30
31 /***
32 *
33 * Constructor
34 *
35 * @param width of the buffer
36 * @param height of the buffer
37 *
38 */
39 public ZeeBuffer( int width, int height ) {
40 init( width, height );
41 }
42
43
44
45
46
47
48
49
50
51 public final void init( int width, int height ) {
52 this.w = width;
53 this.h = height;
54
55 max = w * h;
56 zbuffer = new float[ max ];
57 }
58
59 /***
60 *
61 * Get the current value for "far"
62 *
63 * @return the current value for "far"
64 *
65 */
66 public final float getFar() {
67 return zFar;
68 }
69
70 /***
71 *
72 * Set the value for "far"
73 *
74 * @param far value to use
75 *
76 */
77 public final void setFar( float far ) {
78 this.zFar = far;
79 }
80
81 /***
82 *
83 * Determines the width of the buffer.
84 *
85 * @return the width of this buffer
86 *
87 */
88 public final int getWidth() {
89 return w;
90 }
91
92 /***
93 *
94 * Determines the height of the buffer.
95 *
96 * @return the height of this buffer
97 *
98 */
99 public final int getHeight() {
100 return h;
101 }
102
103 /***
104 *
105 * Set and return true if this value is closer than the
106 * point currently registered at (x,y,z)
107 *
108 * @param x coordinate
109 * @param y coordinate
110 * @param z coordinate
111 *
112 * @return true if closer, false if not
113 *
114 */
115 public final boolean set( float x, float y, float z ) {
116 return set( ( int ) ( x + y * w ), z );
117 }
118
119 /***
120 *
121 * Get the depth at screen coordinates
122 *
123 * @param x coordinate
124 * @param y coordinate
125 *
126 * @return the depth
127 *
128 */
129 public final float get( float x, float y ) {
130 return get( ( int ) ( x + y * w ) );
131 }
132
133 /***
134 *
135 * Set and return true if this value is closer than the
136 * point currently registered at index
137 *
138 * @param index to check
139 * @param z coordinate
140 *
141 * @return true if closer, false if not
142 *
143 */
144 public final boolean set( int index, float z ) {
145 if ( z > zbuffer[ index ] ) return false;
146 zbuffer[ index ] = z;
147 return true;
148 }
149
150 /***
151 *
152 * Get the depth at screen coordinates
153 *
154 * @param index to check
155 *
156 * @return the depth
157 *
158 */
159 public final float get( int index ) {
160 return zbuffer[ index ];
161 }
162
163 /***
164 *
165 * Clear (reset to zfar) all the cells in the buffer
166 *
167 */
168 public final void clear() {
169 int cleared = 1;
170 zbuffer[ 0 ] = zFar;
171 for ( cleared = 1 ; cleared < max / 2 ; cleared *= 2 ) {
172 System.arraycopy( zbuffer, 0, zbuffer, cleared, cleared );
173 }
174 System.arraycopy( zbuffer, 0, zbuffer, cleared, max - cleared );
175 }
176
177
178
179 private int w = 0;
180 private int h = 0;
181 private int max = 0;
182
183 private float zbuffer[] = null;
184
185 private float zFar = M3_Constants.bigNumber;
186
187 };
188
189 /***
190 *
191 * $Log: ZeeBuffer.java,v $
192 * Revision 1.4 2005/03/19 17:50:02 brian
193 * repackaging
194 *
195 * Revision 1.3 2005/03/07 13:36:38 brian
196 * invert the buffer to match other changes
197 *
198 * Revision 1.2 2005/02/17 03:31:13 brian
199 * good stuff???
200 *
201 * Revision 1.1 2004/09/02 13:17:16 brian
202 * the big reorg
203 *
204 * Revision 1.4 2004/09/01 01:10:42 brian
205 * fix class level javadoc placement
206 *
207 * Revision 1.3 2004/09/01 00:11:06 brian
208 * author, log and header stuff
209 *
210 *
211 */