Add clang-format, format main
This commit is contained in:
parent
3a93f2410f
commit
8e4eacf48f
13
.clang-format
Normal file
13
.clang-format
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AllowShortBlocksOnASingleLine: 'true'
|
||||
AllowShortCaseLabelsOnASingleLine: 'true'
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: 'false'
|
||||
AlwaysBreakBeforeMultilineStrings: 'true'
|
||||
IndentWidth: '4'
|
||||
ColumnLimit: 100
|
||||
|
||||
...
|
97
main.cpp
97
main.cpp
@ -1,40 +1,37 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Rendering/Shader.h"
|
||||
#include "ECS/Components/DirectionalLight.h"
|
||||
#include "ECS/Components/ObjMesh.h"
|
||||
#include "ECS/Components/PathMove.h"
|
||||
#include "ECS/Components/SineAnimation.h"
|
||||
#include "ECS/Components/Texture.h"
|
||||
#include "ECS/ECS.h"
|
||||
#include "ECS/Events/InputEvent.h"
|
||||
#include "ECS/Events/MouseMoveEvent.h"
|
||||
#include "ECS/Systems/GravitySystem.h"
|
||||
#include "ECS/Systems/PositionDebugSystem.h"
|
||||
#include "ECS/Systems/InteractivePathSystem.h"
|
||||
#include "ECS/Systems/KeyboardMovementSystem.h"
|
||||
#include "ECS/Systems/RenderSystem.h"
|
||||
#include "ECS/Systems/MouseLookSystem.h"
|
||||
#include "ECS/Systems/PathMoveSystem.h"
|
||||
#include "ECS/Components/ObjMesh.h"
|
||||
#include "ECS/Components/Texture.h"
|
||||
#include "ECS/Components/SineAnimation.h"
|
||||
#include "ECS/Systems/PositionDebugSystem.h"
|
||||
#include "ECS/Systems/RenderSystem.h"
|
||||
#include "ECS/Systems/SineAnimationSystem.h"
|
||||
#include "ECS/Components/DirectionalLight.h"
|
||||
#include "ECS/Components/PathMove.h"
|
||||
#include "ECS/Systems/InteractivePathSystem.h"
|
||||
#include "Rendering/Shader.h"
|
||||
|
||||
using namespace ECS;
|
||||
|
||||
|
||||
World *world = World::createWorld();
|
||||
|
||||
|
||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
|
||||
world->emit<InputEvent>({key, action});
|
||||
}
|
||||
|
||||
static void mouse_callback(GLFWwindow* window, double xpos, double ypos) {
|
||||
static void mouse_callback(GLFWwindow *window, double xpos, double ypos) {
|
||||
world->emit<MouseMoveEvent>({xpos, ypos});
|
||||
}
|
||||
|
||||
@ -50,9 +47,8 @@ int main(int argc, char **argv) {
|
||||
GLFWwindow *window;
|
||||
|
||||
/* Initialize the library */
|
||||
if (!glfwInit())
|
||||
return -1;
|
||||
|
||||
if (!glfwInit()) return -1;
|
||||
|
||||
// Anti Aliasing
|
||||
glfwWindowHint(GLFW_SAMPLES, aa_samples);
|
||||
|
||||
@ -74,8 +70,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
// glad: load all OpenGL function pointers
|
||||
// ---------------------------------------
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
std::cout << "Failed to initialize GLAD" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
@ -95,7 +90,7 @@ int main(int argc, char **argv) {
|
||||
world->registerSystem(new SineAnimationSystem());
|
||||
world->registerSystem(new InteractivePathSystem());
|
||||
|
||||
RenderSystem* renderSystem = new RenderSystem();
|
||||
RenderSystem *renderSystem = new RenderSystem();
|
||||
world->registerSystem(renderSystem);
|
||||
|
||||
Entity *player = world->create();
|
||||
@ -103,33 +98,30 @@ int main(int argc, char **argv) {
|
||||
player->assign<Movement>(glm::vec3(5.f, 5.f, 5.f));
|
||||
player->assign<MouseLook>(0.1);
|
||||
player->assign<Camera>(70.0f, 900, 600, 0.1f, 100.0f);
|
||||
player->assign<PathMove>(3.0, PathMove::Path(std::vector<glm::vec3>{
|
||||
glm::vec3(0.0, 2.0, 0.0),
|
||||
glm::vec3(0.0, 2.5, -1.0),
|
||||
glm::vec3(0.0, 2.5, -2.0),
|
||||
glm::vec3(3.0, 3.0, -3.0),
|
||||
glm::vec3(4.0, 2.0, -4.0),
|
||||
glm::vec3(3.0, 2.0, -5.0),
|
||||
glm::vec3(0.0, 2.0, -10.0)
|
||||
}),
|
||||
PathMove::Views(std::vector<glm::quat>{
|
||||
glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(10.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(20.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(40.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))
|
||||
})
|
||||
);
|
||||
player->assign<PathMove>(
|
||||
3.0,
|
||||
PathMove::Path(std::vector<glm::vec3>{glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 2.5, -1.0),
|
||||
glm::vec3(0.0, 2.5, -2.0), glm::vec3(3.0, 3.0, -3.0),
|
||||
glm::vec3(4.0, 2.0, -4.0), glm::vec3(3.0, 2.0, -5.0),
|
||||
glm::vec3(0.0, 2.0, -10.0)}),
|
||||
PathMove::Views(
|
||||
std::vector<glm::quat>{glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(10.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(20.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(40.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))}));
|
||||
player->get<Transform>()->set_origin(glm::vec3(0.0, 3.0, 4.0));
|
||||
|
||||
Entity *monkey = world->create();
|
||||
monkey->assign<Transform>();
|
||||
monkey->assign<LODObjMesh>(std::vector<ObjMesh>{ObjMesh("Resources/Monkey.obj",ObjMesh::Settings(0.0, 8.0, 0.4, 0.6)),
|
||||
ObjMesh("Resources/MonkeySimple.obj", ObjMesh::Settings(8.0, 100.0, 0.4, 0.6))});
|
||||
monkey->assign<LODObjMesh>(std::vector<ObjMesh>{
|
||||
ObjMesh("Resources/Monkey.obj", ObjMesh::Settings(0.0, 8.0, 0.4, 0.6)),
|
||||
ObjMesh("Resources/MonkeySimple.obj", ObjMesh::Settings(8.0, 100.0, 0.4, 0.6))});
|
||||
monkey->assign<Texture>("Resources/Marble010_2K_Color.jpg", Texture::Settings(true), false);
|
||||
monkey->get<Texture>()->addNormalmap("Resources/Marble010_2K_Normal.jpg", Texture::Settings(true));
|
||||
monkey->get<Texture>()->addNormalmap("Resources/Marble010_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
monkey->assign<SineAnimation>(glm::vec3(0.0, 0.3, 0.0), 0.5);
|
||||
monkey->assign<Material>(0.6, 0.6);
|
||||
monkey->get<Transform>()->set_origin(glm::vec3(0.0f, 2.0f, -6.0f));
|
||||
@ -138,7 +130,8 @@ int main(int argc, char **argv) {
|
||||
wall1->assign<Transform>();
|
||||
wall1->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall1->assign<Texture>("Resources/Facade001_2K_Color.png", Texture::Settings(true), true);
|
||||
wall1->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true));
|
||||
wall1->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
wall1->assign<Material>(0.2, 0.8);
|
||||
wall1->get<Transform>()->set_origin(glm::vec3(0.0f, 0.0f, -2.0f));
|
||||
|
||||
@ -146,7 +139,8 @@ int main(int argc, char **argv) {
|
||||
wall2->assign<Transform>();
|
||||
wall2->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall2->assign<Texture>("Resources/Facade001_2K_Color.png", Texture::Settings(true), true);
|
||||
wall2->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true));
|
||||
wall2->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
wall2->assign<Material>(0.2, 0.8);
|
||||
wall2->get<Transform>()->set_origin(glm::vec3(0.0f, 0.0f, -10.0f));
|
||||
|
||||
@ -154,7 +148,8 @@ int main(int argc, char **argv) {
|
||||
wall3->assign<Transform>();
|
||||
wall3->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall3->assign<Texture>("Resources/Facade001_2K_Color.png", Texture::Settings(true), true);
|
||||
wall3->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true));
|
||||
wall3->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
wall3->assign<Material>(0.2, 0.8);
|
||||
wall3->get<Transform>()->set_origin(glm::vec3(4.0f, 0.0f, -6.0f));
|
||||
wall3->get<Transform>()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0));
|
||||
@ -163,7 +158,8 @@ int main(int argc, char **argv) {
|
||||
wall4->assign<Transform>();
|
||||
wall4->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall4->assign<Texture>("Resources/Facade001_2K_Color.png", Texture::Settings(true), true);
|
||||
wall4->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true));
|
||||
wall4->get<Texture>()->addNormalmap("Resources/Facade001_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
wall4->assign<Material>(0.2, 0.8);
|
||||
wall4->get<Transform>()->set_origin(glm::vec3(-4.0f, 0.0f, -6.0f));
|
||||
wall4->get<Transform>()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0));
|
||||
@ -172,7 +168,8 @@ int main(int argc, char **argv) {
|
||||
ground->assign<Transform>();
|
||||
ground->assign<ObjMesh>(ObjMesh("Resources/Ground.obj", ObjMesh::Settings()));
|
||||
ground->assign<Texture>("Resources/Ground003_2K_Color.jpg", Texture::Settings(true), false);
|
||||
ground->get<Texture>()->addNormalmap("Resources/Ground003_2K_Normal.jpg", Texture::Settings(true));
|
||||
ground->get<Texture>()->addNormalmap("Resources/Ground003_2K_Normal.jpg",
|
||||
Texture::Settings(true));
|
||||
ground->assign<Material>(1.0, 0.0);
|
||||
ground->get<Transform>()->set_origin(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
@ -214,7 +211,9 @@ int main(int argc, char **argv) {
|
||||
renderSystem->render(world, defaultShader, shadowShader, debugShader);
|
||||
|
||||
ring->get<Transform>()->rotate(delta * 100.0, glm::vec3(0.0, 1.0, 0.0));
|
||||
sun->get<DirectionalLight>()->direction = glm::normalize(glm::vec3(glm::rotate(glm::mat4(1), (float)elapsed_time * 0.5f, glm::vec3(0.0, 1.0, 0.0)) * glm::vec4(1.0, 1.0, 1.0, 0.0)));
|
||||
sun->get<DirectionalLight>()->direction = glm::normalize(glm::vec3(
|
||||
glm::rotate(glm::mat4(1), (float)elapsed_time * 0.5f, glm::vec3(0.0, 1.0, 0.0)) *
|
||||
glm::vec4(1.0, 1.0, 1.0, 0.0)));
|
||||
|
||||
/* Swap front and back buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
13
tools/format.sh
Executable file
13
tools/format.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
clang_format_command="clang-format"
|
||||
clang_tidy_command="run-clang-tidy"
|
||||
fi
|
||||
if [[ "$OSTYPE" == "linux"* ]]; then
|
||||
clang_format_command="clang-format-11"
|
||||
clang_tidy_command="run-clang-tidy-11"
|
||||
fi
|
||||
|
||||
eval "$clang_format_command -i *.h *.cpp -style=file"
|
||||
eval "$clang_tidy_command -fix"
|
Loading…
x
Reference in New Issue
Block a user