Debian Codegraph @

lib/database/src/so/nodes/nurbs/clients/gl4base.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 #include "../SoAddPrefix.h"
38 #include "mymath.h"
39 #include "mystdlib.h"
40 #include "gl4base.h"
41
42 _SoNurbsGL4Base::_SoNurbsGL4Base(
43 _SoNurbsBasicCurveEvaluator& curveEvaluator,
44 _SoNurbsBasicSurfaceEvaluator& surfaceEvaluator )
45 : _SoNurbsNurbsTessellator( curveEvaluator, surfaceEvaluator )
46 {
47 redefineMaps();
48 defineMap( N_C4D, 0, 4 );
49 defineMap( N_C4DR, 1, 5 );
50 defineMap( N_T2D, 0, 2 );
51 defineMap( N_T2DR, 1, 3 );
52 defineMap( N_V3D, 0, 3 );
53 defineMap( N_V3DR, 1, 4 );
54
55 makingGLobj = 0;
56 needMatrices = 0;
57 }
58
59 void
60 _SoNurbsGL4Base::makeGLobj( int n )
61 {
62 makingGLobj = 1;
63 objnum = n;
64 }
65
66 void
67 _SoNurbsGL4Base::gl4samplingmode( void )
68 {
69 needMatrices = 1;
70 }
71
72 void
73 _SoNurbsGL4Base::bgnrender( void )
74 {
75 if( needMatrices ) loadGLMatrices();
76 // if( makingGLobj ) {
77 // if( ::isobj( objnum ) ) ::delobj( objnum );
78 // ::makeobj( objnum );
79 // }
80 }
81
82 void
83 _SoNurbsGL4Base::endrender( void )
84 {
85 // if( makingGLobj )
86 // ::closeobj( );
87 }
88
89 void
90 _SoNurbsGL4Base::loadGLMatrices( void )
91 {
92 float vmat[4][4];
93 grabGLMatrix( vmat );
94 loadCullingMatrix( vmat );
95 loadSamplingMatrix( vmat );
96 }
97
98 void
99 _SoNurbsGL4Base::errorHandler( int )
100 {
101 // ::fprintf( stderr, "Error: %s\n", nurbserror[msg] );
102 }
103
104 /*--------------------------------------------------------------------------
105 * grabGLMatrix
106 *--------------------------------------------------------------------------
107 */
108
109 void
110 _SoNurbsGL4Base::grabGLMatrix( float [4][4] )
111 {
112 // long matmmode = getmmode();
113 // if( matmmode != MSINGLE ) {
114 // ::mmode( MVIEWING );
115 // float nmat[4][4];
116 // ::getmatrix( nmat ); /* get viewing matrix */
117 // ::mmode( MPROJECTION );
118 // float pmat[4][4];
119 // ::getmatrix( pmat ); /* get projection matrix */
120 // multmatrix4d( vmat, nmat, pmat );
121 // } else {
122 // ::getmatrix( vmat ); /* get combined matrix */
123 // }
124 // ::mmode( (short) matmmode );
125 }
126
127 void
128 _SoNurbsGL4Base::loadSamplingMatrix( float [4][4] )
129 {
130 // short llx, urx, lly, ury;
131 // ::getviewport( &llx, &urx, &lly, &ury );
132
133 /* rescale the mapping to correspond to pixels in x/y */
134 /*
135 REAL xsize = 0.5 * (REAL) (urx - llx);
136 REAL ysize = 0.5 * (REAL) (ury - lly);
137
138 INREAL smat[4][4];
139 smat[0][0] = vmat[0][0] * xsize;
140 smat[1][0] = vmat[1][0] * xsize;
141 smat[2][0] = vmat[2][0] * xsize;
142 smat[3][0] = vmat[3][0] * xsize;
143
144 smat[0][1] = vmat[0][1] * ysize;
145 smat[1][1] = vmat[1][1] * ysize;
146 smat[2][1] = vmat[2][1] * ysize;
147 smat[3][1] = vmat[3][1] * ysize;
148
149 smat[0][2] = 0.0;
150 smat[1][2] = 0.0;
151 smat[2][2] = 0.0;
152 smat[3][2] = 0.0;
153
154 smat[0][3] = vmat[0][3];
155 smat[1][3] = vmat[1][3];
156 smat[2][3] = vmat[2][3];
157 smat[3][3] = vmat[3][3];
158
159 const long rstride = sizeof( smat[0]) / sizeof(smat[0][0]);
160 const long cstride = 1;
161
162 setnurbsproperty( N_V3D, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride );
163 setnurbsproperty( N_V3DR, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride );
164 */
165 }
166
167 void
168 _SoNurbsGL4Base::loadCullingMatrix( float vmat[4][4] )
169 {
170 INREAL cmat[4][4];
171
172 cmat[0][0] = vmat[0][0];
173 cmat[0][1] = vmat[0][1];
174 cmat[0][2] = vmat[0][2];
175 cmat[0][3] = vmat[0][3];
176
177 cmat[1][0] = vmat[1][0];
178 cmat[1][1] = vmat[1][1];
179 cmat[1][2] = vmat[1][2];
180 cmat[1][3] = vmat[1][3];
181
182 cmat[2][0] = vmat[2][0];
183 cmat[2][1] = vmat[2][1];
184 cmat[2][2] = vmat[2][2];
185 cmat[2][3] = vmat[2][3];
186
187 cmat[3][0] = vmat[3][0];
188 cmat[3][1] = vmat[3][1];
189 cmat[3][2] = vmat[3][2];
190 cmat[3][3] = vmat[3][3];
191
192 // const long rstride = sizeof( cmat[0]) / sizeof(cmat[0][0]);
193 // const long cstride = 1;
194
195 // setnurbsproperty( N_V3D, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride );
196 // setnurbsproperty( N_V3DR, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride );
197 }
198
199 /*---------------------------------------------------------------------
200 * A = B * MAT ; transform a 4d vector through a 4x4 matrix
201 *---------------------------------------------------------------------
202 */
203 void
204 _SoNurbsGL4Base::transform4d( float A[4], float B[4], float mat[4][4] )
205 {
206
207 A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
208 A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
209 A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
210 A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
211 }
212
213 /*---------------------------------------------------------------------
214 * new = [left][right] ; multiply two matrices together
215 *---------------------------------------------------------------------
216 */
217 void
218 _SoNurbsGL4Base::multmatrix4d ( float n[4][4], float left[4][4], float right[4][4] )
219 {
220 transform4d (n[0],left[0],right);
221 transform4d (n[1],left[1],right);
222 transform4d (n[2],left[2],right);
223 transform4d (n[3],left[3],right);
224 }
225
226