placeObjectOnPlanet (not complete)
This commit is contained in:
parent
f52d3aa18d
commit
6718cd7e5e
@ -55,83 +55,6 @@ void Core::RenderContext::initFromAssimpMesh2(aiMesh* mesh) {
|
|||||||
glBindVertexArray(vertexArray);
|
glBindVertexArray(vertexArray);
|
||||||
|
|
||||||
|
|
||||||
glGenBuffers(1, &vertexIndexBuffer);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glGenBuffers(1, &vertexBuffer);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
|
||||||
//std::cout << vertexBuffer;
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
glEnableVertexAttribArray(3);
|
|
||||||
glEnableVertexAttribArray(4);
|
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
|
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
|
||||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
|
|
||||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
|
|
||||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
|
||||||
vertexArray = 0;
|
|
||||||
vertexBuffer = 0;
|
|
||||||
vertexIndexBuffer = 0;
|
|
||||||
|
|
||||||
std::vector<float> textureCoord;
|
|
||||||
std::vector<unsigned int> indices;
|
|
||||||
//tex coord must be converted to 2d vecs
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
|
||||||
{
|
|
||||||
if (mesh->mTextureCoords[0] != nullptr) {
|
|
||||||
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
|
|
||||||
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "did else ok?"<<std::endl;
|
|
||||||
textureCoord.push_back(0.0f);
|
|
||||||
textureCoord.push_back(0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mesh->mTextureCoords[0] == nullptr) {
|
|
||||||
std::cout << "no uv coords\n";
|
|
||||||
}
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
|
|
||||||
{
|
|
||||||
aiFace face = mesh->mFaces[i];
|
|
||||||
// retrieve all indices of the face and store them in the indices vector
|
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++)
|
|
||||||
indices.push_back(face.mIndices[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
|
||||||
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
|
||||||
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
|
|
||||||
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
|
||||||
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
|
||||||
|
|
||||||
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
|
|
||||||
size = indices.size();
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &vertexArray);
|
|
||||||
glBindVertexArray(vertexArray);
|
|
||||||
|
|
||||||
|
|
||||||
glGenBuffers(1, &vertexIndexBuffer);
|
glGenBuffers(1, &vertexIndexBuffer);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
|
||||||
@ -165,6 +88,82 @@ void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
||||||
|
vertexArray = 0;
|
||||||
|
vertexBuffer = 0;
|
||||||
|
vertexIndexBuffer = 0;
|
||||||
|
|
||||||
|
std::vector<float> textureCoord;
|
||||||
|
std::vector<unsigned int> indices;
|
||||||
|
//tex coord must be converted to 2d vecs
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
||||||
|
{
|
||||||
|
if (mesh->mTextureCoords[0] != nullptr) {
|
||||||
|
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
|
||||||
|
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "did else ok?"<<std::endl;
|
||||||
|
textureCoord.push_back(0.0f);
|
||||||
|
textureCoord.push_back(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mesh->mTextureCoords[0] == nullptr) {
|
||||||
|
std::cout << "no uv coords\n";
|
||||||
|
}
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
|
||||||
|
{
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
|
// retrieve all indices of the face and store them in the indices vector
|
||||||
|
for (unsigned int j = 0; j < face.mNumIndices; j++)
|
||||||
|
indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||||
|
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||||
|
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
|
||||||
|
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||||
|
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||||
|
|
||||||
|
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
|
||||||
|
size = indices.size();
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &vertexArray);
|
||||||
|
glBindVertexArray(vertexArray);
|
||||||
|
|
||||||
|
|
||||||
|
glGenBuffers(1, &vertexIndexBuffer);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glGenBuffers(1, &vertexBuffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glEnableVertexAttribArray(3);
|
||||||
|
glEnableVertexAttribArray(4);
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
||||||
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
|
||||||
|
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
|
||||||
|
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
|
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
|
||||||
{
|
{
|
||||||
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
|
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
|
||||||
|
@ -49,6 +49,8 @@ glm::vec3 spaceshipPos = glm::vec3(-4.f, 0, 0);
|
|||||||
glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
|
glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
|
||||||
GLuint VAO,VBO;
|
GLuint VAO,VBO;
|
||||||
|
|
||||||
|
glm::mat4 planetMatrix = glm::mat4();
|
||||||
|
|
||||||
float aspectRatio = 1.f;
|
float aspectRatio = 1.f;
|
||||||
bool DoTheImportThing(const std::string& pFile) {
|
bool DoTheImportThing(const std::string& pFile) {
|
||||||
// Create an instance of the Importer class
|
// Create an instance of the Importer class
|
||||||
@ -86,7 +88,7 @@ glm::mat4 createPerspectiveMatrix()
|
|||||||
|
|
||||||
glm::mat4 perspectiveMatrix;
|
glm::mat4 perspectiveMatrix;
|
||||||
float n = 0.05;
|
float n = 0.05;
|
||||||
float f = 20.;
|
float f = 100.;
|
||||||
float a1 = glm::min(aspectRatio, 1.f);
|
float a1 = glm::min(aspectRatio, 1.f);
|
||||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
float a2 = glm::min(1 / aspectRatio, 1.f);
|
||||||
perspectiveMatrix = glm::mat4({
|
perspectiveMatrix = glm::mat4({
|
||||||
@ -140,6 +142,26 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
|
|||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
void placeObjectOnPlanet(Core::RenderContext& objectContext, glm::mat4 objectMatrix,glm::vec3 placePoint, Core::RenderContext& planetContext, glm::mat4 planetMatrix) {
|
||||||
|
//placePoint is described by normalized vector that points to a point on a sphere from inside of itself
|
||||||
|
placePoint = glm::normalize(placePoint);
|
||||||
|
|
||||||
|
//float diameter = ?;
|
||||||
|
float diameter = 10;
|
||||||
|
|
||||||
|
objectMatrix = objectMatrix*glm::translate(placePoint * diameter) * glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
|
placePoint,
|
||||||
|
glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
objectMatrix = objectMatrix;
|
||||||
|
//* objectMatrix;
|
||||||
|
//*glm::translate(placePoint)
|
||||||
|
//TEMPORARY DRAW FUNCTION
|
||||||
|
drawObjectBiomes(objectContext, objectMatrix , programBiomes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void renderScene(GLFWwindow* window)
|
void renderScene(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
@ -150,8 +172,22 @@ void renderScene(GLFWwindow* window)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//drawObjectBiomes(sphereContext, glm::mat4(), programBiomes);
|
drawObjectBiomes(sphereContext, glm::mat4(), programBiomes);
|
||||||
drawObjectBiomes(plantContext, glm::mat4(), programBiomes);
|
for (int i = 0; i < 5; i++) {
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1*i, 0.f, 1.f)), sphereContext, planetMatrix);
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 1.f)), sphereContext, planetMatrix);
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix);
|
||||||
|
placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(-0.1 * i, 0.f, 0.f)), sphereContext, planetMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
//placeObjectOnPlanet(plantContext ,glm::scale(glm::mat4(),glm::vec3(0.2)), normalize(glm::vec3(1.f,0.f,1.f)), sphereContext, planetMatrix);
|
||||||
|
//placeObjectOnPlanet(plantContext, glm::scale(glm::mat4(), glm::vec3(0.2)), normalize(glm::vec3(0.f, 0.f, -1.f)), sphereContext, planetMatrix);
|
||||||
|
|
||||||
|
//drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(60.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||||
|
//drawObjectBiomes(plantContext, glm::eulerAngleY(glm::radians(90.f)) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||||
|
//drawObjectBiomes(plantContext, glm::eulerAngleX(30.f) * glm::translate(glm::vec3(0.f, 0.f, 0.f)), programBiomes);
|
||||||
|
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||||
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||||
@ -216,7 +252,7 @@ void init(GLFWwindow* window)
|
|||||||
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
|
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
|
||||||
programBiomes = shaderLoader.CreateProgram("shaders/shader_biomes.vert", "shaders/shader_biomes.frag");
|
programBiomes = shaderLoader.CreateProgram("shaders/shader_biomes.vert", "shaders/shader_biomes.frag");
|
||||||
|
|
||||||
loadModelToContext("./models/plants/polygon.obj", plantContext);
|
loadModelToContext2("./models/plants/polygon.obj", plantContext);
|
||||||
|
|
||||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||||
loadModelToContext("./models/spaceship.obj", shipContext);
|
loadModelToContext("./models/spaceship.obj", shipContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user