示例#1
0
bool Model::LoadModel(char* obj_file, char* color_file)
{
	model = glmReadOBJ(obj_file);
	if(!model)
		return false;

	//normal
	if( ! model->normals )
	{
		glmFacetNormals(model);
		glmVertexNormals(model, 90.0);

		assert(model->numnormals == model->numvertices);
	}

	//bbox
	bbox = new BBox();
	float dim[3];
	float center[3];
	glmDimensions(model, dim);
	glmCenter(model, center);
	for(int i = 0; i < 3; i++)
	{
		bbox->min[i] = center[i] - dim[i] / 2.0;
		bbox->max[i] = center[i] + dim[i] / 2.0;
	}

	//color
	return readColor(color_file);
}
示例#2
0
Viewer* create_viewer(Placeable *object)
{
    Viewer *v = malloc(sizeof(Viewer));
	if (object) {
		v->pos[0] = object->pos[0];
		v->pos[1] = object->pos[1];
		v->pos[2] = object->pos[2];
        observe_object(v, object);
	}
	else {
		v->pos[0] = 0;
		v->pos[1] = 0.1;
		v->pos[2] = 1;
		v->lookat[0] = 0;
		v->lookat[1] = 0;
		v->lookat[2] = 0;
	}
	
    v->model = (GLMmodel*) malloc(sizeof(GLMmodel));
	v->model = glmReadOBJ("objs/girl/girl.obj");

    // dimensions
    GLfloat dimensions[3];
    glmDimensions(v->model, dimensions);
    v->height = dimensions[1];
    v->width = dimensions[0];
    v->depth = dimensions[2];

    // look at 90% of the height of the model from its center.
    v->eye_at[0] = 0.5; // w
    v->eye_at[1] = 0.9; // h

	return v;
}
// ----------------------------------------------- //
void init_model() {
    model = glmReadOBJ("../data/al.obj");
    if (!model) exit(0);
    glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, 90.0);
    glmDimensions(model, model_dimensions);
}
mdlDimensions cModelLoader::getModelDimensions()
{
	mdlDimensions mdl_Dims;
	GLfloat mdlDims[3];
	glmDimensions(m_model, mdlDims);
	mdl_Dims.s_mdlWidth = mdlDims[0];
	mdl_Dims.s_mdlheight = mdlDims[1];
	mdl_Dims.s_mdldepth = mdlDims[2];
	return mdl_Dims;
}
示例#5
0
mdlDimensions cModelLoader::getModelDimensions()
{
	//Set the dimentions of the model (width, height, depth)
	mdlDimensions mdl_Dims;
	GLfloat mdlDims[3];
	glmDimensions(m_model, mdlDims);
	mdl_Dims.s_mdlWidth = mdlDims[0];
	mdl_Dims.s_mdlheight = mdlDims[1];
	mdl_Dims.s_mdldepth = mdlDims[2];
	return mdl_Dims;
}
示例#6
0
/* 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)
{
  GLMgroup *group;
  GLfloat dimensions[3];
  GLfloat x, y, scalefactor;
  GLuint i;
  
  assert(model);

  if (model->texcoords)
    free(model->texcoords);
  model->numtexcoords = model->numvertices;
  model->texcoords=(GLfloat*)malloc(sizeof(GLfloat)*2*(model->numtexcoords+1));
  
  glmDimensions(model, dimensions);
  scalefactor = 2.0 / 
    _glmAbs(_glmMax(_glmMax(dimensions[0], dimensions[1]), dimensions[2]));

  /* do the calculations */
  for(i = 1; i <= model->numvertices; i++) {
    x = model->vertices[3 * i + 0] * scalefactor;
    y = model->vertices[3 * i + 2] * scalefactor;
    model->texcoords[2 * i + 0] = (x + 1.0) / 2.0;
    model->texcoords[2 * i + 1] = (y + 1.0) / 2.0;
  }
  
  /* go through and put texture coordinate indices in all the triangles */
  group = model->groups;
  while(group) {
    for(i = 0; i < group->numtriangles; i++) {
      T(group->triangles[i]).tindices[0] = T(group->triangles[i]).vindices[0];
      T(group->triangles[i]).tindices[1] = T(group->triangles[i]).vindices[1];
      T(group->triangles[i]).tindices[2] = T(group->triangles[i]).vindices[2];
    }    
    group = group->next;
  }

#if 0
  printf("glmLinearTexture(): generated %d linear texture coordinates\n",
	  model->numtexcoords);
#endif
}
示例#7
0
文件: main.cpp 项目: sekouzed/echec3D
void init(void) {
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);

    /* load up the model */

    pmodel = glmReadOBJ(FICHIER_OBJ);
    glmUnitize(pmodel);	//glmVertexNormals(obj, 90.0, GL_TRUE);

    glmScale(pmodel,1.6);

    GLfloat dimensions[3];
    glmDimensions(pmodel,  dimensions);
    pmodel->position[2]=dimensions[1]/2;


    for(int i=0; i<8; i++) {
        place[i+1]=place[i+1]*(echelle/8);
    }

    int n=0,m=0;
    for(int id=0; id<64; id++) {
        lesCases[id+1].id=id+1;
        lesCases[id+1].idPion=-1;

        if((id)%8==0) {
            n+=1;
            m=1;
            // printf("\n");
        }
        lesCases[id+1].nl=n;
        lesCases[id+1].nc=m++;
        // printf("%d(%d,%d) pion=%d\n",lesCases[id+1].id,lesCases[id+1].nl,lesCases[id+1].nc,lesCases[id+1].idPion);


        // int j= lesCases[id+1].nc;  int k=lesCases[id+1].nl;

    }
    // printf("\n");

    GLMmaterial* mm=pmodel->materials ;
    group = pmodel->groups;
    int k=1;
    while(group) {
        group->position[0]=0.0;
        group->position[1]=0.0;
        for(int i=0; i<32; i++)  {
            if(strstr(group->name,lesNoms[i])) {
                if(i<16) {
                    k=1;
                    lesPions[i].camp=2;
                }
                else {
                    k=33;
                    lesPions[i].camp=1;
                }
                strcpy(lesPions[i].nom,lesNoms[i]);
                lesPions[i].nombrePosibilite=0;
                lesPions[i].ix=place[lesCases[i+k].nc];
                lesPions[i].iy=place[lesCases[i+k].nl];
                lesCases[i+k].idPion=i;
                lesPions[i].idCase=i+k;
                //printf("--group %s : %d(%d,%d)\n",group->name,lesCases[i+k].id,lesCases[i+k].nl,lesCases[i+k].nc);
            }
        }
        group = group->next;
    }



}
示例#8
0
/*
LoadModel: Loads .obj model files

char *filename = takes in the location of the obj, if there is only one frame of the model
put the entire filename including the .obj. If there are more than one frames just type in 
the base name minus the '_' and the number. For example for "models/dorumon_textured_000001.obj"
just put in "models/dorumon_textured"

char *texturefile = the path to the texture image

int texw, int texh = the width and hieght of the texure image

int numFrames = The number of frames starting from 0, so if your model has only one frame, just put 0;

int center = 1, If the model should be centered 2 if both the model and texture should be centered

*/
Model *LoadModel(char *filename, int numFrames,int center)
{

  int i,r;
  char temp[50];

  /*first search to see if the requested model is already loaded*/
  for(i = 0; i < MaxModels; i++)
  {
    if(strncmp(filename,ModelList[i].filename,50)==0)
    {
      ModelList[i].used++;
      return &ModelList[i];
    }
  }
  /*makesure we have the room for a new model*/
  if(NumModels + 1 >= MaxModels)
  {
    fprintf(stderr, "Maximum Models Reached.\n");
    exit(1);
  }
  /*if its not already in memory, then load it.*/
  NumModels++;
  for(i = 0;i <= MaxModels;i++)
  {
    if(!ModelList[i].used)break;
  }
  strncpy(ModelList[i].filename,filename,50);

  ModelList[i].used++;
  ModelList[i].numFrames = numFrames + 1;
  if(numFrames==0){
    ModelList[i].object[0] =glmReadOBJ(filename);
    if(ModelList[i].object[0] == NULL)
    {
      fprintf(stderr,"unable to load obj file!");
      return NULL;
    }
    glmDimensions(ModelList[i].object[0],ModelList[i].dimensions);
    if(center)centerModel(ModelList[i].object[0]);
    ModelList[i].center[0]=ModelList[i].dimensions[0]/2.0f;
    ModelList[i].center[1]=ModelList[i].dimensions[1]/2.0f;
    ModelList[i].center[2]=ModelList[i].dimensions[2]/2.0f;
  }else
  {
    for(r=0; r < ModelList[i].numFrames;r++)
    {
      sprintf(temp,"%s_%06i.obj",filename,r+1);
      ModelList[i].object[r] =glmReadOBJ(temp);
      if(ModelList[i].object[r] == NULL)
      {
        fprintf(stderr,"unable to load obj file!");
        return NULL;
      }
      glmDimensions(ModelList[i].object[r],ModelList[i].dimensions);
      if(center)centerModel(ModelList[i].object[r]);
      ModelList[i].center[0]=ModelList[i].dimensions[0]/2.0f;
      ModelList[i].center[1]=ModelList[i].dimensions[1]/2.0f;
      ModelList[i].center[2]=ModelList[i].dimensions[2]/2.0f;
    }
  }
  if(numFrames!=0)
  {
    ModelList[i].temp =glmReadOBJ(temp);
    glmDimensions(ModelList[i].temp,ModelList[i].dimensions);
    if(center)centerModel(ModelList[i].temp);
    ModelList[i].center[0]=ModelList[i].dimensions[0]/2.0f;
    ModelList[i].center[1]=ModelList[i].dimensions[1]/2.0f;
    ModelList[i].center[2]=ModelList[i].dimensions[2]/2.0f;
  }
  return &ModelList[i];

}