glm.h in VisualCprogrammingOp


Visual C programming OpenGL chapter "source code with a special three-dimen...Original Link
    Sponsored links

			
			/*    
      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			click here to download the whole source code package.

			
			


Project Files

    Sponsored links
NameSizeDate
 <Visual>0.00 B0 0
 <Chap07_Worms>0.00 B18-04-05 11:01
 Worms.c6.82 kB23-12-98 12:48
 Worms.dsp3.42 kB05-08-00 13:17
 Worms.0013.38 kB25-11-99 00:14
 Worms.opt47.50 kB05-08-00 13:21
 Worms.dsw533.00 B05-08-00 13:17
 Worms.plg3.46 kB05-08-00 13:17
 <Chap07_SSaver>0.00 B18-04-05 11:01
 EZFONT.H355.00 B01-01-96 00:00
 Ssaver.c2.41 kB30-09-99 00:09
 ogl.c7.00 kB28-09-99 23:37
 SSAVER.DEF174.00 B06-12-96 12:59
 ICON1.ICO766.00 B06-12-96 09:00
 glss.dsp3.85 kB23-12-98 12:26
 glss.dsw531.00 B21-08-98 18:22
 Ezfont.c2.33 kB28-09-99 22:53
 resource.h1.02 kB28-09-99 23:42
 Ssaver.rc3.95 kB28-09-99 23:42
 <Chap07_Puzzle>0.00 B18-04-05 11:01
 Glpuzzle.c20.20 kB05-08-00 13:13
 glpuzzle.0013.36 kB31-01-99 16:52
 Glpuzzle.opt47.50 kB05-08-00 13:16
 glpuzzle.dsp3.45 kB05-08-00 13:16
 Glpuzzle.dsw539.00 B05-08-00 13:12
 glpuzzle.plg4.67 kB05-08-00 13:13
 <Chap01_Olympic>0.00 B18-04-05 11:01
 OLYMPIC.DSW537.00 B05-08-00 10:07
 OLYMPIC.C6.40 kB06-08-98 09:08
 Olympic.0013.35 kB06-08-98 09:17
 Olympic.dsp3.44 kB05-08-00 10:10
 Olympic.plg250.00 B05-08-00 10:10
 Olympic.opt47.50 kB05-08-00 10:10
 <Chap07_Maze>0.00 B18-04-05 11:01
 Maze.bmp48.05 kB13-05-98 10:08
 MAZE.C13.99 kB19-07-98 23:04
 Maze.dsw531.00 B05-08-00 13:11
 Maze.opt47.50 kB05-08-00 13:11
 Maze.plg1.04 kB05-08-00 13:11
 Maze.dsp3.98 kB05-08-00 13:10
 <Chap07_Hanoi>0.00 B18-04-05 11:01
 HANOI.C6.47 kB06-08-98 06:39
 Hanoi.dsp3.42 kB05-08-00 13:03
 Hanoi.0013.38 kB03-12-99 23:35
 Hanoi.opt47.50 kB05-08-00 13:04
 Hanoi.dsw533.00 B05-08-00 13:03
 Hanoi.plg1.05 kB05-08-00 13:03
 <Chap06_Terrain>0.00 B18-04-05 11:02
 patriot.obj22.26 kB31-03-97 21:27
 DlgAbout.cpp323.00 B15-10-98 09:59
 DlgAbout.h789.00 B08-05-98 10:23
 FormCommandView.cpp2.50 kB01-12-99 17:50
 FormCommandView.h1.92 kB01-12-99 15:24
 README.TXT4.37 kB12-12-97 11:43
 RenderView.cpp21.04 kB02-12-99 01:36
 RenderView.h2.58 kB02-12-99 01:13
 resource.h1.66 kB01-12-99 15:00
 STDAFX.CPP202.00 B30-04-98 13:01
 STDAFX.H1.46 kB08-05-98 10:23
 Tool.0014.86 kB09-01-99 16:40
 TOOL.CLW4.83 kB01-12-99 22:25
 Tool.cpp2.31 kB05-08-00 10:00
 Tool.dsp6.37 kB05-08-00 10:07
 glm.cpp46.00 kB01-12-99 19:37
 Tool.h1.31 kB23-10-99 16:56
 Tool.rc15.27 kB01-12-99 15:27
 TOOL.REG669.00 B12-12-97 11:43
 TOOLDOC.H1.73 kB16-06-98 09:22
 Mainfrm.cpp2.43 kB01-12-99 22:26
 MainFrm.h1.62 kB01-12-99 22:25
 glm.h8.11 kB30-11-99 15:03
 Plane.obj23.90 kB10-06-98 09:34
 F-16.mtl573.00 B01-12-99 17:44
 Tooldoc.cpp1.11 kB01-12-99 20:22
 Airport.asc1.00 MB14-11-97 14:38
 Tool.0026.53 kB02-12-99 01:36
 Tool.opt48.50 kB05-08-00 10:07
 Tool.dsw531.00 B05-08-00 09:58
 Tool.plg2.25 kB05-08-00 10:00
 <RES>0.00 B18-04-05 11:02
 A.dat3.00 kB09-01-99 14:18
 terrain.bmp48.05 kB01-12-99 10:10
 TOOL.ICO1.05 kB21-05-98 17:17
 TOOL.RC2396.00 B21-05-98 17:17
 TOOLDOC.ICO1.05 kB21-05-98 17:18
 toolbar.bmp1.05 kB30-11-99 21:44
 Texture.bmp3.05 kB09-01-99 14:41
 terrain2.bmp192.05 kB29-11-99 17:37
 <Chap05_ReadObj>0.00 B18-04-05 11:02
 ToolDoc.h1.83 kB17-10-98 02:03
 ToolDoc.cpp2.16 kB17-10-98 02:03
 Tool.reg669.00 B12-12-97 11:43
 Tool.rc14.23 kB17-10-98 02:21
 Tool.plg2.24 kB08-01-00 00:23
 Tool.0015.03 kB23-12-98 12:53
 Tool.h1.42 kB17-10-98 01:49
 Tool.dsw531.00 B07-01-98 22:13
 Tool.dsp4.97 kB07-01-98 22:13
 Tool.cpp2.56 kB17-10-98 05:05
 StdAfx.h1.46 kB08-05-98 10:23
 StdAfx.cpp202.00 B30-04-98 13:01
 resource.h1.52 kB16-10-98 02:57
 RenderView.h2.76 kB15-10-98 23:28
 RenderView.cpp8.13 kB17-10-98 05:04
 ReadMe.txt4.37 kB12-12-97 11:43
 MainFrm.h1.62 kB16-10-98 22:20
 MainFrm.cpp2.89 kB16-10-98 22:20
 glm.h8.03 kB26-10-98 19:24
 glm.cpp45.79 kB26-10-98 19:24
 FormCommandView.h2.94 kB15-10-98 23:42
 FormCommandView.cpp10.84 kB17-10-98 05:04
 DlgAbout.cpp640.00 B08-05-98 10:24
 DlgAbout.h789.00 B08-05-98 10:23
 Tool.opt48.50 kB09-01-00 20:43
 Tool.aps32.05 kB08-01-00 00:22
 <Res>0.00 B18-04-05 11:02
 Tool.rc2396.00 B21-05-98 17:17
 Tool.ico1.05 kB21-05-98 17:17
 ToolDoc.ico1.05 kB21-05-98 17:18
 Toolbar.bmp478.00 B17-10-98 02:07
 <Chap04_MyTemplate>0.00 B18-04-05 11:02
 StdAfx.cpp202.00 B05-08-00 10:32
 DlgAbout.cpp496.00 B05-08-00 10:32
 DlgAbout.h766.00 B05-08-00 11:21
 FormCommandView.cpp10.07 kB05-08-00 10:47
 FormCommandView.h2.95 kB05-08-00 11:21
 MainFrm.cpp2.89 kB05-08-00 10:47
 MainFrm.h1.60 kB05-08-00 11:21
 ReadMe.txt4.37 kB05-08-00 10:32
 RenderView.h2.76 kB05-08-00 10:47
 resource.h1.53 kB05-08-00 11:43
 MyTemplate.rc14.16 kB05-08-00 11:43
 StdAfx.h1.43 kB05-08-00 10:47
 MyTemplate.clw5.29 kB05-08-00 11:43
 MyTemplate.aps47.65 kB05-08-00 11:43
 MyTemplate.reg669.00 B05-08-00 10:32
 MyTemplate.dsp4.87 kB05-08-00 11:14
 MyTemplate.h1.46 kB05-08-00 10:47
 RenderView.cpp7.59 kB05-08-00 10:47
 MyTemplateDoc.h1.85 kB05-08-00 11:21
 MyTemplate.cpp2.38 kB05-08-00 10:47
 MyTemplate.dsw543.00 B05-08-00 10:56
 MyTemplate.mak10.01 kB07-05-98 19:10
 MyTemplateDoc.cpp2.24 kB05-08-00 10:47
 MyTemplate.plg256.00 B05-08-00 11:14
 <Res>0.00 B18-04-05 11:02
 MyTemplateDoc.ico1.05 kB21-05-98 17:18
 Toolbar.bmp478.00 B17-10-98 02:07
 MyTemplate.ico1.05 kB21-05-98 17:17
 MyTemplate.rc2396.00 B05-08-00 10:32
 <Chap08_Triangle>0.00 B18-04-05 11:02
 README.TXT3.72 kB07-06-96 09:13
 Triangle.rc22.39 kB17-05-00 17:02
 TRIANGLE.MDP35.50 kB09-06-96 14:36
 Triangle.dsw539.00 B17-05-00 16:26
 Triangle.dsp5.18 kB17-05-00 16:41
 TRIANGLE.MAK9.42 kB07-06-96 15:14
 vector.h1.34 kB03-08-98 11:28
 TriangleView.h9.63 kB17-06-00 21:45
 TRIANGLEDOC.H1.03 kB07-06-96 09:13
 TRIANGLE.H947.00 B07-06-96 09:13
 Stdafx.h537.00 B03-08-98 11:46
 Skeleten.h1.42 kB01-04-98 14:26
 resource.h3.74 kB04-04-98 09:59
 ooglTexture.h3.65 kB15-03-98 06:04
 NameDlg.h1.17 kB03-04-98 04:57
 MainFrm.h2.99 kB02-07-00 11:18
 Frame.h1.25 kB02-04-98 23:11
 body.h954.00 B03-08-98 11:30
 vector.cpp5.00 kB03-08-98 12:09
 Triangleview.cpp104.41 kB03-08-98 12:16
 TRIANGLE.CPP2.65 kB03-08-98 11:00
 STDAFX.CPP206.00 B07-06-96 09:13
 Skeleten.cpp2.52 kB03-08-98 10:59
 ooglTexture.cpp16.64 kB30-03-98 02:43
 NameDlg.cpp960.00 B03-04-98 04:57
 MainFrm.cpp19.88 kB01-07-00 16:21
 Frame.cpp2.07 kB17-05-00 16:28
 TRIANGLE.CLW8.40 kB17-05-00 17:02
 Triangledoc.cpp1.78 kB04-04-98 10:07
 Triangle.0015.36 kB03-08-98 12:21
 Triangle.opt48.50 kB17-05-00 17:22
 Triangle.aps68.57 kB17-05-00 17:02
 Triangle.plg816.00 B17-05-00 17:03
 <RES>0.00 B18-04-05 11:02
 attribut.bmp6.27 kB04-04-98 08:01
 icon1.ico766.00 B04-04-98 09:31
 manipula.bmp4.62 kB17-05-00 17:02
 play.bmp238.00 B01-04-98 18:57
 smallico.ico1.05 kB04-04-98 09:44
...

Related Items

    Sponsored links