亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? glm.cpp

?? 詳細介紹c++編程
?? CPP
?? 第 1 頁 / 共 4 頁
字號:
/*
      glm.cpp
      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 <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "glm.h"

#define T(x) (model->triangles[(x)])

#define fsin(x) (float)sin(x)
#define fcos(x) (float)cos(x)
#define fasin(x) (float)asin(x)
#define facos(x) (float)acos(x)
#define fsqrt(x) (float)sqrt(x)

/* _GLMnode: general purpose node
 */
typedef struct _GLMnode {
  GLuint           index;
  GLboolean        averaged;
  struct _GLMnode* next;
} GLMnode;

/* glmMax: returns the maximum of two floats */
static GLfloat glmMax(GLfloat a, GLfloat b) 
{
  if (b > a)
    return b;
  return a;
}

/* 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);
  return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
}

/* 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);
  n[0] = u[1]*v[2] - u[2]*v[1];
  n[1] = u[2]*v[0] - u[0]*v[2];
  n[2] = u[0]*v[1] - u[1]*v[0];
}

/* glmNormalize: normalize a vector
 *
 * v - array of 3 GLfloats (GLfloat v[3]) to be normalized
 */
static GLvoid glmNormalize(GLfloat* v)
{
  GLfloat l;
  assert(v);
  l = (GLfloat)sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  v[0] /= l;
  v[1] /= l;
  v[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]) < epsilon &&
      glmAbs(u[1] - v[1]) < epsilon &&
      glmAbs(u[2] - v[2]) < epsilon) 
  {
    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 duplicate;
      }
    }

    /* must not be any duplicates -- add to the copies array */
    copies[3 * copied + 0] = vectors[3 * i + 0];
    copies[3 * copied + 1] = vectors[3 * i + 1];
    copies[3 * copied + 2] = vectors[3 * i + 2];
    j = copied;				/* pass this along for below */
    copied++;

  duplicate:
    /* set the first component of this vector to point at the correct
       index into the new copies array */
    vectors[3 * i + 0] = (GLfloat)j;
  }

  *numvectors = copied-1;
  return copies;
}

/* glmFindGroup: Find a group in the model
 */
GLMgroup* glmFindGroup(GLMmodel* model, char* name)
{
  GLMgroup* group;

  assert(model);

  group = model->groups;
  while(group) {
    if (!strcmp(name, group->name))
      break;
    group = group->next;
  }

  return group;
}

/* glmAddGroup: Add a group to the model
 */
GLMgroup* glmAddGroup(GLMmodel* model, char* name)
{
  GLMgroup* group;

  group = glmFindGroup(model, name);
  if (!group) {
    group = (GLMgroup*)malloc(sizeof(GLMgroup));
    group->name = strdup(name);
    group->material = 0;
    group->numtriangles = 0;
    group->triangles = NULL;
    group->next = model->groups;
    model->groups = group;
    model->numgroups++;
  }

  return group;
}

/* glmFindGroup: Find a material in the model
 */
GLuint glmFindMaterial(GLMmodel* model, char* name)
{
  GLuint i;

  /* XXX doing a linear search on a string key'd list is pretty lame,
     but it works and is fast enough for now. */
  for (i = 0; i < model->nummaterials; i++) {
    if (!strcmp(model->materials[i].name, name))
      goto found;
  }

  /* didn't find the name, so print a warning and return the default
     material (0). */
  printf("glmFindMaterial():  can't find material \"%s\".\n", name);
  i = 0;

found:
  return i;
}


/* glmDirName: return the directory given a path
 *
 * path - filesystem path
 *
 * NOTE: the return value should be free'd.
 */
static char* glmDirName(char* path)
{
  char* dir;
  char* s;

  dir = strdup(path);

  s = strrchr(dir, '/');
  if (s)
    s[1] = '\0';
  else
    dir[0] = '\0';

  return dir;
}


/* glmReadMTL: read a wavefront material library file
 *
 * model - properly initialized GLMmodel structure
 * name  - name of the material library
 */
static GLvoid glmReadMTL(GLMmodel* model, char* name)
{
  FILE* file;
  char* dir;
  char* filename;
  char  buf[128];
  GLuint nummaterials, i;

  dir = glmDirName(model->pathname);
  filename = (char*)malloc(sizeof(char) * (strlen(dir) + strlen(name) + 1));
  strcpy(filename, dir);
  strcat(filename, name);
  free(dir);

  file = fopen(filename, "r");
  if (!file) {
    fprintf(stderr, "glmReadMTL() failed: can't open material file \"%s\".\n",
	    filename);
    exit(1);
  }
  free(filename);

  /* count the number of materials in the file */
  nummaterials = 1;
  while(fscanf(file, "%s", buf) != EOF) {
    switch(buf[0]) {
    case '#':				/* comment */
      /* eat up rest of line */
      fgets(buf, sizeof(buf), file);
      break;
    case 'n':				/* newmtl */
      fgets(buf, sizeof(buf), file);
      nummaterials++;
      sscanf(buf, "%s %s", buf, buf);
      break;
    default:
      /* eat up rest of line */
      fgets(buf, sizeof(buf), file);
      break;
    }
  }

  rewind(file);

  model->materials = (GLMmaterial*)malloc(sizeof(GLMmaterial) * nummaterials);
  model->nummaterials = nummaterials;

  /* set the default material */
  for (i = 0; i < nummaterials; i++) {
    model->materials[i].name = NULL;
    model->materials[i].shininess = 65.0f;
    model->materials[i].diffuse[0] = 0.8f;
    model->materials[i].diffuse[1] = 0.8f;
    model->materials[i].diffuse[2] = 0.8f;
    model->materials[i].diffuse[3] = 1.0f;
    model->materials[i].ambient[0] = 0.2f;
    model->materials[i].ambient[1] = 0.2f;
    model->materials[i].ambient[2] = 0.2f;
    model->materials[i].ambient[3] = 1.0f;
    model->materials[i].specular[0] = 0.0f;
    model->materials[i].specular[1] = 0.0f;
    model->materials[i].specular[2] = 0.0f;
    model->materials[i].specular[3] = 1.0f;
  }
  model->materials[0].name = strdup("default");

  /* now, read in the data */
  nummaterials = 0;
  while(fscanf(file, "%s", buf) != EOF) {
    switch(buf[0]) {
    case '#':				/* comment */
      /* eat up rest of line */
      fgets(buf, sizeof(buf), file);
      break;
    case 'n':				/* newmtl */
      fgets(buf, sizeof(buf), file);
      sscanf(buf, "%s %s", buf, buf);
      nummaterials++;
      model->materials[nummaterials].name = strdup(buf);
      break;
    case 'N':
      fscanf(file, "%f", &model->materials[nummaterials].shininess);
      /* wavefront shininess is from [0, 1000], so scale for OpenGL */
      model->materials[nummaterials].shininess /= 1000.0;
      model->materials[nummaterials].shininess *= 128.0;
      break;
    case 'K':
      switch(buf[1]) {
      case 'd':
	fscanf(file, "%f %f %f",
	       &model->materials[nummaterials].diffuse[0],
	       &model->materials[nummaterials].diffuse[1],
	       &model->materials[nummaterials].diffuse[2]);
	break;
      case 's':
	fscanf(file, "%f %f %f",
	       &model->materials[nummaterials].specular[0],
	       &model->materials[nummaterials].specular[1],
	       &model->materials[nummaterials].specular[2]);
	break;
      case 'a':
	fscanf(file, "%f %f %f",
	       &model->materials[nummaterials].ambient[0],
	       &model->materials[nummaterials].ambient[1],
	       &model->materials[nummaterials].ambient[2]);
	break;
      default:
	/* eat up rest of line */
	fgets(buf, sizeof(buf), file);
	break;
      }
      break;
    default:
      /* eat up rest of line */
      fgets(buf, sizeof(buf), file);
      break;
    }
  }
}

/* glmFirstPass: first pass at a Wavefront OBJ file that gets all the
 * statistics of the model (such as #vertices, #normals, etc)
 *
 * model - properly initialized GLMmodel structure
 * file  - (fopen'd) file descriptor 
 */
static GLvoid glmFirstPass(GLMmodel* model, FILE* file) 
{
  GLuint    numvertices;		/* number of vertices in model */
  GLuint    numnormals;			/* number of normals in model */
  GLuint    numtexcoords;		/* number of texcoords in model */
  GLuint    numtriangles;		/* number of triangles in model */
  GLMgroup* group;			/* current group */
  unsigned  v, n, t;
  char      buf[128];

  /* make a default group */
  group = glmAddGroup(model, "default");

  numvertices = numnormals = numtexcoords = numtriangles = 0;
  while(fscanf(file, "%s", buf) != EOF) {
    switch(buf[0]) {
    case '#':				/* comment */
      /* eat up rest of line */
      fgets(buf, sizeof(buf), file);
      break;
    case 'v':				/* v, vn, vt */
      switch(buf[1]) {
      case '\0':			/* vertex */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人精品免费在线| 中文文精品字幕一区二区| 国产校园另类小说区| 亚洲成人综合网站| 99re热这里只有精品免费视频| 91精品久久久久久久91蜜桃| 亚洲欧美日韩中文播放| 国产精品一卡二卡| 欧美一区二区视频在线观看2022| 亚洲乱码国产乱码精品精98午夜| 国产酒店精品激情| 欧美日韩午夜精品| 久久国产成人午夜av影院| 91丨porny丨户外露出| av激情成人网| 欧美体内she精高潮| 亚洲国产激情av| 精品一区二区在线观看| 欧美视频一二三区| 综合久久久久久久| 国产69精品一区二区亚洲孕妇| 日韩精品一区二区三区在线观看 | 成人免费高清在线| 欧美成人激情免费网| 亚洲国产aⅴ成人精品无吗| 99精品一区二区三区| 国产片一区二区| 国产一区二区在线影院| 日韩欧美一区电影| 日本 国产 欧美色综合| 337p亚洲精品色噜噜| 婷婷中文字幕综合| 欧美日韩美少妇| 亚洲一本大道在线| 欧美视频在线一区| 亚洲成av人片在线| 欧美日本韩国一区二区三区视频| 亚洲精品国产精华液| 色综合欧美在线视频区| 欧美一级欧美一级在线播放| 亚洲精品视频免费看| 五月婷婷久久丁香| 欧美影院一区二区三区| 亚洲精品亚洲人成人网| 91亚洲男人天堂| 亚洲日本免费电影| 色丁香久综合在线久综合在线观看| 中文字幕亚洲精品在线观看| 91免费视频观看| 亚洲激情中文1区| 欧美私模裸体表演在线观看| 亚洲影院免费观看| 欧美日韩电影在线播放| 日韩av网站在线观看| 日韩欧美卡一卡二| 国产精品亚洲一区二区三区妖精| 国产午夜久久久久| 99久久婷婷国产综合精品| 亚洲久草在线视频| 4438亚洲最大| 国产又黄又大久久| 亚洲欧洲无码一区二区三区| 在线亚洲高清视频| 日本视频一区二区| 久久青草欧美一区二区三区| 成人黄色综合网站| 亚洲日本一区二区三区| 在线观看亚洲成人| 美女国产一区二区| 欧美国产精品久久| 在线观看视频一区二区欧美日韩| 色噜噜狠狠成人中文综合| 不卡一卡二卡三乱码免费网站| 欧美久久久久久久久久| 久久aⅴ国产欧美74aaa| 国产欧美精品一区| 91成人看片片| 六月丁香综合在线视频| 日本一区二区三区视频视频| 91国偷自产一区二区开放时间| 视频一区视频二区中文字幕| 久久综合久色欧美综合狠狠| 99精品国产一区二区三区不卡| 亚洲gay无套男同| 精品国产91洋老外米糕| 99视频精品免费视频| 午夜久久久影院| 久久人人97超碰com| 欧美在线一二三| 久久综合综合久久综合| 亚洲欧洲在线观看av| 欧美日韩国产123区| 高清在线成人网| 午夜欧美电影在线观看| 中文字幕免费不卡| 欧美日韩中文一区| 国产成人aaa| 亚洲二区在线观看| 国产欧美日韩卡一| 91精品欧美久久久久久动漫| 成人午夜精品一区二区三区| 亚洲国产日韩综合久久精品| 久久久精品天堂| 欧美色视频在线| 成人性生交大片免费看中文 | 欧美高清视频在线高清观看mv色露露十八 | 亚洲综合自拍偷拍| 久久综合五月天婷婷伊人| 在线观看三级视频欧美| 国产激情一区二区三区| 午夜不卡在线视频| 中文字幕在线一区| 日韩精品一区在线| 欧美三级午夜理伦三级中视频| 国产美女精品一区二区三区| 午夜精品久久久久久不卡8050| 中文字幕一区二区三区不卡在线 | 亚洲精品在线免费播放| 欧洲一区在线电影| 不卡的电影网站| 国产在线精品一区二区| 天堂在线一区二区| 亚洲精品免费在线观看| 中文字幕乱码久久午夜不卡| 欧美成人精品3d动漫h| 欧美日韩久久久| 91免费小视频| av不卡免费电影| 国产精品1区2区3区| 日本aⅴ免费视频一区二区三区 | 欧美国产精品一区| 精品欧美黑人一区二区三区| 欧美男同性恋视频网站| 欧美探花视频资源| 在线视频综合导航| 91麻豆123| www.日韩在线| 国产成人综合在线播放| 精品亚洲成av人在线观看| 日本aⅴ亚洲精品中文乱码| 亚洲不卡一区二区三区| 夜夜嗨av一区二区三区网页| 国产精品久久久久久久久动漫| 久久人人爽爽爽人久久久| 日韩欧美国产一区二区在线播放| 8v天堂国产在线一区二区| 在线观看区一区二| 欧美亚洲综合在线| 欧美写真视频网站| 欧美视频中文字幕| 欧美少妇一区二区| 在线观看日韩国产| 欧美日韩国产影片| 欧美日韩精品系列| 欧美日韩一二三区| 欧美精品1区2区3区| 5858s免费视频成人| 欧美电影影音先锋| 91精品国产乱| 欧美成人精品二区三区99精品| 日韩亚洲欧美中文三级| 欧美精品在线一区二区| 欧美一级夜夜爽| 日韩欧美自拍偷拍| 精品久久久久久亚洲综合网| 2023国产一二三区日本精品2022| 久久天天做天天爱综合色| 久久午夜老司机| 国产精品萝li| 亚洲欧美日韩综合aⅴ视频| 亚洲一区二区av在线| 亚洲成a人v欧美综合天堂| 美国一区二区三区在线播放| 韩日av一区二区| 国产成人自拍网| 91在线精品秘密一区二区| 91丨porny丨蝌蚪视频| 欧美性xxxxx极品少妇| 日韩一区国产二区欧美三区| 精品少妇一区二区三区视频免付费| 久久色成人在线| ㊣最新国产の精品bt伙计久久| 亚洲乱码国产乱码精品精小说| 午夜久久福利影院| 精品午夜久久福利影院| 国产a区久久久| va亚洲va日韩不卡在线观看| 欧美午夜精品理论片a级按摩| 欧美一区二区三级| 欧美国产日韩一二三区| 亚洲一区二区免费视频| 久久精品理论片| 99视频在线观看一区三区| 欧美日韩综合一区| 久久久欧美精品sm网站| 国产精品久久久久7777按摩| 亚洲国产精品久久人人爱| 玖玖九九国产精品| 色综合欧美在线| 欧美tickling挠脚心丨vk|