[Fencommits] libvob: more code ported.

Matti J. Katila majukati at cc.jyu.fi
Tue Feb 7 23:05:17 EET 2006


Tue Feb  7 02:35:04 EET 2006  Matti J. Katila <majukati at cc.jyu.fi>
  * more code ported.

diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/CallGL.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/CallGL.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/CallGL.java	2006-02-07 23:05:16.052521859 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/CallGL.java	2006-02-07 23:05:16.866399126 +0200
@@ -594,7 +594,7 @@
 	throw new Error("assert error.");
     }
 
-    private static void checkGlError(String context) {
+    public static void checkGlError(String context) {
 	int errno = GL11.glGetError();
 	if (errno != GL11.GL_NO_ERROR)
 	    throw new Error(GLU.gluErrorString(errno) + " " + context);
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/Coorder.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/Coorder.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/Coorder.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/Coorder.java	2006-02-07 23:05:16.861399880 +0200
@@ -0,0 +1,48 @@
+// (c): Matti J. Katila
+
+package org.nongnu.libvob.gl.impl.lwjgl;
+
+import org.nongnu.libvob.gl.GLVobCoorder;
+import org.nongnu.libvob.gl.impl.lwjgl.LwjglRenderer.TransformProxy;
+
+/**
+ * A java coorder.
+ * 
+ * 
+ * @author mudyc
+ */
+public class Coorder {
+
+    private Transform tr; 
+    
+    public Coorder(GLVobCoorder from, TransformProxy transProxy) {
+
+	for (int i = 1, lastIndSize = 1; i < from.inds.length && i<from.ninds; i+=lastIndSize) {
+	    // System.out.print(inds[i]+" ");
+	    // if ((i % 10) == 0) System.out.println();
+
+	    int type = from.inds[i];
+	    lastIndSize = from.getIndSize(type);	    
+	    Transform tr1 = transProxy.instantiate(type);
+	    tr1.setYourself(this, i, from.inds, from.floats);
+
+	    Transform tr2 = null;
+	    int cs2;
+
+	}
+    }
+
+    /**
+     * @return a new Coorder which has been linearly
+     *         interpolated between given coordinates.
+     */
+    public static Coorder lerp(Coorder c1, Coorder c2,
+	    int[] interps, float fract) {
+	return null;
+    }
+
+    public Transform getTransform(int cs0) {
+	return null;
+    }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LWJGLRen.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LWJGLRen.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LWJGLRen.java	2006-02-07 23:05:16.050522160 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LWJGLRen.java	2006-02-07 22:10:35.000000000 +0200
@@ -8,9 +8,31 @@
 import org.nongnu.libvob.Vob;
 import org.nongnu.libvob.VobScene;
 import org.nongnu.libvob.Vob.RenderInfo;
+import org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial.CallListBoxCoorder;
+import org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial.CallListCoorder;
+import org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial.NonFilledRectangleVob;
 
 public class LWJGLRen {
 
+    static public interface Vob0 {
+	public void render(int callList);
+    }
+    static public interface Vob1 {
+	public void render(Transform cs0, int callList);
+    }
+    static public interface Vob2 {
+	public void render(Transform cs0, Transform cs1, int callList);
+    }
+    static public interface Vob3 {
+	public void render(Transform cs0, Transform cs1, Transform cs2, int callList);
+    }
+    static public interface VobN  {
+	public void render(Transform[] ncs, int callList);
+    }
+    
+    
+    
+    
     static AbstractVob stubVob1 = new AbstractVob(){
 	public void render(Graphics g, boolean fast, RenderInfo info1, RenderInfo info2) {
 	}
@@ -18,18 +40,28 @@
 	    return 0;
 	}
     };
-    public static final Object NONE = new Object();
-    public static final Object COORDER = new Object();
-    public static final Object BOX_COORDER = new Object();
     
-    public static Vob createNonFilledRectangle(float lineWidth, float f, float g, float h, int i, float j, float k, float l, int m) {
-	return stubVob1;
+    static class GLVob extends AbstractVob {
+	public void render(Graphics g, boolean fast, RenderInfo info1, RenderInfo info2) {
+	}
+    }
+    
+
+    public static Vob createNonFilledRectangle(float lineWidth, float r1, float g1, float b1, float a1, float r2, float g2, float b2, float a2) {
+	return new NonFilledRectangleVob(lineWidth, r1,g1,b1,a1,r2,g2,b2,a2);
     }
 
     // putGL(vs);
-    public static Vob createCallList(String s, Object k) {
-	CallGL callGl = new CallGL(s);
-	return callGl;
+    public static Vob createCallList(String s) {
+	return new CallGL(s);
+    }
+
+    public static Vob createCallListCoorder(String s) {
+	return new CallListCoorder(s);
+    }
+
+    public static Vob createCallListBoxCoorder(String s) {
+	return new CallListBoxCoorder(s);
     }
 
     
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LwjglCoorder.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LwjglCoorder.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LwjglCoorder.java	2006-02-07 23:05:16.049522311 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LwjglCoorder.java	1970-01-01 02:00:00.000000000 +0200
@@ -1,130 +0,0 @@
-// (c): Matti J. Katila
-
-// src bases on code of Tuomas J. Lukka and others.
-
-package org.nongnu.libvob.gl.impl.lwjgl;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.nongnu.libvob.VobMap;
-import org.nongnu.libvob.gl.GLVobCoorder;
-
-/*-
- *  What? Why? How?
- *  ===============
- *  
- *  
- *  
- * 
- */
-public class LwjglCoorder {
-
-    public class TransformFactory {
-	Transform instantiate(int type) {
-	    switch(type) {
-	    case 0: return null;
-	    case 1: return null;
-	    }
-	    return null;
-	}
-    }
-    
-    
-    /*-
-     * Well, there's a huge work to build transformation tree per *every*
-     * frame and I do not want to lost any instances of objects since
-     * creation of those is so slowly. I want to be sure that
-     * storing/flushing transformation instances is very fast operation.
-     * 
-     * Arrays are the fastest way to flush data *fast*. 
-     */
-    public class TransformProxy {
-	TransformFactory factory = new TransformFactory();
-	int size = 100;
-	int[] useIndex = new int[NUM_TYPES];
-	Transform[] clear;
-	Transform[][] inUse = new Transform[NUM_TYPES][],
-		freeForUse = new Transform[NUM_TYPES][];
-
-	TransformProxy() {
-	    for (int i = 0; i < inUse.length; i++)
-		inUse[i] = new Transform[size];
-	    clear = new Transform[size];
-	}
-
-	Transform instantiate(int type) {
-	    if (useIndex[type] + 1 >= size) {
-		resize(size = size * 2);
-	    }
-	    if (freeForUse[type][size - 1 - useIndex[type]] == null)
-		inUse[type][useIndex[type]] = factory.instantiate(type);
-	    else
-		inUse[type][useIndex[type]] = freeForUse[type][size - 1 - useIndex[type]];
-
-	    Transform ret = inUse[type][useIndex[type]];
-	    useIndex[type] = useIndex[type] + 1;
-	    return ret;
-	}
-
-	private void resize(int size) {
-	    for (int i = 0; i < inUse.length; i++) {
-		// create
-		Transform[] newArr = new Transform[size];
-		Transform[] newArr2 = new Transform[size];
-		// copy
-		System.arraycopy(inUse[i], 0, newArr, 0,
-			inUse[i].length);
-		System.arraycopy(freeForUse[i], 0, newArr2, 0,
-			inUse[i].length);
-		// swap
-		inUse[i] = newArr;
-		freeForUse[i] = newArr2;
-	    }
-	    clear = new Transform[size];
-	}
-
-	public void clear() {
-	    // copy to safe but do not deinitialize
-	    for (int i = 0; i < inUse.length; i++)
-		System.arraycopy(inUse[i], 0, freeForUse[i],
-			size - 1 - useIndex[i], useIndex[i]);
-	    // clear
-	    for (int i = 0; i < inUse.length; i++)
-		System.arraycopy(clear, 0, inUse[i], 0,
-			clear.length);
-	}
-    }
-
-    private TransformProxy transProxy;
-    private static LwjglCoorder instance = null;
-    public static final int NUM_TYPES = 22;
-
-    private LwjglCoorder() {
-	transProxy = new TransformProxy();
-    }
-
-    public static synchronized LwjglCoorder getInstance() {
-	if (instance == null)
-	    instance = new LwjglCoorder();
-	return instance;
-    }
-
-    public void render(VobMap map, int[] interps,
-	    GLVobCoorder from, GLVobCoorder to, float fract,
-	    boolean towards, boolean showFinal) {
-	int[] inds = from.inds;
-	for (int i = 0; i < inds.length; i++) {
-	    // System.out.print(inds[i]+" ");
-	    // if ((i % 10) == 0) System.out.println();
-
-	    int cs1 = inds[i];
-
-	    Transform tr = transProxy.instantiate(cs1);
-
-	}
-    }
-
-}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LwjglRenderer.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LwjglRenderer.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/LwjglRenderer.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/LwjglRenderer.java	2006-02-07 23:05:16.860400031 +0200
@@ -0,0 +1,221 @@
+// (c): Matti J. Katila
+
+// src bases on code of Tuomas J. Lukka and others.
+
+package org.nongnu.libvob.gl.impl.lwjgl;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.GL11;
+import org.nongnu.libvob.VobMap;
+import org.nongnu.libvob.gl.GL;
+import org.nongnu.libvob.gl.GLVobCoorder;
+import org.nongnu.libvob.gl.impl.lwjgl.trans.linear.BoxTransform;
+import org.nongnu.libvob.gl.impl.lwjgl.trans.linear.OrthoBoxTransform;
+import org.nongnu.libvob.gl.impl.lwjgl.trans.linear.ScaleTransform;
+import org.nongnu.libvob.gl.impl.lwjgl.trans.linear.TranslateTransform;
+import org.nongnu.libvob.impl.lwjgl.LWJGL_VobMap;
+
+/*-
+ *  What? Why? How?
+ *  ===============
+ *  
+ *  So, what's up? I read tjl's native code like ten times before I started to code this up.
+ *  And finally I'm not sure how it should be done, still I feel like that.
+ *  
+ *  Tuomas' code creates transform (coordinate) instances for every frame. It's not a 
+ *  bottleneck in C++ side for some reason. It's also good for API. The only thing that 
+ *  one render call needs are the inds and floats given. I would like to continue to 
+ *  support this simple API but I'm a bit scary that in the end it's too slow after all.
+ *  
+ *  Tuomas' architecture instantiates one coordinatesystem but it may instantiate two more if there are interpolations which 
+ *  need special handling. 
+ *  
+ *  
+ *  Why not just instantiate coordinate system on the way when coordinate systems are added? There's some issues:
+ *  - I want setCoordinateSystem methods to work.
+ *  
+ *  
+ *  Well, argh..
+ *  
+ *  I will code it like this:
+ *  
+ *  
+ * 
+ */
+public class LwjglRenderer {
+
+    public class TransformFactory {
+	Transform instantiate(int type) {
+	    switch(type) {
+	    case 7: return new TranslateTransform();
+	    case 8: return new ScaleTransform();
+	    case 12: return new BoxTransform();
+	    case 19: return new OrthoBoxTransform();
+	    
+	    default:
+		throw new Error("No transform for type "+type+" implemented (yet).");
+	    }
+	}
+    }
+    
+    
+    /*-
+     * Well, there's a huge work to build transformation tree per *every*
+     * frame and I do not want to lost any instances of objects since
+     * creation of those is so slowly. I want to be sure that
+     * storing/flushing transformation instances is very fast operation.
+     * 
+     * Arrays are the fastest way to flush data *fast*. 
+     */
+    public class TransformProxy {
+	TransformFactory factory = new TransformFactory();
+	int size = 100;
+	int[] useIndex = new int[NUM_TYPES];
+	Transform[] clear;
+	Transform[][] inUse = new Transform[NUM_TYPES][],
+		freeForUse = new Transform[NUM_TYPES][];
+
+	TransformProxy() {
+	    for (int i = 0; i < inUse.length; i++)
+		inUse[i] = new Transform[size];
+	    for (int i = 0; i < inUse.length; i++)
+		freeForUse[i] = new Transform[size];
+	    clear = new Transform[size];
+	}
+
+	Transform instantiate(int type) {
+	    if (useIndex[type] + 1 >= size) {
+		resize(size = size * 2);
+	    }
+	    if (freeForUse[type][size - 1 - useIndex[type]] == null)
+		inUse[type][useIndex[type]] = factory.instantiate(type);
+	    else
+		inUse[type][useIndex[type]] = freeForUse[type][size - 1 - useIndex[type]];
+
+	    Transform ret = inUse[type][useIndex[type]];
+	    useIndex[type] = useIndex[type] + 1;
+	    return ret;
+	}
+
+	private void resize(int size) {
+	    for (int i = 0; i < inUse.length; i++) {
+		// create
+		Transform[] newArr = new Transform[size];
+		Transform[] newArr2 = new Transform[size];
+		// copy
+		System.arraycopy(inUse[i], 0, newArr, 0,
+			inUse[i].length);
+		System.arraycopy(freeForUse[i], 0, newArr2, 0,
+			inUse[i].length);
+		// swap
+		inUse[i] = newArr;
+		freeForUse[i] = newArr2;
+	    }
+	    clear = new Transform[size];
+	}
+
+	public void clear() {
+	    // copy to safe but do not deinitialize
+	    for (int i = 0; i < inUse.length; i++)
+		System.arraycopy(inUse[i], 0, freeForUse[i],
+			size - 1 - useIndex[i], useIndex[i]);
+	    // clear
+	    for (int i = 0; i < inUse.length; i++)
+		System.arraycopy(clear, 0, inUse[i], 0,
+			clear.length);
+	}
+    }
+
+    private TransformProxy transProxy;
+    private static LwjglRenderer instance = null;
+    public static final int NUM_TYPES = 22;
+
+    private LwjglRenderer() {
+	transProxy = new TransformProxy();
+    }
+
+    public static synchronized LwjglRenderer getInstance() {
+	if (instance == null)
+	    instance = new LwjglRenderer();
+	return instance;
+    }
+
+    public void render(LWJGL_VobMap map, int[] interps,
+	    GLVobCoorder from, GLVobCoorder to, float fract) {
+
+	// creates the coordinate systems according to given animation fraction.
+	// this coordinate system is the one that is linearly interpolated.
+	Coorder c = createCoorder(from, to, interps, fract);
+
+	// render vobs to coordinates
+	realRender(c, map);
+	
+	transProxy.clear();
+    }
+
+    
+    private void realRender(Coorder c, LWJGL_VobMap map) {
+	int lastVobSize = 1;
+	for (int i=0; i<map.list.length && i<map.getSize() && map.list[i] != 0; i+= lastVobSize)
+	{
+	    int vob = map.list[i];
+	    int code = map.list[i] & ~GL.RMASK;
+	    
+	    if ((vob & GL.RMASK) == GL.RENDERABLE0) {	
+		GL11.glCallList(code);
+		lastVobSize = 1;
+	    } else if ((vob & GL.RMASK) == GL.RENDERABLE1) {	
+		int cs0 = map.list[i+1];
+		LWJGLRen.Vob1 v = (LWJGLRen.Vob1)map.index2vob[i];
+		v.render(c.getTransform(cs0), code);
+		lastVobSize = 2;
+	    } else if ((vob & GL.RMASK) == GL.RENDERABLE2) {	
+		int cs0 = map.list[i+1];
+		int cs1 = map.list[i+2];
+		LWJGLRen.Vob2 v = (LWJGLRen.Vob2)map.index2vob[i];
+		v.render(c.getTransform(cs0), c.getTransform(cs1), code);
+		lastVobSize = 3;
+	    } else if ((vob & GL.RMASK) == GL.RENDERABLE3) {	
+		int cs0 = map.list[i+1];
+		int cs1 = map.list[i+2];
+		int cs2 = map.list[i+3];
+		LWJGLRen.Vob3 v = (LWJGLRen.Vob3)map.index2vob[i];
+		v.render(c.getTransform(cs0), c.getTransform(cs1), c.getTransform(cs2), code);
+		lastVobSize = 4;
+	    } else if ((vob & GL.RMASK) == GL.RENDERABLEN) {	
+		int ncs = map.list[i+1];
+		System.out.println("renderable N ");
+		lastVobSize = ncs;
+	    } else if ((vob & GL.RMASK) == GL.RENDERABLE_VS) {	
+		throw new Error("un impl.");
+		
+	    } else throw new Error("out of vobs...");
+	}
+	
+	//for (int i=0; i<map.)
+	System.out.println("render impl.");
+	Display.update();
+    }
+
+
+    private Coorder createCoorder(GLVobCoorder from, GLVobCoorder to, int[] interps, float fract) {
+
+	// check for still image - then we use just the given vob coorder
+	if (interps == null || to == null) {
+	    return new Coorder(from, transProxy);
+	} else {
+	    Coorder c1 = new Coorder(from, transProxy);
+	    Coorder c2 = new Coorder(to, transProxy);
+	    
+	    return Coorder.lerp(c1, c2, interps, fract);
+	}
+    }	    
+	    
+	
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/Transform.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/Transform.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/Transform.java	2006-02-07 23:05:16.049522311 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/Transform.java	2006-02-07 23:05:16.864399428 +0200
@@ -1,7 +1,225 @@
 // (c): Matti J. Katila
 
+// bases directly to code by Tuomas J. Lukka on native side.
+
 package org.nongnu.libvob.gl.impl.lwjgl;
 
+
+
+import java.io.OutputStream;
+import org.lwjgl.util.vector.Vector2f;
+import org.lwjgl.util.vector.Vector3f;
+
 public interface Transform {
 
+    /** 
+     * Set up this instance of transform.
+     */
+    void setYourself(Coorder base, int index, int[] inds, float[] floats);
+    
+    
+    
+    //void setActivated(boolean b);
+
+    //boolean isActive();
+
+    /**
+     * Check whether this coordinate system should be drawn with the current
+     * parameters. This method should not recurse; the parents will already
+     * have been asked. It should only consider the parameters of the
+     * current coordinate system.
+     */
+    boolean shouldBeDrawn();
+
+    /**
+     * Return the given Vector3f transformed into this coordinate system.
+     * Note that some "coordinate systems" may overload this to return e.g.
+     * a color in the Vector3f always, without regard to the parameter.
+     */
+    Vector3f transform(final Vector3f p);
+
+    /**
+     * Call glVertex with the given Vector3f transformed into this
+     * coordinate system.
+     */
+    void vertex(final Vector3f p);
+
+    /**
+     * Whether the transformation is nonlinear.
+     */
+    boolean isNonlinear();
+
+    /**
+     * How nonlinear is the coordinate system at the given point. The return
+     * value is 1/l where l would be a reasonable length for dicing. Returns
+     * 0 if dicing is not required. XXX This needs more thought.
+     */
+    float nonlinearity(final Vector3f p, float radius);
+
+    /**
+     * Whether this transformation can be performed by OpenGL alone by using
+     * the transformation matrix. If true, calling performGL allows the
+     * caller to use plain glVertex calls to place vertices using this
+     * transform.
+     */
+    boolean canPerformGL();
+
+    /**
+     * Try to perform the GL operations to set this coordinate system in the
+     * current matrix. Only the topmost matrix on the matrix stack may be
+     * altered by this routine, no other GL state. The matrix used is
+     * determined by the GL current matrix state.
+     * <p>
+     * This method will NOT set up vertex programs or change any other
+     * OpenGL state.
+     * 
+     * @return True if successful, but if false is returned, then the matrix
+     *         is in an undefined state. If this is not acecptable, try
+     *         canPerformGL() first.
+     */
+    boolean performGL();
+
+    /**
+     * Get the inverse of this coordinate system. Always returns non-null
+     * but it is not guaranteed that this will work properly. (XXX
+     * canInvert() ?) The returned inverse is owned by this object and
+     * mustn't be deleted by the caller.
+     */
+    Transform getInverse();
+
+    /**
+     * Print this coordinate system into the given ostream.
+     */
+    void dump(OutputStream out);
+
+    /**
+     * Get the size of the "unit square" of this coordinate system. For most
+     * coordinate systems, this will be Vector2f(1,1) but there are some
+     * which alter this, for the purpose of catching mouse clicks at a
+     * larger area. A mouse click is "in" this coordinate system, if it is
+     * in the area Vector2f(0,0) .. getSqSize()
+     * 
+     * NOTE: Must be implemented also at GLVobCoorder.java.
+     */
+    Vector2f getSqSize();
+
+    
+    
+    
+    // tag interfaces.
+    
+    
+    
+    
+    
+    /** A primitive transform, implying an interface
+     * used by the templates for building up 
+     * transforms.
+     * Deriving from this class implies the following method:
+     * <pre>
+	void tr(const ZPt &from, ZPt &to) const 
+	typedef InverseType ???;
+	void inverse(InverseType &into) ;
+      </pre>
+     */
+    static public interface PrimitiveTransform {
+    };
+
+    /** A tag interface, implying that the primitive transform
+     * may switch off rendering of the vobs in it.
+     * This interface implies for a primitive
+     * transform that there is shouldBeDrawn() method:
+     * <pre>
+      	bool shouldBeDrawn() const;
+      </pre>
+     */
+    static public interface DisablablePrimitiveTransform { };
+
+    /** A tag interface, implying that the transform requires
+     * floating-point parameters.
+     * Implies the following interface in the inheriting class:
+     * <pre>
+	enum { NParams = ??? };
+	template<class Ptr> void setParams(Ptr p)
+	</pre>
+	Note that combining this with DependentPrimitiveTransform
+	adds more arguments to the setParams() call.
+     */
+    static public interface ParametrizedPrimitiveTransform { };
+
+
+    /** A tag interface, for a transform which 
+     * depends on some transform(s).
+     * This class unfortunately shows some abstraction through,
+     * because sometimes you want the transformation to depend
+     * on the real parent (UnitSqBox, Nadir), and sometimes not (cull).
+     * Thus, this class will know about the "first parent".
+     * Implies the following interface:
+     * <pre>
+	enum { NDepends = ??? }; // Number of parent coordsyses
+	template<class SPtr> void setParams(SPtr depends) ;
+	</pre>
+	Note that combining this with ParametrizedPrimitiveTransform
+	adds more arguments to the setParams() call.
+     */
+    static public interface DependentPrimitiveTransform { };
+
+    /** A tag interface for transformations which can be performed
+     * by manipulating the OpenGL fixed-function vertex pipeline.
+     * For instance rotations and transformations can be performed faster by
+     * just letting OpenGL combine the transformations into a matrix.
+     * Implies the following method:
+       <pre>
+	void performGL() { }
+       </pre>
+     *
+     */
+    static public interface GLPerformablePrimitiveTransform { };
+
+    /** A tag interface for transformations which may <em>sometimes</em>
+     * be performed using OpenGL but sometimes not.
+     * Implies the following methods:
+      <pre>
+	bool canPerformGL() ;
+	bool performGL() ;
+      </pre>
+      with the same semantics as in {@link Vob::Transform}.
+     *
+     * @link Vob::Transform
+     */
+    static public interface PotentiallyGLPerformablePrimitiveTransform { };
+
+    /** A tag interface for transformations which may be nonlinear.
+     * Implies
+     * <pre>
+	float nonlinearity(ZPt p, float radius) ;
+	</pre>
+     */
+    static public interface NonlinearPrimitiveTransform { };
+
+    /** A tag for a primitive transform that sets a box size.
+     * Implies
+     * <pre>
+	Pt getSqSize() { return Pt(1,1); }
+	</pre>
+     */
+    static public interface BoxPrimitiveTransform { };
+
+
+    /** A tag for a transform that is not invertible.
+     * This is done this way because the non-invertible 
+     * transforms are rightly in a minority.
+     */
+    static public interface NonInvertiblePrimitiveTransform { };
+
+    /** A tag for a primitive transform that can print out
+     * stuff.
+     * Implies
+     * <pre>
+        void dump(std::ostream &out) const { }
+     * </pre>
+     */
+    static public interface DumpingPrimitiveTransform { };
+
+    
 }
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/BoxTransform.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/BoxTransform.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/BoxTransform.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/BoxTransform.java	2006-02-07 23:05:16.855400785 +0200
@@ -0,0 +1,66 @@
+package org.nongnu.libvob.gl.impl.lwjgl.trans.linear;
+
+import java.io.OutputStream;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector2f;
+import org.lwjgl.util.vector.Vector3f;
+import org.nongnu.libvob.gl.impl.lwjgl.Coorder;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class BoxTransform implements Transform {
+
+    public void setYourself(Coorder base, int index, int[] inds, float[] floats) {
+	System.out.println("box");
+    }
+
+    public boolean shouldBeDrawn() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public Vector3f transform(Vector3f p) {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void vertex(Vector3f p) {
+	// TODO Auto-generated method stub
+
+    }
+
+    public boolean isNonlinear() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public float nonlinearity(Vector3f p, float radius) {
+	// TODO Auto-generated method stub
+	return 0;
+    }
+
+    public boolean canPerformGL() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public boolean performGL() {
+	return true;
+    }
+
+    public Transform getInverse() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void dump(OutputStream out) {
+	// TODO Auto-generated method stub
+
+    }
+
+    public Vector2f getSqSize() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/OrthoBoxTransform.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/OrthoBoxTransform.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/OrthoBoxTransform.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/OrthoBoxTransform.java	2006-02-07 23:05:16.858400333 +0200
@@ -0,0 +1,66 @@
+package org.nongnu.libvob.gl.impl.lwjgl.trans.linear;
+
+import java.io.OutputStream;
+
+import org.lwjgl.util.vector.Vector2f;
+import org.lwjgl.util.vector.Vector3f;
+import org.nongnu.libvob.gl.impl.lwjgl.Coorder;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class OrthoBoxTransform implements Transform {
+
+    public void setYourself(Coorder base, int index, int[] inds, float[] floats) {
+	System.out.println("orthobox");
+    }
+
+    public boolean shouldBeDrawn() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public Vector3f transform(Vector3f p) {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void vertex(Vector3f p) {
+	// TODO Auto-generated method stub
+	
+    }
+
+    public boolean isNonlinear() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public float nonlinearity(Vector3f p, float radius) {
+	// TODO Auto-generated method stub
+	return 0;
+    }
+
+    public boolean canPerformGL() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public boolean performGL() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public Transform getInverse() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void dump(OutputStream out) {
+	// TODO Auto-generated method stub
+	
+    }
+
+    public Vector2f getSqSize() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/ScaleTransform.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/ScaleTransform.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/ScaleTransform.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/ScaleTransform.java	2006-02-07 23:05:16.859400182 +0200
@@ -0,0 +1,72 @@
+package org.nongnu.libvob.gl.impl.lwjgl.trans.linear;
+
+import java.io.OutputStream;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector2f;
+import org.lwjgl.util.vector.Vector3f;
+import org.nongnu.libvob.gl.impl.lwjgl.Coorder;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class ScaleTransform implements Transform {
+
+    private float xs, ys, zs;
+    public void setYourself(Coorder base, int index, int[] inds, float[] floats) {
+	System.out.println("scale");
+	int floatInd = inds[index+2];
+	int parent = inds[index+1];
+	xs = floats[floatInd];
+	ys = floats[floatInd+1];
+	zs = floats[floatInd+2];
+    }
+
+    public boolean shouldBeDrawn() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public Vector3f transform(Vector3f p) {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void vertex(Vector3f p) {
+	// TODO Auto-generated method stub
+
+    }
+
+    public boolean isNonlinear() {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    public float nonlinearity(Vector3f p, float radius) {
+	// TODO Auto-generated method stub
+	return 0;
+    }
+
+    public boolean canPerformGL() {
+	return true;
+    }
+
+    public boolean performGL() {
+	GL11.glScalef(xs,ys,zs);
+	return true;
+    }
+
+    public Transform getInverse() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public void dump(OutputStream out) {
+	// TODO Auto-generated method stub
+
+    }
+
+    public Vector2f getSqSize() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/TranslateTransform.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/TranslateTransform.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/TranslateTransform.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/trans/linear/TranslateTransform.java	2006-02-07 23:05:16.857400483 +0200
@@ -0,0 +1,63 @@
+package org.nongnu.libvob.gl.impl.lwjgl.trans.linear;
+
+import java.io.OutputStream;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector2f;
+import org.lwjgl.util.vector.Vector3f;
+import org.nongnu.libvob.gl.impl.lwjgl.Coorder;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class TranslateTransform implements Transform {
+
+    private float x=0, y=0, z=0;
+    public void setYourself(Coorder base, int index, int[] inds, float[] floats) {
+	System.out.println("translate");
+	int floatInd = inds[index+2];
+	int parent = inds[index+1];
+	x = floats[floatInd];
+	y = floats[floatInd+1];
+	z = floats[floatInd+2];
+    }
+
+    public boolean shouldBeDrawn() {
+	return false;
+    }
+
+    public Vector3f transform(Vector3f p) {
+	return null;
+    }
+
+    public void vertex(Vector3f p) {
+    }
+
+    public boolean isNonlinear() {
+	return false;
+    }
+
+    public float nonlinearity(Vector3f p, float radius) {
+	return 0;
+    }
+
+    public boolean canPerformGL() {
+	return true;
+    }
+
+    public boolean performGL() {
+	GL11.glTranslatef(x,y,z);
+	return true;
+    }
+
+    public Transform getInverse() {
+	return null;
+    }
+
+    public void dump(OutputStream out) {
+	
+    }
+
+    public Vector2f getSqSize() {
+	return null;
+    }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListBoxCoorder.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListBoxCoorder.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListBoxCoorder.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListBoxCoorder.java	2006-02-07 23:05:16.854400936 +0200
@@ -0,0 +1,34 @@
+package org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector2f;
+import org.nongnu.libvob.Vob;
+import org.nongnu.libvob.VobScene;
+import org.nongnu.libvob.gl.impl.lwjgl.CallGL;
+import org.nongnu.libvob.gl.impl.lwjgl.LWJGLRen;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class CallListBoxCoorder extends CallGL implements LWJGLRen.Vob1  {
+
+    public CallListBoxCoorder(String s) {
+	super(s);
+    }
+    
+    public void render(Transform t, int callList) {
+	CallGL.checkGlError("Start boxcoorder");
+	GL11.glPushMatrix();
+	if(t.performGL()) {           
+	    Vector2f boxwh = t.getSqSize();
+	    GL11.glScalef(boxwh.x, boxwh.y, 1.0f);
+
+	    GL11.glCallList(callList);
+	} else {
+	    System.out.println("Error: CallisBoxtCoorded with non-glperformable.");
+//	    t.dump(std::cout);
+	}
+	GL11.glPopMatrix();
+	CallGL.checkGlError("After boxcoorded calling list ");
+
+    }
+    
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListCoorder.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListCoorder.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListCoorder.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/CallListCoorder.java	2006-02-07 22:10:35.000000000 +0200
@@ -0,0 +1,33 @@
+package org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial;
+
+import java.awt.Graphics;
+
+import org.lwjgl.opengl.GL11;
+import org.nongnu.libvob.AbstractVob;
+import org.nongnu.libvob.Vob;
+import org.nongnu.libvob.Vob.RenderInfo;
+import org.nongnu.libvob.gl.impl.lwjgl.CallGL;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+import org.nongnu.libvob.gl.impl.lwjgl.LWJGLRen.Vob1;
+
+public class CallListCoorder extends CallGL implements Vob1 {
+
+    public CallListCoorder(String s) {
+	super(s);
+    }
+
+    public void render(Transform t, int callList) {
+	CallGL.checkGlError("before call list coorder");
+	GL11.glPushMatrix();
+	if(t.performGL()) {
+	    GL11.glCallList(callList);
+	} else {
+	    System.out.println("Error: CallistCoorded with non-glperformable.");
+//	    t.dump(std::cout);
+	}
+	GL11.glPopMatrix();
+	CallGL.checkGlError("After coorded calling list "+callList);
+
+    }
+    
+}
diff -rN -u libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/NonFilledRectangleVob.java libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/NonFilledRectangleVob.java
--- libvob-old/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/NonFilledRectangleVob.java	1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/gl/impl/lwjgl/vobs/trivial/NonFilledRectangleVob.java	2006-02-07 23:05:16.853401086 +0200
@@ -0,0 +1,95 @@
+/**
+ * 
+ */
+package org.nongnu.libvob.gl.impl.lwjgl.vobs.trivial;
+
+import java.awt.Graphics;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.util.vector.Vector2f;
+import org.nongnu.libvob.AbstractVob;
+import org.nongnu.libvob.Vob.RenderInfo;
+import org.nongnu.libvob.gl.impl.lwjgl.CallGL;
+import org.nongnu.libvob.gl.impl.lwjgl.LWJGLRen;
+import org.nongnu.libvob.gl.impl.lwjgl.Transform;
+
+public class NonFilledRectangleVob extends AbstractVob implements LWJGLRen.Vob1 {
+
+    private final float lineWidth, r1,g1,b1,a1, r2,g2,b2,a2;
+    
+    public NonFilledRectangleVob(float lineWidth, float r1, float g1,
+	    float b1, float a1, float r2, float g2, float b2,
+	    float a2) {
+	super();
+	this.a2 = a2;
+	this.g2 = g2;
+	this.g1 = g1;
+	this.r2 = r2;
+	this.a1 = a1;
+	this.r1 = r1;
+	this.lineWidth = lineWidth;
+	this.b2 = b2;
+	this.b1 = b1;
+    }
+
+    public void render(Transform t, int callList) {
+	CallGL.checkGlError("Before NonFilledRect");
+	GL11.glPushMatrix();
+	if (t.performGL()) {
+	    GL11.glPushAttrib(GL11.GL_CURRENT_BIT
+		    | GL11.GL_ENABLE_BIT);
+	    GL11.glDisable(GL11.GL_TEXTURE_2D);
+
+	    Vector2f box = t.getSqSize();
+
+	    GL11.glColor4d(r1, g1, b1, a1);
+
+	    // top strip
+	    GL11.glBegin(GL11.GL_QUAD_STRIP);
+	    GL11.glVertex2f(0, 0);
+	    GL11.glVertex2f(lineWidth, lineWidth);
+	    GL11.glVertex2f(box.x, 0);
+	    GL11.glVertex2f(box.x - lineWidth, lineWidth);
+	    GL11.glEnd();
+
+	    // left strip
+	    GL11.glBegin(GL11.GL_QUAD_STRIP);
+	    GL11.glVertex2f(0, 0);
+	    GL11.glVertex2f(0, box.y);
+	    GL11.glVertex2f(lineWidth, lineWidth);
+	    GL11.glVertex2f(lineWidth, box.y - lineWidth);
+	    GL11.glEnd();
+
+	    GL11.glColor4d(r2, g2, b2, a2);
+
+	    // right strip
+	    GL11.glBegin(GL11.GL_QUAD_STRIP);
+	    GL11.glVertex2f(box.x - lineWidth, lineWidth);
+	    GL11.glVertex2f(box.x - lineWidth, box.y - lineWidth);
+	    GL11.glVertex2f(box.x, 0);
+	    GL11.glVertex2f(box.x, box.y);
+	    GL11.glEnd();
+
+	    // bottom strip
+	    GL11.glBegin(GL11.GL_QUAD_STRIP);
+	    GL11.glVertex2f(lineWidth, box.y - lineWidth);
+	    GL11.glVertex2f(0, box.y);
+	    GL11.glVertex2f(box.x - lineWidth, box.y - lineWidth);
+	    GL11.glVertex2f(box.x, box.y);
+	    GL11.glEnd();
+
+	    GL11.glPopAttrib();
+	} else {
+	    System.out
+		    .println("Error: NonFilledRectangle with non-glperformable.");
+	    // t.dump(std::cout);
+	}
+	GL11.glPopMatrix();
+	CallGL.checkGlError("After NonFilledRect");
+
+    }
+
+    public void render(Graphics g, boolean fast, RenderInfo info1, RenderInfo info2) {
+    }
+
+}
\ No newline at end of file




More information about the Fencommits mailing list