public LinearCoupleSystem(IIntegrator integrator) : base(integrator) { LinearNode linear1 = new LinearNode(1, 2, 0); linear1.Name = "u"; LinearNode linear2 = new LinearNode(0, -1, 0); linear2.Name = "v"; linear1.AddIncomingNode(linear2); linear2.AddIncomingNode(linear1); this.Nodes = new[] { linear1, linear2 }; }
private LinearNode GetNode(LinearNode n, Ray r) { for (int j = 0; j < 1000; j++) { float minDistance = Single.MaxValue; int index = -1; for (int i = 0; i < 8; i++) { if (n.children[i] != -1 && nodes[n.children[i]].bounds.IntersectRay(r, out var distance)) { if (distance < minDistance) { index = n.children[i]; minDistance = distance; } } } if (index == -1) { Debug.Log("f**k nothing"); return(null); } Debug.Log(index); Debug.Log(nodes[index].bounds); if (nodes[index].IsLeaf()) { Debug.Log("It's a leaf"); if (!nodes[index].isEmpty) { return(nodes[index]); } Debug.Log("found zero things"); return(null); } n = nodes[index]; } Debug.Log("found nothing"); return(null); }
private void DrawOctree(LinearNode l) { if (l.IsLeaf()) { if (!l.isEmpty) { Gizmos.DrawWireCube(l.bounds.center, l.bounds.size); } } else { for (int i = 0; i < 8; i++) { if (l.children[i] != -1) { DrawOctree(linear.nodes[l.children[i]]); } } } }
public bool Add(ref List <LinearNode> nodes, ref LinearNodeData[] data, int nodeIndex) { Vector3 middle = (data[nodeIndex].vertexA + data[nodeIndex].vertexB + data[nodeIndex].vertexC) / 3; if (!bounds.Contains(middle)) { return(false); } var bitFlagMiddle = middle.x > bounds.center.x ? 4 : 0; bitFlagMiddle |= middle.y > bounds.center.y ? 2 : 0; bitFlagMiddle |= middle.z > bounds.center.z ? 1 : 0; float boundsSize = bounds.size.x; if (IsLeaf()) { if (!isEmpty) // we need to separate { if (bounds.size.x < 0.001f) { return(false); } //replace the initial node Vector3 middleDataIndex = (data[dataIndex].vertexA + data[dataIndex].vertexB + data[dataIndex].vertexC) / 3; var bitFlagDataIndex = middleDataIndex.x > bounds.center.x ? 4 : 0; bitFlagDataIndex |= middleDataIndex.y > bounds.center.y ? 2 : 0; bitFlagDataIndex |= middleDataIndex.z > bounds.center.z ? 1 : 0; var n = new LinearNode(bounds.center + boundsSize * 0.25f * offsets[bitFlagDataIndex] , Vector3.one * boundsSize * 0.5f, nodes.Count); children[bitFlagMiddle] = nodes.Count; nodes.Add(n); n.Add(ref nodes, ref data, dataIndex); //place the new node var node = new LinearNode(bounds.center + boundsSize * 0.25f * offsets[bitFlagMiddle] , Vector3.one * boundsSize * 0.5f, nodes.Count); children[bitFlagMiddle] = nodes.Count; nodes.Add(node); if (!node.Add(ref nodes, ref data, nodeIndex)) { Debug.Log("F**k not inserted"); } isLeaf = false; } dataIndex = nodeIndex; isEmpty = false; return(true); } //if the child doesn't exist we create it if (children[bitFlagMiddle] == -1) { //place the new node var node = new LinearNode(bounds.center + boundsSize * 0.25f * offsets[bitFlagMiddle] , Vector3.one * boundsSize * 0.5f, nodes.Count); children[bitFlagMiddle] = nodes.Count; nodes.Add(node); return(node.Add(ref nodes, ref data, nodeIndex)); } return(nodes[children[bitFlagMiddle]].Add(ref nodes, ref data, nodeIndex)); }