in draw()
consider
void draw() {
background(0);
avoidClipping();
lights();
...
and paste this
// Tools
void avoidClipping() {
// avoid clipping (at camera):
// https : //
// forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
also, you can use peasyCam to rotate freely in 3D: peasycam
Chrisir
not related QUADS example
final int resolution = 32;
QUAD3D[] points = new QUAD3D[resolution * resolution];
float scale = 250.0;
void setup() {
size(1720, 905, P3D);
// perspective(PI / 3.0, -width / (float)height, 0.001, 1000.0);
noStroke();
int len = points.length;
// Calc points.
float toFac = 1.0 / (resolution - 1.0);
for (int k = 0; k < len; ++k) {
int i = k / resolution;
int j = k % resolution;
float iFac = i * toFac;
float jFac = j * toFac;
float iSigned = iFac + iFac - 1.0;
float jSigned = jFac + jFac - 1.0;
float fxy = iSigned * iSigned * jSigned;
float x = iSigned * scale;
float y = jSigned * scale;
float z = fxy * scale;
int red = (int)(0.5 + 255.0 * iFac);
int green = (int)(0.5 + 255.0 * jFac);
int blue = (int)(0.5 + 255.0 * (fxy * 0.5 + 0.5));
points[k] = new QUAD3D();
points[k].col = 0xff000000 | (red << 0x10) | (green << 0x08) | blue;
points[k].pos.set(x, y, z);
}
}
void draw() {
surface.setTitle(nfs(frameRate, 1, 1));
background(#202020);
camera(
width/2, -633, 320,
0.0, 0.0, 0.0,
0.0, 1, 0);
avoidClipping();
lights();
// coord()
strokeWeight(1.0);
stroke(#ff0000);
line(0.0, 0.0, 0.0, 100.0, 0.0, 0.0);
stroke(#00ff00);
line(0.0, 0.0, 0.0, 0.0, 100.0, 0.0);
stroke(#0000ff);
line(0.0, 0.0, 0.0, 0.0, 0.0, 100.0);
noStroke();
// Draw.
/*
if (mousePressed) {
strokeWeight(1.0);
stroke(#ffffff);
} else {
noStroke();
}
*/
rotateZ(frameCount * 0.01);
beginShape(QUADS);
for (int i = 0; i < resolution - 1; ++i) {
int noff0 = i * resolution;
int noff1 = noff0 + resolution;
for (int j = 0; j < resolution - 1; ++j) {
int v00 = noff0 + j;
int v10 = v00 + 1;
int v01 = noff1 + j;
int v11 = v01 + 1;
points[v00].display();
points[v10].display();
points[v11].display();
points[v01].display();
}
}
endShape(CLOSE);
}
// Tools
void avoidClipping() {
// avoid clipping (at camera):
// https : //
// forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
//==============================================================================
class QUAD3D {
PVector pos=new PVector();
color col=color(0);
// no constr
void display() {
fill(col);
vertex(pos.x, pos.y, pos.z);
}
//
}//class
//
Quad_strip example
import peasy.*;
final int GENERAL_Y_HEIGHT = 500;
//
PeasyCam camera;
PShape shapeBridgeToCastleGate;
// Array of ArrayList
ArrayList[] arrListBridgeToCastle = new ArrayList[2];
// -----------------------------------------------------
void setup() {
size (1400, 800, P3D);
avoidClipping();
// The bridge over the water
makeBridgeToCastle();
camera = new PeasyCam(this, width/2, height/2, 0, 900);
} // func
void draw() {
background(#12AEFF);
// apply lights
lights();
shape(shapeBridgeToCastleGate);
}
// -----------------------------------------------------
void makeBridgeToCastle() {
// plate in front - way to castle
// make ArrayLists
for ( ArrayList<PVector> a1 : arrListBridgeToCastle) {
a1 = new ArrayList();
}//for
float depthHalf = 100;
arrListBridgeToCastle[0] = getLineArc2( 115, depthHalf ); // lower right // arc
arrListBridgeToCastle[1] = getLineArc2( 115, -depthHalf ); // lower left // arc
noStroke();
// fill(183, 143, 11);//brown
fill(255, 0, 0);
shapeBridgeToCastleGate=createShape();
shapeBridgeToCastleGate.beginShape(QUAD_STRIP);
// Eval ArrayLists
for (int i3=0; i3<200-1; i3++) { //
makeVertex3D2a( arrListBridgeToCastle[0], i3);
makeVertex3D2a( arrListBridgeToCastle[0], i3+1);
makeVertex3D2a( arrListBridgeToCastle[1], i3);
makeVertex3D2a( arrListBridgeToCastle[1], i3+1);
}//for
shapeBridgeToCastleGate.endShape();
}//func
void makeVertex3D2a( ArrayList<PVector> arrL_, int i ) {
// ArrayList version
PVector v = arrL_.get(i);
shapeBridgeToCastleGate.vertex(v.x, v.y, v.z);
}
void avoidClipping() {
// avoid clipping :
// https : //
// forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
// ---------------------------------------------------------------------------------------
ArrayList<PVector> getLineArc2 ( float y_, float z_ ) {
// fill ArrayList with Arc
// make ArrayList
ArrayList<PVector> newArrayList = new ArrayList();
for (int i3=0; i3<800; i3++) { //
float farAngle=PI/3;
float angle=map(i3, 0, 800, -farAngle, farAngle);
angle+=radians(310);
float r =580 ;
float x=cos(angle)*r;
float y=sin(angle)*r+y_;
// store points in list
PVector pv1 = new PVector(2.5*x+394+222+111-32-32, 4.1*y+GENERAL_Y_HEIGHT+941+400+22+22+12+22+333+111, zValue2(z_, angle));
newArrayList.add(pv1);
} //for
return newArrayList;
//
}// func ---
float zValue2(float z_, float angle_) {
float factor1=3.1;
if (z_<0)
return z_-angle_*factor1;
else
return z_+angle_*factor1;
}
//