Core/Maps: Implemented getting area id from gameobject spawns
This commit is contained in:
@@ -24,6 +24,7 @@ namespace Game.Collision
|
||||
public class WorkerCallback
|
||||
{
|
||||
public virtual void Invoke(Vector3 point, uint entry) { }
|
||||
public virtual void Invoke(Vector3 point, IModel entry) { }
|
||||
public virtual bool Invoke(Ray ray, uint entry, ref float distance, bool pStopAtFirstHit) { return false; }
|
||||
public virtual bool Invoke(Ray r, IModel obj, ref float distance) { return false; }
|
||||
public virtual bool Invoke(Ray ray, uint idx, ref float maxDist) { return false; }
|
||||
@@ -59,7 +60,7 @@ namespace Game.Collision
|
||||
zDist = float.PositiveInfinity;
|
||||
zVec = down;
|
||||
}
|
||||
|
||||
|
||||
List<GroupModel> prims;
|
||||
public GroupModel hit;
|
||||
public float zDist;
|
||||
@@ -245,5 +246,21 @@ namespace Game.Collision
|
||||
PhaseShift _phaseShift;
|
||||
}
|
||||
|
||||
public class DynamicTreeAreaInfoCallback : WorkerCallback
|
||||
{
|
||||
public DynamicTreeAreaInfoCallback(PhaseShift phaseShift)
|
||||
{
|
||||
_phaseShift = phaseShift;
|
||||
}
|
||||
|
||||
public override void Invoke(Vector3 p, IModel obj)
|
||||
{
|
||||
obj.IntersectPoint(p, _areaInfo, _phaseShift);
|
||||
}
|
||||
|
||||
public AreaInfo GetAreaInfo() { return _areaInfo; }
|
||||
|
||||
PhaseShift _phaseShift;
|
||||
AreaInfo _areaInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@ namespace Game.Collision
|
||||
{
|
||||
public class DynamicMapTree
|
||||
{
|
||||
DynTreeImpl impl;
|
||||
|
||||
public DynamicMapTree()
|
||||
{
|
||||
impl = new DynTreeImpl();
|
||||
}
|
||||
|
||||
public void insert(GameObjectModel mdl)
|
||||
{
|
||||
impl.insert(mdl);
|
||||
@@ -128,6 +127,30 @@ namespace Game.Collision
|
||||
else
|
||||
return float.NegativeInfinity;
|
||||
}
|
||||
|
||||
public bool getAreaInfo(float x, float y, ref float z, PhaseShift phaseShift, out uint flags, out int adtId, out int rootId, out int groupId)
|
||||
{
|
||||
flags = 0;
|
||||
adtId = 0;
|
||||
rootId = 0;
|
||||
groupId = 0;
|
||||
|
||||
Vector3 v = new Vector3(x, y, z + 0.5f);
|
||||
DynamicTreeAreaInfoCallback intersectionCallBack = new DynamicTreeAreaInfoCallback(phaseShift);
|
||||
impl.intersectPoint(v, intersectionCallBack);
|
||||
if (intersectionCallBack.GetAreaInfo().result)
|
||||
{
|
||||
flags = intersectionCallBack.GetAreaInfo().flags;
|
||||
adtId = intersectionCallBack.GetAreaInfo().adtId;
|
||||
rootId = intersectionCallBack.GetAreaInfo().rootId;
|
||||
groupId = intersectionCallBack.GetAreaInfo().groupId;
|
||||
z = intersectionCallBack.GetAreaInfo().ground_Z;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DynTreeImpl impl;
|
||||
}
|
||||
|
||||
public class DynTreeImpl : RegularGrid2D<GameObjectModel, BIHWrap<GameObjectModel>>
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Game.Collision
|
||||
{
|
||||
public virtual bool IsSpawned() { return false; }
|
||||
public virtual uint GetDisplayId() { return 0; }
|
||||
public virtual byte GetNameSetId() { return 0; }
|
||||
public virtual bool IsInPhase(PhaseShift phaseShift) { return false; }
|
||||
public virtual Vector3 GetPosition() { return Vector3.Zero; }
|
||||
public virtual float GetOrientation() { return 0.0f; }
|
||||
@@ -111,6 +112,33 @@ namespace Game.Collision
|
||||
return hit;
|
||||
}
|
||||
|
||||
public override void IntersectPoint(Vector3 point, AreaInfo info, PhaseShift phaseShift)
|
||||
{
|
||||
if (!isCollisionEnabled() || !owner.IsSpawned())
|
||||
return;
|
||||
|
||||
if (!owner.IsInPhase(phaseShift))
|
||||
return;
|
||||
|
||||
if (!iBound.contains(point))
|
||||
return;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot * new Vector3(0.0f, 0.0f, -1.0f);
|
||||
float zDist;
|
||||
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
Vector3 modelGround = pModel + zDist * zDirModel;
|
||||
float world_Z = ((modelGround * iInvRot) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
info.adtId = owner.GetNameSetId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdatePosition()
|
||||
{
|
||||
if (iModel == null)
|
||||
|
||||
@@ -27,5 +27,6 @@ namespace Game.Collision
|
||||
|
||||
public virtual bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, PhaseShift phaseShift) { return false; }
|
||||
public virtual bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit) { return false; }
|
||||
public virtual void IntersectPoint(Vector3 point, AreaInfo info, PhaseShift phaseShift) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Game.Collision
|
||||
} while (cell.isValid());
|
||||
}
|
||||
|
||||
void intersectPoint(Vector3 point, WorkerCallback intersectCallback)
|
||||
public void intersectPoint(Vector3 point, WorkerCallback intersectCallback)
|
||||
{
|
||||
Cell cell = Cell.ComputeCell(point.X, point.Y);
|
||||
if (!cell.isValid())
|
||||
|
||||
Reference in New Issue
Block a user