diff --git a/gb.opengl/src/glu/GLU.c b/gb.opengl/src/glu/GLU.c index 3177bc294..0b5324710 100644 --- a/gb.opengl/src/glu/GLU.c +++ b/gb.opengl/src/glu/GLU.c @@ -29,6 +29,7 @@ #include "GLUtextureImage.h" #include "GLUquadratic.h" #include "GLUnurb.h" +#include "GLUproject.h" BEGIN_METHOD(GLUERRORSTRING, GB_INTEGER code) @@ -80,6 +81,11 @@ GB_DESC Cglu[] = GB_STATIC_METHOD("NurbsSurface", NULL, GLUNURBSSURFACE, "(Nurb)GluNurb;(SKnotCount)i(SKnots)Single[];(TKnotCount)i(TKnots)Single[];(SStride)i(TStride)i(SOrder)i(TOrder)i(Type)i(Control)Single[]"), GB_STATIC_METHOD("NewNurbsRenderer","GluNurb", GLUNEWNURBSRENDERER, NULL), + /* Projections - see GLUproject.h */ + GB_STATIC_METHOD("Project", "Float[]", GLUPROJECT, "(ObjectX)f(ObjectY)f(ObjectZ)f(Modelview)Float[];(Projection)Float[];(Viewport)Integer[];"), + GB_STATIC_METHOD("UnProject", "Float[]", GLUUNPROJECT, "(WindowX)f(WindowY)f(WindowZ)f(Modelview)Float[];(Projection)Float[];(Viewport)Integer[];"), + GB_STATIC_METHOD("UnProject4", "Float[]", GLUUNPROJECT4, "(WindowX)f(WindowY)f(WindowZ)f(ClipW)f(Modelview)Float[];(Projection)Float[];(Viewport)Integer[];(NearValue)f(FarValue)f"), + /********************/ /* opengl constants */ /********************/ diff --git a/gb.opengl/src/glu/GLUnurb.c b/gb.opengl/src/glu/GLUnurb.c index fd0e32155..9c22984c4 100644 --- a/gb.opengl/src/glu/GLUnurb.c +++ b/gb.opengl/src/glu/GLUnurb.c @@ -89,7 +89,7 @@ BEGIN_METHOD(GLUENDTRIM, GB_OBJECT nurb) END_METHOD -BEGIN_METHOD(GLUNURBSCURVE, GB_OBJECT nurb; GB_INTEGER knotCount; GB_OBJECT knots; GB_INTEGER stride; GB_OBJECT control; GB_INTEGER order; GB_INTEGER type) +BEGIN_METHOD(GLUNURBSCURVE, GB_OBJECT nurb; GB_INTEGER knotCount; GB_OBJECT knots; GB_INTEGER stride; GB_OBJECT control; GB_INTEGER order; GB_INTEGER type) GET_NURB(); diff --git a/gb.opengl/src/glu/GLUproject.c b/gb.opengl/src/glu/GLUproject.c new file mode 100644 index 000000000..c5674465d --- /dev/null +++ b/gb.opengl/src/glu/GLUproject.c @@ -0,0 +1,138 @@ +/*************************************************************************** + + GLUproject.c + + (c) 2005-2012 Laurent Carlier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + +***************************************************************************/ + +#define __GLUPROJECT_C + +#include "GLU.h" + +BEGIN_METHOD(GLUPROJECT, GB_FLOAT ObjX; GB_FLOAT ObjY; GB_FLOAT ObjZ; GB_OBJECT Model; GB_OBJECT Proj; GB_OBJECT View) + + GLdouble model[16], proj[16], win[3]; + GLint view[4]; + int i, status; + GB_ARRAY fArray; + + if ((GB.Array.Count(VARG(Model)) != 16) || (GB.Array.Count(VARG(Proj)) != 16) || (GB.Array.Count(VARG(View)) != 4)) + { + GB.ReturnNull(); + return; + } + + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Model),i)); + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Proj),i)); + for (i=0; i<4; i++) + view[i] = *((GLint *)GB.Array.Get(VARG(View),i)); + + status = gluProject(VARG(ObjX), VARG(ObjY), VARG(ObjZ), model, proj, view, &win[0], &win[1], &win[2]); + + if (status == GLU_FALSE) + { + GB.ReturnNull(); + return; + } + + GB.Array.New(&fArray , GB_T_FLOAT , 3); + + for (i=0; i<3; i++) + *((GLdouble *)GB.Array.Get(fArray, i)) = win[i]; + + GB.ReturnObject(fArray); + +END_METHOD + +BEGIN_METHOD(GLUUNPROJECT, GB_FLOAT WinX; GB_FLOAT WinY; GB_FLOAT WinZ; GB_OBJECT Model; GB_OBJECT Proj; GB_OBJECT View) + + + GLdouble model[16], proj[16], obj[3]; + GLint view[4]; + int i, status; + GB_ARRAY fArray; + + if ((GB.Array.Count(VARG(Model)) != 16) || (GB.Array.Count(VARG(Proj)) != 16) || (GB.Array.Count(VARG(View)) != 4)) + { + GB.ReturnNull(); + return; + } + + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Model),i)); + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Proj),i)); + for (i=0; i<4; i++) + view[i] = *((GLint *)GB.Array.Get(VARG(View),i)); + + status = gluUnProject(VARG(WinX), VARG(WinY), VARG(WinZ), model, proj, view, &obj[0], &obj[1], &obj[2]); + + if (status == GLU_FALSE) + { + GB.ReturnNull(); + return; + } + + GB.Array.New(&fArray , GB_T_FLOAT , 3); + + for (i=0; i<3; i++) + *((GLdouble *)GB.Array.Get(fArray, i)) = obj[i]; + + GB.ReturnObject(fArray); + +END_METHOD + +BEGIN_METHOD(GLUUNPROJECT4, GB_FLOAT WinX; GB_FLOAT WinY; GB_FLOAT WinZ; GB_FLOAT ClipW; GB_OBJECT Model; GB_OBJECT Proj; GB_OBJECT View; GB_FLOAT NearVal; GB_FLOAT FarVal) + + GLdouble model[16], proj[16], obj[4]; + GLint view[4]; + int i, status; + GB_ARRAY fArray; + + if ((GB.Array.Count(VARG(Model)) != 16) || (GB.Array.Count(VARG(Proj)) != 16) || (GB.Array.Count(VARG(View)) != 4)) + { + GB.ReturnNull(); + return; + } + + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Model),i)); + for (i=0; i<16; i++) + view[i] = *((GLdouble *)GB.Array.Get(VARG(Proj),i)); + for (i=0; i<4; i++) + view[i] = *((GLint *)GB.Array.Get(VARG(View),i)); + + status = gluUnProject4(VARG(WinX), VARG(WinY), VARG(WinZ), VARG(ClipW), model, proj, view, VARG(NearVal), VARG(FarVal), &obj[0], &obj[1], &obj[2], &obj[3]); + + if (status == GLU_FALSE) + { + GB.ReturnNull(); + return; + } + + GB.Array.New(&fArray , GB_T_FLOAT , 4); + + for (i=0; i<4; i++) + *((GLdouble *)GB.Array.Get(fArray, i)) = obj[i]; + + GB.ReturnObject(fArray); + +END_METHOD diff --git a/gb.opengl/src/glu/GLUproject.h b/gb.opengl/src/glu/GLUproject.h new file mode 100644 index 000000000..39d4e78d9 --- /dev/null +++ b/gb.opengl/src/glu/GLUproject.h @@ -0,0 +1,34 @@ +/*************************************************************************** + + GLUproject.h + + (c) 2005-2012 Laurent Carlier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + +***************************************************************************/ + +#ifndef __GLUPROJECT_H +#define __GLUPROJECT_H + +#include "main.h" + +DECLARE_METHOD(GLUPROJECT); +DECLARE_METHOD(GLUUNPROJECT); +DECLARE_METHOD(GLUUNPROJECT4); + +#endif /* __GLUPROJECT_H */ + diff --git a/gb.opengl/src/glu/Makefile.am b/gb.opengl/src/glu/Makefile.am index 1dee81a4f..41a824b7a 100644 --- a/gb.opengl/src/glu/Makefile.am +++ b/gb.opengl/src/glu/Makefile.am @@ -15,4 +15,6 @@ gb_opengl_glu_la_SOURCES = \ GLUquadratic.h GLUquadratic.c \ cgluquadric.h cgluquadric.c \ cglunurb.h cglunurb.c\ - GLUnurb.h GLUnurb.c + GLUnurb.h GLUnurb.c \ + GLUproject.h GLUproject.c +