demo player movement

This commit is contained in:
h4570
2022-07-31 17:37:48 +02:00
parent 12dd72f15e
commit b94ef8c416
12 changed files with 134 additions and 15 deletions
+2
View File
@@ -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();
+2 -2
View File
@@ -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() {
+65 -10
View File
@@ -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;
}
+1 -1
View File
@@ -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;
@@ -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;
@@ -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;
};
@@ -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};
}
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);
@@ -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;
@@ -14,6 +14,7 @@ namespace Tyra {
PipelineInfoBag::PipelineInfoBag() {
shadingType = TyraShadingFlat;
transformationType = TyraMVP;
textureMappingType = TyraLinear;
blendingEnabled = true;
antiAliasingEnabled = false;
@@ -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) {
@@ -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;