Permalink
Browse files

adding webgl with css

  • Loading branch information...
adam adam
adam authored and adam committed Jun 3, 2012
1 parent 053799a commit b11559bce77f10afdd074815b17f9b8e2a79545b
View
@@ -0,0 +1 @@
+teapot.dart
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>teapot</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.google.dart.tools.core.dartBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.google.dart.tools.core.dartNature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,56 @@
+class CameraController {
+
+ Function onchange = null;
+ num xRot = 0;
+ num yRot = 0;
+ num scaleFactor = 3.0;
+ bool dragging = false;
+ num curX = 0;
+ num curY = 0;
+ Element element;
+
+ CameraController(this.element) {
+ element.on.mouseDown.add(_onmousedown);
+ element.on.mouseUp.add(_onmouseup);
+ element.on.mouseMove.add(_onmousemove);
+ }
+
+ _onmousedown(MouseEvent event) {
+ curX = event.clientX;
+ curY = event.clientY;
+ dragging = true;
+
+ }
+
+ _onmouseup(MouseEvent event) {
+ dragging = false;
+
+ }
+
+ _onmousemove(MouseEvent event) {
+ if (dragging) {
+ // Determine how far we have moved since the last mouse move
+ // event.
+ var _curX = event.clientX;
+ var _curY = event.clientY;
+ var deltaX = (curX - _curX) / scaleFactor;
+ var deltaY = (curY - _curY) / scaleFactor;
+ curX = _curX;
+ curY = _curY;
+ // Update the X and Y rotation angles based on the mouse motion.
+ yRot = (yRot + deltaX) % 360;
+ xRot = (xRot + deltaY);
+ // Clamp the X rotation to prevent the camera from going upside
+ // down.
+ if (xRot < -90) {
+ xRot = -90;
+ } else if (xRot > 90) {
+ xRot = 90;
+ }
+ // Send the onchange event to any listener.
+ if (onchange != null) {
+ onchange();
+ }
+ }
+ }
+}
View
Binary file not shown.
@@ -0,0 +1,65 @@
+class Matrix3 {
+
+ Float32Array _dest;
+
+ Matrix3() {
+ _dest = new Float32Array(9);
+ }
+
+ Matrix3.fromList(List<num> list) {
+ if (list.length != 9) {
+ throw new Exception("Matrix4.fromList requires list of exactly 9 items (${list.length} given)");
+ }
+ _dest = new Float32Array.fromList(list);
+ }
+
+ Matrix3.fromFloat32Array(Float32Array list) {
+ if (list.length != 9) {
+ throw new Exception("Matrix4.fromList requires Float32Array of exactly 9 items (${list.length} given)");
+ }
+ _dest = list;
+ }
+
+ operator [](int index) => _dest[index];
+
+ operator []=(int index, double value) => _dest[index] = value;
+
+ Float32Array get array() => _dest;
+ set array(Float32Array array) => _dest = array;
+
+ /**
+ * Transposes a mat3 (flips the values over the diagonal)
+ *
+ * @param {mat3} mat mat3 to transpose
+ * @param {mat3} [dest] mat3 receiving transposed values. If not specified result is written to mat
+ *
+ * @param {mat3} dest is specified, mat otherwise
+ */
+ void transpose([Matrix3 dest]) {
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
+ if (dest == null) {
+ var a01 = _dest[1], a02 = _dest[2],
+ a12 = _dest[5];
+
+ _dest[1] = _dest[3];
+ _dest[2] = _dest[6];
+ _dest[3] = a01;
+ _dest[5] = _dest[7];
+ _dest[6] = a02;
+ _dest[7] = a12;
+
+ } else {
+
+ dest[0] = _dest[0];
+ dest[1] = _dest[3];
+ dest[2] = _dest[6];
+ dest[3] = _dest[1];
+ dest[4] = _dest[4];
+ dest[5] = _dest[7];
+ dest[6] = _dest[2];
+ dest[7] = _dest[5];
+ dest[8] = _dest[8];
+
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit b11559b

Please sign in to comment.