Subversion Repositories AndroidProjects

Rev

Rev 791 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
787 chris 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
 
7
using BauzoidNET.math;
8
 
9
namespace BauzoidNET.graphics.model
10
{
11
    public class GeometryUtil
12
    {
13
        static public SimpleGeometry createQuad(float minX, float minY, float maxX, float maxY,
14
            float minS, float minT, float maxS, float maxT, Vector4 color)
15
        {
16
            SimpleGeometry mesh = new SimpleGeometry(Geometry.PrimitiveType.TRIANGLES);
17
 
18
            AttributeArray vertices = new AttributeArray(SimpleGeometry.POSITION_COORD_PER_ELEMENT * 6);
19
            vertices.fill(minX, minY, 0.0f);
20
            vertices.fill(maxX, minY, 0.0f);
21
            vertices.fill(minX, maxY, 0.0f);
22
 
23
            vertices.fill(minX, maxY, 0.0f);
24
            vertices.fill(maxX, minY, 0.0f);
25
            vertices.fill(maxX, maxY, 0.0f);
26
 
27
            AttributeArray colors = new AttributeArray(SimpleGeometry.COLOR_COORD_PER_ELEMENT * 6);
28
            colors.fill(color.x, color.y, color.z, color.w);
29
            colors.fill(color.x, color.y, color.z, color.w);
30
            colors.fill(color.x, color.y, color.z, color.w);
31
            colors.fill(color.x, color.y, color.z, color.w);
32
            colors.fill(color.x, color.y, color.z, color.w);
33
            colors.fill(color.x, color.y, color.z, color.w);
34
 
35
            AttributeArray texCoords = new AttributeArray(SimpleGeometry.TEXCOORD_COORD_PER_ELEMENT * 6);
36
            texCoords.fill(minS, maxT);
37
            texCoords.fill(maxS, maxT);
38
            texCoords.fill(minS, minT);
39
 
40
            texCoords.fill(minS, minT);
41
            texCoords.fill(maxS, maxT);
42
            texCoords.fill(maxS, minT);
43
 
44
            mesh.setPositions(vertices.getAttributeArray());
45
            mesh.setColors(colors.getAttributeArray());
46
            mesh.setTexCoords(texCoords.getAttributeArray());
47
 
48
            return mesh;
49
        }
50
 
51
        public static SimpleGeometry createQuad(float minX, float minY, float maxX, float maxY,
52
                float minS, float minT, float maxS, float maxT)
53
        {
54
            return createQuad(minX, minY, maxX, maxY, minS, minT, maxS, maxT, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
55
        }
56
 
57
        public static SimpleGeometry createQuad(float minX, float minY, float maxX, float maxY, Vector4 color)
58
        {
59
            return createQuad(minX, minY, maxX, maxY, 0.0f, 0.0f, 1.0f, 1.0f, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
60
        }
61
 
62
        public static SimpleGeometry createQuad(float minX, float minY, float maxX, float maxY)
63
        {
64
            return createQuad(minX, minY, maxX, maxY, 0.0f, 0.0f, 1.0f, 1.0f);
65
        }
66
 
67
        static public SimpleGeometry createSubdividedQuad(float minX, float minY, float maxX, float maxY,
68
                float minS, float minT, float maxS, float maxT, Vector4 color, int subdivisionX, int subdivisionY)
69
            {
70
                    SimpleGeometry mesh = new SimpleGeometry(Geometry.PrimitiveType.TRIANGLES);
71
 
72
                    int numTiles = (subdivisionX + 1) * (subdivisionY + 1);
73
 
74
                    AttributeArray vertices = new AttributeArray(SimpleGeometry.POSITION_COORD_PER_ELEMENT * 6 * numTiles);
75
                    AttributeArray colors = new AttributeArray(SimpleGeometry.COLOR_COORD_PER_ELEMENT * 6 * numTiles);
76
                    AttributeArray texCoords = new AttributeArray(SimpleGeometry.TEXCOORD_COORD_PER_ELEMENT * 6 * numTiles);
77
 
78
                    float stepX = (maxX - minX) / (subdivisionX + 1);
79
                    float stepY = (maxY - minY) / (subdivisionY + 1);
80
 
81
                    float stepS = (maxS - minS) / (subdivisionX + 1);
82
                    float stepT = (maxT - minT) / (subdivisionY + 1);
83
 
84
                    float segmentX = minX;
85
                    float segmentY = minY;
86
 
87
                    float segmentS = minS;
88
                    float segmentT = maxT;
89
 
90
                    for (int y = 0; y < (subdivisionY + 1); y++)
91
                    {
92
                            for (int x = 0; x < (subdivisionX + 1); x++)
93
                            {
94
                                    float segmentMinX = segmentX;
95
                                    float segmentMaxX = segmentX + stepX;
96
                                    float segmentMinY = segmentY;
97
                                    float segmentMaxY = segmentY + stepY;
98
 
99
                                    float segmentMinS = segmentS;
100
                                    float segmentMaxS = (segmentS + stepS);
101
                                    float segmentMinT = (segmentT - stepT);
102
                                    float segmentMaxT = segmentT;
103
 
104
                                    vertices.fill(segmentMinX, segmentMinY, 0.0f);
105
                                    vertices.fill(segmentMaxX, segmentMinY, 0.0f);
106
                                    vertices.fill(segmentMinX, segmentMaxY, 0.0f);
107
 
108
                                    vertices.fill(segmentMinX, segmentMaxY, 0.0f);
109
                                    vertices.fill(segmentMaxX, segmentMinY, 0.0f);
110
                                    vertices.fill(segmentMaxX, segmentMaxY, 0.0f);
111
 
112
                                    colors.fill(color.x, color.y, color.z, color.w);
113
                                    colors.fill(color.x, color.y, color.z, color.w);
114
                                    colors.fill(color.x, color.y, color.z, color.w);
115
 
116
                                    colors.fill(color.x, color.y, color.z, color.w);
117
                                    colors.fill(color.x, color.y, color.z, color.w);
118
                                    colors.fill(color.x, color.y, color.z, color.w);
119
 
120
                                    texCoords.fill(segmentMinS, segmentMaxT);
121
                                    texCoords.fill(segmentMaxS, segmentMaxT);
122
                                    texCoords.fill(segmentMinS, segmentMinT);
123
 
124
                                    texCoords.fill(segmentMinS, segmentMinT);
125
                                    texCoords.fill(segmentMaxS, segmentMaxT);
126
                                    texCoords.fill(segmentMaxS, segmentMinT);
127
 
128
                                    segmentX += stepX;
129
                                    segmentS += stepS;
130
                            }
131
 
132
                            segmentX = minX;                   
133
                            segmentS = minS;
134
 
135
                            segmentY += stepY;
136
                            segmentT -= stepT;
137
                    }
138
 
139
    /*          AttributeArray vertices = new AttributeArray(SimpleGeometry.POSITION_COORD_PER_ELEMENT * 6);
140
                    vertices.fill(minX, minY, 0.0f);
141
                    vertices.fill(maxX, minY, 0.0f);
142
                    vertices.fill(minX, maxY, 0.0f);
143
 
144
                    vertices.fill(minX, maxY, 0.0f);
145
                    vertices.fill(maxX, minY, 0.0f);
146
                    vertices.fill(maxX, maxY, 0.0f);
147
 
148
                    AttributeArray colors = new AttributeArray(SimpleGeometry.COLOR_COORD_PER_ELEMENT * 6);
149
                    colors.fill(color.x, color.y, color.z, color.w);
150
                    colors.fill(color.x, color.y, color.z, color.w);
151
                    colors.fill(color.x, color.y, color.z, color.w);
152
                    colors.fill(color.x, color.y, color.z, color.w);
153
                    colors.fill(color.x, color.y, color.z, color.w);
154
                    colors.fill(color.x, color.y, color.z, color.w);
155
 
156
                    AttributeArray texCoords = new AttributeArray(SimpleGeometry.TEXCOORD_COORD_PER_ELEMENT * 6);
157
                    texCoords.fill(minS, maxT);
158
                    texCoords.fill(maxS, maxT);
159
                    texCoords.fill(minS, minT);
160
 
161
                    texCoords.fill(minS, minT);
162
                    texCoords.fill(maxS, maxT);
163
                    texCoords.fill(maxS, minT);*/
164
 
165
                    mesh.setPositions(vertices.getAttributeArray());
166
                    mesh.setColors(colors.getAttributeArray());
167
                    mesh.setTexCoords(texCoords.getAttributeArray());
168
 
169
                    return mesh;
170
            }
171
 
172
        public static SimpleGeometry createSubdividedQuad(float minX, float minY, float maxX, float maxY,
173
                float minS, float minT, float maxS, float maxT, int subdivisionX, int subdivisionY)
174
        {
175
            return createSubdividedQuad(minX, minY, maxX, maxY, minS, minT, maxS, maxT, new Vector4(1.0f, 1.0f, 1.0f, 1.0f),
176
                    subdivisionX, subdivisionY);
177
        }
178
 
179
        public static SimpleGeometry createSubdividedQuad(float minX, float minY, float maxX, float maxY,
180
                Vector4 color, int subdivisionX, int subdivisionY)
181
        {
182
            return createSubdividedQuad(minX, minY, maxX, maxY, 0.0f, 0.0f, 1.0f, 1.0f, new Vector4(1.0f, 1.0f, 1.0f, 1.0f),
183
                    subdivisionX, subdivisionY);
184
        }
185
 
186
        public static SimpleGeometry createSubdividedQuad(float minX, float minY, float maxX, float maxY,
187
                int subdivisionX, int subdivisionY)
188
        {
189
            return createSubdividedQuad(minX, minY, maxX, maxY, 0.0f, 0.0f, 1.0f, 1.0f, subdivisionX, subdivisionY);
190
        }
191
    }
192
}