Home » Source Code » » glm.h

glm.h ( File view )

From:
  • By 2010-07-19
  • View(s):7
  • Download(s):1
  • Point(s): 1
			/*    
      glm.h
      Wavefront OBJ model file format reader/writer/manipulator.

      Includes routines for generating smooth normals with
      preservation of edges, welding redundant vertices & texture
      coordinate generation (spheremap and planar projections) + more.
 */
#include <windows.h>
#include <gl/gl.h>

#ifndef GL_MODEL

#define GL_MODEL

#ifndef M_PI
#define M_PI 3.14159265
#endif

#define GLM_NONE     (0)		/* render with only vertices */
#define GLM_FLAT     (1 << 0)		/* render with facet normals */
#define GLM_SMOOTH   (1 << 1)		/* render with vertex normals */
#define GLM_TEXTURE  (1 << 2)		/* render with texture coords */
#define GLM_COLOR    (1 << 3)		/* render with colors */
#define GLM_MATERIAL (1 << 4)		/* render with materials */


/* GLMmaterial: Structure that defines a material in a model. 
 */
typedef struct _GLMmaterial
{

  char* name;				/* name of material */
  GLfloat diffuse[4];			/* diffuse component */
  GLfloat ambient[4];			/* ambient component */
  GLfloat specular[4];			/* specular component */
  GLfloat emmissive[4];			/* emmissive component */
  GLfloat shininess;			/* specular exponent */

} GLMmaterial;

/* GLMtriangle: Structure that defines a triangle in a model.
 */
typedef struct _GLMtriangle {

  GLuint vindices[3];			/* array of triangle vertex indices */
  GLuint nindices[3];			/* array of triangle normal indices */
  GLuint tindices[3];			/* array of triangle texcoord indices*/
  GLuint findex;			/* index of triangle facet normal */

} GLMtriangle;

/* GLMgroup: Structure that defines a group in a model.
 */
typedef struct _GLMgroup {

  char*             name;		/* name of this group */
  GLuint            numtriangles;	/* number of triangles in this group */
  GLuint*           triangles;		/* array of triangle indices */
  GLuint            material;           /* index to material for group */
  struct _GLMgroup* next;		/* pointer to next group in model */

} GLMgroup;

/* GLMmodel: Structure that defines a model.
 */
typedef struct _GLMmodel {

  char*    pathname;			/* path to this model */
  char*    mtllibname;			/* name of the material library */

  GLuint   numvertices;			/* number of vertices in model */
  GLfloat* vertices;			/* array of vertices  */

  GLuint   numnormals;			/* number of normals in model */
  GLfloat* normals;			/* array of normals */

  GLuint   numtexcoords;		/* number of texcoords in model */
  GLfloat* texcoords;			/* array of texture coordinates */

  GLuint   numfacetnorms;		/* number of facetnorms in model */
  GLfloat* facetnorms;			/* array of facetnorms */

  GLuint       numtriangles;		/* number of triangles in model */
  GLMtriangle* triangles;		/* array of triangles */

  GLuint       nummaterials;		/* number of materials in model */
  GLMmaterial* materials;		/* array of materials */

  GLuint       numgroups;		/* number of groups in model */
  GLMgroup*    groups;			/* linked list of groups */

  GLfloat position[3];			/* position of the model */


} GLMmodel;

/* glmUnitize: "unitize" a model by translating it to the origin and
 * scaling it to fit in a unit cube around the origin.  Returns the
 * scalefactor used.
 *
 * model - properly initialized GLMmodel structure 
 */
GLfloat glmUnitize(GLMmodel* model);

/* glmDimensions: Calculates the dimensions (width, height, depth) of
 * a model.
 *
 * model      - initialized GLMmodel structure
 * dimensions - array of 3 GLfloats (GLfloat dimensions[3])
 */
GLvoid glmDimensions(GLMmodel* model, GLfloat* dimensions);

/* glmScale: Scales a model by a given amount.
 * 
 * model - properly initialized GLMmodel structure
 * scale - scalefactor (0.5 = half as large, 2.0 = twice as large)
 */
GLvoid glmScale(GLMmodel* model, GLfloat scale);

/* glmReverseWinding: Reverse the polygon winding for all polygons in
 * this model.  Default winding is counter-clockwise.  Also changes
 * the direction of the normals.
 * 
 * model - properly initialized GLMmodel structure 
 */
GLvoid glmReverseWinding(GLMmodel* model);

/* glmFacetNormals: Generates facet normals for a model (by taking the
 * cross product of the two vectors derived from the sides of each
 * triangle).  Assumes a counter-clockwise winding.
 *
 * model - initialized GLMmodel structure
 */
GLvoid glmFacetNormals(GLMmodel* model);

/* glmVertexNormals: Generates smooth vertex normals for a model.
 * First builds a list of all the triangles each vertex is in.  Then
 * loops through each vertex in the the list averaging all the facet
 * normals of the triangles each vertex is in.  Finally, sets the
 * normal index in the triangle for the vertex to the generated smooth
 * normal.  If the dot product of a facet normal and the facet normal
 * associated with the first triangle in the list of triangles the
 * current vertex is in is greater than the cosine of the angle
 * parameter to the function, that facet normal is not added into the
 * average normal calculation and the corresponding vertex is given
 * the facet normal.  This tends to preserve hard edges.  The angle to
 * use depends on the model, but 90 degrees is usually a good start.
 *
 * model - initialized GLMmodel structure
 * angle - maximum angle (in degrees) to smooth across
 */
GLvoid glmVertexNormals(GLMmodel* model, GLfloat angle);

/* glmLinearTexture: Generates texture coordinates according to a
 * linear projection of the texture map.  It generates these by
 * linearly mapping the vertices onto a square.
 *
 * model - pointer to initialized GLMmodel structure
 */
GLvoid glmLinearTexture(GLMmodel* model);

/* glmSpheremapTexture: Generates texture coordinates according to a
 * spherical projection of the texture map.  Sometimes referred to as
 * spheremap, or reflection map texture coordinates.  It generates
 * these by using the normal to calculate where that vertex would map
 * onto a sphere.  Since it is impossible to map something flat
 * perfectly onto something spherical, there is distortion at the
 * poles.  This particular implementation causes the poles along the X
 * axis to be distorted.
 *
 * model - pointer to initialized GLMmodel structure
 */
GLvoid glmSpheremapTexture(GLMmodel* model);

/* glmDelete: Deletes a GLMmodel structure.
 *
 * model - initialized GLMmodel structure
 */
GLvoid glmDelete(GLMmodel* model);

/* glmReadOBJ: Reads a model description from a Wavefront .OBJ file.
 * Returns a pointer to the created object which should be free'd with
 * glmDelete().
 *
 * filename - name of the file containing the Wavefront .OBJ format data.  
 */
GLMmodel* glmReadOBJ(char* filename);


/* glmDraw: Renders the model to the current OpenGL context using the
 * mode specified.
 *
 * model    - initialized GLMmodel structure
 * mode     - a bitwise OR of values describing what is to be rendered.
 *            GLM_NONE    -  render with only vertices
 *            GLM_FLAT    -  render with facet normals
 *            GLM_SMOOTH  -  render with vertex normals
 *            GLM_TEXTURE -  render with texture coords
 *            GLM_FLAT and GLM_SMOOTH should not both be specified.
 */
GLvoid glmDraw(GLMmodel* model, GLuint mode);

/* glmList: Generates and returns a display list for the model using
 * the mode specified.
 *
 * model    - initialized GLMmodel structure
 * mode     - a bitwise OR of values describing what is to be rendered.
 *            GLM_NONE    -  render with only vertices
 *            GLM_FLAT    -  render with facet normals
 *            GLM_SMOOTH  -  render with vertex normals
 *            GLM_TEXTURE -  render with texture coords
 *            GLM_FLAT and GLM_SMOOTH should not both be specified.  
 */
GLuint glmList(GLMmodel* model, GLuint mode);

/* glmWeld: eliminate (weld) vectors that are within an epsilon of
 * each other.
 *
 * model      - initialized GLMmodel structure
 * epsilon    - maximum difference between vertices
 *              ( 0.00001 is a good start for a unitized model)
 *
 */
GLuint glmWeld(GLMmodel* model, GLfloat epsilon);

#endif //GL_MODEL			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
源码文件 <Visual><Visual>0.00 B0 0
源码文件 <Chap07_Worms><Chap07_Worms>0.00 B18-04-05 11:01
code file Worms.cWorms.c6.82 kB23-12-98 12:48
源码文件 Worms.dspWorms.dsp3.42 kB05-08-00 13:17
源码文件 Worms.001Worms.0013.38 kB25-11-99 00:14
源码文件 Worms.optWorms.opt47.50 kB05-08-00 13:21
源码文件 Worms.dswWorms.dsw533.00 B05-08-00 13:17
源码文件 Worms.plgWorms.plg3.46 kB05-08-00 13:17
源码文件 <Chap07_SSaver><Chap07_SSaver>0.00 B18-04-05 11:01
code file EZFONT.HEZFONT.H355.00 B01-01-96 00:00
code file Ssaver.cSsaver.c2.41 kB30-09-99 00:09
code file ogl.cogl.c7.00 kB28-09-99 23:37
源码文件 SSAVER.DEFSSAVER.DEF174.00 B06-12-96 12:59
源码文件 ICON1.ICOICON1.ICO766.00 B06-12-96 09:00
源码文件 glss.dspglss.dsp3.85 kB23-12-98 12:26
源码文件 glss.dswglss.dsw531.00 B21-08-98 18:22
code file Ezfont.cEzfont.c2.33 kB28-09-99 22:53
code file resource.hresource.h1.02 kB28-09-99 23:42
code file Ssaver.rcSsaver.rc3.95 kB28-09-99 23:42
源码文件 <Chap07_Puzzle><Chap07_Puzzle>0.00 B18-04-05 11:01
code file Glpuzzle.cGlpuzzle.c20.20 kB05-08-00 13:13
源码文件 glpuzzle.001glpuzzle.0013.36 kB31-01-99 16:52
源码文件 Glpuzzle.optGlpuzzle.opt47.50 kB05-08-00 13:16
源码文件 glpuzzle.dspglpuzzle.dsp3.45 kB05-08-00 13:16
源码文件 Glpuzzle.dswGlpuzzle.dsw539.00 B05-08-00 13:12
源码文件 glpuzzle.plgglpuzzle.plg4.67 kB05-08-00 13:13
源码文件 <Chap01_Olympic><Chap01_Olympic>0.00 B18-04-05 11:01
源码文件 OLYMPIC.DSWOLYMPIC.DSW537.00 B05-08-00 10:07
code file OLYMPIC.COLYMPIC.C6.40 kB06-08-98 09:08
源码文件 Olympic.001Olympic.0013.35 kB06-08-98 09:17
源码文件 Olympic.dspOlympic.dsp3.44 kB05-08-00 10:10
源码文件 Olympic.plgOlympic.plg250.00 B05-08-00 10:10
源码文件 Olympic.optOlympic.opt47.50 kB05-08-00 10:10
源码文件 <Chap07_Maze><Chap07_Maze>0.00 B18-04-05 11:01
源码文件 Maze.bmpMaze.bmp48.05 kB13-05-98 10:08
code file MAZE.CMAZE.C13.99 kB19-07-98 23:04
源码文件 Maze.dswMaze.dsw531.00 B05-08-00 13:11
源码文件 Maze.optMaze.opt47.50 kB05-08-00 13:11
源码文件 Maze.plgMaze.plg1.04 kB05-08-00 13:11
源码文件 Maze.dspMaze.dsp3.98 kB05-08-00 13:10
源码文件 <Chap07_Hanoi><Chap07_Hanoi>0.00 B18-04-05 11:01
code file HANOI.CHANOI.C6.47 kB06-08-98 06:39
源码文件 Hanoi.dspHanoi.dsp3.42 kB05-08-00 13:03
源码文件 Hanoi.001Hanoi.0013.38 kB03-12-99 23:35
源码文件 Hanoi.optHanoi.opt47.50 kB05-08-00 13:04
源码文件 Hanoi.dswHanoi.dsw533.00 B05-08-00 13:03
源码文件 Hanoi.plgHanoi.plg1.05 kB05-08-00 13:03
源码文件 <Chap06_Terrain><Chap06_Terrain>0.00 B18-04-05 11:02
源码文件 patriot.objpatriot.obj22.26 kB31-03-97 21:27
code file DlgAbout.cppDlgAbout.cpp323.00 B15-10-98 09:59
code file DlgAbout.hDlgAbout.h789.00 B08-05-98 10:23
code file FormCommandView.cppFormCommandView.cpp2.50 kB01-12-99 17:50
code file FormCommandView.hFormCommandView.h1.92 kB01-12-99 15:24
code file README.TXTREADME.TXT4.37 kB12-12-97 11:43
code file RenderView.cppRenderView.cpp21.04 kB02-12-99 01:36
code file RenderView.hRenderView.h2.58 kB02-12-99 01:13
code file resource.hresource.h1.66 kB01-12-99 15:00
code file STDAFX.CPPSTDAFX.CPP202.00 B30-04-98 13:01
code file STDAFX.HSTDAFX.H1.46 kB08-05-98 10:23
源码文件 Tool.001Tool.0014.86 kB09-01-99 16:40
源码文件 TOOL.CLWTOOL.CLW4.83 kB01-12-99 22:25
code file Tool.cppTool.cpp2.31 kB05-08-00 10:00
源码文件 Tool.dspTool.dsp6.37 kB05-08-00 10:07
code file glm.cppglm.cpp46.00 kB01-12-99 19:37
code file Tool.hTool.h1.31 kB23-10-99 16:56
code file Tool.rcTool.rc15.27 kB01-12-99 15:27
源码文件 TOOL.REGTOOL.REG669.00 B12-12-97 11:43
code file TOOLDOC.HTOOLDOC.H1.73 kB16-06-98 09:22
code file Mainfrm.cppMainfrm.cpp2.43 kB01-12-99 22:26
code file MainFrm.hMainFrm.h1.62 kB01-12-99 22:25
code file glm.hglm.h8.11 kB30-11-99 15:03
源码文件 Plane.objPlane.obj23.90 kB10-06-98 09:34
源码文件 F-16.mtlF-16.mtl573.00 B01-12-99 17:44
code file Tooldoc.cppTooldoc.cpp1.11 kB01-12-99 20:22
源码文件 Airport.ascAirport.asc1.00 MB14-11-97 14:38
源码文件 Tool.002Tool.0026.53 kB02-12-99 01:36
源码文件 Tool.optTool.opt48.50 kB05-08-00 10:07
源码文件 Tool.dswTool.dsw531.00 B05-08-00 09:58
源码文件 Tool.plgTool.plg2.25 kB05-08-00 10:00
源码文件 <RES><RES>0.00 B18-04-05 11:02
源码文件 A.datA.dat3.00 kB09-01-99 14:18
源码文件 terrain.bmpterrain.bmp48.05 kB01-12-99 10:10
源码文件 TOOL.ICOTOOL.ICO1.05 kB21-05-98 17:17
源码文件 TOOL.RC2TOOL.RC2396.00 B21-05-98 17:17
源码文件 TOOLDOC.ICOTOOLDOC.ICO1.05 kB21-05-98 17:18
源码文件 toolbar.bmptoolbar.bmp1.05 kB30-11-99 21:44
源码文件 Texture.bmpTexture.bmp3.05 kB09-01-99 14:41
源码文件 terrain2.bmpterrain2.bmp192.05 kB29-11-99 17:37
源码文件 <Chap05_ReadObj><Chap05_ReadObj>0.00 B18-04-05 11:02
code file ToolDoc.hToolDoc.h1.83 kB17-10-98 02:03
code file ToolDoc.cppToolDoc.cpp2.16 kB17-10-98 02:03
源码文件 Tool.regTool.reg669.00 B12-12-97 11:43
code file Tool.rcTool.rc14.23 kB17-10-98 02:21
源码文件 Tool.plgTool.plg2.24 kB08-01-00 00:23
源码文件 Tool.001Tool.0015.03 kB23-12-98 12:53
code file Tool.hTool.h1.42 kB17-10-98 01:49
源码文件 Tool.dswTool.dsw531.00 B07-01-98 22:13
源码文件 Tool.dspTool.dsp4.97 kB07-01-98 22:13
code file Tool.cppTool.cpp2.56 kB17-10-98 05:05
code file StdAfx.hStdAfx.h1.46 kB08-05-98 10:23
code file StdAfx.cppStdAfx.cpp202.00 B30-04-98 13:01
code file resource.hresource.h1.52 kB16-10-98 02:57
code file RenderView.hRenderView.h2.76 kB15-10-98 23:28
code file RenderView.cppRenderView.cpp8.13 kB17-10-98 05:04
code file ReadMe.txtReadMe.txt4.37 kB12-12-97 11:43
code file MainFrm.hMainFrm.h1.62 kB16-10-98 22:20
code file MainFrm.cppMainFrm.cpp2.89 kB16-10-98 22:20
code file glm.hglm.h8.03 kB26-10-98 19:24
code file glm.cppglm.cpp45.79 kB26-10-98 19:24
code file FormCommandView.hFormCommandView.h2.94 kB15-10-98 23:42
code file FormCommandView.cppFormCommandView.cpp10.84 kB17-10-98 05:04
code file DlgAbout.cppDlgAbout.cpp640.00 B08-05-98 10:24
code file DlgAbout.hDlgAbout.h789.00 B08-05-98 10:23
源码文件 Tool.optTool.opt48.50 kB09-01-00 20:43
源码文件 Tool.apsTool.aps32.05 kB08-01-00 00:22
源码文件 <Res><Res>0.00 B18-04-05 11:02
源码文件 Tool.rc2Tool.rc2396.00 B21-05-98 17:17
源码文件 Tool.icoTool.ico1.05 kB21-05-98 17:17
源码文件 ToolDoc.icoToolDoc.ico1.05 kB21-05-98 17:18
源码文件 Toolbar.bmpToolbar.bmp478.00 B17-10-98 02:07
源码文件 <Chap04_MyTemplate><Chap04_MyTemplate>0.00 B18-04-05 11:02
code file StdAfx.cppStdAfx.cpp202.00 B05-08-00 10:32
code file DlgAbout.cppDlgAbout.cpp496.00 B05-08-00 10:32
code file DlgAbout.hDlgAbout.h766.00 B05-08-00 11:21
code file FormCommandView.cppFormCommandView.cpp10.07 kB05-08-00 10:47
code file FormCommandView.hFormCommandView.h2.95 kB05-08-00 11:21
code file MainFrm.cppMainFrm.cpp2.89 kB05-08-00 10:47
code file MainFrm.hMainFrm.h1.60 kB05-08-00 11:21
code file ReadMe.txtReadMe.txt4.37 kB05-08-00 10:32
code file RenderView.hRenderView.h2.76 kB05-08-00 10:47
code file resource.hresource.h1.53 kB05-08-00 11:43
code file MyTemplate.rcMyTemplate.rc14.16 kB05-08-00 11:43
code file StdAfx.hStdAfx.h1.43 kB05-08-00 10:47
源码文件 MyTemplate.clwMyTemplate.clw5.29 kB05-08-00 11:43
源码文件 MyTemplate.apsMyTemplate.aps47.65 kB05-08-00 11:43
源码文件 MyTemplate.regMyTemplate.reg669.00 B05-08-00 10:32
源码文件 MyTemplate.dspMyTemplate.dsp4.87 kB05-08-00 11:14
code file MyTemplate.hMyTemplate.h1.46 kB05-08-00 10:47
code file RenderView.cppRenderView.cpp7.59 kB05-08-00 10:47
code file MyTemplateDoc.hMyTemplateDoc.h1.85 kB05-08-00 11:21
code file MyTemplate.cppMyTemplate.cpp2.38 kB05-08-00 10:47
源码文件 MyTemplate.dswMyTemplate.dsw543.00 B05-08-00 10:56
源码文件 MyTemplate.makMyTemplate.mak10.01 kB07-05-98 19:10
code file MyTemplateDoc.cppMyTemplateDoc.cpp2.24 kB05-08-00 10:47
源码文件 MyTemplate.plgMyTemplate.plg256.00 B05-08-00 11:14
源码文件 <Res><Res>0.00 B18-04-05 11:02
源码文件 MyTemplateDoc.icoMyTemplateDoc.ico1.05 kB21-05-98 17:18
源码文件 Toolbar.bmpToolbar.bmp478.00 B17-10-98 02:07
源码文件 MyTemplate.icoMyTemplate.ico1.05 kB21-05-98 17:17
源码文件 MyTemplate.rc2MyTemplate.rc2396.00 B05-08-00 10:32
源码文件 <Chap08_Triangle><Chap08_Triangle>0.00 B18-04-05 11:02
code file README.TXTREADME.TXT3.72 kB07-06-96 09:13
code file Triangle.rcTriangle.rc22.39 kB17-05-00 17:02
源码文件 TRIANGLE.MDPTRIANGLE.MDP35.50 kB09-06-96 14:36
源码文件 Triangle.dswTriangle.dsw539.00 B17-05-00 16:26
源码文件 Triangle.dspTriangle.dsp5.18 kB17-05-00 16:41
源码文件 TRIANGLE.MAKTRIANGLE.MAK9.42 kB07-06-96 15:14
code file vector.hvector.h1.34 kB03-08-98 11:28
code file TriangleView.hTriangleView.h9.63 kB17-06-00 21:45
code file TRIANGLEDOC.HTRIANGLEDOC.H1.03 kB07-06-96 09:13
code file TRIANGLE.HTRIANGLE.H947.00 B07-06-96 09:13
code file Stdafx.hStdafx.h537.00 B03-08-98 11:46
code file Skeleten.hSkeleten.h1.42 kB01-04-98 14:26
code file resource.hresource.h3.74 kB04-04-98 09:59
code file ooglTexture.hooglTexture.h3.65 kB15-03-98 06:04
code file NameDlg.hNameDlg.h1.17 kB03-04-98 04:57
code file MainFrm.hMainFrm.h2.99 kB02-07-00 11:18
code file Frame.hFrame.h1.25 kB02-04-98 23:11
code file body.hbody.h954.00 B03-08-98 11:30
code file vector.cppvector.cpp5.00 kB03-08-98 12:09
code file Triangleview.cppTriangleview.cpp104.41 kB03-08-98 12:16
code file TRIANGLE.CPPTRIANGLE.CPP2.65 kB03-08-98 11:00
code file STDAFX.CPPSTDAFX.CPP206.00 B07-06-96 09:13
code file Skeleten.cppSkeleten.cpp2.52 kB03-08-98 10:59
code file ooglTexture.cppooglTexture.cpp16.64 kB30-03-98 02:43
code file NameDlg.cppNameDlg.cpp960.00 B03-04-98 04:57
code file MainFrm.cppMainFrm.cpp19.88 kB01-07-00 16:21
code file Frame.cppFrame.cpp2.07 kB17-05-00 16:28
源码文件 TRIANGLE.CLWTRIANGLE.CLW8.40 kB17-05-00 17:02
code file Triangledoc.cppTriangledoc.cpp1.78 kB04-04-98 10:07
源码文件 Triangle.001Triangle.0015.36 kB03-08-98 12:21
源码文件 Triangle.optTriangle.opt48.50 kB17-05-00 17:22
源码文件 Triangle.apsTriangle.aps68.57 kB17-05-00 17:02
源码文件 Triangle.plgTriangle.plg816.00 B17-05-00 17:03
源码文件 <RES><RES>0.00 B18-04-05 11:02
源码文件 attribut.bmpattribut.bmp6.27 kB04-04-98 08:01
源码文件 icon1.icoicon1.ico766.00 B04-04-98 09:31
源码文件 manipula.bmpmanipula.bmp4.62 kB17-05-00 17:02
源码文件 play.bmpplay.bmp238.00 B01-04-98 18:57
源码文件 smallico.icosmallico.ico1.05 kB04-04-98 09:44
...
Sponsored links
×

glm.h (674.94 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

×

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com
×

切换到中文版?

CodeForge Chinese Version
CodeForge English Version
×

Where are you going?

×

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK
×

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D