Subversion Repositories AndroidProjects

Rev

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