Bonjour, j'utilise MS Visual C++ 2005 et je dois afficher une scene 3D comprenant une maison (2 polygones : pavé & toit)
Mes structures sont définies mais je ne sait pas comment & quelles sont les fonctions pour afficher un polygone ?
Dans mon cours on me dit d'appeller aussi une fonction permettant de dessiner des triangles (possibiliter d'implémenter).
void scanCon2DTr(HDC hdc, int x1, int y1, int x2, int y2, int x3, int y3, COLORREF c);
DataStruct.h :
DataStruct.c :
Code : 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 #ifndef _3D_DATASTRUCT_H #define _3D_DATASTRUCT_H #include "windows.h" /* Colour */ typedef struct structTagRGBColour { int red, green, blue; /* red, green, blue components*/ } RGBColour, /* RGB colour */ * pRGBColour; /* pointer to RGB colour */ /* 2D vertex */ typedef struct tagVertex2D { double x, y; /* x and y coordinates of a vertex */ } Vertex2D, /* 2D vertex */ * pVertex2D; /* pointer to 2D vertex */ /* 3D vertex */ typedef struct tagVertex { double x, y, z; /* x, y, and z coordinates of a vertex */ } Vertex3D, /* 3D vertex */ * pVertex3D; /* pointer to 3D vertex */ /* 3D polygon */ typedef struct structTag3DPolygon { int f3SidedPoly[3]; /* each integer is index of vertex in array of vertices for object */ int visible; /* polygon visibility flag: 1 -> visible, 0 ->invisible */ } f3DPolygon, /* 3D polygon */ * p3DPolygon, /* pointer to 3D polygon */ f3DFacet, /* 3D facet */ * p3DFacet; /* pointer to 3D facet */ /* 3D object */ typedef struct structTag3DObject { p3DFacet pFacetArray; /* array of facets */ int numFacets; /* number of object facets */ pVertex3D pVertexArray; /* array of vertex coordinates */ int numVertices; /* count of object vertices */ /* modelling transformation parameters */ Vertex3D worldPosition; /* object position */ double xScale, yScale, zScale; /* object's x, y, and z scale factors */ double rotXAngle, rotYAngle, rotZAngle; /* object's x, y, and z angle (degrees) of rotation */ RGBColour colour; /* object colour */ int visible; /* object visibility flag: 1 -> visible, 0 ->invisible */ } f3DObject, /* 3D Object */ * p3DObject; /* pointer to 3D object */ /* Object group */ typedef struct structTag3DObjectGroup { p3DObject pObjectArray; /* array of objects in group */ int numObjs; /* count of objects in group */ } f3DObjectGroup, /* group of 3D object */ * p3DObjectGroup; /* pointer to group of 3D object */ /* Scene */ typedef struct structTag3DScene { p3DObjectGroup pObjGroupArray; /* array of grouped scene objects */ int numObjGroups; /* count of grouped scene objects */ } f3DScene, /* 3D Scene */ * p3DScene; /* pointer to 3D scene */ /* Function prototypes */ void loadHouseData(p3DScene scene); void loadWallsData(p3DObject pObj); void loadRoofData(p3DObject pObj); p3DObjectGroup allocateObjGroupArray(int numObjGroups); p3DObject allocateObjectArray(int numObjects); p3DFacet allocateFacetArray(int numFacets); Vertex3D * allocateVertexArray(int numVertices); #endif /* _3D_DATASTRUCT_H */
PS : je débute en 3D
Code : 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 /* This function loads a specific scene (house) */ void loadHouseData(p3DScene pWorld ) { pWorld->numObjGroups = 2; if ( (pWorld->pObjGroupArray = allocateObjGroupArray(pWorld->numObjGroups)) == NULL ) { return; /* improve */ } else { pWorld->pObjGroupArray[0].numObjs = 1; /* each object group has one object */ pWorld->pObjGroupArray[1].numObjs = 1; if ( (pWorld->pObjGroupArray[0].pObjectArray = allocateObjectArray(pWorld->pObjGroupArray[0].numObjs)) == NULL ) { return; /* improve */ } else if ( (pWorld->pObjGroupArray[1].pObjectArray = allocateObjectArray(pWorld->pObjGroupArray[1].numObjs)) == NULL ) { return; /* improve */ } loadWallsData(&(pWorld->pObjGroupArray[0].pObjectArray[0])); /* load walls data */ loadRoofData(&(pWorld->pObjGroupArray[1].pObjectArray[0])); /* load roof data */ } return; } /* This function loads wall data for a house */ void loadWallsData(p3DObject pWalls) { pWalls->numFacets = 8; if ( (pWalls->pFacetArray = allocateFacetArray(pWalls->numFacets)) == NULL ) { return; /* improve */ } else { pWalls->pFacetArray[0].f3SidedPoly[0] = 0; pWalls->pFacetArray[0].f3SidedPoly[1] = 1; pWalls->pFacetArray[0].f3SidedPoly[2] = 2; pWalls->pFacetArray[0].visible = 1; pWalls->pFacetArray[1].f3SidedPoly[0] = 0; pWalls->pFacetArray[1].f3SidedPoly[1] = 2; pWalls->pFacetArray[1].f3SidedPoly[2] = 3; pWalls->pFacetArray[1].visible = 1; pWalls->pFacetArray[2].f3SidedPoly[0] = 3; pWalls->pFacetArray[2].f3SidedPoly[1] = 2; pWalls->pFacetArray[2].f3SidedPoly[2] = 5; pWalls->pFacetArray[2].visible = 1; pWalls->pFacetArray[3].f3SidedPoly[0] = 3; pWalls->pFacetArray[3].f3SidedPoly[1] = 5; pWalls->pFacetArray[3].f3SidedPoly[2] = 4; pWalls->pFacetArray[3].visible = 1; pWalls->pFacetArray[4].f3SidedPoly[0] = 4; pWalls->pFacetArray[4].f3SidedPoly[1] = 5; pWalls->pFacetArray[4].f3SidedPoly[2] = 6; pWalls->pFacetArray[4].visible = 1; pWalls->pFacetArray[5].f3SidedPoly[0] = 4; pWalls->pFacetArray[5].f3SidedPoly[1] = 6; pWalls->pFacetArray[5].f3SidedPoly[2] = 7; pWalls->pFacetArray[5].visible = 1; pWalls->pFacetArray[6].f3SidedPoly[0] = 7; pWalls->pFacetArray[6].f3SidedPoly[1] = 1; pWalls->pFacetArray[6].f3SidedPoly[2] = 0; pWalls->pFacetArray[6].visible = 1; pWalls->pFacetArray[7].f3SidedPoly[0] = 7; pWalls->pFacetArray[7].f3SidedPoly[1] = 6; pWalls->pFacetArray[7].f3SidedPoly[2] = 1; pWalls->pFacetArray[7].visible = 1; } pWalls->numVertices = 8; if ( (pWalls->pVertexArray = allocateVertexArray(pWalls->numVertices)) == NULL ) { return; /* improve */ } else { pWalls->pVertexArray[0].x = 0; pWalls->pVertexArray[0].y = 1; pWalls->pVertexArray[0].z = 1; pWalls->pVertexArray[1].x = 0; pWalls->pVertexArray[1].y = 0; pWalls->pVertexArray[1].z = 1; pWalls->pVertexArray[2].x = 1; pWalls->pVertexArray[2].y = 0; pWalls->pVertexArray[2].z = 1; pWalls->pVertexArray[3].x = 1; pWalls->pVertexArray[3].y = 1; pWalls->pVertexArray[3].z = 1; pWalls->pVertexArray[4].x = 1; pWalls->pVertexArray[4].y = 1; pWalls->pVertexArray[4].z = 0; pWalls->pVertexArray[5].x = 1; pWalls->pVertexArray[5].y = 0; pWalls->pVertexArray[5].z = 0; pWalls->pVertexArray[6].x = 0; pWalls->pVertexArray[6].y = 0; pWalls->pVertexArray[6].z = 0; pWalls->pVertexArray[7].x = 0; pWalls->pVertexArray[7].y = 1; pWalls->pVertexArray[7].z = 0; } pWalls->worldPosition.x = 10, pWalls->worldPosition.y = 0, pWalls->worldPosition.z = 0; pWalls->xScale = pWalls->yScale = pWalls->zScale = 100; pWalls->rotXAngle = pWalls->rotYAngle = pWalls->rotZAngle = 0; pWalls->colour.red = 128, pWalls->colour.green = 128, pWalls->colour.blue = 128; pWalls->visible = 1; return; } /* This function loads roof data for a house */ void loadRoofData(p3DObject pRoof) { pRoof->numFacets = 6; if ( (pRoof->pFacetArray = allocateFacetArray(pRoof->numFacets)) == NULL ) { return; /* improve */ } else { pRoof->pFacetArray[0].f3SidedPoly[0] = 0; pRoof->pFacetArray[0].f3SidedPoly[1] = 1; pRoof->pFacetArray[0].f3SidedPoly[2] = 2; pRoof->pFacetArray[0].visible = 1; pRoof->pFacetArray[1].f3SidedPoly[0] = 0; pRoof->pFacetArray[1].f3SidedPoly[1] = 2; pRoof->pFacetArray[1].f3SidedPoly[2] = 3; pRoof->pFacetArray[1].visible = 1; pRoof->pFacetArray[2].f3SidedPoly[0] = 3; pRoof->pFacetArray[2].f3SidedPoly[1] = 2; pRoof->pFacetArray[2].f3SidedPoly[2] = 5; pRoof->pFacetArray[2].visible = 1; pRoof->pFacetArray[3].f3SidedPoly[0] = 3; pRoof->pFacetArray[3].f3SidedPoly[1] = 5; pRoof->pFacetArray[3].f3SidedPoly[2] = 4; pRoof->pFacetArray[3].visible = 1; pRoof->pFacetArray[4].f3SidedPoly[0] = 0; pRoof->pFacetArray[4].f3SidedPoly[1] = 3; pRoof->pFacetArray[4].f3SidedPoly[2] = 1; pRoof->pFacetArray[4].visible = 1; pRoof->pFacetArray[5].f3SidedPoly[0] = 1; pRoof->pFacetArray[5].f3SidedPoly[1] = 3; pRoof->pFacetArray[5].f3SidedPoly[2] = 4; pRoof->pFacetArray[5].visible = 1; } pRoof->numVertices = 6; if ( (pRoof->pVertexArray = allocateVertexArray(pRoof->numVertices)) == NULL ) { return; /* improve */ } else { pRoof->pVertexArray[0].x = 0.5; pRoof->pVertexArray[0].y = 1; pRoof->pVertexArray[0].z = 1; pRoof->pVertexArray[1].x = 0; pRoof->pVertexArray[1].y = 0; pRoof->pVertexArray[1].z = 1; pRoof->pVertexArray[2].x = 1; pRoof->pVertexArray[2].y = 0; pRoof->pVertexArray[2].z = 1; pRoof->pVertexArray[3].x = 0.5; pRoof->pVertexArray[3].y = 1; pRoof->pVertexArray[3].z = 0; pRoof->pVertexArray[4].x = 0; pRoof->pVertexArray[4].y = 0; pRoof->pVertexArray[4].z = 0; pRoof->pVertexArray[5].x = 1; pRoof->pVertexArray[5].y = 0; pRoof->pVertexArray[5].z = 0; } pRoof->worldPosition.x = 10, pRoof->worldPosition.y = 100, pRoof->worldPosition.z = 0; pRoof->xScale = pRoof->zScale = 100; pRoof->yScale = 50; pRoof->rotXAngle = pRoof->rotYAngle = pRoof->rotZAngle = 0; pRoof->colour.red = 128, pRoof->colour.green = 0, pRoof->colour.blue = 0; pRoof->visible = 1; return; }
Partager