add: spaceship\add: a few new models and textures

This commit is contained in:
Szymon Szczubkowski 2024-01-27 23:09:04 +01:00
parent 1890648b26
commit a82556f390
33 changed files with 120 additions and 23 deletions

View File

@ -23,7 +23,7 @@ int main(int argc, char** argv)
#endif
// tworzenie okna za pomoca glfw
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(900, 900, "FirstWindow", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
@ -34,7 +34,7 @@ int main(int argc, char** argv)
// ladowanie OpenGL za pomoca glew
glewInit();
glViewport(0, 0, 500, 500);
glViewport(0, 0, 900, 900);
init(window);

View File

@ -18,6 +18,7 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sunContext;
Core::RenderContext planetContext;
Core::RenderContext stationContext;
namespace texture {
@ -27,22 +28,59 @@ namespace texture {
GLuint planet_ao;
GLuint planet_normal;
GLuint planet_roughness;
GLuint planet_metallic;
GLuint mars_albedo;
GLuint mars_normal;
GLuint mars_ao;
GLuint mars_roughness;
GLuint mars_metallic;
GLuint ship_albedo;
GLuint ship_normal;
GLuint ship_ao;
GLuint ship_roughness;
GLuint ship_metallic;
GLuint jupiter_albedo;
GLuint jupiter_normal;
GLuint jupiter_ao;
GLuint jupiter_roughness;
GLuint jupiter_metallic;
GLuint venus_albedo;
GLuint venus_ao;
GLuint venus_normal;
GLuint venus_roughness;
GLuint venus_metallic;
GLuint earth_albedo;
GLuint earth_normal;
GLuint earth_ao;
GLuint earth_roughness;
GLuint earth_metallic;
GLuint moon_albedo;
GLuint moon_normal;
GLuint moon_ao;
GLuint moon_roughness;
GLuint moon_metallic;
GLuint station_albedo;
GLuint station_normal;
GLuint station_ao;
GLuint station_roughness;
GLuint station_metallic;
}
float aspectRatio = 1.f;
glm::vec3 cameraPos = glm::vec3(-4.0f, 0.0f, 0.0f);
glm::vec3 cameraFront = glm::vec3(1.0f, 0.0f, 0.0f);
glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraPos;
glm::vec3 cameraDir;
glm::vec3 spaceshipPos = glm::vec3(-4.0f, 0.0f, 0.0f);
glm::vec3 spaceshipDir = glm::vec3(1.0f, 0.0f, 0.0f);
//declarations of functions
void loadModelToContext(std::string path, Core::RenderContext& context);
@ -54,7 +92,7 @@ glm::mat4 createPerspectiveMatrix();
glm::mat4 createCameraMatrix();
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix);
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint ao, GLuint normal, GLuint roughness);
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint ao, GLuint normal, GLuint roughness, GLuint metallic);
void init(GLFWwindow* window)
{
@ -73,6 +111,8 @@ void init(GLFWwindow* window)
loadModelToContext("./models/sphere.obj", planetContext);
loadModelToContext("./models/station.obj", stationContext);
//load textures here
@ -82,16 +122,43 @@ void init(GLFWwindow* window)
texture::planet_ao = Core::LoadTexture("textures/planet/ao.jpg");
texture::planet_normal = Core::LoadTexture("textures/planet/normal.jpg");
texture::planet_roughness = Core::LoadTexture("textures/planet/roughness.jpg");
texture::planet_metallic = Core::LoadTexture("textures/planet/metallic.png");
texture::mars_albedo = Core::LoadTexture("textures/mars/albedo.jpg");
texture::mars_normal = Core::LoadTexture("textures/mars/normal.png");
texture::mars_ao = Core::LoadTexture("textures/mars/ao.png");
texture::mars_roughness = Core::LoadTexture("textures/mars/roughness.png");
texture::mars_metallic = Core::LoadTexture("textures/mars/metallic.png");
texture::ship_albedo = Core::LoadTexture("textures/ship/albedo.png");
texture::ship_ao = Core::LoadTexture("textures/ship/ao.png");
texture::ship_normal = Core::LoadTexture("textures/ship/normal.png");
texture::ship_roughness = Core::LoadTexture("textures/ship/roughness.png");
texture::ship_metallic = Core::LoadTexture("textures/ship/metallic.jpg");
texture::jupiter_albedo = Core::LoadTexture("textures/jupiter/albedo.png");
texture::jupiter_normal = Core::LoadTexture("textures/jupiter/normal.png");
texture::jupiter_ao = Core::LoadTexture("textures/jupiter/ao.png");
texture::jupiter_roughness = Core::LoadTexture("textures/jupiter/roughness.png");
texture::jupiter_metallic = Core::LoadTexture("textures/jupiter/metallic.png");
texture::earth_albedo = Core::LoadTexture("textures/earth/albedo.png");
texture::earth_normal = Core::LoadTexture("textures/earth/normal.png");
texture::earth_roughness = Core::LoadTexture("textures/earth/roughness.png");
texture::earth_ao = Core::LoadTexture("textures/earth/ao.png");
texture::earth_metallic = Core::LoadTexture("textures/earth/metallic.png");
texture::moon_albedo = Core::LoadTexture("textures/moon/albedo.jpg");
texture::moon_normal = Core::LoadTexture("textures/moon/normal.jpg");
texture::moon_roughness = Core::LoadTexture("textures/moon/roughness.jpg");
texture::moon_ao = Core::LoadTexture("textures/moon/ao.jpg");
texture::moon_metallic = Core::LoadTexture("textures/moon/metallic.png");
texture::station_albedo = Core::LoadTexture("textures/station/albedo.jpg");
texture::station_normal = Core::LoadTexture("textures/station/normal.png");
texture::station_roughness = Core::LoadTexture("textures/station/roughness.jpg");
texture::station_ao = Core::LoadTexture("textures/station/ao.jpg");
texture::station_metallic = Core::LoadTexture("textures/station/metallic.jpg");
}
void renderScene(GLFWwindow* window){
@ -104,14 +171,33 @@ void renderScene(GLFWwindow* window){
//desired objects go here
drawObjectSun(sunContext, glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time/10));
drawObjectPBR(shipContext, glm::translate(cameraPos) * glm::translate(glm::vec3(0.85f, -0.25f, 0.f))
* glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 0, 1))
* glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 1, 0))
* glm::rotate(glm::mat4(1.0f), glm::radians(-5.f), glm::vec3(1, 0, 0))
* glm::scale(glm::vec3(0.015f)),
texture::ship_albedo, texture::ship_normal, texture::ship_ao, texture::ship_roughness);
drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::planet_albedo, texture::planet_normal, texture::planet_ao, texture::planet_roughness);
drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(-4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::mars_albedo, texture::mars_normal, texture::mars_ao, 0);
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::mat4 spaceshipRotationMatrix = glm::mat4({
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
0.,0.,0.,1.,
});
drawObjectPBR(shipContext,
glm::translate(spaceshipPos)
* spaceshipRotationMatrix
* glm::translate(glm::vec3(0.f, -0.1f, 0.1f))
* glm::eulerAngleX(glm::radians(80.f))
* glm::eulerAngleY(glm::radians(180.f))
* glm::scale(glm::vec3(0.005f)),
texture::ship_albedo, texture::ship_normal, texture::ship_ao, texture::ship_roughness, texture::ship_metallic);
drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-0.5f*time), texture::planet_albedo, texture::planet_normal, texture::planet_ao, texture::planet_roughness, texture::planet_metallic);
drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(-4.f, 0, 0)) * glm::eulerAngleY(-0.5f*time), texture::mars_albedo, texture::mars_normal, texture::mars_ao, texture::mars_roughness, texture::mars_metallic);
drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(0, 0, 4.f)) * glm::eulerAngleY(-0.5f*time), texture::jupiter_albedo, texture::jupiter_normal, texture::jupiter_ao, texture::jupiter_roughness, texture::jupiter_metallic);
drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(0, 0, -4.f)) * glm::eulerAngleY(-0.5f*time), texture::earth_albedo, texture::earth_normal, texture::earth_ao, texture::earth_roughness, texture::earth_metallic);
drawObjectPBR(planetContext, glm::translate(glm::vec3(4.f, 0, 4.f)) * glm::eulerAngleY(-0.5f * time), texture::moon_albedo, texture::moon_normal, texture::moon_ao, texture::moon_roughness, texture::moon_metallic);
drawObjectPBR(stationContext, glm::translate(glm::vec3(0.f, 3.f, 0.f)) * glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time), texture::station_albedo, texture::station_normal, texture::station_ao, texture::station_roughness, texture::station_metallic);
//desired objects end here
glUseProgram(0);
glfwSwapBuffers(window);
@ -124,16 +210,20 @@ void processInput(GLFWwindow* window)
float cameraSpeed = 0.1f;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
cameraPos += cameraSpeed * cameraFront;
spaceshipPos += cameraSpeed * spaceshipDir;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
cameraPos -= cameraSpeed * cameraFront;
spaceshipPos -= cameraSpeed * spaceshipDir;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
spaceshipDir = glm::vec3(glm::eulerAngleY(cameraSpeed) * glm::vec4(spaceshipDir, 0));
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
spaceshipDir = glm::vec3(glm::eulerAngleY(-cameraSpeed) * glm::vec4(spaceshipDir, 0));
cameraDir = spaceshipDir;
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.05f;
}
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness) {
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness, GLuint metallic) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
@ -148,6 +238,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint a
Core::SetActiveTexture(normal, "normalMap", program, 1);
Core::SetActiveTexture(ao, "aoMap", program, 2);
Core::SetActiveTexture(roughness, "roughnessMap", program, 3);
Core::SetActiveTexture(metallic, "metallicMap", program, 4);
Core::DrawContext(context);
}
@ -228,12 +319,12 @@ glm::mat4 createPerspectiveMatrix()
glm::mat4 createCameraMatrix()
{
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraFront, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraFront));
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
glm::mat4 cameraRotrationMatrix = glm::mat4({
cameraSide.x,cameraSide.y,cameraSide.z,0,
cameraUp.x,cameraUp.y,cameraUp.z ,0,
-cameraFront.x,-cameraFront.y,-cameraFront.z,0,
-cameraDir.x,-cameraDir.y,-cameraDir.z,0,
0.,0.,0.,1.,
});
cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

BIN
cw_8/textures/earth/ao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 MiB

After

Width:  |  Height:  |  Size: 4.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
cw_8/textures/moon/ao.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 MiB

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 MiB

After

Width:  |  Height:  |  Size: 7.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 MiB

After

Width:  |  Height:  |  Size: 6.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw8", "cw_8\grk-cw8.vcxproj", "{6D813233-7D21-4888-944E-8E3CCAC3EFD3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw4", "..\cw 4\grk-cw4.vcxproj", "{D7858112-9412-4E7E-AB73-A911604592EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@ -15,6 +17,10 @@ Global
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Debug|x86.Build.0 = Debug|Win32
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.ActiveCfg = Release|Win32
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.Build.0 = Release|Win32
{D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.ActiveCfg = Debug|Win32
{D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.Build.0 = Debug|Win32
{D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.ActiveCfg = Release|Win32
{D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE