-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Pinkolik/issue-12
Refactoring and cleaning up
- Loading branch information
Showing
30 changed files
with
290 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[submodule "glfw"] | ||
path = glfw | ||
[submodule "dependencies/glfw"] | ||
path = dependencies/glfw | ||
url = [email protected]:glfw/glfw.git | ||
[submodule "glm"] | ||
path = glm | ||
[submodule "dependencies/glm"] | ||
path = dependencies/glm | ||
url = [email protected]:g-truc/glm.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule glfw
updated
from 000000 to dd8a67
Submodule glm
updated
from 000000 to fc8f4b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Created by pinkolik on 12/15/22. | ||
// | ||
|
||
#include "GameInstance.h" | ||
#include <iostream> | ||
|
||
GameInstance::GameInstance(const char *mapModelPath, const char *playerModelPath, const int width, | ||
const int height) : width(width), height(height) { | ||
map = new Map(mapModelPath); | ||
player = new Player(playerModelPath, map->getSpawnPos()); | ||
} | ||
|
||
void GameInstance::draw() { | ||
shader.use(); | ||
shader.setBool("debug", false); | ||
glm::mat4 projection = glm::perspective( | ||
glm::radians(45.0f), (float) width / (float) height, 0.1f, 100.0f); | ||
shader.setMatrix4f("projection", projection); | ||
|
||
glm::mat4 view = player->getViewMatrix(); | ||
shader.setMatrix4f("view", view); | ||
|
||
map->getModel().draw(shader); | ||
|
||
shader.setBool("debug", true); | ||
player->getModel().draw(shader); | ||
shader.setBool("debug", false); | ||
} | ||
|
||
void GameInstance::tick(GLFWwindow *window, const float deltaTime) { | ||
glm::vec3 gravity = glm::vec3(0, GRAVITY * fallTime * fallTime, 0); | ||
std::cout << "Fall time: " << fallTime << std::endl; | ||
glm::vec3 move = player->processKeyboard(window, deltaTime); | ||
player->applyForce(gravity); | ||
player->applyForce(move); | ||
|
||
bool first = true; | ||
while (true) { | ||
glm::vec3 *mtv = map->getModel().getMinimumTranslationVec(player->getModel(), gravity); | ||
if (mtv != nullptr) { | ||
std::cout << "Applying force: " << mtv->x << ", " << mtv->y << ", " << mtv->z << std::endl; | ||
player->applyForce(*mtv); | ||
delete mtv; | ||
fallTime = 0.1f; | ||
} else if (first) { | ||
fallTime += deltaTime; | ||
first = false; | ||
} | ||
mtv = map->getModel().getMinimumTranslationVec(player->getModel(), move); | ||
if (mtv != nullptr) { | ||
std::cout << "Applying force: " << mtv->x << "," << mtv->y << "," << mtv->z << std::endl; | ||
player->applyForce(*mtv); | ||
delete mtv; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void GameInstance::processMouseMovement(float xOffset, float yOffset) { | ||
player->processMouseMovement(xOffset, yOffset); | ||
} | ||
|
||
void GameInstance::processResize(const int newWidth, const int newHeight) { | ||
width = newWidth; | ||
height = newHeight; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Created by pinkolik on 12/15/22. | ||
// | ||
|
||
#ifndef GAME_GAMEINSTANCE_H | ||
#define GAME_GAMEINSTANCE_H | ||
|
||
|
||
#include "../map/Map.h" | ||
#include "../player/Player.h" | ||
#include "../../shader/Shader.h" | ||
|
||
class GameInstance { | ||
public: | ||
GameInstance(const char *mapModelPath, const char *playerModelPath, int width, int height); | ||
|
||
void draw(); | ||
|
||
void tick(GLFWwindow *window, float deltaTime); | ||
|
||
void processMouseMovement(float xOffset, float yOffset); | ||
|
||
void processResize(int newWidth, int newHeight); | ||
|
||
private: | ||
const float GRAVITY = -0.05f; | ||
|
||
int width; | ||
int height; | ||
|
||
Map *map; | ||
Player *player; | ||
|
||
float fallTime = 0.1f; | ||
|
||
Shader shader = Shader("resources/shaders/vShader.glsl", | ||
"resources/shaders/fShader.glsl"); | ||
}; | ||
|
||
|
||
#endif //GAME_GAMEINSTANCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "Map.h" | ||
|
||
Map::Map(const char *mapModelPath) : | ||
model(Model(mapModelPath)) { | ||
model.buffer(); | ||
} | ||
|
||
Model &Map::getModel() { | ||
return model; | ||
} | ||
|
||
glm::vec3 Map::getSpawnPos() { | ||
return model.getSpawnPos(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef MAP_H | ||
#define MAP_H | ||
|
||
#include "../model/Model.h" | ||
|
||
class Map { | ||
public: | ||
explicit Map(const char *mapModelPath); | ||
|
||
glm::vec3 getSpawnPos(); | ||
|
||
Model &getModel(); | ||
|
||
private: | ||
|
||
Model model; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "mesh.h" | ||
#include "Mesh.h" | ||
|
||
Mesh::Mesh(std::vector<Primitive> &primitives) : primitives(primitives) {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.