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