I'd like to rotate an ImageView with a different pivot in Android Studio.
This is how it rotates when it's -45 degree by default pivot(centre).
So, when we do animation, it works in a fixed image area such as a fan or a windmill.
But what I want to do is like this.
The red point is the new pivot that I want. In this way, it will take over 4 times bigger areas if it rotates 360 degrees.
How can I implement this?
Related
I am using hmmer.js.
Trying to rotate image on android by multi touch.
I just want to increase or decrease the rotation angle of image.
In that case I need to have events for clock wise and anticlock wise.
Can anyone tell me, how to recognize that is element being rotated in clock wise or anti clock wise?
The event object given by Hammer contains a rotation property which is the angle of rotation in degrees. It ranges from -180 to 180, and is negative when the rotation is anti-clockwise and positive when it's clockwise.
You can test for yourself in this plunker: https://plnkr.co/edit/uVCYoytxc12llL74oyOI?p=preview
How can I determine in which direction and how far I have to rotate the image? I use Android Canvas to draw the line and the arrow image.
canvas.drawBitmap(arrow_direction, leftpos,rightpos,null);
The image is always shown as it is. The image shows clearly that I have to rotate it 90 degree to the left.
I know I can rotate the image with
Matrix rotator = new Matrix();
rotator.reset();
rotator.postRotate(degree);
But I don't know how to calculate the value for degree to rotate the arrow? I know only the coordinates of the two red points. So I think it might be possible to calculate it with this two points, but I don't know how.
In another way how can determine on which side of the image is the end point of the line? In the example it is on the right side, therefore I know that I have to rotate the image -90 degree.
I am trying to create a game like Jigsaw Puzzle. I am using a class that extends View and in its draw method, I am drawing different bitmap pieces. When user tap a bitmap, I rotates that bitmap by 90 degree angle. Its working perfectly. But user combines some bitmap pieces and then rotate the group, the bitmaps rotate around their center point destroying the group structure.
My question is how to rotate a set of bitmaps around a common pivot point so that when a group of bitmaps rotate, it retains its shape structure?
I am assuming that you have each of the pieces center-weighted which is causing your problem.
On possibility is to have the background be a center weighted object or to look at background and declare the center as the point of rotation.
Then, calculate the approximate box size of each jigsaw piece (this could be dynamic based on if you are using Zoom). to figure out its placement on the screen as bitmap objects in Draw().
Now, imagine a line being draw from the center to the edge of the screen being rotated to get your angle.
So, based on this new information, you would need to calculate your new angle for each center weighted object (jigsaw piece) based off of the angle set by the center of the screen rotation. Each piece would have a different angle of rotation on its axis because of the new line or angle of rotation set by the center of the screen.
This is more of an algorithm/calculation than programming, more specifics on your issue would help.
In my game, I have a 4x4 grid of TextViews, each displaying one letter, arranged in a TableLayout.
I'd like to implement a "rotate 90 degrees clockwise" feature, and I'd like the grid to rotate, but I want the letters to stay upright.
It could be achieved by applying a 0 to 90 degree rotation on the TableLayout and another 0 to -90 degrees animation on each TextView. Then it will appear as if the letters are still oriented upwards, because the grid will be rotated from 0 to 90 degrees, and the TextViews' animation will cancel the rotation, as it's the exact opposite.
It works, but the animation is choppy on low-end devices and that doesn't look good. Is there something I can do to improve the animation performance, as I'm animating 17 views at once now. Is there some trick I might employ, like disabling antialiasing or setting lower color depth for the duration of animation (on slower devices)? Or is there some way to glue the 16 TextViews together and let Android do only one animation on this glued view?
I have a sphere that I am translating into the middle of, then I would like to be able look around in that spehere.
I notice that rotation works around the y axis perfectly, and rotation works around the x axis great at the initial viewing angle, but when I rotate 90 right on the y axis, and then try to rotate again on the x axis, the sphere rotates in a rolling fashion instead of a looking up and down.
This behavior leads me to believe that the axis do not change when you rotate. Do I need to have a special call to reset the axis once my rotation is complete?
What you are describing sounds like gimbal lock.
The relevant wikipedia article has some solutions, e.g. quaternions.