i would like to know the code of a 3D wireframe cube, without using any help like box etc. only the 3D Translation matrixes...thanks a lot for helping. martinpla
a cube has 8 corners. work out the coordinates for these (in 3 dimensions) and stick them in an array, call it vertices.
then work out which corners are connected to which other corners. put this into another array, call it edges.
in draw() loop over the edges array picking out the pairs of points. look up each of these points in the vertices table. draw a line from the one to the other.
// the points
PVector[] vertices = new PVector [9];
// the connecting lines
// e.g. edge 1 goes from vertices edgesFrom[0] to edgesTo[0]
int[] edgesFrom = new int [9];
int[] edgesTo = new int [9];
void setup() {
size(900, 790, OPENGL);
background(0);
vertices[0]=new PVector (100, 100, 100);
} // func
void draw() {
background(0);
// use for loop i and line (x1,y1,z1, x2,y2,z2); here
// with float x1 = vertices [ edgesFrom [i] ].x;
} // func
//
Hi Koogs,
Hi Chrisir,
would it be possible to get the whole code ? i am a beginner and i need more help in this topic...many thanks in advance, martinpla
begin by creating your own square. can you solve that problem first? now you have 4 out of 8 points and 4 of 12 edges.
now create a second square which is a side-length above the first square. can you draw the two squares? now you have all 8 points and 8 out of 12 edges
finally, connect the four pairs of points vertically. now you have all 12 edges.
This is more or less the way I would do it if I was using toothpicks and glue.
Since the corners in the cube can be easily calculated , it’s only necessary to know the position of upper left backfacing corner and the length of the edges.
Then you can calculate the values for all 8 corners
Answers
draw diagrams.
a cube has 8 corners. work out the coordinates for these (in 3 dimensions) and stick them in an array, call it vertices.
then work out which corners are connected to which other corners. put this into another array, call it edges.
in draw() loop over the edges array picking out the pairs of points. look up each of these points in the vertices table. draw a line from the one to the other.
Hi Koogs, Hi Chrisir, would it be possible to get the whole code ? i am a beginner and i need more help in this topic...many thanks in advance, martinpla
Show your attempt as code please
One way to approach this problem is to:
This is more or less the way I would do it if I was using toothpicks and glue.
https://www.OpenProcessing.org/sketch/421281
Naive approach:
Array of pvector named points or corners
Store 8 Points here each with its 3D position
2 parallel Array of int named from and to that hold the indexes(!) of first array. For loop over from and to and show lines:
Using 3D line command with 6 Parameters
More advanced:
Since the corners in the cube can be easily calculated , it’s only necessary to know the position of upper left backfacing corner and the length of the edges.
Then you can calculate the values for all 8 corners
I made an graphical editor for that.
See
https://forum.processing.org/two/discussion/comment/124510/#Comment_124829