fixed floors sample

This commit is contained in:
Sandro Sobczyński
2020-11-03 16:44:39 +01:00
parent 5aa2a9bdb5
commit b75b2d6e4f
30 changed files with 331 additions and 224 deletions
+4 -4
View File
@@ -5,17 +5,17 @@ EE_OBJS = \
../../engine/models/math/plane.o \
../../engine/models/math/point.o \
../../engine/models/math/vector3.o \
../../engine/models/dff_model.o \
../../engine/models/md2_model.o \
../../engine/models/mesh_frame.o \
../../engine/models/mesh_material.o \
../../engine/models/mesh.o \
../../engine/models/mesh_spec.o \
../../engine/models/obj_model.o \
../../engine/models/mesh_texture.o \
../../engine/modules/audio.o \
../../engine/modules/camera_base.o \
../../engine/modules/gif_sender.o \
../../engine/modules/light.o \
../../engine/modules/pad.o \
../../engine/modules/renderer.o \
../../engine/modules/texture_repository.o \
../../engine/modules/timer.o \
../../engine/modules/vif_sender.o \
../../engine/modules/vu1.o \
+2 -2
View File
@@ -5,10 +5,10 @@
Simple demo which shows lighting using PATH3, and player movement and animation.
### Assets
[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.0.0/samples/floors/assets.zip)
[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.1.0/samples/floors/assets.zip)
### Screenshot
[![Floors screenshot][floors-screenshot]](#)
[floors-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.0.0/samples/floors/floors.gif
[floors-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.1.0/samples/floors/floors.gif
+6
View File
@@ -33,6 +33,12 @@ void Floors::onInit()
engine.audio.addListener(&lightManager);
engine.audio.loadSong("NF-CHILL.WAV");
engine.audio.play();
texRepo = engine.renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player->mesh);
texRepo->addByMesh("floor/", *floorManager->meshes[0]);
for (size_t i = 1; i < floorManager->floorAmount; i++)
texRepo->getByMesh(floorManager->meshes[0]->getId(), floorManager->meshes[0]->getMaterial(0).getId())
->addLink(floorManager->meshes[i]->getId(), floorManager->meshes[i]->getMaterial(0).getId());
}
void Floors::onUpdate()
+2
View File
@@ -16,6 +16,7 @@
#include <engine.hpp>
#include "managers/floor_manager.hpp"
#include "managers/light_manager.hpp"
#include "modules/texture_repository.hpp"
#include "objects/player.hpp"
#include "./camera.hpp"
@@ -32,6 +33,7 @@ public:
Engine engine;
private:
TextureRepository *texRepo;
LightManager lightManager;
FloorManager *floorManager;
Player *player;
@@ -12,7 +12,6 @@
#include <utils/math.hpp>
#include <utils/debug.hpp>
#include <loaders/obj_loader.hpp>
// ----
// Constructors/Destructors
@@ -34,8 +33,6 @@ FloorManager::FloorManager(int t_floorAmount)
FloorManager::~FloorManager()
{
delete[] spirals;
delete[] spec;
delete[] obj;
delete[] meshes;
}
@@ -83,15 +80,13 @@ void FloorManager::initFloors()
PRINT_LOG("Initializing floors");
meshes = new Mesh *[floorAmount];
Vector3 initPos = Vector3(0.0F, 0.0F, 0.0F);
meshes[0] = new Mesh();
meshes[0]->loadObj("floor/", "floor.obj", initPos, 2.0F);
meshes[0]->loadObj("floor/", "floor", 2.0F, false);
meshes[0]->shouldBeFrustumCulled = true;
obj = meshes[0]->obj;
spec = meshes[0]->spec;
meshes[0]->shouldBeLighted = true;
for (u8 i = 0; i < floorAmount; i++)
{
floors[i].init(obj, spec, spirals[i], i);
floors[i].init(meshes[0], spirals[i], i);
meshes[i] = &floors[i].mesh;
}
PRINT_LOG("Floors initialized!");
@@ -14,8 +14,6 @@
class Player; // Forward definition
#include <models/math/point.hpp>
#include <models/obj_model.hpp>
#include <models/mesh_spec.hpp>
#include <modules/camera_base.hpp>
#include <models/audio_listener.hpp>
@@ -33,12 +31,10 @@ public:
void update(Player &t_player);
Mesh **meshes;
void onAudioTick();
MeshSpec *spec;
private:
u8 audioOffset, audioMode;
u32 audioTick;
ObjModel *obj;
Point *spirals;
void calcSpiral(int X, int Y);
void initFloors();
+3 -3
View File
@@ -36,10 +36,10 @@ Floor::~Floor() {}
* @param spiral Spiral position
* @param initOffset Number of floor (index)
*/
void Floor::init(ObjModel *obj, MeshSpec *spec, Point &spiral, u8 &initOffset)
void Floor::init(Mesh *mother, Point &spiral, u8 &initOffset)
{
Vector3 initPos = Vector3(0.00F, -10.00F, 0.00F);
this->mesh.setObj(initPos, obj, spec);
this->mesh.position.set(0.00F, -10.00F, 0.00F);
this->mesh.loadFrom(*mother);
this->initOffset = initOffset;
this->animTimer = rand() % FLOOR_ANIMATION_LENGTH;
this->mesh.shouldBeLighted = true;
+1 -2
View File
@@ -14,7 +14,6 @@
class Player; // Forward definition
#include <models/mesh.hpp>
#include <models/obj_model.hpp>
#include <models/math/point.hpp>
#include <tamtypes.h>
@@ -30,7 +29,7 @@ public:
Floor();
~Floor();
void init(ObjModel *obj, MeshSpec *spec, Point &spiral, u8 &initOffset);
void init(Mesh *mother, Point &spiral, u8 &initOffset);
void animate(Player &player);
};
+36 -33
View File
@@ -26,8 +26,8 @@ Player::Player()
this->gravity = 0.1F;
this->lift = -1.0F;
Vector3 initPos = Vector3(0.00F, 20.00F, 0.00F);
this->mesh.loadMD2("warrior/", "warrior.md2", initPos, 0.2F);
this->mesh.loadMD2("warrior/", "warrior", 0.2F, true);
this->mesh.position.set(0.00F, 20.00F, 0.00F);
this->mesh.rotation.x = -1.6F;
this->mesh.shouldBeBackfaceCulled = false;
this->mesh.shouldBeFrustumCulled = false;
@@ -39,7 +39,6 @@ Player::Player()
Player::~Player()
{
delete[] this->spec;
}
// ----
@@ -83,7 +82,7 @@ void Player::updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager
Vector3 max = Vector3();
for (int i = 0; i < floorManager.floorAmount; i++)
{
floorManager.floors[i].mesh.getMinMax(&min, &max);
getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max);
if (this->isCollideFloor == 1)
break;
@@ -106,37 +105,41 @@ void Player::onBeforePlayerFloorMove(Floor *floor, float &newY)
this->mesh.position.y -= -newY * 1.05F;
}
/** Calculates minimum and maximum X, Y, Z of this 3D objects vertices + current position */
// void Mesh::getMinMax(Vector3 *t_min, Vector3 *t_max)
// {
// Vector3 calc = Vector3();
// u8 isInitialized = 0;
// for (u32 i = 0; i < 8; i++)
// {
// getFarthestVertex(&calc, i);
// if (isInitialized == 0)
// {
// isInitialized = 1;
// t_min->set(calc);
// t_max->set(calc);
// }
/** Calculates minimum and maximum X, Y, Z of mesh vertices + current position */
void Player::getMinMax(Mesh *t_mesh, Vector3 *t_min, Vector3 *t_max)
{
Vector3 calc = Vector3();
u8 isInitialized = 0;
Vector3 *boundingBox = t_mesh->getCurrentBoundingBox();
for (u32 i = 0; i < 8; i++)
{
calc.set(
boundingBox[i].x + t_mesh->position.x,
boundingBox[i].y + t_mesh->position.y,
boundingBox[i].z + t_mesh->position.z);
if (isInitialized == 0)
{
isInitialized = 1;
t_min->set(calc);
t_max->set(calc);
}
// if (t_min->x > calc.x)
// t_min->x = calc.x;
// if (calc.x > t_max->x)
// t_max->x = calc.x;
if (t_min->x > calc.x)
t_min->x = calc.x;
if (calc.x > t_max->x)
t_max->x = calc.x;
// if (t_min->y > calc.y)
// t_min->y = calc.y;
// if (calc.y > t_max->y)
// t_max->y = calc.y;
if (t_min->y > calc.y)
t_min->y = calc.y;
if (calc.y > t_max->y)
t_max->y = calc.y;
// if (t_min->z > calc.z)
// t_min->z = calc.z;
// if (calc.z > t_max->z)
// t_max->z = calc.z;
// }
// }
if (t_min->z > calc.z)
t_min->z = calc.z;
if (calc.z > t_max->z)
t_max->z = calc.z;
}
}
/** Update player position by gravity and update index of current floor */
void Player::updateGravity(Pad &pad, FloorManager &floorManager)
@@ -150,7 +153,7 @@ void Player::updateGravity(Pad &pad, FloorManager &floorManager)
this->isOnFloor = 0;
for (int i = 0; i < floorManager.floorAmount; i++)
{
floorManager.floors[i].mesh.getMinMax(&min, &max);
getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isOnFloor = this->mesh.position.isOnSquare(min, max);
if (this->isOnFloor == 1)
{
+1 -2
View File
@@ -14,7 +14,6 @@
#include "../managers/floor_manager.hpp"
#include "../camera.hpp"
#include <modules/pad.hpp>
#include <models/mesh_spec.hpp>
#include <tamtypes.h>
/** Player 3D object class */
@@ -25,7 +24,6 @@ public:
float gravity, velocity, lift;
u8 isOnFloor, isCollideFloor, indexOfCurrentFloor;
Mesh mesh;
MeshSpec *spec;
Player();
~Player();
@@ -34,6 +32,7 @@ public:
private:
Vector3 playerNextPosition;
void getMinMax(Mesh *t_mesh, Vector3 *t_min, Vector3 *t_max);
void updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager);
void updateGravity(Pad &pad, FloorManager &floorManager);
};