We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm new to Processing and would like to draw a box with some sides being transparents. Is there a simplier solution than drawing each rect of the box one by one using beginShape() and vertex() ?
I wonder is there is an API call with 3D rects or quads as rect(startx, starty, startz, endx, endy, endz)
Answers
It is simple to write your own method that will take indexes to 4 points and draw a quad containing then. So, define all the corners (array of Pvectors?). Then call your method 6 times with different arguments.
Ho yeah that make sense ! (I often tend to over complexify ;-)
Thanks ! I'll give a try and come back here if there something wrong
There are probably 100 ways to do it
For example instead of defining 8 corners of the cube manually with xyz, it would be enough to define the top left corner in front and width height and depth of the cube.
Calculate the other 7 points then.
Call the function then with 4 parameters plus one saying
transparentYesNo
as a booleanSince rect() and quad() are both only 2D (other than point() and line()) in your own method you need to use beginShape() and vertex().
3D operations and vertices usually give me headaches (because I know coding but I very very bad at maths ;-) )
I did not yet started to code this stuff but I would define a class as
Does it seems a kinda 'OK' solution ?
nobody was speaking abut a class but never mind
Remark 1
Cube (float _x, float _y, float _z, float _h, float _w) {
here
float _d
for your depth is missing (andd=_d;
)Remark 2
the line
class Cube {
is missingRemark 2 a)
this
PShape face;
isPShape[] faces;
?Remark 3
not sure what
faceColors[i] = new RGBA(255, 255, 255, 0);
is - just usecolor
Remark 4
also I was suggesting transparentYesNo as a boolean
Here you could basically say
If I were you, I wouldn't work this way.
I would start bottom up instead and have always a runnable code. I could run it throughout the process.
So do setup and draw first. Then add a class with one shape. Test it (that's run it), if it's still running... add next step (otherwise debug it). Test it, if it's still running... and so on.
If you write something like you do now in theoretical way, when you will run it the first time, there'll be couple of hard to find errors. In my approach, the error is just in the step you last added.
https://forum.processing.org/two/discussion/comment/119958/#Comment_119958
Kf
Thanks for the hints, I get rid of RGBA and used color instead, and added the depth param.
The overall demo works great, it could be done better but at least it works ! But there is a last thing (for now) that I don't understand : I can use filled faces with colors, but how can I draw faces as wireframe ? The reason for this is : - most cubes will be wireframe - some cubes will have filled faces, except front and back
Inside CubeFace.draw() the statements s.setStroke(255); s.setFill(false); produces nothing but black cubes.
Here is the whole code try, that should run copied/pasted
Any idea ?
visible
is saying whether it's filled or wireframeI also set s.stroke(255); before vertex class CubeFace
instead of void vertex better call it void setVertex - too confusing
also new in class CubeFace, in the constructor
and changes in draw() in class CubeFace
there is flickering right at the bottom of the screen
it's caused here I think:
maybe you can fix that
In fact I wanted to have "some" tunnel's cubes colored/filled and I ended with a poor man's solution : fallback to box() when no fill is needed at all.
And yes, you're right - The flickering is annoying - it might be cause by having too many cubes in the far Z. I'll tweak and see ;-) The result is pretty fun :-)
I dunno if it's a common/tolerated practice to post revised code in comments but here it is.
yeah, but with my solution you have a partial filled, partial non-filled cube. You don't have that
@Paganoni
Yes, that is fine. It is often preferred to editing the original code, as then comments and the statement of the problem all still make sense.