Hallo!
Ik ben bezig met het leren van OpenGL en was begonnen aan een leuk heightmap-probeersel.
Het wireframe zit er goed uit, bij de normals gaat het echter helemaal de mist in.

Zoals je ziet, ziet het er ondanks de smooth-shading nogal brak en brokkerig uit.
De blauwe lijntjes zijn de berekende normals.
En hier de relevante code:
Weet iemand wat ik fout doe? De berekende normals zien er toch goed uit?
Ik ben bezig met het leren van OpenGL en was begonnen aan een leuk heightmap-probeersel.
Het wireframe zit er goed uit, bij de normals gaat het echter helemaal de mist in.

Zoals je ziet, ziet het er ondanks de smooth-shading nogal brak en brokkerig uit.
De blauwe lijntjes zijn de berekende normals.
En hier de relevante code:
C:
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
| glTranslatef( -heightMapWidth / 2, 0, -heightMapHeight / 2 ); glLightfv( GL_LIGHT0, GL_POSITION, light0_pos ); for( int y =0; y < heightMapHeight-1; ++y ) { for( int x =0; x < heightMapWidth-1; ++x ) { float height[4] = { 0, 0, 0, 0 }; height[0] =heightMapData[heightMapWidth*y +x] / heightDiv; height[1] =heightMapData[heightMapWidth*(y+1) +x]/ heightDiv; height[2] =heightMapData[heightMapWidth*y +x+1]/ heightDiv; height[3] =heightMapData[heightMapWidth*(y+1) +x+1]/ heightDiv; float point1[3] = { x, height[0], y }; float point2[3] = { x, height[1], y+1 }; float point3[3] = { x+1, height[2], y }; float point4[3] = { x+1, height[3], y+1 }; float norm1[3] = { 0, 0, 0 }; float norm2[3] = { 0, 0, 0 }; calcNormal( point1, point2, point3, norm1 ); calcNormal( point3, point2, point4, norm2 ); glEnable( GL_LIGHTING ); glBegin( GL_TRIANGLES ); glNormal3fv( norm1 ); glVertex3fv( point1 ); glVertex3fv( point2 ); glVertex3fv( point3 ); glEnd( ); glBegin( GL_TRIANGLES ); glNormal3fv( norm2 ); glVertex3fv( point3 ); glVertex3fv( point2 ); glVertex3fv( point4 ); glEnd( ); float plane1[3][3] = { { point1[0], point1[1], point1[2] }, { point2[0], point2[1], point2[2] }, { point3[0], point3[1], point3[2] } }; float plane2[3][3] = { { point3[0], point3[1], point3[2] }, { point2[0], point2[1], point2[2] }, { point4[0], point4[1], point4[2] } }; float linePoint1[3]; float linePoint2[3]; glDisable( GL_LIGHTING ); qglColor( blue ); glBegin( GL_LINES ); lineNormal( plane1, norm1, linePoint1, linePoint2 ); glVertex3fv( linePoint1 ); glVertex3fv( linePoint2 ); lineNormal( plane2, norm2, linePoint1, linePoint2 ); glVertex3fv( linePoint1 ); glVertex3fv( linePoint2 ); glEnd( ); } } |
Weet iemand wat ik fout doe? De berekende normals zien er toch goed uit?

