Setup initial cube sample

This commit is contained in:
Wellinator
2021-04-07 08:17:10 -03:00
parent 11717f42eb
commit e43fae88e8
12 changed files with 218 additions and 64 deletions
+2 -1
View File
@@ -4,8 +4,9 @@ TYRA_DIR = ./../../engine
EE_OBJS = \
managers/light_manager.o \
objects/cube.o \
camera.o \
cube.o \
cubes.o \
main.o
EE_LIBS = -ltyra
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

+13
View File
@@ -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
+46
View File
@@ -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
-32
View File
@@ -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);
}
-28
View File
@@ -1,28 +0,0 @@
#ifndef _CUBE_
#define _CUBE_
#include <tamtypes.h>
#include <game.hpp>
#include <engine.hpp>
#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
+37
View File
@@ -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);
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef _CUBES_
#define _CUBES_
#include <tamtypes.h>
#include <game.hpp>
#include <engine.hpp>
#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
+3 -2
View File
@@ -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;
+58
View File
@@ -0,0 +1,58 @@
#include "cube.hpp"
#include <models/mesh.hpp>
#include <loaders/obj_loader.hpp>
#include <utils/debug.hpp>
// ----
// 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;
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef _CUBE_
#define _CUBE_
#include "../camera.hpp"
#include <tamtypes.h>
#include <modules/pad.hpp>
#include <modules/timer.hpp>
#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