First of, thanks for the library.
I have a question, it more has to do with drawing offscreen than keystone.
For some reason the center point of the 3D object is shifted once i draw everything into offscreen, can't figure out why. here is example where I added Keystone to Esfera:
Code:
import processing.opengl.*;
import codeanticode.glgraphics.*;
import deadpixel.keystone.*;
GLGraphicsOffScreen offscreen;
Keystone ks;
CornerPinSurface surface;
int cuantos = 8000;
pelo[] lista ;
float[] z = new float[cuantos];
float[] phi = new float[cuantos];
float[] largos = new float[cuantos];
float radio = 200;
float rx = 0;
float ry =0;
void setup() {
size(1024, 768, GLConstants.GLGRAPHICS);
radio = height/3.5;
lista = new pelo[cuantos];
for (int i=0; i<cuantos; i++){
lista[i] = new pelo();
}
noiseDetail(3);
//--------------------------
offscreen = new GLGraphicsOffScreen(this, width, height);
ks = new Keystone(this);
surface = ks.createCornerPinSurface(width, height, 1);
}
void draw() {
PVector mouse = surface.getTransformedMouse();
offscreen.beginDraw();
offscreen.background(0);
offscreen.translate(width/2,height/2,height);
float rxp = ((mouse.x-(width/2))*0.005);
float ryp = ((mouse.y-(height/2))*0.005);
rx = (rx*0.9)+(rxp*0.1);
ry = (ry*0.9)+(ryp*0.1);
offscreen.rotateY(-rx);
offscreen.rotateX(ry);
offscreen.fill(0);
offscreen.noStroke();
offscreen.sphere(radio);
for (int i=0;i<cuantos;i++){
lista[i].dibujar();
}
printCamera();
offscreen.endDraw();
background(0);
surface.render(offscreen.getTexture());
}
void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// & moved
ks.toggleCalibration();
break;
case 'l':
// loads the saved layout
ks.load();
break;
case 's':
// saves the layout
ks.save();
break;
}
}
class pelo
{
float z = random(-radio,radio);
float phi = random(TWO_PI);
float largo = random(1.15,1.2);
float theta = asin(z/radio);
void dibujar(){
float off = (noise(millis() * 0.0005,sin(phi))-0.5) * 0.3;
float offb = (noise(millis() * 0.0007,sin(z) * 0.01)-0.5) * 0.3;
float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float msx= screenX(x,y,z);
float msy= screenY(x,y,z);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);
float xb = xo * largo;
float yb = yo * largo;
float zb = zo * largo;
offscreen.beginShape(LINES);
offscreen.stroke(0);
offscreen.vertex(x,y,z);
offscreen.stroke(200,150);
offscreen.vertex(xb,yb,zb);
offscreen.endShape();
}
}