fork(2) download
  1. //Mesh.h
  2. #include <string>
  3.  
  4. #include "glut\include\GL\glew.h"
  5. #include "glut\include\GL\glut.h"
  6.  
  7. #include <assimp/Importer.hpp> // C++ importer interface
  8. #include <assimp/scene.h> // Output data structure
  9. #include <assimp/postprocess.h> // Post processing fla
  10.  
  11. //#include "glm\glm.hpp"
  12.  
  13. //textures
  14. #include <SOIL.h>
  15.  
  16. class Mesh
  17. {
  18. public:
  19. //struct Bone
  20. //{
  21. //char *name;
  22. //glm::mat4 inverse_bone_matrix;
  23. //};
  24.  
  25. Mesh(void);
  26. Mesh(std::string filename, std::string textureFilename, float x, float y, float z, float width, float height, float depth, float rotX, float rotY, float rotZ);
  27. ~Mesh(void);
  28.  
  29. void Init(std::string filename);
  30. void LoadTexture(std::string textureName);
  31. void Draw();
  32.  
  33. private:
  34. GLfloat *vertexArray;
  35. GLfloat *normalArray;
  36. GLfloat *uvArray;
  37.  
  38. //Bone *boneArray;
  39.  
  40. GLint numVerts;
  41.  
  42. GLuint m_Texture[1];
  43.  
  44. float m_CenterX, m_CenterY, m_CenterZ, m_Width, m_Height, m_Depth;
  45. float m_XRotation, m_YRotation, m_ZRotation;
  46. };
  47.  
  48. //Mesh.cpp
  49. #include "Mesh.h"
  50.  
  51. Mesh::Mesh(void)
  52. {
  53. }
  54.  
  55. Mesh::Mesh(std::string filename, std::string textureFilename, float x, float y, float z, float width, float height, float depth, float rotX, float rotY, float rotZ)
  56. {
  57. //fills in variables
  58. Init(filename);
  59. LoadTexture(textureFilename);
  60. }
  61.  
  62. Mesh::~Mesh(void)
  63. {
  64.  
  65. }
  66.  
  67. void Mesh::Init(std::string filename)
  68. {
  69. Assimp::Importer importer;
  70. const aiScene *scene = importer.ReadFile(filename,aiProcessPreset_TargetRealtime_Fast);//aiProcessPreset_TargetRealtime_Fast has the configs you'll need
  71.  
  72. aiMesh *mesh = scene->mMeshes[0]; //assuming you only want the first mesh
  73.  
  74. numVerts = mesh->mNumFaces*3;
  75.  
  76. vertexArray = new float[mesh->mNumFaces*3*3];
  77. normalArray = new float[mesh->mNumFaces*3*3];
  78. uvArray = new float[mesh->mNumFaces*3*2];
  79. //boneArray = new Bone[mesh->mNumBones*3*4];
  80.  
  81. for(unsigned int i=0;i<mesh->mNumFaces;i++)
  82. {
  83. const aiFace& face = mesh->mFaces[i];
  84.  
  85. for(int j=0;j<3;j++)
  86. {
  87. aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
  88. memcpy(uvArray,&uv,sizeof(float)*2);
  89. uvArray+=2;
  90.  
  91. aiVector3D normal = mesh->mNormals[face.mIndices[j]];
  92. memcpy(normalArray,&normal,sizeof(float)*3);
  93. normalArray+=3;
  94.  
  95. aiVector3D pos = mesh->mVertices[face.mIndices[j]];
  96. memcpy(vertexArray,&pos,sizeof(float)*3);
  97. vertexArray+=3;
  98. }
  99. }
  100.  
  101. //for (unsigned int boneindex = 0; boneindex < mesh->mNumBones; boneindex++)
  102. //{
  103. // Bone b;
  104. // b.name = mesh->mBones[boneindex]->mName;
  105. // for (int weightindex = 0; weightindex < mesh->mBones[boneindex]->mNumWeights; weightindex++)
  106. // {
  107. // glm::mat4 temp = toMat4(&mesh->mBones[boneindex]->mOffsetMatrix);
  108. // memcpy(boneArray, &b, sizeof(Bone) * 4);
  109. // boneArray += 4;
  110. // }
  111. //}
  112.  
  113.  
  114. uvArray-=mesh->mNumFaces*3*2;
  115. normalArray-=mesh->mNumFaces*3*3;
  116. vertexArray-=mesh->mNumFaces*3*3;
  117. //boneArray -= mesh->mNumFaces*3*4;
  118. }
  119.  
  120. void Mesh::LoadTexture(std::string textureName)
  121. {
  122.  
  123. }
  124.  
  125. void Mesh::Draw()
  126. {
  127. glPushMatrix();
  128. glTranslatef(m_CenterX, m_CenterY, m_CenterZ);
  129.  
  130. glRotatef(m_XRotation, 1, 0, 0);
  131. glRotatef(m_YRotation, 0, 1, 0);
  132. glRotatef(m_ZRotation, 0, 0, 1);
  133.  
  134. glScalef(m_Width, m_Height, m_Depth);
  135.  
  136. glEnableClientState(GL_NORMAL_ARRAY);
  137. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  138. glEnableClientState(GL_VERTEX_ARRAY);
  139.  
  140. glNormalPointer(GL_FLOAT,0,normalArray);
  141. glTexCoordPointer(2,GL_FLOAT,0,uvArray);
  142. glVertexPointer(3,GL_FLOAT,0,vertexArray);
  143.  
  144. glActiveTexture(GL_TEXTURE0);
  145. glBindTexture(GL_TEXTURE_2D, m_Texture[0]);
  146. glDrawArrays(GL_TRIANGLES,0,numVerts);
  147.  
  148. glDisableClientState(GL_NORMAL_ARRAY);
  149. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  150. glDisableClientState(GL_VERTEX_ARRAY);
  151. glPopMatrix();
  152. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:38: fatal error: glut\include\GL\glew.h: No such file or directory
     #include "glut\include\GL\glew.h"
                                      ^
compilation terminated.
stdout
Standard output is empty