finish 8 tutorial
This commit is contained in:
@@ -15,7 +15,10 @@ namespace Tyra {
|
||||
|
||||
Tutorial05::Tutorial05(Engine* t_engine) : engine(t_engine) {}
|
||||
|
||||
Tutorial05::~Tutorial05() {}
|
||||
Tutorial05::~Tutorial05() {
|
||||
engine->renderer.getTextureRepository().freeByMesh(zombieMesh.get());
|
||||
engine->renderer.getTextureRepository().freeByMesh(warriorMesh.get());
|
||||
}
|
||||
|
||||
void Tutorial05::init() {
|
||||
dynpip.setRenderer(&engine->renderer.core);
|
||||
|
||||
@@ -65,6 +65,14 @@ void Tutorial07::loadMeshWithLightmap() {
|
||||
ObjLoaderOptions options;
|
||||
options.scale = 2.0F;
|
||||
|
||||
/**
|
||||
* Material colors are automatically fetched from .mtl file
|
||||
* (Kd field)
|
||||
*
|
||||
* If you want to change it manually, just try to change
|
||||
* mesh.materials[].ambient
|
||||
*/
|
||||
|
||||
auto data = ObjLoader::load(FileUtils::fromCwd("cup.obj"), options);
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,20 @@ class Tutorial08 : public Game {
|
||||
void loop();
|
||||
|
||||
private:
|
||||
void loadCupMesh();
|
||||
void loadSkyboxMesh();
|
||||
|
||||
Vec4 cameraPosition, cameraLookAt;
|
||||
|
||||
Engine* engine;
|
||||
|
||||
u8 fpsCounter;
|
||||
|
||||
StaticPipeline stapip;
|
||||
StaPipOptions skyboxRenderOptions;
|
||||
StaPipOptions cupRenderOptions;
|
||||
std::unique_ptr<StaticMesh> skyboxMesh;
|
||||
std::unique_ptr<StaticMesh> cupMesh;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -13,12 +13,90 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Tutorial08::Tutorial08(Engine* t_engine) : engine(t_engine) {}
|
||||
Tutorial08::Tutorial08(Engine* t_engine) : engine(t_engine), fpsCounter(0) {}
|
||||
|
||||
Tutorial08::~Tutorial08() {}
|
||||
Tutorial08::~Tutorial08() {
|
||||
engine->renderer.getTextureRepository().freeByMesh(skyboxMesh.get());
|
||||
}
|
||||
|
||||
void Tutorial08::init() {}
|
||||
void Tutorial08::init() {
|
||||
stapip.setRenderer(&engine->renderer.core);
|
||||
|
||||
void Tutorial08::loop() {}
|
||||
cameraPosition = Vec4(0.0F, 0.0F, -10.0F);
|
||||
cameraLookAt.unit();
|
||||
|
||||
loadSkyboxMesh();
|
||||
loadCupMesh();
|
||||
|
||||
/** Uncomment this, to disable vsync */
|
||||
// engine->renderer.setFrameLimit(false);
|
||||
}
|
||||
|
||||
void Tutorial08::loop() {
|
||||
if (fpsCounter++ > 50) {
|
||||
fpsCounter = 0;
|
||||
TYRA_LOG("FPS: ", engine->info.getFps(),
|
||||
" RAM: ", engine->info.getAvailableRAM());
|
||||
}
|
||||
|
||||
cupMesh->rotation.rotate(Vec4(0.03F, 0.03F, 0.03F));
|
||||
|
||||
auto& utilityTools = engine->renderer.renderer3D.utility;
|
||||
|
||||
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
|
||||
{
|
||||
engine->renderer.renderer3D.usePipeline(stapip);
|
||||
stapip.render(skyboxMesh.get(), skyboxRenderOptions);
|
||||
stapip.render(cupMesh.get(), cupRenderOptions);
|
||||
|
||||
/** Utility drawing should be done AFTER pipeline rendering */
|
||||
|
||||
/** Draw cup bbox */
|
||||
utilityTools.drawBBox(
|
||||
cupMesh->frame->bbox->getTransformed(cupMesh->getModelMatrix()));
|
||||
|
||||
/** Draw line */
|
||||
utilityTools.drawLine(Vec4(50.0F, 50.0F, 50.0F), *cupMesh->getPosition(),
|
||||
Color(0.0F, 128.0F, 0.0F));
|
||||
|
||||
/** Draw box at origin */
|
||||
utilityTools.drawBox(Vec4(0.0F, 0.0F, 0.0F), 0.2F,
|
||||
Color(0.0F, 0.0F, 255.0F));
|
||||
}
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
|
||||
void Tutorial08::loadSkyboxMesh() {
|
||||
ObjLoaderOptions options;
|
||||
options.scale = 200.0F;
|
||||
options.flipUVs = true;
|
||||
|
||||
auto data = ObjLoader::load(FileUtils::fromCwd("skybox/skybox.obj"), options);
|
||||
|
||||
skyboxMesh = std::make_unique<StaticMesh>(data.get());
|
||||
|
||||
skyboxRenderOptions.frustumCulling = Tyra::PipelineFrustumCulling_None;
|
||||
|
||||
/**
|
||||
* We need to put the skybox at infinite Z, so this options
|
||||
* will help us to do that.
|
||||
*/
|
||||
skyboxRenderOptions.zTestType = Tyra::PipelineZTest_AllPass;
|
||||
|
||||
engine->renderer.getTextureRepository().addByMesh(
|
||||
skyboxMesh.get(), FileUtils::fromCwd("skybox/"), "png");
|
||||
}
|
||||
|
||||
void Tutorial08::loadCupMesh() {
|
||||
ObjLoaderOptions options;
|
||||
options.scale = 3.0F;
|
||||
|
||||
auto data = ObjLoader::load(FileUtils::fromCwd("cup/cup.obj"), options);
|
||||
data->textureCoordsEnabled = false;
|
||||
|
||||
cupMesh = std::make_unique<StaticMesh>(data.get());
|
||||
|
||||
cupMesh->translation.translateZ(10.0F);
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
Reference in New Issue
Block a user