【发布时间】:2018-01-08 22:00:20
【问题描述】:
我有一架飞行的飞机,我正在跟随它,我还展示了飞机所遵循的路径。我正在绘制圆柱体作为绘制路径的线。它有点像在两点之间画一条线。我有一个最初设置为 (0,200,200) 的 cameraNode。那时我可以看到飞机。但是当我开始飞行时。它走出屏幕。我想要两件事:
- 只跟随飞机(路径无关紧要)。
- 显示整个路径以及飞机。
我尝试找到最小广告最大 x、y 和 z 并取平均值,但它不起作用。如果你看到下面的 gif 它太放大了,飞机已经移出屏幕
这是我设置相机的方法:
- (void)setUpCamera {
SCNScene *workingScene = [self getWorkingScene];
_cameraNode = [[SCNNode alloc] init];
_cameraNode.camera = [SCNCamera camera];
_cameraNode.camera.zFar = 500;
_cameraNode.position = SCNVector3Make(0, 60, 50);
[workingScene.rootNode addChildNode:_cameraNode];
SCNNode *frontCameraNode = [SCNNode node];
frontCameraNode.position = SCNVector3Make(0, 100, 50);
frontCameraNode.camera = [SCNCamera camera];
frontCameraNode.camera.xFov = 75;
frontCameraNode.camera.zFar = 500;
[_assetActivity addChildNode:frontCameraNode]; //_assetActivity is the aircraft node.
}
以下是我如何更改不起作用的相机位置:
- (void)showRealTimeFlightPath {
DAL3DPoint *point = [self.aircraftLocation convertCooridnateTo3DPoint];
DAL3DPoint *previousPoint = [self.previousAircraftLocation convertCooridnateTo3DPoint];
self.minCoordinate = [self.minCoordinate findMinPoint:self.minCoordinate currentPoint:point];
self.maxCoordinate = [self.minCoordinate findMaxPoint:self.maxCoordinate currentPoint:point];
DAL3DPoint *averagePoint = [[DAL3DPoint alloc] init];
averagePoint = [averagePoint averageBetweenCoordiantes:self.minCoordinate maxPoint:self.maxCoordinate];
SCNVector3 positions[] = {
SCNVector3Make(point.x,point.y,point.z) ,
SCNVector3Make(previousPoint.x,previousPoint.y,previousPoint.z)
};
SCNScene *workingScene = [self getWorkingScene];
DALLineNode *lineNodeA = [[DALLineNode alloc] init];
[lineNodeA init:workingScene.rootNode v1:positions[0] v2:positions[1] radius:0.1 radSegementCount:6 lineColor:[UIColor greenColor]] ;
[workingScene.rootNode addChildNode:lineNodeA];
self.previousAircraftLocation = [self.aircraftLocation mutableCopy];
self.cameraNode.position = SCNVector3Make(averagePoint.x, averagePoint.y, z);
self.pointOfView = self.cameraNode;
}
欢迎使用 swift 或 Objective c 中的代码。
谢谢!!
【问题讨论】:
-
如果我理解正确,您是在问如何实现两种不同的相机行为?另外,你能澄清一下“只跟随飞机”的意思吗?摄像头应该与飞机保持最小距离,还是只是更新以朝其方向看?
-
@ErikFoss 是的,我想要 2 种行为: 1. 跟随飞机(相机只会关注飞机而不是路径)。 2.在一个屏幕上显示整个路径和飞机。相机必须与飞机保持一定距离。
标签: ios objective-c swift scenekit