add v2 gesture handlers
This commit is contained in:
@@ -6,6 +6,12 @@ class Geometry {
|
||||
final List<double> normals;
|
||||
|
||||
Geometry(this.vertices, this.indices, this.normals);
|
||||
|
||||
void scale(double factor) {
|
||||
for (int i = 0; i < vertices.length; i++) {
|
||||
vertices[i] = vertices[i] * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GeometryHelper {
|
||||
@@ -32,7 +38,11 @@ class GeometryHelper {
|
||||
double z = sinPhi * sinTheta;
|
||||
|
||||
vertices.addAll([x, y, z]);
|
||||
normals.addAll([x, y, z]); // For a sphere, normals are the same as vertex positions
|
||||
normals.addAll([
|
||||
x,
|
||||
y,
|
||||
z
|
||||
]); // For a sphere, normals are the same as vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +51,8 @@ class GeometryHelper {
|
||||
int first = (latNumber * (longitudeBands + 1)) + longNumber;
|
||||
int second = first + longitudeBands + 1;
|
||||
|
||||
indices.addAll([first, second, first + 1, second, second + 1, first + 1]);
|
||||
indices
|
||||
.addAll([first, second, first + 1, second, second + 1, first + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,4 +153,73 @@ class GeometryHelper {
|
||||
|
||||
return Geometry(vertices, indices, normals);
|
||||
}
|
||||
}
|
||||
|
||||
static Geometry cylinder({double radius = 1.0, double length = 1.0}) {
|
||||
int segments = 32;
|
||||
List<double> vertices = [];
|
||||
List<int> indices = [];
|
||||
|
||||
// Create vertices
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double theta = i * 2 * pi / segments;
|
||||
double x = radius * cos(theta);
|
||||
double z = radius * sin(theta);
|
||||
|
||||
// Top circle
|
||||
vertices.addAll([x, length / 2, z]);
|
||||
// Bottom circle
|
||||
vertices.addAll([x, -length / 2, z]);
|
||||
}
|
||||
|
||||
// Create indices
|
||||
for (int i = 0; i < segments; i++) {
|
||||
int topFirst = i * 2;
|
||||
int topSecond = (i + 1) * 2;
|
||||
int bottomFirst = topFirst + 1;
|
||||
int bottomSecond = topSecond + 1;
|
||||
|
||||
// Top face (counter-clockwise)
|
||||
indices.addAll([segments * 2, topSecond, topFirst]);
|
||||
// Bottom face (counter-clockwise when viewed from below)
|
||||
indices.addAll([segments * 2 + 1, bottomFirst, bottomSecond]);
|
||||
// Side faces (counter-clockwise)
|
||||
indices.addAll([topFirst, bottomFirst, topSecond]);
|
||||
indices.addAll([bottomFirst, bottomSecond, topSecond]);
|
||||
}
|
||||
|
||||
// Add center vertices for top and bottom faces
|
||||
vertices.addAll([0, length / 2, 0]); // Top center
|
||||
vertices.addAll([0, -length / 2, 0]); // Bottom center
|
||||
|
||||
return Geometry(vertices:vertices, indices:indices, normals:normals);
|
||||
}
|
||||
|
||||
static Geometry conic({double radius = 1.0, double length = 1.0}) {
|
||||
int segments = 32;
|
||||
List<double> vertices = [];
|
||||
List<int> indices = [];
|
||||
|
||||
// Create vertices
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double theta = i * 2 * pi / segments;
|
||||
double x = radius * cos(theta);
|
||||
double z = radius * sin(theta);
|
||||
|
||||
// Base circle
|
||||
vertices.addAll([x, 0, z]);
|
||||
}
|
||||
// Apex
|
||||
vertices.addAll([0, length, 0]);
|
||||
|
||||
// Create indices
|
||||
for (int i = 0; i < segments; i++) {
|
||||
// Base face
|
||||
indices.addAll([i, i + 1, segments + 1]);
|
||||
// Side faces
|
||||
indices.addAll([i, segments, i + 1]);
|
||||
}
|
||||
|
||||
return Geometry(vertices:vertices, indices:indices, normals:normals);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user