jdf / peasycam Goto Github PK
View Code? Open in Web Editor NEWDead-simple mouse-driven camera for Processing
Home Page: http://MrFeinberg.com/peasycam/
License: Apache License 2.0
Dead-simple mouse-driven camera for Processing
Home Page: http://MrFeinberg.com/peasycam/
License: Apache License 2.0
Hi! Peasycam in Processing 2.2.1 is giving me this error:
UnsupportedClassVersionError: A library is using code compiled with an unsupported version of Java.
This version of Processing only supports libraries and JAR files compiled
for Java 1.6 or earlier. A library used by this sketch was compiled for
Java 1.7 or later, and needs to be recompiled to be compatible with Java 1.6.
I tried changing the Java versions but no results...
Hey Folks,
I downloaded the new 2.0 Beta 4 this morning on my OSX Lion Mac and realized there is a problem with the peasycam library (peasycam v105). The basic Hello Peasy example won't react to any mouse interaction. Any ideas what could cause this?
Hello,
I wanted to have an axis gizmo to represent the camera angle, but I'm having huge problems, cause the rotation values don't use shortest way.
Any idea how this could be fixed ?
pushMatrix();
translate(width/2, 50);
scale(3);
rotateX((cam.getRotations()[0])*-1);
rotateY((cam.getRotations()[1])*-1);
rotateZ((cam.getRotations()[2])*-1);
shape(axis);
popMatrix();
The following line is used to calculate the distance on zoom:
private void mouseZoom(final double delta) {
safeSetDistance(distance + delta * Math.log1p(distance));
}
So, when the distance is 0
and the minimumDistance is also 0
or lower you cant zoom out anymore. Also minimumDistance lower then 0
will cause distance to be NaN
in some cases.
I could really use a "lookThrough" feature that would maintain the lookAt, but position the camera to look through a particular vector by rotating the camera (with a animation time of course). I'm using peasycam in a sketch of the Earth and I've plotted points on it for particular locations based on my data. I'm adding a menu of the particular locations, and when the user clicks on the menu item (like France), I'd like the Camera to rotate the correct location given the particular x,y,z location of France on the sphere. So the center of the Earth is my lookAt, but I need something like a lookThrough x,y,z.
Thanks Jon, this library is the best!
When I download the Peasycam library through the contribution manager on Processing 2.2.1 I get the following error.
java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: peasy/PeasyCam : Unsupported major.minor version 52.0
It looks like the current version of the library doesn't run on OSX 10.9.2 with Processing 2.1.1.
java.lang.NoSuchMethodError: javax.media.opengl.GLDrawableFactory.initSingleton()V
at javax.media.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1573)
at javax.media.opengl.GLProfile.access$100(GLProfile.java:76)
at javax.media.opengl.GLProfile$1.run(GLProfile.java:155)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:123)
at javax.media.opengl.GLProfile.getProfileMap(GLProfile.java:2070)
at javax.media.opengl.GLProfile.get(GLProfile.java:906)
at javax.media.opengl.GLProfile.getGL2ES1(GLProfile.java:797)
at processing.opengl.PJOGL.initSurface(PJOGL.java:250)
at processing.opengl.PGraphicsOpenGL.initPrimary(PGraphicsOpenGL.java:6244)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1625)
at processing.core.PApplet.run(PApplet.java:2177)
at java.lang.Thread.run(Thread.java:744)
https://mrfeinberg.com/peasycam/ seems to be down.
importing through processing 4 doesn't show up
importing through processing 2 doesn't work
there is no build on github
and looking for "peasycam.jar" doesn't show any conclusive result.
The only way to get the library currently would be to build it from the github source.
Which honestly I and probably many others don't know how to do.
Would you consider releasing a ready to download build on github ? To provide an additionnal mirror in case the website goes down ?
I feel like this is a silly question, but how I do I install this? I used to use the version from the zipfile on http://mrfeinberg.com/peasycam/, but I'm using processing 2.0 now. I thought I could just clone this repository into sketchbook/libraries/, but I was wrong. Any pointers?
Everything works great except if you resize the window. When you resize the window, it doesn't update the viewport width and height. This causes an issue when writing a HUD that is resizable based on window size. This isn't a hard fix but I don't know about for fixing in PeasyCam exactly.
Running the following:
OS: Windows 7 Professional 32 bit
Processing Version: 3.5.4
Processing Mode: java
Here is an example showing the issue as well as the fix. It opens with the bug and then if you resize you will see what the bug does. Then just press the "f" to apply or remove the fix.
import peasy.*;
PeasyCam camera;
int w = 0, h = 0;
boolean fixApplied = false;
void setup() {
size(600, 600, P3D);
surface.setResizable(true);
this.camera = new PeasyCam(this, 500);
registerMethod("pre", this);
}
void pre() {
// HUD Fix... When fix is applied and width or height has changed
if (this.fixApplied && (this.w != this.width || this.h != this.height)) {
this.w = this.width;
this.h = this.height;
this.camera.setViewport(0, 0, this.w, this.h);
this.camera.reset();
}
}
void draw() {
background(100);
fill(255);
box(10);
// Draw GUI
this.camera.beginHUD();
// Hardcode fix for hud not resizing correctly (old) new way is to set viewport ourselves
//ortho(0, width, -height, 0, -Float.MAX_VALUE, +Float.MAX_VALUE);
// Darken Game
fill(25, 25, 25, 180);
stroke(0);
strokeWeight(1.5);
rectMode(RADIUS);
rect(width / 2, height / 2, width * 0.375, height * 0.375, max(width, height) / 30);
// Draw HUD
textSize(21);
fill(180, 180, 180);
text("GUI", width * 0.125 + 20, height * 0.125 + 30);
// TODO
this.camera.endHUD();
}
void keyPressed() {
if (key == 'f')
this.fixApplied = !this.fixApplied;
}
I really like how PeasyCam works - especially with the double-clicking returning you to the default position. The only thing I'm missing is setting this default position of PeasyCam programmatically. So far, on this issue I've found:
How to change PeasyCam position - Processing Forum
PeasyCam is meant to provide intuitive mouse-driven camera movement, and not programmatic control. There are a few excellent libraries for non-interactive camera control.
3d - Rotating camera around object axis with Peasycam - Stack Overflow
Peasycam is not well-suited to programmatic control. If you want to manipulate the view yourself, you'd be better off with the excellent Proscene or OCD libraries.
However, looking at the code, I notice peasycam/src/peasy/CameraState.java
has:
final Rotation rotation;
final Vector3D center;
final double distance;
I'm not sure if the center
refers to the camera position (cannot tell, because printing it fails the compilation with "The field CameraState.center is not visible
"; and I couldn't really test with a new class, because of Is javac supposed to be included with Processing 2* or not? · Issue #2929 · processing/processing · GitHub), but if it does, then all that is needed is to make these properties public instead of final; then I could in principle do (pseudocode):
void setup(){
size(640, 480, OPENGL);
cam = new PeasyCam(this, 60);
CameraState cstate = cam.getState();
cstate.center = new Vector3D(10, 20, 30); // set new position?
cam.setState(cstate);
cam.lookAt(0,0,0);
cam.setDefaultPosition(); // new API
}
... and then, if something like cam.setDefaultPosition()
is added to the API, I could "memorize" the new position (and rotation, as per the lookAt()
) as the default, to which the PeasyCam would return upon doubleclick.
However, I'm primarily interested in setting the position programatically - I can somewhat do it with .pan(x,y)
(in the x/y plane normal to the camera at start, I guess); but if I do lookAt()
after it, the position seemingly gets reset. Is there a way I can do it with the current API? If not, what are the chances for changes to the current API, so that something like the above pseudocode becomes possible?
In functions like getLookAt()
, getRotations
and getPosition()
return a float[]
array. It would be much more useful if it returned a PVector
.
Hello!
The library is non-functional under Linux as the jar file is called PeasyCam.jar instead of peasycam.jar. Fork it and fix... I know, but might be simpler to just rename the jar on the main branch.
best
Matthew
Hi!
Processing 2.x / 3.x for desktop computers has an ide with a library manager, but APDE (android processing environment) relies on ZIP files for the user to install libraries. While the user can download the source, from github, compile it and install it in his/her phone, having a Zipfile build for 2.x / 3.x would be great.
Yours,
José.
I realize there hasn't been a peasycam release in about five years, but! If you feel like blowing the dust off the code...
add_library('peasycam')
def setup():
size(800, 600)
def draw():
pass
yields
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
at jycessing.LibraryImporter.addJarToClassLoader(LibraryImporter.java:315)
at jycessing.LibraryImporter.recursivelyAddJarsToClasspath(LibraryImporter.java:164)
at jycessing.LibraryImporter.addLibrary(LibraryImporter.java:140)
at jycessing.LibraryImporter$1.__call__(LibraryImporter.java:82)
at org.python.core.PyObject.__call__(PyObject.java:480)
at org.python.core.PyObject.__call__(PyObject.java:484)
at org.python.pycode._pyx117.f$0(QuadRendering.pyde:1)
at org.python.pycode._pyx117.call_function(QuadRendering.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.pycode._pyx116.f$0(/var/folders/4x/9g74c86d7k1bzcqy50r_xdcc0000gn/T/QuadRendering9422620782247159764/QuadRendering.pyde:96)
at org.python.pycode._pyx116.call_function(/var/folders/4x/9g74c86d7k1bzcqy50r_xdcc0000gn/T/QuadRendering9422620782247159764/QuadRendering.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
at jycessing.PAppletJythonDriver.processSketch(PAppletJythonDriver.java:233)
at jycessing.PAppletJythonDriver.findSketchMethods(PAppletJythonDriver.java:613)
at jycessing.Runner.runSketchBlocking(Runner.java:399)
at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:112)
at java.base/java.lang.Thread.run(Thread.java:833)
The left/right/center mouse button constants used to select which handler to use omit the case where the dragging device isn't any of those, but is rather a touch screen or other such device. Adding a fourth fallback drag handler which doesn't require a particular mouseButton
value would probably fix this.
At the moment I am working on a multi-pass rendering in processing. There I have to use a new PGraphics3D
canvas and I can not use the default g
object. After the rendering and shading, I'm just going to "print" it on to the g
object again as texture:
cam.beginHUD();
image(canvas, 0, 0);
cam.endHUD();
Now I have the problem that things like peasycam do not work anymore because they are attached to the original g
and do not transform the camera matrix of my canvas.
So I tried to use the camera matrix of the original graphics and copy it to my canvas:
PGraphics3D p = (PGraphics3D)this.g;
canvas.camera = p.camera;
This did not work, maybe because peasycam is doing something special and it does not change the original camera matrix. So my next idea was to use the static apply
method from peasy cam. I had to copy the function out of the original code and make it public:
import peasy.org.apache.commons.math.geometry.Rotation;
import peasy.org.apache.commons.math.geometry.Vector3D;
Vector3D positionVec = new Vector3D(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
Vector3D rotationVec = new Vector3D(cam.getRotations()[0], cam.getRotations()[1], cam.getRotations()[2]);
apply(canvas, positionVec, new Rotation(rotationVec, 0), cam.getDistance());
Here the apply
method:
void apply(final PGraphics g, final Vector3D center, final Rotation rotation,
final double distance) {
final Vector3D pos = rotation.applyTo(Vector3D.plusK).scalarMultiply(distance).add(center);
final Vector3D rup = rotation.applyTo(Vector3D.plusJ);
g.camera((float)pos.getX(), (float)pos.getY(), (float)pos.getZ(), //
(float)center.getX(), (float)center.getY(), (float)center.getZ(), //
(float)rup.getX(), (float)rup.getY(), (float)rup.getZ());
}
There I always have a zero norm for rotation (Arithmetic Exception).
So my final idea was to just copy all the rotations and translation to my camera matrix:
canvas.beginCamera();
canvas.camera();
canvas.rotateX(cam.getRotations()[0]);
canvas.rotateY(cam.getRotations()[1]);
canvas.rotateZ(cam.getRotations()[2]);
canvas.translate(
cam.getPosition()[0],
cam.getPosition()[1],
cam.getPosition()[2]);
canvas.endCamera();
So now I could rotate my cube, but it was not accurate and I think there is something wrong with some axis.
I would like to ask if someone has done this before and if there is a simple method to do this?
Hi, as I tried to use postfx : https://github.com/cansik/processing-postfx/ with peasycam I got this bug :
As you can see, the original is displayed in the background, and the post fx render appears in the front, scaled down.
I tried to move the focus point of my peasycam object, but it doesn't fix the issue :/
a sketch which reproduce this bug :
import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam cam;
PostFX fx;
void setup(){
size(400,400,P3D);
cam=new PeasyCam(this, 800);
fx = new PostFX(this);
}
void draw(){
background(100);
pushMatrix();
translate(width/2,height/2);
rotateY(frameCount/17.0);
box(200);
popMatrix();
fx.render()
.bloom(0.5, 20, 40)
.compose();
}
regards
PeasyCam does not work with the new OpenGL2 of Processing.
Hi jdf,
I just installed Processing 2.2.1 and imported PeasyCam in a new Windows 10 computer.
Apparently Processing 2.2.1 runs java 1.7.0_40, and I get exactly the same message as in issue #24 when running scripts that work fine in my old computer:
java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: peasy/PeasyCam : Unsupported major.minor version 52.0
Would it be possible to have access to old PeasyCam versions compatible with Processing 2.2.1 runnig java 7?
Thanks,
F
Either I'm doing something wrong or null
can't be passed in to setWheelHandler()
like the documentation says. It appears that cam.setCenterDragHandler(null);
and cam.setRightDragHandler(null);
work as expected and documented. Any help, if I'm doing this wrong, would be appreciated. Thanks!
cam.setWheelHandler(null); // throws NullPointerException
cam.setWheelScale(0); // workaround
java.lang.NullPointerException
at peasy.PeasyCam$PeasyEventListener.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1408)
at processing.core.PApplet.handleMethods(PApplet.java:1610)
at processing.core.PApplet.handleMouseEvent(PApplet.java:2674)
at processing.core.PApplet.dequeueEvents(PApplet.java:2596)
at processing.core.PApplet.handleDraw(PApplet.java:2437)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
excellent library, just about everything I was looking for! I've gone through the docs and couldn't immediately find it: is it possible to always rotate around the origin point, even after the camera has been panned?
So Mac OS Lion set by default "Natural" scrolling, which flips the zoom. It would be easy enough to detect Mac OS < 10.7 uses normal and >= flips it, but you can turn this feature off. I have, love it on IOS, but it's annoying on the Mac. So I'm not sure if there is any way to detect this, but I thought I would mention it.
Side Note:
Also, was wondering if you ever had a chance to look at my changes (my fork). I've become dependent on many of them, so I'm really hoping they make it into the official version. One feature that I did add that I don't use, so I would be fine with removing it, would be the pan on edge screen. I think it's a cool feature, but it's not something I use personally, so I wouldn't cry about it if you choose not to include it. I know there is a balance between keeping it simple and adding new features.
hi everybody... i have a question, i want to map current mouse position to a position a camera view... the main goal is to let people drag things from a 2D canvas to the 3D space...
i would really thank you if you can give me any help...
@jdf and thanks for your wonderful library...
Feature request - add velocity damping for camera panning.
Figured I'd add this to your todo. ;-)
Hi Jonathan,
I'm currently using your library but I didn't find at yet how to set up correctly the camera.
I explain : I want to set up the cam wich Y axis stays vertical. I allready built my own cam here , with the Y axis allways vertical.
I didn't find how to do that with Peasycam.
Thanks for your answer !
Clément
(btw I try differents set up and apparently camera.setSuppressRollRotationMode() did nothing different to the free mode an my computer)
hello,
i was previously using code below to save and load camera states. i really do not remember where i got peasy from (git, zip download), imho it was repacked to get rid of that version warning (console says it's PeasyCam v2.0.0+, jar is built on 04.06.13)
my specs
java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
OS X 10.7.5
anyways, here's code i'm using
import peasy.*;
import java.io.Serializable;
import peasy.org.apache.commons.math.geometry.*;
//import peasy.org.apache.commons.math.geometry.Rotation;
//import peasy.org.apache.commons.math.geometry.RotationOrder;
//import peasy.org.apache.commons.math.geometry.Vector3D;
PeasyCam cam;
// init as usual
cam = new PeasyCam(this, 600);
// i am setting and saving camera states as follows
public void cameraStateSave() {
CameraState state = cam.getState(); // get a serializable settings object for current state
// i used (saved) these variables from the camera state
state.distance;
state.rotation.getQ0();
state.rotation.getQ1();
state.rotation.getQ2();
state.rotation.getQ3();
state.center.getX();
state.center.getY();
state.center.getZ();
}
public void cameraStateLoad(int animMillis) {
double inZoom = savedVal;
double[] inQ = new double[4];
inQ[0] = savedVal;
inQ[1] = savedVal;
inQ[2] = savedVal;
inQ[3] = savedVal;
Rotation inRotation = new Rotation(inQ[0], inQ[1], inQ[2], inQ[3], false);
double[] inCoord = new double[3];
inCoord[0] = savedVal;
inCoord[1] = savedVal;
inCoord[2] = savedVal;
Vector3D inVector3D = new Vector3D(inCoord[0], inCoord[1], inCoord[2]);
CameraState newState = new CameraState(
inRotation,
inVector3D,
inZoom);
cam.setState(newState, animMillis);
}
after upgrading to peasycam_201 i get error
the field CameraState.distance is not visible
before digging deeper
or rewriting this to use getRotations()
, setRotations()
, getDistance()
, setDistance()
…although while there is getPosition()
, don't see any method for setPosition()
so imho it is not possible with this approach
i wanted to ask - has there been any changes lately in how CameraState is retrieved and set?
thanks you for the great lib!
This is not necessarily a bug, but maybe just not mentioned in the documentation?
I'm trying to draw objects, apply a shader filter, then draw more objects. The effect of the shader spins around in a flat plane when moving the camera. How can I avoid having the filter effect move? I tried with state and with HUD...
Here an example (it needs blur.glsl from Examples > Topics > Shaders > BlurFilter)
import peasy.*;
PeasyCam cam;
PShader blur;
void setup() {
size(1000, 800, P3D);
cam = new PeasyCam(this, 500);
blur = loadShader("blur.glsl");
noFill();
stroke(255);
}
void draw() {
background(40);
for (int i=0; i<100; i++) {
pushMatrix();
rotateX(i*0.11);
rotateY(i*0.21);
translate(500, 0, 0);
box(20);
popMatrix();
}
cam.beginHUD();
rect(10,10,width-20,height-20);
filter(blur);
cam.endHUD();
box(200);
}
I need to change the target of camera, but don't work. Why?
cam.lookAt(target.x, target.y += 1.5, target.z);
println(target.x +","+ target.y +","+ target.z);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.