- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个场景设置,其中包含围绕对象旋转的 SCNCamera。
限制相机可以围绕物体实现的旋转范围的最佳方法是什么?
示例:我不能围绕整个球体旋转,而是如何将旋转限制在单个半球内?
我的第一个尝试是查看是否有任何 .allowsCameraControl 的限制。找不到任何东西。
然后我尝试调整 c# Unity:mouse orbit script , 运气不好。
一些关于如何处理或解决这个问题的建议会很好。
样板 Arcball 感谢 this answer.
var lastWidthRatio: Float = 0
var lastHeightRatio: Float = 0
let camera = SCNCamera()
let cameraNode = SCNNode()
let cameraOrbit = SCNNode()
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// create and add a camera to the scene
camera.usesOrthographicProjection = true
camera.orthographicScale = 9
camera.zNear = 0
camera.zFar = 100
cameraNode.position = SCNVector3(x: 0, y: 0, z: 50)
cameraNode.camera = camera
cameraOrbit.addChildNode(cameraNode)
scene.rootNode.addChildNode(cameraOrbit)
// retrieve the ship node
let ship = scene.rootNode.childNodeWithName("ship", recursively: true)!
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
// add a tap gesture recognizer
let gesture = UIPanGestureRecognizer(target: self, action: "panDetected:");
scnView.addGestureRecognizer(gesture);
}
func panDetected(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(sender.view!)
let widthRatio = Float(translation.x) / Float(sender.view!.frame.size.width) + lastWidthRatio
let heightRatio = Float(translation.y) / Float(sender.view!.frame.size.height) + lastHeightRatio
self.cameraOrbit.eulerAngles.y = Float(-2 * M_PI) * widthRatio
self.cameraOrbit.eulerAngles.x = Float(-M_PI) * heightRatio
print(Float(-2 * M_PI) * widthRatio)
if (sender.state == .Ended) {
lastWidthRatio = widthRatio % 1
lastHeightRatio = heightRatio % 1
}
}
最佳答案
也许这对读者有用。
class GameViewController: UIViewController {
var cameraOrbit = SCNNode()
let cameraNode = SCNNode()
let camera = SCNCamera()
//HANDLE PAN CAMERA
var lastWidthRatio: Float = 0
var lastHeightRatio: Float = 0.2
var WidthRatio: Float = 0
var HeightRatio: Float = 0.2
var fingersNeededToPan = 1
var maxWidthRatioRight: Float = 0.2
var maxWidthRatioLeft: Float = -0.2
var maxHeightRatioXDown: Float = 0.02
var maxHeightRatioXUp: Float = 0.4
//HANDLE PINCH CAMERA
var pinchAttenuation = 20.0 //1.0: very fast ---- 100.0 very slow
var lastFingersNumber = 0
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
//Create a camera like Rickster said
camera.usesOrthographicProjection = true
camera.orthographicScale = 9
camera.zNear = 1
camera.zFar = 100
cameraNode.position = SCNVector3(x: 0, y: 0, z: 50)
cameraNode.camera = camera
cameraOrbit = SCNNode()
cameraOrbit.addChildNode(cameraNode)
scene.rootNode.addChildNode(cameraOrbit)
//initial camera setup
self.cameraOrbit.eulerAngles.y = Float(-2 * M_PI) * lastWidthRatio
self.cameraOrbit.eulerAngles.x = Float(-M_PI) * lastHeightRatio
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
//allows the user to manipulate the camera
scnView.allowsCameraControl = false //not needed
// add a tap gesture recognizer
let panGesture = UIPanGestureRecognizer(target: self, action: "handlePan:")
scnView.addGestureRecognizer(panGesture)
// add a pinch gesture recognizer
let pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinch:")
scnView.addGestureRecognizer(pinchGesture)
}
func handlePan(gestureRecognize: UIPanGestureRecognizer) {
let numberOfTouches = gestureRecognize.numberOfTouches()
let translation = gestureRecognize.translationInView(gestureRecognize.view!)
if (numberOfTouches==fingersNeededToPan) {
widthRatio = Float(translation.x) / Float(gestureRecognize.view!.frame.size.width) + lastWidthRatio
heightRatio = Float(translation.y) / Float(gestureRecognize.view!.frame.size.height) + lastHeightRatio
// HEIGHT constraints
if (heightRatio >= maxHeightRatioXUp ) {
heightRatio = maxHeightRatioXUp
}
if (heightRatio <= maxHeightRatioXDown ) {
heightRatio = maxHeightRatioXDown
}
// WIDTH constraints
if(widthRatio >= maxWidthRatioRight) {
widthRatio = maxWidthRatioRight
}
if(widthRatio <= maxWidthRatioLeft) {
widthRatio = maxWidthRatioLeft
}
self.cameraOrbit.eulerAngles.y = Float(-2 * M_PI) * widthRatio
self.cameraOrbit.eulerAngles.x = Float(-M_PI) * heightRatio
print("Height: \(round(heightRatio*100))")
print("Width: \(round(widthRatio*100))")
//for final check on fingers number
lastFingersNumber = fingersNeededToPan
}
lastFingersNumber = (numberOfTouches>0 ? numberOfTouches : lastFingersNumber)
if (gestureRecognize.state == .Ended && lastFingersNumber==fingersNeededToPan) {
lastWidthRatio = widthRatio
lastHeightRatio = heightRatio
print("Pan with \(lastFingersNumber) finger\(lastFingersNumber>1 ? "s" : "")")
}
}
func handlePinch(gestureRecognize: UIPinchGestureRecognizer) {
let pinchVelocity = Double.init(gestureRecognize.velocity)
//print("PinchVelocity \(pinchVelocity)")
camera.orthographicScale -= (pinchVelocity/pinchAttenuation)
if camera.orthographicScale <= 0.5 {
camera.orthographicScale = 0.5
}
if camera.orthographicScale >= 10.0 {
camera.orthographicScale = 10.0
}
}
关于swift - SCNCamera 限制弧球旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967838/
我试图让球弹起,或者在它们碰撞时反转方向。我让它检查移动方法中的碰撞。它检查两个球之间是否发生碰撞,如果发生碰撞,它将反转速度。问题是,有时球会互相穿过,主要是较小的球。球要么弹跳得早,要么弹得晚,要
我一直在努力根据 2 个弹跳圆/球获得正确的矢量值。我知道他们什么时候反弹;使用毕达哥拉斯,但后来我迷路了。我知道我可能不得不使用三 Angular 函数 cos/sin/tan2。 情况,以我的形象
using UnityEngine; using System.Collections; public class audio : MonoBehaviour { public AudioClip
我正在尝试创建 3d 球体的动画,该动画是由该球体表面上的随机点制作的。这是我的代码,我在其中创建 500 个随机极点,然后将这些极坐标转换为笛卡尔坐标,然后将 X 和 Y 坐标映射到屏幕。这就是我得
我创建的这个程序应该基本上使用公式 V=Pi*h^2(3r-h)/3 但我的最终答案并没有相加。 例如:如果我用 1 代替半径,用 2 代替高度,我应该得到 4.18,但通过程序我得到 -1。 #in
我正在尝试制作一个简单的游戏,但如果我需要弹跳球的图像,我该怎么做呢?我正在做这个- function draw() { ctx.clearRect(0, 0, 300, 300);
我只是提出一个有可能结束的想法。我需要画一个 Crystal 球,红色和蓝色粒子随机分布在其中。我想我必须使用 photoshop,甚至尝试在图像中制作球,但由于这是用于研究论文并且不必很花哨,我想知
我有圆与圆相交的代码。但我需要将其扩展到 3-D。你能帮我写函数吗? static class Point{ double x, y, z; int dimension; Po
目标:我有一个三 Angular 形的球。球具有初始位置和速度。我试图弄清楚球会击中三 Angular 形的哪一边。 我试过的: I derived a formula通过参数化球的路径和三 Angu
由于我是 cocos2d 的新手,而且我很挣扎。任何人都可以建议我如何解决这个问题。 我有 3 个盒子(它们是运动体) 还有多个球(它们是动态物体),每个球都有一个标签值(盒子编号)。 我在射球位置和
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
我正在为 rpm 编写一个 .spec 文件,它只是将一个 tar 球解压到文件系统上的某个目录中 那么我把原来的 tar 球放在哪里呢?我看到的所有示例都是从互联网上下载原始 tar 球的。但就我而
我是 THREE.js 的新手,对物理知识知之甚少 - 但我正在尝试构建一个足球游戏引擎(从顶部看),现在我正在为球的运动而苦苦挣扎。 当尝试将球从一侧移动到另一侧时,旋转始终朝向一个方向,我不明白如
我必须在 Android 中开发一个在屏幕上 move 球的应用程序。我需要用加速度计 move 球。我有这段代码,但球绕过边界并且没有反弹。 package com.example.test
我正在尝试创建一个 Roomba 程序,其中有一个球在屏幕上弹跳,以清洁它经过的瓷砖。该程序应该从所有灰色瓷砖开始,当球经过它们时,瓷砖就会变成白色。目前我有一个可以到处弹跳的球和一个创建 5x5 网
我正在尝试为我当前的作业创建一个加载屏幕效果。 它需要我们创建一个与 position: fixed .以此资金为背景。使用这个 div,有 4 个 与 position: absolute . 我们
我想将一个球(带有图像)扔到一个二维场景中,并在它到达一定距离时检查它是否发生碰撞。但我无法让它正确地“飞”。似乎这个问题已经被问过一百万次了,但随着我发现的越多,我就越困惑..现在我关注了this
这是我的代码 import java.util.*; import javafx.application.Application; import javafx.scene.Scene; import
我是一名优秀的程序员,十分优秀!