[multidim~master:198] Add Plain Camera

  • From: raindrop@kenai.com
  • To: commits@multidim.kenai.com
  • Subject: [multidim~master:198] Add Plain Camera
  • Date: Fri, 2 Jul 2010 12:46:20 +0000

Project:    multidim
Repository: master
Revision:   198
Author:     raindrop
Date:       2010-07-02 12:46:17 UTC
Link:       

Log Message:
------------
Add Plain Camera


Revisions:
----------
198


Modified Paths:
---------------
MultiDim/src/mathematics/multidimensional/shape2/MDPerspectiveCamera.fx
MultiDim/src/mathematics/multidimensional/shape2/MDCamera.fx


Added Paths:
------------
MultiDim/src/test/multidimensional/shape/camera/MDUniverseCamerasTest.fx
MultiDim/src/test/multidimensional/shape/camera
MultiDim/src/mathematics/multidimensional/shape2/MDPlainCamera.fx


Diffs:
------
Index: MultiDim/src/mathematics/multidimensional/shape2/MDPerspectiveCamera.fx
===================================================================
--- MultiDim/src/mathematics/multidimensional/shape2/MDPerspectiveCamera.fx   
  (revision 197)
+++ MultiDim/src/mathematics/multidimensional/shape2/MDPerspectiveCamera.fx   
  (revision 198)
@@ -4,16 +4,8 @@
  */
 package mathematics.multidimensional.shape2;
 
-import javafx.util.*;
-import javafx.scene.input.*;
 
 import mathematics.multidimensional.*;
-import mathematics.multidimensional.dim2.*;
-import java.lang.UnsupportedOperationException;
-import mathematics.multidimensional.shape2.MDCamera.CameraPoint2;
-import mathematics.multidimensional.shape2.MDCarcassNode;
-import mathematics.multidimensional.shape2.MDCamera.CameraSegment2;
-import mathematics.multidimensional.shape2.MDCarcassSegment;
 
 /**
  * @author andromeda
@@ -21,17 +13,12 @@
 public class MDPerspectiveCamera extends MDCamera {
 
 
-
-
     public var center: IMDVector = MDVector { dim: 3 elems: [0, 0, 500] };
     public var direction: IMDVector = MDVector { dim: 3 elems: [0, 0, -50] };
 
     
     var basis1: MDVector = MDVector { dim: 3 elems: [1, 0, 0] };
     var basis2: MDVector = MDVector { dim: 3 elems: [0, 1, 0] };
-    var rotateAngle: Number = 0.0;
-    var deltaAngle: Number = 5 * Math.PI / 180;
-    var deltaZoom: Number = 1.2;
 
     var cdd:Number;
 
@@ -42,11 +29,13 @@
         super.recalculate();
     }
 
-    function zoom(z: Number) {
+    override function zoom(z: Number) {
         //direction.length()}, {direction}");
         //println("[camera] zoom changed: {changed}");
         if (not changed) {
+            
             def d = direction.mul(z);
+
             if (5 < d.length()) {
                 direction = d;
             }
@@ -54,55 +43,10 @@
         }
     }
 
-    function rotate(delta: Number) {
-        if (not changed) {
-            rotateAngle += delta;
-            changed = true;
-        }
-    }
     
 
-    override function keys(e: KeyEvent): Void {
-        //println("key pressed: {e.char}");
-        //println("key pressed: {e.code}");
-        //        var delta = deltaAngle;
 
-        if (e.code == KeyCode.VK_RIGHT) {
-            rotate(deltaAngle);
-        }
 
-        if (e.code == KeyCode.VK_LEFT) {
-            rotate(-deltaAngle);
-        }
-
-        if (e.code == KeyCode.VK_EQUALS) {
-            zoom(deltaZoom)
-        }
-        if (e.code == KeyCode.VK_MINUS) {
-            zoom(1.0 / deltaZoom)
-        }
-
-    }
-
-//    function handleCarcass(carcass: MDCarcassShape): Void {
-//
-//        for (node in carcass.nodes) {
-//            //insert CameraPoint { carcass: node camera: this } into 
points;
-//            insert createPoint(node) into points;
-//        }
-//
-//        for (segment in carcass.segments) {
-//            //insert CameraSegment { carcass: segment camera: this} into 
segments;
-//            insert createSegment(segment) into segments;
-//        }
-//
-//        for (child in carcass.childs) {
-//            handleCarcass(child);
-//        }
-//
-//    }
-
-
     override public function createPoint (carcass : MDCarcassNode) : 
CameraPoint2 {
         CameraPoint { carcass: carcass camera: this }
     }
@@ -134,10 +78,7 @@
         def xx = basis1.innerProduct(r);
         def yy = basis2.innerProduct(r);
 
-        P {
-            x: VectorDim2.rotateX(xx, yy, rotateAngle)
-            y: VectorDim2.rotateY(xx, yy, rotateAngle)
-        }
+        return rotate(xx, yy, rotateAngle);
 
     }
 
@@ -146,12 +87,6 @@
 class CameraPoint extends CameraPoint2{
       var camera: MDPerspectiveCamera;
 
-//    override function reset() {
-//        node = Duplicator.duplicate(carcass.node.node);
-//    }
-
-
-
     override function recalculate(): Void {
         def p = camera.recalculate(carcass.rootPoint, camera.cdd);
         x = p.x;
@@ -178,10 +113,6 @@
         weight = carcass.segment.weight;
     }
 
-    override function toString() {
-        "segment: ({x1}, {y1} - {x2}, {y2})"
-    }
-
 }
 
 
Index: MultiDim/src/mathematics/multidimensional/shape2/MDCamera.fx
===================================================================
--- MultiDim/src/mathematics/multidimensional/shape2/MDCamera.fx        
(revision 197)
+++ MultiDim/src/mathematics/multidimensional/shape2/MDCamera.fx        
(revision 198)
@@ -4,16 +4,20 @@
  */
 package mathematics.multidimensional.shape2;
 
+import javafx.fxd.*;
 import javafx.scene.*;
+import javafx.scene.shape.*;
 import javafx.scene.paint.*;
 import javafx.scene.input.*;
+
+import javafx.util.Math;
 import mathematics.multidimensional.*;
-import javafx.scene.shape.Line;
-import javafx.fxd.Duplicator;
+import mathematics.multidimensional.dim2.VectorDim2;
 
 /**
  * @author andromeda
  */

 public abstract class MDCamera extends CustomNode {
 
     public var width: Number = 300;
@@ -25,6 +29,13 @@
     public var segments: CameraSegment2[];
     package var changed: Boolean;
 
+    public var rotateAngle: Number = 0.0;
+    public var deltaAngle: Number = 5 * Math.PI / 180;
+    
+    public var z:Number = 1.0;
+    public var deltaZoom: Number = 1.2;
+
+
     public function run() {
         if (changed) {
             recalculate();
@@ -57,8 +68,44 @@
         changed = false;
     }
 
-    public function keys(e: KeyEvent) { }
+    public function keys(e: KeyEvent): Void {
+        //println("key pressed: {e.char}");
+        //println("key pressed: {e.code}");
+        //        var delta = deltaAngle;
 
+        if (e.code == KeyCode.VK_RIGHT) {
+            rotate(deltaAngle);
+        }
+
+        if (e.code == KeyCode.VK_LEFT) {
+            rotate(-deltaAngle);
+        }
+
+        if (e.code == KeyCode.VK_EQUALS) {
+            zoom(deltaZoom)
+        }
+        if (e.code == KeyCode.VK_MINUS) {
+            zoom(1.0 / deltaZoom)
+        }
+
+    }
+
+    public function rotate(delta: Number) {
+        if (not changed) {
+            rotateAngle += delta;
+            changed = true;
+        }
+    }
+
+    function zoom(delta: Number) {
+        if (not changed) {
+            z *= delta;
+            changed = true;
+        }
+        
+    }
+
+
     public abstract function createPoint(carcass: MDCarcassNode): 
CameraPoint2;
 
     public abstract function createSegment(carcass: MDCarcassSegment): 
CameraSegment2;
@@ -106,6 +153,19 @@
 
 }
 
+
+public function rotate(vector:IMDVector, rotateAngle:Number): P {
+    rotate(vector.getElem(0), vector.getElem(1), rotateAngle)
+}
+
+public function rotate(xx:Number, yy:Number, rotateAngle:Number): P {
+        P {
+            x: VectorDim2.rotateX(xx, yy, rotateAngle)
+            y: VectorDim2.rotateY(xx, yy, rotateAngle)
+        }
+
+}
+
 public class P {
 
     public var x: Number;
@@ -141,4 +201,8 @@
 
     public function recalculate() { }
 
+    override function toString() {
+        "segment: ({x1}, {y1} - {x2}, {y2})"
+    }
+
 }
Index: MultiDim/src/mathematics/multidimensional/shape2/MDPlainCamera.fx
===================================================================
--- MultiDim/src/mathematics/multidimensional/shape2/MDPlainCamera.fx   
(revision 0)
+++ MultiDim/src/mathematics/multidimensional/shape2/MDPlainCamera.fx   
(revision 198)
@@ -0,0 +1,62 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package mathematics.multidimensional.shape2;
+
+
+/**
+ * @author andromeda
+ */
+
+
+public class MDPlainCamera extends MDCamera{
+
+
+    override public function createSegment (carcass : MDCarcassSegment) : 
CameraSegment2 {
+        CameraSegment{  carcass: carcass }
+    }
+
+    override public function createPoint (carcass : MDCarcassNode) : 
CameraPoint2 {
+        CameraPoint{ carcass:carcass }
+    }
+
+}
+
+class CameraPoint extends CameraPoint2{
+
+    override function recalculate(): Void {
+        def point = carcass.rootPoint;
+
+        def p = rotate(point, rotateAngle);
+        
+        x = z * p.x;
+        y = z * p.y;
+    }
+
+}
+
+class CameraSegment extends CameraSegment2{
+
+
+    override function recalculate(): Void {
+        color = carcass.segment.color;
+        weight = carcass.segment.weight;
+        
+        def p1 = rotate(carcass.rootPoint1, rotateAngle);
+        def p2 = rotate(carcass.rootPoint2, rotateAngle);
+
+        x1 = z * p1.x;
+        y1 = z * p1.y;
+
+        x2 = z * p2.x;
+        y2 = z * p2.y;
+
+    }
+
+    override function toString() {
+        "segment: ({x1}, {y1} - {x2}, {y2})"
+    }
+
+}
Index: 
MultiDim/src/test/multidimensional/shape/camera/MDUniverseCamerasTest.fx
===================================================================
--- MultiDim/src/test/multidimensional/shape/camera/MDUniverseCamerasTest.fx  
  (revision 0)
+++ MultiDim/src/test/multidimensional/shape/camera/MDUniverseCamerasTest.fx  
  (revision 198)
@@ -0,0 +1,51 @@
+package test.multidimensional.shape.camera;
+
+import javafx.stage.*;
+import javafx.scene.*;
+import javafx.scene.transform.*;
+import mathematics.multidimensional.shape.*;
+import javafx.scene.paint.Color;
+import mathematics.multidimensional.shape2.MDCube2;
+import mathematics.multidimensional.shape2.MDUniversePlayer2;
+import mathematics.multidimensional.shape2.MDUniverse2;
+import mathematics.multidimensional.MDRotate;
+import mathematics.multidimensional.shape2.MDPerspectiveCamera;
+import mathematics.multidimensional.shape2.MDPlainCamera;
+
+var dim = 3;
+var side = 100;
+var delta = 2.0;
+var angle = 0.0;
+var universe: MDUniverse2;
+
+Stage {
+    title: "Test Cameras"
+    scene: Scene {
+        width: 800
+        height: 500
+        content: MDUniversePlayer2 {
+            dimension: dim
+            transforms: Transform.translate(100, 100);
+            universe: universe = MDUniverse2 {
+                        mdtransforms: [
+                            MDRotate { dim: dim axisN: 0 axisM: 1 angle: 
bind angle }
+                            MDRotate { dim: dim axisN: 0 axisM: 2 angle: 
bind angle / 2 }
+                            MDRotate { dim: dim axisN: 1 axisM: 2 angle: 
bind angle / 3 }
+                        ]
+
+                        cameras: [
+                            MDPerspectiveCamera { direction: MDPoint { 
elems: [0, 0, -800] } }
+                            MDPlainCamera {}
+                        ]
+
+                        transformsMotion: MotionType.DYMAMIC
+                        evaluate: function() {
+                            angle += delta;
+                            universe.transformsUpdated = true;
+                        }
+
+                        shapes: [MDCube2 { dim: dim size: side color: 
Color.DARKRED }]
+                    }
+        }
+    }
+}





[multidim~master:198] Add Plain Camera

raindrop 07/02/2010
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close