/// <summary> /// Gets a vector with the maximum x,y and z values of both vectors. /// </summary> /// <param name="value1">The first value.</param> /// <param name="value2">The second value.</param> /// <returns>A vector with the maximum x,y and z values of both vectors.</returns> #region public static JVector Max(JVector value1, JVector value2) public static TSVector Max(TSVector value1, TSVector value2) { TSVector result; TSVector.Max(ref value1, ref value2, out result); return(result); }
void BuildQuadtree(List <IAgentBehaviour> agents, Quadtree <QTData> tree) { // foreach(KeyValuePair< int, List < IAgentBehaviour >> kv in _agents) { tree.Clear(); if (agents.Count > 0) { QTBound bounds = QTBound.MinMaxQTBound(agents[0].position, agents[0].position); int count = agents.Count; for (int i = 1; i < count; i++) { //if(agents[i]==null || agents[i]==null) //{ // continue; //} TSVector p = agents[i].position; bounds = QTBound.MinMaxQTBound(TSVector.Min(bounds.min, p), TSVector.Max(bounds.max, p)); } tree.SetBounds(bounds); for (int i = 0; i < count; i++) { tree.Insert(agents[i]); } // tree.DebugDraw(); } tree.CalculateSpeeds(); } }
/// <summary> /// Creates a new box containing the two given ones. /// </summary> /// <param name="original">First box.</param> /// <param name="additional">Second box.</param> /// <param name="result">A JBBox containing the two given boxes.</param> public static void CreateMerged(ref TSBBox original, ref TSBBox additional, out TSBBox result) { TSVector vector; TSVector vector2; TSVector.Min(ref original.min, ref additional.min, out vector2); TSVector.Max(ref original.max, ref additional.max, out vector); result.min = vector2; result.max = vector; }
/// <summary> /// Expands a bounding box with the volume 0 by all points /// given. /// </summary> /// <param name="points">A array of JVector.</param> /// <returns>The resulting bounding box containing all points.</returns> #region public static JBBox CreateFromPoints(JVector[] points) public static TSBBox CreateFromPoints(TSVector[] points) { TSVector vector3 = new TSVector(FP.MaxValue); TSVector vector2 = new TSVector(FP.MinValue); for (int i = 0; i < points.Length; i++) { TSVector.Min(ref vector3, ref points[i], out vector3); TSVector.Max(ref vector2, ref points[i], out vector2); } return(new TSBBox(vector3, vector2)); }
/// <summary> /// Builds the octree. /// </summary> #region public void BuildOctree() public void BuildOctree() { // create tri and tri bounding box arrays triBoxes = new TSBBox[tris.Length]; // create an infinite size root box rootNodeBox = new TSBBox(new TSVector(FP.PositiveInfinity, FP.PositiveInfinity, FP.PositiveInfinity), new TSVector(FP.NegativeInfinity, FP.NegativeInfinity, FP.NegativeInfinity)); for (int i = 0; i < tris.Length; i++) { TSVector.Min(ref positions[tris[i].I1], ref positions[tris[i].I2], out triBoxes[i].min); TSVector.Min(ref positions[tris[i].I0], ref triBoxes[i].min, out triBoxes[i].min); TSVector.Max(ref positions[tris[i].I1], ref positions[tris[i].I2], out triBoxes[i].max); TSVector.Max(ref positions[tris[i].I0], ref triBoxes[i].max, out triBoxes[i].max); // get size of the root box TSVector.Min(ref rootNodeBox.min, ref triBoxes[i].min, out rootNodeBox.min); TSVector.Max(ref rootNodeBox.max, ref triBoxes[i].max, out rootNodeBox.max); } List <BuildNode> buildNodes = new List <BuildNode>(); buildNodes.Add(new BuildNode()); buildNodes[0].box = rootNodeBox; TSBBox[] children = new TSBBox[8]; for (int triNum = 0; triNum < tris.Length; triNum++) { int nodeIndex = 0; TSBBox box = rootNodeBox; while (box.Contains(ref triBoxes[triNum]) == TSBBox.ContainmentType.Contains) { int childCon = -1; for (int i = 0; i < 8; ++i) { CreateAABox(ref box, (EChild)i, out children[i]); if (children[i].Contains(ref triBoxes[triNum]) == TSBBox.ContainmentType.Contains) { // this box contains the tri, it can be the only one that does, // so we can stop our child search now and recurse into it childCon = i; break; } } // no child contains this tri completely, so it belong in this node if (childCon == -1) { buildNodes[nodeIndex].triIndices.Add(triNum); break; } else { // do we already have this child int childIndex = -1; for (int index = 0; index < buildNodes[nodeIndex].nodeIndices.Count; ++index) { if (buildNodes[buildNodes[nodeIndex].nodeIndices[index]].childType == childCon) { childIndex = index; break; } } if (childIndex == -1) { // nope create child BuildNode parentNode = buildNodes[nodeIndex]; BuildNode newNode = new BuildNode(); newNode.childType = childCon; newNode.box = children[childCon]; buildNodes.Add(newNode); nodeIndex = buildNodes.Count - 1; box = children[childCon]; parentNode.nodeIndices.Add(nodeIndex); } else { nodeIndex = buildNodes[nodeIndex].nodeIndices[childIndex]; box = children[childCon]; } } } } // now convert to the tighter Node from BuildNodes nodes = new Node[buildNodes.Count]; nodeStackPool = new ArrayResourcePool <ushort>(buildNodes.Count); //nodeStack = new UInt16[buildNodes.Count]; for (int i = 0; i < nodes.Length; i++) { nodes[i].nodeIndices = new UInt16[buildNodes[i].nodeIndices.Count]; for (int index = 0; index < nodes[i].nodeIndices.Length; ++index) { nodes[i].nodeIndices[index] = (UInt16)buildNodes[i].nodeIndices[index]; } nodes[i].triIndices = new int[buildNodes[i].triIndices.Count]; buildNodes[i].triIndices.CopyTo(nodes[i].triIndices); nodes[i].box = buildNodes[i].box; } buildNodes.Clear(); buildNodes = null; }
public void AddPoint(ref TSVector point) { TSVector.Max(ref this.max, ref point, out this.max); TSVector.Min(ref this.min, ref point, out this.min); }
public void AddPoint(TSVector point) { TSVector.Max(this.max, point, out this.max); TSVector.Min(this.min, point, out this.min); }