2

I have a series of SCNPlane-type objects set to revolve around a central SCNPlane with width and height set to 0. When loading the view in my app, I get the below, which shows that my planes are being loaded correctly. Rotating them left to right with my cursor works, too. It looks like this:

enter image description here

However, if my cursor moves in the y-direction, the view ends up shifting so that the display is shown from another angle. Basically, the view could end up looking like this:

enter image description here

I don't want that to happen; I want the first image to be what I want. When I move the cursor, it should move either left or right, and not up or down.

Here is what I have tried doing:

  • setting the pivot to SCNMatrix4MakeRotation(Float(CGFloat(M_PI_2)), 0, 0, 0)
  • setting the rotation to SCNVector4(1, 0, 1, Float(CGFloat(M_PI_2))
  • setting the orientation to SCNQuaternion(0, 0, 0, Float(CGFloat(M_PI_2))
  • using the SCNLookAtConstraint function to center all the planes around a central coordinate and face outward
  • using the SCNTransformConstraint function with a block that takes in the node and a matrix (newMatrix = incomingMatrix) variable. If it detects that the position of an object has a value of y, then newMatrix.m42 = 0. newMatrix is returned either way.

None of the above have fixed my issue. Is it even possible for me to restrict the camera to the x and z-axes only?

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • 1
    This sounds like you're using the built-in camera control (`SCNView` `allowsCameraControl`). Is that the case? If so, don't. Add your own camera to the scene hierarchy, and control its position directly (as in [this answer](http://stackoverflow.com/a/25674762/957768)). Then, when you're mapping user input to camera motion, move the node containing the camera only in the axis you want it to move in. – rickster Dec 29 '15 at 00:06
  • @rickster I found that answer you posted before I asked the question. My concern was figuring out how to implement the input. I can't find any good resources on arcball rotation _in Swift_, and I'm not sure how I'd be able to do the gesture mapping. I think the second one would be easier in my case; would you be able to expand on the explanation? The math is still confusing to me. – William Putnam Dec 29 '15 at 18:44
  • 1. If you're looking for help with an Apple API and you're ignoring ObjC-based resources, you're doing yourself a disservice. The most important part of the answer to any "how do I do X with SceneKit" question will be in what SceneKit APIs to call and how to architect a solution around them — language differences in the actual code are minor details. It behooves any new Swift programmer to learn to *read* ObjC (if not write it, and only well enough to grok what a program is doing and translate to Swift). – rickster Dec 30 '15 at 00:19
  • 2. There's not much math there. Put your camera on a node such that rotating the node orbits the camera, as in that answer. Then when the cursor/touch moves left, rotate the node one way, and when it moves right rotate the node the other way. – rickster Dec 30 '15 at 00:23

1 Answers1

0

It took me a few days, but I finally figured out the fix.

I implemented the camera node as rickster suggested and set allowsCameraControl to false. I then implemented a UIPanGestureRecognizer and tied it to a function, as suggested here, which was also based on rickster's answer.

It now does what I want it to. Thanks a lot, everybody!

Community
  • 1
  • 1