a few more changes on parcels location finding

LSLKeyTest
UbitUmarov 2015-12-15 18:19:08 +00:00
parent a9e8bd2884
commit 9327bb2546
1 changed files with 44 additions and 45 deletions

View File

@ -5787,8 +5787,6 @@ Environment.Exit(1);
ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, pos.X, pos.Y, excludeParcel); ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, pos.X, pos.Y, excludeParcel);
Vector3 retPos = Vector3.Zero;
if (nearestParcel != null) if (nearestParcel != null)
{ {
Vector2? nearestPoint = null; Vector2? nearestPoint = null;
@ -5803,14 +5801,8 @@ Environment.Exit(1);
if (nearestPoint != null) if (nearestPoint != null)
{ {
retPos.X = nearestPoint.Value.X; return GetPositionAtAvatarHeightOrGroundHeight(avatar,
retPos.Y = nearestPoint.Value.Y; nearestPoint.Value.X, nearestPoint.Value.Y);
float h = GetGroundHeight(retPos.X, retPos.Y) + 0.8f;
if(pos.Z > h)
retPos.Z = pos.Z;
else
retPos.Z = h;
return retPos;
} }
ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y); ILandObject dest = LandChannel.GetLandObject(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y);
@ -5845,18 +5837,30 @@ Environment.Exit(1);
public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel) public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
{ {
List<ILandObject> all = AllParcels(); if(LandChannel == null)
float minParcelDistance = float.MaxValue; return null;
List<ILandObject> all = LandChannel.AllParcels();
if(all == null || all.Count == 0)
return null;
float minParcelDistanceSQ = float.MaxValue;
ILandObject nearestParcel = null; ILandObject nearestParcel = null;
Vector2 curCenter;
float parcelDistanceSQ;
foreach (var parcel in all) foreach (var parcel in all)
{ {
if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel) if (parcel != excludeParcel && !parcel.IsEitherBannedOrRestricted(avatarId))
{ {
float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); curCenter = parcel.CenterPoint;
if (parcelDistance < minParcelDistance) curCenter.X -= x;
curCenter.Y -= y;
parcelDistanceSQ = curCenter.LengthSquared();
if (parcelDistanceSQ < minParcelDistanceSQ)
{ {
minParcelDistance = parcelDistance; minParcelDistanceSQ = parcelDistanceSQ;
nearestParcel = parcel; nearestParcel = parcel;
} }
} }
@ -5865,57 +5869,52 @@ Environment.Exit(1);
return nearestParcel; return nearestParcel;
} }
private List<ILandObject> AllParcels()
{
return LandChannel.AllParcels();
}
private Vector2 GetParcelSafeCorner(ILandObject parcel) private Vector2 GetParcelSafeCorner(ILandObject parcel)
{ {
return parcel.StartPoint; Vector2 place = parcel.StartPoint;
} place.X += 2f;
place.Y += 2f;
private float GetParcelDistancefromPoint(ILandObject parcel, float x, float y) return place;
{
return Vector2.Distance(new Vector2(x, y), parcel.CenterPoint);
} }
private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar) private Vector3 GetNearestRegionEdgePosition(ScenePresence avatar)
{ {
float xdistance = avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2 float posX = avatar.AbsolutePosition.X;
? avatar.AbsolutePosition.X : RegionInfo.RegionSizeX - avatar.AbsolutePosition.X; float posY = avatar.AbsolutePosition.Y;
float ydistance = avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2 float regionSizeX = RegionInfo.RegionSizeX;
? avatar.AbsolutePosition.Y : RegionInfo.RegionSizeY - avatar.AbsolutePosition.Y; float halfRegionSizeX = regionSizeX * 0.5f;
float regionSizeY = RegionInfo.RegionSizeY;
float halfRegionSizeY = regionSizeY * 0.5f;
float xdistance = posX < halfRegionSizeX ? posX : regionSizeX - posX;
float ydistance = posY < halfRegionSizeY ? posY : regionSizeY - posY;
//find out what vertical edge to go to //find out what vertical edge to go to
if (xdistance < ydistance) if (xdistance < ydistance)
{ {
if (avatar.AbsolutePosition.X < RegionInfo.RegionSizeX / 2) if (posX < halfRegionSizeX)
{ return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.5f, posY);
return GetPositionAtAvatarHeightOrGroundHeight(avatar, 0.0f, avatar.AbsolutePosition.Y);
}
else else
{ return GetPositionAtAvatarHeightOrGroundHeight(avatar, regionSizeX - 0.5f, posY);
return GetPositionAtAvatarHeightOrGroundHeight(avatar, RegionInfo.RegionSizeY, avatar.AbsolutePosition.Y);
}
} }
//find out what horizontal edge to go to //find out what horizontal edge to go to
else else
{ {
if (avatar.AbsolutePosition.Y < RegionInfo.RegionSizeY / 2) if (posY < halfRegionSizeY)
{ return GetPositionAtAvatarHeightOrGroundHeight(avatar, posX, 0.5f);
return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, 0.0f);
}
else else
{ return GetPositionAtAvatarHeightOrGroundHeight(avatar, posX, regionSizeY - 0.5f);
return GetPositionAtAvatarHeightOrGroundHeight(avatar, avatar.AbsolutePosition.X, RegionInfo.RegionSizeY);
}
} }
} }
private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y) private Vector3 GetPositionAtAvatarHeightOrGroundHeight(ScenePresence avatar, float x, float y)
{ {
Vector3 ground = GetPositionAtGround(x, y); Vector3 ground = GetPositionAtGround(x, y);
if(avatar.Appearance != null)
ground.Z += avatar.Appearance.AvatarHeight * 0.5f;
else
ground.Z += 0.8f;
if (avatar.AbsolutePosition.Z > ground.Z) if (avatar.AbsolutePosition.Z > ground.Z)
{ {
ground.Z = avatar.AbsolutePosition.Z; ground.Z = avatar.AbsolutePosition.Z;