I have configured Core Motion manager in order to access the rotation coordinates and use them to animate deviation, like in native compass application. So here is what I want to achieve:
It is this green line showing the deviation. I've tried simply to animate bezier's curve by setting it in
manager.startDeviceMotionUpdates(to: OperationQueue.current!, withHandler:)
method, but it didn't work - the animation was starting each time coordiantes was changing and filling the center with lines. I suppose that this animation should run on different thread, and motion manager should update only end point of bezier's curve. I have no idea how to do it. Any tips or examples would be appreciated!
Related
I wish to emulate this effect in Xcode with Swift. After some research I managed to find some articles about drawing smooth curves using a set of points .But I am still unclear about how I could to dynamically modify curves when the user touches/holds the screen.
Question :
I know how to make a smooth Bezier curve, but how can I add gesture recognizers such that by dragging the curve its shape changes.
I only need someone to point me in the right direction. Is there a guide or article in particular that could be useful?
Create transparent ControlPointView for every control point of the curve with a size of 50*50pt, so that users can easily tap them and drag.
Add a small image in the middle of every ControlPointView, so that users can see where the control point is located.
Add UIPanGestureRecognizer on every ControlPointView and handle it in view controller.
Use centers of control points to rebuild UIBezierPath every time gesture recognizer's state is changed.
when rotating a 3D-plot in Matlab one can only rotate completely, so full 360°, around the z-axis (azimuthal angle) but only from +/-90° around the x/y-axes (elevation angle). I know that this includes all possible views in a spherical coordinate system, yet, a customer of mine would like to have the same functionality like in Fiji (3D-Viewer) or similar 3D-Viewers, to rotate fully about the 360° around an arbitary axis.
As simple demo:
surf(peaks); rotate3d on
I thought of a handles listener with callback when the view changes and then adjusting the azimuthal and elevation angles accordingly to generate the feeling of a full rotation but maybe someone has a better and simpler idea :)
Cheers Mika
I found a possible solution:
One can enable the camera control toolbar and use the camorbit functionality which does exactly what it should. In my GUI I just enable/disable it via a custom toggle button in the toolbar like so
if strcmp(get(handles.uitoggletool5,'State'),'on') == 1
cameratoolbar('SetMode','orbit');
else
cameratoolbar('SetMode','nomode');
end
Im trying to figure out if there is a better way to draw a fading line then the method that I am currently using.
Currently to draw a fading line that can be moved around the screen I am using SKEmitterNodes. The SkEmitterNodes however are extremely CPU expensive. They have a birth rate of 300 to be able to maintain a thick line while being moved around the screen. Does anyone know of a better way to achieve this fading line drawing effect better?
The effect I am looking for is similar to the lines being drawn in Dark Echo. Here is a video. https://www.youtube.com/watch?v=tuOC8oTrFbM
Thanks,
Chris
If you are looking to fade a node's alpha property then you can use (SKAction *)fadeOutWithDuration:(NSTimeInterval)sec. This will gradually fade your node's alpha to zero in the specified time frame.
For proper memory management you should remove the node from parent if you no longer need it and the alpha has reached zero.
I need to show a view on which I need to animate a polygon using its vertices. The polygon should be touchable, thus fire an event once touched, and I need to be able to move its vertices using some animation procedure, once it has fired that event.
I need to have three polygons like that to form a 3D Cube.
The darkened area is the view (actually an image) on which I have the cube.
There are two steps in the process: drawing and event handling.
Drawing can be done with Quartz2D, by implementing a drawRect in a view, calculating the coordinates of the cube on screen, followed by creating and drawing the path, which works fine for solidly filled shapes. The alternative method uses an OpenGL view where you specify triangles.
At the event handling end, you can implement onTouchesBegan: and friends to get the location of the interaction, and possibly hitTest: to allow other views below it to handle subsequent events. The next thing you will need to decide is how accurate you want to be - you can define a box that roughly matches the cube and test that for touches. Most people will want to touch it somewhere in the middle anyway. For accurate testing, you need the screen coordinates, and test each triangle in each polygon to see if it contains the location. Google turned up a nice explanation on the maths needed for that. In the OpenGL case, you'll have to manually repeat the calculations performed by OpenGL to find out where on screen your polygons have ended up.
I want to bend a rod like image in response to user touches. The user should be able to change the curvature of the image using touches. How do you do this using Quartz? There is obviously no standard transform for this. I am having a tough time figuring the math for doing this.
You can’t do it using just an affine transform, which is by definition linear. You can draw the bar in many small chunks, slowly bending along the path, or use OpenGL to draw them along a tri-strip or quad-strip.