diff --git a/demo/inc/states/game/player/weapon.hpp b/demo/inc/states/game/player/weapon.hpp index 0118461..13d9673 100644 --- a/demo/inc/states/game/player/weapon.hpp +++ b/demo/inc/states/game/player/weapon.hpp @@ -18,6 +18,7 @@ using Tyra::Renderer; using Tyra::StaPipOptions; using Tyra::StaticMesh; using Tyra::TextureRepository; +using Tyra::Vec4; namespace Demo { @@ -30,6 +31,7 @@ class Weapon { StaPipOptions* options; void update(); + // void debugPosition(Pad* pad); private: void allocateOptions(); diff --git a/demo/src/states/game/player/player.cpp b/demo/src/states/game/player/player.cpp index 89ced84..706e1ec 100644 --- a/demo/src/states/game/player/player.cpp +++ b/demo/src/states/game/player/player.cpp @@ -18,9 +18,9 @@ Player::Player(Engine* engine) camera(&engine->pad) { staticPairs.push_back(new RendererStaticPair{weapon.mesh, weapon.options}); pad = &engine->pad; - position = Vec4(3.0F, 3.0F, 0.0F); + position = Vec4(3.0F, 15.0F, 0.0F); camera.lookAt = Vec4(0.0F, 0.0F, -30.0F); - speed = 0.5F; + speed = 2.0F; } Player::~Player() { diff --git a/demo/src/states/game/player/weapon.cpp b/demo/src/states/game/player/weapon.cpp index fe1754f..f56d550 100644 --- a/demo/src/states/game/player/weapon.cpp +++ b/demo/src/states/game/player/weapon.cpp @@ -20,27 +20,79 @@ namespace Demo { Weapon::Weapon(TextureRepository* repo) { TyrobjLoader loader; auto* data = loader.load(FileUtils::fromCwd("game/models/ak47/ak47.obj"), 1, - 1.0F, true); + .5F, true); data->normalsEnabled = false; mesh = new StaticMesh(*data); delete data; - mesh->translation.translateZ(-50.0F); + mesh->translation.translateX(2.85F); + mesh->translation.translateY(-3.40F); + mesh->translation.translateZ(-10.50F); + + mesh->rotation.rotateY(1.60F); + mesh->rotation.rotateZ(-6.30F); + + mesh->scale.scale(0.5F); repo->addByMesh(mesh, FileUtils::fromCwd("game/models/ak47/"), "png"); allocateOptions(); } -// float testRotation = 0.0F; +void Weapon::update() {} -void Weapon::update() { - // testRotation += 0.001F; - mesh->rotation.identity(); - mesh->rotation.rotateZ(0.1F); - mesh->rotation.rotateY(-4.3F); - // TYRA_LOG(testRotation); -} +// float tX = 0.0F; +// float tY = -3.0F; +// float tZ = -10.0F; + +// float rY = 0.1F; +// float rZ = -4.3F; + +// void Weapon::debugPosition(Pad* pad) { +// const auto& leftJoy = pad->getLeftJoyPad(); +// const auto& rightJoy = pad->getRightJoyPad(); +// const float offset = 0.05F; + +// if (leftJoy.v <= 100) { +// rY -= offset; +// } else if (leftJoy.v >= 200) { +// rY += offset; +// } +// if (leftJoy.h <= 100) { +// rZ -= offset; +// } else if (leftJoy.h >= 200) { +// rZ += offset; +// } + +// if (rightJoy.h <= 100) { +// tY -= offset; +// } else if (rightJoy.h >= 200) { +// tY += offset; +// } + +// if (rightJoy.v <= 100) { +// tZ -= offset; +// } else if (rightJoy.v >= 200) { +// tZ += offset; +// } + +// if (pad->getPressed().Circle) { +// tX -= offset; +// } else if (pad->getPressed().Cross) { +// tX += offset; +// } + +// mesh->rotation.identity(); +// mesh->rotation.rotateY(rY); +// mesh->rotation.rotateZ(rZ); + +// mesh->translation.identity(); +// mesh->translation.translateX(tX); +// mesh->translation.translateY(tY); +// mesh->translation.translateZ(tZ); + +// TYRA_LOG("tX: ", tX, " tY: ", tY, " tZ: ", tZ, " rY: ", rY, " rZ: ", rZ); +// } Weapon::~Weapon() { delete mesh; @@ -51,6 +103,9 @@ void Weapon::allocateOptions() { options = new StaPipOptions(); options->shadingType = Tyra::TyraShadingGouraud; options->blendingEnabled = false; + options->fullClipChecks = false; + options->frustumCulling = Tyra::PipelineFrustumCulling_None; + options->transformationType = Tyra::TyraMP; options->antiAliasingEnabled = false; } diff --git a/demo/src/states/game/terrain/terrain.cpp b/demo/src/states/game/terrain/terrain.cpp index cb7298e..1813c89 100644 --- a/demo/src/states/game/terrain/terrain.cpp +++ b/demo/src/states/game/terrain/terrain.cpp @@ -20,7 +20,7 @@ namespace Demo { Terrain::Terrain(TextureRepository* repo) { TyrobjLoader loader; auto* data = loader.load( - FileUtils::fromCwd("game/models/terrain/terrain.obj"), 1, 5.0F, true); + FileUtils::fromCwd("game/models/terrain/terrain.obj"), 1, 25.0F, true); data->normalsEnabled = false; mesh = new StaticMesh(*data); mesh->getMaterial(0)->color.r = 96.0F; diff --git a/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp index b2e4a65..788518e 100644 --- a/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/bag/pipeline_info_bag.hpp @@ -15,6 +15,7 @@ #include "math/vec4.hpp" #include "../pipeline_shading_type.hpp" #include "../pipeline_texture_mapping_type.hpp" +#include "../pipeline_transformation_type.hpp" namespace Tyra { @@ -28,6 +29,7 @@ class PipelineInfoBag { PipelineShadingType shadingType; PipelineTextureMappingType textureMappingType; + PipelineTransformationType transformationType; bool blendingEnabled; bool antiAliasingEnabled; diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp index 8800054..a71fde8 100644 --- a/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_options.hpp @@ -13,6 +13,7 @@ #include "../shared/pipeline_shading_type.hpp" #include "../shared/pipeline_lighting_options.hpp" #include "../shared/pipeline_texture_mapping_type.hpp" +#include "../shared/pipeline_transformation_type.hpp" #include "./pipeline_frustum_culling.hpp" namespace Tyra { @@ -25,15 +26,28 @@ class PipelineOptions { blendingEnabled = true; shadingType = TyraShadingFlat; textureMappingType = TyraLinear; + transformationType = TyraMVP; } ~PipelineOptions() {} + /** Type of frustum culling */ PipelineFrustumCulling frustumCulling; + + /** Flat or gouraud */ PipelineShadingType shadingType; + + /** Linear or nearest */ PipelineTextureMappingType textureMappingType; + + /** Blending texture with color */ bool blendingEnabled; + + /** Anti-aliasing */ bool antiAliasingEnabled; + /** Multiply by model matrix by MVP or MP */ + PipelineTransformationType transformationType; + /** Optional */ PipelineLightingOptions* lighting; }; diff --git a/engine/inc/renderer/3d/pipeline/shared/pipeline_transformation_type.hpp b/engine/inc/renderer/3d/pipeline/shared/pipeline_transformation_type.hpp new file mode 100644 index 0000000..82c9355 --- /dev/null +++ b/engine/inc/renderer/3d/pipeline/shared/pipeline_transformation_type.hpp @@ -0,0 +1,22 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Tyra { + +enum PipelineTransformationType { + /** Multiplies model by view and projection matrix */ + TyraMVP, + /** Multiplies model by only projection matrix */ + TyraMP, +}; + +} // namespace Tyra diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp index 5cc9d14..4b2aa64 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_core.cpp @@ -63,7 +63,11 @@ void DynPipCore::initParts(DynPipBag* bag) { texBuffers = new RendererCoreTextureBuffers{temp.id, temp.core, temp.clut}; } - mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; + if (bag->info->transformationType == TyraMP) { + mvp = rendererCore->renderer3D.getProjection() * *bag->info->model; + } else { + mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; + } qbufferRenderer.sendObjectData(bag, &mvp, texBuffers); diff --git a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp index fced2aa..7cb1653 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/dynamic_pipeline.cpp @@ -212,11 +212,13 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh, result->blendingEnabled = options->blendingEnabled; result->shadingType = options->shadingType; result->textureMappingType = options->textureMappingType; + result->transformationType = options->transformationType; } else { result->antiAliasingEnabled = false; result->blendingEnabled = true; result->shadingType = TyraShadingFlat; result->textureMappingType = TyraLinear; + result->transformationType = TyraMVP; } result->model = model; diff --git a/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp index 923d913..17300c9 100644 --- a/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp +++ b/engine/src/renderer/3d/pipeline/shared/bag/pipeline_info_bag.cpp @@ -14,6 +14,7 @@ namespace Tyra { PipelineInfoBag::PipelineInfoBag() { shadingType = TyraShadingFlat; + transformationType = TyraMVP; textureMappingType = TyraLinear; blendingEnabled = true; antiAliasingEnabled = false; diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index 8e46555..ae96514 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -96,6 +96,10 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, TYRA_ASSERT( !bag->texture || (bag->texture->texture && bag->texture->coordinates), "If you want texture, please provide texture and coordinates!"); + TYRA_ASSERT(bag->info->transformationType == TyraMVP || + (!bag->info->fullClipChecks && !frustumCull), + "Please disable clip checks and frustum culling if not using MVP " + "matrix!"); TYRA_ASSERT(!(frustumCull == false && bag->info->fullClipChecks == true), "Full clip checks are not supported with frustum culling = off!"); @@ -126,7 +130,13 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull, packager.setRenderBBox(renderBbox); - auto mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; + M4x4 mvp; + + if (bag->info->transformationType == TyraMP) { + mvp = rendererCore->renderer3D.getProjection() * *bag->info->model; + } else { + mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model; + } RendererCoreTextureBuffers* texBuffers = nullptr; if (bag->texture) { diff --git a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp index 734bbc0..38642ae 100644 --- a/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp +++ b/engine/src/renderer/3d/pipeline/static/static_pipeline.cpp @@ -47,6 +47,11 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) { !(frustumCulling != PipelineFrustumCulling_Precise && infoBag->fullClipChecks == true), "Full clip checks are only supported with frustum culling == Precise!"); + TYRA_ASSERT(options->transformationType == TyraMVP || + (!options->fullClipChecks && + options->frustumCulling == PipelineFrustumCulling_None), + "Please disable clip checks and frustum culling if not using MVP " + "matrix!"); if (frustumCulling == PipelineFrustumCulling_Simple) { auto* frame = mesh->getFrame(); @@ -95,12 +100,14 @@ PipelineInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh, result->shadingType = options->shadingType; result->fullClipChecks = options->fullClipChecks; result->textureMappingType = options->textureMappingType; + result->transformationType = options->transformationType; } else { result->antiAliasingEnabled = false; result->blendingEnabled = true; result->shadingType = TyraShadingFlat; result->textureMappingType = TyraLinear; result->fullClipChecks = false; + result->transformationType = TyraMVP; } result->model = model;