finished 5 tutorial

This commit is contained in:
h4570
2022-08-23 22:18:53 +02:00
parent 3bbf3202ac
commit 9f831c7a6f
4 changed files with 98 additions and 3 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

@@ -23,7 +23,18 @@ class Tutorial05 : public Game {
void loop();
private:
void loadZombieMesh();
void loadWarriorMesh();
void warriorAnimationCallback(const AnimationSequenceCallback& callback);
Engine* engine;
Vec4 cameraPosition, cameraLookAt;
std::unique_ptr<DynamicMesh> warriorMesh;
std::unique_ptr<DynamicMesh> zombieMesh;
DynamicPipeline dynpip;
DynPipOptions renderOptions;
};
} // namespace Tyra
+85 -2
View File
@@ -17,8 +17,91 @@ Tutorial05::Tutorial05(Engine* t_engine) : engine(t_engine) {}
Tutorial05::~Tutorial05() {}
void Tutorial05::init() {}
void Tutorial05::init() {
dynpip.setRenderer(&engine->renderer.core);
void Tutorial05::loop() {}
cameraPosition = Vec4(0.0F, 0.0F, -10.0F);
cameraLookAt.unit();
loadZombieMesh();
loadWarriorMesh();
}
void Tutorial05::loop() {
zombieMesh->update(); // update animation state
warriorMesh->update();
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
{
engine->renderer.renderer3D.usePipeline(dynpip);
dynpip.render(zombieMesh.get(), renderOptions);
dynpip.render(warriorMesh.get(), renderOptions);
}
engine->renderer.endFrame();
}
void Tutorial05::loadZombieMesh() {
ObjLoaderOptions options;
options.scale = 20.0F;
options.flipUVs = true;
/** If count is > 1, loader will automatically add _00000X suffix */
options.animation.count = 6;
/** Starting file suffix index. It means that 1 will start from _000001.obj */
options.animation.startingIndex = 1;
/** If you want to know how to cook this file, please watch tutorial video */
auto data = ObjLoader::load(FileUtils::fromCwd("zombie/zombie.obj"), options);
zombieMesh = std::make_unique<DynamicMesh>(data.get());
zombieMesh->translation.translate(Vec4(-3.0F, -5.0F, 0.0F));
zombieMesh->rotation.rotateY(3.0F);
/**
* Tyra will play all frames by default.
* If you want to arrange animation frames by yourself, you can use this
* method.
*/
zombieMesh->animation.setSequence({3, 4, 5}); // fight animation
// zombieMesh->animation.setSequence({0, 1, 2}); // walk animation
zombieMesh->animation.loop = true;
engine->renderer.getTextureRepository().addByMesh(
zombieMesh.get(), FileUtils::fromCwd("zombie/"), "png");
}
void Tutorial05::loadWarriorMesh() {
MD2LoaderOptions options;
options.scale = .08F;
auto data =
MD2Loader::load(FileUtils::fromCwd("warrior/warrior.md2"), options);
warriorMesh = std::make_unique<DynamicMesh>(data.get());
warriorMesh->translation.translate(Vec4(3.0F, -4.0F, 0.0F));
warriorMesh->rotation.rotateX(-1.566F);
warriorMesh->rotation.rotateY(1.566F);
warriorMesh->animation.speed = 0.2F;
/** Callback can return useful animation informations */
warriorMesh->animation.setCallback(std::bind(
&Tutorial05::warriorAnimationCallback, this, std::placeholders::_1));
engine->renderer.getTextureRepository().addByMesh(
warriorMesh.get(), FileUtils::fromCwd("warrior/"), "png");
}
void Tutorial05::warriorAnimationCallback(
const AnimationSequenceCallback& callback) {
if (callback == AnimationSequenceCallback_Loop) {
TYRA_LOG("Warrior animation sequence is starting from beginning!");
}
}
} // namespace Tyra