Cześć. Ogarnąłem assimpa i wczytałem model. Problem w tym że zamiast być na ustalonej pozycji lata przyczepiony do kamery. Kod źródłowy wygląda tak:
//ładowanie z pliku *.obj
OBJLoader::OBJLoader(std::string wayToFile, Rendering &render)
{
const aiScene *scene = aiImportFile(wayToFile.c_str(), aiProcess_Triangulate);
int totalVerticesCount = 0;
std::vector<GLfloat> bufferVboData;
for (unsigned int i = 0; i != scene->mNumMeshes; ++i)
{
aiMesh *mesh = scene->mMeshes[i];
unsigned int meshVertices = 0;
for (unsigned int j = 0; j != mesh->mNumFaces; ++j)
{
const aiFace *face = &mesh->mFaces[j];
for (short unsigned int k = 0; k < 3; ++k)
{
aiVector3D vertexPositions = aiVector3D(0.0f, 0.0f, 0.0f);
aiVector3D vertexNormals = aiVector3D(0.0f, 0.0f, 0.0f);
aiVector3D vertexTexCoords = aiVector3D(0.0f, 0.0f, 0.0f);
if (mesh->HasPositions())
{
vertexPositions = mesh->mVertices[face->mIndices[k]];
}
if (mesh->HasNormals())
{
vertexNormals = mesh->mNormals[face->mIndices[k]];
}
if (mesh->HasTextureCoords(10))
{
vertexTexCoords = mesh->mTextureCoords[0][face->mIndices[k]];
}
bufferVboData.push_back(vertexPositions.x);
bufferVboData.push_back(vertexPositions.y);
bufferVboData.push_back(vertexPositions.z);
bufferVboData.push_back(vertexNormals.x);
bufferVboData.push_back(vertexNormals.y);
bufferVboData.push_back(vertexNormals.z);
bufferVboData.push_back(vertexTexCoords.x);
bufferVboData.push_back(vertexTexCoords.y);
++meshVertices;
}
}
verticesCount.push_back(meshVertices);
startingVertex.push_back(totalVerticesCount);
totalVerticesCount += meshVertices;
if (scene->mNumMaterials != 0)
{
const aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
aiString texturePath;
GLuint tex = 0;
if (material->GetTexture(aiTextureType_DIFFUSE, 10, &texturePath) == AI_SUCCESS)
{
unsigned int foundPos = wayToFile.find_last_of("/\\");
std::string path = wayToFile.substr(0, foundPos);
std::string name(texturePath.C_Str());
if (name[0] == '/')
{
name.erase(0, 1);
}
std::string filePath = path + "/" + name;
if (render.loadTexture(filePath, tex))
{
std::cout << "Can't load testure: " << filePath << std::endl;
}
}
textures.push_back(tex);
}
}
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, bufferVboData.size() * sizeof(GLfloat), bufferVboData.data(), GL_STATIC_DRAW);
singleVertexSize = 2 * 3 * sizeof(GLfloat) + 2 * sizeof(GLfloat);
}
//rysowanie i inicjalizacja załadowanego pliku
Figures::Figures(OBJLoader &obj)
{
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, obj.singleVertexSize, 0); glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, obj.singleVertexSize, reinterpret_cast<void*>(3 * sizeof(GLfloat))); glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, obj.singleVertexSize, reinterpret_cast<void*>(2 * 3 * sizeof(GLfloat))); glEnableVertexAttribArray(2);
startingVertex = obj.startingVertex;
verticesCount = obj.verticesCount;
textures = obj.textures;
}
void Figures::draw()
{
transform = glm::translate(glm::mat4(1.0f), position);
transformRot = glm::rotate(transform, rotation.x, glm::vec3(1, 0, 0));
transformRot = glm::rotate(transformRot, rotation.y, glm::vec3(0, 1, 0));
transformRot = glm::rotate(transformRot, rotation.z, glm::vec3(0, 0, 1));
transformScale = glm::scale(transformRot, scaling);
glBindVertexArray(vao);
for (int i = 0; i < startingVertex.size(); ++i)
{
glBindTexture(GL_TEXTURE_2D, textures[i]);
glUniform1i(Slots::textureSlot, 10);
glDrawArrays(GL_TRIANGLES, startingVertex[i], verticesCount[i]);
}
}