Salut,

j'ai essayé d'adapté le tuto sur les heighmaps à mon projet, mais j'ai quelque difficulté à avoir un résultat satisfaisant...

J'ai utilisé les même images que dans le tuto (la heighmap et la texture général), voici un screen du résultat :


En fait c'est principalement ce que j'ai fait pour la méthode getPixel() dans le tuto qui me pose problème :
Citation Envoyé par tuto
Point3D<GLfloat> vertex4( x,
getPixel( x, getPrecision()+z ),
getPrecision()+z,
(x)/(float)getWidth (),
1.f-((z+getPrecision())/getHeight()) );
Voila ma classe map
Code Map.hpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef DEF_MAP_HPP
#define DEF_MAP_HPP
 
#include "Global.hpp"
 
class Map
{
	private:
		unsigned int   _precision;
		unsigned int   _width;
		unsigned int   _height;
		unsigned char* _pixels;
		sf::Image      _textureMain;
		GLuint         _list;
 
		bool loadHeightmap( const std::string& filename );
		bool loadTexture  ( const std::string& filename );
		void compile();
 
	public:
		Map();
		~Map();
 
		void render( sf::RenderWindow& w );
};
 
#endif

Code Map.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Map.hpp"
 
Map::Map()
{
	_precision = 1;
	loadHeightmap("data/heightmap.png");
	loadTexture("data/texture.png");
	compile();
}
 
void Map::compile()
{
	// Génération d'un identifiant pour notre display lsit
	_list = glGenLists( 1 );
 
	// display list
	glNewList( _list, GL_COMPILE );
	{
		glBegin( GL_TRIANGLES );
		{
			//  Pour chaque ligne, avec un pas dépendant de la précision souhaitée
			for( unsigned int x=0; x<(_height-_precision); x+=_precision)
			{
				// Pour chaque colonne, avec un pas dépendant de la précision souhaitée
				for( unsigned int z=0; z<(_width-_precision); z+=_precision)
				{
					// Définition des coordonnées des points
 
					// triangle 1
					//v3
					glTexCoord2f( (x+_precision)/_width, (1.f-(z+_precision))/_height );
					glVertex3f( _precision+x, _pixels[_precision+z*_height+_precision+x], _precision+z );
 
					//v2
					glTexCoord2f( (x+_precision)/_width, 1.f-(z/_height) );
					glVertex3f( _precision+x, _pixels[z*_height+_precision+x], z );
 
					//v1
					glTexCoord2f( x/_width, 1.f-(z/_height) );
					glVertex3f( x, _pixels[z*_height+x], z );
 
					// triange 2
					//v4
					glTexCoord2f( x/_width, (1.f-(z+_precision))/_height );
					glVertex3f( x, _pixels[_precision+z*_height+x], _precision+z );
 
					//v3
					glTexCoord2f( (x+_precision)/_width, (1.f-(z+_precision))/_height );
					glVertex3f( _precision+x, _pixels[_precision+z*_height+_precision+x], _precision+z );
 
					//v1
					glTexCoord2f( x/_width, 1.f-(z/_height) );
					glVertex3f( x, _pixels[z*_height+x], z );
				}
			}
		}
		glEnd();
	}
	glEndList();
}
 
 
void Map::render( sf::RenderWindow& w )
{
	_textureMain.Bind(); // Sélection de la texture principale
	glCallList( _list ); // Appel de la display list
}
 
bool Map::loadHeightmap( const std::string& filename )
{
	sf::Image image;
 
	if ( !image.LoadFromFile(filename) )
		return false;
 
	_width = image.GetWidth ();
	_height = image.GetHeight();
 
	// Le tableau renvoyé par GetPixelsPtr() contient les 4 composantes RGBA
	// sous forme de char
	static const int elemSize = 4;
 
	// La taille totale du tableau renvoyé par GetPixelsPtr()
	const int size = image.GetWidth() * image.GetHeight() * 4;
 
	// Création de notre propre tableau qui ne contiendra qu'une composante (noir et blanc)
	_pixels = new unsigned char[size/elemSize];
 
	// On stocke un pointeur vers le tableau renvoyé par GetPixelsPtr() pour y accéder plus
	// simplement
	const unsigned char* const px = image.GetPixelsPtr();
 
	// On copie les pixels
	for ( int i=0; i<size/elemSize; ++i )
	{
		_pixels[i] = px[i*elemSize];
	}
 
	return true;
}
 
bool Map::loadTexture( const std::string& filename )
{
	if ( !_textureMain.LoadFromFile(filename) )
		return false;
	return true;
}
 
Map::~Map()
{
	delete _pixels;
}

J'appel render() lorsque je dessine ma scene.
J'aurais besoin d'un peu d'aide pour déterminer les pixels à afficher dans mes boucles :/
J'ai essayé de m'arranger avec
Citation Envoyé par tuto
tableau_multidimensionnel[x][y] == tableau_monodimensionnel[y*height+x] Le schéma ci-dessous clarifiera les choses:
mais on dirais que ca pas trop bien marché ...

Merci d'avance !