diff options
author | Brian Paul <[email protected]> | 2001-09-14 22:19:18 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2001-09-14 22:19:18 +0000 |
commit | 04120f6cce0aa9e3604a64c740c25b99ca3999dc (patch) | |
tree | 18b48cfc6380ecd6b1137c4d2a12144d5a5f32b9 /src/glu/sgi | |
parent | 7c276329e815c84ea2403bb08c44ff60179c0cd6 (diff) |
Win32 updates (Karl Schultz)
Diffstat (limited to 'src/glu/sgi')
-rw-r--r-- | src/glu/sgi/Makefile.win | 156 | ||||
-rw-r--r-- | src/glu/sgi/glu.def | 46 | ||||
-rw-r--r-- | src/glu/sgi/libutil/project.c | 762 |
3 files changed, 583 insertions, 381 deletions
diff --git a/src/glu/sgi/Makefile.win b/src/glu/sgi/Makefile.win new file mode 100644 index 00000000000..1d239e7dfdf --- /dev/null +++ b/src/glu/sgi/Makefile.win @@ -0,0 +1,156 @@ +# Makefile for Win32
+
+#
+# Sept 12, 2001
+# Note: The nurbs code is not being built at this time.
+# If you want to work on it, uncomment the definitions
+# noted below to try to compile the sources.
+# There are numerous problems, some of which may be solved
+# by setting some #defines.
+#
+
+!include <win32.mak>
+
+.SUFFIXES : .cc
+
+TOP = ..
+
+GLU_SRCS_CC = \
+ libnurbs\interface\bezierEval.cc \
+ libnurbs\interface\bezierPatch.cc \
+ libnurbs\interface\bezierPatchMesh.cc \
+ libnurbs\interface\glcurveval.cc \
+ libnurbs\interface\glinterface.cc \
+ libnurbs\interface\glrenderer.cc \
+ libnurbs\interface\glsurfeval.cc \
+ libnurbs\interface\incurveeval.cc \
+ libnurbs\interface\insurfeval.cc \
+ libnurbs\internals\arc.cc \
+ libnurbs\internals\arcsorter.cc \
+ libnurbs\internals\arctess.cc \
+ libnurbs\internals\backend.cc \
+ libnurbs\internals\basiccrveval.cc \
+ libnurbs\internals\basicsurfeval.cc \
+ libnurbs\internals\bin.cc \
+ libnurbs\internals\bufpool.cc \
+ libnurbs\internals\cachingeval.cc \
+ libnurbs\internals\ccw.cc \
+ libnurbs\internals\coveandtiler.cc \
+ libnurbs\internals\curve.cc \
+ libnurbs\internals\curvelist.cc \
+ libnurbs\internals\curvesub.cc \
+ libnurbs\internals\dataTransform.cc \
+ libnurbs\internals\displaylist.cc \
+ libnurbs\internals\flist.cc \
+ libnurbs\internals\flistsorter.cc \
+ libnurbs\internals\hull.cc \
+ libnurbs\internals\intersect.cc \
+ libnurbs\internals\knotvector.cc \
+ libnurbs\internals\mapdesc.cc \
+ libnurbs\internals\mapdescv.cc \
+ libnurbs\internals\maplist.cc \
+ libnurbs\internals\mesher.cc \
+ libnurbs\internals\monoTriangulationBackend.cc \
+ libnurbs\internals\monotonizer.cc \
+ libnurbs\internals\mycode.cc \
+ libnurbs\internals\nurbsinterfac.cc \
+ libnurbs\internals\nurbstess.cc \
+ libnurbs\internals\patch.cc \
+ libnurbs\internals\patchlist.cc \
+ libnurbs\internals\quilt.cc \
+ libnurbs\internals\reader.cc \
+ libnurbs\internals\renderhints.cc \
+ libnurbs\internals\slicer.cc \
+ libnurbs\internals\sorter.cc \
+ libnurbs\internals\splitarcs.cc \
+ libnurbs\internals\subdivider.cc \
+ libnurbs\internals\tobezier.cc \
+ libnurbs\internals\trimline.cc \
+ libnurbs\internals\trimregion.cc \
+ libnurbs\internals\trimvertpool.cc \
+ libnurbs\internals\uarray.cc \
+ libnurbs\internals\varray.cc \
+ libnurbs\nurbtess\directedLine.cc \
+ libnurbs\nurbtess\gridWrap.cc \
+ libnurbs\nurbtess\monoChain.cc \
+ libnurbs\nurbtess\monoPolyPart.cc \
+ libnurbs\nurbtess\monoTriangulation.cc \
+ libnurbs\nurbtess\partitionX.cc \
+ libnurbs\nurbtess\partitionY.cc \
+ libnurbs\nurbtess\polyDBG.cc \
+ libnurbs\nurbtess\polyUtil.cc \
+ libnurbs\nurbtess\primitiveStream.cc \
+ libnurbs\nurbtess\quicksort.cc \
+ libnurbs\nurbtess\rectBlock.cc \
+ libnurbs\nurbtess\sampleComp.cc \
+ libnurbs\nurbtess\sampleCompBot.cc \
+ libnurbs\nurbtess\sampleCompRight.cc \
+ libnurbs\nurbtess\sampleCompTop.cc \
+ libnurbs\nurbtess\sampleMonoPoly.cc \
+ libnurbs\nurbtess\sampledLine.cc \
+ libnurbs\nurbtess\searchTree.cc
+
+GLU_SRCS = \
+ libtess\dict.c \
+ libtess\geom.c \
+ libtess\memalloc.c \
+ libtess\mesh.c \
+ libtess\normal.c \
+ libtess\priorityq.c \
+ libtess\render.c \
+ libtess\sweep.c \
+ libtess\tess.c \
+ libtess\tessmono.c \
+ libutil\error.c \
+ libutil\glue.c \
+ libutil\mipmap.c \
+ libutil\project.c \
+ libutil\quad.c \
+ libutil\registry.c
+
+SRCS = $(GLU_SRCS)
+
+GLUDLL = glu32.dll
+
+all : gludll install
+
+!include "$(TOP)/mesawin32.mak"
+
+gludll : $(GLUDLL)
+
+CFLAGS = $(cvarsdll) $(CFLAGS) -D_OPENGL32_ -Iinclude -DBUILD_GL32
+LFLAGS = $(dlllflags) $(LFLAGS)
+
+OBJS = $(GLU_SRCS:.c=.obj)
+LIBS = ../lib/opengl32.lib winmm.lib $(guilibsdll)
+
+# Uncomment these definitions to try to compile the NURBS code.
+#OBJS = $(GLU_SRCS_CC:.cc=.obj) $(GLU_SRCS:.c=.obj)
+#NURBSINC = -Ilibnurbs\interface -Ilibnurbs\internals -Ilibnurbs\nurbtess
+#CFLAGS = $(CFLAGS) $(NURBSINC)
+
+$(GLUDLL) : $(OBJS) glu.def
+ $(link) $(LFLAGS) -out:$(GLUDLL) -def:glu.def $(OBJS) $(LIBS)
+
+install : $(GLUDLL)
+ @echo "copying Mesa GLU dynamic link library to system directory..."
+ -copy $(GLUDLL) $(TOP)\lib
+ @echo "copying Mesa GLU import library to library directory..."
+ -copy $(GLU) $(TOP)\lib
+
+clean ::
+ @del /f libtess\*.obj libutil\*.obj
+ @del /f libnurbs\interface\*.obj libnurbs\internals\*.obj
+ @del /f libnurbs\nurbtess\*.obj
+
+# override default inference rule with one that writes the object to
+# the correct subdir.
+
+.c.obj :
+ $(cc) $(CFLAGS) -I. $< /Fo$*.obj
+
+# /TP is needed for C++ files because MS compiler
+# does not recognize .cc as a C++ file.
+
+.cc.obj :
+ $(cc) $(CFLAGS) -I. $< /TP /Fo$*.obj
diff --git a/src/glu/sgi/glu.def b/src/glu/sgi/glu.def new file mode 100644 index 00000000000..19da640d247 --- /dev/null +++ b/src/glu/sgi/glu.def @@ -0,0 +1,46 @@ +DESCRIPTION 'Mesa GLU (OpenGL work-alike) for Win32' +VERSION 3.5 + +EXPORTS + gluBeginPolygon + gluBuild1DMipmapLevels + gluBuild1DMipmaps + gluBuild2DMipmapLevels + gluBuild2DMipmaps + gluBuild3DMipmapLevels + gluBuild3DMipmaps + gluCheckExtension + gluCylinder + gluDeleteQuadric + gluDeleteTess + gluDisk + gluEndPolygon + gluErrorString + gluGetString + gluGetTessProperty + gluLookAt + gluNewQuadric + gluNewTess + gluNextContour + gluOrtho2D + gluPartialDisk + gluPerspective + gluPickMatrix + gluProject + gluQuadricCallback + gluQuadricDrawStyle + gluQuadricNormals + gluQuadricOrientation + gluQuadricTexture + gluScaleImage + gluSphere + gluTessBeginContour + gluTessBeginPolygon + gluTessCallback + gluTessEndContour + gluTessEndPolygon + gluTessNormal + gluTessProperty + gluTessVertex + gluUnProject + gluUnProject4 diff --git a/src/glu/sgi/libutil/project.c b/src/glu/sgi/libutil/project.c index f67c8782f8b..4d9819471b6 100644 --- a/src/glu/sgi/libutil/project.c +++ b/src/glu/sgi/libutil/project.c @@ -1,381 +1,381 @@ -/* -** License Applicability. Except to the extent portions of this file are -** made subject to an alternative license as permitted in the SGI Free -** Software License B, Version 1.1 (the "License"), the contents of this -** file are subject only to the provisions of the License. You may not use -** this file except in compliance with the License. You may obtain a copy -** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 -** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: -** -** http://oss.sgi.com/projects/FreeB -** -** Note that, as provided in the License, the Software is distributed on an -** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS -** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND -** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A -** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. -** -** Original Code. The Original Code is: OpenGL Sample Implementation, -** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, -** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. -** Copyright in any portions created by third parties is as indicated -** elsewhere herein. All Rights Reserved. -** -** Additional Notice Provisions: The application programming interfaces -** established by SGI in conjunction with the Original Code are The -** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released -** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version -** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X -** Window System(R) (Version 1.3), released October 19, 1998. This software -** was created using the OpenGL(R) version 1.2.1 Sample Implementation -** published by SGI, but has not been independently verified as being -** compliant with the OpenGL(R) version 1.2.1 Specification. -** -** $Date: 2001/07/16 15:46:42 $ $Revision: 1.2 $ -** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libutil/project.c,v 1.2 2001/07/16 15:46:42 brianp Exp $ -*/ - -#include "gluos.h" -#include <math.h> -#include <GL/gl.h> -#include <GL/glu.h> -#include "gluint.h" - -/* -** Make m an identity matrix -*/ -static void __gluMakeIdentityd(GLdouble m[16]) -{ - m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0; - m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0; - m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0; - m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1; -} - -static void __gluMakeIdentityf(GLfloat m[16]) -{ - m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0; - m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0; - m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0; - m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1; -} - -void GLAPIENTRY -gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) -{ - glOrtho(left, right, bottom, top, -1, 1); -} - -#define __glPi 3.14159265358979323846 - -void GLAPIENTRY -gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) -{ - GLdouble m[4][4]; - double sine, cotangent, deltaZ; - double radians = fovy / 2 * __glPi / 180; - - deltaZ = zFar - zNear; - sine = sin(radians); - if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { - return; - } - cotangent = COS(radians) / sine; - - __gluMakeIdentityd(&m[0][0]); - m[0][0] = cotangent / aspect; - m[1][1] = cotangent; - m[2][2] = -(zFar + zNear) / deltaZ; - m[2][3] = -1; - m[3][2] = -2 * zNear * zFar / deltaZ; - m[3][3] = 0; - glMultMatrixd(&m[0][0]); -} - -static void normalize(float v[3]) -{ - float r; - - r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); - if (r == 0.0) return; - - v[0] /= r; - v[1] /= r; - v[2] /= r; -} - -static void cross(float v1[3], float v2[3], float result[3]) -{ - result[0] = v1[1]*v2[2] - v1[2]*v2[1]; - result[1] = v1[2]*v2[0] - v1[0]*v2[2]; - result[2] = v1[0]*v2[1] - v1[1]*v2[0]; -} - -void GLAPIENTRY -gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, - GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, - GLdouble upz) -{ - int i; - float forward[3], side[3], up[3]; - GLfloat m[4][4]; - - forward[0] = centerx - eyex; - forward[1] = centery - eyey; - forward[2] = centerz - eyez; - - up[0] = upx; - up[1] = upy; - up[2] = upz; - - normalize(forward); - - /* Side = forward x up */ - cross(forward, up, side); - normalize(side); - - /* Recompute up as: up = side x forward */ - cross(side, forward, up); - - __gluMakeIdentityf(&m[0][0]); - m[0][0] = side[0]; - m[1][0] = side[1]; - m[2][0] = side[2]; - - m[0][1] = up[0]; - m[1][1] = up[1]; - m[2][1] = up[2]; - - m[0][2] = -forward[0]; - m[1][2] = -forward[1]; - m[2][2] = -forward[2]; - - glMultMatrixf(&m[0][0]); - glTranslated(-eyex, -eyey, -eyez); -} - -static void __gluMultMatrixVecd(const GLdouble matrix[16], const GLdouble in[4], - GLdouble out[4]) -{ - int i; - - for (i=0; i<4; i++) { - out[i] = - in[0] * matrix[0*4+i] + - in[1] * matrix[1*4+i] + - in[2] * matrix[2*4+i] + - in[3] * matrix[3*4+i]; - } -} - -/* -** inverse = invert(src) -*/ -static int __gluInvertMatrixd(const GLdouble src[16], GLdouble inverse[16]) -{ - int i, j, k, swap; - double t; - GLdouble temp[4][4]; - - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - temp[i][j] = src[i*4+j]; - } - } - __gluMakeIdentityd(inverse); - - for (i = 0; i < 4; i++) { - /* - ** Look for largest element in column - */ - swap = i; - for (j = i + 1; j < 4; j++) { - if (fabs(temp[j][i]) > fabs(temp[i][i])) { - swap = j; - } - } - - if (swap != i) { - /* - ** Swap rows. - */ - for (k = 0; k < 4; k++) { - t = temp[i][k]; - temp[i][k] = temp[swap][k]; - temp[swap][k] = t; - - t = inverse[i*4+k]; - inverse[i*4+k] = inverse[swap*4+k]; - inverse[swap*4+k] = t; - } - } - - if (temp[i][i] == 0) { - /* - ** No non-zero pivot. The matrix is singular, which shouldn't - ** happen. This means the user gave us a bad matrix. - */ - return GL_FALSE; - } - - t = temp[i][i]; - for (k = 0; k < 4; k++) { - temp[i][k] /= t; - inverse[i*4+k] /= t; - } - for (j = 0; j < 4; j++) { - if (j != i) { - t = temp[j][i]; - for (k = 0; k < 4; k++) { - temp[j][k] -= temp[i][k]*t; - inverse[j*4+k] -= inverse[i*4+k]*t; - } - } - } - } - return GL_TRUE; -} - -static void __gluMultMatricesd(const GLdouble a[16], const GLdouble b[16], - GLdouble r[16]) -{ - int i, j; - - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - r[i*4+j] = - a[i*4+0]*b[0*4+j] + - a[i*4+1]*b[1*4+j] + - a[i*4+2]*b[2*4+j] + - a[i*4+3]*b[3*4+j]; - } - } -} - -GLint GLAPIENTRY -gluProject(GLdouble objx, GLdouble objy, GLdouble objz, - const GLdouble modelMatrix[16], - const GLdouble projMatrix[16], - const GLint viewport[4], - GLdouble *winx, GLdouble *winy, GLdouble *winz) -{ - double in[4]; - double out[4]; - - in[0]=objx; - in[1]=objy; - in[2]=objz; - in[3]=1.0; - __gluMultMatrixVecd(modelMatrix, in, out); - __gluMultMatrixVecd(projMatrix, out, in); - if (in[3] == 0.0) return(GL_FALSE); - in[0] /= in[3]; - in[1] /= in[3]; - in[2] /= in[3]; - /* Map x, y and z to range 0-1 */ - in[0] = in[0] * 0.5 + 0.5; - in[1] = in[1] * 0.5 + 0.5; - in[2] = in[2] * 0.5 + 0.5; - - /* Map x,y to viewport */ - in[0] = in[0] * viewport[2] + viewport[0]; - in[1] = in[1] * viewport[3] + viewport[1]; - - *winx=in[0]; - *winy=in[1]; - *winz=in[2]; - return(GL_TRUE); -} - -GLint GLAPIENTRY -gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, - const GLdouble modelMatrix[16], - const GLdouble projMatrix[16], - const GLint viewport[4], - GLdouble *objx, GLdouble *objy, GLdouble *objz) -{ - double finalMatrix[16]; - double in[4]; - double out[4]; - - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); - if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); - - in[0]=winx; - in[1]=winy; - in[2]=winz; - in[3]=1.0; - - /* Map x and y from window coordinates */ - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; - - /* Map to range -1 to 1 */ - in[0] = in[0] * 2 - 1; - in[1] = in[1] * 2 - 1; - in[2] = in[2] * 2 - 1; - - __gluMultMatrixVecd(finalMatrix, in, out); - if (out[3] == 0.0) return(GL_FALSE); - out[0] /= out[3]; - out[1] /= out[3]; - out[2] /= out[3]; - *objx = out[0]; - *objy = out[1]; - *objz = out[2]; - return(GL_TRUE); -} - -GLint GLAPIENTRY -gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw, - const GLdouble modelMatrix[16], - const GLdouble projMatrix[16], - const GLint viewport[4], - GLclampd near, GLclampd farVal, - GLdouble *objx, GLdouble *objy, GLdouble *objz, - GLdouble *objw) -{ - double finalMatrix[16]; - double in[4]; - double out[4]; - - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); - if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); - - in[0]=winx; - in[1]=winy; - in[2]=winz; - in[3]=clipw; - - /* Map x and y from window coordinates */ - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; - in[2] = (in[2] - near) / (farVal - near); - - /* Map to range -1 to 1 */ - in[0] = in[0] * 2 - 1; - in[1] = in[1] * 2 - 1; - in[2] = in[2] * 2 - 1; - - __gluMultMatrixVecd(finalMatrix, in, out); - if (out[3] == 0.0) return(GL_FALSE); - *objx = out[0]; - *objy = out[1]; - *objz = out[2]; - *objw = out[3]; - return(GL_TRUE); -} - -void GLAPIENTRY -gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, - GLint viewport[4]) -{ - if (deltax <= 0 || deltay <= 0) { - return; - } - - /* Translate and scale the picked region to the entire window */ - glTranslatef((viewport[2] - 2 * (x - viewport[0])) / deltax, - (viewport[3] - 2 * (y - viewport[1])) / deltay, 0); - glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0); -} +/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+**
+** $Date: 2001/09/14 22:19:19 $ $Revision: 1.3 $
+** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libutil/project.c,v 1.3 2001/09/14 22:19:19 brianp Exp $
+*/
+
+#include "gluos.h"
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include "gluint.h"
+
+/*
+** Make m an identity matrix
+*/
+static void __gluMakeIdentityd(GLdouble m[16])
+{
+ m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
+ m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
+ m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
+ m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
+}
+
+static void __gluMakeIdentityf(GLfloat m[16])
+{
+ m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
+ m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
+ m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
+ m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
+}
+
+void GLAPIENTRY
+gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
+{
+ glOrtho(left, right, bottom, top, -1, 1);
+}
+
+#define __glPi 3.14159265358979323846
+
+void GLAPIENTRY
+gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
+{
+ GLdouble m[4][4];
+ double sine, cotangent, deltaZ;
+ double radians = fovy / 2 * __glPi / 180;
+
+ deltaZ = zFar - zNear;
+ sine = sin(radians);
+ if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
+ return;
+ }
+ cotangent = COS(radians) / sine;
+
+ __gluMakeIdentityd(&m[0][0]);
+ m[0][0] = cotangent / aspect;
+ m[1][1] = cotangent;
+ m[2][2] = -(zFar + zNear) / deltaZ;
+ m[2][3] = -1;
+ m[3][2] = -2 * zNear * zFar / deltaZ;
+ m[3][3] = 0;
+ glMultMatrixd(&m[0][0]);
+}
+
+static void normalize(float v[3])
+{
+ float r;
+
+ r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
+ if (r == 0.0) return;
+
+ v[0] /= r;
+ v[1] /= r;
+ v[2] /= r;
+}
+
+static void cross(float v1[3], float v2[3], float result[3])
+{
+ result[0] = v1[1]*v2[2] - v1[2]*v2[1];
+ result[1] = v1[2]*v2[0] - v1[0]*v2[2];
+ result[2] = v1[0]*v2[1] - v1[1]*v2[0];
+}
+
+void GLAPIENTRY
+gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
+ GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
+ GLdouble upz)
+{
+ int i;
+ float forward[3], side[3], up[3];
+ GLfloat m[4][4];
+
+ forward[0] = centerx - eyex;
+ forward[1] = centery - eyey;
+ forward[2] = centerz - eyez;
+
+ up[0] = upx;
+ up[1] = upy;
+ up[2] = upz;
+
+ normalize(forward);
+
+ /* Side = forward x up */
+ cross(forward, up, side);
+ normalize(side);
+
+ /* Recompute up as: up = side x forward */
+ cross(side, forward, up);
+
+ __gluMakeIdentityf(&m[0][0]);
+ m[0][0] = side[0];
+ m[1][0] = side[1];
+ m[2][0] = side[2];
+
+ m[0][1] = up[0];
+ m[1][1] = up[1];
+ m[2][1] = up[2];
+
+ m[0][2] = -forward[0];
+ m[1][2] = -forward[1];
+ m[2][2] = -forward[2];
+
+ glMultMatrixf(&m[0][0]);
+ glTranslated(-eyex, -eyey, -eyez);
+}
+
+static void __gluMultMatrixVecd(const GLdouble matrix[16], const GLdouble in[4],
+ GLdouble out[4])
+{
+ int i;
+
+ for (i=0; i<4; i++) {
+ out[i] =
+ in[0] * matrix[0*4+i] +
+ in[1] * matrix[1*4+i] +
+ in[2] * matrix[2*4+i] +
+ in[3] * matrix[3*4+i];
+ }
+}
+
+/*
+** inverse = invert(src)
+*/
+static int __gluInvertMatrixd(const GLdouble src[16], GLdouble inverse[16])
+{
+ int i, j, k, swap;
+ double t;
+ GLdouble temp[4][4];
+
+ for (i=0; i<4; i++) {
+ for (j=0; j<4; j++) {
+ temp[i][j] = src[i*4+j];
+ }
+ }
+ __gluMakeIdentityd(inverse);
+
+ for (i = 0; i < 4; i++) {
+ /*
+ ** Look for largest element in column
+ */
+ swap = i;
+ for (j = i + 1; j < 4; j++) {
+ if (fabs(temp[j][i]) > fabs(temp[i][i])) {
+ swap = j;
+ }
+ }
+
+ if (swap != i) {
+ /*
+ ** Swap rows.
+ */
+ for (k = 0; k < 4; k++) {
+ t = temp[i][k];
+ temp[i][k] = temp[swap][k];
+ temp[swap][k] = t;
+
+ t = inverse[i*4+k];
+ inverse[i*4+k] = inverse[swap*4+k];
+ inverse[swap*4+k] = t;
+ }
+ }
+
+ if (temp[i][i] == 0) {
+ /*
+ ** No non-zero pivot. The matrix is singular, which shouldn't
+ ** happen. This means the user gave us a bad matrix.
+ */
+ return GL_FALSE;
+ }
+
+ t = temp[i][i];
+ for (k = 0; k < 4; k++) {
+ temp[i][k] /= t;
+ inverse[i*4+k] /= t;
+ }
+ for (j = 0; j < 4; j++) {
+ if (j != i) {
+ t = temp[j][i];
+ for (k = 0; k < 4; k++) {
+ temp[j][k] -= temp[i][k]*t;
+ inverse[j*4+k] -= inverse[i*4+k]*t;
+ }
+ }
+ }
+ }
+ return GL_TRUE;
+}
+
+static void __gluMultMatricesd(const GLdouble a[16], const GLdouble b[16],
+ GLdouble r[16])
+{
+ int i, j;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ r[i*4+j] =
+ a[i*4+0]*b[0*4+j] +
+ a[i*4+1]*b[1*4+j] +
+ a[i*4+2]*b[2*4+j] +
+ a[i*4+3]*b[3*4+j];
+ }
+ }
+}
+
+GLint GLAPIENTRY
+gluProject(GLdouble objx, GLdouble objy, GLdouble objz,
+ const GLdouble modelMatrix[16],
+ const GLdouble projMatrix[16],
+ const GLint viewport[4],
+ GLdouble *winx, GLdouble *winy, GLdouble *winz)
+{
+ double in[4];
+ double out[4];
+
+ in[0]=objx;
+ in[1]=objy;
+ in[2]=objz;
+ in[3]=1.0;
+ __gluMultMatrixVecd(modelMatrix, in, out);
+ __gluMultMatrixVecd(projMatrix, out, in);
+ if (in[3] == 0.0) return(GL_FALSE);
+ in[0] /= in[3];
+ in[1] /= in[3];
+ in[2] /= in[3];
+ /* Map x, y and z to range 0-1 */
+ in[0] = in[0] * 0.5 + 0.5;
+ in[1] = in[1] * 0.5 + 0.5;
+ in[2] = in[2] * 0.5 + 0.5;
+
+ /* Map x,y to viewport */
+ in[0] = in[0] * viewport[2] + viewport[0];
+ in[1] = in[1] * viewport[3] + viewport[1];
+
+ *winx=in[0];
+ *winy=in[1];
+ *winz=in[2];
+ return(GL_TRUE);
+}
+
+GLint GLAPIENTRY
+gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz,
+ const GLdouble modelMatrix[16],
+ const GLdouble projMatrix[16],
+ const GLint viewport[4],
+ GLdouble *objx, GLdouble *objy, GLdouble *objz)
+{
+ double finalMatrix[16];
+ double in[4];
+ double out[4];
+
+ __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix);
+ if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE);
+
+ in[0]=winx;
+ in[1]=winy;
+ in[2]=winz;
+ in[3]=1.0;
+
+ /* Map x and y from window coordinates */
+ in[0] = (in[0] - viewport[0]) / viewport[2];
+ in[1] = (in[1] - viewport[1]) / viewport[3];
+
+ /* Map to range -1 to 1 */
+ in[0] = in[0] * 2 - 1;
+ in[1] = in[1] * 2 - 1;
+ in[2] = in[2] * 2 - 1;
+
+ __gluMultMatrixVecd(finalMatrix, in, out);
+ if (out[3] == 0.0) return(GL_FALSE);
+ out[0] /= out[3];
+ out[1] /= out[3];
+ out[2] /= out[3];
+ *objx = out[0];
+ *objy = out[1];
+ *objz = out[2];
+ return(GL_TRUE);
+}
+
+GLint GLAPIENTRY
+gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw,
+ const GLdouble modelMatrix[16],
+ const GLdouble projMatrix[16],
+ const GLint viewport[4],
+ GLclampd nearVal, GLclampd farVal,
+ GLdouble *objx, GLdouble *objy, GLdouble *objz,
+ GLdouble *objw)
+{
+ double finalMatrix[16];
+ double in[4];
+ double out[4];
+
+ __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix);
+ if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE);
+
+ in[0]=winx;
+ in[1]=winy;
+ in[2]=winz;
+ in[3]=clipw;
+
+ /* Map x and y from window coordinates */
+ in[0] = (in[0] - viewport[0]) / viewport[2];
+ in[1] = (in[1] - viewport[1]) / viewport[3];
+ in[2] = (in[2] - nearVal) / (farVal - nearVal);
+
+ /* Map to range -1 to 1 */
+ in[0] = in[0] * 2 - 1;
+ in[1] = in[1] * 2 - 1;
+ in[2] = in[2] * 2 - 1;
+
+ __gluMultMatrixVecd(finalMatrix, in, out);
+ if (out[3] == 0.0) return(GL_FALSE);
+ *objx = out[0];
+ *objy = out[1];
+ *objz = out[2];
+ *objw = out[3];
+ return(GL_TRUE);
+}
+
+void GLAPIENTRY
+gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay,
+ GLint viewport[4])
+{
+ if (deltax <= 0 || deltay <= 0) {
+ return;
+ }
+
+ /* Translate and scale the picked region to the entire window */
+ glTranslatef((viewport[2] - 2 * (x - viewport[0])) / deltax,
+ (viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
+ glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
+}
|