We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Howdy, I'm making a program that shows a 3d model I import from a file.
I already have the basic stuff such as loading and displaying the model, and I calcolate the angle I want to rotate by dragging the mouse movements.
The probem is that a simple conversion to rotateX/Y/Z gives a non intuitive navigation in the 3d space.
I would like a movement similar to that seen in every 3d modeling program ever, like sketchup, autocad, etc.
An example in processing would be under /examples/demos/graphics/ribbons.
Any idea on how to do this? Or where to look at? I'm not sure of the terminology here, so every google search gave unrelated results to me.
Answers
look at the peasycam library, it does all this in 2 lines of code (and 1 import)
Do you mind to show your code?
I am curious?
PeasyCam is "a dead-simple mouse-driven camera for Processing" -- it can be installed using the Processing IDE Contributions Manager > Add Library.
For more details, see:
...including the minimal example that @koogs mentioned:
For previous sketches discussed on the forum that involved orbiting planets (or protons), try looking at these threads:
...and these searches:
Thanks, I've been looking into PEasycam, it is quite interesting but is a bit...too dead easy. I will report any news.
P.S. Did anyone notice that with sizes>200x200 the cam moves wildly?
You wrote:
I haven't noticed this. Ever.
Simple Sketch
Here is a small approach without peasyCam (look at lines 17 and 18):
more advanced sketch with a Camera class and different ways (try keys 0..6) :
@Chrisir , I've taken some bits from your code here to try and make a simple "orbital" camera... rotate around an object at the center of a scene with the ability to zoom in and out on the object. I'm using LMB+drag to navigate around the object and mouse wheel to zoom because I need to be able to move cursor within the view and right click on objects in scene without reframing the viewpoint (if that makes sense) Problem I'm now stuck on is that every time I click and drag, the view navigation/rotation will start from the position of that new 'drag'. I need to somehow save the last position and then add the magnitude of the last drag ?
I have a horrible feeling from looking at the "ribbons" demo(even though that's rotating the objects not a camera-which I can't do) that this is going to involve some deep vector shenanigans well beyond me. Do you or anyone else have any suggestions ?
stripped down version of code here (just a box to nav around and no right clicking to select) :
I don't understand this:
You mean where you click the mouse to begin the dragging the cam jumps to and that annoys you?
Just store the mouse pos at beginning of drag (I suppose in mousePressed) and during drag take the difference and add it to the old mouse position in the cam class.
Clear?
ah, much easier solution (lines 68 and 69 plus 77):
I need more sleep... haha was obvious. Thanks Chris ;)
;-)