tracking camera's position and rotation - ios

I have allowsCameraControl property set to true. I need my camera to tell me what it's position and rotation is, while I move it around with pinch and pan gestures so I can later update my camera to that position. Is there some function that is called every rendering moment so I can put println: statement in it? The other option I could think was to set a didSet statement at camera's position and rotation property but I have no idea how to do that if I'm not the one defining the property in the first place.

Found a way around it using custom buttons(moveLeft,moveRight,rotateLeft etc..) to move the camera(and report current position) around 3D space. Works great. Can't tell if mnuages's suggestion works, but it looks allright.

you can use delegation methods such as SCNSceneRendererDelegate's -renderer:didRenderScene:atTime: and you can access the "free" camera by using the view's pointOfView.

Related

SceneKit Calculate Viewable Bounds?

so as per title I am trying to figure out if there is a good way to calculate the bounds of a scene as the usual frame/bounds properties don't really work in the context.
I basically need a way to check if an object has moved out of the viewable screen based on the camera settings of xFov/yFov/zNear/zFar. So far I haven't really found a good way to do so. Have I overlooked any API methods here or does this need to be calculated manually?
I hope I have made sense here if not please tell me and I will clarify further.
SCNView conforms to SCNSceneRenderer which in turn has a method called isNodeInsideFrustum:withPointOfView: which is what you are looking for. According to the documentation, it returns:
YES if the bounding box of the tested node intersects the view frustum defined by the pointOfView node; otherwise, NO.
Using it looks something like this:
BOOL isInside = [sceneView isNodeInsideFrustum:nodeToTest
withPointOfView:sceneView.pointOfView];
if (!isInside) {
// the bounding box of nodeToTest is not in the viewport ...
}

UIView perpetual linear animation with collision detection

I'm trying to make a circular UIView animate in a particular direction until it collides with the borders of the view (which is full screen, so basically the borders of the device), at which point it will reflect off it and continue on its way infinitely. However, I'm not really sure how to pose my question, so I'm having trouble finding any information on it. I already have the view, the direction it will move in, and its velocity. I'm just not sure how to handle an animation like that.
Any advice is much appreciated! Thanks!
Use a CADisplayLink to continuously update the position of the view, synced with the refresh rate of the screen. The update method that that display link triggers will take into account the current x and y velocity of the view and update the frame based on it. If at ever point the x- or y-coordinate goes under or over a limit (0 or screen width/height), reverse the appropriate velocity value and recalculate the position.

scale around certain point over time SpriteKit

I have a SpriteKit Scene in which I want to have the effect as if a camera zoom and scale. Does anyone know of any libraries or some easy methods of doing this?
It was very easy to do in other 2D engines but does not seem simple.
I was thinking of doing it from the app delegate, and using the window to zoom since my character does stay around the same position.
The desired effect I would like to accomplish is like that of the start of an Angry Bird level when the camera pans into the level and then the launch doc.
http://www.youtube.com/watch?v=_iQbZ3KNGWQ This is an example of the camera zoom and pans I am talking about.
Thanks for the help.
If you add an SKNode to the SKScene, and make your scene content children of that node instead of direct children of the scene, then you can zoom and pan all of the contained content just by adjusting the xScale, yScale and position properties of the added node. (Any content you did not want scrolled e.g. scores or whatever could then be added to a different SKNode or added directly to the scene).
The adjustment could be done by overriding one of update:, didEvaluateActions, or didSimulatePhysics in your SKScene subclass. The choice would depend on if you are just moving your character around by yourself in update:, or if it also gets moved around by running SKActions or by simulated physics.

Putting hard bounds on an animating view in iOS

I've been exploring iOS animations and I'm trying to find out if there is a simple way to restrict animation movement to within a certain area. For example, lets say you are using a pan gesture recognizer to drag a UIView around the screen. Is there a simple way to enforce that the frame of the UIView does not move beyond a specified location?
The way i've currently been approaching it is to take the UIView, calculate the location of the edges, and within my handlePan method, simply return (ie don't adjust the center point) if the frame is touching the boundary. Is there a more elegant way to do this? Even if only along a single axis?
Thanks!
I actually am doing that in one project and basically well, I am using the "non elegant" way. I have a set of coordinates "boundaries" from which the view I am dragging should not pass. Although there better ways to do this than others. For instance for a smoother experience:
Compare the X axis independently for the Y axis. What I was doing in the beginning was to compare the X and the Y in the same if sentence.
Extra: Check this project to get some ideas.

LocationToViewportPoint issue

I have an issue with this where LocationToViewportPoint for Bing Maps is calculating based on current viewport of the map as opposed to calculating the target viewport point.
The reason is because if the user is panning/zooming the map, this method will return inconsistent results.
I've tried reflecting this method but to no avail, does anyone have any more insight on how to solve this problem?
Solved this:
What I had to do was turn off the AnimationLevel for (panning/zooming) and explicitly SetView to the target bounding rectangle and then performed whatever calculations I needed to calculate the Map's new center point.
I then changed the AnimationLevel back on and then setting the new Map's center point for the map to zoom/pan to.
Apparently the LocationToViewportPoint had a dependency on AnimationLevel and "current" view.

Resources