This commit is contained in:
Lendemor 2016-12-16 19:26:35 +01:00
commit 4d5c352f4c
7 changed files with 2187 additions and 8 deletions

9
data/bak/sword.mtl Normal file
View File

@ -0,0 +1,9 @@
#
# generated by kHED
#
newmtl steel
d 1.0
map_Kd steel.jpg
newmtl leather
d 1.0
map_Kd leather.jpg

2107
data/bak/sword.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -38,10 +38,10 @@ void GibGeneratorNode::update()
Gib *g = *it;
if(g->expiration < getEngine().getTime())
{
removeChild(g->graphics);
delete g->graphics;
it = m_gibs.erase(it);
getEngine().getPhysics()->removeCollisionObject(g->body);
removeChild(g->graphics);
it = m_gibs.erase(it);
delete g->graphics;
delete g;
}
else

View File

@ -3,7 +3,7 @@
GraphicalContainerNode::~GraphicalContainerNode()
{
setVisible(false); // renderer de-indexing
setSceneTree(nullptr);
for(GraphicalNode* child : m_children)
delete child;
}

View File

@ -185,19 +185,20 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
currentMesh->addTriangle(nb_vertices, nb_vertices+1, nb_vertices+2);
for(int i=0; i<3; ++i)
{
int offset = i*3;
if(norm.size() == 0)
{
if(tex.size() == 0)
currentMesh->addVertex(pos[tab[i]-1]);
currentMesh->addVertex(pos[tab[offset]-1]);
else
currentMesh->addVertex(pos[tab[i]-1], tex[tab[i+1]-1]);
currentMesh->addVertex(pos[tab[offset]-1], tex[tab[offset+1]-1]);
}
else
{
if(tex.size() == 0)
currentMesh->addVertex(pos[tab[i]-1], norm[tab[i+2]-1]);
currentMesh->addVertex(pos[tab[offset]-1], norm[tab[offset+2]-1]);
else
currentMesh->addVertex(pos[tab[i]-1], norm[tab[i+2]-1], tex[tab[i+1]-1]);
currentMesh->addVertex(pos[tab[offset]-1], norm[tab[offset+2]-1], tex[tab[offset+1]-1]);
}
}
}
@ -246,6 +247,11 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
meshes.pop_back();
--i;
}
else
{
Mesh* m = meshes[i];
m->mergeVertices();
}
}
return meshes;
}

View File

@ -1,6 +1,51 @@
#include "noise.h"
#include <iostream>
#include <glm/ext.hpp>
#include <ctime>
void Random::init()
{
std::srand(std::time(nullptr));
}
void Random::init(unsigned int seed)
{
std::srand(seed);
}
int Random::rand(int min, int max)
{
return std::rand();
}
long Random::rand(long min, long max)
{
long val;
int * ptr = ((int*)&val);
ptr[0] = std::rand();
ptr[1] = std::rand();
long range = max-min;
val = (val % range);
return (val > 0 ? val : val + range) + min;
}
float Random::rand(float min, float max)
{
float val = float(std::rand()) / RAND_MAX;
return val*(max-min) + min;
}
double Random::rand(double min, double max)
{
double val;
int * ptr = ((int*)&val);
ptr[0] = std::rand();
ptr[1] = std::rand();
return val*(max-min) + min;
}
Noise::Noise()
{

View File

@ -6,6 +6,18 @@
#define ARBITRARY_VALUE 12 // TODO : find an appropriate name
class Random
{
public:
static void init();
static void init(unsigned int seed);
static int rand(int min, int max);
static long rand(long min, long max);
static float rand(float min, float max);
static double rand(double min, double max);
};
class Noise
{
private: