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
+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);
};