demo player movement
This commit is contained in:
@@ -18,6 +18,7 @@ using Tyra::Renderer;
|
|||||||
using Tyra::StaPipOptions;
|
using Tyra::StaPipOptions;
|
||||||
using Tyra::StaticMesh;
|
using Tyra::StaticMesh;
|
||||||
using Tyra::TextureRepository;
|
using Tyra::TextureRepository;
|
||||||
|
using Tyra::Vec4;
|
||||||
|
|
||||||
namespace Demo {
|
namespace Demo {
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ class Weapon {
|
|||||||
StaPipOptions* options;
|
StaPipOptions* options;
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
// void debugPosition(Pad* pad);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void allocateOptions();
|
void allocateOptions();
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ Player::Player(Engine* engine)
|
|||||||
camera(&engine->pad) {
|
camera(&engine->pad) {
|
||||||
staticPairs.push_back(new RendererStaticPair{weapon.mesh, weapon.options});
|
staticPairs.push_back(new RendererStaticPair{weapon.mesh, weapon.options});
|
||||||
pad = &engine->pad;
|
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);
|
camera.lookAt = Vec4(0.0F, 0.0F, -30.0F);
|
||||||
speed = 0.5F;
|
speed = 2.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player() {
|
Player::~Player() {
|
||||||
|
|||||||
@@ -20,27 +20,79 @@ namespace Demo {
|
|||||||
Weapon::Weapon(TextureRepository* repo) {
|
Weapon::Weapon(TextureRepository* repo) {
|
||||||
TyrobjLoader loader;
|
TyrobjLoader loader;
|
||||||
auto* data = loader.load(FileUtils::fromCwd("game/models/ak47/ak47.obj"), 1,
|
auto* data = loader.load(FileUtils::fromCwd("game/models/ak47/ak47.obj"), 1,
|
||||||
1.0F, true);
|
.5F, true);
|
||||||
data->normalsEnabled = false;
|
data->normalsEnabled = false;
|
||||||
mesh = new StaticMesh(*data);
|
mesh = new StaticMesh(*data);
|
||||||
delete 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");
|
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/ak47/"), "png");
|
||||||
|
|
||||||
allocateOptions();
|
allocateOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// float testRotation = 0.0F;
|
void Weapon::update() {}
|
||||||
|
|
||||||
void Weapon::update() {
|
// float tX = 0.0F;
|
||||||
// testRotation += 0.001F;
|
// float tY = -3.0F;
|
||||||
mesh->rotation.identity();
|
// float tZ = -10.0F;
|
||||||
mesh->rotation.rotateZ(0.1F);
|
|
||||||
mesh->rotation.rotateY(-4.3F);
|
// float rY = 0.1F;
|
||||||
// TYRA_LOG(testRotation);
|
// 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() {
|
Weapon::~Weapon() {
|
||||||
delete mesh;
|
delete mesh;
|
||||||
@@ -51,6 +103,9 @@ void Weapon::allocateOptions() {
|
|||||||
options = new StaPipOptions();
|
options = new StaPipOptions();
|
||||||
options->shadingType = Tyra::TyraShadingGouraud;
|
options->shadingType = Tyra::TyraShadingGouraud;
|
||||||
options->blendingEnabled = false;
|
options->blendingEnabled = false;
|
||||||
|
options->fullClipChecks = false;
|
||||||
|
options->frustumCulling = Tyra::PipelineFrustumCulling_None;
|
||||||
|
options->transformationType = Tyra::TyraMP;
|
||||||
options->antiAliasingEnabled = false;
|
options->antiAliasingEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Demo {
|
|||||||
Terrain::Terrain(TextureRepository* repo) {
|
Terrain::Terrain(TextureRepository* repo) {
|
||||||
TyrobjLoader loader;
|
TyrobjLoader loader;
|
||||||
auto* data = loader.load(
|
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;
|
data->normalsEnabled = false;
|
||||||
mesh = new StaticMesh(*data);
|
mesh = new StaticMesh(*data);
|
||||||
mesh->getMaterial(0)->color.r = 96.0F;
|
mesh->getMaterial(0)->color.r = 96.0F;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "math/vec4.hpp"
|
#include "math/vec4.hpp"
|
||||||
#include "../pipeline_shading_type.hpp"
|
#include "../pipeline_shading_type.hpp"
|
||||||
#include "../pipeline_texture_mapping_type.hpp"
|
#include "../pipeline_texture_mapping_type.hpp"
|
||||||
|
#include "../pipeline_transformation_type.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ class PipelineInfoBag {
|
|||||||
|
|
||||||
PipelineShadingType shadingType;
|
PipelineShadingType shadingType;
|
||||||
PipelineTextureMappingType textureMappingType;
|
PipelineTextureMappingType textureMappingType;
|
||||||
|
PipelineTransformationType transformationType;
|
||||||
bool blendingEnabled;
|
bool blendingEnabled;
|
||||||
bool antiAliasingEnabled;
|
bool antiAliasingEnabled;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "../shared/pipeline_shading_type.hpp"
|
#include "../shared/pipeline_shading_type.hpp"
|
||||||
#include "../shared/pipeline_lighting_options.hpp"
|
#include "../shared/pipeline_lighting_options.hpp"
|
||||||
#include "../shared/pipeline_texture_mapping_type.hpp"
|
#include "../shared/pipeline_texture_mapping_type.hpp"
|
||||||
|
#include "../shared/pipeline_transformation_type.hpp"
|
||||||
#include "./pipeline_frustum_culling.hpp"
|
#include "./pipeline_frustum_culling.hpp"
|
||||||
|
|
||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
@@ -25,15 +26,28 @@ class PipelineOptions {
|
|||||||
blendingEnabled = true;
|
blendingEnabled = true;
|
||||||
shadingType = TyraShadingFlat;
|
shadingType = TyraShadingFlat;
|
||||||
textureMappingType = TyraLinear;
|
textureMappingType = TyraLinear;
|
||||||
|
transformationType = TyraMVP;
|
||||||
}
|
}
|
||||||
~PipelineOptions() {}
|
~PipelineOptions() {}
|
||||||
|
|
||||||
|
/** Type of frustum culling */
|
||||||
PipelineFrustumCulling frustumCulling;
|
PipelineFrustumCulling frustumCulling;
|
||||||
|
|
||||||
|
/** Flat or gouraud */
|
||||||
PipelineShadingType shadingType;
|
PipelineShadingType shadingType;
|
||||||
|
|
||||||
|
/** Linear or nearest */
|
||||||
PipelineTextureMappingType textureMappingType;
|
PipelineTextureMappingType textureMappingType;
|
||||||
|
|
||||||
|
/** Blending texture with color */
|
||||||
bool blendingEnabled;
|
bool blendingEnabled;
|
||||||
|
|
||||||
|
/** Anti-aliasing */
|
||||||
bool antiAliasingEnabled;
|
bool antiAliasingEnabled;
|
||||||
|
|
||||||
|
/** Multiply by model matrix by MVP or MP */
|
||||||
|
PipelineTransformationType transformationType;
|
||||||
|
|
||||||
/** Optional */
|
/** Optional */
|
||||||
PipelineLightingOptions* lighting;
|
PipelineLightingOptions* lighting;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Tyra {
|
||||||
|
|
||||||
|
enum PipelineTransformationType {
|
||||||
|
/** Multiplies model by view and projection matrix */
|
||||||
|
TyraMVP,
|
||||||
|
/** Multiplies model by only projection matrix */
|
||||||
|
TyraMP,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tyra
|
||||||
@@ -63,7 +63,11 @@ void DynPipCore::initParts(DynPipBag* bag) {
|
|||||||
texBuffers = new RendererCoreTextureBuffers{temp.id, temp.core, temp.clut};
|
texBuffers = new RendererCoreTextureBuffers{temp.id, temp.core, temp.clut};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bag->info->transformationType == TyraMP) {
|
||||||
|
mvp = rendererCore->renderer3D.getProjection() * *bag->info->model;
|
||||||
|
} else {
|
||||||
mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model;
|
mvp = rendererCore->renderer3D.getViewProj() * *bag->info->model;
|
||||||
|
}
|
||||||
|
|
||||||
qbufferRenderer.sendObjectData(bag, &mvp, texBuffers);
|
qbufferRenderer.sendObjectData(bag, &mvp, texBuffers);
|
||||||
|
|
||||||
|
|||||||
@@ -212,11 +212,13 @@ PipelineInfoBag* DynamicPipeline::getInfoBag(DynamicMesh* mesh,
|
|||||||
result->blendingEnabled = options->blendingEnabled;
|
result->blendingEnabled = options->blendingEnabled;
|
||||||
result->shadingType = options->shadingType;
|
result->shadingType = options->shadingType;
|
||||||
result->textureMappingType = options->textureMappingType;
|
result->textureMappingType = options->textureMappingType;
|
||||||
|
result->transformationType = options->transformationType;
|
||||||
} else {
|
} else {
|
||||||
result->antiAliasingEnabled = false;
|
result->antiAliasingEnabled = false;
|
||||||
result->blendingEnabled = true;
|
result->blendingEnabled = true;
|
||||||
result->shadingType = TyraShadingFlat;
|
result->shadingType = TyraShadingFlat;
|
||||||
result->textureMappingType = TyraLinear;
|
result->textureMappingType = TyraLinear;
|
||||||
|
result->transformationType = TyraMVP;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->model = model;
|
result->model = model;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Tyra {
|
|||||||
|
|
||||||
PipelineInfoBag::PipelineInfoBag() {
|
PipelineInfoBag::PipelineInfoBag() {
|
||||||
shadingType = TyraShadingFlat;
|
shadingType = TyraShadingFlat;
|
||||||
|
transformationType = TyraMVP;
|
||||||
textureMappingType = TyraLinear;
|
textureMappingType = TyraLinear;
|
||||||
blendingEnabled = true;
|
blendingEnabled = true;
|
||||||
antiAliasingEnabled = false;
|
antiAliasingEnabled = false;
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ void StaPipCore::render(StaPipBag* bag, const bool& frustumCull,
|
|||||||
TYRA_ASSERT(
|
TYRA_ASSERT(
|
||||||
!bag->texture || (bag->texture->texture && bag->texture->coordinates),
|
!bag->texture || (bag->texture->texture && bag->texture->coordinates),
|
||||||
"If you want texture, please provide texture and 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),
|
TYRA_ASSERT(!(frustumCull == false && bag->info->fullClipChecks == true),
|
||||||
"Full clip checks are not supported with frustum culling = off!");
|
"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);
|
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;
|
RendererCoreTextureBuffers* texBuffers = nullptr;
|
||||||
if (bag->texture) {
|
if (bag->texture) {
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ void StaticPipeline::render(StaticMesh* mesh, const StaPipOptions* options) {
|
|||||||
!(frustumCulling != PipelineFrustumCulling_Precise &&
|
!(frustumCulling != PipelineFrustumCulling_Precise &&
|
||||||
infoBag->fullClipChecks == true),
|
infoBag->fullClipChecks == true),
|
||||||
"Full clip checks are only supported with frustum culling == Precise!");
|
"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) {
|
if (frustumCulling == PipelineFrustumCulling_Simple) {
|
||||||
auto* frame = mesh->getFrame();
|
auto* frame = mesh->getFrame();
|
||||||
@@ -95,12 +100,14 @@ PipelineInfoBag* StaticPipeline::getInfoBag(StaticMesh* mesh,
|
|||||||
result->shadingType = options->shadingType;
|
result->shadingType = options->shadingType;
|
||||||
result->fullClipChecks = options->fullClipChecks;
|
result->fullClipChecks = options->fullClipChecks;
|
||||||
result->textureMappingType = options->textureMappingType;
|
result->textureMappingType = options->textureMappingType;
|
||||||
|
result->transformationType = options->transformationType;
|
||||||
} else {
|
} else {
|
||||||
result->antiAliasingEnabled = false;
|
result->antiAliasingEnabled = false;
|
||||||
result->blendingEnabled = true;
|
result->blendingEnabled = true;
|
||||||
result->shadingType = TyraShadingFlat;
|
result->shadingType = TyraShadingFlat;
|
||||||
result->textureMappingType = TyraLinear;
|
result->textureMappingType = TyraLinear;
|
||||||
result->fullClipChecks = false;
|
result->fullClipChecks = false;
|
||||||
|
result->transformationType = TyraMVP;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->model = model;
|
result->model = model;
|
||||||
|
|||||||
Reference in New Issue
Block a user