Reputation: 767
I have gotten all the corners of the Box but I have no idea how to determine min and max x and y coordinates in Python Processing.
Here is the code
add_library('peasycam')
def setup():
size(900, 800, P3D)
global camera
camera = PeasyCam(this, 0, 0, 0, 500)
def draw():
background(255, 255, 255)
lights()
directionalLight(0, 255, 0, 0.5, 1, 0.1)
pushMatrix()
fill(100, 100, 100)
box(100, 100, 100)
corner(50, 50, 50)
cx1 = screenX(0, 0, 0)
cy1 = screenY(0, 0, 0)
corner(-100, 0, 0)
cx2 = screenX(0, 0, 0)
cy2 = screenY(0, 0, 0)
corner(0, -100, 0)
cx3 = screenX(0, 0, 0)
cy3 = screenY(0, 0, 0)
corner(100, 0, 0)
cx4 = screenX(0, 0, 0)
cy4 = screenY(0, 0, 0)
corner(-100, 0, -100)
cx5 = screenX(0, 0, 0)
cy5 = screenY(0, 0, 0)
corner(100, 0, 0)
cx6 = screenX(0, 0, 0)
cy6 = screenY(0, 0, 0)
corner(0, 100, 0)
cx7 = screenX(0, 0, 0)
cy7 = screenY(0, 0, 0)
corner(-100, 0, 0)
cx8 = screenX(0, 0, 0)
cy8 = screenY(0, 0, 0)
popMatrix()
def corner(x, y, z):
translate(x, y, z)
box(10);
I have researched a lot but haven't found any better solution.
Thanks in advance :)
Upvotes: 1
Views: 520
Reputation: 121
I've attached a Java implementation of the working code below. You can access the coordinates by traversing through the PVector array. I'd suggest that you maybe switch to using Java for this project since Processing.py is a bit shaky at the moment and Java will prove to be much more robust in the long run. But if you're more comfortable with Python there's no problem in sticking with it.
import peasy.*;
PeasyCam camera;
PVector[] corners;
void setup() {
size(900, 800, P3D);
camera = new PeasyCam(this, 0, 0, 0, 500);
corners = new PVector[8];
int index = 0;
for(int x = 0; x < 2; x++) {
for(int y = 0; y < 2; y++) {
for(int z = 0; z < 2; z++) {
corners[index] = new PVector(mapCorner(x), mapCorner(y), mapCorner(z));
index++;
}
}
}
}
void draw() {
background(255, 255, 255);
lights();
directionalLight(0, 255, 0, 0.5, 1, 0.1);
pushMatrix();
fill(100, 100, 100);
box(100, 100, 100);
for(PVector v : corners) {
corner(v.x, v.y, v.z);
}
popMatrix();
}
void corner(float x, float y, float z) {
pushMatrix();
translate(x, y, z);
box(10);
popMatrix();
}
float mapCorner(float x) {
return map(x, 0, 1, -50, 50);
}
Hope this helps!
Upvotes: 2