【发布时间】:2015-09-23 03:27:59
【问题描述】:
我目前正在使用的光线投射引擎存在问题。我目前正在向渲染引擎添加非传送门,但我得到了一些奇怪的工件。我已经包含了每个案例的一些绘制示例。
这是一扇垂直(南北)的门,从 -X 角(向东看)看。如您所见,这就是在所有情况下都应该绘制门的方式。
这是同一扇门,但从 Y 轴(看南/北)直视。如您所见,这是视觉伪影开始出现的时候。画在门口中间的那个方块来自右侧,会向左移动,直到你到达 +X 角(向西看)。
这种行为会在所有水平和垂直打开的门口复制自己。它们从一个角度看起来是正常的,但随后奇怪的伪影将从右向左移动(反之亦然),直到某个时候抛出溢出错误,因为 X-collision 或 Y-collision 会跳转到一些高得离谱的数字
这是我用来确定碰撞的代码。这是用基本编写的,因为我还没有将它转换为 C/C++。这两个函数都使用 GOTO 语句调用,并且能够返回它们被调用的函数。
`X and Y are the non-precalculated ray coordinates while COLLX and COLLY are precalculated for the typical orthogonal cubes
`For when DX(direction X) is the greater magnitude (-1, +1). Called by @CASTXLOOP
@XDOOR
`ignore any occurences of T=2, for drawing code only
IF T==10 THEN @XDOORH `horizontal east-west door
T=2
IF COLLX-FLOOR(COLLX)>=.8 THEN RETURN `return positive collision to be drawn
IF SGN(DX)>1 THEN @CASTXLOOP `X-ray going the wrong direction to detect door
COLLY=Y+DY*(FLOOR(X)+.8-X) `Mulltiplied by fraction of X to +.8
COLLX=FLOOR(X)+.8
RETURN `Collision point returned
@XDOORH
T=2
IF COLLY-FLOOR(COLLY)>=.8 THEN RETURN `Return positive collision to be drawn
IF SGN(DY)>1 THEN @CASTXLOOP `Y ray going wrong direction
IF FLOOR(Y)+.8-Y>=DY THEN @CASTXLOOP `Distance to door collision is greater than magnitude 1
COLLX=X+DX*((FLOOR(Y)+.8-Y)/DY) `Important, move by magnitude of DY distance to .8
COLLY=FLOOR(Y)+.8
RETURN `Collision point returned
`For when DY(direction Y) is the greater magnitude (-1, +1). Called by @CASTYLOOP
@YDOOR
IF T==10 THEN @YDOORH
T=2
IF COLLX-FLOOR(COLLX)>=.8 THEN RETURN `Return positive collision to be drawn
IF SGN(DX)>1 THEN @CASTYLOOP `X ray going wrong direction
IF FLOOR(X)+.8-X>=DX THEN @CASTYLOOP `Distance to door collision greater than magnitude 1
COLLY=Y+DY*((FLOOR(X)+.8-X)/DX)
COLLX=FLOOR(X)+.8
RETURN `Collision point returned
@YDOORH
T=2
IF COLLY-FLOOR(COLLY)>=.8 THEN RETURN `Return collision to be drawn
IF SGN(DY)>1 THEN @CASTYLOOP `Y ray going wrong direction
COLLX=X+DX*(FLOOR(Y)+.8-Y)
COLLY=FLOOR(Y)+.8
RETURN `Collision point returned
【问题讨论】:
标签: rendering basic raycasting