資源簡介
opengl讀取obj文件時(shí)可以使用的庫

代碼片段和文件信息
/*????
?*??Wavefront?.obj?file?format?reader.
?*
?*??author:?Nate?Robins
?*??email:?ndr@pobox.com
?*??www:?http://www.pobox.com/~ndr
?*/
/*?includes?*/
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include?“glm.h“
/*?defines?*/
#define?T(x)?model->triangles[(x)]
/*?enums?*/
enum?{?X?Y?Z?W?}; /*?elements?of?a?vertex?*/
/*?typedefs?*/
/*?_GLMnode:?general?purpose?node
?*/
typedef?struct?_GLMnode?{
??GLuint???????????index;
??GLboolean????????averaged;
??struct?_GLMnode*?next;
}?GLMnode;
/*?private?functions?*/
/*?_glmMax:?returns?the?maximum?of?two?floats?*/
static?GLfloat
_glmMax(GLfloat?a?GLfloat?b)?
{
??if?(a?>?b)
????return?a;
??return?b;
}
/*?_glmAbs:?returns?the?absolute?value?of?a?float?*/
static?GLfloat
_glmAbs(GLfloat?f)
{
??if?(f?0)
????return?-f;
??return?f;
}
/*?_glmDot:?compute?the?dot?product?of?two?vectors
?*
?*?u?-?array?of?3?GLfloats?(GLfloat?u[3])
?*?v?-?array?of?3?GLfloats?(GLfloat?v[3])
?*/
static?GLfloat
_glmDot(GLfloat*?u?GLfloat*?v)
{
??assert(u);
??assert(v);
??/*?compute?the?dot?product?*/
??return?u[X]?*?v[X]?+?u[Y]?*?v[Y]?+?u[Z]?*?v[Z];
}
/*?_glmCross:?compute?the?cross?product?of?two?vectors
?*
?*?u?-?array?of?3?GLfloats?(GLfloat?u[3])
?*?v?-?array?of?3?GLfloats?(GLfloat?v[3])
?*?n?-?array?of?3?GLfloats?(GLfloat?n[3])?to?return?the?cross?product?in
?*/
static?GLvoid
_glmCross(GLfloat*?u?GLfloat*?v?GLfloat*?n)
{
??assert(u);
??assert(v);
??assert(n);
??/*?compute?the?cross?product?(u?x?v?for?right-handed?[ccw])?*/
??n[X]?=?u[Y]?*?v[Z]?-?u[Z]?*?v[Y];
??n[Y]?=?u[Z]?*?v[X]?-?u[X]?*?v[Z];
??n[Z]?=?u[X]?*?v[Y]?-?u[Y]?*?v[X];
}
/*?_glmNormalize:?normalize?a?vector
?*
?*?n?-?array?of?3?GLfloats?(GLfloat?n[3])?to?be?normalized
?*/
static?GLvoid
_glmNormalize(GLfloat*?n)
{
??GLfloat?l;
??assert(n);
??/*?normalize?*/
??l?=?(GLfloat)sqrt(n[X]?*?n[X]?+?n[Y]?*?n[Y]?+?n[Z]?*?n[Z]);
??n[0]?/=?l;
??n[1]?/=?l;
??n[2]?/=?l;
}
/*?_glmEqual:?compares?two?vectors?and?returns?GL_TRUE?if?they?are
?*?equal?(within?a?certain?threshold)?or?GL_FALSE?if?not.?An?epsilon
?*?that?works?fairly?well?is?0.000001.
?*
?*?u?-?array?of?3?GLfloats?(GLfloat?u[3])
?*?v?-?array?of?3?GLfloats?(GLfloat?v[3])?
?*/
static?GLboolean
_glmEqual(GLfloat*?u?GLfloat*?v?GLfloat?epsilon)
{
??if?(_glmAbs(u[0]?-?v[0])???????_glmAbs(u[1]?-?v[1])???????_glmAbs(u[2]?-?v[2])???{
????return?GL_TRUE;
??}
??return?GL_FALSE;
}
/*?_glmWeldVectors:?eliminate?(weld)?vectors?that?are?within?an
?*?epsilon?of?each?other.
?*
?*?vectors????-?array?of?GLfloat[3]‘s?to?be?welded
?*?numvectors?-?number?of?GLfloat[3]‘s?in?vectors
?*?epsilon????-?maximum?difference?between?vectors?
?*
?*/
GLfloat*
_glmWeldVectors(GLfloat*?vectors?GLuint*?numvectors?GLfloat?epsilon)
{
??GLfloat*?copies;
??GLuint???copied;
??GLuint???i?j;
??copies?=?(GLfloat*)malloc(sizeof(GLfloat)?*?3?*?(*numvectors?+?1));
??memcpy(copies?vectors?(sizeof(GLfloat)?*?3?*?(*numvectors?+?1)));
??copied?=?1
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????8451??1997-07-17?23:27??glm.h
?????文件???????54878??2000-04-23?17:27??glm.cpp
- 上一篇:ttf格式轉(zhuǎn)bdf格式
- 下一篇:二叉樹的構(gòu)造與遍歷
評論
共有 條評論