source: trunk/src/opengl/mesa/bbox.c@ 3721

Last change on this file since 3721 was 3598, checked in by jeroen, 25 years ago

* empty log message *

File size: 5.9 KB
Line 
1/* $Id: bbox.c,v 1.2 2000-05-23 20:40:23 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27/*
28 * New (3.1) transformation code written by Keith Whitwell
29 */
30
31
32#include "glheader.h"
33#include "bbox.h"
34#include "types.h"
35#include "xform.h"
36
37static void cliptest_bounds( GLubyte *orMask,
38 GLubyte *andMask,
39 CONST GLfloat (*bounds)[4],
40 GLuint count )
41{
42 GLubyte tmpOrMask = 0;
43 GLubyte tmpAndMask = ~0;
44 GLuint i;
45
46 for (i = 0 ; i < count ; i++) {
47 const GLfloat cx = bounds[i][0];
48 const GLfloat cy = bounds[i][1];
49 const GLfloat cz = bounds[i][2];
50 const GLfloat cw = bounds[i][3];
51 GLubyte mask = 0;
52
53 if (cx > cw) mask |= CLIP_RIGHT_BIT;
54 else if (cx < -cw) mask |= CLIP_LEFT_BIT;
55 if (cy > cw) mask |= CLIP_TOP_BIT;
56 else if (cy < -cw) mask |= CLIP_BOTTOM_BIT;
57 if (cz > cw) mask |= CLIP_FAR_BIT;
58 else if (cz < -cw) mask |= CLIP_NEAR_BIT;
59
60 tmpOrMask |= mask;
61 tmpAndMask &= mask;
62 }
63
64 *orMask = tmpOrMask;
65 *andMask = tmpAndMask;
66}
67
68
69static void transform_bounds3( GLubyte *orMask, GLubyte *andMask,
70 const GLmatrix *mat,
71 CONST GLfloat src[][3] )
72{
73 GLuint i;
74 GLfloat dx[4], dy[4], dz[4];
75 GLfloat data[8][4];
76 const GLfloat *m = mat->m;
77
78 /* Do the first transform */
79 gl_transform_point_sz( data[0], mat->m, src[0], 3 );
80
81 for (i = 1 ; i < 8 ; i++)
82 COPY_4FV( data[i], data[0] );
83
84 dx[0] = m[ 0]*src[1][0];
85 dx[1] = m[ 1]*src[1][0];
86 dx[2] = m[ 2]*src[1][0];
87 dx[3] = m[ 3]*src[1][0];
88
89 for (i = 4 ; i < 8 ; i++)
90 ACC_4V( data[i], dx );
91
92 dy[0] = m[ 4]*src[1][1];
93 dy[1] = m[ 5]*src[1][1];
94 dy[2] = m[ 6]*src[1][1];
95 dy[3] = m[ 7]*src[1][1];
96
97 ACC_4V( data[2], dy );
98 ACC_4V( data[3], dy );
99 ACC_4V( data[6], dy );
100 ACC_4V( data[7], dy );
101
102 dz[0] = m[ 8]*src[1][2];
103 dz[1] = m[ 9]*src[1][2];
104 dz[2] = m[10]*src[1][2];
105 dz[3] = m[11]*src[1][2];
106
107 for (i = 1 ; i < 8 ; i+=2)
108 ACC_4V( data[i], dz );
109
110
111 cliptest_bounds( orMask, andMask, (const GLfloat (*)[4])data, 8 );
112}
113
114static void transform_bounds2( GLubyte *orMask, GLubyte *andMask,
115 const GLmatrix *mat,
116 CONST GLfloat src[][3] )
117{
118 GLuint i;
119 GLfloat dx[4], dy[4];
120 GLfloat data[4][4];
121 const GLfloat *m = mat->m;
122
123 /* Do the first transform */
124 gl_transform_point_sz( data[0], mat->m, src[0], 2 );
125
126 for (i = 1 ; i < 4 ; i++)
127 COPY_4FV( data[i], data[0] );
128
129 dx[0] = m[0]*src[1][0];
130 dx[1] = m[1]*src[1][0];
131 dx[2] = m[2]*src[1][0];
132 dx[3] = m[3]*src[1][0];
133
134 ACC_4V( data[1], dx );
135 ACC_4V( data[3], dx );
136
137 dy[0] = m[4]*src[1][1];
138 dy[1] = m[5]*src[1][1];
139 dy[2] = m[6]*src[1][1];
140 dy[3] = m[7]*src[1][1];
141
142 ACC_4V( data[2], dy );
143 ACC_4V( data[3], dy );
144
145 cliptest_bounds( orMask, andMask, (const GLfloat (*)[4])data, 4 );
146}
147
148/* Dummy
149 */
150static void transform_bounds4( GLubyte *orMask, GLubyte *andMask,
151 const GLmatrix *mat,
152 CONST GLfloat src[][3] )
153{
154 (void) mat;
155 (void) src;
156 *orMask = ~0;
157 *andMask = 0;
158}
159
160static void calculate_bounds3( GLfloat (*bounds)[3],
161 const GLvector4f *obj )
162{
163 CONST GLfloat (*data)[4] = (CONST GLfloat (*)[4])obj->start;
164 GLfloat xmin = data[0][0];
165 GLfloat ymin = data[0][1];
166 GLfloat zmin = data[0][2];
167 GLfloat xmax = data[0][0];
168 GLfloat ymax = data[0][1];
169 GLfloat zmax = data[0][2];
170 GLuint i, count = obj->count;
171
172 for (i = 1 ; i < count ; i++) {
173 GLfloat t;
174 t = data[i][0]; if (t > xmax) xmax = t; else if (t < xmin) xmin = t;
175 t = data[i][1]; if (t > ymax) ymax = t; else if (t < ymin) ymin = t;
176 t = data[i][2]; if (t > zmax) zmax = t; else if (t < zmin) zmin = t;
177 }
178
179 bounds[0][0] = xmin;
180 bounds[0][1] = ymin;
181 bounds[0][2] = zmin;
182 bounds[1][0] = xmax - xmin;
183 bounds[1][1] = ymax - ymin;
184 bounds[1][2] = zmax - zmin;
185}
186
187static void calculate_bounds2( GLfloat (*bounds)[3],
188 const GLvector4f *obj )
189{
190 CONST GLfloat (*data)[4] = (CONST GLfloat (*)[4])obj->start;
191 GLfloat xmin = data[0][0];
192 GLfloat ymin = data[0][1];
193 GLfloat xmax = data[0][0];
194 GLfloat ymax = data[0][1];
195 GLuint i, count = obj->count;
196
197 for (i = 1 ; i < count ; i++) {
198 GLfloat t;
199 t = data[i][0]; if (t > xmax) xmax = t; if (t < xmin) xmin = t;
200 t = data[i][1]; if (t > ymax) ymax = t; if (t < ymin) ymin = t;
201 }
202
203 bounds[0][0] = xmin;
204 bounds[0][1] = ymin;
205 bounds[0][2] = 0;
206 bounds[1][0] = xmax - xmin;
207 bounds[1][1] = ymax - ymin;
208 bounds[1][2] = 0;
209}
210
211
212calc_bound_func gl_calc_bound_tab[5] =
213{
214 0,
215 0,
216 calculate_bounds2,
217 calculate_bounds3,
218 0 /* would 4d bounds make sense? */
219};
220
221test_bound_func gl_test_bound_tab[5] =
222{
223 0,
224 0,
225 transform_bounds2,
226 transform_bounds3,
227 transform_bounds4
228};
229
Note: See TracBrowser for help on using the repository browser.