简体   繁体   English

3d相机位置给出一些点

[英]3d Camera Position given some points

Heyo, Heyo,

I'm currently working on a project where I need to place the camera such that the full motion of a character would be viewable without moving the camera. 我目前正在开发一个项目,我需要放置相机,以便在不移动相机的情况下可以查看角色的完整动作。 I have the position where the character starts, as well as the maximum distance that the character will travel in all three directions (X,Y, & Z). 我有角色开始的位置,以及角色在所有三个方向(X,Y和Z)上行进的最大距离。 I also have the field of view (which is 90 degrees). 我也有视野(90度)。

Is there an equation that'll figure out where I need to place the camera so it won't have to move to see the full motion? 是否有一个方程式可以找出我需要放置相机的位置,以便不必移动以查看完整的运动?

Note: this is using OpenGL. 注意:这是使用OpenGL。

Clarification: The camera should be "in front" of the character that's in the motion, not above. 澄清:相机应该在运动中的角色“前方”,而不是在上方。

It'll also be moving along a ground plane. 它也将沿地平面移动。

If you make a bounding sphere of the points, all you need to do is keep the camera at a distance greater than or equal to the radius of the bounding sphere / sin(FOV/2). 如果你制作点的边界球,你需要做的就是让相机保持一个大于或等于边界球/半径(FOV / 2)半径的距离。

For example, if you have a bounding sphere with radius Radius, and a specified Field of View FOV, your camera just needs to be at a point "Dist" away, pointing towards the center of the bounding sphere. 例如,如果您有一个半径为Radius的边界球体和一个指定的视野FOV,则您的相机只需要位于“Dist”点,指向边界球体的中心。

The equation for calculating the distance is: Dist = Radius / sin( FOV/2 ); 计算距离的公式为:Dist = Radius / sin(FOV / 2);

This will work in 3D, for a camera at any orientation. 对于任何方向的相机,这将在3D中工作。

Take the line segment from the startpoint to the endpoint. 从起点到终点获取线段。 Construct a plane orthogonal to this line segment through the midpoint of the line segment. 通过线段的中点构造与该线段正交的平面。 Then position the camera somewhere in this plane at an distance of more than the following from the intersection point of plane and line looking at the intersection point. 然后将摄像机定位在此平面中的某个位置,距离平面和线的交叉点处的距离大于以下距离,以查看交叉点。 The up vector of the camera must be in the plane and the horizontal field of view must be 90 degrees. 摄像机的向上矢量必须在平面内,水平视场必须为90度。

distance = sqrt(dx^2 + dy^2 + dz^2) / 2

This camera positions will all have the startpoint and the endpoint on the left or right border of the view port and verticaly centered. 此摄像机位置将在视口的左侧或右侧边界上具有起点和终点,并且垂直居中。

Another solution might be to write a function that takes the startpoint, the endpoint, and the desired position of both points on the screen. 另一个解决方案可能是编写一个函数,该函数获取屏幕上两个点的起点,终点和所需位置。 Then just solve the projection equation for the camera transformation. 然后只需求解相机变换的投影方程。

Simply having the maximum range of (X, Y, Z) is not on its own sufficient, because the viewing port is essentially pyramid shaped, with the apex of the pyramid being at the eye position. 简单地具有(X,Y,Z)的最大范围本身并不充分,因为观察口基本上是金字塔形的,金字塔的顶点位于眼睛位置。

For the sake of argument, let's assume that all movement is in the (X, Z) plane (ie the ground), and the eye is directly above the origin 10m along the Y axis. 为了论证,我们假设所有运动都在(X,Z)平面(即地面),并且眼睛沿着Y轴直接位于原点10m的上方。

Assuming a square viewport, with your 90˚ field of view you'd be able to see from ±10m along both the X and Z axis, but only for objects who are on the ground (Y = 0). 假设一个方形视口,在90°视野范围内,您可以沿X轴和Z轴看到±10m,但仅适用于地面上的物体(Y = 0)。 As soon as they come off the ground your view is reduced. 一旦他们离开地面,你的视野就会减少。 If it's 1m of the ground then your (X, Z) extent is only ±9m. 如果距离地面1米,那么你的(X,Z)范围只有±9米。

Clearly a real camera could be placed anyway in the scene, facing any direction. 很明显,无论如何都可以在场景中放置真正的相机,面向任何方向。 Even the "roll" angle of the camera could change how much is visible. 即使相机的“滚动”角度也可以改变可见的程度。 There are actually infinitely many such camera points, so you will need to constrain your criteria somewhat. 实际上有无数的这样的摄像机点,所以你需要稍微限制你的标准。

It depends, for example, if the object is gonna move in a plane, you can just place the camera outside a ball circumscribed its movement area (this depends on the fact that FOV is 90, which is a fortunate angle). 例如,它取决于物体是否会在一个平面内移动,你可以将相机放置在一个球的外面,并限定其运动区域(这取决于FOV为90,这是一个幸运的角度)。

If the object is gonna move in 3D, it's much more difficult. 如果物体要以3D移动,那就更困难了。 It would help if you'd specify the region where the object moves (cube vs. ball...) and the direction you want to see it from. 如果您指定对象移动的区域(立方体与球...)以及您想要从中看到它的方向,这将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM