Skip to content

Commit

Permalink
removed all 'new'
Browse files Browse the repository at this point in the history
  • Loading branch information
escamoteur committed Mar 6, 2021
1 parent 762ae94 commit e3eb65d
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 153 deletions.
10 changes: 5 additions & 5 deletions web/cube.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Cube implements Renderable {
];
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(vertices),
Float32List.fromList(vertices),
WebGL.STATIC_DRAW,
);

Expand Down Expand Up @@ -104,7 +104,7 @@ class Cube implements Renderable {
];
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(vertexNormals),
Float32List.fromList(vertexNormals),
WebGL.STATIC_DRAW,
);

Expand Down Expand Up @@ -149,15 +149,15 @@ class Cube implements Renderable {
];
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(textureCoords),
Float32List.fromList(textureCoords),
WebGL.STATIC_DRAW,
);

indexBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(
WebGL.ELEMENT_ARRAY_BUFFER,
new Uint16List.fromList([
Uint16List.fromList([
0, 1, 2, 0, 2, 3, // Front face
4, 5, 6, 4, 6, 7, // Back face
8, 9, 10, 8, 10, 11, // Top face
Expand Down Expand Up @@ -225,7 +225,7 @@ class CubeColor {
}
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(unpackedColors),
Float32List.fromList(unpackedColors),
WebGL.STATIC_DRAW,
);
}
Expand Down
4 changes: 2 additions & 2 deletions web/gl_program.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ part of learn_gl;
/// Create a WebGL [Program], compiling [Shader]s from passed in sources and
/// cache [UniformLocation]s and AttribLocations.
class GlProgram {
Map<String, int> attributes = new Map<String, int>();
Map<String, UniformLocation> uniforms = new Map<String, UniformLocation>();
Map<String, int> attributes = Map<String, int>();
Map<String, UniformLocation> uniforms = Map<String, UniformLocation>();
late Program program;

late Shader fragShader, vertShader;
Expand Down
20 changes: 10 additions & 10 deletions web/json_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,49 @@ class JsonObject implements Renderable {

List<dynamic>? numArray = data['vertexNormals'];
if (numArray != null) {
List<double> normals = new List<double>.from(numArray.map((index) => index.toDouble()));
List<double> normals = List<double>.from(numArray.map((index) => index.toDouble()));

vertexNormalBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ARRAY_BUFFER, vertexNormalBuffer);
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(normals),
Float32List.fromList(normals),
WebGL.STATIC_DRAW,
);
}

numArray = data['vertexTextureCoords'];
if (numArray != null) {
List<double> coords = new List<double>.from(numArray.map((index) => index.toDouble()));
List<double> coords = List<double>.from(numArray.map((index) => index.toDouble()));

textureCoordBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ARRAY_BUFFER, textureCoordBuffer);
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(coords),
Float32List.fromList(coords),
WebGL.STATIC_DRAW,
);
}

numArray = data['vertexPositions'];
List<double> positions = new List<double>.from(numArray!.map((index) => index.toDouble()));
List<double> positions = List<double>.from(numArray!.map((index) => index.toDouble()));

vertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ARRAY_BUFFER, vertexPositionBuffer);
gl.bufferData(
WebGL.ARRAY_BUFFER,
new Float32List.fromList(positions),
Float32List.fromList(positions),
WebGL.STATIC_DRAW,
);

numArray = data['indices'];
if (numArray != null) {
List<int> indices = new List<int>.from(numArray.map((index) => index.toInt()));
List<int> indices = List<int>.from(numArray.map((index) => index.toInt()));
indexBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(
WebGL.ELEMENT_ARRAY_BUFFER,
new Uint16List.fromList(indices),
Uint16List.fromList(indices),
WebGL.STATIC_DRAW,
);
_itemSize = indices.length;
Expand All @@ -87,9 +87,9 @@ class JsonObject implements Renderable {

/// Return a future [JsonObject] by fetching the JSON data from [url].
static Future<JsonObject> fromUrl(String url) {
Completer<JsonObject> complete = new Completer<JsonObject>();
Completer<JsonObject> complete = Completer<JsonObject>();
HttpRequest.getString(url).then((json) {
JsonObject obj = new JsonObject(json);
JsonObject obj = JsonObject(json);
print("json object from $url loaded as $obj");
complete.complete(obj);
});
Expand Down
48 changes: 24 additions & 24 deletions web/learn_gl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ late RenderingContext2 gl;
late Lesson lesson;

void main() {
mvMatrix = new Matrix4()..identity();
mvMatrix = Matrix4()..identity();
// Nab the context we'll be drawing to.
// gl = canvas.getContext3d();
gl = canvas.getContext("webgl2") as RenderingContext2;
Expand Down Expand Up @@ -88,7 +88,7 @@ void main() {

SelectElement lessonSelect = querySelector("#lessonNumber") as SelectElement;
for (int i = 1; i < 17; i++) {
lessonSelect.children.add(new OptionElement(data: "Lesson $i", value: "$i", selected: defaultLesson == i));
lessonSelect.children.add(OptionElement(data: "Lesson $i", value: "$i", selected: defaultLesson == i));
}
lessonSelect.onChange.listen((event) {
lesson = selectLesson(lessonSelect.selectedIndex! + 1)!..initHtml(lessonHook);
Expand All @@ -112,7 +112,7 @@ void main() {
}

/// This is the infinite animation loop; we request that the web browser
/// call us back every time its ready for a new frame to be rendered. The [time]
/// call us back every time its ready for a frame to be rendered. The [time]
/// parameter is an increasing value based on when the animation loop started.
tick(time) {
window.animationFrame.then(tick);
Expand All @@ -123,7 +123,7 @@ tick(time) {
}

/// The global key-state map.
Set<int> currentlyPressedKeys = new Set<int>();
Set<int> currentlyPressedKeys = Set<int>();

/// Test if the given [KeyCode] is active.
bool isActive(int code) => currentlyPressedKeys.contains(code);
Expand Down Expand Up @@ -162,7 +162,7 @@ List<Matrix4> mvStack = <Matrix4>[];

/// Add a copy of the current Model-View matrix to the the stack for future
/// restoration.
mvPushMatrix() => mvStack.add(new Matrix4.fromMatrix(mvMatrix));
mvPushMatrix() => mvStack.add(Matrix4.fromMatrix(mvMatrix));

/// Pop the last matrix off the stack and set the Model View matrix.
mvPopMatrix() => mvMatrix = mvStack.removeLast();
Expand Down Expand Up @@ -229,9 +229,9 @@ abstract class Lesson {
/// Load the given image at [url] and call [handle] to execute some GL code.
/// Return a [Future] to asynchronously notify when the texture is complete.
Future<Texture> loadTexture(String url, handle(Texture tex, ImageElement ele)) {
var completer = new Completer<Texture>();
var completer = Completer<Texture>();
var texture = gl.createTexture();
var element = new ImageElement();
var element = ImageElement();
element.onLoad.listen((e) {
handle(texture, element);
completer.complete(texture);
Expand Down Expand Up @@ -273,37 +273,37 @@ bool trackFrameRate = false;
Lesson? selectLesson(int number) {
switch (number) {
case 1:
return new Lesson1();
return Lesson1();
case 2:
return new Lesson2();
return Lesson2();
case 3:
return new Lesson3();
return Lesson3();
case 4:
return new Lesson4();
return Lesson4();
case 5:
return new Lesson5();
return Lesson5();
case 6:
return new Lesson6();
return Lesson6();
case 7:
return new Lesson7();
return Lesson7();
case 8:
return new Lesson8();
return Lesson8();
case 9:
return new Lesson9();
return Lesson9();
case 10:
return new Lesson10();
return Lesson10();
case 11:
return new Lesson11();
return Lesson11();
case 12:
return new Lesson12();
return Lesson12();
case 13:
return new Lesson13();
return Lesson13();
case 14:
return new Lesson14();
return Lesson14();
case 15:
return new Lesson15();
return Lesson15();
case 16:
return new Lesson16();
return Lesson16();
}
return null;
}
Expand All @@ -313,7 +313,7 @@ class NullTreeSanitizer implements NodeTreeSanitizer {
static NullTreeSanitizer? instance;
factory NullTreeSanitizer() {
if (instance == null) {
instance = new NullTreeSanitizer._();
instance = NullTreeSanitizer._();
}
return instance!;
}
Expand Down
8 changes: 4 additions & 4 deletions web/lesson1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Lesson1 extends Lesson {
late Buffer triangleVertexPositionBuffer, squareVertexPositionBuffer;

Lesson1() {
program = new GlProgram(
program = GlProgram(
'''
precision mediump float;
Expand Down Expand Up @@ -50,13 +50,13 @@ class Lesson1 extends Lesson {

// bindBuffer() tells the WebGL system the target of future calls
gl.bindBuffer(WebGL.ARRAY_BUFFER, triangleVertexPositionBuffer);
gl.bufferData(WebGL.ARRAY_BUFFER, new Float32List.fromList([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0]),
WebGL.STATIC_DRAW);
gl.bufferData(
WebGL.ARRAY_BUFFER, Float32List.fromList([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0]), WebGL.STATIC_DRAW);

squareVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(WebGL.ARRAY_BUFFER, squareVertexPositionBuffer);
gl.bufferData(WebGL.ARRAY_BUFFER,
new Float32List.fromList([1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, -1.0, -1.0, 0.0]), WebGL.STATIC_DRAW);
Float32List.fromList([1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, -1.0, -1.0, 0.0]), WebGL.STATIC_DRAW);

// Specify the color to clear with (black with 100% alpha) and then enable
// depth testing.
Expand Down
4 changes: 2 additions & 2 deletions web/lesson10.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Lesson10 extends Lesson {

var attributes = ['aVertexPosition', 'aTextureCoord'];
var uniforms = ['uMVMatrix', 'uPMatrix', 'uSampler'];
program = new GlProgram(
program = GlProgram(
"""
precision mediump float;
Expand Down Expand Up @@ -180,7 +180,7 @@ class Lesson10 extends Lesson {
Use the cursor keys or WASD to run around, and <code>Page Up</code>/<code>Page Down</code> to
look up and down.
""",
treeSanitizer: new NullTreeSanitizer(),
treeSanitizer: NullTreeSanitizer(),
);
}
}
12 changes: 6 additions & 6 deletions web/lesson11.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Lesson11 extends Lesson {
late Sphere moon;
Texture? moonTexture;

Matrix4 _rotation = new Matrix4()..identity();
Matrix4 _rotation = Matrix4()..identity();
bool _mouseDown = false;
var _lastMouseX, _lastMouseY;

bool get isLoaded => moonTexture != null;

Lesson11() {
moon = new Sphere(lats: 30, lons: 30, radius: 2);
moon = Sphere(lats: 30, lons: 30, radius: 2);

var attributes = ['aVertexPosition', 'aVertexNormal', 'aTextureCoord'];
var uniforms = [
Expand All @@ -40,7 +40,7 @@ class Lesson11 extends Lesson {
'uDirectionalColor',
'uUseLighting'
];
program = new GlProgram(
program = GlProgram(
'''
precision mediump float;
Expand Down Expand Up @@ -110,7 +110,7 @@ class Lesson11 extends Lesson {
var newX = event.client.x;
var newY = event.client.y;
var deltaX = newX - _lastMouseX;
Matrix4 newRot = new Matrix4()
Matrix4 newRot = Matrix4()
..identity()
..rotateY(radians(deltaX / 10));
var deltaY = newY - _lastMouseY;
Expand Down Expand Up @@ -151,7 +151,7 @@ class Lesson11 extends Lesson {
gl.uniform3f(uAmbientColor, double.parse(_aR.value!), double.parse(_aG.value!), double.parse(_aB.value!));

// Take the lighting point and normalize / reverse it.
Vector3 direction = new Vector3(double.parse(_ldX.value!), double.parse(_ldY.value!), double.parse(_ldZ.value!));
Vector3 direction = Vector3(double.parse(_ldX.value!), double.parse(_ldY.value!), double.parse(_ldZ.value!));
direction = direction.normalize().scale(-1.0);
gl.uniform3fv(uLightingDirection, direction.buf);

Expand Down Expand Up @@ -233,7 +233,7 @@ class Lesson11 extends Lesson {
Moon texture courtesy of <a href="http://maps.jpl.nasa.gov/">the Jet Propulsion Laboratory</a>.
""",
treeSanitizer: new NullTreeSanitizer(),
treeSanitizer: NullTreeSanitizer(),
);

// Re-look up our dom elements
Expand Down
8 changes: 4 additions & 4 deletions web/lesson12.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Lesson12 extends Lesson {
bool get isLoaded => moonTexture != null && cubeTexture != null;

Lesson12() {
moon = new Sphere(lats: 30, lons: 30, radius: 2);
cube = new Cube();
moon = Sphere(lats: 30, lons: 30, radius: 2);
cube = Cube();

var attributes = ['aVertexPosition', 'aVertexNormal', 'aTextureCoord'];
var uniforms = [
Expand All @@ -43,7 +43,7 @@ class Lesson12 extends Lesson {
'uPointLightingColor',
'uUseLighting'
];
program = new GlProgram(
program = GlProgram(
'''
precision mediump float;
Expand Down Expand Up @@ -249,7 +249,7 @@ class Lesson12 extends Lesson {
Moon texture courtesy of <a href="http://maps.jpl.nasa.gov/">the Jet Propulsion Laboratory</a>.
""",
treeSanitizer: new NullTreeSanitizer(),
treeSanitizer: NullTreeSanitizer(),
);

// Re-look up our dom elements
Expand Down
Loading

0 comments on commit e3eb65d

Please sign in to comment.