- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在做一个大学 compsci 项目,我需要一些关于视野算法的帮助。我主要工作,但在某些情况下,算法会看穿墙壁并突出显示玩家不应该看到的墙壁。
void cMap::los(int x0, int y0, int radius)
{ //Does line of sight from any particular tile
for(int x = 0; x < m_Height; x++) {
for(int y = 0; y < m_Width; y++) {
getTile(x,y)->setVisible(false);
}
}
double xdif = 0;
double ydif = 0;
bool visible = false;
float dist = 0;
for (int x = MAX(x0 - radius,0); x < MIN(x0 + radius, m_Height); x++) { //Loops through x values within view radius
for (int y = MAX(y0 - radius,0); y < MIN(y0 + radius, m_Width); y++) { //Loops through y values within view radius
xdif = pow( (double) x - x0, 2);
ydif = pow( (double) y - y0, 2);
dist = (float) sqrt(xdif + ydif); //Gets the distance between the two points
if (dist <= radius) { //If the tile is within view distance,
visible = line(x0, y0, x, y); //check if it can be seen.
if (visible) { //If it can be seen,
getTile(x,y)->setVisible(true); //Mark that tile as viewable
}
}
}
}
}
bool cMap::line(int x0,int y0,int x1,int y1)
{
bool steep = abs(y1-y0) > abs(x1-x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0,x1);
swap(y0,y1);
}
int deltax = x1-x0;
int deltay = abs(y1-y0);
int error = deltax/2;
int ystep;
int y = y0;
if (y0 < y1)
ystep = 1;
else
ystep = -1;
for (int x = x0; x < x1; x++) {
if ( steep && getTile(y,x)->isBlocked()) {
getTile(y,x)->setVisible(true);
getTile(y,x)->setDiscovered(true);
return false;
} else if (!steep && getTile(x,y)->isBlocked()) {
getTile(x,y)->setVisible(true);
getTile(x,y)->setDiscovered(true);
return false;
}
error -= deltay;
if (error < 0) {
y = y + ystep;
error = error + deltax;
}
}
return true;
}
如果有人可以帮助我使第一个被阻止的图 block 可见但阻止其余的图 block ,我将不胜感激。
谢谢,Manderin87
最佳答案
您似乎在尝试创建光线转换算法。我假设您了解 Bresenham 的线路是如何工作的,所以我将切入正题。
无需检查潜在视野中每个单元格的可见性,您只需从 FOV 中心向潜在 FOV 区域(您循环穿过的正方形)周边的每个单元格发射 Bresenham 线。在 Bresenham 线的每一步,您都检查单元格状态。每条射线的伪代码如下所示:
while (current_cell != destination) {
current_cell.visible = true;
if (current_cell.opaque) break;
else current_cell = current_cell.next();
}
请记住,光线转换会产生大量伪影,并且在计算视野后您可能还需要进行后处理。
一些有用的资源:
关于c++ - Roguelike FOV问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5174781/
考虑以下透视投影矩阵,它仅适用于调用者给出的垂直视场和纵横比(非常好): func (me *Mat4) Perspective (fovY, aspect, near, far float64) {
我正在使用 Google Card Board Unity SDK 为 Android 开发一款狙击游戏。现在需要调整相机的 FOV,这导致我在 CardBoard.cs 中与名为“mockField
我需要完全按照用户选择的方式保存街景图像(包括 panoID、航向、俯仰和视野)。我有以下代码: panorama = new google.maps.StreetViewPa
我有一个透视 FOV,但在旋转时,它“看起来”不正确 - 较远的物体比较近的物体移动得更快,在屏幕中间通过它们。 所以:这是正确的吗?使用右手坐标,如果这很重要? public static
有一些measured results适用于某些较旧的 iOS 设备,但我无法找到较新型号的 FOV 数字,特别是 iPhone 5s ~ 6s Plus 和 iPad 4 ~ iPad Pro。此外
我在 THREE.JS 中手动设置了我的透视相机的position和fov。它的行为符合预期。但是,当我稍后尝试通过 TrackBall Controls 与 scene 交互时,它只显示黑屏,没有错
我想知道如何使用 c# 在 Unity3d 中平滑地放大和平滑地按下按钮。我已经缩小了部分,但不确定如何平滑地进行放大和缩小的过渡。例如,我希望它像在 ARMA 或 DayZ 游戏中一样平滑地放大。
我有一个程序可以获取设备后置摄像头的 FOV 角度,它以度数返回水平和垂直角度,如下所示: 54.8 42.5 是否有一个简单的转换来应用获取正确的“左、右、下、上”参数以传递到 OpenGL 的 M
我正在尝试更新相机视野而不创建新相机。我已经能够使用下面的代码来通过位置来做到这一点: camera.position.set() 我想以与 fov 类似的方式进行设置: camera.fov.set
我想检测所有由“Wall_[0-24]”标记的游戏对象,它们在相机 FOV 内。我已经尝试过 Raycasting,但因为它只是一条光线,所以它不会同时捕捉到多个物体。我试过这个: void Upda
我正在尝试按照本教程进行操作: http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/ 在 three.js
目前我正在使用 bablyon.js 引擎,目前唯一的主要问题是 FOV。 FOV 太浅,有时会导致渲染效果不佳。 目前我正在使用 BABYLON.FreeCamera() 作为带有控件的主相机,这是
有谁知道我可以使用 Google Maps Android API 中的 Zoom 进行转换的公式:https://developers.google.com/maps/documentation/a
我有一个 SCNCamera 在 iOS 上的 3D SceneKit View 中工作。 当我改变屏幕的方向时,为了保持世界对象相同的大小和相对位置,我需要改变 SCNCamera 的 FoV。 但
我正在尝试开始使用 Direct 3D。但我无法让 fov 相机工作。至少不是垂直运动。我知道了原因,但我仍然无法修复它。 我正在使用 C++ (140) 和 D3DX9 代码: D3DXMATRIX
我实际上正在实现一个 C++ 光线追踪器,并且我正面临一个关于光线追踪的经典问题。当放置高垂直 FOV 时,形状离边缘越近,变形越大。 我知道为什么会发生这种失真,但我不知道如何解决它(当然,减少 F
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseOrb
我目前有一个由两个区域组成的屏幕: (值只是这个特定示例的假定值,当然可能因屏幕而异)。 屏幕总尺寸为 1080x1432 像素(宽 x 高),由两个区域组成,每个区域都使用 glViewPort 进
VREyeParameters里面曾经有视野信息,但这已被弃用。所以现在我想知道:是否可以使用 VRFrameData 提供的 View /投影矩阵来计算它? 最佳答案 投影矩阵描述了从场景的 3D
背景 我使用视口(viewport)单位调整所有内容: body { font-size: calc((1vw + 1vh) / 2); } h6 { font-size: 1em; } di
我是一名优秀的程序员,十分优秀!