- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
基本上我想做的是使用非常非常基本的光线转换系统对 2D 高度图进行着色,该系统基本上只是在应该对光线进行着色之前检查光线是否被拦截。然而,它不能正常工作,我已经为此苦苦思索了几个小时,所以我认为把它交给你们也没什么坏处,因为我认为这可能是非常明显的事情,我不会看到它或如此复杂以至于我永远不会全神贯注。
我有这样一张 map :
光线转换给了我这个(记住它只是调试颜色;红色是光线拦截,但在预期位置之前(所以阴影),蓝色将是正确位置的光线拦截(所以高亮或原样), 黄色表示该点在 while 循环切断之前根本没有光线相互作用)。
结果应该是在背面的斜坡和大山后面的区域(阴影)是红色的,在朝阳的斜坡(高光)是蓝色的。不应该有任何黄色。所以这张图片表明要么所有的光线都击中了错误的地方,要么光线在到达目标之前总是在其他地方相交,这是不可能的。
此时我高度怀疑问题出在我的触发器上。
这是 Ray 类:
class Ray
{
public Vector2 Position;
public Vector2 Direction; // Think in XZ coordinates for these (they are on a perpendicular plane to the heightmap)
// Angle is angle from horizon (I think), and height is height above zero (arbitrary)
public float Angle, Height;
private TerrainUnit[,] Terrainmap;
private float U, V;
public Ray(ref TerrainUnit[,] Terrainmap, float height, float angle)
{
this.Terrainmap = Terrainmap;
this.Angle = angle;
this.Height = this.V = height;
// Create new straight vector
this.Direction = new Vector2(0, 1);
// Rotate it to the values determined by the angle
this.Direction = Vector2.Transform(Direction, Matrix.CreateRotationX(Angle));
//this.Direction = new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle));
// Find the horizontal distance of the origin-destination triangle
this.U = V / (float)Math.Tan(Angle);
// Bleh just initialize the vector to something
this.Position = new Vector2(U, V);
}
public void CastTo(int x, int y)
{
// Get the height of the target terrain unit
float H = (float)Terrainmap[x, y].Height;
// Find where the ray would have to be to intersect that terrain unit based on its angle and height
Position = new Vector2(x - U, H + V);
float Z = 1000 * (float)Terrainmap[0, y].Height;
// As long as the ray is not below the terrain and not past the destination point
while (Position.Y > Z && Position.X <= x)
{
// If the ray has passed into terrain bounds update Z every step
if (Position.X > 0) Z = 1000 * (float)Terrainmap[(int)Position.X, y].Height;
Position.X += Direction.X;
Position.Y += Direction.Y;
}
Terrainmap[x, y].TypeColor = Color.Yellow;
if ((int)Position.X == x) Terrainmap[x, y].TypeColor = Color.Blue;
else Terrainmap[x, y].TypeColor = Color.Red;
}
}
另外,作为一种形式,转换每条光线的函数以及我如何调用它:
if (lighting) CastSunRays(1f, MathHelper.PiOver4);
private void CastSunRays(float height, float angle)
{
Ray ray = new Ray(ref Terrainmap, height, angle);
for (int x = 0; x < Width; x++)
for (int y = 0; y < Height; y++)
ray.CastTo(x, y);
}
最佳答案
我最终使用了一种更简单的方法 Bresenham's Line Algorithm找到拦截点;我想它比我尝试做的方式更快、更有效。
关于c# - 二维高度图上的基本(假)光线转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6804664/
我注意到一些 PHP 框架只使用小写字母 true/false 而其他框架则使用大写字母。 这有什么区别吗?我个人更喜欢小写字母。 最佳答案 没什么区别,有些人认为 FALSE 是常量,因此使用旧的尖
在我看来,以下两种映射方式实际上没有区别。以下是基于 @MapsId javadoc 的示例: // parent entity has simple primary key @Entity publ
我想知道是否有人知道编译器如何解释以下代码: #include using namespace std; int main() { cout << (true && true || false &
我想知道为什么alert(new Boolean(false))打印 false 而不是打印对象,因为 new Boolean 应该返回对象。如果我使用 console.log(new Boolean
即使在 verify=False 时,Python 请求也会给我一个 ssl 握手失败(我知道不使用 SSL 是不可取的)。对于其他具有有效证书的站点,请求按预期工作。我正在使用2.7。 from l
TDPL 描述了 assert(false); 语句的行为。此类断言不会从发布版本中删除(与所有其他断言一样),并且实际上会立即停止程序。问题是为什么?为什么会有如此令人困惑的行为?他们可能会添加 h
如何确定文档是否存在于 Meteor 的集合中? 编辑:新代码。 mongodb 有一个 ProductName 的文档:Apples 输入产品是“苹果” var exists = Products.
我想在 R 中做一些相当复杂的事情,但我不确定从哪里开始。 我有一个看起来像这样的数据框: main_val sub_val bit_one bit_two one a 1
我正在尝试编写一个函数 long(S1,S2) 如果 S1 比 S2 长,则该函数应该为真,否则为假。到目前为止,我所拥有的是以下内容: longer(A,nil). longer(nil,B) :-
我想知道我在这里缺少什么我有一个代码可以检查图像是否基于 Canvas 是透明的。 function Trasparent(url, npc, clb) { var img = new Ima
我想在按下按钮时使其他类框架设置可见(false)。 有一个名为 DisplayScore 的类,该类获取 getContentPane().add(new ScoreInfo());来自 Score
我正在使用 TableLayout 和 TableRow 创建 6/6 网格按钮。 private Button myButton; private static final int
这个问题没有实际用途!我之所以问这个只是因为我很好奇! 在C++中,有一种方法可以通过在某处编写#define true false来将true伪造为false,然后在代码中到处的true都将被视为f
我不久前学习 java,所以也许我有一个愚蠢的问题。 我有一张表,我在其中存储了一些信息。我想在此表中检查一些信息的可用性(这将只有一行),如果是 - 从这一行中获取特定列中的信息,如果没有 - 做另
这是一个 JavaScript 问题... 我正在尝试返回完全不区分大小写的匹配项。例如,如果我在输入框中输入 "yo",我希望它返回 true,这在我当前的方法中是这样做的,但它也会返回 true
我认为,我在 JS 中写了一个直接的 if 语句,但它运行不正确。 function printLetter(LetterId) { var studentflag = $("#IsStude
我如何使用 Javascript 执行以下操作? var object function() { return { object: Return true if object
我试图让导航栏在向上滚动时向下滑动,并在单击#menu-bar 时保持固定。但是当我再次单击同一个按钮时,我不知道如何在自动隐藏时将值改回 false,就在我有两个按钮的时候。非常感谢任何帮助! $(
下面的代码 #include using namespace std; int main(){ char greeting[50] = "goodmorning everyone";
我正在使用数据源将数据填充到我的数据 GridView 中。但是,我正在尝试找到一种方法让用户能够隐藏他不想看到的列。 我可以在程序运行之前隐藏和显示列: [Browsable(false)] pub
我是一名优秀的程序员,十分优秀!