Hi, well I figured out the first part - detecting the boundaries and moving my objects by the correct amount - if anyone encounters the same situation my code is below (this assumes a basic camera looking down the Z axis with no rotation). But now I have a new problem...
Code:
final static int WIDTH = 1200; // width of render viewport
final static int HEIGHT = 1800 * 3/4 / 3; // height of render viewport
final static float HALF_WIDTH = WIDTH * 0.5;
final static float HALF_HEIGHT = HEIGHT * 0.5;
final static float FOV_Y = PI/3; // vertical field of view
final static float CAM_DIST = HALF_HEIGHT / tan(FOV_Y/2); // distance from camera to render plane
final static float FOV_X = 2 * atan(HALF_WIDTH / CAM_DIST); // horizontal field of view
final static float TAN_HALF_FOV_X = tan(FOV_X/2);
// gives screen X, Y coordinate for world position x,y,z
Vec3D msaGetScreenXY(float worldX, float worldY, float worldZ) {
float f = CAM_DIST / (CAM_DIST - worldZ);
return new Vec3D (HALF_WIDTH + (f * (worldX - HALF_WIDTH)), HALF_HEIGHT - (f * (HALF_HEIGHT - worldY)), 0);
}
void draw() {
float scrWidth = 2 * TAN_HALF_FOV_X * (CAM_DIST - pos.z);
scrPos = msaGetScreenXY(pos.x, pos.y, pos.z);
if (scrPos.x < 0) {
println(" LESSS ");
pos.x += scrWidth;
scrPos.x += width;
for(int i=0; i<ribbonSegments; i++) {
particles[i].moveBy(scrWidth, 0, 0);
particles[i].velocity().clear();
}
}
else if (scrPos.x > width) {
println(" MORE ");
pos.x -= scrWidth;
scrPos.x -= width;
for(int i=0; i<ribbonSegments; i++) {
particles[i].moveBy(-scrWidth, 0, 0);
particles[i].velocity().clear();
}
}
}
This seems to take care of the edge detection and wrapping (moving the object) quite nicely. But now my problem is that if the object crosses the edge slowly, as soon as the head passes the edge, the whole object jumps to the other side. To resolve this I was rendering the object twice, but I'm not sure that works. Originally I was just rendering the whole object again shifted by scrWidth. But thats a shift in 3D, and I dont think the perspective matches the far left and far right. Is this even possible to do with a perspective view as I'm going to have problems with the vanishing point probably!?