spaceship get instance returns pointer

This commit is contained in:
Pawel Felcyn 2024-01-10 21:20:52 +01:00
parent 7b2fb51136
commit 06a808b3a7
5 changed files with 19 additions and 18 deletions

View File

@ -5,7 +5,8 @@
*.suo *.suo
*.user *.user
*.sln.docstates *.sln.docstates
./Debug
./.vs
# Build results # Build results
# Roslyn cache directories # Roslyn cache directories

View File

@ -15,10 +15,10 @@ private:
public: public:
static Spaceship& getInstance() static Spaceship* getInstance()
{ {
static Spaceship instance; // Jedna i jedyna instancja static Spaceship instance; // Jedna i jedyna instancja
return instance; return &instance;
} }
glm::vec3 color = glm::vec3(0.3, 0.3, 0.5); glm::vec3 color = glm::vec3(0.3, 0.3, 0.5);

View File

@ -28,7 +28,7 @@ public:
void draw() { void draw() {
glUseProgram(program); glUseProgram(program);
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix(); glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance()->createCameraMatrix();
positionMatrix = glm::translate(sunPos); positionMatrix = glm::translate(sunPos);
glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale)); glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale));
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);

View File

@ -151,8 +151,8 @@ glm::mat4 Core::createPerspectiveMatrix()
} }
void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program) { void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program) {
Spaceship* spaceship = Spaceship::getInstance();
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix(); glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix; glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
@ -164,7 +164,7 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z); glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(program, "cameraPos"), Spaceship::getInstance().cameraPos.x, Spaceship::getInstance().cameraPos.y, Spaceship::getInstance().cameraPos.z); glUniform3f(glGetUniformLocation(program, "cameraPos"), spaceship->cameraPos.x, spaceship->cameraPos.y, spaceship->cameraPos.z);
const int NUM_LIGHTS = 23; const int NUM_LIGHTS = 23;
@ -183,9 +183,9 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
glUniform3f(glGetUniformLocation(program, "lightPos"), firstSunPos.x, firstSunPos.y, firstSunPos.z); glUniform3f(glGetUniformLocation(program, "lightPos"), firstSunPos.x, firstSunPos.y, firstSunPos.z);
glUniform3f(glGetUniformLocation(program, "lightColor"), firstSunColor.x, firstSunColor.y, firstSunColor.z); glUniform3f(glGetUniformLocation(program, "lightColor"), firstSunColor.x, firstSunColor.y, firstSunColor.z);
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), Spaceship::getInstance().spotlightConeDir.x, Spaceship::getInstance().spotlightConeDir.y, Spaceship::getInstance().spotlightConeDir.z); glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spaceship->spotlightConeDir.x, spaceship->spotlightConeDir.y, spaceship->spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), Spaceship::getInstance().spotlightPos.x, Spaceship::getInstance().spotlightPos.y, Spaceship::getInstance().spotlightPos.z); glUniform3f(glGetUniformLocation(program, "spotlightPos"), spaceship->spotlightPos.x, spaceship->spotlightPos.y, spaceship->spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), Spaceship::getInstance().spotlightColor.x, Spaceship::getInstance().spotlightColor.y, Spaceship::getInstance().spotlightColor.z); glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship->spotlightColor.x, spaceship->spotlightColor.y, spaceship->spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), Spaceship::getInstance().spotlightPhi); glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship->spotlightPhi);
Core::DrawContext(context); Core::DrawContext(context);
} }

View File

@ -54,7 +54,7 @@ glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6);
float lastTime = -1.f; float lastTime = -1.f;
float deltaTime = 0.f; float deltaTime = 0.f;
Spaceship& spaceship = Spaceship::getInstance(); Spaceship* spaceship = Spaceship::getInstance();
void updateDeltaTime(float time) { void updateDeltaTime(float time) {
if (lastTime < 0) { if (lastTime < 0) {
@ -107,9 +107,9 @@ void renderScene(GLFWwindow* window)
drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f, program); drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f, program);
drawObjectPBR(models::spaceshipContext, drawObjectPBR(models::spaceshipContext,
spaceship.calculateModelMatrix(), spaceship->calculateModelMatrix(),
spaceship.color, spaceship->color,
spaceship.roughness, spaceship.metallic, program spaceship->roughness, spaceship->metallic, program
); );
glUseProgram(0); glUseProgram(0);
@ -195,7 +195,7 @@ void shutdown(GLFWwindow* window)
//obsluga wejscia //obsluga wejscia
void processInput(GLFWwindow* window) void processInput(GLFWwindow* window)
{ {
Spaceship::getInstance().processInput(window, deltaTime); spaceship->processInput(window, deltaTime);
/*if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) /*if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
exposition -= 0.05; exposition -= 0.05;
@ -203,8 +203,8 @@ void processInput(GLFWwindow* window)
exposition += 0.05;*/ exposition += 0.05;*/
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
printf("GameUtils::spaceshipPos = glm::vec3(%ff, %ff, %ff);\n",spaceship.spaceshipPos.x,spaceship.spaceshipPos.y,spaceship.spaceshipPos.z); printf("GameUtils::spaceshipPos = glm::vec3(%ff, %ff, %ff);\n",spaceship->spaceshipPos.x,spaceship->spaceshipPos.y,spaceship->spaceshipPos.z);
printf("GameUtils::spaceshipDir = glm::vec3(%ff, %ff, %ff);\n",spaceship.spaceshipDir.x,spaceship.spaceshipDir.y,spaceship.spaceshipDir.z); printf("GameUtils::spaceshipDir = glm::vec3(%ff, %ff, %ff);\n",spaceship->spaceshipDir.x,spaceship->spaceshipDir.y,spaceship->spaceshipDir.z);
} }
//cameraDir = glm::normalize(-cameraPos); //cameraDir = glm::normalize(-cameraPos);