public static void Merge(ref DbvtAabbMm a, ref DbvtAabbMm b, ref DbvtAabbMm r) { //r = a; //SetMin(ref r._min, ref b._min); //SetMax(ref r._max, ref b._max); MathUtil.VectorMin(ref a._min, ref b._min, ref r._min); MathUtil.VectorMax(ref a._max, ref b._max, ref r._max); }
public DbvtNode(Dbvt tree, DbvtNode aparent, ref DbvtAabbMm avolume, Object adata) { volume = avolume; parent = aparent; data = adata; if (data is int) { dataAsInt = (int)data; } }
public static bool NotEqual(ref DbvtAabbMm a, ref DbvtAabbMm b) { return ((a._min.X != b._min.X) || (a._min.Y != b._min.Y) || (a._min.Z != b._min.Z) || (a._max.X != b._max.X) || (a._max.Y != b._max.Y) || (a._max.Z != b._max.Z)); }
public virtual void GetBroadphaseAabb(ref Vector3 aabbMin,ref Vector3 aabbMax) { DbvtAabbMm bounds = new DbvtAabbMm(); if(!m_sets[0].Empty()) { if(!m_sets[1].Empty()) { DbvtAabbMm.Merge(ref m_sets[0].m_root.volume,ref m_sets[1].m_root.volume,ref bounds); } else { bounds=m_sets[0].m_root.volume; } } else if(!m_sets[1].Empty()) { bounds=m_sets[1].m_root.volume; } else { Vector3 temp = Vector3.Zero; bounds=DbvtAabbMm.FromCR(ref temp,0); } aabbMin=bounds.Mins(); aabbMax=bounds.Maxs(); }
public static DbvtAabbMm Merge(ref DbvtAabbMm a, ref DbvtAabbMm b) { DbvtAabbMm res = new DbvtAabbMm(); Merge(ref a, ref b, ref res); return (res); }
public static bool Intersect(DbvtAabbMm a, ref Vector3 b) { return ((b.X >= a._min.X) && (b.Y >= a._min.Y) && (b.Z >= a._min.Z) && (b.X <= a._max.X) && (b.Y <= a._max.Y) && (b.Z <= a._max.Z)); }
public static float Proximity(ref DbvtAabbMm a, ref DbvtAabbMm b) { Vector3 d = (a._min + a._max) - (b._min + b._max); return (System.Math.Abs(d.X) + System.Math.Abs(d.Y) + System.Math.Abs(d.Z)); }
public bool Contain(ref DbvtAabbMm a) { return ((_min.X <= a._min.X) && (_min.Y <= a._min.Y) && (_min.Z <= a._min.Z) && (_max.X >= a._max.X) && (_max.Y >= a._max.Y) && (_max.Z >= a._max.Z)); }
public static bool Intersect(ref DbvtAabbMm a, ref DbvtAabbMm b) { return ((a._min.X <= b._max.X) && (a._max.X >= b._min.X) && (a._min.Y <= b._max.Y) && (a._max.Y >= b._min.Y) && (a._min.Z <= b._max.Z) && (a._max.Z >= b._min.Z)); }
public static void CollideTV(DbvtNode root, ref DbvtAabbMm volume, Collide collideable) { if (root != null) { Stack<DbvtNode> stack = new Stack<DbvtNode>(SIMPLE_STACKSIZE); stack.Push(root); do { DbvtNode n = stack.Pop(); if (DbvtAabbMm.Intersect(ref n.volume, ref volume)) { if (n.IsInternal()) { stack.Push(n._children[0]); stack.Push(n._children[1]); } else { collideable.Process(n); } } } while (stack.Count > 0); } }
// volume+edge lengths public static float Size(ref DbvtAabbMm a) { Vector3 edges = a.Lengths(); return (edges.X * edges.Y * edges.Z + edges.X + edges.Y + edges.Z); }
public bool Update(DbvtNode leaf, ref DbvtAabbMm volume, float margin) { if (leaf.volume.Contain(ref volume)) { return (false); } volume.Expand(new Vector3(margin, margin, margin)); Update(leaf, ref volume); return (true); }
public bool Update(DbvtNode leaf, ref DbvtAabbMm volume, ref Vector3 velocity) { if (leaf.volume.Contain(ref volume)) { return (false); } volume.SignedExpand(velocity); Update(leaf, ref volume); return (true); }
public void Update(DbvtNode leaf, ref DbvtAabbMm volume) { DbvtNode root = RemoveLeaf(this, leaf); if (root != null) { if (m_lkhd >= 0) { for (int i = 0; (i < m_lkhd) && (root.parent != null); ++i) { root = root.parent; } } else { root = Root; } } leaf.volume = volume; InsertLeaf(this, root, leaf); }
public DbvtNode Insert(ref DbvtAabbMm box, Object data) { DbvtNode leaf = new DbvtNode(this, null, ref box, data); InsertLeaf(this, Root, leaf); ++m_leaves; return leaf; }
//public static bool Intersect(ref DbvtAabbMm a, ref DbvtAabbMm b) //{ // Vector3 amin = a.Mins(); // Vector3 amax = a.Maxs(); // Vector3 bmin = b.Mins(); // Vector3 bmax = b.Maxs(); // return ((amin.X <= bmin.X) && // (amin.Y <= bmax.Y) && // (amin.Z <= bmax.Z) && // (amax.X >= bmin.X) && // (amax.Y >= bmin.Y) && // (amax.Z >= bmin.Z)); //} //public static bool Intersect(ref DbvtAabbMm a, ref Vector3 b) //{ // Vector3 amin = a.Mins(); // Vector3 amax = a.Maxs(); // return ((b.X >= amin.X) && // (b.Y >= amin.Y) && // (b.Z >= amin.Z) && // (b.X <= amax.X) && // (b.Y <= amax.Y) && // (b.Z <= amax.Z)); //} public static bool Intersect(ref DbvtAabbMm a, ref Vector3 org, ref Vector3 invdir, int[] signs) { Vector3 amin = a.Mins(); Vector3 amax = a.Maxs(); Vector3[] bounds = new Vector3[] { amin, amax }; float txmin = (bounds[signs[0]].X - org.X) * invdir.X; float txmax = (bounds[1 - signs[0]].X - org.X) * invdir.X; float tymin = (bounds[signs[1]].Y - org.Y) * invdir.Y; float tymax = (bounds[1 - signs[1]].Y - org.Y) * invdir.Y; if ((txmin > tymax) || (tymin > txmax)) return (false); if (tymin > txmin) txmin = tymin; if (tymax < txmax) txmax = tymax; float tzmin = (bounds[signs[2]].Z - org.Z) * invdir.Z; float tzmax = (bounds[1 - signs[2]].Z - org.Z) * invdir.Z; if ((txmin > tzmax) || (tzmin > txmax)) return (false); if (tzmin > txmin) txmin = tzmin; if (tzmax < txmax) txmax = tzmax; return (txmax > 0); }