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


C++ Mesh::CalculateNormals方法代码示例

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


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

示例1: SetMeshes

void SetMeshes()
{
	Cube cube;
	cube.CalculateNormals();
	cube.CalculateTangents();
	cube.CalculateBitangents();
	cube.Build(XYZ_UV_TBN);
	cube.position = Vector3(-10, 20, 0);

	cubie = RenderableObject(cube, Diffuse, mtlBrickD);
	scene.AddObject(&cubie);

	Sphere sphere(1, 24, 16);
	sphere.CalculateNormals();
	sphere.CalculateTangents();
	sphere.CalculateBitangents();
	sphere.Build(XYZ_UV_TBN);
	sphere.position = Vector3(-14, 20, 0);

	sphereRO = RenderableObject(sphere, BumpPOMSpecular, mtlBrickPOM);
	scene.AddObject(&sphereRO);

	/*Sphere sphere(1, 24, 16);
	sphere.CalculateNormals();
	sphere.Build(XYZ_N);
	sphere.position = Vector3(4, 0, 0);

	sphereRO = RenderableObject(sphere, CubeEM, mtlCubeMap);
	scene.AddObject(&sphereRO);*/
	
	Mesh teapot;
	teapot.LoadDataFromFile("./Models/teapot.obj", OBJ);
	teapot.CalculateUVs(SphereUV);
	teapot.CalculateNormals();
	teapot.Build(XYZ_N);
	teapot.scale = Vector3(0.01f, 0.01f, 0.01f);
	teapot.position = Vector3(-18, 20, 0);

	teapotRO = RenderableObject(teapot, CubeEM, mtlCubeMap);
	scene.AddObject(&teapotRO);
}
开发者ID:SinYocto,项目名称:Siny,代码行数:41,代码来源:SinyMain.cpp

示例2: LoadFile

// Load a file to the mesh
void GLViewer::LoadFile(const char * aFileName, const char * aOverrideTexture)
{
  // Get the file size
  ifstream f(aFileName, ios::in | ios::binary);
  if(f.fail())
    throw runtime_error("Unable to open the file.");
  f.seekg(0, ios_base::end);
  long tmpFileSize = (long) f.tellg();
  f.close();

  // Load the mesh
  cout << "Loading " << aFileName << "..." << flush;
  mTimer.Push();
  Mesh * newMesh = new Mesh();
  try
  {
    ImportMesh(aFileName, newMesh);
  }
  catch(exception &e)
  {
    delete newMesh;
    throw;
  }
  if(mMesh)
    delete mMesh;
  mMesh = newMesh;
  cout << "done (" << int(mTimer.PopDelta() * 1000.0 + 0.5) << " ms)" << endl;

  // Get the file name (excluding the path), and the path (excluding the file name)
  mFileName = ExtractFileName(string(aFileName));
  mFilePath = ExtractFilePath(string(aFileName));

  // The temporary file size is now the official file size...
  mFileSize = tmpFileSize;

  // Set window title
  string windowCaption = string("OpenCTM viewer - ") + mFileName;
  glutSetWindowTitle(windowCaption.c_str());

  // If the file did not contain any normals, calculate them now...
  if(mMesh->mNormals.size() != mMesh->mVertices.size())
  {
    cout << "Calculating normals..." << flush;
    mTimer.Push();
    mMesh->CalculateNormals();
    cout << "done (" << int(mTimer.PopDelta() * 1000.0 + 0.5) << " ms)" << endl;
  }

  // Load the texture
  if(mTexHandle)
    glDeleteTextures(1, &mTexHandle);
  mTexHandle = 0;
  if(mMesh->mTexCoords.size() == mMesh->mVertices.size())
  {
    string texFileName = mMesh->mTexFileName;
    if(aOverrideTexture)
      texFileName = string(aOverrideTexture);
    if(texFileName.size() > 0)
      InitTexture(texFileName.c_str());
    else
      InitTexture(0);
  }

  // Setup texture parameters for the shader
  if(mUseShader)
  {
    glUseProgram(mShaderProgram);

    // Set the uUseTexture uniform
    GLint useTexLoc = glGetUniformLocation(mShaderProgram, "uUseTexture");
    if(useTexLoc >= 0)
      glUniform1i(useTexLoc, glIsTexture(mTexHandle));

    // Set the uTex uniform
    GLint texLoc = glGetUniformLocation(mShaderProgram, "uTex");
    if(texLoc >= 0)
      glUniform1i(texLoc, 0);

    glUseProgram(0);
  }

  // Load the mesh into a displaylist
  if(mDisplayList)
    glDeleteLists(mDisplayList, 1);
  mDisplayList = glGenLists(1);
  glNewList(mDisplayList, GL_COMPILE);
  DrawMesh(mMesh);
  glEndList();

  // Init the camera for the new mesh
  mCameraUp = Vector3(0.0f, 0.0f, 1.0f);
  SetupCamera();
}
开发者ID:mbitsnbites,项目名称:openctm,代码行数:94,代码来源:ctmviewer.cpp

示例3: PreProcessMesh

//-----------------------------------------------------------------------------
// PreProcessMesh()
//-----------------------------------------------------------------------------
static void PreProcessMesh(Mesh &aMesh, Options &aOptions)
{
  // Nothing to do?
  if((aOptions.mScale == 1.0f) && (aOptions.mUpAxis == uaZ) &&
     (!aOptions.mFlipTriangles) && (!aOptions.mCalcNormals))
    return;

  // Create 3x3 transformation matrices for the vertices and the normals
  Vector3 vX, vY, vZ;
  Vector3 nX, nY, nZ;
  switch(aOptions.mUpAxis)
  {
    case uaX:
      nX = Vector3(0.0f, 0.0f, 1.0f);
      nY = Vector3(0.0f, 1.0f, 0.0f);
      nZ = Vector3(-1.0f, 0.0f, 0.0f);
      break;
    case uaY:
      nX = Vector3(1.0f, 0.0f, 0.0f);
      nY = Vector3(0.0f, 0.0f, 1.0f);
      nZ = Vector3(0.0f, -1.0f, 0.0f);
      break;
    case uaZ:
      nX = Vector3(1.0f, 0.0f, 0.0f);
      nY = Vector3(0.0f, 1.0f, 0.0f);
      nZ = Vector3(0.0f, 0.0f, 1.0f);
      break;
    case uaNX:
      nX = Vector3(0.0f, 0.0f, -1.0f);
      nY = Vector3(0.0f, 1.0f, 0.0f);
      nZ = Vector3(1.0f, 0.0f, 0.0f);
      break;
    case uaNY:
      nX = Vector3(1.0f, 0.0f, 0.0f);
      nY = Vector3(0.0f, 0.0f, -1.0f);
      nZ = Vector3(0.0f, 1.0f, 0.0f);
      break;
    case uaNZ:
      nX = Vector3(-1.0f, 0.0f, 0.0f);
      nY = Vector3(0.0f, 1.0f, 0.0f);
      nZ = Vector3(0.0f, 0.0f, -1.0f);
      break;
  }
  vX = nX * aOptions.mScale;
  vY = nY * aOptions.mScale;
  vZ = nZ * aOptions.mScale;

  cout << "Processing... " << flush;
  SysTimer timer;
  timer.Push();

  // Update all vertex coordinates
  for(CTMuint i = 0; i < aMesh.mVertices.size(); ++ i)
    aMesh.mVertices[i] = vX * aMesh.mVertices[i].x +
                         vY * aMesh.mVertices[i].y +
                         vZ * aMesh.mVertices[i].z;

  // Update all normals
  if(aMesh.HasNormals() && !aOptions.mNoNormals)
  {
    for(CTMuint i = 0; i < aMesh.mNormals.size(); ++ i)
      aMesh.mNormals[i] = nX * aMesh.mNormals[i].x +
                          nY * aMesh.mNormals[i].y +
                          nZ * aMesh.mNormals[i].z;
  }

  // Flip trianlges?
  if(aOptions.mFlipTriangles)
  {
    CTMuint triCount = aMesh.mIndices.size() / 3;
    for(CTMuint i = 0; i < triCount; ++ i)
    {
      CTMuint tmp = aMesh.mIndices[i * 3];
      aMesh.mIndices[i * 3] = aMesh.mIndices[i * 3 + 1];
      aMesh.mIndices[i * 3 + 1] = tmp;
    }
  }

  // Calculate normals?
  if((!aOptions.mNoNormals) && aOptions.mCalcNormals &&
     (!aMesh.HasNormals()))
    aMesh.CalculateNormals();

  double dt = timer.PopDelta();
  cout << 1000.0 * dt << " ms" << endl;
}
开发者ID:151706061,项目名称:OpenCTM,代码行数:89,代码来源:ctmconv.cpp


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