31 |
import org.nongnu.libvob.gl.*; |
import org.nongnu.libvob.gl.*; |
32 |
import java.util.HashMap; |
import java.util.HashMap; |
33 |
|
|
34 |
public final class GLVobCoorder extends AffineVobCoorder { |
public class GLVobCoorder extends AffineVobCoorder { |
35 |
public static final String rcsid = "$Id$"; |
public static final String rcsid = "$Id$"; |
36 |
public static boolean dbg = false; |
public static boolean dbg = false; |
37 |
private static void pa(String s) { System.err.println(s); } |
private static void pa(String s) { System.err.println(s); } |
97 |
if(cs == 0) return -1; |
if(cs == 0) return -1; |
98 |
return inds[cs+1]; |
return inds[cs+1]; |
99 |
} |
} |
|
|
|
|
// For at least debugging purposes. |
|
|
public String getCoordSystemStr(int cs) { |
|
|
if (cs < 0 || cs >= 5000) return "Out of index!"; |
|
|
String cs_str = null; |
|
|
|
|
|
switch(inds[cs]) { |
|
|
case 1: cs_str = "Affine"; break; |
|
|
case 2: cs_str = "Rotation"; break; |
|
|
case 3: cs_str = "Distort"; break; |
|
|
case 4: cs_str = "Rotation xyz"; break; |
|
|
case 5: cs_str = "Rotation xyz"; break; |
|
|
case 6: cs_str = "Translation xyz"; break; |
|
|
case 7: cs_str = "BuoyOnCircle"; break; |
|
|
case 8: cs_str = "Concat"; break; |
|
|
case 9: cs_str = "Nadir"; break; |
|
|
case 10: cs_str = "Culling"; break; |
|
|
case 11: cs_str = "Box"; break; |
|
|
case 12: cs_str = "unitSq"; break; |
|
|
case 14: cs_str = "OrthoBox"; break; |
|
|
case 15: cs_str = "Invert"; break; |
|
|
} |
|
|
if (cs_str == null) return "CoordSystem: "+cs+" not defined."; |
|
|
else return cs_str; |
|
|
} |
|
|
|
|
|
|
|
|
public int affineCoordsys( |
|
|
int into, float depth, |
|
|
float cx, float cy, |
|
|
float x_x, float x_y, |
|
|
float y_x, float y_y |
|
|
) { |
|
|
if(dbg) pa("AffineCoordSys "+ninds+": "+into+" '"+depth+" --- "+ |
|
|
cx+" "+cy+" "+x_x+" "+x_y+" "+y_x+" "+y_y); |
|
|
|
|
|
int paramInd = nfloats; |
|
|
nfloats += 7; |
|
|
|
|
|
inds[ninds + 0] = 1; // affine = 1 |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
|
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setAffineParams(was, depth, cx, cy, x_x, x_y, y_x, y_y); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setAffineParams( |
|
|
int cs, float depth, float cx, float cy, |
|
|
float x_x, float x_y, float y_x, float y_y) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = cx; |
|
|
floats[ind + 1] = cy; |
|
|
floats[ind + 2] = depth; |
|
|
floats[ind + 3] = x_x; |
|
|
floats[ind + 4] = x_y; |
|
|
floats[ind + 5] = y_x; |
|
|
floats[ind + 6] = y_y; |
|
|
} |
|
|
|
|
|
public int rotate(int into, float degrees) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 1; |
|
|
|
|
|
inds[ninds + 0] = 2; // rotation = 2 |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setRotateParams(was, degrees); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setRotateParams(int cs, float degrees) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = degrees; |
|
|
} |
|
|
|
|
|
|
|
|
public int rotateCentered(int into, float degrees, float x, float y) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 3; |
|
|
|
|
|
inds[ninds + 0] = 16; // rotationCentered = 16 |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setRotateCenteredParams(was, degrees, x, y); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setRotateCenteredParams(int cs, float degrees, |
|
|
float x, float y) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = degrees; |
|
|
floats[ind + 1] = x; |
|
|
floats[ind + 2] = y; |
|
|
} |
|
|
|
|
|
|
|
|
public int rotateXYZ(int into, float degrees, float x, float y, float z) { |
|
|
floats[nfloats + 0] = x; |
|
|
floats[nfloats + 1] = y; |
|
|
floats[nfloats + 2] = z; |
|
|
floats[nfloats + 3] = degrees; |
|
|
int paramInd = nfloats; |
|
|
nfloats += 4; |
|
|
|
|
|
inds[ninds + 0] = 4; // rotation xyz |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public int translateXYZ(int into, float sx, float sy, float sz) { |
|
|
floats[nfloats + 0] = sx; |
|
|
floats[nfloats + 1] = sy; |
|
|
floats[nfloats + 2] = sz; |
|
|
int paramInd = nfloats; |
|
|
nfloats += 3; |
|
|
|
|
|
inds[ninds + 0] = 6; // translation xyz |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public int buoyOnCircle(int into, int anchor, float cx, float cy, |
|
|
float rad, float px, float py, |
|
|
float shiftamount) { |
|
|
floats[nfloats + 0] = cx; |
|
|
floats[nfloats + 1] = cy; |
|
|
floats[nfloats + 2] = rad; |
|
|
floats[nfloats + 3] = px; |
|
|
floats[nfloats + 4] = py; |
|
|
floats[nfloats + 5] = shiftamount; |
|
|
int paramInd = nfloats; |
|
|
nfloats += 6; |
|
|
|
|
|
inds[ninds + 0] = 7; // buoy xyz |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = anchor; |
|
|
inds[ninds + 3] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 4; |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public int getBuoyOnCircleAnchor(int cs) { |
|
|
if(inds[cs] != 7) throw new Error("GetBuoyOnCircle: not buoyOnCircle "+cs); |
|
|
return inds[cs + 2]; |
|
|
} |
|
|
|
|
|
/** Make a nadir rotation of into towards nadir. |
|
|
* That is, at each moment of time, nadirOrigin(a, b) |
|
|
* is equivalent to rotate(a, X) for some angle. |
|
|
* The angle is determined so that the |
|
|
* positive y direction from (0,0) of the rotated |
|
|
* coordinate system points towards the origin of the |
|
|
* nadir coordinate system. |
|
|
* @param into The coordinate system for which a rotated |
|
|
* child is to be constructed. |
|
|
* @param nadir The coordinate system towards whose origin |
|
|
* the positive y coordinate axis of the rotated CS |
|
|
* should point. |
|
|
*/ |
|
|
public int nadirOrigin(int into, int nadir) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 0; |
|
|
|
|
|
inds[ninds + 0] = 9; // nadir |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = nadir; |
|
|
inds[ninds + 3] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 4; |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
/** Make a nadir rotation around unitsq center towards nadir. |
|
|
*/ |
|
|
public int nadirUnitSq(int into, int nadir) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 0; |
|
|
|
|
|
inds[ninds + 0] = 17; // nadirUnitSq |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = nadir; |
|
|
inds[ninds + 3] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 4; |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int scale(int into, float sx, float sy, float sz) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 3; |
|
|
|
|
|
inds[ninds + 0] = 5; // rotation xyz |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setScaleParams(was, sx, sy, sz); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setScaleParams(int cs, float sx, float sy, float sz) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = sx; |
|
|
floats[ind + 1] = sy; |
|
|
floats[ind + 2] = sz; |
|
|
} |
|
|
|
|
|
public int box(int into, float w, float h) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 2; |
|
|
|
|
|
inds[ninds + 0] = 11; // box |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setBoxParams(was, w, h); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setBoxParams(int cs, float w, float h) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = w; |
|
|
floats[ind + 1] = h; |
|
|
} |
|
|
|
|
|
public int unitSq(int into) { |
|
|
inds[ninds + 0] = 12; // unitsq |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = -42; // not used |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
return was; |
|
|
} |
|
|
|
|
|
|
|
|
public int orthoBox(int into, float z, float x, float y, float sx, float sy, float w, float h) { |
|
|
int paramInd = nfloats; |
|
|
nfloats += 7; |
|
|
|
|
|
inds[ninds + 0] = 14; // orthobox |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setOrthoBoxParams(was, z, x, y, sx, sy, w, h); |
|
|
|
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setOrthoBoxParams(int cs, float z, float x, float y, float sx, float sy, float w, float h) { |
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = x; |
|
|
floats[ind + 1] = y; |
|
|
floats[ind + 2] = z; |
|
|
floats[ind + 3] = sx; |
|
|
floats[ind + 4] = sy; |
|
|
floats[ind + 5] = w; |
|
|
floats[ind + 6] = h; |
|
|
} |
|
|
|
|
|
public void getSqSize(int cs, float[] into) { |
|
|
// XXX Dangerous: this needs to be updated whenever new non-unit box |
|
|
// coordsys are added. |
|
|
int type = inds[cs] & ~GL.CSFLAGS; |
|
|
int ind=-42; |
|
|
switch(type) { |
|
|
case 10: // culling |
|
|
getSqSize(inds[cs + 1], into); // forwards to cs' parent |
|
|
break; |
|
|
case 11: // box |
|
|
ind = inds[cs+2]; |
|
|
into[0] = floats[ind + 0]; |
|
|
into[1] = floats[ind + 1]; |
|
|
break; |
|
|
case 14: // orthobox |
|
|
ind = inds[cs+2]; |
|
|
into[0] = floats[ind + 5]; |
|
|
into[1] = floats[ind + 6]; |
|
|
break; |
|
|
case 9: case 17: // nadir -- recurse |
|
|
ind = inds[cs + 1]; |
|
|
getSqSize(ind, into); |
|
|
break; |
|
|
default: |
|
|
into[0] = into[1] = 1; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** A fisheye coordinate system: non-linear magnification. |
|
|
* @param into The parent coordinate system, inside which this cs is |
|
|
* @param x,y,w,h The location and size of the center of magnification |
|
|
* @param mag The magnification at its largest, i.e. in the center of the rectangle |
|
|
* defined by x, y, w, h |
|
|
* @param min The magnification at its smallest, i.e. far away from the origin. |
|
|
*/ |
|
|
public int distort(int into, float x, float y, float w, float h, float mag, float min) { |
|
|
|
|
|
int paramInd = nfloats; |
|
|
nfloats += 6; |
|
|
|
|
|
inds[ninds + 0] = 3; // distort |
|
|
inds[ninds + 1] = into; |
|
|
inds[ninds + 2] = paramInd; |
|
|
|
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
|
|
|
setDistortParams(was, x, y, w, h, mag, min); |
|
|
return was; |
|
|
} |
|
|
|
|
|
public void setDistortParams(int cs, float x, float y, float w, float h, float mag, float min) { |
|
|
|
|
|
int ind = inds[cs + 2]; |
|
|
floats[ind + 0] = x; |
|
|
floats[ind + 1] = y; |
|
|
floats[ind + 2] = (float)Math.log(mag); |
|
|
floats[ind + 3] = (float)Math.log(min); |
|
|
floats[ind + 4] = w; |
|
|
floats[ind + 5] = h; |
|
|
} |
|
|
|
|
|
|
|
|
public int concat(int parent, int child) { |
|
|
int paramInd = nfloats; |
|
|
inds[ninds+0] = 8; // concat |
|
|
inds[ninds+1] = parent; |
|
|
inds[ninds+2] = child; |
|
|
inds[ninds+3] = paramInd; |
|
|
|
|
|
int was = ninds; |
|
|
ninds += 4; |
|
|
return was; |
|
|
} |
|
|
|
|
|
public int invert(int parent) { |
|
|
inds[ninds+0] = 15; // invert |
|
|
inds[ninds+1] = parent; |
|
|
inds[ninds+2] = 42; |
|
|
|
|
|
int was = ninds; |
|
|
ninds += 3; |
|
|
return was; |
|
|
} |
|
|
|
|
|
public int cull(int parent, int clip) { |
|
|
return cull(parent, parent, clip); |
|
|
} |
|
|
|
|
|
public int cull(int parent, int test, int clip) { |
|
|
int paramInd = nfloats; |
|
|
inds[ninds+0] = 10; // culling |
|
|
inds[ninds+1] = parent; |
|
|
inds[ninds+2] = test; |
|
|
inds[ninds+3] = clip; |
|
|
inds[ninds+4] = paramInd; |
|
|
|
|
|
int was = ninds; |
|
|
ninds += 5; |
|
|
return was; |
|
|
} |
|
|
|
|
100 |
public void dump() { |
public void dump() { |
101 |
pa("GLVobCoorder: "); |
pa("GLVobCoorder: "); |
102 |
for(int i=0; i<ninds; i++) { |
for(int i=0; i<ninds; i++) { |