fixed mesh loading, added random utils static class
This commit is contained in:
parent
ebb77b7470
commit
438a0162e4
@ -185,19 +185,20 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
|
|||||||
currentMesh->addTriangle(nb_vertices, nb_vertices+1, nb_vertices+2);
|
currentMesh->addTriangle(nb_vertices, nb_vertices+1, nb_vertices+2);
|
||||||
for(int i=0; i<3; ++i)
|
for(int i=0; i<3; ++i)
|
||||||
{
|
{
|
||||||
|
int offset = i*3;
|
||||||
if(norm.size() == 0)
|
if(norm.size() == 0)
|
||||||
{
|
{
|
||||||
if(tex.size() == 0)
|
if(tex.size() == 0)
|
||||||
currentMesh->addVertex(pos[tab[i]-1]);
|
currentMesh->addVertex(pos[tab[offset]-1]);
|
||||||
else
|
else
|
||||||
currentMesh->addVertex(pos[tab[i]-1], tex[tab[i+1]-1]);
|
currentMesh->addVertex(pos[tab[offset]-1], tex[tab[offset+1]-1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(tex.size() == 0)
|
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
|
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();
|
meshes.pop_back();
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mesh* m = meshes[i];
|
||||||
|
m->mergeVertices();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,51 @@
|
|||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <glm/ext.hpp>
|
#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()
|
Noise::Noise()
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,18 @@
|
|||||||
|
|
||||||
#define ARBITRARY_VALUE 12 // TODO : find an appropriate name
|
#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
|
class Noise
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user