当前位置: 首页>>代码示例>>C++>>正文


C++ StaticObject::getVertexDataPtr方法代码示例

本文整理汇总了C++中StaticObject::getVertexDataPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticObject::getVertexDataPtr方法的具体用法?C++ StaticObject::getVertexDataPtr怎么用?C++ StaticObject::getVertexDataPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StaticObject的用法示例。


在下文中一共展示了StaticObject::getVertexDataPtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: load


//.........这里部分代码省略.........
  for (uint32_t i = 0; i < soh.num_meshes; ++i) {
    if (fread(&som, sizeof(SearObjectMesh), 1, fp) != 1) {
      fprintf(stderr, "[SearObject] Error reading SearObject Mesh in %s\n", filename.c_str());
      fclose(fp);
      return 1;
    }

    if (big_endian) {
      swap_bytes_uint32_t(som.num_vertices);
      swap_bytes_uint32_t(som.num_faces);
      for (x = 0; x < 4; ++x) {
        for (y = 0; y < 4; ++y) {
          swap_bytes_float(som.mesh_transform[x][y]);
          swap_bytes_float(som.texture_transform[x][y]);
        }
      }

      for (x = 0; x < 4; ++x) {
        swap_bytes_float(som.ambient[x]);
        swap_bytes_float(som.diffuse[x]);
        swap_bytes_float(som.specular[x]);
        swap_bytes_float(som.emissive[x]);
      }
      swap_bytes_float(som.shininess);
    }

    StaticObject* so = new StaticObject();
    so->init();
   
    so->setNumPoints(som.num_vertices);
    so->setNumFaces(som.num_faces);

    // Does this use all 256 chars, or only up to 256?
    som.texture_map[255] = '\0'; // Make sure the string is null-terminated
    std::string tex_name(som.texture_map);

    // See if config file has a mapping
    m_config.clean(tex_name);
    if (m_config.findItem(tex_name, KEY_texture_map_0)) {
      tex_name = (std::string)m_config.getItem(tex_name, KEY_texture_map_0);
    }

    // Get texture ids
    tex_id =  RenderSystem::getInstance().requestTexture(tex_name);
    tex_mask_id =  RenderSystem::getInstance().requestTexture(tex_name, true);
    so->setTexture(0, tex_id, tex_mask_id);   

    // Set transform matrices
    so->getMatrix().setMatrix(som.mesh_transform);
    so->getTexMatrix().setMatrix(som.texture_transform);

    // Set Materials
    so->setAmbient(som.ambient);
    so->setDiffuse(som.diffuse);
    so->setSpecular(som.specular);
    so->setEmission(som.emissive);
    so->setShininess(som.shininess);

    // Read in the vertex data array 
    so->createVertexData(som.num_vertices * 3);
    fread(so->getVertexDataPtr(), sizeof(float), som.num_vertices * 3, fp);
    if (big_endian) {
      fptr = so->getVertexDataPtr();
      c = som.num_vertices * 3;
      while (c--) swap_bytes_float(*fptr++);
    }

    so->createNormalData(som.num_vertices * 3);
    fread(so->getNormalDataPtr(), sizeof(float), som.num_vertices * 3, fp);
    if (big_endian) {
      fptr = so->getNormalDataPtr();
      c = som.num_vertices * 3;
      while (c--) swap_bytes_float(*fptr++);
    }

    so->createTextureData(som.num_vertices * 2);
    fread(so->getTextureDataPtr(), sizeof(float), som.num_vertices * 2, fp);
    if (big_endian) {
      fptr = so->getTextureDataPtr();
      c = som.num_vertices * 2;
      while (c--) swap_bytes_float(*fptr++);
    }

    if (som.num_faces > 0) {
      so->createIndices(som.num_faces * 3);
      fread(so->getIndicesPtr(), sizeof(uint32_t), som.num_faces * 3, fp);
      if (big_endian) {
        uptr = (uint32_t*)so->getIndicesPtr();
        c = som.num_faces * 3;
        while (c--) swap_bytes_uint32_t(*uptr++);
      }
    }

    m_static_objects.push_back(so);
  }  

  fclose(fp);

  return 0;
}
开发者ID:bsmr-worldforge,项目名称:sear,代码行数:101,代码来源:SearObject.cpp

示例2: init


//.........这里部分代码省略.........
        const std::string &str = (std::string)m_config.getItem(name, KEY_ambient);
        sscanf(str.c_str(), "%f;%f;%f;%f", &m[0], &m[1], &m[2], &m[3]);
        so->setAmbient(m); 
      }
      if (m_config.findItem(name, KEY_diffuse)) {
        const std::string &str = (std::string)m_config.getItem(name, KEY_diffuse);
        sscanf(str.c_str(), "%f;%f;%f;%f", &m[0], &m[1], &m[2], &m[3]);
        so->setDiffuse(m); 
      }
      if (m_config.findItem(name, KEY_specular)) {
        const std::string &str = (std::string)m_config.getItem(name, KEY_specular);
        sscanf(str.c_str(), "%f;%f;%f;%f", &m[0], &m[1], &m[2], &m[3]);
        so->setSpecular(m); 
      }
      if (m_config.findItem(name, KEY_emission)) {
        const std::string &str = (std::string)m_config.getItem(name, KEY_emission);
        sscanf(str.c_str(), "%f;%f;%f;%f", &m[0], &m[1], &m[2], &m[3]);
        so->setEmission(m); 
      }
      if (m_config.findItem(name, KEY_shininess)) {
        so->setShininess((double)m_config.getItem(name, KEY_shininess));
      }
      
    }
    // Set the transform
    so->getMatrix().setMatrix(matrix);
    // Set the textures
    so->setTexture(0, texture_id, texture_mask_id);
    so->setNumPoints(meshp->mesh_header->vertex_count);
    so->setNumFaces(meshp->mesh_header->triangle_count);

    // Copy data into array.
    so->createVertexData(meshp->mesh_header->vertex_count * 3);
    float *ptr = so->getVertexDataPtr();
    for (int i = 0; i < meshp->mesh_header->vertex_count * 3; ++i) {
      ptr[i] = default_scale * (float)meshp->vertices[i];
    }  
 
    so->copyTextureData(meshp->texcoords, meshp->mesh_header->vertex_count * 2);
    so->copyNormalData(meshp->normals, meshp->mesh_header->vertex_count * 3);

    so->copyIndices(meshp->triangles, meshp->mesh_header->triangle_count * 3);

    m_static_objects.push_back(so);
  }

  libmd3_file_free(modelFile);


  bool ignore_minus_z = false;

  Scaling scale = SCALE_NONE;
  Alignment align = ALIGN_NONE;
  bool process_model = false;

  if (m_config.findItem(SECTION_model, KEY_ignore_minus_z)) {
    if ((bool)m_config.getItem(SECTION_model, KEY_ignore_minus_z)) {
      process_model = true;
      ignore_minus_z = true;
    }
  }
  if (m_config.findItem(SECTION_model, KEY_z_align)) {
    if ((bool)m_config.getItem(SECTION_model, KEY_z_align)) {
      process_model = true;
      align = ALIGN_Z;
    }
开发者ID:bsmr-worldforge,项目名称:sear,代码行数:67,代码来源:LibModelFile.cpp


注:本文中的StaticObject::getVertexDataPtr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。