diff --git a/src/def/ItemDef.h b/src/def/ItemDef.h index 748a5539..219bbd02 100644 --- a/src/def/ItemDef.h +++ b/src/def/ItemDef.h @@ -6,6 +6,8 @@ #include +#include "../game/entity/Model.h" + class ItemDef { public: enum class Type { @@ -21,5 +23,7 @@ public: unsigned short maxStackSize; Type type = Type::INVALID; + + std::shared_ptr entityModel = std::make_shared(); }; diff --git a/src/def/item/BlockDef.h b/src/def/item/BlockDef.h index 211b99f1..06b5f1c5 100644 --- a/src/def/item/BlockDef.h +++ b/src/def/item/BlockDef.h @@ -6,11 +6,12 @@ #include #include -#include "SelectionBox.h" -#include "BlockModel.h" + #include "../ItemDef.h" + +#include "BlockModel.h" +#include "SelectionBox.h" #include "../../lua/Callback.h" -#include "../../game/entity/Model.h" class BlockDef : public ItemDef { public: @@ -31,7 +32,6 @@ public: std::vector sBoxes; std::vector cBoxes; - std::shared_ptr entityModel {}; std::unordered_map callbacks {}; }; diff --git a/src/def/item/CraftItemDef.h b/src/def/item/CraftItemDef.h index 29995661..2f66f26d 100644 --- a/src/def/item/CraftItemDef.h +++ b/src/def/item/CraftItemDef.h @@ -5,9 +5,10 @@ #pragma once #include + #include "../ItemDef.h" + #include "../texture/AtlasRef.h" -#include "../../game/entity/Model.h" class CraftItemDef : public ItemDef { public: @@ -22,6 +23,4 @@ public: std::vector textures {}; std::vector> textureRefs {}; - - std::shared_ptr entityModel = std::make_shared(); }; diff --git a/src/game/entity/Entity.cpp b/src/game/entity/Entity.cpp index b8eb151f..f7567a42 100644 --- a/src/game/entity/Entity.cpp +++ b/src/game/entity/Entity.cpp @@ -129,16 +129,22 @@ glm::mat4 Entity::getModelMatrix() { glm::mat4 model = glm::mat4(1.0); model = glm::translate(model, visualPosition + visualVisualOffset); - - model = glm::rotate(model, glm::radians(visualRotation.x), {1, 0, 0}); - model = glm::rotate(model, glm::radians(visualRotation.y), {0, 1, 0}); - model = glm::rotate(model, glm::radians(visualRotation.z), {0, 0, 1}); - + model = model * getRotationMatrix(); model = glm::scale(model, visualScale); return model; } +glm::mat4 Entity::getRotationMatrix() { + glm::mat4 parentMatrix = (parent != nullptr ? parent->getRotationMatrix() : glm::mat4(1.0f)); + glm::mat4 rotMatrix = glm::mat4(1.0f); + rotMatrix = glm::rotate(rotMatrix, glm::radians(visualRotation.x), {1, 0, 0}); + rotMatrix = glm::rotate(rotMatrix, glm::radians(visualRotation.y), {0, 1, 0}); + rotMatrix = glm::rotate(rotMatrix, glm::radians(visualRotation.z), {0, 0, 1}); + return parentMatrix * rotMatrix; +} + + void Entity::cleanup() { model = nullptr; } diff --git a/src/game/entity/Entity.h b/src/game/entity/Entity.h index 658a144e..aa83cce4 100644 --- a/src/game/entity/Entity.h +++ b/src/game/entity/Entity.h @@ -57,8 +57,11 @@ public: ~Entity() override; AnimationState animState {}; + + Entity* parent = nullptr; protected: glm::mat4 getModelMatrix(); + glm::mat4 getRotationMatrix(); glm::vec3 position {}; glm::vec3 visualPosition {}; diff --git a/src/game/graph/Camera.cpp b/src/game/graph/Camera.cpp index 19b193d8..c5ab872b 100644 --- a/src/game/graph/Camera.cpp +++ b/src/game/graph/Camera.cpp @@ -25,7 +25,7 @@ void Camera::createMatrices() { projectionMatrix = glm::perspective(glm::radians(fov), ratio, nearClip, farClip); frustum.setCamInternals(glm::radians(fov) / 1.2f, ratio, nearClip, farClip); - orthographicMatrix = glm::ortho(0.0f, bufferDimensions.x, bufferDimensions.y, 0.0f, -100.0f, 100.0f); + orthographicMatrix = glm::ortho(0.0f, bufferDimensions.x, bufferDimensions.y, 0.0f, -1000.0f, 1000.0f); } void Camera::changeWindowDimensions(glm::vec2 size) { diff --git a/src/game/inventory/InventoryRefs.cpp b/src/game/inventory/InventoryRefs.cpp index d34ccee2..64c51f88 100644 --- a/src/game/inventory/InventoryRefs.cpp +++ b/src/game/inventory/InventoryRefs.cpp @@ -16,7 +16,7 @@ void InventoryRefs::update() { } std::shared_ptr InventoryRefs::createInv(const std::string &inv) { - inventories.emplace(inv, std::make_shared(defs, clients, inv)); + if (!inventories.count(inv)) inventories.emplace(inv, std::make_shared(defs, clients, inv)); return inventories[inv]; } @@ -46,11 +46,9 @@ bool InventoryRefs::removeWatcher(const std::string &inv, const std::string &lis } void InventoryRefs::primaryInteract(const std::string &inv, const std::string &list, unsigned short ind, unsigned int cid) { - std::cout << "primary interaction" << std::endl; inventories[inv]->operator[](list)->primaryInteract(*inventories["player:" + std::to_string(cid)]->operator[]("hand"), ind); } void InventoryRefs::secondaryInteract(const std::string &inv, const std::string &list, unsigned short ind, unsigned int cid) { - std::cout << "secondary interaction" << std::endl; inventories[inv]->operator[](list)->secondaryInteract(*inventories["player:" + std::to_string(cid)]->operator[]("hand"), ind); } diff --git a/src/game/scene/world/Player.cpp b/src/game/scene/world/Player.cpp index c8f0c8af..8eb4af50 100644 --- a/src/game/scene/world/Player.cpp +++ b/src/game/scene/world/Player.cpp @@ -17,8 +17,9 @@ Player::Player(LocalWorld& world, ClientGame& defs, Renderer& renderer, LocalInv void Player::update(Input &input, double delta, glm::vec2 mouseDelta) { if (activeBlock == -1) { - activeBlock = defs.defs.blockFromStr("zeus:default:stone").index; - handModel.setModel(defs.defs.blockFromId(activeBlock).entityModel); + activeBlock = defs.defs.fromStr("zeus:default:stone").index; + handItemModel.setModel(defs.defs.fromId(activeBlock).entityModel); + handItemModel.parent = &handModel; } gameGui.update(delta); @@ -34,6 +35,7 @@ void Player::update(Input &input, double delta, glm::vec2 mouseDelta) { } void Player::moveAndLook(Input &input, double delta, glm::vec2 mouseDelta) { + //Position movement bool sprinting = input.isKeyDown(GLFW_KEY_LEFT_CONTROL); @@ -105,6 +107,8 @@ void Player::updateCamera() { renderer.camera.setYaw(yaw); renderer.camera.setPitch(pitch); + auto type = defs.defs.fromId(activeBlock).type; + glm::vec3 eyesPos = {pos.x, pos.y + EYE_HEIGHT, pos.z}; renderer.camera.setPos(eyesPos); @@ -117,13 +121,24 @@ void Player::updateCamera() { glm::vec3 right = glm::normalize(glm::cross(front, {0, 1, 0})); glm::vec3 up = glm::normalize(glm::cross(right, front)); - glm::vec3 handPos = eyesPos + front * 0.25f + right * 0.25f + up * -0.2f; + glm::vec3 handPos = eyesPos + front * 0.25f + right * 0.25f + up * (type == ItemDef::Type::CRAFTITEM ? -0.15f : -0.2f); handModel.setRotateY(-yaw); handModel.setRotateZ(pitch); - handModel.setPos(handPos + vel * 0.1f); - handModel.setScale(0.12f); + if (type == ItemDef::Type::CRAFTITEM) { + handItemModel.setRotateX(45); + handItemModel.setRotateY(110); + handItemModel.setRotateZ(-25); + } + else { + handItemModel.setRotateX(0); + handItemModel.setRotateY(0); + handItemModel.setRotateZ(0); + } + + handItemModel.setPos(handPos + vel * 0.1f); + handItemModel.setScale((type == ItemDef::Type::CRAFTITEM ? 0.2f : 0.12f)); } void Player::findPointedThing(Input &input) { @@ -256,8 +271,8 @@ LocalInventory& Player::getInventory() { */ void Player::setActiveBlock(const std::string& block) { - activeBlock = defs.defs.blockFromStr(block).index; - handModel.setModel(defs.defs.blockFromStr(block).entityModel); + activeBlock = defs.defs.fromStr(block).index; + handItemModel.setModel(defs.defs.fromId(activeBlock).entityModel); } void Player::setMenu(const std::string& menu, const std::map& callbacks) { @@ -284,7 +299,8 @@ std::string Player::getMenuState() { void Player::draw(Renderer &renderer) { wireframe.draw(renderer); - handModel.draw(renderer); +// handModel.draw(renderer); + handItemModel.draw(renderer); } void Player::drawGUI(Renderer &renderer) { diff --git a/src/game/scene/world/Player.h b/src/game/scene/world/Player.h index 7fca4791..3082ad40 100644 --- a/src/game/scene/world/Player.h +++ b/src/game/scene/world/Player.h @@ -67,6 +67,7 @@ private: GameGui gameGui; Entity handModel; + Entity handItemModel; WireframeEntity wireframe; float yaw = 0; diff --git a/subgames/zeus/mods/zeus_default/script/main.venus b/subgames/zeus/mods/zeus_default/script/main.venus index 9d280321..c9413f47 100644 --- a/subgames/zeus/mods/zeus_default/script/main.venus +++ b/subgames/zeus/mods/zeus_default/script/main.venus @@ -3,6 +3,7 @@ runfile(_PATH .. "entity/_index") local blockTypes = { "@aurailus:tnt:tnt", + "@aurailus:basictools:flint_pickaxe", "zeus:default:grass_slab", "zeus:kinetic:axle_0", "zeus:default:stone", diff --git a/subgames/zeus/mods/zeus_materials/script/items/plant_fibre.venus b/subgames/zeus/mods/zeus_materials/script/items/plant_fibre.venus index a1a6571e..60ed2e82 100644 --- a/subgames/zeus/mods/zeus_materials/script/items/plant_fibre.venus +++ b/subgames/zeus/mods/zeus_materials/script/items/plant_fibre.venus @@ -1,9 +1,9 @@ zepha.register_item("zeus:materials:plant_fibre", { name = "Plant Fibre", - groups = { - organic = 1, - }, textures = { "zeus:materials:plant_fibre" - } + }, + groups = { + organic = 1, + } }) diff --git a/subgames/zeus/mods/zeus_materials/script/items/plant_twine.venus b/subgames/zeus/mods/zeus_materials/script/items/plant_twine.venus index b7412f1e..8ae1456d 100644 --- a/subgames/zeus/mods/zeus_materials/script/items/plant_twine.venus +++ b/subgames/zeus/mods/zeus_materials/script/items/plant_twine.venus @@ -1,11 +1,11 @@ zepha.register_item("zeus:materials:plant_twine", { name = "Plant Twine", - groups = { - rope = 1, - }, textures = { "zeus:materials:plant_twine" - } + }, + groups = { + rope = 1, + } }) crafting.register_recipe({ diff --git a/subgames/zeus/mods/zeus_materials/script/items/rock.venus b/subgames/zeus/mods/zeus_materials/script/items/rock.venus index 45c91d3b..ed17d3c9 100644 --- a/subgames/zeus/mods/zeus_materials/script/items/rock.venus +++ b/subgames/zeus/mods/zeus_materials/script/items/rock.venus @@ -1,9 +1,9 @@ zepha.register_item("zeus:materials:rock", { name = "Rock", - groups = { - rock = 1, - }, textures = { "zeus:materials:rock" + }, + groups = { + rock = 1, } }) diff --git a/subgames/zeus/mods/zeus_materials/script/items/stick.venus b/subgames/zeus/mods/zeus_materials/script/items/stick.venus index 41709bcc..dfc61b55 100644 --- a/subgames/zeus/mods/zeus_materials/script/items/stick.venus +++ b/subgames/zeus/mods/zeus_materials/script/items/stick.venus @@ -1,12 +1,12 @@ zepha.register_item("zeus:materials:stick", { name = "Stick", - groups = { - stick = 1, - }, textures = { "zeus:materials:stick_0", "zeus:materials:stick_1", "zeus:materials:stick_2", "zeus:materials:stick_3" + }, + groups = { + stick = 1, } }) \ No newline at end of file