We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have an urgent question about PeasyCam's damping property.. When I use PeasyCam to rotate a 3D object, after the mouse stops the object still moves with a decreasing velocity (damping). PeasyCam has a class called DampedAction for this movement. My question is: How can I change the damping value (original 0.16) or disable the damping property. For example in the PeasyCam sample bellow I would like to change (extend) this class in peasy library or Override it.. How is it possible to do it in this code:
import peasy.*;
PeasyCam cam;
void setup() {
size(800,600,P3D);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
}
void draw() {
rotateX(-.5);
rotateY(-.5);
background(0);
fill(255,0,0);
box(50);
pushMatrix();
translate(0,0,30);
fill(0,0,255);
box(5);
popMatrix();
}
Thanks for any help!..
Answers
Check out a previous discussion here:
If you want to do it yourself, one guess at a starting point: here is the constructor for a DampedAction with a custom friction:
- https://github.com/jdf/peasycam/blob/master/src/peasy/DampedAction.java#L38
...and here are the DampedActions built into a PeasyCam object:
Perhaps you could extend this PeasyCam constructor:
...and also pass in a friction value, which the constructor would in turn would pass it to new DampedAction constructors.
Alternately, create a setFriction() method.
Thank you very much for your reply.. I have read the previous discussion before, but I couldn't make it work. I also would like to use the original peasy library and make it in my own code if possible. Creating something like setFriction() method is exactly what I am looking for, but I don't know how to make it. Could you please give a sample setFriction() code? Thanks..
I'd suggest starting by looking at the
setDamping()
example code linked from the previous discussion. You should either extend PeasyCam or else edit the library and create your own version -- or contribute a commit to the main peasycam repo.I have also tried to use the PeasyCam+ library. Dowloaded it and there is a "core.jar" file in a lib folder (instead of peasycam.jar in library folder). I have no idea, what to do with it.. If I use the peasy+ files in peasy folder it won't work.. How should I use this peasycam+ library? Where and how to locate it?.. Please help..
Well, the simplest of all possible ways to change it is to fork PeasyCam on github and change 0.16 to some other value.
Isn't the simplest way to use the hook already within peasycam to set your own drag handler?
@ jeremydouglass
I have tried to change DampedAction.java in PeasyCam package, but I could not make class files and jar file (using javac). I don't have enough knowledge for that. Could you please give a link showing how to do it or an example?.. Thanks..
@koogs
I don't think we can change the damping with drag handler.. Is it possible? It could be a perfect solution. Could you please give an example how to do it?
In the peasy source there is setLeftDragHandler, and two others for right and centre.
this is initially set to
which is defined immeditely above that as
which is defined on line 332
https://github.com/jdf/peasycam/blob/master/src/peasy/PeasyCam.java#L332
so just copy that code, change it to what you want and call setLeftDragHandler with your new code. no need to recompile peasycam.
i would guess it'd just be a case of returning mouseRotate(dx, dy) without the handleDrag wrapper. (DragHandler is just an interface, contains no code)
@koogs -- very nice -- I didn't realize that the
set*DragHandler
methods were there.i've never used them tbh 8)
I think that I am missing something.
I have tried to use setLeftDragHandler, but I don't know if you mean that..
Here is the code:
But it did not change anything..
mouseRotate(dx, dy); uses RotateX, RotateY, RotateZ which are difined as damped rotations:
So what am I doing wrong?
ok, problems.
the rotateX, rotateY and rotateZ members are dampedActions and private final and any drag handler only calls impulse() on those (which is a velocity rather than an absolute, and the damping is done there, not in the drag handler)
you might be able to write a drag handler that calls cam.rotateX etc to set the rotation (absolute position rather than a velocity). but i've had no luck so far.
ok, this is better. not sure it's what you want though.
koogs thank you very much for the code.. I didn't think to make it with drag handlers.. It works like I want, without damping..
I didn't make any MyHandler.jave, but put your class in the code.. I have used both damping movement with left drag and base mouse movement with right drag to show the difference..
Here is the end code:
Now I have a little question more..
If I move the mouse, I want that the object rotates more.. It means that I would like to change the rotation angle/ mouse movement ratio.
How can I make it in this class??
(i put the handler into a java class because processing compiler was complaining about calling rotateX, which i guess was due to the fact there's a member called rotateX and a method called rotateX(). it shouldn't, really, but it was. after moving it to a java class it stopped complaining)
making it rotate faster might just be a case of adding a multiplier to each of the 4 rotation angles. and / or multiplying the distance moved by the mouse, maybe by modifying dx and dy (which i'm guessing are the delta movements) right at the start of the method. but i can't check that here / now.
OK, I did it. I just made a multiplier (rmult), to control rotation angle..
@koogs Thank you very much for your ideas!..