-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check current rotation of an object #22
Comments
here is how you do that with an object named 'box', for example: |
For any kind of web animation, I generally advise against animating incrementally like that. i.e. setting the state based on the previous state - unless your state is controlled by something like user input or a physics engine. A more reliable approach is to simply write an expression that runs on every frame and takes the current time as an input. One very reliable way to have something wave or oscillate back and forth is to use a sine or cosine function. Like this: var period = Math.PI * 2 / 5000; // one full cycle every 5000 milliseconds
var range = 60 * Math.PI / 180; // max rotation of 60 degrees off center
box.rotation.x = Math.cos(time * period) * range; Because it's a trigonometric wave, it'll slow down as it approaches the edge of the rotation and then speed up again as it goes back towards the center. You can try other wave functions, like a triangle wave:
But @skompc is not wrong; that should be the correct way to check the local rotation of the object. |
Thanks alot @skompc and @brianchirls! I will try this. |
Hi again, Here is how I have set up the image that is giving me problems, I use a container to get it to rotate around the top of the image instead of the center.
My VR.animate function looks like this:
Thanks |
Yeah, that function provides Let us know how it goes and I'd love it if you'd share the results when you're done. |
@simonhultgren Euler rotations are weird. Try adding this:
Also, I don't think it's entirely necessary to use empty container objects. You should be able to just manipulate the images directly. |
Thanks @brianchirls , that did the trick! About the container, I use that to offset the rotation to occur along the top of the image instead of center. Is there some way in java script to move the origin of the rotation within the image instead? (I'm usually not using javascript so sorry if this is a really basic question). Anyway, we are using your framework to put together a very brief presentation of our project, we thought using this is better than doing a traditional power point presentation. Simon |
@simonhultgren You know, you're right. There are ways to offset the rotation without a parent object, but honestly this way is easier. I'm very glad to see you putting together a real, live VR piece instead of a PDF deck. Excellent. |
Hi Brian!
Trying to make an object 'flutter in the wind' by rotating it back and forth along x-axis. Right now I count amount of calls to rotateX and swap direction of the rotation based on that. But I noticed it is not consistent and will instead need to use the actual rotation of the object as deciding factor for when to swap direction. So my question is how I read out the current rotation of the object.
Thanks
Simon
The text was updated successfully, but these errors were encountered: