摄像机边界控制

综合编程 2015-08-26 阅读原文

由于美术场景有限制,所以需要将摄像机限制在一个如下图所示的凸六面体内:

那八个顶点的位置根据场景不同而不同,限制摄像机位置的关键在于判定摄像机位置是否在六面体内。而剩下的就是几何知识了。

首先要求出6个平面的方程,取一个平面的三个顶点 V1, V2, V3,分别代入平面方程:

aX+ bY + cZ +d = 0 中然后求出:

a = v1.y * v2.z – v1.y * v3.z -v2.y * v1.z + v2.y * v3.z + v3.y * v1.z – v3.y * v2.z;

b = -v1.x * v2.z + v1.x * v3.z + v2.x * v1.z – v2.x * v3.z – v3.x * v1.z + v3.x * v2.z;

c = v1.x * v2.y – v1.x * v3.y – v2.x * v1.y + v2.x * v3.y + v3.x * v1.y – v3.x * v2.y;

d = -v1.x * v2.y * v3.z + v1.x * v3.y * v2.z + v2.x * v1.y * v3.z – v2.x * v3.y * v1.z – v3.x * v1.y * v2.z + v3.x * v2.y * v1.z;

取一个六面体内的点V0,代入方程中,得出:

P0 = a * V0.x + b * V0.y + c * V0.z + d 。

设待验证的摄像机位置为Vx,同样代入,得出:

Px = a * Vx.x + b * Vx.y + c * Vx.z + d 。

然后对比P0和Px的正负号,如果相同,则证明V0和Vx在同侧。

按照以上算法,验证P0和Px是否同时满足在六个面同侧,是,则说明摄像机在六面体内,否则在六面体外。

责编内容by:WantGame 【阅读原文】。感谢您的支持!

您可能感兴趣的

Papers I like (part 2) Continued frompart 1. Once I was about a thousand words into describing background for GEMM, it became pretty clear ...
My Journey Of Learning Programming Through Flatiro... My name is Mason Ellwood, and I’m currently working on Flatiron School’s Online Full Stack Web Development Program . Ea...
A whole heap of work The majority of my Perl 6 grant time in the last week went on building a heap snapshot mechanism in MoarVM. But, before ...
How to become a Fool Stack Programmer At least once in your career as a programmer, and hopefully more than once and with deliberate regularity, it is import...
一行代码蒸发了¥6,447,277,680人民币! 现在进入你还是先行者,最后观望者进场才是韭菜。 美图董事长蔡文胜曾在三点钟群,高调的说出了这句话,随即被大众疯传。 在他发表完言论没多久,2月美链(BEC)上交易所会暴涨4000%,后又暴跌。尽管他多次否认,聪明的网友早已扒出,他与...