It looks like you're new here. If you want to get involved, click one of these buttons!
Hello all.
Let's say I draw a 3D scene that I don't know beforehand. I just know the min and max position (how long it stretches out) in each direction x y z.
How can I get from these 6 points to tell Peasy Cam its zoom and rotation?
Thanks....
Chrisir
Answers
Hello,
Okay, I obviously need to ask that again.
What would be the solution without PeasyCam, just with the normal camera in P3D please?
My goal is to place the camera automatically in a way that the whole scene is visible but not much more; so I need the eye and center/ look at of the camera to be placed.
The center should be easy (average of min and max for x and y and z) but the eye / camera position is a problem for me.
(My final goal is to be able to make a good screenshot automatically)
Thanks to you all!
Chrisir ;-)
Do you have a camera angle (pitch) in mind? Straight on, or angling down? That probably changes the optimal camera distance if you don't want any clipping of the cube volume. Does the scene always fill the entire volume? Should the camera be pointed at the center of the cube, or is it pointed at a center-offset point?
I don't mind really. Straight on like the default.
It belongs to the Turtle project where you helped me a great deal indeed. So it mostly are single lines in that cube volume. Or some planes. But the Turtle log-files / protocols the min and max ranges for x, y and z. So the volume is mostly empty but the min and max is known for x, y and z. So, yes, I guess we need the entire volume.
center of the cube.
initial thoughts.
given an wider than tall window, rotate until the longest axis is x, next longest is y (and thus narrowest is in/out)
distance from the object (along z) is such that the x dimensions fill the width.
something like d = (width / 2) / tan(pi / 6)
(pi / 6 is half of pi / 3 which is the default fov used in perspective command (aka half of 60 degrees))
(bad) picture in an attempt to explain
the camerax (at the bottom) is the average of minx and maxx.
the distance d is a function of the view angle (alpha), which is typically 60 degrees, or two pi by 6 radians.
take the left hand right-angled triangle
tan (alpha / 2) = opposite / adjacent, opposite is (maxx - minx) / 2, adjacent is d, alpha is 60
so d = ((maxx - minx) / 2) / tan(30)
And..... hmm......
ok, I can calculate center/lookAt see above
So camere Position/ eye is at lookAt position and here Z minus d, correct?
if you arrange the long axis of your thing to be along x then yes, camx is in the middle and camz is -d (or +d, i can never remember) (and y is (maxy + miny) / 2 and up is (0, 1, 0))
try it! (i haven't!)
(have arranged the long axis along x because, assuming the screen is wider than it is tall, that's how you minimise d, which means the object looks as large as it can)
alternatively, you could put lookat as the centre of the object and have distance as the 3d pythagorus of the point of your object furthest from the centre, plus a bit to avoid clipping. so, for a cube, slightly outside the distance of any corner from the centre.
Thank you so much, I 'll look into it - when I find the time, hopefully next weekend
Does it make any sense? I'd throw an example together but have no real idea about the objects you're generating.
Absolutely it makes sense
I am on a journey and can't test it really
The context is my 3D Turtle program where the user writes his own script to draw a 3D shape. See my other discussion.
https://forum.processing.org/two/discussion/comment/88164/#Comment_88164
But since I don't know the size of the shape the Turtle Script generates I am planning to let the Turtle store the range of the cube it moved in for one shape and adjust peasyCam or processing camera accordingly to make sure the entire shape is in the view.
Then I can make a proper screen shot automatically which I am planning to store on hard drive as a preview for the saved Turtle Scripts that the user saved.
But thank you!
Chrisir
hello,
thank you again.
I had time to look at it.
your formula
d = ((maxx - minx) / 2) / tan(30)
in processing is missing the radians, so it'sfloat d = ((maxx - minx) / 2) / tan(radians(30));
ok, instead of using my Turtle Sketch right away I made a simulation for that.
Instead of the Turtle Scene I want to look at later, I use 3 boxes. When you draw them min and max is defined for x,y,z.
You test this by placing the 3 boxes outside the screen at x being around 1800 or so or by spreading them further apart.
The camera has to adjust to that. There are different camera types, you call them by 0,1,2,3 keys. 2 should be the best.
this works good, when you place 3 boxes next to each other on the x-axis
it works less good when you distribute the boxes more
(it's not peasyCam but classical camera)
Best, Chrisir
little simplified version