finished tutorial 9

This commit is contained in:
h4570
2022-08-24 19:27:16 +02:00
parent 5c375dd24f
commit a21bcee671
11 changed files with 130 additions and 41 deletions
@@ -11,6 +11,7 @@
#pragma once
#include <tyra>
#include <memory>
namespace Tyra {
@@ -23,7 +24,22 @@ class Tutorial09 : public Game {
void loop();
private:
void setDrawData();
void loadBags();
Engine* engine;
StaticPipeline stapip;
Vec4 cameraPosition, cameraLookAt;
M4x4 translation, rotation, scale, model;
std::array<Vec4, 3> vertices;
std::array<Color, 3> colors;
std::unique_ptr<StaPipBag> bag;
std::unique_ptr<StaPipInfoBag> infoBag;
std::unique_ptr<StaPipColorBag> colorBag;
};
} // namespace Tyra
+75 -3
View File
@@ -13,12 +13,84 @@
namespace Tyra {
Tutorial09::Tutorial09(Engine* t_engine) : engine(t_engine) {}
Tutorial09::Tutorial09(Engine* t_engine) : engine(t_engine) {
translation = M4x4::Identity;
rotation = M4x4::Identity;
scale = M4x4::Identity;
model = M4x4::Identity;
}
Tutorial09::~Tutorial09() {}
void Tutorial09::init() {}
void Tutorial09::init() {
stapip.setRenderer(&engine->renderer.core);
void Tutorial09::loop() {}
cameraPosition = Vec4(0.0F, 0.0F, -10.0F);
cameraLookAt.unit();
setDrawData();
loadBags();
}
void Tutorial09::loop() {
rotation.rotateY(0.1F);
model = translation * rotation * scale;
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
{
engine->renderer.renderer3D.usePipeline(stapip);
/**
* Lets draw manually via "bags".
* You can do the same thing with dynamic pipeline.
*/
stapip.core.render(bag.get());
}
engine->renderer.endFrame();
}
void Tutorial09::setDrawData() {
vertices = {
Vec4(-3.0F, -3.0F, 0.0F),
Vec4(3.0F, -3.0F, 0.0F),
Vec4(0.0F, 3.0F, 0.0F),
};
colors = {
Color(128.0F, 0.0F, 0.0F),
Color(0.0F, 128.0F, 0.0F),
Color(0.0F, 0.0F, 128.0F),
};
}
void Tutorial09::loadBags() {
/**
* Create info bag and fill it with model matrix and shading type.
* Keep rest of the options as default.
*/
infoBag = std::make_unique<StaPipInfoBag>();
infoBag->model = &model;
infoBag->shadingType = TyraShadingGouraud;
/** Create colors bag and set data pointer */
colorBag = std::make_unique<StaPipColorBag>();
colorBag->many = colors.begin();
/**
* Create main bag and set:
* - vertices data
* - vertices count
* - pointers to other bags
*
* You can add here lighting and texture bag as well.
* If you want to have deeper look of this feature, please
* read static_pipeline.cpp code file.
*/
bag = std::make_unique<StaPipBag>();
bag->color = colorBag.get();
bag->info = infoBag.get();
bag->vertices = vertices.begin();
bag->count = vertices.size();
}
} // namespace Tyra