Seperate Chunk, Entity, and GUI mesh related structures
parent
1bc66e4d60
commit
43cb70da4f
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/workspace.xml
|
||||
|
||||
# Datasource local storage ignored files
|
||||
/dataSources.local.xml
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ClangdSettings">
|
||||
<option name="clangWarnings" value="-Wno-unused-variable,-Wno-shadow,-Wshadow-field-in-constructor-modified,-Wshadow-ivar,-Wno-switch,-Wno-parentheses,-Wbitwise-op-parentheses,-Wdangling-else,-Wlogical-not-parentheses,-Wlogical-op-parentheses,-Woverloaded-shift-op-parentheses,-Wparentheses-equality,-Wshift-op-parentheses,-Werror=implicit-function-declaration,-Wno-unknown-pragmas" />
|
||||
</component>
|
||||
</project>
|
|
@ -28,13 +28,14 @@ set (DYNAMIC_LIBRARY_HEADERS
|
|||
lib/dynamic/enet/include # ENet headers.
|
||||
lib/dynamic/noise/include # Noise headers.
|
||||
lib/dynamic/lua5.3/include # Lua headers.
|
||||
lib/dynamic/assimp/include # Assimp headers.
|
||||
)
|
||||
|
||||
include_directories (${DYNAMIC_LIBRARY_HEADERS})
|
||||
|
||||
# Add source files to the executable as a library
|
||||
add_subdirectory (src)
|
||||
add_executable (${MAIN_EXEC_NAME} src/Main.cpp)
|
||||
add_executable (${MAIN_EXEC_NAME} src/Main.cpp src/StartGame.h)
|
||||
target_link_libraries (${MAIN_EXEC_NAME} zeusCore)
|
||||
|
||||
# Include OpenGL
|
||||
|
@ -42,7 +43,7 @@ find_package (OpenGL REQUIRED)
|
|||
target_link_libraries(${MAIN_EXEC_NAME} ${OPENGL_gl_LIBRARY})
|
||||
|
||||
# Build and include GLFW
|
||||
find_package (glfw3 REQUIRED)
|
||||
#find_package (glfw3 REQUIRED)
|
||||
set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||
set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
|
@ -55,7 +56,7 @@ find_package (GLEW REQUIRED)
|
|||
target_link_libraries (${MAIN_EXEC_NAME} ${GLEW_LIBRARIES})
|
||||
|
||||
# Include the other dynamic libraries - End goal would be to build these at compile time
|
||||
set (ZEUS_LIBRARIES pthread lua5.3 z enet noise)
|
||||
set (ZEUS_LIBRARIES pthread lua5.3 z enet noise assimp)
|
||||
|
||||
target_link_libraries (${MAIN_EXEC_NAME} ${ZEUS_LIBRARIES})
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#version 420 core
|
||||
|
||||
in vec4 colorData;
|
||||
in vec3 colorBlend;
|
||||
in float useTex;
|
||||
in vec4 colorData;
|
||||
in vec3 colorBlend;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
layout (binding = 0) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
if (useTex > 0.5) {
|
||||
if (useTex > 0.5)
|
||||
fragColor = texture(tex, colorData.xy) * vec4(colorBlend, 1);
|
||||
}
|
||||
else {
|
||||
else
|
||||
fragColor = colorData * vec4(colorBlend, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#version 420 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 0) in vec2 aPos;
|
||||
layout (location = 1) in vec4 aColorData;
|
||||
layout (location = 2) in vec3 aColorBlend;
|
||||
layout (location = 3) in float aUseTex;
|
||||
layout (location = 4) in vec3 aNormal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 ortho;
|
||||
|
||||
out vec4 colorData;
|
||||
out vec3 colorBlend;
|
||||
out float useTex;
|
||||
out vec4 colorData;
|
||||
out vec3 colorBlend;
|
||||
|
||||
void main() {
|
||||
gl_Position = ortho * model * vec4(aPos, 1.0);
|
||||
useTex = aUseTex;
|
||||
gl_Position = ortho * model * vec4(aPos, 0, 1);
|
||||
colorData = aColorData;
|
||||
colorBlend = aColorBlend;
|
||||
useTex = aUseTex;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
set(ZEUS_SRC_FILES
|
||||
game/graph/ChunkMesh.cpp
|
||||
game/graph/ChunkMesh.h
|
||||
game/entity/Entity.cpp
|
||||
game/entity/Entity.h
|
||||
game/entity/world/Entity.cpp
|
||||
game/entity/world/Entity.h
|
||||
game/graph/Shader.cpp
|
||||
game/graph/Shader.h
|
||||
game/graph/window/Window.cpp
|
||||
|
@ -20,7 +20,7 @@ set(ZEUS_SRC_FILES
|
|||
def/block/MeshPart.cpp
|
||||
def/block/MeshPart.h
|
||||
def/block/ShaderMod.h
|
||||
game/scene/world/graph/MeshVertex.h
|
||||
game/scene/world/graph/BlockModelVertex.h
|
||||
game/scene/world/LocalWorld.cpp
|
||||
game/scene/world/LocalWorld.h
|
||||
world/chunk/BlockChunk.cpp
|
||||
|
@ -181,6 +181,20 @@ set(ZEUS_SRC_FILES
|
|||
api/LuaMod.cpp
|
||||
def/ItemDef.h
|
||||
def/DefinitionAtlas.cpp
|
||||
def/block/BlockModel.h api/modules/sRegisterItem.h def/texture/Font.cpp def/texture/Font.h)
|
||||
def/block/BlockModel.h
|
||||
api/modules/sRegisterItem.h
|
||||
def/texture/Font.cpp
|
||||
def/texture/Font.h
|
||||
def/entity/Model.cpp
|
||||
def/entity/Model.h
|
||||
game/graph/EntityVertex.h
|
||||
game/graph/ChunkVertex.h
|
||||
game/graph/Mesh.cpp
|
||||
game/graph/Mesh.h
|
||||
game/graph/GuiMesh.cpp
|
||||
game/graph/GuiMesh.h
|
||||
game/graph/GuiVertex.h
|
||||
game/entity/hud/GuiEntity.cpp
|
||||
game/entity/hud/GuiEntity.h)
|
||||
|
||||
add_library (zeusCore ${ZEUS_SRC_FILES})
|
95
src/Main.cpp
95
src/Main.cpp
|
@ -1,96 +1,19 @@
|
|||
/*
|
||||
* Zepha, designed, developed, and created by Nicole Collings
|
||||
* This is my child, and I hope you like it.
|
||||
* Copyright 2018 - present Nicole Collings, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wconversion"
|
||||
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define CUTE_FILES_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#include "game/Client.h"
|
||||
#include "server/Server.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
uint64_t constexpr mix(char m, uint64_t s) {
|
||||
return ((s<<7) + ~(s>>3)) + ~m;
|
||||
}
|
||||
uint64_t constexpr hashStr(const char * m) {
|
||||
return (*m) ? mix(*m, hashStr(m+1)) : 0;
|
||||
}
|
||||
#include "StartGame.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Address addr {"127.0.0.1", 32000};
|
||||
|
||||
enum class Mode {
|
||||
NONE, CLIENT, SERVER, LOCAL_SERVER
|
||||
};
|
||||
|
||||
//Collect arguments into `args` map
|
||||
std::map<std::string, std::string> args;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
std::string arg(argv[i]);
|
||||
size_t equals = arg.find('=');
|
||||
std::string first = (equals == -1) ? arg : arg.substr(0, equals);
|
||||
|
||||
if (args.count(first)) {
|
||||
std::cout << Log::err << "Duplicate argument " << first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
if (equals == -1) args.emplace(first, "");
|
||||
else {
|
||||
if (equals == arg.length() - 1) {
|
||||
std::cout << Log::err << "Empty equals-assignment " << first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
args.emplace(first, arg.substr(equals + 1, arg.length()));
|
||||
}
|
||||
}
|
||||
|
||||
Mode mode = Mode::CLIENT;
|
||||
|
||||
//Parse the arguments map
|
||||
for (auto arg : args) {
|
||||
switch (hashStr(arg.first.c_str())) {
|
||||
default: {
|
||||
std::cout << Log::err << "Invalid argument " << arg.first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
case hashStr("--mode"): {
|
||||
if (arg.second == "client") mode = Mode::CLIENT;
|
||||
else if (arg.second == "server") mode = Mode::SERVER;
|
||||
else if (arg.second == "local" ) mode = Mode::LOCAL_SERVER;
|
||||
else std::cout << Log::err << "Invalid mode argument." << Log::endl;
|
||||
break;
|
||||
}
|
||||
case hashStr("--port"): {
|
||||
addr.port = stoi(arg.second);
|
||||
}
|
||||
case hashStr("--address"): {
|
||||
addr.host = arg.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Start the game
|
||||
switch (mode) {
|
||||
default: {
|
||||
std::cout << Log::err << "Mode not setText." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
case Mode::CLIENT: {
|
||||
Client c(argv[0], addr, 1366, 768);
|
||||
break;
|
||||
}
|
||||
case Mode::LOCAL_SERVER: {
|
||||
Client c(argv[0], addr, 1366, 768);
|
||||
break;
|
||||
}
|
||||
case Mode::SERVER: {
|
||||
Server s(argv[0], addr.port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return StartGame(argc, argv);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// Created by aurailus on 22/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_STARTGAME_H
|
||||
#define ZEUS_STARTGAME_H
|
||||
|
||||
#include "game/Client.h"
|
||||
#include "server/Server.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
uint64_t constexpr mix(char m, uint64_t s) {
|
||||
return ((s<<7) + ~(s>>3)) + ~m;
|
||||
}
|
||||
uint64_t constexpr hashStr(const char * m) {
|
||||
return (*m) ? mix(*m, hashStr(m+1)) : 0;
|
||||
}
|
||||
|
||||
int StartGame(int argc, char* argv[]) {
|
||||
Address addr {"127.0.0.1", 32000};
|
||||
|
||||
enum class Mode {
|
||||
NONE, CLIENT, SERVER, LOCAL_SERVER
|
||||
};
|
||||
|
||||
//Collect arguments into `args` map
|
||||
std::map<std::string, std::string> args;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
std::string arg(argv[i]);
|
||||
size_t equals = arg.find('=');
|
||||
std::string first = (equals == -1) ? arg : arg.substr(0, equals);
|
||||
|
||||
if (args.count(first)) {
|
||||
std::cout << Log::err << "Duplicate argument " << first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
if (equals == -1) args.emplace(first, "");
|
||||
else {
|
||||
if (equals == arg.length() - 1) {
|
||||
std::cout << Log::err << "Empty equals-assignment " << first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
args.emplace(first, arg.substr(equals + 1, arg.length()));
|
||||
}
|
||||
}
|
||||
|
||||
Mode mode = Mode::CLIENT;
|
||||
|
||||
//Parse the arguments map
|
||||
for (auto arg : args) {
|
||||
switch (hashStr(arg.first.c_str())) {
|
||||
default: {
|
||||
std::cout << Log::err << "Invalid argument " << arg.first << "." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
case hashStr("--mode"): {
|
||||
if (arg.second == "client") mode = Mode::CLIENT;
|
||||
else if (arg.second == "server") mode = Mode::SERVER;
|
||||
else if (arg.second == "local" ) mode = Mode::LOCAL_SERVER;
|
||||
else std::cout << Log::err << "Invalid mode argument." << Log::endl;
|
||||
break;
|
||||
}
|
||||
case hashStr("--port"): {
|
||||
addr.port = static_cast<unsigned short>(stoi(arg.second));
|
||||
}
|
||||
case hashStr("--address"): {
|
||||
addr.host = arg.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Start the game
|
||||
switch (mode) {
|
||||
default: {
|
||||
std::cout << Log::err << "Mode not setText." << Log::endl;
|
||||
return -1;
|
||||
}
|
||||
case Mode::CLIENT: {
|
||||
Client c(argv[0], addr, 1366, 768);
|
||||
break;
|
||||
}
|
||||
case Mode::LOCAL_SERVER: {
|
||||
Client c(argv[0], addr, 1366, 768);
|
||||
break;
|
||||
}
|
||||
case Mode::SERVER: {
|
||||
Server s(argv[0], addr.port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_STARTGAME_H
|
|
@ -98,7 +98,7 @@ LocalRegisterBlocks::LocalRegisterBlocks(sol::table& zeus, LocalDefs &defs) {
|
|||
if (points.size() % 20 != 0) throw "Points array is ill-formed. (Not a multiple of 20 values)";
|
||||
|
||||
//Populate the Vertices and Indices vectors from the points table
|
||||
std::vector<MeshVertex> vertices;
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (int i = 1; i <= points.size()/5; i++) {
|
||||
|
|
|
@ -98,7 +98,7 @@ ServerRegisterBlocks::ServerRegisterBlocks(sol::table& zeus, ServerDefs &defs) {
|
|||
if (points.size() % 20 != 0) throw "Points array is ill-formed. (Not a multiple of 20 values)";
|
||||
|
||||
//Populate the Vertices and Indices vectors from the points table
|
||||
std::vector<MeshVertex> vertices;
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (int i = 1; i <= points.size()/5; i++) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "MeshPart.h"
|
||||
|
||||
MeshPart::MeshPart(const std::vector<MeshVertex>& vertices, const std::vector<unsigned int>& indices, std::shared_ptr<AtlasRef> texture) :
|
||||
MeshPart::MeshPart(const std::vector<BlockModelVertex>& vertices, const std::vector<unsigned int>& indices, std::shared_ptr<AtlasRef> texture) :
|
||||
vertices(vertices),
|
||||
indices(indices),
|
||||
texture(texture) {
|
||||
|
@ -16,9 +16,9 @@ MeshPart::MeshPart(const std::vector<MeshVertex>& vertices, const std::vector<un
|
|||
//Iterate through the indices to find all used vertices to add normals and adjust texture coordinates.
|
||||
for (int i = 0; i < this->indices.size()/3; i++) {
|
||||
//Get the three vertices
|
||||
MeshVertex& p1 = this->vertices[this->indices[i*3]];
|
||||
MeshVertex& p2 = this->vertices[this->indices[i*3 + 1]];
|
||||
MeshVertex& p3 = this->vertices[this->indices[i*3 + 2]];
|
||||
BlockModelVertex& p1 = this->vertices[this->indices[i*3]];
|
||||
BlockModelVertex& p2 = this->vertices[this->indices[i*3 + 1]];
|
||||
BlockModelVertex& p3 = this->vertices[this->indices[i*3 + 2]];
|
||||
|
||||
//Get the normal of the formed triangle
|
||||
glm::vec3 normal = glm::triangleNormal(p1.pos, p2.pos, p3.pos);
|
||||
|
@ -35,7 +35,7 @@ MeshPart::MeshPart(const std::vector<MeshVertex>& vertices, const std::vector<un
|
|||
auto uv = texture->uv;
|
||||
|
||||
//Iterate through the vertices to adjust the texture coordinates to fit the textureAtlas.
|
||||
for (MeshVertex &vertex : this->vertices) {
|
||||
for (BlockModelVertex &vertex : this->vertices) {
|
||||
//Store the old positions in texUVs
|
||||
vertex.texUVs.x = vertex.tex.x;
|
||||
vertex.texUVs.y = vertex.tex.y;
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
#include "ShaderMod.h"
|
||||
#include "../texture/TextureAtlas.h"
|
||||
#include "../../game/scene/world/graph/MeshVertex.h"
|
||||
#include "../../game/scene/world/graph/BlockModelVertex.h"
|
||||
|
||||
struct MeshPart {
|
||||
MeshPart(const std::vector<MeshVertex>& vertices, const std::vector<unsigned int>& indices, std::shared_ptr<AtlasRef> texture);
|
||||
MeshPart(const std::vector<BlockModelVertex>& vertices, const std::vector<unsigned int>& indices, std::shared_ptr<AtlasRef> texture);
|
||||
|
||||
std::vector<MeshVertex> vertices;
|
||||
std::vector<BlockModelVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
std::shared_ptr<AtlasRef> texture;
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// Created by aurailus on 22/08/19.
|
||||
//
|
||||
|
||||
#include "Model.h"
|
||||
|
||||
int Model::create(const std::string &path, TextureAtlas& atlas, const std::string& tex) {
|
||||
this->atlas = &atlas;
|
||||
this->tex = tex;
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
|
||||
|
||||
if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
|
||||
std::cout << "ERROR::ASSIMP::" << importer.GetErrorString() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
processNode(scene->mRootNode, scene);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Model::processNode(aiNode* node, const aiScene* scene) {
|
||||
std::cout << node->mName.data << std::endl;
|
||||
for (uint i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
meshes.push_back(processMesh(mesh, scene));
|
||||
}
|
||||
|
||||
for (uint i = 0; i < node->mNumChildren; i++) {
|
||||
processNode(node->mChildren[i], scene);
|
||||
}
|
||||
}
|
||||
|
||||
EntityMesh Model::processMesh(aiMesh *mesh, const aiScene *scene) {
|
||||
EntityMesh m;
|
||||
|
||||
std::vector<EntityVertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
auto texRef = atlas->getTextureRef(tex);
|
||||
|
||||
for (uint i = 0; i < mesh->mNumVertices; i++) {
|
||||
EntityVertex vertex {};
|
||||
vertex.position.x = mesh->mVertices[i].x;
|
||||
vertex.position.y = mesh->mVertices[i].y;
|
||||
vertex.position.z = mesh->mVertices[i].z;
|
||||
vertex.normal.x = mesh->mNormals[i].x;
|
||||
vertex.normal.y = mesh->mNormals[i].y;
|
||||
vertex.normal.z = mesh->mNormals[i].z;
|
||||
vertex.colorBlend = {1, 1, 1};
|
||||
if (mesh->mTextureCoords[0]) {
|
||||
vertex.useTex = true;
|
||||
vertex.colorData.x = texRef->uv.x + mesh->mTextureCoords[0][i].x * (texRef->uv.z - texRef->uv.x);
|
||||
vertex.colorData.y = texRef->uv.y + mesh->mTextureCoords[0][i].y * (texRef->uv.w - texRef->uv.y);
|
||||
}
|
||||
else {
|
||||
vertex.colorData = {1, 0, 0, 1};
|
||||
}
|
||||
vertices.push_back(vertex);
|
||||
}
|
||||
|
||||
for (uint i = 0; i < mesh->mNumFaces; i++) {
|
||||
aiFace face = mesh->mFaces[i];
|
||||
for (uint j = 0; j < face.mNumIndices; j++) {
|
||||
indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh->mMaterialIndex >= 0) {
|
||||
//TODO: Require list of textures to use with the model, and use those in here to translate texCoords based on idx
|
||||
}
|
||||
|
||||
m.create(vertices, indices);
|
||||
return m;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Created by aurailus on 22/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_MODEL_H
|
||||
#define ZEUS_MODEL_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include "../../game/graph/EntityMesh.h"
|
||||
#include "../texture/TextureAtlas.h"
|
||||
|
||||
class Model {
|
||||
public:
|
||||
Model() = default;
|
||||
int create(const std::string& path, TextureAtlas& atlas, const std::string& tex);
|
||||
|
||||
std::vector<EntityMesh> meshes;
|
||||
private:
|
||||
void processNode(aiNode* node, const aiScene* scene);
|
||||
EntityMesh processMesh(aiMesh* mesh, const aiScene* scene);
|
||||
|
||||
TextureAtlas* atlas = nullptr;
|
||||
std::string tex = "";
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_MODEL_H
|
|
@ -14,57 +14,57 @@ GameGui::GameGui(glm::vec2 bufferSize, TextureAtlas& atlas) {
|
|||
viginette->create(bufferSize, {}, atlas.getTextureRef("viginette"));
|
||||
add(viginette);
|
||||
|
||||
auto root = std::make_shared<GUIRect>("root");
|
||||
root->create(bufferSize, {}, {0, 0, 0, 0.25});
|
||||
add(root);
|
||||
// auto root = std::make_shared<GUIRect>("root");
|
||||
// root->create(bufferSize, {}, {0, 0, 0, 0.25});
|
||||
// add(root);
|
||||
|
||||
auto inv_root = std::make_shared<GUIRect>("inv_root");
|
||||
inv_root->create({648, 270}, {60, 30, 24, 30}, atlas.getTextureRef("inventory"));
|
||||
inv_root->setPos({bufferSize.x / 2 - 354, bufferSize.y / 2 - 90});
|
||||
root->add(inv_root);
|
||||
|
||||
std::array<std::string, 6> mats = {
|
||||
"zeus:materials:stick",
|
||||
"zeus:materials:rock",
|
||||
"zeus:materials:flint",
|
||||
"aurailus:basictools:flint_pickaxe",
|
||||
"aurailus:basictools:flint_hatchet",
|
||||
"aurailus:basictools:flint_shovel"
|
||||
};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 12; j++) {
|
||||
auto inv_slot = std::make_shared<GUIRect>("inv_slot_" + to_string(i) + "_" + to_string(j));
|
||||
inv_slot->create({48, 48}, {}, atlas.getTextureRef(mats[rand() % 6]));
|
||||
inv_slot->setPos({3 + j * 54, 3 + i * 54});
|
||||
inv_root->add(inv_slot);
|
||||
}
|
||||
}
|
||||
|
||||
auto shortcuts_root = std::make_shared<GUIRect>("shortcut_root");
|
||||
shortcuts_root->create({156, 156}, {}, atlas.getTextureRef("inventory_wheel"));
|
||||
shortcuts_root->setPos({bufferSize.x / 2 - 72, bufferSize.y - 200});
|
||||
root->add(shortcuts_root);
|
||||
|
||||
std::array<glm::vec2, 6> vec_roots = {
|
||||
glm::vec2 { 133, -26 },
|
||||
glm::vec2 { 155, 37 },
|
||||
glm::vec2 { 133, 100},
|
||||
glm::vec2 {-241, -26 },
|
||||
glm::vec2 {-263, 37 },
|
||||
glm::vec2 {-241, 100}
|
||||
};
|
||||
|
||||
for (auto i = 0; i < 6; i++) {
|
||||
glm::vec2 vec = vec_roots[i];
|
||||
|
||||
auto shortcut_slot = std::make_shared<GUIRect>("shortcut_slot_" + to_string(i));
|
||||
shortcut_slot->create({216, 54}, {15, 24, 15, 24}, atlas.getTextureRef("inventory_wheel_slot"));
|
||||
shortcut_slot->setPos(vec);
|
||||
shortcuts_root->add(shortcut_slot);
|
||||
}
|
||||
|
||||
root->setVisible(false);
|
||||
// auto inv_root = std::make_shared<GUIRect>("inv_root");
|
||||
// inv_root->create({648, 270}, {60, 30, 24, 30}, atlas.getTextureRef("inventory"));
|
||||
// inv_root->setPos({bufferSize.x / 2 - 354, bufferSize.y / 2 - 90});
|
||||
// root->add(inv_root);
|
||||
//
|
||||
// std::array<std::string, 6> mats = {
|
||||
// "zeus:materials:stick",
|
||||
// "zeus:materials:rock",
|
||||
// "zeus:materials:flint",
|
||||
// "aurailus:basictools:flint_pickaxe",
|
||||
// "aurailus:basictools:flint_hatchet",
|
||||
// "aurailus:basictools:flint_shovel"
|
||||
// };
|
||||
//
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// for (int j = 0; j < 12; j++) {
|
||||
// auto inv_slot = std::make_shared<GUIRect>("inv_slot_" + to_string(i) + "_" + to_string(j));
|
||||
// inv_slot->create({48, 48}, {}, atlas.getTextureRef(mats[rand() % 6]));
|
||||
// inv_slot->setPos({3 + j * 54, 3 + i * 54});
|
||||
// inv_root->add(inv_slot);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// auto shortcuts_root = std::make_shared<GUIRect>("shortcut_root");
|
||||
// shortcuts_root->create({156, 156}, {}, atlas.getTextureRef("inventory_wheel"));
|
||||
// shortcuts_root->setPos({bufferSize.x / 2 - 72, bufferSize.y - 200});
|
||||
// root->add(shortcuts_root);
|
||||
//
|
||||
// std::array<glm::vec2, 6> vec_roots = {
|
||||
// glm::vec2 { 133, -26 },
|
||||
// glm::vec2 { 155, 37 },
|
||||
// glm::vec2 { 133, 100},
|
||||
// glm::vec2 {-241, -26 },
|
||||
// glm::vec2 {-263, 37 },
|
||||
// glm::vec2 {-241, 100}
|
||||
// };
|
||||
//
|
||||
// for (auto i = 0; i < 6; i++) {
|
||||
// glm::vec2 vec = vec_roots[i];
|
||||
//
|
||||
// auto shortcut_slot = std::make_shared<GUIRect>("shortcut_slot_" + to_string(i));
|
||||
// shortcut_slot->create({216, 54}, {15, 24, 15, 24}, atlas.getTextureRef("inventory_wheel_slot"));
|
||||
// shortcut_slot->setPos(vec);
|
||||
// shortcuts_root->add(shortcut_slot);
|
||||
// }
|
||||
//
|
||||
// root->setVisible(false);
|
||||
}
|
||||
|
||||
void GameGui::bufferResized(glm::vec2 bufferSize) {
|
||||
|
@ -74,11 +74,11 @@ void GameGui::bufferResized(glm::vec2 bufferSize) {
|
|||
|
||||
void GameGui::setVisible(bool visible) {
|
||||
GUIComponent::setVisible(visible);
|
||||
get<GUIRect>("root")->setVisible(invOpen);
|
||||
// get<GUIRect>("root")->setVisible(invOpen);
|
||||
}
|
||||
|
||||
void GameGui::setInvOpen(bool open) {
|
||||
get<GUIRect>("root")->setVisible(open);
|
||||
// get<GUIRect>("root")->setVisible(open);
|
||||
invOpen = open;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "components/basic/GUIContainer.h"
|
||||
#include "../../graph/drawable/DrawableGroup.h"
|
||||
#include "../../ClientState.h"
|
||||
#include "../Entity.h"
|
||||
#include "../world/Entity.h"
|
||||
|
||||
class GameGui : public GUIContainer {
|
||||
public:
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// Created by aurailus on 25/11/18.
|
||||
//
|
||||
|
||||
#include "GuiEntity.h"
|
||||
|
||||
GuiEntity::GuiEntity(GuiMesh* mesh) {
|
||||
setMesh(mesh);
|
||||
}
|
||||
|
||||
void GuiEntity::setMesh(GuiMesh* myMesh) {
|
||||
cleanup();
|
||||
this->mesh = myMesh;
|
||||
}
|
||||
|
||||
void GuiEntity::draw(Renderer& renderer) {
|
||||
if (visible) {
|
||||
auto mm = getModelMatrix();
|
||||
renderer.setModelMatrix(mm);
|
||||
mesh->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiEntity::setPos(glm::vec2 position) {
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
glm::vec2 GuiEntity::getPos() {
|
||||
return position;
|
||||
}
|
||||
|
||||
void GuiEntity::setAngle(float angle) {
|
||||
this->angle = angle;
|
||||
}
|
||||
|
||||
float GuiEntity::getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
void GuiEntity::setScale(float scale) {
|
||||
setScale({scale, scale});
|
||||
}
|
||||
|
||||
void GuiEntity::setScale(glm::vec2 scale) {
|
||||
this->scale = scale;
|
||||
}
|
||||
|
||||
glm::vec2 GuiEntity::getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
glm::mat4 GuiEntity::getModelMatrix() {
|
||||
glm::mat4 model = glm::mat4(1.0);
|
||||
|
||||
model = glm::translate(model, {position.x, position.y, 0});
|
||||
model = glm::rotate(model, angle * (GLfloat)(3.14159265 / 180), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
model = glm::scale(model, {scale.x, scale.y, 1});
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
void GuiEntity::cleanup() {
|
||||
delete mesh;
|
||||
mesh = nullptr;
|
||||
}
|
||||
|
||||
GuiEntity::~GuiEntity() {
|
||||
cleanup();
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// Created by aurailus on 25/11/18.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_GUIENTITY_H
|
||||
#define ZEUS_GUIENTITY_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "../../graph/GuiMesh.h"
|
||||
#include "../../graph/drawable/Drawable.h"
|
||||
|
||||
class GuiEntity : public Drawable {
|
||||
public:
|
||||
GuiEntity() = default;
|
||||
explicit GuiEntity(GuiMesh* mesh);
|
||||
void setMesh(GuiMesh* mesh);
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
|
||||
void setPos(glm::vec2 position);
|
||||
glm::vec2 getPos();
|
||||
|
||||
void setAngle(float angle);
|
||||
float getAngle();
|
||||
|
||||
void setScale(float scale);
|
||||
void setScale(glm::vec2 scale);
|
||||
glm::vec2 getScale();
|
||||
|
||||
glm::mat4 getModelMatrix();
|
||||
|
||||
void cleanup();
|
||||
~GuiEntity() override;
|
||||
|
||||
protected:
|
||||
glm::vec2 position {0, 0};
|
||||
glm::vec2 scale {1, 1};
|
||||
GLfloat angle = 0;
|
||||
|
||||
private:
|
||||
GuiMesh* mesh = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_GUIENTITY_H
|
|
@ -1,9 +1,8 @@
|
|||
#include <utility>
|
||||
|
||||
//
|
||||
// Created by aurailus on 27/07/19.
|
||||
//
|
||||
|
||||
#include <utility>
|
||||
#include "GUIComponent.h"
|
||||
|
||||
GUIComponent::GUIComponent(const std::string& key) :
|
||||
|
@ -11,7 +10,7 @@ GUIComponent::GUIComponent(const std::string& key) :
|
|||
|
||||
void GUIComponent::setScale(glm::vec2 scale) {
|
||||
this->scale = scale;
|
||||
entity.setScale({scale.x, scale.y, 1});
|
||||
entity.setScale(scale);
|
||||
}
|
||||
|
||||
glm::vec2 GUIComponent::getScale() {
|
||||
|
@ -29,11 +28,11 @@ glm::vec4 GUIComponent::getPadding() {
|
|||
void GUIComponent::setPos(glm::vec2 pos) {
|
||||
this->pos = pos;
|
||||
if (parent != nullptr) {
|
||||
glm::vec3 parentPos = parent->entity.getPos();
|
||||
pos += glm::vec2{parentPos.x, parentPos.y};
|
||||
pos += glm::vec2{parent->getPadding().w, parent->getPadding().x};
|
||||
glm::vec2 parentPos = parent->entity.getPos();
|
||||
pos += glm::vec2 {parentPos.x, parentPos.y};
|
||||
pos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
|
||||
}
|
||||
entity.setPos({pos.x, pos.y, 0});
|
||||
entity.setPos(pos);
|
||||
for (const auto& child : children) {
|
||||
child->updatePos();
|
||||
}
|
||||
|
@ -76,11 +75,11 @@ void GUIComponent::setVisible(bool visible) {
|
|||
void GUIComponent::updatePos() {
|
||||
glm::vec2 realPos(pos);
|
||||
if (parent != nullptr) {
|
||||
glm::vec3 parentPos = parent->entity.getPos();
|
||||
realPos += glm::vec2{parentPos.x, parentPos.y};
|
||||
realPos += glm::vec2{parent->getPadding().w, parent->getPadding().x};
|
||||
glm::vec2 parentPos = parent->entity.getPos();
|
||||
realPos += glm::vec2 {parentPos.x, parentPos.y};
|
||||
realPos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
|
||||
}
|
||||
entity.setPos({realPos.x, realPos.y, 0});
|
||||
entity.setPos(realPos);
|
||||
for (const auto& child : children) {
|
||||
child->updatePos();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
//#include <unordered_map>
|
||||
#include "../../Entity.h"
|
||||
#include "../GuiEntity.h"
|
||||
|
||||
class GUIComponent : public Drawable {
|
||||
public:
|
||||
|
@ -36,20 +35,18 @@ public:
|
|||
void remove(std::string key);
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
protected:
|
||||
std::string key = "";
|
||||
GUIComponent* parent = nullptr;
|
||||
std::list<std::shared_ptr<GUIComponent>> children;
|
||||
// std::unordered_map<std::string, std::shared_ptr<GUIComponent>> children;
|
||||
|
||||
glm::vec2 pos {};
|
||||
glm::vec2 scale {};
|
||||
glm::vec4 padding {};
|
||||
bool visible = true;
|
||||
|
||||
Entity entity;
|
||||
GuiEntity entity;
|
||||
private:
|
||||
void updatePos();
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <Atlas
|
|||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
|
||||
|
||||
this->length = length;
|
||||
this->maxVal = maxValue;
|
||||
|
@ -22,7 +22,7 @@ void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <Atlas
|
|||
|
||||
history = std::vector<float>(static_cast<unsigned long>(length));
|
||||
|
||||
entity.setMesh(new EntityMesh());
|
||||
entity.setMesh(new GuiMesh());
|
||||
}
|
||||
|
||||
void GUIGraph::pushValue(float value) {
|
||||
|
@ -55,7 +55,7 @@ void GUIGraph::setMax(float max) {
|
|||
}
|
||||
|
||||
void GUIGraph::buildHistogramMesh() {
|
||||
std::vector<EntityVertex> vertices {};
|
||||
std::vector<GuiVertex> vertices {};
|
||||
std::vector<unsigned int> indices {};
|
||||
|
||||
auto uv = texture->uv;
|
||||
|
@ -72,11 +72,11 @@ void GUIGraph::buildHistogramMesh() {
|
|||
float h = num / maxVal;
|
||||
float sec = (float)std::round(9 - fmin(h, 1)*9) * 0.1f;
|
||||
|
||||
auto columnVerts = std::vector<EntityVertex> {
|
||||
{{xOffset, -h, 0}, {uv.x + age * uv.z, uv.y + sec * uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{xOffset + 1,-h, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + sec * uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{xOffset + 1, 0, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{xOffset, 0, 0}, {uv.x + age * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
auto columnVerts = std::vector<GuiVertex> {
|
||||
{{xOffset, -h}, {uv.x + age * uv.z, uv.y + sec * uv.w, 0, 0}, {1, 1, 1}},
|
||||
{{xOffset + 1,-h}, {uv.x + (age+0.01f) * uv.z, uv.y + sec * uv.w, 0, 0}, {1, 1, 1}},
|
||||
{{xOffset + 1, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 0}, {1, 1, 1}},
|
||||
{{xOffset, 0}, {uv.x + age * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 0}, {1, 1, 1}},
|
||||
};
|
||||
|
||||
vertices.insert(vertices.end(), columnVerts.begin(), columnVerts.end());
|
||||
|
@ -92,7 +92,7 @@ void GUIGraph::buildHistogramMesh() {
|
|||
indOffset += 4;
|
||||
}
|
||||
|
||||
auto m = new EntityMesh();
|
||||
auto m = new GuiMesh();
|
||||
m->create(vertices, indices);
|
||||
entity.setMesh(m);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,16 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
|
|||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {color}, {1, 1, 1}, false, {}}, {{0, 1, 0}, {color}, {1, 1, 1}, false, {}},
|
||||
{{1, 1, 0}, {color}, {1, 1, 1}, false, {}}, {{1, 0, 0}, {color}, {1, 1, 1}, false, {}}
|
||||
std::vector<GuiVertex> vertices {
|
||||
{{0, 0}, color, {1, 1, 1}, false}, {{0, 1}, color, {1, 1, 1}, false},
|
||||
{{1, 1}, color, {1, 1, 1}, false}, {{1, 0}, color, {1, 1, 1}, false}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
auto mesh = new GuiMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
|
||||
}
|
||||
|
||||
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4 tr, glm::vec4 bl, glm::vec4 br) {
|
||||
|
@ -34,16 +34,16 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4
|
|||
this->scale = scale;
|
||||
this->padding = padding;
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, tl, {1, 1, 1}, false, {}}, {{0, 1, 0}, bl, {1, 1, 1}, false, {}},
|
||||
{{1, 1, 0}, br, {1, 1, 1}, false, {}}, {{1, 0, 0}, tr, {1, 1, 1}, false, {}}
|
||||
std::vector<GuiVertex> vertices {
|
||||
{{0, 0}, tl, {1, 1, 1}, false}, {{0, 1}, bl, {1, 1, 1}, false},
|
||||
{{1, 1}, br, {1, 1, 1}, false}, {{1, 0}, tr, {1, 1, 1}, false}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
auto mesh = new GuiMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
|
||||
}
|
||||
|
||||
void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRef> texture) {
|
||||
|
@ -55,16 +55,16 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRe
|
|||
this->padding = padding;
|
||||
this->texture = std::move(texture);
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, 0}, {1, 1, 1}, true, {}},
|
||||
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, 0}, {1, 1, 1}, true, {}}
|
||||
std::vector<GuiVertex> vertices {
|
||||
{{0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, 0}, {1, 1, 1}, true},
|
||||
{{0, 1}, {this->texture->uv.x, this->texture->uv.w, 0, 0}, {1, 1, 1}, true},
|
||||
{{1, 1}, {this->texture->uv.z, this->texture->uv.w, 0, 0}, {1, 1, 1}, true},
|
||||
{{1, 0}, {this->texture->uv.z, this->texture->uv.y, 0, 0}, {1, 1, 1}, true}
|
||||
};
|
||||
std::vector<unsigned int> indices {0, 1, 2, 2, 3, 0};
|
||||
|
||||
auto mesh = new EntityMesh();
|
||||
auto mesh = new GuiMesh();
|
||||
mesh->create(vertices, indices);
|
||||
entity.setMesh(mesh);
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, 1});
|
||||
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ void GUIText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm:
|
|||
this->bgcolor = bgcolor;
|
||||
this->color = color;
|
||||
|
||||
entity.setScale({scale.x, scale.y, 1});
|
||||
entity.setScale(scale);
|
||||
|
||||
setText("");
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ void GUIText::setText(std::string text) {
|
|||
this->text = std::move(text);
|
||||
uint indOffset = 0;
|
||||
|
||||
std::vector<EntityVertex> textVertices;
|
||||
std::vector<GuiVertex> textVertices;
|
||||
std::vector<unsigned int> textIndices;
|
||||
|
||||
//Create background rectangles
|
||||
|
@ -43,11 +43,11 @@ void GUIText::setText(std::string text) {
|
|||
if (lineWidth > 0) {
|
||||
lineWidth += 2;
|
||||
|
||||
std::vector<EntityVertex> vertices {
|
||||
{{-1, yOffset - 1, 0}, bgcolor, {1, 1, 1}, false, {}},
|
||||
{{-1, yOffset + h + 1, 0}, bgcolor, {1, 1, 1}, false, {}},
|
||||
{{lineWidth + 1, yOffset + h + 1, 0}, bgcolor, {1, 1, 1}, false, {}},
|
||||
{{lineWidth + 1, yOffset - 1, 0}, bgcolor, {1, 1, 1}, false, {}},
|
||||
std::vector<GuiVertex> vertices {
|
||||
{{-1, yOffset - 1 }, bgcolor, {1, 1, 1}, false},
|
||||
{{-1, yOffset + h + 1}, bgcolor, {1, 1, 1}, false},
|
||||
{{lineWidth + 1, yOffset + h + 1}, bgcolor, {1, 1, 1}, false},
|
||||
{{lineWidth + 1, yOffset - 1 }, bgcolor, {1, 1, 1}, false},
|
||||
};
|
||||
std::vector<uint> indices {
|
||||
indOffset,
|
||||
|
@ -112,11 +112,11 @@ void GUIText::setText(std::string text) {
|
|||
yOffset -= 1;
|
||||
}
|
||||
|
||||
std::vector<EntityVertex> vertices{
|
||||
{{xOffset, yOffset, 0}, {charUVs.x, charUVs.y, 0, 0}, color, true, {}},
|
||||
{{xOffset, yOffset + h, 0}, {charUVs.x, charUVs.w, 0, 0}, color, true, {}},
|
||||
{{xOffset + charWidth, yOffset + h, 0}, {charUVs.z, charUVs.w, 0, 0}, color, true, {}},
|
||||
{{xOffset + charWidth, yOffset, 0}, {charUVs.z, charUVs.y, 0, 0}, color, true, {}},
|
||||
std::vector<GuiVertex> vertices {
|
||||
{{xOffset, yOffset }, {charUVs.x, charUVs.y, 0, 0}, color, true},
|
||||
{{xOffset, yOffset + h}, {charUVs.x, charUVs.w, 0, 0}, color, true},
|
||||
{{xOffset + charWidth, yOffset + h}, {charUVs.z, charUVs.w, 0, 0}, color, true},
|
||||
{{xOffset + charWidth, yOffset }, {charUVs.z, charUVs.y, 0, 0}, color, true},
|
||||
};
|
||||
std::vector<uint> indices{
|
||||
indOffset,
|
||||
|
@ -136,7 +136,7 @@ void GUIText::setText(std::string text) {
|
|||
xOffset += charWidth;
|
||||
}
|
||||
|
||||
auto m = new EntityMesh();
|
||||
auto m = new GuiMesh();
|
||||
m->create(textVertices, textIndices);
|
||||
entity.setMesh(m);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#ifndef ZEUS_STATGRAPH_H
|
||||
#define ZEUS_STATGRAPH_H
|
||||
|
||||
#include "../../../Entity.h"
|
||||
#include "../../../world/Entity.h"
|
||||
#include "../../../../../util/Util.h"
|
||||
#include "../basic/GUIRect.h"
|
||||
#include "../basic/GUIGraph.h"
|
||||
|
|
|
@ -57,7 +57,7 @@ void BlockCrackEntity::addFaces(unsigned int &indOffset, std::vector<EntityVerte
|
|||
|
||||
crackedFaces.push_back(ref);
|
||||
|
||||
for (const MeshVertex &vertex : mp.vertices) {
|
||||
for (const BlockModelVertex &vertex : mp.vertices) {
|
||||
glm::vec3 pushed_pos = vertex.pos;
|
||||
pushed_pos += glm::normalize(vertex.nml) * 0.003f;
|
||||
glm::vec4 tex = {uv.x + (uv.z - uv.x) * vertex.texUVs.x, uv.y + ((uv.w - uv.y) * vertex.texUVs.y), 0, 0};
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
#ifndef ZEUS_BLOCKMODELENTITY_H
|
||||
#define ZEUS_BLOCKMODELENTITY_H
|
||||
|
||||
|
||||
#include "../../../game/entity/Entity.h"
|
||||
#include "Entity.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
|
||||
class BlockCrackEntity : public Entity {
|
||||
|
@ -30,5 +29,4 @@ private:
|
|||
LocalDefs& defs;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_BLOCKMODELENTITY_H
|
||||
|
|
|
@ -10,36 +10,15 @@ Entity::Entity(EntityMesh* mesh) {
|
|||
setMesh(mesh);
|
||||
}
|
||||
|
||||
Entity::Entity(EntityMesh* mesh, Texture* texture) {
|
||||
setMesh(mesh, texture);
|
||||
}
|
||||
|
||||
void Entity::setMesh(EntityMesh* myMesh) {
|
||||
cleanup();
|
||||
this->mesh = myMesh;
|
||||
}
|
||||
|
||||
void Entity::setMesh(EntityMesh* myMesh, Texture* texture) {
|
||||
cleanup();
|
||||
this->mesh = myMesh;
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void Entity::setTexture(Texture* texture) {
|
||||
this->texture = texture;
|
||||
};
|
||||
|
||||
Texture* Entity::getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
void Entity::draw(Renderer& renderer) {
|
||||
if (visible) {
|
||||
auto mm = getModelMatrix();
|
||||
|
||||
renderer.setModelMatrix(mm);
|
||||
if (texture != nullptr) renderer.enableTexture(texture);
|
||||
|
||||
mesh->draw();
|
||||
}
|
||||
}
|
|
@ -9,24 +9,18 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "../graph/EntityMesh.h"
|
||||
#include "../graph/Texture.h"
|
||||
#include "../graph/drawable/Drawable.h"
|
||||
#include "../../graph/EntityMesh.h"
|
||||
#include "../../graph/drawable/Drawable.h"
|
||||
|
||||
class Entity : public Drawable {
|
||||
public:
|
||||
Entity();
|
||||
explicit Entity(EntityMesh* mesh);
|
||||
Entity(EntityMesh* mesh, Texture* texture);
|
||||
|
||||
void setMesh(EntityMesh* mesh);
|
||||
void setMesh(EntityMesh* mesh, Texture* texture);
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
|
||||
void setTexture(Texture* texture);
|
||||
Texture* getTexture();
|
||||
|
||||
void setPos(glm::vec3 position);
|
||||
glm::vec3 getPos();
|
||||
|
||||
|
@ -49,7 +43,6 @@ protected:
|
|||
|
||||
private:
|
||||
EntityMesh* mesh = nullptr;
|
||||
Texture* texture = nullptr;
|
||||
};
|
||||
|
||||
|
|
@ -5,8 +5,7 @@
|
|||
#ifndef ZEUS_PARTICLEENTITY_H
|
||||
#define ZEUS_PARTICLEENTITY_H
|
||||
|
||||
|
||||
#include "../Entity.h"
|
||||
#include "Entity.h"
|
||||
#include "../../../def/block/BlockDef.h"
|
||||
|
||||
class ParticleEntity : public Entity {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define ZEUS_PLAYERENTITY_H
|
||||
|
||||
#include <memory>
|
||||
#include "../../../game/entity/Entity.h"
|
||||
#include "Entity.h"
|
||||
#include "../../../def/texture/AtlasRef.h"
|
||||
|
||||
class PlayerEntity : public Entity {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define ZEUS_WIREFRAMEGENERATOR_H
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include "../Entity.h"
|
||||
#include "Entity.h"
|
||||
#include "../../../def/block/SelectionBox.h"
|
||||
|
||||
class WireframeEntity : public Entity {
|
||||
|
|
|
@ -4,70 +4,25 @@
|
|||
|
||||
#include "ChunkMesh.h"
|
||||
|
||||
ChunkMesh::ChunkMesh() {
|
||||
VAO = 0;
|
||||
VBO = 0;
|
||||
IBO = 0;
|
||||
indCount = 0;
|
||||
ChunkMesh::ChunkMesh(const ChunkMesh &o) {
|
||||
throw "Copy constructor for ChunkMesh is not supported! Throwing.";
|
||||
}
|
||||
|
||||
void ChunkMesh::create(const std::vector<ChunkVertex>& vertices, const std::vector<unsigned int>& indices) {
|
||||
this->indCount = (int)indices.size();
|
||||
indCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
glGenBuffers(1, &IBO);
|
||||
genArrays(static_cast<unsigned int>(vertices.size() * sizeof(ChunkVertex)),
|
||||
static_cast<unsigned int>(indices.size() * sizeof(unsigned int)),
|
||||
&vertices.front(), &indices.front());
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indCount * sizeof(unsigned int), &indices.front(), GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(ChunkVertex), &vertices.front(), GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_CHUNK(position));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_CHUNK(texCoords));
|
||||
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_CHUNK(normal));
|
||||
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_CHUNK(shaderMod));
|
||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_CHUNK(modValues));
|
||||
unsigned int idx = 0;
|
||||
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_CHUNK(position));
|
||||
createVertexAttrib(idx++, 2, GL_FLOAT, STRIDE_OFFSET_CHUNK(texCoords));
|
||||
createVertexAttrib(idx++, 1, GL_FLOAT, STRIDE_OFFSET_CHUNK(normal));
|
||||
createVertexAttrib(idx++, 1, GL_FLOAT, STRIDE_OFFSET_CHUNK(shaderMod));
|
||||
createVertexAttrib(idx , 3, GL_FLOAT, STRIDE_OFFSET_CHUNK(modValues));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void ChunkMesh::draw() {
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indCount, GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
void ChunkMesh::cleanup() {
|
||||
if (IBO != 0) {
|
||||
glDeleteBuffers(1, &IBO);
|
||||
IBO = 0;
|
||||
}
|
||||
|
||||
if (VBO != 0) {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
VBO = 0;
|
||||
}
|
||||
|
||||
if (VAO != 0) {
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
VAO = 0;
|
||||
}
|
||||
|
||||
indCount = 0;
|
||||
}
|
||||
|
||||
ChunkMesh::~ChunkMesh() {
|
||||
cleanup();
|
||||
glBindVertexArray(0);
|
||||
}
|
|
@ -5,36 +5,16 @@
|
|||
#ifndef GLPROJECT_MESH_H
|
||||
#define GLPROJECT_MESH_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
#include "Mesh.h"
|
||||
#include "ChunkVertex.h"
|
||||
|
||||
struct ChunkVertex {
|
||||
glm::vec3 position;
|
||||
glm::vec2 texCoords;
|
||||
float normal;
|
||||
float shaderMod;
|
||||
glm::vec3 modValues;
|
||||
};
|
||||
|
||||
#define STRIDE_OFFSET_CHUNK(m) sizeof(struct ChunkVertex), (void *)offsetof(struct ChunkVertex, m)
|
||||
|
||||
class ChunkMesh {
|
||||
class ChunkMesh : public Mesh {
|
||||
public:
|
||||
ChunkMesh();
|
||||
|
||||
ChunkMesh() = default;
|
||||
ChunkMesh(const ChunkMesh& o);
|
||||
void create(const std::vector<ChunkVertex>& vertices, const std::vector<unsigned int>& indices);
|
||||
void draw();
|
||||
void cleanup();
|
||||
|
||||
~ChunkMesh();
|
||||
|
||||
private:
|
||||
GLuint VAO, VBO, IBO;
|
||||
GLsizei indCount;
|
||||
~ChunkMesh() = default;
|
||||
};
|
||||
|
||||
|
||||
#endif //GLPROJECT_MESH_H
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_CHUNKVERTEX_H
|
||||
#define ZEUS_CHUNKVERTEX_H
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
struct ChunkVertex {
|
||||
glm::vec3 position;
|
||||
glm::vec2 texCoords;
|
||||
float normal;
|
||||
float shaderMod;
|
||||
glm::vec3 modValues;
|
||||
};
|
||||
|
||||
#define STRIDE_OFFSET_CHUNK(m) sizeof(struct ChunkVertex), (void *)offsetof(struct ChunkVertex, m)
|
||||
|
||||
#endif //ZEUS_CHUNKVERTEX_H
|
|
@ -4,73 +4,35 @@
|
|||
|
||||
#include "EntityMesh.h"
|
||||
|
||||
EntityMesh::EntityMesh() {
|
||||
VAO = 0;
|
||||
VBO = 0;
|
||||
IBO = 0;
|
||||
indCount = 0;
|
||||
EntityMesh::EntityMesh(const EntityMesh &o) :
|
||||
vertices(o.vertices),
|
||||
indices(o.indices) {
|
||||
this->indCount = o.indCount;
|
||||
if (indCount > 0) initModel();
|
||||
}
|
||||
|
||||
void EntityMesh::create(const std::vector<EntityVertex>& vertices, const std::vector<unsigned int>& indices) {
|
||||
this->indCount = (int)indices.size();
|
||||
indCount = static_cast<GLsizei>(indices.size());
|
||||
this->vertices = vertices;
|
||||
this->indices = indices;
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
glGenBuffers(1, &IBO);
|
||||
initModel();
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indCount * sizeof(unsigned int), &indices.front(), GL_STATIC_DRAW);
|
||||
void EntityMesh::initModel() {
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(EntityVertex), &vertices.front(), GL_STATIC_DRAW);
|
||||
genArrays(static_cast<unsigned int>(vertices.size() * sizeof(EntityMesh)),
|
||||
static_cast<unsigned int>(indices.size() * sizeof(unsigned int)),
|
||||
&vertices.front(), &indices.front());
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_ENTITY(position));
|
||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_ENTITY(colorData));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_ENTITY(colorBlend));
|
||||
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_ENTITY(useTex));
|
||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, STRIDE_OFFSET_ENTITY(normal));
|
||||
unsigned int idx = 0;
|
||||
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_ENTITY(position));
|
||||
createVertexAttrib(idx++, 4, GL_FLOAT, STRIDE_OFFSET_ENTITY(colorData));
|
||||
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_ENTITY(colorBlend));
|
||||
createVertexAttrib(idx++, 1, GL_FLOAT, STRIDE_OFFSET_ENTITY(useTex));
|
||||
createVertexAttrib(idx , 3, GL_FLOAT, STRIDE_OFFSET_ENTITY(normal));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void EntityMesh::draw() {
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indCount, GL_UNSIGNED_INT, nullptr);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void EntityMesh::cleanup() {
|
||||
if (IBO != 0) {
|
||||
glDeleteBuffers(1, &IBO);
|
||||
IBO = 0;
|
||||
}
|
||||
|
||||
if (VBO != 0) {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
VBO = 0;
|
||||
}
|
||||
|
||||
if (VAO != 0) {
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
VAO = 0;
|
||||
}
|
||||
|
||||
indCount = 0;
|
||||
}
|
||||
|
||||
EntityMesh::~EntityMesh() {
|
||||
cleanup();
|
||||
}
|
|
@ -5,35 +5,21 @@
|
|||
#ifndef ZEUS_ENTITYMESH_H
|
||||
#define ZEUS_ENTITYMESH_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
#include "Mesh.h"
|
||||
#include "EntityVertex.h"
|
||||
|
||||
struct EntityVertex {
|
||||
glm::vec3 position;
|
||||
glm::vec4 colorData;
|
||||
glm::vec3 colorBlend;
|
||||
float useTex;
|
||||
glm::vec3 normal;
|
||||
};
|
||||
|
||||
#define STRIDE_OFFSET_ENTITY(m) sizeof(struct EntityVertex), (void *)offsetof(struct EntityVertex, m)
|
||||
|
||||
class EntityMesh {
|
||||
class EntityMesh : public Mesh {
|
||||
public:
|
||||
EntityMesh();
|
||||
|
||||
EntityMesh() = default;
|
||||
EntityMesh(const EntityMesh& o);
|
||||
void create(const std::vector<EntityVertex>& vertices, const std::vector<unsigned int>& indices);
|
||||
void draw();
|
||||
void cleanup();
|
||||
|
||||
~EntityMesh();
|
||||
|
||||
~EntityMesh() = default;
|
||||
private:
|
||||
GLuint VAO, VBO, IBO;
|
||||
GLsizei indCount;
|
||||
};
|
||||
void initModel();
|
||||
|
||||
std::vector<EntityVertex> vertices {};
|
||||
std::vector<unsigned int> indices {};
|
||||
};
|
||||
|
||||
#endif //ZEUS_ENTITYMESH_H
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_ENTITYVERTEX_H
|
||||
#define ZEUS_ENTITYVERTEX_H
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
struct EntityVertex {
|
||||
glm::vec3 position;
|
||||
glm::vec4 colorData;
|
||||
glm::vec3 colorBlend;
|
||||
float useTex;
|
||||
glm::vec3 normal;
|
||||
};
|
||||
|
||||
#define STRIDE_OFFSET_ENTITY(m) sizeof(struct EntityVertex), (void *)offsetof(struct EntityVertex, m)
|
||||
|
||||
#endif //ZEUS_ENTITYVERTEX_H
|
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#include "GuiMesh.h"
|
||||
|
||||
GuiMesh::GuiMesh(const GuiMesh &o) {
|
||||
throw "Copy constructor for GuiMesh is not supported! Throwing.";
|
||||
}
|
||||
|
||||
void GuiMesh::create(const std::vector<GuiVertex>& vertices, const std::vector<unsigned int>& indices) {
|
||||
indCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
genArrays(static_cast<unsigned int>(vertices.size() * sizeof(GuiVertex)),
|
||||
static_cast<unsigned int>(indices.size() * sizeof(unsigned int)),
|
||||
&vertices.front(), &indices.front());
|
||||
|
||||
unsigned int idx = 0;
|
||||
createVertexAttrib(idx++, 2, GL_FLOAT, STRIDE_OFFSET_GUI(position));
|
||||
createVertexAttrib(idx++, 4, GL_FLOAT, STRIDE_OFFSET_GUI(colorData));
|
||||
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_GUI(colorBlend));
|
||||
createVertexAttrib(idx , 1, GL_FLOAT, STRIDE_OFFSET_GUI(useTexture));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_GUIMESH_H
|
||||
#define ZEUS_GUIMESH_H
|
||||
|
||||
#include <vector>
|
||||
#include "Mesh.h"
|
||||
#include "GuiVertex.h"
|
||||
|
||||
class GuiMesh : public Mesh {
|
||||
public:
|
||||
GuiMesh() = default;
|
||||
GuiMesh(const GuiMesh& o);
|
||||
void create(const std::vector<GuiVertex>& vertices, const std::vector<unsigned int>& indices);
|
||||
~GuiMesh() = default;
|
||||
};
|
||||
|
||||
#endif //ZEUS_GUIMESH_H
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_GUIVERTEX_H
|
||||
#define ZEUS_GUIVERTEX_H
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
struct GuiVertex {
|
||||
glm::vec2 position;
|
||||
glm::vec4 colorData;
|
||||
glm::vec3 colorBlend;
|
||||
float useTexture;
|
||||
};
|
||||
|
||||
#define STRIDE_OFFSET_GUI(m) sizeof(struct GuiVertex), (void *)offsetof(struct GuiVertex, m)
|
||||
|
||||
#endif //ZEUS_GUIVERTEX_H
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#include "Mesh.h"
|
||||
|
||||
void Mesh::cleanup() {
|
||||
if (VAO != 0) glDeleteVertexArrays(1, &VAO);
|
||||
if (VBO != 0) glDeleteBuffers(1, &VBO);
|
||||
if (IBO != 0) glDeleteBuffers(1, &IBO);
|
||||
|
||||
IBO = 0;
|
||||
VBO = 0;
|
||||
VAO = 0;
|
||||
indCount = 0;
|
||||
}
|
||||
|
||||
void Mesh::genArrays(GLuint vboLength, GLuint iboLength, const void *verticesPtr, const void *indicesPtr) {
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glGenBuffers(1, &IBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, iboLength, indicesPtr, GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, vboLength, verticesPtr, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
void Mesh::createVertexAttrib(GLuint offset, GLuint size, GLenum type, GLsizei stride, const void *pointer) {
|
||||
glEnableVertexAttribArray(offset);
|
||||
glVertexAttribPointer(offset, size, type, GL_FALSE, stride, pointer);
|
||||
}
|
||||
|
||||
void Mesh::draw() {
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indCount, GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
cleanup();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// Created by aurailus on 24/08/19.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_MESH_H
|
||||
#define ZEUS_MESH_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
Mesh() = default;
|
||||
|
||||
void cleanup();
|
||||
virtual void draw();
|
||||
|
||||
~Mesh();
|
||||
protected:
|
||||
void genArrays(GLuint vboLength, GLuint iboLength, const void* verticesPtr, const void* indicesPtr);
|
||||
void createVertexAttrib(GLuint offset, GLuint size, GLenum type, GLsizei stride, const void* pointer);
|
||||
|
||||
GLuint VAO = 0;
|
||||
GLuint VBO = 0;
|
||||
GLuint IBO = 0;
|
||||
GLsizei indCount = 0;
|
||||
};
|
||||
|
||||
#endif //ZEUS_MESH_H
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
#include "GameScene.h"
|
||||
#include "../../def/entity/Model.h"
|
||||
|
||||
GameScene::GameScene(ClientState& state) : Scene(state),
|
||||
defs(state.defs),
|
||||
|
@ -25,6 +26,13 @@ GameScene::GameScene(ClientState& state) : Scene(state),
|
|||
|
||||
entities.push_back(&player);
|
||||
|
||||
Model m;
|
||||
m.create("/home/aurailus/Zepha/mods/default/models/player.b3d", defs.textures(), "zeus:default:player");
|
||||
EntityMesh* mesh = new EntityMesh(m.meshes[0]);
|
||||
Entity* e = new Entity(mesh);
|
||||
e->setScale(1.f/16.f);
|
||||
entities.push_back(e);
|
||||
|
||||
server.init(entities, &world);
|
||||
|
||||
Packet r(PacketType::CONNECT_DATA_RECVD);
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#ifndef SRC_GAMEWORLD_H
|
||||
#define SRC_GAMEWORLD_H
|
||||
|
||||
#include "net/ClientNetworkInterpreter.h"
|
||||
#include "world/LocalWorld.h"
|
||||
#include "world/Player.h"
|
||||
#include "../graph/scene/Scene.h"
|
||||
#include "../graph/Renderer.h"
|
||||
#include "../entity/hud/DebugGui.h"
|
||||
#include "../entity/hud/GameGui.h"
|
||||
#include "world/LocalWorld.h"
|
||||
#include "world/Player.h"
|
||||
#include "net/ClientNetworkInterpreter.h"
|
||||
#include "../entity/world/PlayerEntity.h"
|
||||
#include "../entity/world/WireframeEntity.h"
|
||||
#include "../entity/world/BlockCrackEntity.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
struct MeshVertex {
|
||||
struct BlockModelVertex {
|
||||
glm::vec3 pos;
|
||||
glm::vec3 nml;
|
||||
glm::vec2 tex;
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef GLPROJECT_MESHCHUNK_H
|
||||
#define GLPROJECT_MESHCHUNK_H
|
||||
|
||||
#include "../../../entity/Entity.h"
|
||||
#include "../../../entity/world/Entity.h"
|
||||
#include "../../../../util/TransPos.h"
|
||||
|
||||
class MeshChunk : Drawable {
|
||||
|
|
|
@ -107,7 +107,7 @@ void MeshGenerator::addFaces(const glm::vec3 &offset, const vector<MeshPart> &me
|
|||
}
|
||||
}
|
||||
|
||||
for (const MeshVertex &vertex : mp.vertices) {
|
||||
for (const BlockModelVertex &vertex : mp.vertices) {
|
||||
meshDetails->vertices.push_back({
|
||||
vertex.pos + offset,
|
||||
vertex.tex,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
#include "MeshVertex.h"
|
||||
#include "BlockModelVertex.h"
|
||||
#include "../MeshDetails.h"
|
||||
#include "../../../../world/chunk/BlockChunk.h"
|
||||
#include "../../../../def/LocalDefinitionAtlas.h"
|
||||
|
|
|
@ -47,7 +47,6 @@ void Server::update() {
|
|||
Packet p(event.packet);
|
||||
ServerClient* client = static_cast<ServerClient*>(event.peer->data);
|
||||
|
||||
std::cout << "Recieve from " << client << std::endl;
|
||||
if (client->hasPlayer()) {
|
||||
handlePlayerPacket(*client, p);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue