#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Peasy Cam rotation

edited June 2016

Hi, I'm trying to create a button that rotates my object perfectly 90 degrees to the left from it's initiate state.

I made a button that when it is triggered, it will execute the following code.

``````cam.reset(); // Resets the camera so that the object is in its initial state.
cam.rotateY(-PI/2); // cam.rotateX(-PI/2);
``````

However, every time I press the button, cam.reset() will be executed but not rotateX(). And when I execute rotateX() by itself, it works. Hence, I think that it is the cam.reset() that nullifies the rotateX() that comes after it.

Does anyone know a way to prevent this from happening? Or does anyone know how to reset the 3d object to its initial position without using cam.reset()?

Thank you so much, Jerry

Tagged:

• are you using a double? try using `(double)(PI / 2)` as the argument.

• also, what is your object? would you be able to tell if it had been rotated 90 degrees in Y?

• try using `(double)(PI / 2)` as the argument.

Constant PI has already lost precision when it was converted from `double` to `float`:

``````println(PI, Math.PI); // 3.1415927 3.141592653589793
println(HALF_PI, .5d * Math.PI); // 1.5707964 1.5707963267948966
exit();
``````
• i was more worried about the type than the precision. he's saying it doesn't work, not that it's slightly inaccurate.

• Java automatically coerces up all numerical types to `double` when at least 1 of the operands is `double`.

For example: `PI + Math.PI` results type `double`, b/c the 2nd operand is `double`.
Same for `Math.E + 'A'`, which also evals to `double`. :-B

• runnable example, shows the same problem

``````import peasy.*;

PeasyCam cam;

void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 200);
stroke(255, 0, 0);
strokeWeight(4);
fill(0, 255, 0);
}

void draw() {
background(0);
box(100, 100, 100);
}

void keyReleased() {
cam.reset();
cam.rotateX((double)(PI / 4.0));
}
``````

where's the double in -PI/2 ?

• replace the cam.rotate() with `cam.setRotations(0, HALF_PI, 0);` and that works. i think cam.rotate() works within dra() but not as an absolute, if you see what i mean. just a theory, which i'm testing now...

• yes, add `cam.rotateY(.02);` after line 15 and it'll sit there happily rotating.

not sure why it should work like this though.

• Alas... if PeasyCam's rotateX() method only accepts `double` as its argument, no matter which numerical datatype we pass to it, it's gonna be automatically coerced to `double`.

If it's the case it's desirable to pass `double`'s full precision, we should use Math's `double` PI, not PConstants's `float` PI:

``````cam.rotateX(Math.PI * .25d);
``````

Besides, Processing already got QUARTER_PI which is PI/4f btW: ;;)
https://Processing.org/reference/QUARTER_PI.html

• Hey, thank you guys for your advice! I tried out using changing the inputs into doubles. However that didn't work

• The object is a box(500);

• Hi Koogs, the set rotations thing works! Thank you so much!