移动相机对准它指向的方向同时转动考虑 [英] move a camera toward it pointing direction taking rotation into consideration
问题描述
可以说我们与位于不同的XYZ位置和旋转物体的场景。 其中一个节点是,我要走向画面的虚点,例如中心(512,384),向前或向后一台照相机。通过屏幕中心我指的是相机的方向的中心,所以它的什么用户可以看到。我面对目前的问题是:
- 在虚点(512,384)在2D以及如何将其转换成3D
- 如何移动摄像机向前/向后走转成 审议
有例如,照相机具有当前位置(x,Y,Z)(140,199,20),并绕其轴(x,Y,Z)(25°,187°,301°)转动。因此如何将相机对准它的指向方向。 我在学习现场套件(包括新3D)和任何例子/伪code是多少AP preciated。
我的努力,到现在只有移动相机对准根节点。
[_cameraNode runAction:[SCNAction MOVETO:。SCNVector3Make(_cameraNode presentationNode.position.x,_cameraNode presentationNode.position.y,_cameraNode presentationNode .position.z - 5)时间:1];
根据@mnuages发表评论,我可以采取必要的code出来,达到我要求的。谢谢!
- (SCNVector3)位置:(SCNVector3)位置multipliedByRotation:(SCNVector4)旋转
{
如果(rotation.w == 0)
{
返回的位置;
}
GLKVector3 gPosition = SCNVector3ToGLKVector3(位置);
GLKMatrix4 gRotation = GLKMatrix4MakeRotation(rotation.w,rotation.x,rotation.y,rotation.z);
GLKVector3 R = GLKMatrix4MultiplyVector3(gRotation,gPosition);
返回SCNVector3FromGLKVector3(r)的;
}
- (SCNMatrix4)moveCamera
{
CGFloat的步长= 2.0
CGFloat的X = 0.0;
CGFloat的Y = 0.0;
CGFloat的Z = _touchCount == 2? - 步骤:_touchCount == 1?步骤:0.0;
SCNMatrix4 cameraTransform = _cameraNode.transform;
SCNVector3 rotatedPosition = [自我定位:SCNVector3Make(X,Y,Z)multipliedByRotation:_cameraNode.rotation]。
cameraTransform = SCNMatrix4Translate(cameraTransform,rotatedPosition.x,rotatedPosition.y,rotatedPosition.z);
返回cameraTransform;
}
lets say we have a scene with objects located in different xyz positions and rotations. one of the nodes is a camera which I want to move toward an imaginary point e.g center of screen(512, 384) backward or forward. by center of screen I mean center of a direction of a camera, so its what the user can see. the problems I'm facing currently are:
- imaginary point (512, 384) is in 2D and how to convert that to 3D
- how to move the camera forward/backward taking rotation into consideration
for instance, the camera has current location (x,y,z)(140, 199, 20) and is rotated around its axis (x,y,z)(25°, 187°, 301°). so how to move the camera toward its pointing direction. I'm learning scene kit (incl. new to 3D) and any example/pseudo code is much appreciated.
my efforts till now only moves the camera toward root node.
[_cameraNode runAction:[SCNAction moveTo:SCNVector3Make(_cameraNode.presentationNode.position.x, _cameraNode.presentationNode.position.y, _cameraNode.presentationNode.position.z - 5) duration:1]];
according @mnuages comment I could take the necessary code out and achieve what i asked for. thank you!
-(SCNVector3)position:(SCNVector3)position multipliedByRotation:(SCNVector4)rotation
{
if (rotation.w == 0)
{
return position;
}
GLKVector3 gPosition = SCNVector3ToGLKVector3(position);
GLKMatrix4 gRotation = GLKMatrix4MakeRotation(rotation.w, rotation.x, rotation.y, rotation.z);
GLKVector3 r = GLKMatrix4MultiplyVector3(gRotation, gPosition);
return SCNVector3FromGLKVector3(r);
}
-(SCNMatrix4)moveCamera
{
CGFloat step = 2.0
CGFloat x = 0.0;
CGFloat y = 0.0;
CGFloat z = _touchCount == 2 ? -step : _touchCount == 1 ? step : 0.0;
SCNMatrix4 cameraTransform = _cameraNode.transform;
SCNVector3 rotatedPosition = [self position:SCNVector3Make(x, y, z) multipliedByRotation: _cameraNode.rotation];
cameraTransform = SCNMatrix4Translate(cameraTransform, rotatedPosition.x, rotatedPosition.y, rotatedPosition.z);
return cameraTransform;
}
这篇关于移动相机对准它指向的方向同时转动考虑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!