Author: paperwing
Date: 2012-03-06 08:10:11 -0800 (Tue, 06 Mar 2012)
New Revision: 28438

Added:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/DefaultLightingProcessor.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/LightingProcessor.java
Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
Log:
Lighting-maintaining class, LightingProcessor created and integrated into 
GraphicsHandler and Graphics classes. Now, MainGraphicsHandler and 
BirdsEyeGraphicsHandler are capable of initializing and updating their own 
lighting rather and rely on the Graphics class.

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
  2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
  2012-03-06 16:10:11 UTC (rev 28438)
@@ -17,6 +17,8 @@
 import org.cytoscape.paperwing.internal.input.KeyboardMonitor;
 import org.cytoscape.paperwing.internal.input.MainInputProcessor;
 import org.cytoscape.paperwing.internal.input.MouseMonitor;
+import org.cytoscape.paperwing.internal.lighting.DefaultLightingProcessor;
+import org.cytoscape.paperwing.internal.lighting.LightingProcessor;
 import org.cytoscape.paperwing.internal.picking.ShapePickingProcessor;
 import org.cytoscape.paperwing.internal.rendering.PositionCameraProcedure;
 import org.cytoscape.paperwing.internal.rendering.ReadOnlyGraphicsProcedure;
@@ -144,6 +146,11 @@
                        }
                };
        }
+       
+       @Override
+       public LightingProcessor getLightingProcessor() {
+               return new DefaultLightingProcessor();
+       }
 
        @Override
        public void initializeGraphicsProcedures(GraphicsData graphicsData) {

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-06 16:10:11 UTC (rev 28438)
@@ -25,6 +25,7 @@
 import org.cytoscape.paperwing.internal.input.InputProcessor;
 import org.cytoscape.paperwing.internal.input.KeyboardMonitor;
 import org.cytoscape.paperwing.internal.input.MouseMonitor;
+import org.cytoscape.paperwing.internal.lighting.LightingProcessor;
 import org.cytoscape.paperwing.internal.picking.ShapePickingProcessor;
 import org.cytoscape.paperwing.internal.tools.GeometryToolkit;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
@@ -66,6 +67,11 @@
        private CoordinatorProcessor coordinatorProcessor;
        private CytoscapeDataProcessor cytoscapeDataProcessor;
        
+       /**
+        * The {@link LightingProcessor} object responsible for setting up and 
maintaining lighting
+        */
+       private LightingProcessor lightingProcessor;
+       
        private GraphicsHandler handler;
        
        /** Create a new Graphics object
@@ -101,6 +107,7 @@
                inputProcessor = handler.getInputProcessor();
                
                cytoscapeDataProcessor = handler.getCytoscapeDataProcessor();
+               lightingProcessor = handler.getLightingProcessor();
        }
        
        /** Attach the KeyboardMonitor and MouseMonitors, which are listeners,
@@ -153,6 +160,9 @@
                // Process Cytoscape data
                cytoscapeDataProcessor.processCytoscapeData(graphicsData);
                
+               // Update lighting
+               lightingProcessor.updateLighting(gl, 
graphicsData.getLightingData());
+               
                // Draw the scene
                handler.drawScene(graphicsData);
                
@@ -211,6 +221,8 @@
                gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, 
FloatBuffer.wrap(global));
                gl.glShadeModel(GL2.GL_SMOOTH);
 
+               /*
+               
                float[] ambient = { 0.4f, 0.4f, 0.4f, 1.0f };
                float[] diffuse = { 0.57f, 0.57f, 0.57f, 1.0f };
                float[] specular = { 0.79f, 0.79f, 0.79f, 1.0f };
@@ -228,6 +240,8 @@
 
                gl.glEnable(GL2.GL_LIGHT0);
 
+               */
+
                gl.glEnable(GL2.GL_COLOR_MATERIAL);
                gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE);
                
@@ -243,6 +257,8 @@
                gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 16); // Default 
shininess 31
                
                gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0);
+               
+               lightingProcessor.setupLighting(gl, 
graphicsData.getLightingData());
        }
 
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
  2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
  2012-03-06 16:10:11 UTC (rev 28438)
@@ -8,6 +8,7 @@
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.CytoscapeDataProcessor;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.input.InputProcessor;
+import org.cytoscape.paperwing.internal.lighting.LightingProcessor;
 import org.cytoscape.paperwing.internal.picking.ShapePickingProcessor;
 import org.cytoscape.paperwing.internal.rendering.ReadOnlyGraphicsProcedure;
 import org.cytoscape.view.model.CyNetworkView;
@@ -69,7 +70,7 @@
        public CoordinatorProcessor getCoordinatorProcessor();
        
        /**
-        * Return an intance of a {@link CytoscapeDataProcessor}, which is 
responsible for
+        * Return an instance of a {@link CytoscapeDataProcessor}, which is 
responsible for
         * transferring data to and from Cytoscape's data objects, such as 
{@link CyTable}.
         * This could be used to update a value from a {@link CyTable}, or 
retrieve a value
         * from a {@link CyTable}.
@@ -80,6 +81,14 @@
         */
        public CytoscapeDataProcessor getCytoscapeDataProcessor();
        
+       /**
+        * Return an instance of a {@link LightingProcessor} that is 
responsible for setting
+        * up and maintaining scene lighting.
+        * 
+        * @return A {@link LightingProcessor} object responsible for setting 
up and updating
+        * the scene lighting as necessary.
+        */
+       public LightingProcessor getLightingProcessor();
        
        /**
         * This method should be called before the first frame of rendering. It 
will initialize

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-06 16:10:11 UTC (rev 28438)
@@ -18,7 +18,9 @@
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.input.InputProcessor;
 import org.cytoscape.paperwing.internal.input.MainInputProcessor;
+import org.cytoscape.paperwing.internal.lighting.DefaultLightingProcessor;
 import org.cytoscape.paperwing.internal.lighting.Light;
+import org.cytoscape.paperwing.internal.lighting.LightingProcessor;
 import org.cytoscape.paperwing.internal.picking.DefaultShapePickingProcessor;
 import org.cytoscape.paperwing.internal.picking.ShapePickingProcessor;
 import org.cytoscape.paperwing.internal.rendering.PositionCameraProcedure;
@@ -47,7 +49,6 @@
         */
        private List<ReadOnlyGraphicsProcedure> renderProcedures;
        
-       
        public MainGraphicsHandler() {
                renderProcedures = new LinkedList<ReadOnlyGraphicsProcedure>();
        
@@ -139,10 +140,17 @@
        }
        
        @Override
+       public LightingProcessor getLightingProcessor() {
+               return new DefaultLightingProcessor();
+       }
+       
+       @Override
        public void initializeGraphicsProcedures(GraphicsData graphicsData) {
                for (ReadOnlyGraphicsProcedure renderProcedure : 
renderProcedures) {
                        renderProcedure.initialize(graphicsData);
                }
        }
+
+
        
 }
\ No newline at end of file

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-06 16:10:11 UTC (rev 28438)
@@ -105,6 +105,7 @@
                selectionData = new GraphicsSelectionData();
                coordinatorData = new CoordinatorData();
                pickingData = new PickingData();
+               lightingData = new LightingData();
                
                camera = new SimpleCamera();
                viewingVolume = new ViewingVolume();

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
        2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/LightingData.java
        2012-03-06 16:10:11 UTC (rev 28438)
@@ -23,6 +23,15 @@
        }
        
        /**
+        * Obtain all the currently stored lights.
+        * 
+        * @return All the currently stored lights.
+        */
+       public Light[] getLights() {
+               return lights;
+       }
+       
+       /**
         * Create a default {@link LightingData} object with default lights, 
all turned off.
         */
        public LightingData() {

Added: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/DefaultLightingProcessor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/DefaultLightingProcessor.java
                                (rev 0)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/DefaultLightingProcessor.java
        2012-03-06 16:10:11 UTC (rev 28438)
@@ -0,0 +1,50 @@
+package org.cytoscape.paperwing.internal.lighting;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2;
+
+import org.cytoscape.paperwing.internal.data.LightingData;
+
+public class DefaultLightingProcessor implements LightingProcessor {
+
+       @Override
+       public void setupLighting(GL2 gl, LightingData lightingData) {
+               
+               // Initialize light properties
+               Light light0 = lightingData.getLight(0);
+               light0.setAmbient(0.4f, 0.4f, 0.4f, 1.0f);
+               light0.setDiffuse(0.57f, 0.57f, 0.57f, 1.0f);
+               light0.setSpecular(0.79f, 0.79f, 0.79f, 1.0f);
+               light0.setPosition(-4.0f, 4.0f, 6.0f, 1.0f);
+               light0.setTurnedOn(true);
+       }
+
+       @Override
+       public void updateLighting(GL2 gl, LightingData lightingData) {
+               
+               // Loop through all current lights
+               for (int i = 0; i < LightingData.NUM_LIGHTS; i++) {
+                       Light light = lightingData.getLight(i);
+               
+                       if (light.isTurnedOn()) {
+                               
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, 
FloatBuffer.wrap(light.getAmbient()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, 
FloatBuffer.wrap(light.getDiffuse()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, 
FloatBuffer.wrap(light.getSpecular()));
+                               gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, 
FloatBuffer.wrap(light.getPosition()));
+       
+
+                               // We have that GL_LIGHTi = GL_LIGHT0 + i
+                               if (!gl.glIsEnabled(GL2.GL_LIGHT0 + i)) {
+                                       gl.glEnable(GL2.GL_LIGHT0 + i);
+                               }
+                       } else {
+                               if (gl.glIsEnabled(GL2.GL_LIGHT0 + i)) {
+                                       gl.glDisable(GL2.GL_LIGHT0 + i);
+                               }
+                       }
+               }
+       }
+
+}


Property changes on: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/DefaultLightingProcessor.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/LightingProcessor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/LightingProcessor.java
                               (rev 0)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/LightingProcessor.java
       2012-03-06 16:10:11 UTC (rev 28438)
@@ -0,0 +1,28 @@
+package org.cytoscape.paperwing.internal.lighting;
+
+import javax.media.opengl.GL2;
+
+import org.cytoscape.paperwing.internal.data.LightingData;
+import org.cytoscape.view.presentation.RenderingEngine;
+
+/**
+ * An interface providing functionality that is capable of setting up and 
maintaining lighting for a given {@link RenderingEngine} object.
+ */
+public interface LightingProcessor {
+       
+       /**
+        * Perform initial lighting setup.
+        * 
+        * @param gl The OpenGL context used to perform the setup.
+        * @param lightingData The {@link LightingData} object containing the 
current lighting information.
+        */
+       public void setupLighting(GL2 gl, LightingData lightingData);
+       
+       /**
+        * Updates the current lighting, if necessary. This may include 
changing the positions of lights or turning off some lights.
+        *
+        * @param gl The OpenGL context used to update the lights.
+        * @param lightingData The {@link LightingData} object containing the 
current lighting information.
+        */
+       public void updateLighting(GL2 gl, LightingData lightingData);
+}


Property changes on: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/LightingProcessor.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
      2012-03-06 15:35:36 UTC (rev 28437)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
      2012-03-06 16:10:11 UTC (rev 28438)
@@ -3,7 +3,9 @@
 import javax.media.opengl.GL2;
 import javax.media.opengl.glu.GLU;
 
+import org.cytoscape.paperwing.internal.data.LightingData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
+import org.cytoscape.paperwing.internal.lighting.Light;
 
 public class RenderToolkit {
 

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to