#include "Level.h" #include "Log.h" #include "Global.h" #include "Instance.h" #include namespace { void CreateTransform(float* out, Vec3 pos, Quat rot = {}, Vec3 scale = {1.0f, 1.0f, 1.0f}) { if (out == nullptr) return; float rMat[16]{0}; float tMat[16]{0}; float sMat[16]{0}; bx::mtxFromQuaternion(rMat, bx::Quaternion{rot.X, rot.Y, rot.Z, rot.W}); bx::mtxTranslate(tMat, pos.X, pos.Y, pos.Z); bx::mtxScale(sMat, scale.X, scale.Y, scale.Z); float buf[16]{0}; bx::mtxMul(buf, rMat, sMat); bx::mtxMul(out, buf, tMat); } } namespace Game { void Level::Setup(GameData& data) { Log("Level setup"); Cubes.Setup(data.EntityStorage); if (Cubes.Count == 0) { for (uint32_t yy = 0; yy < 11; ++yy) { for (uint32_t xx = 0; xx < 11; ++xx) { Cube* c = Cubes.New(); if (c) { c->TestX = xx; c->TestY = yy; } } } Cube* floor = Cubes.New(); } } void Level::Update() { Cubes.Update(); } void Cube::Setup() { } void Cube::Update() { if (TestX >= 0 && TestY >= 0) { double globalTime = GetInstance().Now; double time = TestY <= 5 ? globalTime * 1.0f : 0.0f; if (TestX == 4 && TestY == 4) { // bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); // bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(0.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); } else { float scale = 1.0f + TestX * 0.4f; CreateTransform(Transform.M, Vec3{TestX * 10.0f - 40.0f, TestY * 10.0f - 40.0f, (float)TestX}, Quat::FromEuler(time * 10.0f + TestX, time * 5.0f * TestY, 0.0f), {scale, scale, scale} ); } } else { CreateTransform(Transform.M, {0.0f, -30.0f, 100.0f}, {}, {100.0f, 10.0f, 100.0f}); } } }