Simple 3D Cube out of a set of points
in
Programming Questions
•
2 years ago
I am trying to build a simple cube out of a set of a couple of points.
Each point of the 3D shape is defined by its x,y,z coordinates/variables. I want to be able to control the coordinates of each point separately - that is why I declared each x,y,and z coordinate...
At one point I want to be able to change the x coordinate of point5, while at another - I want to be able to change the z coordinate of point8 (for example)
At one point I want to be able to change the x coordinate of point5, while at another - I want to be able to change the z coordinate of point8 (for example)
When I run the sketch, however, only the four corner points are visible. Could you point out as to what I am missing or doing wrongly? Thank you in advance!
import processing.opengl.*;
PointsC point1, point2, point3, point4, point5, point6, point7, point8;
float rotX, rotY;
void setup() {
size(500, 500, P3D);
background(255);
point1 = new PointsC(0, 0, 0);
point2 = new PointsC(100, 0, 0);
point3 = new PointsC(0,100,0);
point4 = new PointsC(100, 100, 0);
point5 = new PointsC(0, 0, -100);
point6 = new PointsC(100, 0, -100);
point7 = new PointsC(100, 100, -100);
point8 = new PointsC(0, 100, -100);
}
void draw() {
background(255);
translations();
point1.drawpoint();
point2.drawpoint();
point3.drawpoint();
point4.drawpoint();
point5.drawpoint();
point6.drawpoint();
point7.drawpoint();
point8.drawpoint();
size(500, 500, P3D);
background(255);
point1 = new PointsC(0, 0, 0);
point2 = new PointsC(100, 0, 0);
point3 = new PointsC(0,100,0);
point4 = new PointsC(100, 100, 0);
point5 = new PointsC(0, 0, -100);
point6 = new PointsC(100, 0, -100);
point7 = new PointsC(100, 100, -100);
point8 = new PointsC(0, 100, -100);
}
void draw() {
background(255);
translations();
point1.drawpoint();
point2.drawpoint();
point3.drawpoint();
point4.drawpoint();
point5.drawpoint();
point6.drawpoint();
point7.drawpoint();
point8.drawpoint();
} //end draw
void mouseDragged() {
float x1 = mouseX-pmouseX;
float y1 = mouseY-pmouseY;
rotX = (mouseY * -0.01);
rotY = (mouseX * 0.01);
}
void translations() {
translate(width/2, height/2);
rotateX(rotX);
rotateY(rotY);
}
float y1 = mouseY-pmouseY;
rotX = (mouseY * -0.01);
rotY = (mouseX * 0.01);
}
void translations() {
translate(width/2, height/2);
rotateX(rotX);
rotateY(rotY);
}
class PointsC {
float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8;
PointsC(float xpos, float ypos, float zpos) {
x1 = xpos;
x2 = xpos;
x3 = xpos;
x4 = xpos;
x5 = xpos;
x6 = xpos;
x7 = xpos;
x8 = xpos;
y1 = ypos;
y2 = ypos;
y3 = ypos;
y4 = ypos;
y5 = ypos;
y6 = ypos;
y7 = ypos;
y8 = ypos;
z1 = zpos;
z2 = zpos;
z3 = zpos;
z4 = zpos;
z5 = zpos;
z6 = zpos;
z7 = zpos;
z8 = zpos;
}
void drawpoint() {
stroke(0);
strokeWeight(5);
point(x1,y1,z1);
point(x2,y2,z2);
point(x3,y3,z3);
point(x4,y4,z4);
point(x5,y5,z5);
point(x6,y6,z6);
point(x7,y7,z7);
point(x8,y8,z8);
}
}
float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8;
PointsC(float xpos, float ypos, float zpos) {
x1 = xpos;
x2 = xpos;
x3 = xpos;
x4 = xpos;
x5 = xpos;
x6 = xpos;
x7 = xpos;
x8 = xpos;
y1 = ypos;
y2 = ypos;
y3 = ypos;
y4 = ypos;
y5 = ypos;
y6 = ypos;
y7 = ypos;
y8 = ypos;
z1 = zpos;
z2 = zpos;
z3 = zpos;
z4 = zpos;
z5 = zpos;
z6 = zpos;
z7 = zpos;
z8 = zpos;
}
void drawpoint() {
stroke(0);
strokeWeight(5);
point(x1,y1,z1);
point(x2,y2,z2);
point(x3,y3,z3);
point(x4,y4,z4);
point(x5,y5,z5);
point(x6,y6,z6);
point(x7,y7,z7);
point(x8,y8,z8);
}
}
1