GL4Dummies  0.1.7
Référence du fichier gl4dm.c

fonctions liées aux calculs mathématiques propres à l'utilisation de GL4Dummies. Plus de détails...

#include "gl4dm.h"
#include <stdlib.h>
#include <math.h>
Graphe des dépendances par inclusion de gl4dm.c:

Aller au code source de ce fichier.

Fonctions

double gl4dmURand (void)
 Retourne un nombre pseudo-aleatoire dans l'intervalle [0, 1[. Ici la distribution est uniforme. Plus de détails...
 
double gl4dmSURand (void)
 Retourne un nombre pseudo-aleatoire dans l'intervalle [-1, 1[. Ici la distribution est uniforme. Plus de détails...
 
double gl4dmGRand (void)
 Retourne un nombre pseudo-aleatoire dans l'intervalle ]-7, +7[. Ici la distribution est Gaussienne. Plus de détails...
 
double gl4dmGURand (void)
 Retourne un nombre pseudo-aleatoire dans l'intervalle [-1, +1[. Ici la distribution est Gaussienne centrée en zéro. Plus de détails...
 
static GLfloat hurst (GLfloat d, GLfloat H)
 
static void triangle_edge (GLfloat *im, int x, int y, int w, int h, int width, GLfloat ri, GLfloat H)
 
GLfloat * gl4dmTriangleEdge (GLuint width, GLuint height, GLfloat H)
 génère une heightmap en utilisant l'algorithme du triangle-edge. Les valeurs retournées dans la map sont comprises entre 0 et 1. Plus de détails...
 

Description détaillée

fonctions liées aux calculs mathématiques propres à l'utilisation de GL4Dummies.

Auteur
Farès BELHADJ amsi@.nosp@m.ai.u.nosp@m.niv-p.nosp@m.aris.nosp@m.8.fr
Date
November 12, 2014

Définition dans le fichier gl4dm.c.

Documentation des fonctions

◆ gl4dmGRand()

double gl4dmGRand ( void  )

Retourne un nombre pseudo-aleatoire dans l'intervalle ]-7, +7[. Ici la distribution est Gaussienne.

Tire du knuth : le rand Gaussien a deux valeurs par passe deux rand : X1 et X2.

Renvoie
un nombre pseudo-aleatoire selon une distribution gaussienne dans l'intervalle ]-7, +7[ (expérimentalement dans [-6.997568, 6.882738])
43  {
44  static int haveX2 = 0;
45  static double X2 = 0.0;
46  if (haveX2) {
47  haveX2 = 0;
48  return X2;
49  } else {
50  double V1, V2, S, precomp;
51  do {
52  V1 = 2.0 * (rand() / (double)RAND_MAX) - 1.0;
53  V2 = 2.0 * (rand() / (double)RAND_MAX) - 1.0;
54  S = V1 * V1 + V2 * V2;
55  } while (S >= 1.0);
56  if(S == 0.0) return (X2 = !((haveX2 = 1)));
57  precomp = sqrt(-2.0 * log(S) / S);
58  X2 = V2 * precomp;
59  haveX2 = 1;
60  return V1 * precomp; /* X1 */
61  }
62 }

Référencé par gl4dmGURand().

◆ gl4dmGURand()

double gl4dmGURand ( void  )

Retourne un nombre pseudo-aleatoire dans l'intervalle [-1, +1[. Ici la distribution est Gaussienne centrée en zéro.

Renvoie
un nombre pseudo-aleatoire selon une distribution gaussienne dans l'intervalle ]-1, +1[
71  {
72  return gl4dmGRand() / 7.0;
73 }

Références gl4dmGRand().

◆ gl4dmSURand()

double gl4dmSURand ( void  )

Retourne un nombre pseudo-aleatoire dans l'intervalle [-1, 1[. Ici la distribution est uniforme.

Renvoie
un nombre pseudo-aleatoire dans l'intervalle [-1, 1[.
28  {
29  return 2.0 * (rand() / (RAND_MAX + 1.0)) - 1.0;
30 }

Référencé par setDimensions(), et triangle_edge().

◆ gl4dmTriangleEdge()

GLfloat* gl4dmTriangleEdge ( GLuint  width,
GLuint  height,
GLfloat  H 
)

génère une heightmap en utilisant l'algorithme du triangle-edge. Les valeurs retournées dans la map sont comprises entre 0 et 1.

Paramètres
widthla largeur de la heightmap
heightla hauteur de la heightmap
Hexposant de Hurst, permet de controler la dimension fractale de la heightmap. La valeur standard est 0.5 (sinon entre 0 et 1)
Renvoie
la heightmap allouée/générée et qu'il faudra libérer avec free.
127  {
128  GLfloat * hm = calloc(width * height, sizeof *hm);
129  assert(hm);
130  hm[0] = GL4DM_EPSILON + gl4dmURand();
131  hm[width - 1] = GL4DM_EPSILON + gl4dmURand();
132  hm[(height - 1) * width + width - 1] = GL4DM_EPSILON + gl4dmURand();
133  hm[(height - 1) * width] = GL4DM_EPSILON + gl4dmURand();
134  triangle_edge(hm, 0, 0, width - 1, height - 1, width, 1, H);
135  return hm;
136 }

Références GL4DM_EPSILON, gl4dmURand(), et triangle_edge().

◆ gl4dmURand()

double gl4dmURand ( void  )

Retourne un nombre pseudo-aleatoire dans l'intervalle [0, 1[. Ici la distribution est uniforme.

Renvoie
un nombre pseudo-aleatoire dans l'intervalle [0, 1[.
19  {
20  return (rand() / (RAND_MAX + 1.0));
21 }

Référencé par gl4dmTriangleEdge().

◆ hurst()

static GLfloat hurst ( GLfloat  d,
GLfloat  H 
)
inlinestatic
75  {
76  return d / powf(2.0f, 2.0f * H);
77 }

Référencé par triangle_edge().

◆ triangle_edge()

static void triangle_edge ( GLfloat *  im,
int  x,
int  y,
int  w,
int  h,
int  width,
GLfloat  ri,
GLfloat  H 
)
static
79  {
80  GLint v;
81  GLint p[9][2], i, w_2 = w >> 1, w_21 = w_2 + (w&1), h_2 = h >> 1, h_21 = h_2 + (h&1);
82  ri = hurst(ri, H);
83  p[0][0] = x; p[0][1] = y;
84  p[1][0] = x + w; p[1][1] = y;
85  p[2][0] = x + w; p[2][1] = y + h;
86  p[3][0] = x; p[3][1] = y + h;
87  p[4][0] = x + w_2; p[4][1] = y;
88  p[5][0] = x + w; p[5][1] = y + h_2;
89  p[6][0] = x + w_2; p[6][1] = y + h;
90  p[7][0] = x; p[7][1] = y + h_2;
91  p[8][0] = x + w_2; p[8][1] = y + h_2;
92  for(i = 4; i < 8; i++) {
93  if(im[p[i][0] + p[i][1] * width] > 0)
94  continue;
95  im[v = p[i][0] + p[i][1] * width] = (im[p[i - 4][0] + p[i - 4][1] * width] +
96  im[p[(i - 3) % 4][0] + p[(i - 3) % 4][1] * width]) / 2.0;
97  im[v] += gl4dmSURand() * ri;
98  im[v] = MIN(MAX(im[v], GL4DM_EPSILON), 1.0);
99  }
100  if(im[p[i][0] + p[i][1] * width] < GL4DM_EPSILON) {
101  im[v = p[8][0] + p[8][1] * width] = (im[p[0][0] + p[0][1] * width] +
102  im[p[1][0] + p[1][1] * width] +
103  im[p[2][0] + p[2][1] * width] +
104  im[p[3][0] + p[3][1] * width]) / 4.0;
105  im[v] += gl4dmSURand() * ri * sqrt(2);
106  im[v] = MIN(MAX(im[v], GL4DM_EPSILON), 1.0);
107  }
108  if(w_2 > 1 || h_2 > 1)
109  triangle_edge(im, p[0][0], p[0][1], w_2, h_2, width, ri, H);
110  if(w_21 > 1 || h_2 > 1)
111  triangle_edge(im, p[4][0], p[4][1], w_21, h_2, width, ri, H);
112  if(w_21 > 1 || h_21 > 1)
113  triangle_edge(im, p[8][0], p[8][1], w_21, h_21, width, ri, H);
114  if(w_2 > 1 || h_21 > 1)
115  triangle_edge(im, p[7][0], p[7][1], w_2, h_21, width, ri, H);
116 }

Références GL4DM_EPSILON, gl4dmSURand(), hurst(), MAX, et MIN.

Référencé par gl4dmTriangleEdge().

triangle_edge
static void triangle_edge(GLfloat *im, int x, int y, int w, int h, int width, GLfloat ri, GLfloat H)
Definition: gl4dm.c:79
gl4dmSURand
double gl4dmSURand(void)
Retourne un nombre pseudo-aleatoire dans l'intervalle [-1, 1[. Ici la distribution est uniforme.
Definition: gl4dm.c:28
MIN
#define MIN(a, b)
Definition: gl4dm.h:57
gl4dmURand
double gl4dmURand(void)
Retourne un nombre pseudo-aleatoire dans l'intervalle [0, 1[. Ici la distribution est uniforme.
Definition: gl4dm.c:19
GL4DM_EPSILON
#define GL4DM_EPSILON
Definition: gl4dm.h:37
hurst
static GLfloat hurst(GLfloat d, GLfloat H)
Definition: gl4dm.c:75
MAX
#define MAX(a, b)
Definition: gl4dm.h:58
gl4dmGRand
double gl4dmGRand(void)
Retourne un nombre pseudo-aleatoire dans l'intervalle ]-7, +7[. Ici la distribution est Gaussienne.
Definition: gl4dm.c:43