thanks!
A few minor typos, check this:
boolean insideSphere(
float cx, float cy, float cz, /*center*/
float radius, /*radius*/
float px, float py, float pz /*test point*/
)
{
float x=px-cx;
float y=py-cy;
float z=pz-cz;
float R=radius*radius;
if ((x*x+y*y+z*z) < R) {
return true;
}
return false;
}
can be shortened to
boolean insideSphere (
float cx, float cy, float cz, // center
float radius, // radius
float px, float py, float pz // test point
) {
PVector center = new PVector(cx, cy, cz);
PVector testPoint = new PVector(px, py, pz);
return center.dist(testPoint) < radius;
}
Full code with peasy cam (and some PVector stuff):
import peasy.*;
PeasyCam peasyCam;
PVector center; // center
PVector testPoint=new PVector(); // test point
// -------------------------------------------
void setup() {
size(1400, 940, P3D);
peasyCam = new PeasyCam(this, 1000);
center = new PVector(0, 0, 0);
}
void draw() {
background(255);
lights();
fill(255, 0, 0);
int radiusSphere=200;
for (int x=-radiusSphere; x<radiusSphere; x+=22) {
for (int y=-radiusSphere; y<radiusSphere; y+=22) {
for (int z=-radiusSphere; z<radiusSphere; z+=22) {
if (insideSphere(radiusSphere/2,
x, y, z)) {
pushMatrix();
translate(x, y, z);
box(22-1);
popMatrix();
}
}
}
}
peasyCam.beginHUD();
noLights();
fill(0);
text("Use PeasyCam by dragging the mouse, pan etc. ", 12, 12);
peasyCam.endHUD();
}
// -------------------------------------------
boolean insideSphere ( float radius, // radius
float px, float py, float pz // test point
) {
testPoint.set(px, py, pz);
return
center.dist(testPoint) < radius;
}
//