Kusal Shrestha
Kusal Shrestha

Reputation: 1673

How to draw infinitely long line in SCENEKIT?

I want to draw axes as that in SketchUp which are infinitely long. I already drew lines that are of fixed length but I want it infinitely long.

Upvotes: 0

Views: 434

Answers (2)

Hal Mueller
Hal Mueller

Reputation: 7665

Fake it with fixed length lines that extend from beyond the camera's view (called the frustum), through it, and then beyond it again.

You can create beginning and ending SCNNode instances for each axis. Then every time the camera changes its view, call

func isNodeInsideFrustum(_ node: SCNNode,
     withPointOfView pointOfView: SCNNode) -> Bool

on each of your 6 endpoints. If an endpoint is within the frustum, move it farther out until it's not.

Methods in the SCNSceneRendererDelegate protocol might be helpful to you.

Upvotes: 1

Jozey
Jozey

Reputation: 1740

Depending on the context of what you mean, you check for when the size of the line is about to cross some x or y axis in the screen. You can detect the size of the screen by using size.frame. Alternatively, you can use CGRectGetMidX, CGRectGetMidY, etc.

For example, I would do something like this:

var x = CGRectGetMaxX(self.frame)
//Where y is the max size of the line you have
if x <= y {
    //Code where you make the line shape extend or add another line over it to make it look continous
}

Upvotes: 1

Related Questions