[11] 楔形体(Wedge)图形的生成算法


顶点数据的生成

 

 1 bool                        YfBuildWedgeVertices
 2 (
 3     Yreal                   width, 
 4     Yreal                   length, 
 5     Yreal                   height, 
 6     YeOriginPose            originPose,  
 7     Yuint                   vertexStriding, 
 8     Yuint                   vertexPos,
 9     void*                   pVerticesBuffer
10 )
11 {
12     if (!pVerticesBuffer)
13     {
14         return false;
15     }
16 
17     Yuint numVertices  = 6;
18 
19     // 顶点赋值
20     char* vertexPtr = (char*)pVerticesBuffer + vertexPos;
21     YsVector3* curVertexPtr   = NULL;
22     Yuint nOffset = 0;
23 
24     YsVector3 vOriginOffset(-width / 2, -height / 2, -length / 2);
25     if (originPose == YE_ORIGIN_POSE_TOP)
26     {
27         vOriginOffset.y = -height;
28     }
29     else if (originPose == YE_ORIGIN_POSE_BOTTOM)
30     {
31         vOriginOffset.y = 0.0f;
32     }
33 
34     // 底四个顶点
35     for (Yuint j = 0; j < 2; j++)
36     {
37         for (Yuint i = 0; i < 2; i++)
38         {
39             nOffset = (j*2 + i) * vertexStriding;
40             curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
41             curVertexPtr->x = width*i + vOriginOffset.x;
42             curVertexPtr->y = vOriginOffset.y;
43             curVertexPtr->z = length*j + vOriginOffset.z;
44         }
45     }
46 
47     // 上顶点
48     nOffset = 4 * vertexStriding;
49     if (vertexPtr)
50     {
51         curVertexPtr = (YsVector3*)(vertexPtr + nOffset);
52         curVertexPtr->x = vOriginOffset.x + width / 2;
53         curVertexPtr->y = height + vOriginOffset.y;
54         curVertexPtr->z = vOriginOffset.z;
55 
56         curVertexPtr = (YsVector3*)(vertexPtr + nOffset + vertexStriding);
57         curVertexPtr->x = vOriginOffset.x + width / 2;
58         curVertexPtr->y = height + vOriginOffset.y;
59         curVertexPtr->z = length + vOriginOffset.z;
60     }
61 
62     return true;
63 }     

 

三角形索引数据的生成

 

 1 bool                        YfBuildWedgeTriIndices
 2 (
 3     YeIndexType             indexType,
 4     Yuint                   indexStriding,  
 5     Yuint                   indexPos,
 6     void*                   pTriIndicesBuffer
 7 )
 8 {
 9     if (!pTriIndicesBuffer)
10     {
11         return false;
12     }
13 
14     char* indexPtr = (char*)pTriIndicesBuffer + indexPos;
15     if (indexType == YE_INDEX_16_BIT)
16     {
17         YsTriIndex16* triIndexPtr = NULL;
18 
19         // bottom
20         triIndexPtr = (YsTriIndex16*)(indexPtr + 0*indexStriding);
21         triIndexPtr->index0 = 0; triIndexPtr->index1 = 1; triIndexPtr->index2 = 3;
22         triIndexPtr = (YsTriIndex16*)(indexPtr + 1*indexStriding);
23         triIndexPtr->index0 = 0; triIndexPtr->index1 = 3; triIndexPtr->index2 = 2;
24 
25         // 4 face
26         triIndexPtr = (YsTriIndex16*)(indexPtr + 2*indexStriding);
27         triIndexPtr->index0 = 0; triIndexPtr->index1 = 2; triIndexPtr->index2 = 5;
28         triIndexPtr = (YsTriIndex16*)(indexPtr + 3*indexStriding);
29         triIndexPtr->index0 = 0; triIndexPtr->index1 = 5; triIndexPtr->index2 = 4;
30         triIndexPtr = (YsTriIndex16*)(indexPtr + 4*indexStriding);
31         triIndexPtr->index0 = 4; triIndexPtr->index1 = 5; triIndexPtr->index2 = 3;
32         triIndexPtr = (YsTriIndex16*)(indexPtr + 5*indexStriding);                                                
33         triIndexPtr->index0 = 4; triIndexPtr->index1 = 3; triIndexPtr->index2 = 1;
34 
35         // 2 face
36         triIndexPtr = (YsTriIndex16*)(indexPtr + 6*indexStriding);
37         triIndexPtr->index0 = 0; triIndexPtr->index1 = 4; triIndexPtr->index2 = 1;
38         triIndexPtr = (YsTriIndex16*)(indexPtr + 7*indexStriding);
39         triIndexPtr->index0 = 2; triIndexPtr->index1 = 3; triIndexPtr->index2 = 5;
40     }
41     else
42     {
43         YsTriIndex32* triIndexPtr = NULL;
44 
45         // bottom
46         triIndexPtr = (YsTriIndex32*)(indexPtr + 0*indexStriding);
47         triIndexPtr->index0 = 0; triIndexPtr->index1 = 1; triIndexPtr->index2 = 3;
48         triIndexPtr = (YsTriIndex32*)(indexPtr + 1*indexStriding);
49         triIndexPtr->index0 = 0; triIndexPtr->index1 = 3; triIndexPtr->index2 = 2;
50 
51         // 4 face
52         triIndexPtr = (YsTriIndex32*)(indexPtr + 2*indexStriding);
53         triIndexPtr->index0 = 0; triIndexPtr->index1 = 2; triIndexPtr->index2 = 5;
54         triIndexPtr = (YsTriIndex32*)(indexPtr + 3*indexStriding);
55         triIndexPtr->index0 = 0; triIndexPtr->index1 = 5; triIndexPtr->index2 = 4;
56         triIndexPtr = (YsTriIndex32*)(indexPtr + 4*indexStriding);
57         triIndexPtr->index0 = 4; triIndexPtr->index1 = 5; triIndexPtr->index2 = 3;
58         triIndexPtr = (YsTriIndex32*)(indexPtr + 5*indexStriding);                                                
59         triIndexPtr->index0 = 4; triIndexPtr->index1 = 3; triIndexPtr->index2 = 1;
60 
61         // 2 face
62         triIndexPtr = (YsTriIndex32*)(indexPtr + 6*indexStriding);
63         triIndexPtr->index0 = 0; triIndexPtr->index1 = 4; triIndexPtr->index2 = 1;
64         triIndexPtr = (YsTriIndex32*)(indexPtr + 7*indexStriding);
65         triIndexPtr->index0 = 2; triIndexPtr->index1 = 3; triIndexPtr->index2 = 5;
66     }
67 
68     return true;
69 }   

 

线框索引数据的生成

  1 bool                        YfBuildWedgeWireIndices
  2 (
  3     YeIndexType             indexType,
  4     Yuint                   indexStriding,  
  5     Yuint                   indexPos,
  6     void*                   pWireIndicesBuffer
  7 )
  8 {
  9     if (!pWireIndicesBuffer)
 10     {
 11         return false;
 12     }
 13 
 14     Yuint numVertices = 6;
 15     Yuint numLines    = 9;
 16 
 17     // 索引赋值
 18     char* indexPtr = (char*)pWireIndicesBuffer + indexPos;
 19     Yuint nOffset = 0;
 20     if (indexType == YE_INDEX_16_BIT)
 21     {
 22         YsLineIndex16* lineIndexPtr = NULL;
 23 
 24         nOffset = 0 * indexStriding;
 25         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 26         lineIndexPtr->index0 = 0;
 27         lineIndexPtr->index1 = 1;
 28 
 29         nOffset = 1 * indexStriding;
 30         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 31         lineIndexPtr->index0 = 0;
 32         lineIndexPtr->index1 = 4;
 33 
 34         nOffset = 2 * indexStriding;
 35         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 36         lineIndexPtr->index0 = 4;
 37         lineIndexPtr->index1 = 1;
 38 
 39         nOffset = 3 * indexStriding;
 40         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 41         lineIndexPtr->index0 = 2;
 42         lineIndexPtr->index1 = 3;
 43 
 44         nOffset = 4 * indexStriding;
 45         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 46         lineIndexPtr->index0 = 2;
 47         lineIndexPtr->index1 = 5;
 48 
 49         nOffset = 5 * indexStriding;
 50         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 51         lineIndexPtr->index0 = 5;
 52         lineIndexPtr->index1 = 3;
 53 
 54         nOffset = 6 * indexStriding;
 55         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 56         lineIndexPtr->index0 = 0;
 57         lineIndexPtr->index1 = 2;
 58 
 59         nOffset = 7 * indexStriding;
 60         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 61         lineIndexPtr->index0 = 4;
 62         lineIndexPtr->index1 = 5;
 63 
 64         nOffset = 8 * indexStriding;
 65         lineIndexPtr = (YsLineIndex16*)(indexPtr + nOffset);
 66         lineIndexPtr->index0 = 1;
 67         lineIndexPtr->index1 = 3;
 68     }
 69     else
 70     {
 71         YsLineIndex32* lineIndexPtr = NULL;
 72 
 73         nOffset = 0 * indexStriding;
 74         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
 75         lineIndexPtr->index0 = 0;
 76         lineIndexPtr->index1 = 1;
 77 
 78         nOffset = 1 * indexStriding;
 79         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
 80         lineIndexPtr->index0 = 0;
 81         lineIndexPtr->index1 = 4;
 82 
 83         nOffset = 2 * indexStriding;
 84         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
 85         lineIndexPtr->index0 = 4;
 86         lineIndexPtr->index1 = 1;
 87 
 88         nOffset = 3 * indexStriding;
 89         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
 90         lineIndexPtr->index0 = 2;
 91         lineIndexPtr->index1 = 3;
 92 
 93         nOffset = 4 * indexStriding;
 94         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
 95         lineIndexPtr->index0 = 2;
 96         lineIndexPtr->index1 = 5;
 97 
 98         nOffset = 5 * indexStriding;
 99         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
100         lineIndexPtr->index0 = 5;
101         lineIndexPtr->index1 = 3;
102 
103         nOffset = 6 * indexStriding;
104         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
105         lineIndexPtr->index0 = 0;
106         lineIndexPtr->index1 = 2;
107 
108         nOffset = 7 * indexStriding;
109         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
110         lineIndexPtr->index0 = 4;
111         lineIndexPtr->index1 = 5;
112 
113         nOffset = 8 * indexStriding;
114         lineIndexPtr = (YsLineIndex32*)(indexPtr + nOffset);
115         lineIndexPtr->index0 = 1;
116         lineIndexPtr->index1 = 3;
117     }
118 
119     return true;
120 }

 


 

posted on 2013-11-09 08:43  叶飞影  阅读(1414)  评论(0编辑  收藏  举报