資源簡介
大學(xué)計算機圖形學(xué)課程作業(yè)代碼示例,主要使用opengl庫,c++語言編寫,包含完整的工程文件,帶有部分注釋。
代碼片段和文件信息
#include?
#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;
??for?(i?=?1;?i?<=?*numvectors;?i++)?{
????for?(j?=?1;?j?<=?copied;?j++)?{
??????if?(_glmEqual(&vectors[3?*?i]?&copies[3?*?j]?epsilon))?{
goto?duplic
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????97727??2015-06-23?00:52??201206020004金瑋?第一次.docx
?????文件??????431268??2015-06-23?08:36??201206020004金瑋?第三次.docx
?????文件??????163344??2015-06-23?00:51??201206020004金瑋?第二次.docx
?????目錄???????????0??2015-06-23?08:36??experi3\
?????目錄???????????0??2015-06-22?20:16??experi3\Debug\
?????文件??????166400??2015-06-23?08:34??experi3\Debug\experi3.exe
?????文件??????778996??2015-06-23?08:34??experi3\Debug\experi3.ilk
?????文件?????1362944??2015-06-23?08:34??experi3\Debug\experi3.pdb
?????目錄???????????0??2015-06-22?20:16??experi3\experi3\
?????文件????33030144??2015-06-23?08:36??experi3\experi3.sdf
?????文件?????????888??2015-06-16?11:56??experi3\experi3.sln
?????文件???????31744??2015-06-23?08:36??experi3\experi3.v11.suo
?????文件??????786450??2015-06-22?18:53??experi3\experi3\bubble.tga
?????文件??????196626??2015-04-21?23:49??experi3\experi3\butterfly.tga
?????目錄???????????0??2015-06-22?20:16??experi3\experi3\data\
?????文件?????2280355??2009-05-02?12:49??experi3\experi3\data\al_sword.obj
?????文件?????2497386??2008-12-18?05:11??experi3\experi3\data\bunny.obj
?????文件?????6754463??2009-03-14?18:01??experi3\experi3\data\couple.obj
?????文件?????1761993??2008-03-14?17:39??experi3\experi3\data\dog.obj
?????文件?????1758059??2008-01-07?18:15??experi3\experi3\data\elk.obj
?????文件?????4585181??2009-01-07?14:11??experi3\experi3\data\fandisk1.obj
?????文件?????4795045??2009-01-24?13:33??experi3\experi3\data\female.obj
?????文件?????1702375??2008-03-14?18:04??experi3\experi3\data\frog.obj
?????文件?????1769311??2008-01-06?00:36??experi3\experi3\data\gargoyle.obj
?????文件??????729270??2009-05-05?09:53??experi3\experi3\data\kiss.obj
?????文件?????2597280??2008-03-16?15:17??experi3\experi3\data\memento.obj
?????文件?????2190908??2008-01-06?22:00??experi3\experi3\data\neptune.obj
?????文件?????5163055??2009-05-06?12:10??experi3\experi3\data\sculpture.obj
?????文件??????220609??2015-04-13?11:36??experi3\experi3\data\teapot.obj
?????文件??????????53??2015-06-21?15:16??experi3\experi3\data\test.obj
?????目錄???????????0??2015-06-23?08:34??experi3\experi3\Debug\
............此處省略276個文件信息
評論
共有 條評論