We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Answers
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?
Constant PI has already lost precision when it was converted from
double
tofloat
: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 isdouble
.For example:
PI + Math.PI
results typedouble
, b/c the 2nd operand isdouble
.Same for
Math.E + 'A'
, which also evals todouble
. :-Brunnable example, shows the same problem
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 todouble
.If it's the case it's desirable to pass
double
's full precision, we should use Math'sdouble
PI, not PConstants'sfloat
PI: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!