iPhone - detecting circle movements - iphone

I have an area where the user can draw using a finger. This area contains an object that I want the user to be able to rotate it clockwise or anti-clockwise. My idea is to offer the user the whole screen to control the object. I mean, if the user starts to describe clock wise finger movements in a circle pattern, the object will rotate on that direction. If the movements are anti-clockwise the object will rotate the other direction.
So, the idea is to detect if the finger is describing circle movements, clockwise or anti-clockwise and the amount of angle. This has to be real-time, I mean, as far as the user is rotating the finger object is rotating.
I have seen apps doing something like that, where the user draws a shape and boom, the app replaces the clunky shape drawn with a pretty one. In essence the app detected that a circle, a triangle, etc., was drawn and replace that gesture with a real pretty shape.
How do I do this kind of stuff? I am just interested in circle movements.
Can you guys point me the direction?
thanks.

Check out the "hough transform for circle detection". Here is a good blog post to start with:

Related

How do I change the color of a circular sector of a 2D stage in Unity?

I am developing a game where a rotating sprite can shine a line onto a black colored and circular arena. I want a circular sector of a certain angle to become white colored, depending on the sprite's orientation.
For example, if the sprite is at 90 degrees, the stage should look like this
What are the most efficient methods to achieve this?
Some details about the game that may be important to know:
The sprite rotates at the center of the stage only and is not mobile.
I'll likely make the arena a n-sided polygon, and the circular sectors will likely be triangular sectors. Then, a circle might overlay this polygon for make the arena look circular. (Not sure how I will be implementing this yet).
One idea I've considered is using cartesian coordinates to create triangles in canvas.
One difficulty I am having conceptually is determining the direction of my rotating sprite.

How can I rotate an object based on an angle?

I am working in Unity3D and I was wondering how I would rotate a cube based on the angle between the cube and the mouse position. With that I don't mean the mouse position in world space but in pixels.
Here are some pages that'll lead you to your answer:
Input.mousePosition This also includes an example of how to turn screen coordinates into a ray in world coordinates. If you know how far away from the camera you want your point, check out ScreenToWorldPoint for a point instead of a ray.
transform.Rotate To perform a rotation.
The rest of your question is kinda vague--rotating "based on" the angle between cube and mouse position could mean a lot of things. You shouldn't need much more information than this though!

How to make a perfect pinch zoom (Unity 3D)

I am searching for a solution to how to make a perfect pinch zoom in Unity by moving the camera along the forward:
Set up:
Horizontal plane centred at the origin with all Game objects.
Perspective camera with FOV 10, offset at (10,10,10) looking down at a 45 degrees angle, so that it looks at the origin (there is also a rotation of 45 degrees around the axis pointing up, to achieve this).
What I need:
When I place two fingers on the screen I am touching two GameObjects with them - so the screen coordinates under the fingers correspond to certain world coordinates. When I make a pinch movement (with moving two fingers or only one) I want the new screen coordinates to correspond to the same world coordinates that were under the fingers at the beginning of the whole interaction.
So to simplify even further - whenever I touch the screen with two fingers, I want the world coordinates corresponding to the screen coordinates under my fingers to always stay under the fingers (allowing a very small margin of error).
An example of this perfect zoom for which I am looking for you can see in the mobile game Boom Beach from Supercell.
I already tried to move the camera along its forward vector and to reposition it and I get pretty good results, but pretty much always the GameObjects underneath ‘slip’ away from under my fingers, that is at some points are no longer underneath them. It would be great if there was a mathematical solution to this, but if it’s necessary to compute the answer (through some search for example) then this is totally fine.
If the setup/scenario is not clear, I could provide some sketches to clarify it a bit more.
Hope someone can help me! :)
I would set up a system that detects when the user is zooming in and out if you are using GameObjects to pinpoint where the fingers are that is easy to do with Vector3.distance. After that, I would make a function that moves the camera closer to your desired zoom level with Vector3.MoveTowards(camera position, desired position, the speed of movement) where I would set "speed of movement" as a mathf.sqrt(vector3.distance(Camera position, Desired position));
as for the "desired position" I would set that Vector3(position) as a fraction of a line between two game objects that represent your maximum and minimum zoom level.
EDIT: with that, you should have a very nice camera system

How to make Unity3d move objects on a table?

I am working on a tabletop game that user controls using accelerometer in the phone. It is pretty similar to Labyrinth on iOS.
The scene contains a tabletop created using planes and cubes, and a sphere as a ball. As it works in Labyrinth game, on tilting phone ball should drop to the tilted side, while the camera stays centered to table. I am trying to do similar thing where user tilts the phone, and objects on table move to tilted side.
Currently, I add the x and z component to Physics.gravity on tilt. Sadly, this change in gravity does not affect the ball which stays put on the table. Use gravity is selected for the ball, and it drop down from height to the tabletop initially and then comes to halt. After the initial drop, ball does not react to any gravity change.
I have also tried rotating the whole table, but using transform.rotate does not work either. The table rotates perfectly, alongwith the camera, but the ball stays put hanging in the air. So, currently I am out of my depth about the issue.
Is there any other way to allow tilt action registered, so that ball moves to the tilted direction? I cannot use addforce function, as there are multiple objects which need to react to tilt, and it will be difficult to keep track of that many addforce calls. How else can I get it working?
See this post for some related information.
As for why your sphere is sticking to the table, can I assume your sphere has a rigidbody? If so, you need need to wake it up:
if (rigidbody.IsSleeping())rigidbody.WakeUp();
Ideally you would make that call only after detecting a change in orientation/gravity, not every frame.

How do I detect which direction a UIImageview is animating?

What is the best way to detect the direction of a uiimageview?
I want to detect when a uiimageview is 'falling' - this is because it follows an arc animation for jumping purposes, i only want to detect when it is 'falling' and intersecting a floor, rather than when it jumps and intersects the floor.
I'm guessing there is no built in method to do this.
Thanks in advance!
The best thing to do, I found, was to draw a path and test it for collision with any above 'floors' or platforms. Then if it does collide, draw another path with an end point matching the y position of the collided platform.