placeObjectOnPlanet (not complete)
This commit is contained in:
parent
f52d3aa18d
commit
6718cd7e5e
@ -72,13 +72,13 @@ void Core::RenderContext::initFromAssimpMesh2(aiMesh* mesh) {
|
|||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
//glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
|
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, mesh->mTangents);
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
// glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
||||||
@ -138,7 +138,6 @@ void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
|||||||
|
|
||||||
glGenBuffers(1, &vertexBuffer);
|
glGenBuffers(1, &vertexBuffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
//std::cout << vertexBuffer;
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
@ -149,13 +148,13 @@ void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
|||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
||||||
|
|
||||||
// glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
||||||
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
|
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, mesh->mTangents);
|
||||||
|
|
||||||
//glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
||||||
|
@ -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