Update KekEngine, Add basic scene
This commit is contained in:
parent
78b0343067
commit
413f4831a5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
build/
|
build/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.cache/
|
||||||
|
2
dependencies/kekengine
vendored
2
dependencies/kekengine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 3d9dd14fd00d978c49ae591110756a4100f1b307
|
Subproject commit da91e92124dec9a11b69bf3e63c4fa5b7d4781df
|
@ -1,32 +1,87 @@
|
|||||||
#include <kekengine.h>
|
#include <glm/geometric.hpp>
|
||||||
#include <ui.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||||
|
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||||
|
#include "LinearMath/btVector3.h"
|
||||||
|
#include "constants.h"
|
||||||
|
#include "engine.h"
|
||||||
|
#include "gameobject.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "internal/physics.h"
|
||||||
|
#include "kekengine.h"
|
||||||
|
#include "light.h"
|
||||||
|
#include "mesh.h"
|
||||||
|
#include "player.h"
|
||||||
|
#include "scene.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "uielements.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
using namespace kek;
|
using namespace kek;
|
||||||
|
|
||||||
void buttonClicked(void *) {
|
static ButtonElement *buttonPlay;
|
||||||
std::cout << "Someone clicked me! :O" << std::endl;
|
|
||||||
|
void startGame(void *) {
|
||||||
|
buttonPlay->visible = false;
|
||||||
|
|
||||||
|
Scene *scene = new Scene();
|
||||||
|
|
||||||
|
std::shared_ptr<Texture> wallpaper = Texture::load("image/wallpaper.png");
|
||||||
|
std::shared_ptr<Texture> white = Texture::generateColor(glm::vec3(1));
|
||||||
|
|
||||||
|
SpotLight *flashlight = new SpotLight(glm::vec3(1), glm::vec3(0), 2, 5, 5, 0.5, 0.7);
|
||||||
|
flashlight->moveTo(Engine::getPlayer()->getPosition());
|
||||||
|
|
||||||
|
Input::addPeriodicCallback(PeriodicCallback([](GLFWwindow *window, void *light) {
|
||||||
|
SpotLight *fl = (SpotLight *) light;
|
||||||
|
glm::vec3 playerRight = glm::cross(Engine::getActiveCamera()->direction, glm::vec3(0, 1, 0));
|
||||||
|
fl->moveTo(Engine::getPlayer()->getPosition() + glm::normalize(playerRight) * 0.3f);
|
||||||
|
fl->lookAt(Engine::getActiveCamera()->direction);
|
||||||
|
},
|
||||||
|
flashlight));
|
||||||
|
|
||||||
|
std::shared_ptr<Texture> cubeTexture = Texture::generateColor(glm::vec3(1, 0, 0));
|
||||||
|
GameObject *floor = new GameObject();
|
||||||
|
floor->addPhysics(new btBoxShape(btVector3(50, 0.5, 50)), 0, btCollisionObject::CF_STATIC_OBJECT);
|
||||||
|
floor->addMesh(genCubeMesh(100, 1, 100, cubeTexture, cubeTexture, white));
|
||||||
|
scene->addObject(floor);
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < 10; i++) {
|
||||||
|
GameObject *cube = new GameObject();
|
||||||
|
cube->addPhysics(new btBoxShape(btVector3(0.5, 0.5, 0.5)), 1);
|
||||||
|
cube->addMesh(genCubeMesh(1, 1, 1, wallpaper, wallpaper, white));
|
||||||
|
cube->moveTo(glm::vec3(5, i * 1.1f, 0));
|
||||||
|
scene->addObject(cube);
|
||||||
|
}
|
||||||
|
|
||||||
|
scene->lights->add(flashlight);
|
||||||
|
scene->lights->add(new DirectionalLight(glm::vec3(0.001), glm::vec3(-0.1, -1, 0.1)));
|
||||||
|
|
||||||
|
Engine::setActiveScene(scene);
|
||||||
|
|
||||||
|
Engine::getPlayer()->moveTo(glm::vec3(0, KEK_PLAYER_HEIGHT - KEK_PLAYER_RADIUS, 0));
|
||||||
|
Engine::getActiveCamera()->lookAt(glm::vec3(0, 0, 1));
|
||||||
|
|
||||||
|
Input::setCursorMode(GLFWCursorMode::CAPTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if(Engine::init() != KEK_SUCCESS) return 1;
|
if(Engine::init() != KEK_SUCCESS) return 1;
|
||||||
|
|
||||||
Scene *scene = new Scene();
|
buttonPlay = new ButtonElement(uiSw(0.5), uiSh(0.5), uiPx(500), uiPx(75));
|
||||||
Engine::setActiveScene(scene);
|
buttonPlay->color = Colors::WHITE;
|
||||||
|
buttonPlay->hoverColor = Colors::GRAY;
|
||||||
|
buttonPlay->origin = Origin::CENTER;
|
||||||
|
buttonPlay->text->setText("Play");
|
||||||
|
buttonPlay->text->sizePixels = 50;
|
||||||
|
buttonPlay->text->color = Colors::BLACK;
|
||||||
|
buttonPlay->onClick = Callable(startGame);
|
||||||
|
|
||||||
ButtonElement *button = new ButtonElement(uiPx(10), uiPx(50), uiPx(300), uiPx(100));
|
UI::addElement(buttonPlay);
|
||||||
//button->origin = Origin::BOTTOM_LEFT;
|
Input::setCursorMode(GLFWCursorMode::FREE);
|
||||||
button->color = Colors::CYAN;
|
|
||||||
button->hoverColor = Colors::WHITE;
|
|
||||||
//button->text->origin = Origin::BOTTOM_LEFT;
|
|
||||||
button->text->color = Colors::RED;
|
|
||||||
button->text->setText("Click me pls uwu!");
|
|
||||||
button->onClick = Callable(buttonClicked, nullptr);
|
|
||||||
|
|
||||||
//TextElement *element = new TextElement(uiPx(10), uiSh(1) - uiPx(10));
|
|
||||||
//element->origin = Origin::BOTTOM_LEFT;
|
|
||||||
//element->setText("Hello World!");
|
|
||||||
UI::addElement(button);
|
|
||||||
|
|
||||||
if(Engine::start() != KEK_SUCCESS) return 1;
|
if(Engine::start() != KEK_SUCCESS) return 1;
|
||||||
|
|
||||||
|
BIN
src/kekrooms/res/image/wallpaper.png
Normal file
BIN
src/kekrooms/res/image/wallpaper.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 746 KiB |
Loading…
Reference in New Issue
Block a user