Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Data structures C#BSP拆分算法逻辑或计算错误_Data Structures_Unity3d_Binary Tree_Game Engine_Bsp - Fatal编程技术网

Data structures C#BSP拆分算法逻辑或计算错误

Data structures C#BSP拆分算法逻辑或计算错误,data-structures,unity3d,binary-tree,game-engine,bsp,Data Structures,Unity3d,Binary Tree,Game Engine,Bsp,我需要你的建议 好的,我对这个算法有个问题。我使用递归方法为这个程序添加和维护二叉树,但是当拆分一次3次时,代码就会中断 举个例子,我们将强制算法的方法始终执行垂直拆分,并且只执行垂直拆分,因此它只调用我使用的VertiSplit方法。方法如下。我是凭记忆做的,所以可能有一两件事不对。。。我要用最简单的方法来解决这个问题 public void VertiSplit(Node curNode) //The node that called the method is passed in. {

我需要你的建议

好的,我对这个算法有个问题。我使用递归方法为这个程序添加和维护二叉树,但是当拆分一次3次时,代码就会中断

举个例子,我们将强制算法的方法始终执行垂直拆分,并且只执行垂直拆分,因此它只调用我使用的VertiSplit方法。方法如下。我是凭记忆做的,所以可能有一两件事不对。。。我要用最简单的方法来解决这个问题

public void VertiSplit(Node curNode) //The node that called the method is passed in.
{
 int vRatio = curNode.height / curNode.width;
 //if( vRatio <=2) // Commented out so it never does a Horizontal Split.
 //{
     //Calculate the Split Point Data for the Parent node that called the method.
     curNode.splitX = curNode.xCoor + (curNode.width / 2);
     curNode.splitY = curNode.yCoor;
     curNode.splitW = 1; // Is 1 because it is passed into the draw call for the line.
     curNode.splitH = curNode.height;
     // Calculate Data for Children...
     curNode.child1.xCoor = curNode.xCoor;
     curNode.child2.xCoor = curNode.splitX;
     curNode.child1.yCoor = curNode.yCoor;
     curNode.child2.yCoor = curNode.yCoor;
     curNode.child1.width = curNode.splitX;
     curNode.child2.width = curNode.splitX;
     curNode.child1.height = curNode.height;
     curNode.child2.height = curNode.height; //At this point, calculations and assignment of the children's variables is completed. So I'll stop writing the code here..

这是我的方法。这是在递归链中调用Split方法的地方。GrowBranchs也由方法SplitCreateOnce和SplitCreateAll调用,但由于上述涉及解析错误的原因,后者不起作用。

如果我不得不猜测,我会说是这两行:

 curNode.child1.width = curNode.splitX;
 curNode.child2.width = curNode.splitX;
如果一个节点的xCoord=256,width=256,splitX将是386(xCoord+256/2),但这不是子节点的宽度,宽度是256/2。使用上面的代码,您将有一个xCoord 386的孩子,宽度为386


关于文本错误问题的第二部分,如果您使用的是Unity文本框,则在清除现有值开始键入时,很可能会将空字符串传递给Convert.ToInt32。只需使用
Try/Catch
并忽略错误。

没有看到您的呼叫站点,很难提供帮助。您的递归右拆分可能不正确,您可能在某处有不正确的偏移量,等等。调用站点?请详细说明。我是个新手,抱歉。如果您提到使用递归方法,那么查看您在代码中递归调用Vertisplit.Oh的位置会很有帮助。我懂了。好。让我快速编辑一下。它在一个名为growBranchs的函数中,它是这个代码构建的递归链的一部分。这是它的一部分,Vertisplit是否递归调用过它自己或HoriSplit?另一件事。我正在做的这个程序是为了可视化。宽度为1,如上图所示,用于DrawTexture调用,用于绘制标记拆分位置的线。实际上,我只是在家里在纸上手工计算。答案如下:Node 5 splitX=448 Node 6 splitX=576这意味着代码正在做一些不可能的事情。。。
 curNode.child1.width = curNode.splitX;
 curNode.child2.width = curNode.splitX;