【问题标题】:Scaling 3D camera pan/zoom based on distance to target根据到目标的距离缩放 3D 相机平移/缩放
【发布时间】:2012-07-03 16:17:03
【问题描述】:

我正在开发一种类似 DCC 的工具,它具有 3D 视口,您可以用鼠标四处移动,类似于 Maya、Blender 等。

我需要一些数学方面的帮助。

我试图确定两点。第一个是基于目标距离的小车速度。在小尺度上(例如,dist=10^-3),它​​移动得太快,而在大尺度上(例如,dist=10^6),它移动得太慢。我想要一个平坦的“相机速度”输入,可以整体缩放效果,但在所有比例下,相机都应该感觉相同。不管我是在 0.1 单位还是 1000 单位之外,对于给定的鼠标增量,我应该感觉我正在以相同的速度接近目标。

另一个是相机平移,同样基于相机距离。实际上,我希望相机目标沿着与相机对齐且distance_to_target 单位距离的平面完美地跟踪鼠标光标。我不确定透视失真是否会影响这一点?

输入是:

// Distance in world units to camera's centre of interest
real distance_to_target

// Number of pixels mouse has moved horizontally since last frame
int mouse_delta_x

// Number of pixels mouse has moved vertically since last frame
int mouse_delta_y

// The vector of the mouse delta, normalized into -1 to 1 space based on
// viewport dimensions where a value of (-1,-1) or (1,1) means the cursor
// moved from one corner of the viewport to the other, or further, since
// the last frame.
vec2 mouse_delta_vector

// Scale the dolly speed
real dolly_speed

通常我会根据经验做类似的事情,尝试不同的值,直到找到我喜欢的东西,但为此我认为是时候尝试理论了。

【问题讨论】:

    标签: input 3d perspectivecamera


    【解决方案1】:

    对于问题 1,只需使用比例速度缩放。

        currSpeed = currDistToTarget * refSpeed / refDistToTarget
    

    其中 refSpeed 和 refDistToTarget 是您认为通过实验可以接受的值。

    至于问题 2,想法是相同的 - 即您计算距离加权角。如果您的 FOV 从未改变,您可以尝试上述相同的线性速度缩放。这里主要是找到 refDistanceToTarget 和 refSpeed 的正确值。

    【讨论】:

    • ::headdesk:: 我说服自己答案一定比这更复杂,但它完全有道理。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多