Format code

This commit is contained in:
MrLetsplay 2023-09-13 20:42:01 +02:00
parent d47eb8c943
commit 74367e5fb0
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
43 changed files with 365 additions and 360 deletions

View File

@ -1,11 +1,11 @@
#include "defaultplayercontroller.h"
#include "input.h"
#include "internal.h"
#include "internal/physics.h"
#include "internal/ui.h"
#include "noclipplayercontroller.h"
#include "ui.h"
#include "uielements.h"
#include "defaultplayercontroller.h"
#include "noclipplayercontroller.h"
#include "internal.h"
#include "internal/ui.h"
#include "internal/physics.h"
namespace kek::Defaults {
@ -88,7 +88,7 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac
double x, y;
glfwGetCursorPos(kekData.window, &x, &y);
doUIMouseHover(x, y);
}else {
} else {
Input::setCursorMode(GLFWCursorMode::CAPTURE);
for(auto e : UI::getElements()) {
@ -102,7 +102,7 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac
kekData.player->controller = kekData.player->noclip ? (PlayerController *) noclipController : (PlayerController *) defaultController;
if(kekData.player->noclip) {
kekData.physics->world->removeRigidBody(kekData.player->physics->body);
}else {
} else {
kekData.physics->world->addRigidBody(kekData.player->physics->body);
}
}
@ -118,8 +118,7 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d
}
switch(Input::getCursorMode()) {
case GLFWCursorMode::CAPTURE:
{
case GLFWCursorMode::CAPTURE: {
float xoff = lastX - x;
float yoff = lastY - y;
@ -131,8 +130,7 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d
break;
}
case GLFWCursorMode::FREE:
case GLFWCursorMode::HIDDEN:
{
case GLFWCursorMode::HIDDEN: {
doUIMouseHover(x, y);
break;
}
@ -142,21 +140,18 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d
lastY = y;
}
static void defaultMouseButtonCallback(GLFWwindow* window, int button, int action, int mods, void *data) {
static void defaultMouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data) {
switch(Input::getCursorMode()) {
case GLFWCursorMode::CAPTURE:
{
case GLFWCursorMode::CAPTURE: {
// TODO
break;
}
case GLFWCursorMode::FREE:
case GLFWCursorMode::HIDDEN:
{
case GLFWCursorMode::HIDDEN: {
switch(action) {
case GLFW_PRESS:
break;
case GLFW_RELEASE:
{
case GLFW_RELEASE: {
double x, y;
glfwGetCursorPos(window, &x, &y);
doUIMouseClick(x, y, (GLFWMouseButton) button);
@ -188,7 +183,7 @@ void init() {
Input::addMouseButtonListener(MouseButtonCallback(defaultMouseButtonCallback, nullptr));
options = new ButtonElement(uiPx(0), uiPx(100), uiPx(100), uiPx(50));
//UI::addElement(options);
// UI::addElement(options);
kekData.player = new Player();
btVector3 positions[2];
@ -204,23 +199,22 @@ void init() {
btTransform from;
from.setIdentity();
from.setOrigin(btVector3(0,0,0));
from.setOrigin(btVector3(0, 0, 0));
btTransform to;
to.setIdentity();
to.setOrigin(btVector3(1,1,1));
to.setOrigin(btVector3(1, 1, 1));
btCollisionWorld::ClosestConvexResultCallback cb = btCollisionWorld::ClosestConvexResultCallback(from.getOrigin(), to.getOrigin());
kekData.physics->world->convexSweepTest((btConvexShape *) shape, from, to, cb);
kekData.player->physics = new PlayerPhysicsObjectData();
kekData.player->physics->body = body;
kekData.player->moveTo(glm::vec3(5,10,0));
kekData.player->moveTo(glm::vec3(5, 10, 0));
kekData.player->controller = defaultController;
}
void destroy() {
}
}

View File

@ -1,33 +1,33 @@
#include "engine.h"
#include <iostream>
#include <chrono>
#include <cstring>
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/gtc/type_ptr.hpp>
#include <chrono>
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image.h>
#include <stb_image_write.h>
#include "errordialog.h"
#include "objparser.h"
#include "resource.h"
#include "camera.h"
#include "constants.h"
#include "gameobject.h"
#include "scene.h"
#include "defaults.h"
#include "errordialog.h"
#include "gameobject.h"
#include "objparser.h"
#include "physics.h"
#include "resource.h"
#include "scene.h"
#include "ui.h"
#include "uielements.h"
#include "physics.h"
#include "internal.h"
#include "internal/ui.h"
#include "internal/input.h"
#include "internal/ui.h"
kek::KekData kek::kekData;
@ -42,19 +42,19 @@ static void framebufferSizeCallback(GLFWwindow *window, int w, int h) {
}
static void glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam) {
//if(id == 0x20071) return;
// if(id == 0x20071) return;
if(severity == GL_DEBUG_SEVERITY_NOTIFICATION) return;
std::cout << "OpenGL Debug (" << id << "): " << message << std::endl;
}
int init() {
// Init GLFW
if (glfwInit() != GL_TRUE) {
if(glfwInit() != GL_TRUE) {
const char *errorMsg;
int code = glfwGetError(&errorMsg);
if(code != GLFW_NO_ERROR) {
ErrorDialog::showError("Failed to initialize GLFW: " + std::string(errorMsg) + std::string(" (") + std::to_string(code) + std::string(")"));
}else {
} else {
ErrorDialog::showError("Failed to initialize GLFW: Unknown error");
}
@ -79,7 +79,7 @@ int init() {
int code = glfwGetError(&errorMsg);
if(code != GLFW_NO_ERROR) {
ErrorDialog::showError("Failed to create window: " + std::string(errorMsg) + " (" + std::to_string(code) + ")");
}else {
} else {
ErrorDialog::showError("Failed to create window: Unknown error");
}
@ -93,7 +93,7 @@ int init() {
// Init GLEW
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
if(glewInit() != GLEW_OK) {
ErrorDialog::showError("Failed to initialize GLEW");
glfwTerminate();
return KEK_ERROR;
@ -105,7 +105,7 @@ int init() {
int flags;
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
if(flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(glDebugOutput, nullptr);
@ -122,7 +122,7 @@ int init() {
glCullFace(GL_BACK);
glClearColor(0.1f, 0.3f, 0.1f, 0.0f);
//glfwSwapInterval(0);
// glfwSwapInterval(0);
stbi_set_flip_vertically_on_load(true);
@ -228,23 +228,20 @@ int start() {
ShaderLight shLight;
memcpy(shLight.color, glm::value_ptr(light->color), sizeof(shLight.color));
switch(light->getType()) {
case LightType::POINT:
{
case LightType::POINT: {
PointLight *l = (PointLight *) light;
memcpy(&shLight.position, glm::value_ptr(l->getPosition()), sizeof(shLight.position));
memcpy(&shLight.attenuation, glm::value_ptr(glm::vec3(l->constant, l->linear, l->quadratic)), sizeof(shLight.attenuation));
numPointLights++;
break;
}
case LightType::DIRECTIONAL:
{
case LightType::DIRECTIONAL: {
DirectionalLight *l = (DirectionalLight *) light;
memcpy(&shLight.direction, glm::value_ptr(l->direction), sizeof(shLight.direction));
numDirectionalLights++;
break;
}
case LightType::SPOT:
{
case LightType::SPOT: {
SpotLight *l = (SpotLight *) light;
memcpy(&shLight.position, glm::value_ptr(l->getPosition()), sizeof(shLight.position));
memcpy(&shLight.direction, glm::value_ptr(l->direction), sizeof(shLight.direction));

View File

@ -1,7 +1,7 @@
#include "input.h"
#include <map>
#include <iostream>
#include <map>
#include "internal.h"
#include "internal/input.h"
@ -55,7 +55,7 @@ void onKeyCharCallback(GLFWwindow *window, unsigned int codepoint) {
}
}
void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
void onMouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
for(auto cb : kekData.input->mouseButtonCallbacks) {
cb.second(window, button, action, mods);
}
@ -157,8 +157,7 @@ KeyboardCapture captureKeyboardInput(KeyCharCallback charCallback, KeyCallback k
id,
charCallback,
keyCallback,
uncaptureCallback
};
uncaptureCallback};
return id;
}
@ -169,8 +168,7 @@ bool uncaptureKeyboardInput(KeyboardCapture capture) {
KEK_INVALID_ID,
KeyCharCallback(),
KeyCallback(),
Callable()
};
Callable()};
return true;
}

View File

@ -34,7 +34,7 @@ void GameObject::draw(Shader *shader) {
void GameObject::addPhysics(btCollisionShape *shape, float mass, int collisionFlags) {
this->physics = new PhysicsObjectData();
btVector3 inertia = btVector3(0,0,0);
btVector3 inertia = btVector3(0, 0, 0);
shape->calculateLocalInertia(mass, inertia);
btRigidBody *body = new btRigidBody(mass, new btDefaultMotionState(), shape, inertia);
body->setFriction(1);

View File

@ -1,7 +1,7 @@
#include <vector>
#include "light.h"
#include "constants.h"
#include "light.h"
namespace kek {
@ -10,40 +10,40 @@ Light::Light(glm::vec3 color) {
}
Light::~Light() {
}
PointLight::PointLight(glm::vec3 color, float constant, float linear, float quadratic): Light(color) {
PointLight::PointLight(glm::vec3 color, float constant, float linear, float quadratic)
: Light(color) {
this->constant = constant;
this->linear = linear;
this->quadratic = quadratic;
}
PointLight::~PointLight() {
}
LightType PointLight::getType() {
return LightType::POINT;
}
DirectionalLight::DirectionalLight(glm::vec3 color, glm::vec3 direction): Light(color) {
DirectionalLight::DirectionalLight(glm::vec3 color, glm::vec3 direction)
: Light(color) {
this->direction = direction;
}
DirectionalLight::~DirectionalLight() {
}
LightType DirectionalLight::getType() {
return LightType::DIRECTIONAL;
}
void DirectionalLight::lookAt(glm::vec3 direction){
void DirectionalLight::lookAt(glm::vec3 direction) {
this->direction = direction;
}
SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff): Light(color) {
SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float linear, float quadratic, float innerCutoff, float outerCutoff)
: Light(color) {
this->direction = direction;
this->constant = constant;
this->linear = linear;
@ -53,7 +53,6 @@ SpotLight::SpotLight(glm::vec3 color, glm::vec3 direction, float constant, float
}
SpotLight::~SpotLight() {
}
LightType SpotLight::getType() {
@ -65,14 +64,19 @@ void SpotLight::lookAt(glm::vec3 direction) {
}
LightList::LightList() {
}
void LightList::add(Light *light) {
switch(light->getType()) {
case LightType::POINT: point.push_back((PointLight *) light); break;
case LightType::DIRECTIONAL: directional.push_back((DirectionalLight *) light); break;
case LightType::SPOT: spot.push_back((SpotLight *) light); break;
case LightType::POINT:
point.push_back((PointLight *) light);
break;
case LightType::DIRECTIONAL:
directional.push_back((DirectionalLight *) light);
break;
case LightType::SPOT:
spot.push_back((SpotLight *) light);
break;
}
}

View File

@ -3,8 +3,8 @@
#include "internal.h"
#include "internal/physics.h"
#include <glm/gtx/vector_angle.hpp>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <glm/gtx/vector_angle.hpp>
namespace kek {
@ -31,7 +31,7 @@ static bool castPlayer(glm::vec3 pos, glm::vec3 delta, const btCollisionObject *
}
static bool checkPlayerGrounded(float groundDistance, float maxWalkAngle, const btCollisionObject **outGround, glm::vec3 *outNormal) {
glm::vec3 groundDir = glm::vec3(0,-groundDistance,0);
glm::vec3 groundDir = glm::vec3(0, -groundDistance, 0);
glm::vec3 point;
glm::vec3 normal;
@ -49,11 +49,9 @@ static bool checkPlayerGrounded(float groundDistance, float maxWalkAngle, const
}
DefaultPlayerController::DefaultPlayerController() {
}
DefaultPlayerController::~DefaultPlayerController() {
}
glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
@ -61,7 +59,7 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
glm::vec3 totalMovement = glm::vec3(0);
int count = 0;
while (count < 3) {
while(count < 3) {
float frac;
glm::vec3 normal;
bool collision = castPlayer(pos + totalMovement, movement, nullptr, &frac, nullptr, &normal);
@ -96,7 +94,7 @@ void DefaultPlayerController::update() {
if(!onGround) {
velocity += gravity * kekData.lastFrameTime;
}else{
} else {
velocity = glm::vec3(0);
}

View File

@ -5,11 +5,9 @@
namespace kek {
NoclipPlayerController::NoclipPlayerController() {
}
NoclipPlayerController::~NoclipPlayerController() {
}
glm::vec3 NoclipPlayerController::move(glm::vec3 movement) {

View File

@ -5,8 +5,8 @@
namespace kek {
Player::Player(): RotateableObject() {
Player::Player()
: RotateableObject() {
}
void Player::rotateTo(glm::quat rotation) {

View File

@ -3,7 +3,6 @@
namespace kek {
PlayerController::~PlayerController() {
}
}

View File

@ -5,8 +5,8 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <math.h>
#include <glm/gtx/matrix_decompose.hpp>
#include <math.h>
#include "object.h"
#include "utils.h"
@ -64,7 +64,7 @@ glm::mat4 Camera::transformationMatrix() {
float x = sin(rollRad);
float y = cos(rollRad);
glm::vec3 up = glm::vec3(x, y, 0.0f);
//glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
// glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 right = glm::normalize(glm::cross(direction, up));
glm::vec3 cameraUp = glm::normalize(glm::cross(right, direction));
@ -103,7 +103,7 @@ glm::vec3 Camera::eulerAngles() {
float yawDegrees;
if(direction.x == 0 && direction.z == 0) {
yawDegrees = 0;
}else {
} else {
glm::vec2 xz = glm::normalize(glm::vec2(direction.x, direction.z)); // Normalized XZ coordinates
yawDegrees = glm::degrees(atan2(-xz.y, xz.x)) + 90.0f; // -z because OpenGL
if(yawDegrees > 180.0f) {

View File

@ -1,15 +1,15 @@
#include "fonts.h"
#include <stb_image_write.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <stb_image_write.h>
#include "shader.h"
#include "engine.h"
#include "constants.h"
#include "engine.h"
#include "internal.h"
#include "shader.h"
#include "unicode.h"
namespace kek {
@ -37,7 +37,8 @@ void TextObject::destroy() {
blocks.clear();
}
TextObject::TextObject(TextObject &&other): blocks(other.blocks) {
TextObject::TextObject(TextObject &&other)
: blocks(other.blocks) {
other.blocks.clear();
}
@ -79,8 +80,7 @@ struct RenderChar {
xPos + w, yPos, texR, texU,
xPos + w, yPos, texR, texU,
xPos, yPos + h, texL, texD,
xPos + w, yPos + h, texR, texD
};
xPos + w, yPos + h, texR, texD};
for(int i = 0; i < 24; i++) data[i] = coords[i];
}
};
@ -142,7 +142,7 @@ void TextObject::loadChars() {
auto charsForBlock = chars.find(charBlock);
if(charsForBlock != chars.end()) {
charsForBlock->second.push_back(rCh);
}else {
} else {
std::vector<RenderChar> chs;
chs.push_back(rCh);
chars[charBlock] = chs;
@ -175,7 +175,7 @@ void TextObject::loadChars() {
oldBlock->length = textLength;
glNamedBufferSubData(oldBlock->vbo, 0, textLength * sizeof(RenderChar), &it->second[0]);
}else {
} else {
// Allocate Buffer
TextBlock block;
allocateBuffer(&block, textLength);
@ -192,7 +192,7 @@ void TextObject::loadChars() {
while(it2 != blocks.end()) {
if(chars.find(it2->first) == chars.end()) {
it2 = blocks.erase(it2);
}else {
} else {
it2++;
}
}

View File

@ -28,7 +28,7 @@ Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, Material
glCreateBuffers(1, &vbo);
glCreateBuffers(1, &ebo);
//glBindVertexArray(vao);
// glBindVertexArray(vao);
glNamedBufferData(vbo, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
glNamedBufferData(ebo, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);

View File

@ -1,7 +1,7 @@
#include "shader.h"
#include "types.h"
#include "resource.h"
#include "constants.h"
#include "resource.h"
#include "types.h"
#include <GL/glew.h>
@ -27,7 +27,7 @@ static GLuint compileShader(GLenum type, std::string path) {
}
stream << includeBuf;
delete includeBuf;
}else {
} else {
stream << line << '\n';
}
}
@ -47,7 +47,8 @@ static GLuint compileShader(GLenum type, std::string path) {
if(!success) {
char log[512];
glGetShaderInfoLog(shaderID, 512, nullptr, log);
std::cout << "Failed to compile shader \"" << path << "\":\n" << log << std::endl;
std::cout << "Failed to compile shader \"" << path << "\":\n"
<< log << std::endl;
throw std::exception();
}
@ -76,7 +77,8 @@ static GLuint compileProgram(unsigned int n, GLenum *types, std::string *paths)
if(!success) {
char log[512];
glGetProgramInfoLog(id, 512, nullptr, log);
std::cout << "Failed to link program:\n" << log << std::endl;
std::cout << "Failed to link program:\n"
<< log << std::endl;
throw std::exception();
}

View File

@ -3,8 +3,8 @@
#include <stb_image.h>
#include <stb_image_write.h>
#include "resource.h"
#include "internal.h"
#include "resource.h"
namespace kek {
@ -18,7 +18,7 @@ static GLuint allocTexture(unsigned char *data, int width, int height, float bor
glTextureParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTextureStorage2D(id, 1, GL_RGB8, width, height);
glTextureSubImage2D(id, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
//glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateTextureMipmap(id);
return id;
}
@ -36,7 +36,7 @@ Texture::Texture(std::string texturePath) {
unsigned char *data = stbi_load_from_memory((stbi_uc *) buf->buffer, buf->length, &width, &height, &nrChannels, 0);
delete buf;
float borderColor[] = { 1.0f, 0.0f, 1.0f, 1.0f };
float borderColor[] = {1.0f, 0.0f, 1.0f, 1.0f};
id = allocTexture(data, width, height, borderColor);
stbi_image_free(data);
@ -74,7 +74,7 @@ std::shared_ptr<Texture> Texture::generateColor(glm::vec3 color) {
data[0] = (unsigned char) (color.x * 255);
data[1] = (unsigned char) (color.y * 255);
data[2] = (unsigned char) (color.z * 255);
float borderColor[4] = { color.x, color.y, color.z, 1.0f };
float borderColor[4] = {color.x, color.y, color.z, 1.0f};
GLuint tex = allocTexture(data, 1, 1, borderColor);
free(data);
return std::make_shared<Texture>(tex);

View File

@ -7,12 +7,12 @@
namespace kek {
UIElement::UIElement(UIValue x, UIValue y): x(x), y(y) {
UIElement::UIElement(UIValue x, UIValue y)
: x(x),
y(y) {
}
UIElement::~UIElement() {
}
// Returns the element's position relative to its parent in pixels
@ -170,7 +170,7 @@ void UIElement::clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button)
if(clickedChild != nullptr) {
UIPoint childPos = clickedChild->getPosition();
clickedChild->clickAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos, button);
}else {
} else {
click(pos, screenPos, button);
}
}
@ -196,7 +196,7 @@ bool UIElement::focusEnterAll(UIPoint pos, UIPoint screenPos) {
}
if(focusable) {
//UI::focusElement(this); FIXME
// UI::focusElement(this); FIXME
return true;
}

View File

@ -7,7 +7,8 @@
namespace kek {
TextElement::TextElement(UIValue x, UIValue y, Font *font): UIElement(x, y) {
TextElement::TextElement(UIValue x, UIValue y, Font *font)
: UIElement(x, y) {
this->text = new TextObject(font, "Text");
this->sizePixels = KEK_DEFAULT_FONT_SIZE_PIXELS;
this->color = Colors::WHITE;
@ -15,7 +16,8 @@ TextElement::TextElement(UIValue x, UIValue y, Font *font): UIElement(x, y) {
this->textBounds = TextBounds::SMALLEST;
}
TextElement::TextElement(UIValue x, UIValue y): TextElement(x, y, kekData.ui->defaultFont) {}
TextElement::TextElement(UIValue x, UIValue y)
: TextElement(x, y, kekData.ui->defaultFont) {}
TextElement::~TextElement() {
delete text;
@ -49,7 +51,6 @@ UIBounds TextElement::getBounds() {
default:
return offsetUIBounds(w, h, origin);
}
}
void TextElement::setText(std::string text) {
@ -84,12 +85,12 @@ void TextElement::draw(UIPoint screenPos, glm::mat4 projection) {
}
}
UIWindow::UIWindow(UIValue x, UIValue y): UIElement(x, y) {
UIWindow::UIWindow(UIValue x, UIValue y)
: UIElement(x, y) {
addChild(new TextElement(x, y));
}
UIWindow::~UIWindow() {
}
UIElementType UIWindow::getType() {
@ -97,19 +98,25 @@ UIElementType UIWindow::getType() {
}
void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) {
}
static float rectangleVerts[] = {
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
0.0f,
1.0f,
1.0f,
1.0f,
1.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
};
RectangleElement::RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h): UIElement(x, y) {
RectangleElement::RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h)
: UIElement(x, y) {
this->w = w;
this->h = h;
color = Colors::BLACK;
@ -153,7 +160,8 @@ void RectangleElement::draw(UIPoint screenPos, glm::mat4 projection) {
glDrawArrays(GL_TRIANGLES, 0, 6);
}
ButtonElement::ButtonElement(UIValue x, UIValue y, UIValue w, UIValue h): RectangleElement(x, y, w, h) {
ButtonElement::ButtonElement(UIValue x, UIValue y, UIValue w, UIValue h)
: RectangleElement(x, y, w, h) {
clickable = true;
color = Colors::CYAN;

View File

@ -44,7 +44,8 @@ static void show(GtkMessageType type, GtkButtonsType buttons, const char *title,
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(w);
gtk_widget_destroy(d);
while(g_main_context_iteration(nullptr, false));
while(g_main_context_iteration(nullptr, false))
;
}
void showInfo(std::string message) {

View File

@ -1,12 +1,12 @@
#include "objparser.h"
#include <iostream>
#include <string>
#include <sstream>
#include <glm/glm.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include "types.h"
#include "resource.h"
#include "types.h"
namespace kek::ObjParser {
@ -51,15 +51,15 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) {
float x, y, z;
str >> x >> y >> z;
vertexPositions.push_back(glm::vec3(x, y, z));
}else if(cmd == "vn") {
} else if(cmd == "vn") {
float x, y, z;
str >> x >> y >> z;
vertexNormals.push_back(glm::normalize(glm::vec3(x, y, z)));
}else if(cmd == "vt") {
} else if(cmd == "vt") {
float u, v = 1.0f;
str >> u >> v;
vertexTexCoords.push_back(glm::vec2(u, v));
}else if(cmd == "f") {
} else if(cmd == "f") {
uint32_t v1, v1T, v1N;
readFaceVertex(str, &v1, &v1T, &v1N);
uint32_t v2, v2T, v2N;
@ -73,14 +73,14 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) {
indices.push_back(indices.size());
vertices.push_back(Vertex(vertexPositions[v3 - 1], vertexNormals[v3N - 1], vertexTexCoords[v3T - 1]));
indices.push_back(indices.size());
}else if(cmd == "mtllib") {
} else if(cmd == "mtllib") {
std::string name;
str >> name;
std::string mtllibPath = folderPath + name;
std::map<std::string, Material *> mats = loadMaterials(mtllibPath);
materials.insert(mats.begin(), mats.end());
}else if(cmd == "usemtl") {
} else if(cmd == "usemtl") {
std::string mtlName;
str >> mtlName;
auto it = materials.find(mtlName);
@ -90,7 +90,7 @@ Mesh *parseMesh(MemoryBuffer *buf, std::string folderPath) {
}
material = it->second;
}else {
} else {
std::cout << "Ignoring unknown/unsupported OBJ command: " << cmd << std::endl;
}
}
@ -146,23 +146,23 @@ std::map<std::string, Material *> parseMaterials(MemoryBuffer *buf, std::string
if(name.length() > 0) mats.emplace(name, makeMaterial(ambient, diffuse, specular, shininess));
str >> name;
}else if(cmd == "Ka") {
} else if(cmd == "Ka") {
float r, g, b;
str >> r >> g >> b;
ambient = Texture::generateColor(glm::vec3(r, g, b));
}else if(cmd == "Kd") {
} else if(cmd == "Kd") {
float r, g, b;
str >> r >> g >> b;
diffuse = Texture::generateColor(glm::vec3(r, g, b));
}else if(cmd == "Ks") {
} else if(cmd == "Ks") {
float r, g, b;
str >> r >> g >> b;
specular = Texture::generateColor(glm::vec3(r, g, b));
}else if(cmd == "Ns") {
} else if(cmd == "Ns") {
float s;
str >> s;
shininess = s;
}else {
} else {
std::cout << "Ignoring unknown/unsupported MTL command: " << cmd << std::endl;
}
}

View File

@ -8,7 +8,7 @@ namespace kek {
class Camera: public DefaultObject {
public:
public:
glm::vec3 direction;
float roll;
@ -38,7 +38,6 @@ public:
glm::vec3 eulerAngles();
void applyEuler(glm::vec3 euler);
};
}

View File

@ -5,11 +5,17 @@ namespace kek {
struct Color {
float r, g, b, a;
constexpr Color(float r, float g, float b, float a): r(r), g(g), b(b), a(a) {}
constexpr Color(float r, float g, float b, float a)
: r(r),
g(g),
b(b),
a(a) {}
constexpr Color(float r, float g, float b): Color(r, g, b, 1.0) {}
constexpr Color(float r, float g, float b)
: Color(r, g, b, 1.0) {}
constexpr Color(): Color(0,0,0,1) {}
constexpr Color()
: Color(0, 0, 0, 1) {}
float *valuePointer() {
return &r;
@ -22,12 +28,11 @@ struct Color {
constexpr Color brighter(float factor = 0.7) const {
return Color(r / factor, g / factor, b / factor, a);
}
};
class Colors {
public:
public:
static constexpr Color RED = Color(1.0, 0.0, 0.0);
static constexpr Color ORANGE = Color(1.0, 0.5, 0.0);
static constexpr Color YELLOW = Color(1.0, 1.0, 0.0);

View File

@ -1,14 +1,14 @@
#pragma once
#include "playercontroller.h"
#include "input.h"
#include "playercontroller.h"
namespace kek {
class DefaultPlayerController: public PlayerController {
public:
glm::vec3 gravity = glm::vec3(0,-9.81,0);
public:
glm::vec3 gravity = glm::vec3(0, -9.81, 0);
float minSlideAngle = 5;
float maxWalkAngle = 60;
float jumpVelocity = 3;
@ -28,7 +28,6 @@ public:
virtual glm::vec3 move(glm::vec3 movement);
virtual void update();
};
}

View File

@ -4,8 +4,8 @@
#include FT_FREETYPE_H
#include <glm/glm.hpp>
#include <string>
#include <map>
#include <string>
#include "color.h"
#include "resource.h"
@ -64,7 +64,7 @@ struct TextBlock {
class TextObject {
private:
private:
Font *font;
std::string text;
@ -73,7 +73,7 @@ private:
int width;
int height;
public:
public:
std::map<unsigned int, TextBlock> blocks;
TextObject(Font *font, std::string text);
@ -96,18 +96,17 @@ public:
TextMetrics getMetrics(int sizePixels);
private:
private:
void destroy();
void allocateBuffer(TextBlock *block, int numChars);
void loadChars();
};
class Font {
private:
private:
int lineHeight;
int ascender;
int descender;
@ -117,8 +116,7 @@ private:
std::map<unsigned int, CharacterBlock> characterBlocks;
public:
public:
Font(std::string path);
~Font();
@ -151,9 +149,8 @@ public:
// Draws text centered around (x,y)
void drawTextCentered(TextObject *textObject, glm::mat4 projection, int x, int y, int sizePixels, Color color);
private:
private:
CharacterBlock generateCharacterBlock(unsigned int block);
};
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "object.h"
#include "mesh.h"
#include "object.h"
#include "physics.h"
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
@ -10,10 +10,10 @@ namespace kek {
class GameObject: public RotateableObject {
protected:
protected:
std::vector<Mesh *> meshes;
public:
public:
PhysicsObjectData *physics;
GameObject();
@ -31,7 +31,7 @@ public:
virtual void rotateTo(glm::quat rotation);
virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0,1,0))); };
virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0, 1, 0))); };
virtual glm::quat getRotation();
@ -40,7 +40,6 @@ public:
virtual void moveTo(glm::vec3 position);
virtual glm::vec3 getPosition();
};
}

View File

@ -4,13 +4,13 @@
#include <memory>
#include <vector>
#include "input.h"
#include "camera.h"
#include "fonts.h"
#include "input.h"
#include "player.h"
#include "scene.h"
#include "texture.h"
#include "fonts.h"
#include "ui.h"
#include "player.h"
namespace kek {

View File

@ -1,5 +1,9 @@
#pragma once
#include <map>
#include "../input.h"
namespace kek {
struct ActiveKeyboardCapture {
@ -26,7 +30,7 @@ namespace Input {
void onCursorPosCallback(GLFWwindow *window, double x, double y);
void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
void onKeyCharCallback(GLFWwindow *window, unsigned int codepoint);
void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void onMouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
}

View File

@ -1,7 +1,10 @@
#pragma once
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <btBulletDynamicsCommon.h>
#include <glm/glm.hpp>
#include "../physics.h"
namespace kek {
@ -17,29 +20,29 @@ struct PlayerPhysicsObjectData: public PhysicsObjectData {
btGhostObject *jumpCollider;
};
struct ClosestNotSelfConvexResultCallback : public btCollisionWorld::ConvexResultCallback {
ClosestNotSelfConvexResultCallback(const btVector3& convexFromWorld, const btVector3& convexToWorld, btCollisionObject *self) :
m_self(self),
struct ClosestNotSelfConvexResultCallback: public btCollisionWorld::ConvexResultCallback {
ClosestNotSelfConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, btCollisionObject *self)
: m_self(self),
m_convexFromWorld(convexFromWorld),
m_convexToWorld(convexToWorld),
m_hitCollisionObject(0){}
m_hitCollisionObject(0) {}
btCollisionObject *m_self;
btVector3 m_convexFromWorld; //used to calculate hitPointWorld from hitFraction
btVector3 m_convexFromWorld; // used to calculate hitPointWorld from hitFraction
btVector3 m_convexToWorld;
btVector3 m_hitNormalWorld;
btVector3 m_hitPointWorld;
const btCollisionObject* m_hitCollisionObject;
const btCollisionObject *m_hitCollisionObject;
virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& convexResult, bool normalInWorldSpace) {
virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) {
if(convexResult.m_hitCollisionObject == m_self) return 1.0f;
m_closestHitFraction = convexResult.m_hitFraction;
m_hitCollisionObject = convexResult.m_hitCollisionObject;
if (normalInWorldSpace) {
if(normalInWorldSpace) {
m_hitNormalWorld = convexResult.m_hitNormalLocal;
}else{
///need to transform normal into worldspace
} else {
/// need to transform normal into worldspace
m_hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal;
}
m_hitPointWorld = convexResult.m_hitPointLocal;

View File

@ -1,5 +1,7 @@
#pragma once
#include "../ui.h"
namespace kek {
struct UIData {

View File

@ -15,7 +15,7 @@ enum class LightType {
class Light {
public:
public:
glm::vec3 color;
Light(glm::vec3 color);
@ -23,12 +23,11 @@ public:
virtual ~Light();
virtual LightType getType() = 0;
};
class PointLight: public Light, public DefaultObject {
public:
public:
float constant, linear, quadratic;
PointLight(glm::vec3 color, float constant, float linear, float quadratic);
@ -36,12 +35,11 @@ public:
~PointLight();
LightType getType();
};
class DirectionalLight: public Light {
public:
public:
glm::vec3 direction;
DirectionalLight(glm::vec3 color, glm::vec3 direction);
@ -51,12 +49,11 @@ public:
LightType getType();
void lookAt(glm::vec3 direction);
};
class SpotLight: public Light, public DefaultObject {
public:
public:
glm::vec3 direction;
float constant, linear, quadratic;
float innerCutoff, outerCutoff;
@ -68,12 +65,11 @@ public:
LightType getType();
void lookAt(glm::vec3 direction);
};
class LightList {
public:
public:
std::vector<PointLight *> point;
std::vector<DirectionalLight *> directional;
std::vector<SpotLight *> spot;
@ -81,7 +77,6 @@ public:
LightList();
void add(Light *light);
};
}

View File

@ -1,10 +1,10 @@
#pragma once
#include <glm/glm.hpp>
#include <vector>
#include <cstdint>
#include <glm/glm.hpp>
#include <iostream>
#include <memory>
#include <vector>
#include "shader.h"
#include "texture.h"
@ -17,24 +17,22 @@ struct Vertex {
glm::vec2 texCoords;
Vertex(glm::vec3 pos, glm::vec3 normal, glm::vec2 texCoords);
};
struct Material {
public:
public:
std::shared_ptr<Texture> ambient;
std::shared_ptr<Texture> diffuse;
std::shared_ptr<Texture> specular;
float shininess;
Material(std::shared_ptr<Texture> ambient, std::shared_ptr<Texture> diffuse, std::shared_ptr<Texture> specular, float shininess);
};
class Mesh {
public:
public:
std::vector<Vertex> vertices;
std::vector<uint32_t> indices;
Material *material;
@ -46,7 +44,6 @@ public:
~Mesh();
void draw(Shader *shader);
};
}

View File

@ -1,13 +1,13 @@
#pragma once
#include "playercontroller.h"
#include "input.h"
#include "playercontroller.h"
namespace kek {
class NoclipPlayerController: public PlayerController {
public:
public:
float noclipSpeed = 6;
KeyBinding keyForward = KEK_INVALID_ID;
@ -24,7 +24,6 @@ public:
virtual glm::vec3 move(glm::vec3 movement);
virtual void update();
};
}

View File

@ -7,8 +7,8 @@ namespace kek {
class Object {
public:
virtual ~Object() {};
public:
virtual ~Object(){};
virtual void translate(glm::vec3 delta) = 0;
@ -21,31 +21,29 @@ public:
virtual void moveTo(glm::vec3 position) = 0;
virtual glm::vec3 getPosition() = 0;
};
class DefaultObject: public Object {
protected:
protected:
glm::vec3 position;
public:
public:
DefaultObject();
virtual ~DefaultObject() {};
virtual ~DefaultObject(){};
virtual void translate(glm::vec3 delta);
virtual void moveTo(glm::vec3 position);
virtual glm::vec3 getPosition();
};
class RotateableObject: public Object {
public:
virtual ~RotateableObject() {};
public:
virtual ~RotateableObject(){};
virtual void rotate(float angle, glm::vec3 axis) = 0;
@ -56,18 +54,17 @@ public:
virtual void lookAtPos(glm::vec3 position);
virtual glm::quat getRotation() = 0;
};
class DefaultRotateableObject: public RotateableObject, public DefaultObject {
protected:
protected:
glm::quat rotation;
public:
public:
DefaultRotateableObject();
virtual ~DefaultRotateableObject() {};
virtual ~DefaultRotateableObject(){};
virtual void rotate(float angle, glm::vec3 axis);
@ -82,7 +79,6 @@ public:
virtual void moveTo(glm::vec3 position) { DefaultObject::moveTo(position); };
virtual glm::vec3 getPosition() { return DefaultObject::getPosition(); };
};
}

View File

@ -2,8 +2,8 @@
#include <map>
#include "types.h"
#include "mesh.h"
#include "types.h"
namespace kek::ObjParser {

View File

@ -7,7 +7,7 @@ namespace kek {
class Player: public RotateableObject {
public:
public:
PlayerPhysicsObjectData *physics;
PlayerController *controller;
bool noclip = false;
@ -19,7 +19,7 @@ public:
virtual void rotateTo(glm::quat rotation);
virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0,1,0))); };
virtual void lookAt(glm::vec3 direction) { rotateTo(glm::quatLookAt(glm::normalize(direction), glm::vec3(0, 1, 0))); };
virtual glm::quat getRotation();
@ -32,7 +32,6 @@ public:
virtual glm::vec3 getEyePosition() { return getPosition() + glm::vec3(0, KEK_PLAYER_EYE_OFFSET, 0); }
virtual glm::vec3 getFootPosition() { return getPosition() - glm::vec3(0, KEK_PLAYER_HEIGHT / 2, 0); };
};
}

View File

@ -6,12 +6,11 @@ namespace kek {
class PlayerController {
public:
public:
virtual ~PlayerController() = 0;
virtual glm::vec3 move(glm::vec3 movement) = 0;
virtual void update() = 0;
};
}

View File

@ -9,7 +9,7 @@ namespace kek {
class Scene {
public:
public:
std::vector<GameObject *> objects;
LightList *lights;
@ -25,7 +25,6 @@ public:
// Draws the scene
void draw(Shader *shader);
};
}

View File

@ -1,13 +1,14 @@
#pragma once
#include <string>
#include <glm/glm.hpp>
#include <string>
#include "constants.h"
namespace kek {
#pragma pack(push, 1)
struct ShaderLight {
float color[3];
float pad;
@ -18,9 +19,10 @@ struct ShaderLight {
float attenuation[3]; // constant, linear, quadratic
float pad4;
float cutoff[2]; // inner, outer
//float lightSpaceMatrix[16]; // mat4
// float lightSpaceMatrix[16]; // mat4
float padding[2];
};
#pragma pack(pop)
// Lighting data for shader
@ -33,7 +35,7 @@ struct LightingData {
class Shader {
public:
public:
unsigned int id;
LightingData *lighting;
@ -46,7 +48,6 @@ public:
void initLighting();
void use();
};
}

View File

@ -4,15 +4,15 @@
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <vector>
#include <string>
#include <memory>
#include <string>
#include <vector>
namespace kek {
class Texture {
public:
public:
GLuint id;
std::string path;
@ -27,7 +27,6 @@ public:
static std::shared_ptr<Texture> load(std::string texturePath);
static std::shared_ptr<Texture> generateColor(glm::vec3 color);
};
}

View File

@ -1,15 +1,15 @@
#pragma once
#include <glm/glm.hpp>
#include <vector>
#include <cstdint>
#include <glm/glm.hpp>
#include <iostream>
#include <vector>
namespace kek {
class MemoryBuffer: public std::streambuf {
public:
public:
char *buffer;
size_t length;
@ -22,7 +22,6 @@ public:
~MemoryBuffer() {
free(buffer);
}
};
}

View File

@ -16,13 +16,20 @@ namespace kek {
struct UIPoint {
int x, y;
UIPoint(int x, int y): x(x), y(y) {}
UIPoint(int x, int y)
: x(x),
y(y) {}
};
struct UIBounds {
int x, y, w, h;
UIBounds(int x, int y, int w, int h): x(x), y(y), w(w), h(h) {}
UIBounds(int x, int y, int w, int h)
: x(x),
y(y),
w(w),
h(h) {}
inline bool contains(UIPoint pos) {
return pos.x > x && pos.y > y && pos.x < x + w && pos.y < y + h;
@ -115,16 +122,15 @@ struct UIValue {
constexpr friend UIValue operator-(const UIValue &lhs, const UIValue &rhs) {
return UIValue(lhs) -= rhs;
}
};
class UIElement {
protected:
protected:
UIElement *parent = nullptr;
std::vector<UIElement *> children;
public:
public:
UIValue x, y;
Origin origin = Origin::TOP_LEFT;
bool clickable = false;
@ -152,13 +158,13 @@ public:
void addChild(UIElement *child);
void removeChild(UIElement *child);
protected:
protected:
int uiToScreen(UIValue val);
static int offsetX(int w, Origin origin);
static int offsetY(int h, Origin origin);
static UIBounds offsetUIBounds(int w, int h, Origin origin);
public:
public:
// Returns the bounds of the element relative to its origin
virtual UIBounds getBounds() = 0;
@ -167,22 +173,21 @@ public:
void hoverAll(UIPoint pos, UIPoint screenPos);
void hoverExitAll();
virtual void hoverEnter(UIPoint pos, UIPoint screenPos) {};
virtual void hover(UIPoint pos, UIPoint screenPos) {};
virtual void hoverExit() {};
virtual void hoverEnter(UIPoint pos, UIPoint screenPos){};
virtual void hover(UIPoint pos, UIPoint screenPos){};
virtual void hoverExit(){};
void clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button);
virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button) {};
virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button){};
bool focusEnterAll(UIPoint pos, UIPoint screenPos);
virtual void focusEnter(UIPoint pos, UIPoint screenPos) {};
virtual void focusExit() {};
virtual void focusEnter(UIPoint pos, UIPoint screenPos){};
virtual void focusExit(){};
UIElement *dragEnterAll(UIPoint pos, UIPoint screenPos);
virtual void dragEnter(UIPoint pos, UIPoint screenPos) {};
virtual void drag(UIPoint pos, UIPoint screenPos) {};
virtual void dragExit(UIPoint pos, UIPoint screenPos) {};
virtual void dragEnter(UIPoint pos, UIPoint screenPos){};
virtual void drag(UIPoint pos, UIPoint screenPos){};
virtual void dragExit(UIPoint pos, UIPoint screenPos){};
};
namespace UI {

View File

@ -13,7 +13,6 @@ class UIWindow: public UIElement {
virtual UIElementType getType();
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
enum class TextMode {
@ -30,10 +29,10 @@ enum class TextBounds {
class TextElement: public UIElement {
protected:
protected:
TextObject *text;
public:
public:
int sizePixels;
Color color;
TextMode textMode;
@ -54,18 +53,17 @@ public:
std::string getText();
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
class RectangleElement: public UIElement {
protected:
protected:
UIValue w, h;
unsigned int vao;
unsigned int vbo;
public:
public:
Color color;
RectangleElement(UIValue x, UIValue y, UIValue w, UIValue h);
@ -77,12 +75,11 @@ public:
virtual UIBounds getBounds();
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
class ButtonElement: public RectangleElement {
public:
public:
TextElement *text;
Color color;
Color hoverColor;
@ -97,7 +94,6 @@ public:
virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button);
virtual void draw(UIPoint screenPos, glm::mat4 projection);
};
}

View File

@ -8,19 +8,25 @@
namespace kek {
template<typename ...Args>
using GenericFunction = void(*)(Args... args);
template <typename... Args>
using GenericFunction = void (*)(Args... args);
template<typename ...Args>
template <typename... Args>
struct GenericCallable {
GenericFunction<Args..., void *> function;
void *data;
GenericCallable(): function(nullptr), data(nullptr) {}
GenericCallable()
: function(nullptr),
data(nullptr) {}
GenericCallable(GenericFunction<Args..., void *> function): function(function), data(nullptr) {};
GenericCallable(GenericFunction<Args..., void *> function)
: function(function),
data(nullptr){};
GenericCallable(GenericFunction<Args..., void *> function, void *data): function(function), data(data) {}
GenericCallable(GenericFunction<Args..., void *> function, void *data)
: function(function),
data(data) {}
void operator()(Args... args) {
if(function == nullptr) return;
@ -39,7 +45,12 @@ float clampCyclic(int value, int min, int max);
float clamp(int value, int min, int max);
enum class CubeFace {
FRONT, BACK, UP, DOWN, LEFT, RIGHT
FRONT,
BACK,
UP,
DOWN,
LEFT,
RIGHT
};
glm::vec3 faceNormal(CubeFace face);

View File

@ -16,37 +16,40 @@ using namespace kek;
static ButtonElement *button;
static KeyboardCapture capture = KEK_INVALID_ID;
void periodicCallback(GLFWwindow *window, void *data){
void periodicCallback(GLFWwindow *window, void *data) {
}
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data){
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) {
}
void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data){
void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data) {
}
void onButtonClick(void *data) {
button->color = Colors::RED;
button->hoverColor = Colors::ORANGE;
capture = Input::captureKeyboardInput(KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) {
capture = Input::captureKeyboardInput(
KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) {
std::u32string str = Unicode::convertStdToU32(button->text->getText());
if(codepoint == KEK_INPUT_DELETE) {
str = str.substr(0, str.length() - 1);
}else {
} else {
str.push_back(codepoint);
}
button->text->setText(Unicode::convertU32ToStd(str));
}, nullptr), KeyCallback([](GLFWwindow *window, int key, int scancode, int action, int mods, void *data) {
},
nullptr),
KeyCallback([](GLFWwindow *window, int key, int scancode, int action, int mods, void *data) {
if(key == GLFW_KEY_ENTER && action == GLFW_PRESS) {
Input::uncaptureKeyboardInput(capture);
}
}, nullptr), Callable([](void *data) {
},
nullptr),
Callable([](void *data) {
button->color = Colors::WHITE;
button->hoverColor = Colors::GRAY;
}, nullptr));
},
nullptr));
}
int main(int argc, char **argv) {
@ -58,7 +61,7 @@ int main(int argc, char **argv) {
{
std::shared_ptr<Texture> tex = Texture::load("image/white.png");
floor->addMesh(genCubeMesh(100, 1, 100, tex, tex, tex));
btCollisionShape *shape = new btBoxShape(btVector3(50,0.5,50));
btCollisionShape *shape = new btBoxShape(btVector3(50, 0.5, 50));
floor->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT);
scene->addObject(floor);
}
@ -67,10 +70,10 @@ int main(int argc, char **argv) {
{
std::shared_ptr<Texture> tex = Texture::load("image/white.png");
wall->addMesh(genCubeMesh(1, 10, 50, tex, tex, tex));
btCollisionShape *shape = new btBoxShape(btVector3(0.5,5,25));
btCollisionShape *shape = new btBoxShape(btVector3(0.5, 5, 25));
wall->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT);
wall->moveTo(glm::vec3(0,2.5,0));
wall->rotate(M_PI / 4, glm::vec3(0,0,1));
wall->moveTo(glm::vec3(0, 2.5, 0));
wall->rotate(M_PI / 4, glm::vec3(0, 0, 1));
scene->addObject(wall);
}
@ -84,7 +87,7 @@ int main(int argc, char **argv) {
Mesh *mesh2 = ObjParser::loadMesh("object/cube_colored/Cube.obj");
GameObject *test3 = new GameObject();
btCollisionShape *shape2 = new btBoxShape(btVector3(1,1,1));
btCollisionShape *shape2 = new btBoxShape(btVector3(1, 1, 1));
test3->addPhysics(shape2, 0, btCollisionObject::CF_STATIC_OBJECT);
test3->addMesh(mesh2);
test3->moveTo(glm::vec3(2, 1, 2));
@ -92,7 +95,7 @@ int main(int argc, char **argv) {
for(int i = 0; i < 10; i++) {
GameObject *test2 = new GameObject();
btCollisionShape *shape = new btBoxShape(btVector3(1,1,1));
btCollisionShape *shape = new btBoxShape(btVector3(1, 1, 1));
test2->addPhysics(shape, 10);
test2->addMesh(ObjParser::loadMesh("object/cube_colored/Cube.obj"));
test2->moveTo(glm::vec3(1.0f, 5.0f, 3 * i));
@ -100,15 +103,15 @@ int main(int argc, char **argv) {
}
PointLight *light = new PointLight(glm::vec3(1), 1, 0, 0.1);
light->moveTo(glm::vec3(0,1,0));
light->moveTo(glm::vec3(0, 1, 0));
scene->lights->add(light);
//DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1));
//scene->lights->add(l);
// DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1));
// scene->lights->add(l);
//SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f));
//spot->moveTo(glm::vec3(0, 0, 5));
//scene->lights->add(spot);
// SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f));
// spot->moveTo(glm::vec3(0, 0, 5));
// scene->lights->add(spot);
Engine::setActiveScene(scene);