private object AsRLocation(Simulator simulator, Vector3d targetPos, SimPosition pos) { Vector3 lpos = new Vector3((float)targetPos.X, (float)targetPos.Y, (float)targetPos.Z); SimRegion r = SimRegion.GetRegion(simulator); if (targetPos == Vector3d.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) return new SimHeading(pos); return SimHeading.UNKNOWN; } return r; } return new SimHeading(pos, lpos); }
private object AsLocation(Simulator simulator, Vector3 position, SimPosition pos) { SimRegion r = SimRegion.GetRegion(simulator); if (position == Vector3.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) return new SimHeading(pos); return SimHeading.UNKNOWN; } return r; } Quaternion rot = Quaternion.Identity; if (pos != null && pos.IsRegionAttached) { rot = pos.SimRotation; } return new SimHeading(r.GetPathStore(position), position, rot); }
public override CmdResult ExecuteRequest(CmdRequest args) { if (args.Length < 1) { return(ShowUsage()); // " goto sim/x/y/z"; } int argsUsed; SimPosition position = WorldSystem.GetVector(args, out argsUsed); if (position == null) { return(Failure("Teleport - Cannot resolve to a location: " + args.str)); } SimPathStore ps = position.PathStore; ulong handle = SimRegion.GetRegionHandle(ps); TheSimAvatar.StopMoving(); if (Client.Self.Teleport(handle, position.SimPosition)) { return(Success("Teleported to " + Client.Network.CurrentSim)); } else { return(Failure("Teleport failed: " + Client.Self.TeleportMessage)); } }
public string DistanceVectorString(SimPosition pos) { Vector3 loc = pos.SimPosition; SimPathStore R = pos.PathStore; return String.Format("{0:0.0#}m ", Vector3d.Distance(GlobalPosition, pos.GlobalPosition)) + String.Format("{0}/{1:0.0#}/{2:0.0#}/{3:0.0#}", R.RegionName, loc.X, loc.Y, loc.Z); }
public string RezAll(BotInventoryEval man, InventoryBase b, SimPosition dest) { string ret = ""; var manager = man.Manager; if (b is InventoryItem) { InventoryItem item = b as InventoryItem; bool canCopy = (item.Permissions.OwnerMask & PermissionMask.Copy) == PermissionMask.Copy; ret += item.Name + nl; if (dest == null) { Simulator sim = Client.Network.CurrentSim; Client.Inventory.RequestRestoreRezFromInventory(sim, item, item.UUID); } else { Simulator sim = SimRegion.GetRegion(dest.GlobalPosition).TheSimulator; Client.Inventory.RequestRezFromInventory(sim, dest.SimRotation, dest.SimPosition, item, UUID.Zero); } } else if (b is InventoryFolder) { InventoryFolder folder = b as InventoryFolder; List<InventoryBase> folderContents = man.FolderContents(folder.UUID); if (folderContents != null) foreach (InventoryBase list in folderContents) { ret += RezAll(man, list, dest); } } return ret; }
public override CmdResult ExecuteRequest(CmdRequest args) { float distance = 2.0f; int argsUsed; SimPosition simObject = WorldSystem.GetVector(args, out argsUsed); if (simObject == null) { return(Failure("Cannot find " + args.str)); } if (!simObject.IsRegionAttached) { return(Failure("Cannot get SimPosition of " + simObject)); } distance = 0.5f + simObject.GetSizeDistance(); if (argsUsed < args.Length) { float d; if (float.TryParse(args[argsUsed], out d)) { distance = d; } } WriteLine("WalkTo {0} {1}", simObject, distance); WorldSystem.TheSimAvatar.SimpleMoveTo(simObject.GlobalPosition, distance, 10, false); WorldSystem.TheSimAvatar.StopMoving(); return(Success(WorldSystem.TheSimAvatar.DistanceVectorString(simObject))); }
public override CmdResult ExecuteRequest(CmdRequest args) { // Get the agent's current "patch" position, where each patch of // wind data is a 16x16m square int argsUsed; SimPosition aPos = WorldSystem.GetVector(args, out argsUsed); Vector3 agentPos = aPos.SimPosition; int xPos = (int)Utils.Clamp(agentPos.X, 0.0f, 255.0f) / 16; int yPos = (int)Utils.Clamp(agentPos.Y, 0.0f, 255.0f) / 16; Simulator sim = SimRegion.GetRegion(aPos.GlobalPosition).TheSimulator; if (sim == null) { return(Failure("Unknown simulator for " + aPos)); } ulong handle = sim.Handle; if (sim.WindSpeeds == null) { return(Failure("Unknown wind speed at sim: " + sim)); } Vector2[] windSpeeds = sim.WindSpeeds; Vector2 windSpeed = windSpeeds[yPos * 16 + xPos]; return(Success("Wind speed at " + aPos + " is " + windSpeed)); }
public BotAction GetNextAction() { BotAction act = CurrentAction; List <BotAction> KnownBotAcions = GetPossibleActions(MaxThinkAboutDistance, MaxSupportedZChange); lock (KnownBotAcions) { if (KnownBotAcions.Count > 0) { act = KnownBotAcions[0];// (BotAction)FindBestUsage(KnownBotAcions); } if (act == null) { SimRegion R = Actor.GetSimRegion(); if (R == null) { return(new CommandAction(Actor, "anim shrug")); } Vector3d v3d = R.LocalToGlobal(new Vector3(MyRandom.Next(250) + 5, MyRandom.Next(250) + 5, Actor.SimPosition.Z)); Actor.Debug("MoveToLocation: " + Actor.DistanceVectorString(v3d)); SimPosition WP = SimWaypointImpl.CreateGlobal(v3d); act = new MoveToLocation(Actor, WP); } return(act); } }
public override CmdResult ExecuteRequest(CmdRequest args) { if (args.Length < 1) { return(ShowUsage()); // "rezitem [avatar5,prev,sim/123/232/23@360] "fairyverse Goodies" [item2] [item3] [...]"; } int argsUsed = 0; string lowerMatch = args[0].ToLower(); SimPosition dest = null; if (!args.ContainsFlag("--prev")) { dest = WorldSystem.GetVector(args.GetProperty("location"), out argsUsed); } var man = Client.BotInventory; var found = man.FindAll(args.GetProperty("items"), true, inventoryName => Failure("No inventory item named " + inventoryName + " found.")); foreach (InventoryBase ib in man.ItemsOnly(found)) { RezAll(man, ib, dest); } return(Success("found.Count=" + found.Count)); }
public SimHeading(SimPosition pos) { late = pos; if (pos.IsRegionAttached) { InitFromPos(pos); } }
public string DistanceVectorString(SimPosition pos) { Vector3 loc = pos.SimPosition; SimPathStore R = pos.PathStore; return(String.Format("{0:0.0#}m ", Vector3d.Distance(GlobalPosition, pos.GlobalPosition)) + String.Format("{0}/{1:0.0#}/{2:0.0#}/{3:0.0#}", R.RegionName, loc.X, loc.Y, loc.Z)); }
private void InitFromPos(SimPosition position) { this.reg = position.PathStore; this.pos = position.SimPosition + lateV3; this.rot = position.SimRotation; late = null; lateV3 = Vector3.Zero; }
public override CmdResult ExecuteRequest(CmdRequest args) { int argsUsed; SimPosition simObject = WorldSystem.GetVector(args.GetProperty("position"), out argsUsed); WriteLine("turnto {0}", simObject); WorldSystem.TheSimAvatar.TurnToward(simObject); return(Success(WorldSystem.TheSimAvatar.DistanceVectorString(simObject))); }
public FollowerAction(SimAvatar impl, SimPosition position) : base(impl,position) { TheBot = (SimControllableAvatar)impl; maxDistance = 3;// position.GetSizeDistance(); Target = position; FollowThread = new Thread(FollowLoop); FollowThread.Name = DebugName; }
public SimHeading(SimPosition pos, Vector3 vector3) { late = pos; lateV3 = vector3; if (pos.IsRegionAttached) { InitFromPos(pos); } }
public FollowerAction(SimAvatar impl, SimPosition position) : base(impl, position) { TheBot = (SimControllableAvatar)impl; maxDistance = 3;// position.GetSizeDistance(); Target = position; FollowThread = new Thread(FollowLoop); FollowThread.Name = DebugName; }
public void SelectedRemove(SimPosition o) { if (!SelectedObjects.Remove(o) || !_SelectedBeam) { return; } _SelectedBeam = false; SelectedBeam = true; }
public string DistanceVectorString(SimPosition obj) { if (!obj.IsRegionAttached) { Vector3 loc = obj.SimPosition; SimPathStore R = obj.PathStore; return(String.Format("unknown relative {0}/{1:0.0#}/{2:0.0#}/{3:0.0#}", R.RegionName, loc.X, loc.Y, loc.Z)); } return(DistanceVectorString(obj.GlobalPosition)); }
public string DistanceVectorString(SimPosition obj) { if (!obj.IsRegionAttached) { Vector3 loc = obj.SimPosition; SimPathStore R = obj.PathStore; return String.Format("unknown relative {0}/{1:0.0#}/{2:0.0#}/{3:0.0#}", R.RegionName, loc.X, loc.Y, loc.Z); } return DistanceVectorString(obj.GlobalPosition); }
public FlyToAction(SimAvatar impl, SimPosition position) : base(impl, position) { // set in base //TheBot = impl; //Target = position; maxDistance = position.GetSizeDistance(); FollowThread = new Thread(FollowLoop); FollowThread.Name = ToString(); callback = Objects_OnObjectUpdated; }
public void SelectedAdd(SimPosition o) { if (!SelectedObjects.AddTo(o) || !_SelectedBeam) return; if (true) { _SelectedBeam = false; SelectedBeam = true; return; } EffectBeamInfo info = new EffectBeamInfo(GetGridClient()); info.SetPointing(o, 3); BeamInfos.AddTo(info); }
public SimCollisionPlaneMover(SimMover mover, SimPosition finalGoal, double finalDistance) : base(mover, finalGoal, finalDistance) { CollisionPlane MoverPlane = MoverPlaneZ; float startZ = (float)SimPathStore.CalcStartZ(mover.SimPosition.Z, finalGoal.SimPosition.Z); double diff = MoverPlane.MinZ - startZ; MoverPlane.MinZ = startZ; MoverPlane.MaxZ = startZ + 3; if (diff > .5 || diff < -0.5f) { MoverPlane.HeightMapNeedsUpdate = true; } }
public override CmdResult ExecuteRequest(CmdRequest args) { RadegastInstance instance = TheBotClient.TheRadegastInstance; foreach (var set in BeamInfos) { set.UnSetPointing(); } BeamInfos.Clear(); int used; if (args.Length == 0) { if (instance != null) { instance.State.UnSetPointing(); } TheSimAvatar.SelectedBeam = !TheSimAvatar.SelectedBeam; return(Success("SelectedBeam = " + TheSimAvatar.SelectedBeam)); } var targets = args.GetProperty("targets"); List <SimObject> PS = WorldSystem.GetPrimitives(targets, out used); GridClient grc = TheBotClient; if (PS.Count == 0) { SimPosition pos = WorldSystem.GetVector(targets, out used); if (pos != null) { EffectBeamInfo info = new EffectBeamInfo(grc); info.SetPointing(pos, 3); BeamInfos.AddTo(info); return(Success(Name + " on " + pos)); } return(Failure(string.Format("Cant find {0}", string.Join(" ", args)))); } foreach (var o in PS) { EffectBeamInfo info = new EffectBeamInfo(grc); info.SetPointing(o, 3); BeamInfos.AddTo(info); Primitive p = o.Prim; if (p != null && instance != null) { instance.State.SetPointing(p, 3); } } return(Success(Name + " on " + PS.Count)); }
public static SimPosition GetSimPositionByName(string arg) { int argsUsed; WorldObjects wo = WorldObjects.GridMaster; string[] args = Parser.Parse(arg); SimPosition prim = wo.GetSimObjectS(args, out argsUsed); if (prim != null) { return(prim); } prim = wo.GetVector(args, out argsUsed); return(prim); }
public void SelectedAdd(SimPosition o) { if (!SelectedObjects.AddTo(o) || !_SelectedBeam) { return; } if (true) { _SelectedBeam = false; SelectedBeam = true; return; } EffectBeamInfo info = new EffectBeamInfo(GetGridClient()); info.SetPointing(o, 3); BeamInfos.AddTo(info); }
private object AsRLocation(Simulator simulator, Vector3d targetPos, SimPosition pos) { Vector3 lpos = new Vector3((float)targetPos.X, (float)targetPos.Y, (float)targetPos.Z); SimRegion r = SimRegion.GetRegion(simulator); if (targetPos == Vector3d.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) { return(new SimHeading(pos)); } return(SimHeading.UNKNOWN); } return(r); } return(new SimHeading(pos, lpos)); }
public SimAbstractMover(SimMover mover, SimPosition finalGoal, double finalDistance) { Mover = mover; SimPathStore.DebugDelegate = mover.Debug; FinalDistance = finalDistance; //var vFinalLocation = finalGoal.UsePosition.GlobalPosition; // FinalLocation = vFinalLocation; FinalPosition = finalGoal; var ps = mover.PathStore; if (ps != null) { ps.LastSimMover = mover; } else { Debug("No pathSTore!?!"); } }
public override CmdResult ExecuteRequest(CmdRequest args) { if (args.Length < 2) { return(ShowUsage()); // " moveprim prim [x y [z]]"; } int used; List <SimObject> PS = WorldSystem.GetSingleArg(args, out used); if (IsEmpty(PS)) { return(Failure("Cannot find prim: " + args.str)); } string[] to = Parser.SplitOff(args, used); SimPosition aPos = WorldSystem.GetVector(to, out used); if (aPos == null) { return(Failure("Cannot find position: " + string.Join(" ", to))); } if (!aPos.IsRegionAttached) { return(Failure("!IsRegionAttached: " + aPos)); } List <SimObject> TODO = new List <SimObject>(); foreach (var O in PS) { if (!O.IsRegionAttached) { return(Failure("!IsRegionAttached: " + O)); } TODO.Add(O); } foreach (var O in TODO) { SimPosition localPos = WorldSystem.GetVector(to, out used, O); Vector3d local = localPos.GlobalPosition; O.SetObjectPosition(local); } return(Success("acted on " + PS.Count)); }
public override CmdResult ExecuteRequest(CmdRequest args) { int argsUsed; if (args.Length < 1) { return(ShowUsage()); // " moveto x y z"; } SimPosition position = WorldSystem.GetVector(args, out argsUsed); if (position == null) { return(Failure("Coulnd not resolve location: " + args.str)); } Vector3d g = position.GlobalPosition; Client.Self.AutoPilot(g.X, g.Y, g.Z); return(Success(string.Format("Attempting to move to (AutoPilot) <{0},{1},{2}>", g.X, g.Y, g.Z))); }
public bool GotoSimRoute(SimPosition pos) { bool IsFake; for (int i = 0; i < 19; i++) { Debug("PLAN GotoTarget: " + pos); // StopMoving(); if (TryGotoTarget(pos, out IsFake)) { Mover.StopMoving(); Mover.TurnToward(pos.GlobalPosition); Debug("SUCCESS GotoTarget: " + pos); return(true); } //TurnToward(pos); double posDist = Mover.Distance(pos); if (posDist <= pos.GetSizeDistance() + 0.5) { Debug("OK GotoTarget: " + pos); return(true); } TurnAvoid += 115; while (TurnAvoid > 360) { TurnAvoid -= 360; } //Vector3d newPost = GetLeftPos(TurnAvoid, 4f); //StopMoving(); //Debug("MOVELEFT GotoTarget: " + pos); //MoveTo(newPost, 2f, 4); if (IsFake) { break; } } Debug("FAILED GotoTarget: " + pos); return(false); }
public void SetPointing(SimPosition prim, int numBeans) { UnSetPointing(); //client.Self.Movement.TurnToward(prim.Position); pointID = UUID.Random(); sphereID = UUID.Random(); beamID = new List <UUID>(); beamTarget = new List <Vector3d>(); targetPrim = prim; this.numBeans = numBeans; SimObject O = prim as SimObject; if (O != null) { client.Self.PointAtEffect(effectSource, O.ID, Vector3d.Zero, PointAtType.Select, pointID); } else { client.Self.PointAtEffect(effectSource, UUID.Zero, prim.GlobalPosition, PointAtType.Select, pointID); } for (int i = 0; i < numBeans; i++) { UUID newBeam = UUID.Random(); beamID.Add(newBeam); beamTarget.Add(Vector3d.Zero); } for (int i = 1; i < numBeans; i++) { UUID newBeam = UUID.Random(); beamID.Add(newBeam); beamTarget.Add(Vector3d.Zero); } beamTimer.Interval = 1000; beamTimer.Enabled = true; }
public void SetPointing(SimPosition prim, int numBeans) { UnSetPointing(); //client.Self.Movement.TurnToward(prim.Position); pointID = UUID.Random(); sphereID = UUID.Random(); beamID = new List<UUID>(); beamTarget = new List<Vector3d>(); targetPrim = prim; this.numBeans = numBeans; SimObject O = prim as SimObject; if (O != null) { client.Self.PointAtEffect(effectSource, O.ID, Vector3d.Zero, PointAtType.Select, pointID); } else { client.Self.PointAtEffect(effectSource, UUID.Zero, prim.GlobalPosition, PointAtType.Select, pointID); } for (int i = 0; i < numBeans; i++) { UUID newBeam = UUID.Random(); beamID.Add(newBeam); beamTarget.Add(Vector3d.Zero); } for (int i = 1; i < numBeans; i++) { UUID newBeam = UUID.Random(); beamID.Add(newBeam); beamTarget.Add(Vector3d.Zero); } beamTimer.Interval = 1000; beamTimer.Enabled = true; }
public string RezAll(BotInventoryEval man, InventoryBase b, SimPosition dest) { string ret = ""; var manager = man.Manager; if (b is InventoryItem) { InventoryItem item = b as InventoryItem; bool canCopy = (item.Permissions.OwnerMask & PermissionMask.Copy) == PermissionMask.Copy; ret += item.Name + nl; if (dest == null) { Simulator sim = Client.Network.CurrentSim; Client.Inventory.RequestRestoreRezFromInventory(sim, item, item.UUID); } else { Simulator sim = SimRegion.GetRegion(dest.GlobalPosition).TheSimulator; Client.Inventory.RequestRezFromInventory(sim, dest.SimRotation, dest.SimPosition, item, UUID.Zero); } } else if (b is InventoryFolder) { InventoryFolder folder = b as InventoryFolder; List <InventoryBase> folderContents = man.FolderContents(folder.UUID); if (folderContents != null) { foreach (InventoryBase list in folderContents) { ret += RezAll(man, list, dest); } } } return(ret); }
/// <summary> /// /// </summary> /// <param name="pos"></param> /// <param name="IsFake"></param> /// <returns></returns>s public bool TryGotoTarget(SimPosition pos, out bool IsFake) { IsFake = false; SimMoverState state = SimMoverState.TRYAGAIN; while (state == SimMoverState.TRYAGAIN) { SimWaypoint target = (SimWaypoint)pos; IList <SimRoute> routes = (IList <SimRoute>)GetRouteList(target, out IsFake); if (routes == null) { return(false); } SimRouteMover ApproachPlan = new SimRouteMover(Mover, routes, pos.GlobalPosition, pos.GetSizeDistance()); state = ApproachPlan.Goto(); if (state == SimMoverState.COMPLETE) { return(true); } } return(false); //== SimMoverState.COMPLETE; }
private object AsLocation(Simulator simulator, Vector3 position, SimPosition pos) { SimRegion r = SimRegion.GetRegion(simulator); if (position == Vector3.Zero) { if (r == null) { if (pos != null && pos.IsRegionAttached) { return(new SimHeading(pos)); } return(SimHeading.UNKNOWN); } return(r); } Quaternion rot = Quaternion.Identity; if (pos != null && pos.IsRegionAttached) { rot = pos.SimRotation; } return(new SimHeading(r.GetPathStore(position), position, rot)); }
public SimOffsetPosition(SimPosition pos, Vector3 vector3, bool isRotated) { _late = pos; _lateV3 = vector3; _isRotated = isRotated; }
public override sealed bool Update(SimPosition simObject) { //if (!WorldObjects.MaintainCollisions) return false; if (!simObject.IsRegionAttached) return false; if (MeshOnlySolids && !((MeshableObject) simObject).IsSolid) return false; Quaternion Rotation = simObject.SimRotation; Vector3 Scale = Prim.Scale; //.GetSimScale(); Vector3 Position = simObject.SimPosition; #if COLLIDER_ODE LastSize = new PhysicsVector(1, 1, 1); // we scaled the PrimMesh already! LastRotation = Quaternion.Identity; // we rotated the PrimMesh already! LastPosition = ToPhysicsVector(Position); // we hadn't done position though #endif //pbs. //List<Mesh> MeshList = new List<Mesh>(); //PrimMesh primMesh; //if (false) //{ // // Add Low PrimMesh (IdealistViewer code) // primMesh = PrimitiveToPrimMesh(simObject.thePrim, LevelOfDetail.Low, Scale, Rotation); // AddMesh(primMesh); //} // Add High PrimMesh (IdealistViewer code) Mesh mesh = PrimitiveToMesh(Prim, Scale, Rotation); #if COLLIDER_ODE this.mesh = mesh; if (!RootObject.IsPhantom) physicsActor = GetPhysicsActor(); #endif //MeshList.Add(mesh); //if (false) //{ // // Add based on PrimitiveBaseShape (OpenSim Meshmerizer code) // PrimitiveBaseShape primShape = PrimToBaseShape(simObject.thePrim); // Mesh mesh = CreateMesh(simObject.ToString(), primShape, // new PhysicsVector(Scale.X, Scale.Y, Scale.Z), 32f, Object.IsPhysical, QuaternionToQuat(Rotation)); // why 32? // AddMesh(mesh); // // i am going to see if i can make simple bounding mox meshes for unhollow cubes // if (primShape.ProfileShape == ProfileShape.Square && primShape.HollowShape == HollowShape.Same) // { // Mesh extramesh = Meshmerizer.CreateBoundingBoxMesh(mesh); // AddMesh(extramesh); // } //} if (InnerBoxes == null) InnerBoxes = new List<Box3Fill>(); else InnerBoxes.Clear(); OuterBox.Reset(); CalcBoxesFromMeshes(mesh, InnerBoxes); bool verySmall = OuterBox.EdgeSize < WorldPathSystem.MinEdgeSizeOfSimplify; if (verySmall) { int b = InnerBoxes.Count; InnerBoxes.Clear(); AddPos(Position); InnerBoxes.Add(OuterBox); DLRConsole.DebugWriteLine("Simplfy EdgeSize {0} -> 1 ", b, InnerBoxes.Count + " " + OuterBox.EdgeSize + " " + this.GetObjectName()); } else { if (SimplifyBoxes) { int b = InnerBoxes.Count; InnerBoxes = Box3Fill.Simplify((List<Box3Fill>)InnerBoxes); if (DebugMesh) if (b > 2000 || InnerBoxes.Count * 4 < b) DLRConsole.DebugWriteLine("Simplfy mesh {0} -> {1} ", b, InnerBoxes.Count + " " + OuterBox.Mass + " " + this.GetObjectName()); } AddPos(Position); } #if COLLIDER_TRIANGLE triangles = mesh.triangles; #endif return true; }
/// <summary> /// /// </summary> /// <param name="zAngleFromFace"></param> /// <param name="distance"></param> /// <returns></returns> public static Vector3d GetGlobalLeftPos(SimPosition pos, int zAngleFromFace, double distance) { double RAD_TO_DEG = 57.29577951f; var Pi2 = (double) (Math.PI*2.0); while (zAngleFromFace > 360) { zAngleFromFace -= 360; } while (zAngleFromFace < 0) { zAngleFromFace += 360; } double radAngle = zAngleFromFace/RAD_TO_DEG; Quaternion rot = pos.SimRotation; Vector3 v3 = Vector3.Transform(Vector3.UnitX, Matrix4.CreateFromQuaternion(rot)); double rz = Math.Atan2(v3.Y, v3.X); double az = rz + radAngle; while (az < 0) { az += Pi2; } while (az > Pi2) { az -= Pi2; } var xmul = (double) Math.Cos(az); var ymul = (double) Math.Sin(az); Vector3d diff = new Vector3d(xmul, ymul, 0)*distance; Vector3d result = pos.GlobalPosition + diff; return result; /* * Client.Self.Movement.SendManualUpdate(AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, Client.Self.Movement.Camera.Position, Client.Self.Movement.Camera.AtAxis, Client.Self.Movement.Camera.LeftAxis, Client.Self.Movement.Camera.UpAxis, Client.Self.Movement.BodyRotation, Client.Self.Movement.HeadRotation, Client.Self.Movement.Camera.Far, AgentFlags.None, AgentState.None, true);*/ }
private SimPosition GetPolarRelative(SimPosition offset, string first, out int argsUsed) { Vector3 rel = offset.SimPosition; int star = first.IndexOf("*"); if (star < 0) { argsUsed = 0; return offset; } // -180*5 == *-5 // -180*5 // +90*5 // +180* == -180* == -0*-1 // +0*5 == -0*5 == *5 // bool relative; double rotate; double dist = 1.0; if (star == 0) { relative = true; rotate = 0.0; float f; if (RelTryParse(first.Substring(1), out f, 0)) { dist = f; } } else { string arg = first.Substring(0, star); relative = true; if (arg.StartsWith("A")) { relative = false; arg = arg.Substring(1); } float f; float offsetZ = (float) (GetZHeading(offset.SimRotation)*180/Math.PI); if (!RelTryParse(arg, out f, offsetZ)) { argsUsed = 0; return offset; } rotate = f; string firstSubstring = first.Substring(star + 1); if (firstSubstring.Length == 0) { dist = 1.0; } else if (RelTryParse(firstSubstring, out f, 0)) { dist = f; } else { argsUsed = 0; return offset; } } Vector3 v3 = Vector3.Transform(Vector3.UnitX, Matrix4.CreateFromQuaternion(offset.SimRotation)); v3.X = (float) (Math.Sin(rotate*(Math.PI/180))*dist) + rel.X; v3.Y = (float) (Math.Cos(rotate*(Math.PI/180))*dist) + rel.Y; v3.Z = rel.Z; argsUsed = 1; return SimWaypointImpl.CreateLocal(v3, offset.PathStore); }
public bool GotoSimRoute(SimPosition pos) { bool IsFake; for (int i = 0; i < 19; i++) { Debug("PLAN GotoTarget: " + pos); // StopMoving(); if (TryGotoTarget(pos, out IsFake)) { Mover.StopMoving(); Mover.TurnToward(pos.GlobalPosition); Debug("SUCCESS GotoTarget: " + pos); return true; } //TurnToward(pos); double posDist = Mover.Distance(pos); if (posDist <= pos.GetSizeDistance() + 0.5) { Debug("OK GotoTarget: " + pos); return true; } TurnAvoid += 115; while (TurnAvoid > 360) { TurnAvoid -= 360; } //Vector3d newPost = GetLeftPos(TurnAvoid, 4f); //StopMoving(); //Debug("MOVELEFT GotoTarget: " + pos); //MoveTo(newPost, 2f, 4); if (IsFake) break; } Debug("FAILED GotoTarget: " + pos); return false; }
public List <SimObject> GetSingleArg(string[] splitted, out int argsUsed) { if (splitted.Length == 0) { argsUsed = 0; return(new List <SimObject>()); } SimObject prim; UUID uuid = UUID.Zero; string name = splitted[0].Trim().Replace(" ", " "); if (name.IndexOf("-") > 2 && UUID.TryParse(name, out uuid)) { prim = GetSimObjectFromUUID(uuid); argsUsed = 1; return(PrimOrNot(prim)); } var resolve = name.ToLower(); /* * if (resolve.Equals("pointing") || resolve.Equals("it")) * { * argsUsed = 1; * if (!client.TheRadegastInstance.State.IsPointing) * { * prim = null; * return false; * } * prim = GetPrimitive(client.TheRadegastInstance.State.TargetID, null); * return prim != null; * } */ foreach (string primid in new[] { "primid", "lid" }) { if (resolve.StartsWith(primid)) { int tl = primid.Length; if (name.Length > tl) { String s = name.Substring(tl); uint localID; if (uint.TryParse(s, out localID)) { prim = GetSimObject(localID, null); argsUsed = 1; return(PrimOrNot(prim)); } } } } if (name.StartsWith("@")) { int splitOffset = 0; name = name.Substring(1); if (name.Length == 0) { splitOffset = 1; splitted = Parser.SplitOff(splitted, 1); } else { splitted[0] = name; } int argsUsed0; SimPosition position = GetVector(splitted, out argsUsed0); if (argsUsed0 == 0) { argsUsed = splitOffset; prim = null; return(PrimOrNot(prim)); } double dist; prim = GetSimObjectFromVector(position.GlobalPosition, out dist); argsUsed = argsUsed0 + splitOffset; if (dist > 2) { prim = null; } return(PrimOrNot(prim)); } if (name.StartsWith("$")) { return(ResolveCollection(name, out argsUsed)); } if (name.StartsWith("[")) { var fnd = GetUnion(Parser.SplitOff(splitted, 1), out argsUsed); argsUsed++; if (argsUsed < splitted.Length) { string t = splitted[argsUsed]; if (t == "]") { argsUsed++; } } return(fnd); } if (name == "+") { var fnd = GetSingleArg(Parser.SplitOff(splitted, 1), out argsUsed); argsUsed++; return(fnd); } if (name.StartsWith("(")) { argsUsed = 1; var result = GridMaster.client.evalLispCode(name); var acol = SingleNameValue.AsCollection(result); if (acol == null) { argsUsed = 0; } var fnd = new List <SimObject>(); GridMaster.AsPrimitives(fnd, acol); return(fnd); } int nth; if (int.TryParse(name, out nth)) { nth--; splitted = Parser.SplitOff(splitted, 1); List <SimObject> fnd = null; if (splitted.Length == 0) { argsUsed = 1; fnd = SimRootObjects.CopyOf(); } else { fnd = GetSingleArg(splitted, out argsUsed); } if (fnd == null) { return(fnd); } if (nth >= fnd.Count) { nth = fnd.Count - 1; } if (nth < 0) { return(null); } if (m_TheSimAvatar != null) { fnd.Sort(((SimObject)m_TheSimAvatar).CompareDistance); } return(new List <SimObject>() { fnd[nth] }); } int len = splitted.Length; if (len > 1) { len = 2; } string largs = name.Replace("_", " "); if (largs.Contains(" ")) { len = 1; } argsUsed = 0; for (int i = len; i > 0; i--) { var fnd = new List <SimObject>(); name = string.Join(" ", splitted, 0, i); foreach (var o in SimObjects) { if (o.Matches(name)) { fnd.Add(o); argsUsed = i; } } if (fnd.Count > 0) { return(fnd); } } return(null); }
public string DistanceVectorString(SimPosition loc3d) { return DistanceVectorString(loc3d.GlobalPosition); }
public static SimAbstractMover CreateSimPathMover(SimMover mover, SimPosition finalGoal, double finalDistance) { return new SimCollisionPlaneMover(mover, finalGoal, finalDistance); }
public override void SetMoveTarget(SimPosition target, double maxDist) { OnlyMoveOnThisThread(); if (target == null) { ApproachVector3D = Vector3d.Zero; //ApproachPosition = null; lastDistance = float.MaxValue; return; } // if (ApproachPosition != target) { lastDistance = float.MaxValue; SetMoveTarget(target.UsePosition.GlobalPosition); ApproachDistance = maxDist; } }
public override bool SalientGoto(SimPosition pos) { double maxDistance = pos.GetSizeDistance() + 1; Debug("SalientMovementProceedure = " + SalientMovementProceedure + " for " + pos); switch (SalientMovementProceedure) { case MovementProceedure.Teleport: return this.TeleportTo(pos); case MovementProceedure.AutoPilot: case MovementProceedure.FlyTo: case MovementProceedure.TurnToAndWalk: return SimpleMoveTo(pos.UsePosition.GlobalPosition, pos.GetSizeDistance(), 3, true); // TODO case MovementProceedure.AStar: bool res = GotoTargetAStar(pos); SetMoveTarget(pos, maxDistance - 1); Thread.Sleep(1000); StopMoving(true); if (res) return res; if (GotoUseTeleportFallback) { Debug("Goto sneaking in TP to " + pos); res = this.TeleportTo(pos.UsePosition); TurnToward(pos); return res; } SetMoveTarget(pos, maxDistance - 1); Thread.Sleep(1000); StopMoving(true); if (maxDistance > this.Distance(pos)) { return true; } return false; default: { throw new InvalidOperationException("" + SalientMovementProceedure); } } }
public override bool Update(SimPosition simObject) { return true; }
private SimPosition GetSimV(string[] tokens, int start, out int argsUsed, SimPosition offset) { // not enough args if (tokens.Length < start) { argsUsed = 0; return offset; } if (start > 0) { tokens = Parser.SplitOff(tokens, start); start = 0; } int maxArgs = 0; string first = tokens[0]; argsUsed = 1; if (first == "last") { return offset; } if (first.EndsWith("s")) first = first.Substring(0, first.Length - 1); if (first == "forward") { return SimOffsetPosition.WithOrientation(offset, new Vector3(0, 1, 0)); } if (first.EndsWith("ward")) first = first.Substring(0, first.Length - 4); if (first == "west") { return new SimOffsetPosition(offset, new Vector3(-1, 0, 0)); } if (first == "east") { return new SimOffsetPosition(offset, new Vector3(1, 0, 0)); } if (first == "north") { return new SimOffsetPosition(offset, new Vector3(0, 1, 0)); } if (first == "south") { return new SimOffsetPosition(offset, new Vector3(0, -1, 0)); } if (first == "left") { return SimOffsetPosition.WithOrientation(offset, new Vector3(-1, 0, 0)); } if (first == "right") { return SimOffsetPosition.WithOrientation(offset, new Vector3(1, 0, 0)); } if (first == "back") { return SimOffsetPosition.WithOrientation(offset, new Vector3(0, -1, 0)); } if (first.Contains("/")) { argsUsed = 1; int uu; return GetSimV(first.Split(new char[] {'/'}), 0, out uu, offset); } bool relative = false; for (int st = start; st < tokens.Length; st++) { if (maxArgs > 2) break; string str = tokens[st]; double doublke; if (double.TryParse(str, out doublke)) { maxArgs++; } else { break; } } Vector3 rel = offset.SimPosition; Vector3 target; first = tokens[start]; // Polar coords if (first.Contains("*")) return GetPolarRelative(offset, first, out argsUsed); if (RelTryParse(first, out target.X, rel.X) && RelTryParse(tokens[start + 1], out target.Y, rel.Y)) { argsUsed = 2; target.Z = rel.Z; if (tokens.Length > start + 1) { RelTryParse(tokens[start + 2], out target.Z, rel.Z); argsUsed = 3; } if (target.X > 512 || target.Y > 512) { // Globals return SimWaypointImpl.CreateGlobal(target.X, target.Y, target.Z); } return SimWaypointImpl.CreateLocal(target, offset.PathStore); } argsUsed = 0; return null; }
abstract public bool Update(SimPosition simObject);
private bool Goto(SimPosition globalEnd, double distance) { bool OnlyStart = true; bool MadeIt = true; int maxTryAgains = 0; IList<Vector3d> route = null; CollisionPlane MoverPlane = MoverPlaneZ; bool faked; bool changePlanes = false; while (OnlyStart && MadeIt) { float InitZ = Mover.SimPosition.Z; Vector3d v3d = GetWorldPosition(); if (Mover.Distance(FinalPosition) < distance) return true; float G = MoverPlane.GlobalBumpConstraint; if (G < 1f) Orig = G; SimMoverState prev = STATE; STATE = SimMoverState.THINKING; route = SimPathStore.GetPath(MoverPlane, v3d, globalEnd.UsePosition.GlobalPosition, distance, out OnlyStart, out faked); // todo need to look at OnlyStart? PreXp = route.Count < 3 && G < MaxBigZ; while (route.Count < 3 && G < MaxBigZ && faked) { if (G < 0.5) { G += 0.1f; } else { G += 0.5f; if (Works > G) G = Works; } MoverPlane.GlobalBumpConstraint = G; route = SimPathStore.GetPath(MoverPlane, v3d, globalEnd.UsePosition.GlobalPosition, distance, out OnlyStart, out faked); } if (PreXp) { Works = G; UsedBigZ++; Debug("BigG used {0} instead of {1} !!", G, Orig); OnlyStart = true; } else { // not PreXP if (UsedBigZ > 0) { if (Works > 0.7f) Works -= 0.5f; // todo not as liberal the next time? UsedBigZ = 0; Debug("BigG RESTORE {0} instead of {1} !!", Orig, MoverPlane.GlobalBumpConstraint); MoverPlane.GlobalBumpConstraint = Orig; } } STATE = prev; STATE = FollowPathTo(route, globalEnd.UsePosition.GlobalPosition, distance); Vector3 newPos = GetSimPosition(); switch (STATE) { case SimMoverState.TRYAGAIN: { if (maxTryAgains-- > 0) { OnlyStart = true; continue; } MadeIt = false; continue; } case SimMoverState.COMPLETE: { MadeIt = true; continue; } case SimMoverState.BLOCKED: { float globalEndUsePositionGlobalPositionZ = (float)globalEnd.UsePosition.GlobalPosition.Z; if (faked) { if (Math.Abs(Mover.SimPosition.Z - InitZ) > 1) { MoverPlane = MoverPlanes[Mover] = PathStore.GetCollisionPlane(Mover.SimPosition.Z); } else { MoverPlane = MoverPlanes[Mover] = PathStore.GetCollisionPlane(globalEndUsePositionGlobalPositionZ); } } OnlyStart = true; MadeIt = false; continue; } case SimMoverState.PAUSED: case SimMoverState.MOVING: case SimMoverState.THINKING: default: { //MadeIt = true; OnlyStart = true; continue; } } } if (!MadeIt && route!=null) { SimMoverState prev = STATE; STATE = SimMoverState.THINKING; CollisionPlane CP = MoverPlane; if (CP.HeightMapNeedsUpdate) CP.MatrixNeedsUpdate = true; if (!CP.MatrixNeedsUpdate || !CP.HeightMapNeedsUpdate) { if (false) { CP.MatrixNeedsUpdate = true; CP.HeightMapNeedsUpdate = true; Debug("Faking matrix needs update?"); } } else { Debug("Matrix really needed update"); } Vector3d v3d = GetWorldPosition(); double fd = DistanceNoZ(v3d, globalEnd.GlobalPosition); if (fd < distance) { STATE = SimMoverState.COMPLETE; return true; } CP.EnsureUpdated(); int index = ClosetPointOnRoute(route, v3d); if (index > 0) { var blockMe = new List<Vector3d>(); if (index + 2 < route.Count) { Vector3d firstBad = route[index + 1]; var np = v3d + ((firstBad - v3d)/2); blockMe.Add(np); blockMe.Add(firstBad); DepricateRoute(blockMe, fd); STATE = prev; return MadeIt; } } if (fd > distance && fd > 2) { if (false) DepricateRoute(route, fd); } Debug("Too far away " + fd + " wanted " + distance); STATE = prev; } return MadeIt; }
/// <summary> /// /// </summary> /// <param name="pos"></param> /// <param name="IsFake"></param> /// <returns></returns>s public bool TryGotoTarget(SimPosition pos, out bool IsFake) { IsFake = false; SimMoverState state = SimMoverState.TRYAGAIN; while (state == SimMoverState.TRYAGAIN) { SimWaypoint target = (SimWaypoint)pos; IList<SimRoute> routes = (IList<SimRoute>)GetRouteList(target, out IsFake); if (routes == null) return false; SimRouteMover ApproachPlan = new SimRouteMover(Mover, routes, pos.GlobalPosition, pos.GetSizeDistance()); state = ApproachPlan.Goto(); if (state == SimMoverState.COMPLETE) return true; } return false; //== SimMoverState.COMPLETE; }
public SimReRouteMover(SimMover mover, SimPosition finalGoal, double finalDistance) : base(mover, finalGoal, finalDistance) { }
public SimPosition GetVector(string[] args, out int argsUsed, SimPosition offset) { argsUsed = 0; if (args.Length == 0) return offset ?? TheSimAvatar; //if (args.Length >= 2) { SimPosition R = GetSimV(args, 0, out argsUsed, offset); if (R != null) return R; } UUID uuid = UUID.Zero; if (UUID.TryParse(args[0], out uuid)) { SimObject O = null; O = GetSimObjectFromUUID(uuid); if (O != null) { argsUsed = 1; return O; } } List<SimObject> prim = GetSingleArg(args, out argsUsed); if (prim.Count == 1) return prim[0]; argsUsed = 0; string destination = String.Empty; // Handle multi-word sim names by combining the arguments foreach (string arg in args) { destination += arg + " "; } int consume = args.Length; destination = destination.Trim(); string[] tokens = destination.Split(new char[] { '/' }); float x, y = 128; if (!float.TryParse(tokens[0], out x)) { x = 128; } else { argsUsed++; } string sim = tokens[argsUsed]; //TODO use the GetSimV code argsUsed += 1; float z = -1; if (tokens.Length > argsUsed + 1) { if (!float.TryParse(tokens[argsUsed], out x) || !float.TryParse(tokens[argsUsed + 1], out y)) { return null; } argsUsed += 2; if (tokens.Length > argsUsed) { if (float.TryParse(tokens[argsUsed], out z)) { argsUsed += 1; } else { z = -1; } } // test for global if (x > 512 || y > 512) { float.TryParse(tokens[argsUsed], out z); return SimWaypointImpl.CreateGlobal(x, y, z); } } SimRegion region = SimRegion.GetRegion(sim, client); if (region == null) return null; if (z == -1) z = region.AverageHieght; Vector3 v3 = new Vector3(x, y, z); return SimWaypointImpl.CreateLocal(v3, region.GetPathStore(v3)); }
public override CmdResult ExecuteRequest(CmdRequest args) { if (args.Length < 1) { return(ShowUsage()); // " FlyTo x y z [seconds]"; } int argsUsed; SimPosition position = WorldSystem.GetVector(args, out argsUsed); if (position == null) { return(ShowUsage()); // " FlyTo x y z [seconds]"; } duration = 30000; if (argsUsed < args.Length) { if (Int32.TryParse(args[argsUsed], out duration)) { duration *= 1000; } } if (true) { startTime = DateTime.Now; FlyToAction fta = new FlyToAction(TheSimAvatar, position); if (true) { fta.InvokeReal(); fta.Abort(); return(Success(string.Format("Start flying to {0}", target))); } try { bool KeepFollowing = true; fta.RegCallback(); while (KeepFollowing) { if (DateTime.Now.Subtract(startTime).TotalMilliseconds > duration) { return(Failure("Timer Complete")); } if (!position.IsRegionAttached) { return(Failure("Target detatched " + position)); } KeepFollowing = fta.FlyToOnce(); } } finally { fta.EndFlyto(); } return(Success(string.Format("Start flying to {0}", target))); } // iterupt any motion //TheSimAvatar.CurrentAction = null; target = position.SimPosition; target0.X = target.X; target0.Y = target.Y; Client.Objects.TerseObjectUpdate += callback; startTime = DateTime.Now; Client.Self.Movement.Fly = true; Client.Self.Movement.AtPos = true; Client.Self.Movement.AtNeg = false; ZMovement(); Client.Self.Movement.TurnToward(target); //System.Threading.Thread.Sleep(100); //XYMovement(); //ZMovement(); //Client.Self.Movement.SendUpdate(false); return(Success(string.Format("flying to {0} in {1} seconds", target.ToString(), duration / 1000))); }
public Vector3d GlobalPosition(SimPosition prim) { return prim.GlobalPosition; }