We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone. I am a beginner to processing. I would like to:
Allow the user to select a second dot in the same plane connecting a straight line between them. Allow the user to go on creating lines in a plane until:
The user right-clicks a dot in the selected plane and chooses (perhaps from a pop-up/drop-down menu) "degrees of arc" (45, 90, 135).
Once chosen a straight "arc line" is created between the "arc point" and a landing point in the adjacent plane determined by the angle chosen (i.e 90 degree arc creates a line running along the z axis (perpendicular to the plane) connecting the "arc dot" to the corresponding dot in the above plane (closer to the user). If 45, or 135 degrees the "arc line" will end at one of two points in-between visible grid dots in the above plane.)
The new plane is automatically selected and any further points (left) clicked will create a line similar to step 7 above (snapping to the nearest grid point (45, 90, 135).
Optional:
A control panel may be displayed (perhaps at the bottom of the screen) Where: The user can view/edit the number/color of the highlighted plane. The user can highlight the 45/135 grid points within the cube (smaller than initial 90 degree grid dots) The user can "take back" previous line creation/dot selections.
I have copied code from two examples I found in the forums here and managed the stitch them together to sort of do the job.
Ive managed to get LINES (not dots) drawn and rotate the shape in 3d however it seems like the grid is made up of separate
boxes all being rotated individually. See code below:
// Below - (Added from rotating cube script)
float rotx = PI/4;
float roty = PI/4;
float rotz = PI/4;
// Above - (Added from rotating cube script)
void setup() {
size(500, 500, P3D);
strokeWeight(.5);
stroke(0, 0, 0);
}
void draw() {
background(152);
for (int x = 0; x <= height/2; x += 50) {
for (int y = 0; y <= height/2; y += 50) {
for (int z = 0; z <= height/2; z += 50) {
pushMatrix();
translate(height/4 + x, height/4 + y, -125);
// Below - (Added from rotating cube script)
rotateX(rotx);
rotateY(roty);
//scale(90);
// Above - (Added from rotating cube script)
fill(255);
box(150, 150, 150);
popMatrix();
}
}
}
}
// Below - (Added from rotating cube script)
void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}
// Above - (Added from rotating cube script)
Any help would be appreciated.
Answers
Hey,
at the moment you apply the rotation to all individual objects. If you want to rotate everything at once, you have to move the rotation-part in front of your for-loops.
This is obviously homework.
Don't try to copy other people's code to get this done. Instead, develop it yourself from scratch. And to do that, start with the first goal:
No lines. No cubes. No 3D. No rotating. Just a grid of dots. Can you attempt that for us, or even get that working? Post your code of it here for more help.
@TfGuy44: no home work. I am an IT professional but have 0 professional experience programming (unless you count batch files back in 1991 :))
This is just my own personal project. I will see if I can create that grid and back to you.
Finally got a chance to get back to my project :) I managed to create the grid.
Should I try to implement the zoom function before transforming the grid into a 3d cube? And again thanks for any help you can bring.
Decided to take it one step at a time and get the line function working. I want to have a line drawn on mouse click from the previous mouse click position to the current one. My code is below but all I am getting are dots:
I'm sure I'm missing a basic concept here. Anyone able to point me in the right direction?
Try
line(mouseX, mouseY, pmouseX, pmouseY);
Pmousex is the previous mouse position
No need to save it - it gets stored automatically
Your version maybe would work if you have the line command before the storing of mousex and y
I suppose you only posted a part of your code, because the is no setup and no variables declared.
The reason for only getting dots instead of lines is in line 10 and 11: You store the mouse-position in "savedMouse", so the saved mouse-position and the current mouse-position are the same. If you draw the line first and store the mouse-position after that, it should work.
Sorry everybody for the incomplete code earlier. @Chrisir I tried pmouseX/Y before and kept getting only dots. I took yours and @benja's advice and added the line command before the storage and it worked but it kept drawing a line from the 0,0 position when the code initiated so I added the if statement below:
Seems to work. Got SO much homework (@TfGuy44 :)) to do. Will be asking a lot more dumb questions later. Thank you all for your help.
So you did lie to TFGuy44 ?
@Chrisir Nope. Just throwing a shot at him :) Created the line -creation-function + 2d grid. Want to add right click menu next:
Your code is all over the place - even the code for your simple grid of dots.
I don't know why you're trying to draw lines, but the code for that is sort of a mess too.
Something like this is all I wanted to see first:
Look at how simple and straight-forward this is. It draws a grid of dots. That's all.
Step two would be to add a "2D view" and a "3D view". To do this, your program would need some information about which one of the two possible states it is in. Here, I accomplish this by adding a boolean variable, is_3d, that is true when we are looking at the 3D view. Also notice that the sketch is now a 3D sketch.
Since part of step three (in your original post) mentions a cube, I decided to draw a cube in the 3D view. Also notice that you can toggle between the 3D and 2D view by pressing space. As before, notice how clear the logic for this code is.
Steps 3 and 4 both deal with camera controls. For 3, you'd have needed the appropriate mouse functions, plus variables to save the starting mouse position, if we're doing rotation, and the amount of rotation done so far. For 4, a zoom variable, a call to scale(), and a event listener to catch the mouse scrolling.
Now that's getting pretty complicated. From here, you start talking a lot about dots and selecting them and planes and stuff. I highly suggest you write a Dot class if you want to keep working on this.
??
this is homework
don't do it for him
@Chrisir Like I said just a pet project. I haven't done homework since '91. @TfGuy44 thanks for the response. This is a lot to go over. I'll get back to you once I've had time to look it over.
This obviously isn't going to be as easy as I thought. I intended the cube (mentioned in part 3) to be a cube of dots (ellipses). There doesn't seem to be a way to pass z coordinates on to the ellipse function. Anyway you recommend getting this accomplished?
Yeah
You can use points First
Then write your own function
ellipse3D
or so withellipse
orsphere
like
see reference
PM me
Easy
??
actually, that was the instruction
Try it
Ok...Give me another 3 months :)
you are a genius....
I mean like
my... what do the kids learn at school nowadays
Post your entire code
but again you don't cover precisely what you mean in the first place.....
Well as I said before I'm not a programmer.
??
So, what are you then?
Do you mean what do I do for a living?
no... rather why do you want a Program....?
Its a personal project of mine. I am trying to visualize the connections between 2 dimensional linear shapes in 3 dimensional space. Come to think of it I probably only need 2 planes but I would like to be able to draw lines in multiple planes, connect them, and then visualize the shapes from different angles by rotating/shifting the cube.
vague...
With cube you just mean scene or the planes with the lines?
And not a cube that I just did for you?! I wasted my time...
The points in the planes where do they come from? Data? Csv? Or a Grid?
the lines between the points: just lines or dotted line as I did for you??
I mean TFGuy44 did a lot for you...
What is missing for you in his code?
you wrote
Can you post the shapes?
Or your code as far as you are now?
here are 2 sketches by me that use mouse to translate / rotate and zoom
https://forum.processing.org/two/discussion/comment/60283/#Comment_60283
Q. The points in the planes where do they come from? Data? Csv? Or a Grid?
A. Just a Grid. Think 3d graph paper without lines. Just points.
Q. The lines between the points: just lines or dotted line as I did for you??
A. The user creates lines by clicking on the points. When they click and hold on a point they get to choose an angle to connect to the next plane (45, 90, or 135)
Q. Can you post the shapes or your code as far as you are now?
A. The "shapes" are just lines between points. This is how it functions in 2D: https://forum.processing.org/two/discussion/comment/54674/#Comment_54674
you are not making sense...
yes. but which points? Can you post the list of the points?
so then he clicks on a given origin point (in plane A) and chooses the angle and thus creating a new point on the opposite plane (plane B)?
are you aware that the angles are nuts because 90° would be inside plane A and never hit plane B and that 135° degree would even be behind plane A and not going anywhere near plane A...?
oh boy....
Does 90 degrees (perpendicular to the x,y viewing plane) not move the view closer to the observer? Where 270 takes them deeper into screen?
you were referring to drawing a new line to the other plane in this angle...
now you're referring to move the camera.... ?
I mean, the user can start a line and draw a line himself, right?
he can start only at an existing point, right?
and he can end anywhere on the 2nd plane right, ?
and where he ends a new point gets created on the 2nd plane?
or can he draw the line only to an existing target point on the 2nd plane?
We are experiencing a disconnect in jargon. Forget for the moment the method with which you would accomplish this in Processing for a moment...
Just image a 3D Cube made of points in space.
Lines can be drawn between points in the same plane (x1, x2) OR Between points in different planes (z1, z2)
A 90 degree line between z1 and z2 will create a line (perpendicular to the x, y plane) moving toward the user.
Got it?
I think your getting it :) Yes the user can only draw the line to one of 3 existing points in the next plane 45, 90, 135. (only 90 will be initially viewable (see Optional section of original post) but 90, 45 and 135 are the only points accessible in each pane.
do you want to be 2 planes visible or would the cube consist of 10 planes
or if it were a 10 x 10 cube had 10 planes?
Seriously, does no one listen to me? I suggested a Dot class ages ago. Yet no Dot class appears.
This is what we're talking about. Now the next step is going to be determining if the user has clicked on a Dot. This is not an easy problem to solve...
http://www.openprocessing.org/sketch/7707
... oh wait.
Now listen this time: You probably want to write a Connection class. One that draws a line that represents the connection between two Dots.
I implemented right mouse button and a small menu for 90, 45, 135 now....
Wow. This is very close! Apparently this is well out of my depth as an amateur programmer. I will be in contact with both of you shortly.
just ask what you need more
What is your goal with this?
Is this a game, a riddle or a drawing program...?
What do you miss from the code?
@Chrisir thanks for your interest and contact info. Will send you a private email