diff --git a/src/samples/cube/Makefile b/src/samples/cube/Makefile index 7d1b17f..09c7d18 100644 --- a/src/samples/cube/Makefile +++ b/src/samples/cube/Makefile @@ -3,9 +3,10 @@ EE_BIN = cube.elf TYRA_DIR = ./../../engine EE_OBJS = \ - managers/light_manager.o \ + managers/light_manager.o \ + objects/cube.o \ camera.o \ - cube.o \ + cubes.o \ main.o EE_LIBS = -ltyra diff --git a/src/samples/cube/bin/AUDSRV.IRX b/src/samples/cube/bin/AUDSRV.IRX new file mode 100644 index 0000000..8699022 Binary files /dev/null and b/src/samples/cube/bin/AUDSRV.IRX differ diff --git a/src/samples/cube/bin/meshes/cube/Material.png b/src/samples/cube/bin/meshes/cube/Material.png new file mode 100644 index 0000000..617d353 Binary files /dev/null and b/src/samples/cube/bin/meshes/cube/Material.png differ diff --git a/src/samples/cube/bin/meshes/cube/cube.mtl b/src/samples/cube/bin/meshes/cube/cube.mtl new file mode 100644 index 0000000..fe6f616 --- /dev/null +++ b/src/samples/cube/bin/meshes/cube/cube.mtl @@ -0,0 +1,13 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Material +Ns 0.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 +map_Kd Z:\\home\\wellington\\repos\\tyra\\src\\samples\\cube\\bin\\meshes\\cube\\Material.png diff --git a/src/samples/cube/bin/meshes/cube/cube.obj b/src/samples/cube/bin/meshes/cube/cube.obj new file mode 100644 index 0000000..db3c258 --- /dev/null +++ b/src/samples/cube/bin/meshes/cube/cube.obj @@ -0,0 +1,46 @@ +# Blender v2.92.0 OBJ File: '' +# www.blender.org +mtllib cube.mtl +o Cube +v 1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 -1.000000 +v 1.000000 1.000000 1.000000 +v 1.000000 -1.000000 1.000000 +v -1.000000 1.000000 -1.000000 +v -1.000000 -1.000000 -1.000000 +v -1.000000 1.000000 1.000000 +v -1.000000 -1.000000 1.000000 +vt 2.000000 2.000000 +vt 1.000000 3.000000 +vt 1.000000 2.000000 +vt 0.000000 4.000000 +vt 0.000000 3.000000 +vt 1.000000 0.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 0.000000 2.000000 +vt -1.000000 3.000000 +vt -1.000000 2.000000 +vt 1.000000 1.000000 +vt 2.000000 3.000000 +vt 1.000000 4.000000 +vn 0.0000 1.0000 0.0000 +vn 0.0000 0.0000 1.0000 +vn -1.0000 0.0000 0.0000 +vn 0.0000 -1.0000 0.0000 +vn 1.0000 0.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +usemtl Material +s off +f 5/1/1 3/2/1 1/3/1 +f 3/2/2 8/4/2 4/5/2 +f 7/6/3 6/7/3 8/8/3 +f 2/9/4 8/10/4 6/11/4 +f 1/3/5 4/5/5 2/9/5 +f 5/12/6 2/9/6 6/7/6 +f 5/1/1 7/13/1 3/2/1 +f 3/2/2 7/14/2 8/4/2 +f 7/6/3 5/12/3 6/7/3 +f 2/9/4 4/5/4 8/10/4 +f 1/3/5 3/2/5 4/5/5 +f 5/12/6 1/3/6 2/9/6 diff --git a/src/samples/cube/cube.cpp b/src/samples/cube/cube.cpp deleted file mode 100644 index c0b4399..0000000 --- a/src/samples/cube/cube.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "cube.hpp" - -Cube::Cube(Engine *t_engine) - : engine(t_engine), camera(&t_engine->screen) -{ - return; -} - -Cube::~Cube() -{ - return; -} - -void Cube::onInit(){ - setBgColorAndAmbientColor(); - engine->renderer->setCameraDefinitions(&camera.view, &camera.unitCirclePosition, camera.planes); -} - -void Cube::onUpdate(){ - lightManager.update(); -} - -void Cube::setBgColorAndAmbientColor() -{ - color_t bgColor; - bgColor.r = 0x20; - bgColor.g = 0x20; - bgColor.b = 0x20; - engine->renderer->setWorldColor(bgColor); - Vector3 ambient = Vector3(0.003F, 0.003F, 0.003F); - engine->renderer->setAmbientLight(ambient); -} \ No newline at end of file diff --git a/src/samples/cube/cube.hpp b/src/samples/cube/cube.hpp deleted file mode 100644 index b46c0bc..0000000 --- a/src/samples/cube/cube.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _CUBE_ -#define _CUBE_ - -#include -#include -#include -#include "managers/light_manager.hpp" -#include "./camera.hpp" - -class Cube : public Game -{ - -public: - Cube(Engine *t_engine); - ~Cube(); - - void onInit(); - void onUpdate(); - - Engine *engine; - -private: - void setBgColorAndAmbientColor(); - LightManager lightManager; - Camera camera; -}; - -#endif \ No newline at end of file diff --git a/src/samples/cube/cubes.cpp b/src/samples/cube/cubes.cpp new file mode 100644 index 0000000..3e61895 --- /dev/null +++ b/src/samples/cube/cubes.cpp @@ -0,0 +1,37 @@ +#include "cubes.hpp" + +Cubes::Cubes(Engine *t_engine) + : engine(t_engine), camera(&t_engine->screen) +{ + PRINT_LOG("Initing cubes sample"); +} + +Cubes::~Cubes() +{ + return; +} + +void Cubes::onInit(){ + texRepo = engine->renderer->getTextureRepository(); + cube = new Cube(texRepo); + setBgColorAndAmbientColor(); + engine->renderer->setCameraDefinitions(&camera.view, &camera.unitCirclePosition, camera.planes); +} + +void Cubes::onUpdate(){ + lightManager.update(); + camera.update(engine->pad, cube->mesh); + cube->update(engine->pad, camera); + engine->renderer->draw(cube->mesh); +} + +void Cubes::setBgColorAndAmbientColor() +{ + color_t bgColor; + bgColor.r = 0x50; + bgColor.g = 0x50; + bgColor.b = 0x50; + engine->renderer->setWorldColor(bgColor); + Vector3 ambient = Vector3(0.2F, 0.2F, 0.2F); + engine->renderer->setAmbientLight(ambient); +} \ No newline at end of file diff --git a/src/samples/cube/cubes.hpp b/src/samples/cube/cubes.hpp new file mode 100644 index 0000000..0a14eb6 --- /dev/null +++ b/src/samples/cube/cubes.hpp @@ -0,0 +1,32 @@ +#ifndef _CUBES_ +#define _CUBES_ + +#include +#include +#include +#include "managers/light_manager.hpp" +#include "modules/texture_repository.hpp" +#include "camera.hpp" +#include "objects/cube.hpp" + +class Cubes : public Game +{ + + public: + Cubes(Engine *t_engine); + ~Cubes(); + + void onInit(); + void onUpdate(); + + Engine *engine; + + private: + void setBgColorAndAmbientColor(); + TextureRepository *texRepo; + Cube *cube; + LightManager lightManager; + Camera camera; +}; + +#endif \ No newline at end of file diff --git a/src/samples/cube/main.cpp b/src/samples/cube/main.cpp index 1b62314..dc03ec4 100644 --- a/src/samples/cube/main.cpp +++ b/src/samples/cube/main.cpp @@ -1,9 +1,10 @@ -#include "cube.hpp" +#include "cubes.hpp" int main() { + PRINT_LOG("INIT"); Engine engine = Engine(); - Cube game = Cube(&engine); + Cubes game = Cubes(&engine); game.engine->init(&game, 128); SleepThread(); return 0; diff --git a/src/samples/cube/objects/cube.cpp b/src/samples/cube/objects/cube.cpp new file mode 100644 index 0000000..60a660b --- /dev/null +++ b/src/samples/cube/objects/cube.cpp @@ -0,0 +1,58 @@ +#include "cube.hpp" +#include +#include +#include + +// ---- +// Constructors/Destructors +// ---- + +Cube::Cube( TextureRepository *t_texRepo ) +{ + PRINT_LOG("Creating cube"); + texRepo = t_texRepo; + speed = 1.5F; + + mesh.loadObj("meshes/cube/", "cube", 6.0F, true); + mesh.position.set(20.00F, 40.00F, 10.00F); + mesh.rotation.x = -1.566F; + mesh.rotation.z = 1.566F; + + texRepo->addByMesh("meshes/cube/", mesh, PNG); + + PRINT_LOG("Cube object created!"); +} + +void Cube::update(const Pad &t_pad, const Camera &t_camera) +{ + Vector3 *nextPos = getNextPosition(t_pad, t_camera); +} + +Vector3 *Cube::getNextPosition(const Pad &t_pad, const Camera &t_camera) +{ + Vector3 *result = new Vector3(mesh.position); + Vector3 normalizedCamera = Vector3(t_camera.unitCirclePosition); + normalizedCamera.normalize(); + normalizedCamera *= speed; + if (t_pad.lJoyV <= 100) + { + result->x += -normalizedCamera.x; + result->z += -normalizedCamera.z; + } + else if (t_pad.lJoyV >= 200) + { + result->x += normalizedCamera.x; + result->z += normalizedCamera.z; + } + if (t_pad.lJoyH <= 100) + { + result->x += -normalizedCamera.z; + result->z += normalizedCamera.x; + } + else if (t_pad.lJoyH >= 200) + { + result->x += normalizedCamera.z; + result->z += -normalizedCamera.x; + } + return result; +} \ No newline at end of file diff --git a/src/samples/cube/objects/cube.hpp b/src/samples/cube/objects/cube.hpp new file mode 100644 index 0000000..22abe35 --- /dev/null +++ b/src/samples/cube/objects/cube.hpp @@ -0,0 +1,26 @@ +#ifndef _CUBE_ +#define _CUBE_ + +#include "../camera.hpp" +#include +#include +#include +#include "modules/texture_repository.hpp" + +/** Cube 3D object class */ +class Cube +{ + public: + Mesh mesh; + Cube( TextureRepository *t_texRepo ); + ~Cube(); + + void update(const Pad &t_pad, const Camera &t_camera); + + private: + TextureRepository *texRepo; + Vector3 *getNextPosition(const Pad &t_pad, const Camera &t_camera); + float speed; +}; + +#endif