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

Last change on this file since 2938 was 2938, checked in by sandervl, 25 years ago

created

File size: 5.8 KB
Line 
1/* $Id: bbox.c,v 1.1 2000-02-29 00:49:58 sandervl 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 "bbox.h"
33#include "types.h"
34#include "xform.h"
35
36static void cliptest_bounds( GLubyte *orMask,
37 GLubyte *andMask,
38 CONST GLfloat (*bounds)[4],
39 GLuint count )
40{
41 GLubyte tmpOrMask = 0;
42 GLubyte tmpAndMask = ~0;
43 GLuint i;
44
45 for (i = 0 ; i < count ; i++) {
46 const GLfloat cx = bounds[i][0];
47 const GLfloat cy = bounds[i][1];
48 const GLfloat cz = bounds[i][2];
49 const GLfloat cw = bounds[i][3];
50 GLubyte mask = 0;
51
52 if (cx > cw) mask |= CLIP_RIGHT_BIT;
53 else if (cx < -cw) mask |= CLIP_LEFT_BIT;
54 if (cy > cw) mask |= CLIP_TOP_BIT;
55 else if (cy < -cw) mask |= CLIP_BOTTOM_BIT;
56 if (cz > cw) mask |= CLIP_FAR_BIT;
57 else if (cz < -cw) mask |= CLIP_NEAR_BIT;
58
59 tmpOrMask |= mask;
60 tmpAndMask &= mask;
61 }
62
63 *orMask = tmpOrMask;
64 *andMask = tmpAndMask;
65}
66
67
68static void transform_bounds3( GLubyte *orMask, GLubyte *andMask,
69 const GLmatrix *mat,
70 CONST GLfloat src[][3] )
71{
72 GLuint i;
73 GLfloat dx[4], dy[4], dz[4];
74 GLfloat data[8][4];
75 const GLfloat *m = mat->m;
76
77 /* Do the first transform */
78 gl_transform_point_sz( data[0], mat->m, src[0], 3 );
79
80 for (i = 1 ; i < 8 ; i++)
81 COPY_4FV( data[i], data[0] );
82
83 dx[0] = m[ 0]*src[1][0];
84 dx[1] = m[ 1]*src[1][0];
85 dx[2] = m[ 2]*src[1][0];
86 dx[3] = m[ 3]*src[1][0];
87
88 for (i = 4 ; i < 8 ; i++)
89 ACC_4V( data[i], dx );
90
91 dy[0] = m[ 4]*src[1][1];
92 dy[1] = m[ 5]*src[1][1];
93 dy[2] = m[ 6]*src[1][1];
94 dy[3] = m[ 7]*src[1][1];
95
96 ACC_4V( data[2], dy );
97 ACC_4V( data[3], dy );
98 ACC_4V( data[6], dy );
99 ACC_4V( data[7], dy );
100
101 dz[0] = m[ 8]*src[1][2];
102 dz[1] = m[ 9]*src[1][2];
103 dz[2] = m[10]*src[1][2];
104 dz[3] = m[11]*src[1][2];
105
106 for (i = 1 ; i < 8 ; i+=2)
107 ACC_4V( data[i], dz );
108
109
110 cliptest_bounds( orMask, andMask, (const GLfloat (*)[4])data, 8 );
111}
112
113static void transform_bounds2( GLubyte *orMask, GLubyte *andMask,
114 const GLmatrix *mat,
115 CONST GLfloat src[][3] )
116{
117 GLuint i;
118 GLfloat dx[4], dy[4];
119 GLfloat data[4][4];
120 const GLfloat *m = mat->m;
121
122 /* Do the first transform */
123 gl_transform_point_sz( data[0], mat->m, src[0], 2 );
124
125 for (i = 1 ; i < 4 ; i++)
126 COPY_4FV( data[i], data[0] );
127
128 dx[0] = m[0]*src[1][0];
129 dx[1] = m[1]*src[1][0];
130 dx[2] = m[2]*src[1][0];
131 dx[3] = m[3]*src[1][0];
132
133 ACC_4V( data[1], dx );
134 ACC_4V( data[3], dx );
135
136 dy[0] = m[4]*src[1][1];
137 dy[1] = m[5]*src[1][1];
138 dy[2] = m[6]*src[1][1];
139 dy[3] = m[7]*src[1][1];
140
141 ACC_4V( data[2], dy );
142 ACC_4V( data[3], dy );
143
144 cliptest_bounds( orMask, andMask, (const GLfloat (*)[4])data, 4 );
145}
146
147/* Dummy
148 */
149static void transform_bounds4( GLubyte *orMask, GLubyte *andMask,
150 const GLmatrix *mat,
151 CONST GLfloat src[][3] )
152{
153 (void) mat;
154 (void) src;
155 *orMask = ~0;
156 *andMask = 0;
157}
158
159static void calculate_bounds3( GLfloat (*bounds)[3],
160 const GLvector4f *obj )
161{
162 CONST GLfloat (*data)[4] = (CONST GLfloat (*)[4])obj->start;
163 GLfloat xmin = data[0][0];
164 GLfloat ymin = data[0][1];
165 GLfloat zmin = data[0][2];
166 GLfloat xmax = data[0][0];
167 GLfloat ymax = data[0][1];
168 GLfloat zmax = data[0][2];
169 GLuint i, count = obj->count;
170
171 for (i = 1 ; i < count ; i++) {
172 GLfloat t;
173 t = data[i][0]; if (t > xmax) xmax = t; else if (t < xmin) xmin = t;
174 t = data[i][1]; if (t > ymax) ymax = t; else if (t < ymin) ymin = t;
175 t = data[i][2]; if (t > zmax) zmax = t; else if (t < zmin) zmin = t;
176 }
177
178 bounds[0][0] = xmin;
179 bounds[0][1] = ymin;
180 bounds[0][2] = zmin;
181 bounds[1][0] = xmax - xmin;
182 bounds[1][1] = ymax - ymin;
183 bounds[1][2] = zmax - zmin;
184}
185
186static void calculate_bounds2( GLfloat (*bounds)[3],
187 const GLvector4f *obj )
188{
189 CONST GLfloat (*data)[4] = (CONST GLfloat (*)[4])obj->start;
190 GLfloat xmin = data[0][0];
191 GLfloat ymin = data[0][1];
192 GLfloat xmax = data[0][0];
193 GLfloat ymax = data[0][1];
194 GLuint i, count = obj->count;
195
196 for (i = 1 ; i < count ; i++) {
197 GLfloat t;
198 t = data[i][0]; if (t > xmax) xmax = t; if (t < xmin) xmin = t;
199 t = data[i][1]; if (t > ymax) ymax = t; if (t < ymin) ymin = t;
200 }
201
202 bounds[0][0] = xmin;
203 bounds[0][1] = ymin;
204 bounds[0][2] = 0;
205 bounds[1][0] = xmax - xmin;
206 bounds[1][1] = ymax - ymin;
207 bounds[1][2] = 0;
208}
209
210
211calc_bound_func gl_calc_bound_tab[5] =
212{
213 0,
214 0,
215 calculate_bounds2,
216 calculate_bounds3,
217 0 /* would 4d bounds make sense? */
218};
219
220test_bound_func gl_test_bound_tab[5] =
221{
222 0,
223 0,
224 transform_bounds2,
225 transform_bounds3,
226 transform_bounds4
227};
228
Note: See TracBrowser for help on using the repository browser.