前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SceneKit-绘制直线

SceneKit-绘制直线

作者头像
酷走天涯
发布2019-06-15 11:11:00
1K0
发布2019-06-15 11:11:00
举报

// private func lineBetweenNodeA(beginPosition: SCNVector3, endPosition: SCNVector3) -> SCNNode { // let positions: [Float32] = [beginPosition.x, beginPosition.y, beginPosition.z, endPosition.x, endPosition.y, endPosition.z] // let positionData = NSData(bytes: positions, length: MemoryLayout<Float32>.size*positions.count) // let indices: [Int32] = [0, 1] // let indexData = NSData(bytes: indices, length: MemoryLayout<Int32>.size * indices.count) // let source = SCNGeometrySource(data: positionData as Data, semantic: SCNGeometrySource.Semantic.vertex, vectorCount: indices.count, usesFloatComponents: true, componentsPerVector: 3, bytesPerComponent: MemoryLayout<Float32>.size, dataOffset: 0, dataStride: MemoryLayout<Float32>.size * 3) // let element = SCNGeometryElement(data: indexData as Data, primitiveType: SCNGeometryPrimitiveType.line, primitiveCount: indices.count, bytesPerIndex: MemoryLayout<Int32>.size) // glLineWidth(10) // let line = SCNGeometry(sources: [source], elements: [element]) // return SCNNode(geometry: line) // } // // func distance(startPosition:SCNVector3,endPosition:SCNVector3) -> CGFloat{ // let x1 = startPosition.x // let y1 = startPosition.y // let z1 = startPosition.z // let x2 = endPosition.x // let y2 = endPosition.y // let z2 = endPosition.z // let r = sqrt(pow(x2-x1, 2) + pow(y2-y1, 2) + pow(z1-z2, 2)) // return CGFloat(r) // }

// func calculateRotationY(beginPosition:SCNVector3,endPosition:SCNVector3) -> Float{ // var θ:Float = 0.0 // let x = endPosition.x // let z = endPosition.z // if z > 0 && x > 0{ // θ = atan(z/x) // }else if z > 0 && x < 0 { // θ = atan(z/x) + Float.pi // }else if z < 0 && x > 0{ // θ = 2*Float.pi + atan(z/x) // }else if z < 0 && x < 0{ // θ = Float.pi + atan(z/x) // }else if x == 0 { // if z > 0 { // θ = 0 // }else if z < 0 { // θ = Float.pi // }else if z == 0 { // θ = 0 // } // } // return θ // }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.09.19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档