public void AddWall(Vector2 p1, Vector2 p2) { double angle1, angle2; angle1 = Math.Atan2(p1.Y, p1.X); angle2 = Math.Atan2(p2.Y, p2.X); double adiff = angle2 - angle1; if (adiff < 0) adiff += Math.PI * 2.0; if (adiff > Math.PI) { Vector2 tmp = p2; p2 = p1; p1 = tmp; double tmp2 = angle1; angle1 = angle2; angle2 = tmp2; } if (angle1 < 0) angle1 += Math.PI * 2.0; if (angle2 < 0) angle2 += Math.PI * 2.0; if (angle2 < angle1) { float tmp = getinetersecty0(p1, p2); addit(tmp, 0.0f, p2.Length(), (float)angle2); addit(p1.Length(), (float)angle1, tmp, (float)Math.PI * 2.0f); } else { addit(p1.Length(), (float)angle1, p2.Length(), (float)angle2); } }
public void Vector2_CalculatesLengthCorrectly() { var vector = new Vector2(123.4f, 567.8f); TheResultingValue(vector.Length()).WithinDelta(0.1f) .ShouldBe((float)Math.Sqrt((123.4f * 123.4f) + (567.8f * 567.8f))); }
/// <summary> /// Cargar valores iniciales del interpolador /// </summary> public void reset() { dir = end - init; distanceToTravel = dir.Length(); dir.Normalize(); current = init; }
/// <summary> /// Converts a Cartesian x-, y- coordinate pair to polar coordinates. /// </summary> /// <param name="cartesian"></param> /// <returns></returns> public static PolarCoordinate FromCartesian(Vector2 cartesian) { float angle = (float)Math.Atan2(cartesian.Y, cartesian.X); float distance = cartesian.Length(); return new PolarCoordinate(angle, distance); }
protected override bool IsInBounds(int x, int y) { int cx = X + radius; int cy = Y + radius; Vector2 d = new Vector2(x - cx, y - cy); return d.Length() <= Radius; }
public void run(float deltaTime) { Vector3 rotation = tankHead.Rotation; float barrelRotation = tankHead.BarrelRotation; Vector3 targetVector = TurretManager.ManagedTurrets[0].Location - tankHead.Location; rotation.X = (float)Math.Atan2(targetVector.X, targetVector.Z); tankHead.Rotation = rotation; Vector2 distanceXZ = new Vector2(targetVector.X, targetVector.Z); tankHead.BarrelRotation = (float)Math.Atan2(distanceXZ.Length(), targetVector.Y); }
protected override void Update(TimeSpan gameTime) { var impulse = new Vector2(); impulse = Behaviors.Aggregate(impulse, (current, behavior) => behavior.Apply(current)); if (impulse.Length() > MaxImpulseLength) { impulse.Normalize(); impulse = impulse*MaxImpulseLength; } RigidBody.ApplyLinearImpulse(new Vector3(impulse.X, 0, impulse.Y)); }
//Genero posicion aleatoria para el asteoride. public void GenerateRandomPosition() { Random rnd = new Random(); //Determina de que lado de la pantalla aparece int lado = (int)(rnd.NextDouble() * 2); if( lado == 0) Position.X = 0; else Position.X = GameManager.ScreenWidth; Position.Y = GameManager.ScreenHeight * (float)rnd.NextDouble(); //Busco el angulo del asteroide para que vaya al centro de la pantalla. Vector2 ScreenCenterVector = new Vector2(); Vector2 ScreenCenter = new Vector2(GameManager.ScreenWidth / 2, GameManager.ScreenHeight / 2); ScreenCenterVector = Vector2.Subtract(ScreenCenter, Position); if (ScreenCenterVector.Length() > 0) angle = (float)Math.Atan2(ScreenCenterVector.Y, ScreenCenterVector.X); }
public void Process(Vector2 gazeNormalizedCenterDelta, double aspectRatio) { const double radialMenuYOffset = 0.17; const double radialMenuInnerRadius = 0.23; const int numberOfSectors = 8; const int sectorSize = 360 / numberOfSectors; var deltaVector = new Vector2((float)(gazeNormalizedCenterDelta.X * aspectRatio), (float)(gazeNormalizedCenterDelta.Y + radialMenuYOffset)); if (deltaVector.Length() < radialMenuInnerRadius) return; var angleRad = Math.Atan2(-deltaVector.Y, deltaVector.X); var angleDeg = Geometry.RadToDeg(angleRad); var region = (int)Math.Floor(360 + angleDeg + sectorSize * 0.5) / sectorSize; region = region % numberOfSectors; if (region < 0) region += numberOfSectors; if (_lastRadialMenuRegion == region) { _newRadialMenuRegionStopwatch.Reset(); } else { _newRadialMenuRegionStopwatch.Start(); } var switchTime = TimeSpan.FromMilliseconds(60); if (_newRadialMenuRegionStopwatch.Elapsed > switchTime) { _lastRadialMenuRegion = region; _newRadialMenuRegionStopwatch.Reset(); } if (_lastRadialMenuRegion < 0) return; var alpha = Geometry.DegToRad(_lastRadialMenuRegion * sectorSize); var freelookDeltaVector = new Vector2((float)(Math.Cos(alpha)), (float)(-Math.Sin(alpha))); const double rotationalSpeed = 1; _controllerEmulation.DeltaX = freelookDeltaVector.X * rotationalSpeed; _controllerEmulation.DeltaY = freelookDeltaVector.Y * rotationalSpeed; }
public void Update() { const float radialMenuYOffset = 0.17f; const float radialMenuInnerRadius = 0.23f; const int numberOfSectors = 8; const int sectorSize = 360 / numberOfSectors; var deltaVector = new Vector2(_tobiiTracker.GazeX * _tobiiTracker.AspectRatio, (float)(_tobiiTracker.GazeY + radialMenuYOffset)); if (deltaVector.Length() < radialMenuInnerRadius) return; var angleRad = (float)Math.Atan2(-deltaVector.Y, deltaVector.X); var angleDeg = Mathf.Rad2Deg * angleRad; var region = (int)Math.Floor(360 + angleDeg + sectorSize * 0.5) / sectorSize; region = region % numberOfSectors; if (region < 0) region += numberOfSectors; if (_lastRadialMenuRegion == region) { _newRadialMenuRegionStopwatch.Reset(); } else { _newRadialMenuRegionStopwatch.Start(); } var switchTime = TimeSpan.FromMilliseconds(60); if (_newRadialMenuRegionStopwatch.Elapsed > switchTime) { _lastRadialMenuRegion = region; _newRadialMenuRegionStopwatch.Reset(); } if (_lastRadialMenuRegion < 0) return; var alpha = Mathf.Deg2Rad * (_lastRadialMenuRegion * sectorSize); var freelookDeltaVector = new Vector2((float)(Math.Cos(alpha)), (float)(-Math.Sin(alpha))); const double rotationalSpeed = 1; _controllerEmulation.DeltaX = freelookDeltaVector.X * rotationalSpeed; _controllerEmulation.DeltaY = freelookDeltaVector.Y * rotationalSpeed; }
internal override void InitVelocityConstraints(ref SolverData data) { _indexA = BodyA.IslandIndex; _indexB = BodyB.IslandIndex; _localCenterA = BodyA._sweep.LocalCenter; _localCenterB = BodyB._sweep.LocalCenter; _invMassA = BodyA._invMass; _invMassB = BodyB._invMass; _invIA = BodyA._invI; _invIB = BodyB._invI; Vector2 cA = data.positions[_indexA].c; float aA = data.positions[_indexA].a; Vector2 vA = data.velocities[_indexA].v; float wA = data.velocities[_indexA].w; Vector2 cB = data.positions[_indexB].c; float aB = data.positions[_indexB].a; Vector2 vB = data.velocities[_indexB].v; float wB = data.velocities[_indexB].w; Rot qA = new Rot(aA), qB = new Rot(aB); _rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA); _rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB); // Get the pulley axes. _uA = cA + _rA - WorldAnchorA; _uB = cB + _rB - WorldAnchorB; float lengthA = _uA.Length(); float lengthB = _uB.Length(); if (lengthA > 10.0f * Settings.LinearSlop) { _uA *= 1.0f / lengthA; } else { _uA = Vector2.Zero; } if (lengthB > 10.0f * Settings.LinearSlop) { _uB *= 1.0f / lengthB; } else { _uB = Vector2.Zero; } // Compute effective mass. float ruA = MathUtils.Cross(_rA, _uA); float ruB = MathUtils.Cross(_rB, _uB); float mA = _invMassA + _invIA * ruA * ruA; float mB = _invMassB + _invIB * ruB * ruB; _mass = mA + Ratio * Ratio * mB; if (_mass > 0.0f) { _mass = 1.0f / _mass; } if (Settings.EnableWarmstarting) { // Scale impulses to support variable time steps. _impulse *= data.step.dtRatio; // Warm starting. Vector2 PA = -(_impulse) * _uA; Vector2 PB = (-Ratio * _impulse) * _uB; vA += _invMassA * PA; wA += _invIA * MathUtils.Cross(_rA, PA); vB += _invMassB * PB; wB += _invIB * MathUtils.Cross(_rB, PB); } else { _impulse = 0.0f; } data.velocities[_indexA].v = vA; data.velocities[_indexA].w = wA; data.velocities[_indexB].v = vB; data.velocities[_indexB].w = wB; }
internal override void InitVelocityConstraints(ref SolverData data) { _indexA = BodyA.IslandIndex; _indexB = BodyB.IslandIndex; _localCenterA = BodyA._sweep.LocalCenter; _localCenterB = BodyB._sweep.LocalCenter; _invMassA = BodyA._invMass; _invMassB = BodyB._invMass; _invIA = BodyA._invI; _invIB = BodyB._invI; Vector2 cA = data.positions[_indexA].c; float aA = data.positions[_indexA].a; Vector2 vA = data.velocities[_indexA].v; float wA = data.velocities[_indexA].w; Vector2 cB = data.positions[_indexB].c; float aB = data.positions[_indexB].a; Vector2 vB = data.velocities[_indexB].v; float wB = data.velocities[_indexB].w; Rot qA = new Rot(aA), qB = new Rot(aB); _rA = MathUtils.Mul(qA, LocalAnchorA - _localCenterA); _rB = MathUtils.Mul(qB, LocalAnchorB - _localCenterB); _u = cB + _rB - cA - _rA; _length = _u.Length(); float C = _length - MaxLength; if (C > 0.0f) { State = LimitState.AtUpper; } else { State = LimitState.Inactive; } if (_length > Settings.LinearSlop) { _u *= 1.0f / _length; } else { _u = Vector2.Zero; _mass = 0.0f; _impulse = 0.0f; return; } // Compute effective mass. float crA = MathUtils.Cross(_rA, _u); float crB = MathUtils.Cross(_rB, _u); float invMass = _invMassA + _invIA * crA * crA + _invMassB + _invIB * crB * crB; _mass = invMass != 0.0f ? 1.0f / invMass : 0.0f; if (Settings.EnableWarmstarting) { // Scale the impulse to support a variable time step. _impulse *= data.step.dtRatio; Vector2 P = _impulse * _u; vA -= _invMassA * P; wA -= _invIA * MathUtils.Cross(_rA, P); vB += _invMassB * P; wB += _invIB * MathUtils.Cross(_rB, P); } else { _impulse = 0.0f; } data.velocities[_indexA].v = vA; data.velocities[_indexA].w = wA; data.velocities[_indexB].v = vB; data.velocities[_indexB].w = wB; }
public void DoProcess() { Main.IsRunning = true; this.GameWindowHandle = this.GameMemory.Process.MainWindowHandle; Native.SetForegroundWindow(this.GameWindowHandle); while (this.GameWindowHandle != IntPtr.Zero && Main.IsRunning && this.GameMemory.IsOpen) { this.GameWindowRect = GetWindowRect(this.GameWindowHandle); this.GameWindowSize.X = this.GameWindowRect.Right - this.GameWindowRect.Left; this.GameWindowSize.Y = this.GameWindowRect.Bottom - this.GameWindowRect.Top; this.GameWindowCenter.X = this.GameWindowRect.Left + (this.GameWindowSize.X / 2); this.GameWindowCenter.Y = this.GameWindowRect.Top + (this.GameWindowSize.Y / 2) + 11; DXDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1f, 0); DXDevice.SetRenderState(RenderState.ZEnable, false); DXDevice.SetRenderState(RenderState.Lighting, false); DXDevice.SetRenderState<Cull>(RenderState.CullMode, Cull.None); DXDevice.BeginScene(); long entityOffset = this.GameMemory.ReadInt64(CGameOffset); long playerOffset = this.GameMemory.ReadInt64(entityOffset + 0x11D8); player_X = this.GameMemory.ReadFloat(playerOffset + 0x210); //0x200 player_Y = this.GameMemory.ReadFloat(playerOffset + 0x214); //0x204 player_Z = this.GameMemory.ReadFloat(playerOffset + 0x218); //0x208 player_D = this.GameMemory.ReadFloat(playerOffset + 0x240); //0x230 long posOffset = this.GameMemory.ReadInt64(playerOffset + 0x198); //0x190 player_X = this.GameMemory.ReadFloat(posOffset + 0x110); player_Y = this.GameMemory.ReadFloat(posOffset + 0x114); player_Z = this.GameMemory.ReadFloat(posOffset + 0x118); PlayerPosition.X = player_X; PlayerPosition.Y = player_Y; PlayerPosition.Z = player_Z; TextRegion = new POINT(this.GameWindowRect.Left + 15, this.GameWindowRect.Top + 35); if (ShowPosition) { DrawText("Position X: " + player_X.ToString("F1") + " Y: " + player_Y.ToString("F1") + " Z: " + player_Z.ToString("F1"), ref TextRegion, Color.White); DrawText("Direction: " + player_D.ToString("F2"), ref TextRegion, Color.White); } ShowESP = (!HideESPWhenAiming || Convert.ToBoolean(Native.GetAsyncKeyState(2) & 0x8000) == false); Entity.Clear(); Aimed = false; int entityCount = this.GameMemory.ReadInt32(entityOffset + 0x688); long entityEntry = this.GameMemory.ReadInt64(playerOffset + 0x410); //0x400 for (int i = 1; i < entityCount; i++) { float EntityX = 0; float EntityY = 0; float EntityZ = 0; float EntityYaw = 0; float EntityPitch = 0; float EntitySpeed = 0; int EntityType = this.GameMemory.ReadInt32(entityEntry + 0x5C8); //0x5B0 if (EntityType == 0) continue; int EntityId = this.GameMemory.ReadInt32(entityEntry + 0x620); //0x608 long _nameEntry = this.GameMemory.ReadInt64(entityEntry + 0x4E0); //0x468 String EntityName = this.GameMemory.ReadString(_nameEntry, this.GameMemory.ReadInt32(entityEntry + 0x4E8)); //0x470 // Player Position // if (EntityType == 0x04) { EntityX = this.GameMemory.ReadFloat(entityEntry + 0x210); //0x1C0 EntityY = this.GameMemory.ReadFloat(entityEntry + 0x214); //0x1C4 EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x218); //0x1C8 EntitySpeed = this.GameMemory.ReadFloat(entityEntry + 0x2C8); //0x1D8 EntityYaw = this.GameMemory.ReadFloat(entityEntry + 0x2E0); //0x1F0 } // Vechicle Position // else if (EntityType == 0x11 || EntityType == 0x72 || EntityType == 0x76) { EntityX = this.GameMemory.ReadFloat(entityEntry + 0x250); //0x200 EntityY = this.GameMemory.ReadFloat(entityEntry + 0x254); EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x258); EntitySpeed = this.GameMemory.ReadFloat(entityEntry + 0x2C8); //0x1D8 } else { // Try Get NPC Position // EntityX = this.GameMemory.ReadFloat(entityEntry + 0x410); //0x3C0 if (EntityX == 0) { // Item Position // EntityX = this.GameMemory.ReadFloat(entityEntry + 0x13F0); //0x13E0 EntityY = this.GameMemory.ReadFloat(entityEntry + 0x13E4); EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x13E8); } else { // NPC Position // EntityY = this.GameMemory.ReadFloat(entityEntry + 0x414); EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x418); EntitySpeed = this.GameMemory.ReadFloat(entityEntry + 0x2C8); //0x1D8 EntityYaw = this.GameMemory.ReadFloat(entityEntry + 0x2E0); //0x1F0 } } long entityPositionOffset = this.GameMemory.ReadInt64(entityEntry + 0x198); EntityX = this.GameMemory.ReadFloat(entityPositionOffset + 0x110); EntityY = this.GameMemory.ReadFloat(entityPositionOffset + 0x114); EntityZ = this.GameMemory.ReadFloat(entityPositionOffset + 0x118); // Create New Entity // ENTITY currentEntity = new ENTITY() { Id = EntityId, Type = EntityType, Name = EntityName, Pos = new Vector3(EntityX, EntityY, EntityZ), Distance = Vector3.Distance(new Vector3(EntityX, EntityY, EntityZ), PlayerPosition), Yaw = EntityYaw, Pitch = EntityPitch, Speed = EntitySpeed }; // Append New Entity // Entity.Add(currentEntity); switch (EntityType) { case 0x04/*Player*/: case 0x0C/*Zombie*/: case 0x13/*Deer*/: case 0x14/*Wolf*/: case 0x50/*Bear*/: case 0x55/*Rabbit*/: case 0x5b/*Zombie*/: // Aiming // /* Vector3 aimingTo = Vector3.Zero; if (Aimed == true || currentEntity.Distance > 300f) { // Already aimed, not in range, entity is dead } else if (ModifierKeys.HasFlag(Keys.Control) || Convert.ToBoolean(Native.GetAsyncKeyState(Keys.XButton1) & 0x8000) == true) { if (AimedEntity != null && AimedEntity.Id == currentEntity.Id) { if (Convert.ToBoolean(this.GameMemory.ReadByte(entityEntry + 0x136C)) == false) { // Target is dead // AimedEntity = null; } else if (AimedUpdate >= DateTime.Now) { Aimed = true; AimedEntity = currentEntity; Vector3 AIM; float offsetY = 1.0f; if (AimedEntity.Type == 0x55) offsetY = 0.20f; if (AimedEntity.Type == 0x13) offsetY = 0.75f; if (AimedEntity.Type == 0x14) offsetY = 0.50f; if (AimedEntity.Type == 0x50) offsetY = 0.65f; if (WorldToScreen(new Vector3(AimedEntity.Pos.X, AimedEntity.Pos.Y + offsetY, AimedEntity.Pos.Z), out AIM)) { float moveOffsetX = AIM.X - this.GameWindowCenter.X; float moveOffsetY = AIM.Y - this.GameWindowCenter.Y; DrawText("Aimed at " + AimedEntity.Name + ": " + moveOffsetX + ", " + moveOffsetY, ref TextRegion, Color.Red); Native.mouse_event(0x0001, (short)moveOffsetX, (short)moveOffsetY, 0, 0); AimedUpdate = DateTime.Now.AddMilliseconds(50); } } } else if (AimedEntity == null && WorldToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), out aimingTo)) { float distance = Vector2.Distance(new Vector2(aimingTo.X, aimingTo.Y), new Vector2(this.GameWindowCenter.X, this.GameWindowCenter.Y)); if (distance < 100f) { AimedEntity = currentEntity; Aimed = true; AimedUpdate = DateTime.Now.AddMilliseconds(50); } } } else { AimedEntity = null; } */ // Show Entity when ESP enabled // if (ShowESP) // && this.GameMemory.ReadFloat(entityEntry + 0x1CC) == 1f) { Byte EntityAlive = this.GameMemory.ReadByte(entityEntry + 0x137C); //0x136C if (HideDead == false || Convert.ToBoolean(EntityAlive) == true) { // Deer or Rabbit // if (EntityType == 0x13 || EntityType == 0x55) { if (ShowAnimals) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.DarkGreen, true, false, BoxedAnimals, 2f, EntityYaw, EntityPitch); } // Player // else if (EntityType == 0x04) { // Show HP long num22 = this.GameMemory.ReadInt64(entityEntry + 0x4068); //old: 0x4058L old old 0x3fa8L 0x4068 uint num23 = this.GameMemory.ReadUInt32(num22); for (uint j = 1; (num23 != 0x30) && (j < 50); j++) { num22 = this.GameMemory.ReadInt64(num22 + 0xf8L); num23 = this.GameMemory.ReadUInt32(num22); } uint playerHP = this.GameMemory.ReadUInt32(num22 + 0xb0L) / 100; int Hue = (int)(120f * (float)playerHP / 100f); // Hue red at 0° green at 120° Color color = ColorTranslator.FromWin32(ColorHLSToRGB(Hue, 120, 240)); // H,L,S; string playerNameHP = EntityName + " " + playerHP.ToString() + "%"; if (ShowPlayers) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), playerNameHP, color, true, false, BoxedPlayers, 2f, EntityYaw, EntityPitch); //if (ShowPlayers) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.SkyBlue, true, false, BoxedPlayers, 2f, EntityYaw, EntityPitch); } // Aggressive NPC (Wolf, Bear, Zombies) // else { if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.Red, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); } } } break; case 0x2E: // Loot if (ShowESP && ShowItems) { if (EntityName.Contains("First")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Green, true, false, BoxedItems, 1f, 0f, 0f); } else { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.GreenYellow, true, false, BoxedItems, 1f, 0f, 0f); } } break; case 0x1B: // Campfire case 0x6D: // Stash case 0x9C: // Land Mine if (ShowESP && ShowItems) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.SaddleBrown, true, false, BoxedItems, 1f, 0f, 0f); break; case 0x2F: // Furnace // case 0x33: // Storage Container case 0x35: // Animal Trap case 0x36: // Dew Collector case 0x53: // Barbeque if (ShowESP && ShowContainers) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Gray, true, false, BoxedItems, 1f, 0f, 0f); break; case 0x34: // Weapons if (ShowESP && ShowWeapons) { if (EntityName.Contains("Shotgun")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.OrangeRed, true, false, BoxedItems, 1f, 0f, 0f); } else if (EntityName.Contains("AR15")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.OrangeRed, true, false, BoxedItems, 1f, 0f, 0f); } else if (EntityName.Contains("M1911")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.OrangeRed, true, false, BoxedItems, 1f, 0f, 0f); } else { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.GreenYellow, true, false, BoxedItems, 1f, 0f, 0f); } } break; case 0x15: // Ammo if (ShowESP && ShowAmmo) { if (EntityName.Contains(".223")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Orange, true, false, BoxedItems, 1f, 0f, 0f); } else if (EntityName.Contains("Shotgun")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Orange, true, false, BoxedItems, 1f, 0f, 0f); } else if (EntityName.Contains(".45")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Orange, true, false, BoxedItems, 1f, 0f, 0f); } } break; case 0x11: // OffRoad case 0x72: // Pickup case 0x76: // PoliceCar if (ShowESP && ShowVehicles) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.HotPink, true, false, BoxedVehicles, 2f, 0f, 0f); break; case 0x2C: // Resources, Battary, Turbo, Sparkplugs if (ShowESP && ShowItems) { if (EntityName.Contains("Battery") || EntityName.Contains("Turbo") || EntityName.Contains("Headlights") || EntityName.Contains("Sparkplugs")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.LavenderBlush, true, false, BoxedItems, 1f, 0f, 0f); } // ******ACTUAL LOCATION if (EntityName.Contains("First Aid Kit")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Lime, true, false, BoxedItems, 1f, 0f, 0f); } else { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.White, true, false, BoxedItems, 1f, 0f, 0f); } } break; case 0x16: // Dresser case 0x17: // Armoire case 0x19: // World Doors case 0x1D: // Cabinets case 0x1E: // Cabinets case 0x21: // Cabinets case 0x22: // Cabinets case 0x23: // Cabinets case 0x25: // Refrigerator case 0x26: // Garbage Can case 0x28: // Cabinets case 0x29: // Desk case 0x27: // Dumpster case 0x30: // File Cabinet case 0x31: // Tool Cabinet case 0x37: // Recycle Bin (with fire) case 0x38: // Punji Sticks case 0x3D: // Wooded Barricade case 0x3E: // Water Well case 0x3F: // Armoire case 0x40: // Dresser case 0x42: // Chest case 0x44: // Wrecked Sedan case 0x45: // Wrecked Van case 0x46: // Wrecked Truck case 0x49: // Ottoman case 0x4A: // Ottoman case 0x4F: // Designer-placed(?) Door case 0x5D: // File Cabinet case 0x61: // Cabinets case 0x63: // Cabinets case 0x6F: // Locker case 0x70: // Weapon Locker case 0x71: // Glass Cabinet case 0x79: // Designer-placed(?) Door case 0x7A: // Resting (Bed) case 0x7B: // Designer-placed(?) Door case 0x7C: // Designer-placed(?) Door case 0x80: // Cabinets case 0x81: // Cabinets case 0x82: // Cabinets case 0x83: // Cabinets case 0x84: // Cabinets case 0x85: // Cabinets case 0x86: // Cabinets case 0x87: // Cabinets case 0x88: // Cabinets case 0xA1: // Washing Machine case 0xA2: // Dryer case 0x7D: // IO.FireHydrant case 0x7E: // IO.FireHydrant //this.WorldToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityId.ToString("X2") + "]", Color.Gray, true, false, false, 0f, 0f); break; case 0x4C: // Shed case 0x5F: // Metal Wall/Gate case 0x62: // Basic Shack Door case 0x6E: // Desk Foundation case 0x9E: // Metal Door case 0xA6: // Large Shelter case 0xA7: // Shed //this.WorldToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityId.ToString("X2") + "]", Color.Gray, true, false, false, 0f, 0f); break; default: // Other Items if (ShowESP && ShowItems) { if (EntityName.Contains("First")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Green, true, false, BoxedItems, 1f, 0f, 0f); } else { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityType.ToString("X2") + "]", Color.White, true, false, false, 1f, 0f, 0f); } } break; } entityEntry = this.GameMemory.ReadInt64(entityEntry + 0x410); } if (Aimed == false) AimedEntity = null; if (ShowEntityLists) { ENTITY[] playerList = Entity.Where(E => E.Type == 0x04).OrderBy(E => E.Distance).ToArray(); ENTITY[] aggressiveList = Entity.Where(E => E.Type == 0x0C || E.Type == 0x14 || E.Type == 0x50 || E.Type == 0x5b).OrderBy(E => E.Distance).ToArray(); ENTITY[] animalsList = Entity.Where(E => E.Type == 0x13 || E.Type == 0x55).OrderBy(E => E.Distance).ToArray(); ENTITY[] vehiclesList = Entity.Where(E => E.Type == 0x11 || E.Type == 0x72 || E.Type == 0x76).OrderBy(E => E.Distance).ToArray(); int itemY = (aggressiveList.Length > 10 ? 150 : aggressiveList.Length * 15); foreach (ENTITY entity in aggressiveList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 20, this.GameWindowRect.Bottom - itemY - 15, Color.Red); itemY -= 15; if (itemY <= 0) break; } itemY = (animalsList.Length > 10 ? 150 : animalsList.Length * 15); foreach (ENTITY entity in animalsList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 120, this.GameWindowRect.Bottom - itemY - 15, Color.Green); itemY -= 15; if (itemY <= 0) break; } itemY = (vehiclesList.Length > 10 ? 150 : vehiclesList.Length * 15); foreach (ENTITY entity in vehiclesList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 220, this.GameWindowRect.Bottom - itemY - 15, Color.HotPink); itemY -= 15; if (itemY <= 0) break; } itemY = (playerList.Length > 10 ? 150 : playerList.Length * 15); foreach (ENTITY entity in playerList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m] " + playerHP.ToString() + "%" , this.GameWindowRect.Left + 320, this.GameWindowRect.Bottom - itemY - 15, Color.SkyBlue); itemY -= 15; if (itemY <= 0) break; } } if (ShowRadar) { DrawFilledBox(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, Color.DarkOliveGreen, RadarTransparency); DrawBoxAbs(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 50, this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 251, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 150, this.GameWindowRect.Right - 24, this.GameWindowRect.Top + 150, 1f, Color.Black); RadarCenter = new Vector2(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 125 + 25); DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White); if (RadarCenter.Length() > 0f) { foreach (ENTITY entity in Entity) { Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z); Vector2 vector3 = new Vector2(player_X, player_Z); pointToRotate = vector3 - pointToRotate; float num30 = pointToRotate.Length() * 0.5f; num30 = Math.Min(num30, 90f); pointToRotate.Normalize(); pointToRotate = (Vector2)(pointToRotate * num30); pointToRotate += RadarCenter; pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true); if (entity.Type == 0x04 && RadarPlayers) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.SkyBlue); } if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red); } if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen); } if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.HotPink); } } } } if (ShowCities) { this.EntityToScreen(new Vector3(-129f, 40f, -1146f), "Pleasant Valley", Color.DarkViolet, true, false, false, 1f, 0f, 0f); this.EntityToScreen(new Vector3(-1233f, 90f, 1855f), "Cranberry", Color.DarkViolet, true, false, false, 1f, 0f, 0f); this.EntityToScreen(new Vector3(2003f, 50f, 2221f), "Ranchito", Color.DarkViolet, true, false, false, 1f, 0f, 0f); } if (Main.ShowMap && (DXTextrureMap != null || DXTextrureMapLarge != null)) { DXSprite.Begin(SpriteFlags.AlphaBlend); if (Main.ShowMapLarge && DXTextrureMapLarge != null) { map_pos_x = RemapValue(player_X, 4000f, -4000f, -512f, 512f); map_pos_z = RemapValue(player_Z, -4000f, 4000f, -512f, 512f); DXSprite.Draw(DXTextrureMapLarge, new Vector3(512f, 512f, 0f), new Vector3(this.GameWindowCenter.X, this.GameWindowCenter.Y, 0f), Color.FromArgb(MapTransparency, 0xff, 0xff, 0xff)); } else if (DXTextrureMap != null) { map_pos_x = RemapValue(player_X, 4000f, -4000f, -265f, 265f); map_pos_z = RemapValue(player_Z, -4000f, 4000f, -265f, 265f); DXSprite.Draw(DXTextrureMap, new Vector3(256f, 256f, 0f), new Vector3(this.GameWindowCenter.X, this.GameWindowCenter.Y, 0f), Color.FromArgb(MapTransparency, 0xff, 0xff, 0xff)); } DXSprite.End(); float direction = Main.player_D * -1f; float fromX = (float)((this.GameWindowCenter.X + map_pos_z) + (20.0 * Math.Cos(direction))); float fromY = (float)((this.GameWindowCenter.Y + map_pos_x) + (20.0 * Math.Sin(direction))); DrawFilledBox((this.GameWindowCenter.X + map_pos_z) - 2f, (this.GameWindowCenter.Y + map_pos_x) - 2f, 6f, 6f, Color.Magenta); DrawLine(fromX, fromY, (this.GameWindowCenter.X + map_pos_z) + 1f, (this.GameWindowCenter.Y + map_pos_x) + 1f, 1f, Color.PaleVioletRed); } DXDevice.EndScene(); DXDevice.Present(); Thread.Sleep(1); } DXDevice.Dispose(); Application.Exit(); }
/// <summary> /// /// </summary> /// <param name="znear"></param> /// <param name="a"></param> /// <param name="z"></param> /// <param name="r"></param> /// <param name="min"></param> /// <param name="max"></param> /// <returns></returns> bool GetSphereExtentAxis( float znear, float a, float z, float r, out float min, out float max ) { min = max = 0; if (z>r-znear) { return false; } var c = new Vector2( a, z ); var t = sqrt( c.LengthSquared() - r * r ); var cLen = c.Length(); var cosT = t / cLen; var sinT = r / cLen; c.X /= cLen; c.Y /= cLen; var T = new Vector2( cosT * c.X - sinT * c.Y, +sinT * c.X + cosT * c.Y ) * t; var B = new Vector2( cosT * c.X + sinT * c.Y, -sinT * c.X + cosT * c.Y ) * t; var tau = new Vector2( a + sqrt( r*r - square(znear-z) ), znear ); var beta = new Vector2( a - sqrt( r*r - square(znear-z) ), znear ); var U = T.Y < znear ? T : tau; var L = B.Y < znear ? B : beta; max = U.X / U.Y * znear; min = L.X / L.Y * znear; return true; }
/// <summary> /// Cos of angle betwwen this and other vector /// </summary> public static float CosAngle(this PointF x1, PointF x2) { return((x1.X * x2.X + x1.Y * x2.Y) / x1.Length() / x2.Length()); }
public bool ClickNode(Point cursor, StereoEye eye, float threshold, out int nodeIndex ) { nodeIndex = 0; var cam = Game.GetService<GreatCircleCamera>(); var viewMatrix = cam.GetViewMatrix( eye ); var projMatrix = cam.GetProjectionMatrix( eye ); Graph graph = this.GetGraph(); Vector2 cursorProj = PixelsToProj(cursor); bool nearestFound = false; float minZ = 99999; int currentIndex = 0; foreach (SpatialNode node in graph.Nodes) { Vector4 posWorld = new Vector4(node.Position - ((SpatialNode)graph.Nodes[referenceNodeIndex]).Position, 1.0f); Vector4 posView = Vector4.Transform(posWorld, viewMatrix); Vector4 posProj = Vector4.Transform(posView, projMatrix); posProj /= posProj.W; Vector2 diff = new Vector2(posProj.X - cursorProj.X, posProj.Y - cursorProj.Y); if (diff.Length() < threshold) { nearestFound = true; if (minZ > posProj.Z) { minZ = posProj.Z; nodeIndex = currentIndex; } } ++currentIndex; } return nearestFound; }
static Vector2 Normalize(short rawX, short rawY, short threshold) { var value = new Vector2(rawX, rawY); var magnitude = value.Length(); var direction = value / (magnitude == 0 ? 1 : magnitude); var normalizedMagnitude = 0.0f; if (magnitude - threshold > 0) normalizedMagnitude = Math.Min((magnitude - threshold) / (short.MaxValue - threshold), 1); return direction * normalizedMagnitude; }
public static void SyncExecuteBehavior(string contextServer, MotionBasedBehavior behavior) { try { if (!string.IsNullOrEmpty(contextServer) && behavior != null) { // Execute Init actions only once if (!behavior.InitActionsComplete) { SyncExecuteBehavior(contextServer, behavior.InitActions); behavior.InitActionsComplete = true; } // Evaluate Expression string humanInfo = GetHumanInfo(contextServer, behavior.Id); var count = GestureTriggerCount(humanInfo, behavior.Trigger, behavior.ConfidenceLevel); // Increment count once count = count + 1; if (!string.IsNullOrEmpty(humanInfo)) { //Log.Info(humanInfo); } if (!behavior.CyclicActionsComplete) { foreach (var behaviorItem in behavior.RobotActions) { var behaviorInfo = behaviorItem.Clone() as BehaviorInfo; // Before executing each action get the latest information about the human humanInfo = GetHumanInfo(contextServer, behavior.Id); if (!string.IsNullOrEmpty(humanInfo)) { //Log.Info(humanInfo); } if (behaviorInfo != null) { Log.InfoFormat("Behavior Detail: {0}", behaviorInfo.ToString()); if (behaviorInfo.BehaviorName == "Say Expressively") { var msg = string.Empty; var arg = string.Empty; var msgDict = behaviorInfo.Parameters.TryGetAndReturn("msg") as Dictionary<string, object>; var argDict = behaviorInfo.Parameters.TryGetAndReturn("arg") as Dictionary<string, object>; if (msgDict != null && argDict != null) { msg = msgDict.TryGetAndReturn("value") as string; arg = argDict.TryGetAndReturn("value") as string; } Log.InfoFormat("Msg: {0}, Arg: {1}", msg, arg); if (!string.IsNullOrEmpty(msg) && !string.IsNullOrEmpty(arg) && !string.IsNullOrEmpty(behavior.TriggerCountVariable)) { var newMsg = string.Empty; if (arg == behavior.TriggerCountVariable) { newMsg = string.Format(msg, count); if (msgDict != null) msgDict["value"] = newMsg; //behaviorInfo.Parameters["msg"] = newMsg; } Log.InfoFormat("New Msg: {0}, Count : {1}", newMsg, count); } } if (behaviorInfo.BehaviorName == "Move To") { var humanDict = behaviorInfo.Parameters.TryGetAndReturn("human") as Dictionary<string, object>; var rotDict = behaviorInfo.Parameters.TryGetAndReturn("rotation") as Dictionary<string, object>; var transDict = behaviorInfo.Parameters.TryGetAndReturn("translation") as Dictionary<string, object>; var distDict = behaviorInfo.Parameters.TryGetAndReturn("dist") as Dictionary<string, object>; float isHuman, isRotation, isTranslation; float.TryParse(humanDict.TryGetAndReturn("value").ToString(), out isHuman); float.TryParse(transDict.TryGetAndReturn("value").ToString(), out isTranslation); float.TryParse(rotDict.TryGetAndReturn("value").ToString(), out isRotation); if (isHuman > 0 && isRotation > 0) { // Get Robot String var robotString = GetRobotInfo(contextServer); // Get World String var worldFrame = GetWorldFrame(contextServer); Matrix3x3 robotRot; Matrix3x3 worldRot; Matrix3x3 humanRot; Quaternion robotQ; Quaternion worldQ; Quaternion humanQ; Vector3 robotTrans; Vector3 worldTrans; Vector3 humanTrans; // Get the transformation from the JSON strings GetHumanPoseFromJson(humanInfo, out humanTrans, out humanRot, out humanQ); GetLocalizationFromRobotJson(robotString, out robotTrans, out robotRot, out robotQ); GetWorldFrameMatrix(worldFrame, out worldTrans, out worldRot, out worldQ); var humanMat = GetMatrixFromPose(humanQ, new Vector3(0, 0, 0)); var worldMat = GetMatrixFromPose(worldQ, new Vector3(0, 0, 0)); var robotMat = GetMatrixFromPose(robotQ, new Vector3(0, 0, 0)); worldMat.Invert(); var hWorld = worldMat*humanMat; var hRobot = worldMat*robotMat; var hWorldQ = Quaternion.RotationMatrix(hWorld); var rWorldQ = Quaternion.RotationMatrix(hRobot); var hWorldYaw = GetHeading(hWorldQ); var rWorldYaw = GetHeading(rWorldQ); // Compute the displacement of Robot and Human wrt to world frame worldRot.Invert(); var hDisp = new Vector3(Vector3.Dot(worldRot.Column1, humanTrans), Vector3.Dot(worldRot.Column2, humanTrans), Vector3.Dot(worldRot.Column3, humanTrans)) - new Vector3(Vector3.Dot(worldRot.Column1, worldTrans), Vector3.Dot(worldRot.Column2, worldTrans), Vector3.Dot(worldRot.Column3, worldTrans)); var rDisp = new Vector3(Vector3.Dot(worldRot.Column1, robotTrans), Vector3.Dot(worldRot.Column2, robotTrans), Vector3.Dot(worldRot.Column3, robotTrans)) - new Vector3(Vector3.Dot(worldRot.Column1, worldTrans), Vector3.Dot(worldRot.Column2, worldTrans), Vector3.Dot(worldRot.Column3, worldTrans)); // We get the unit vector from Robot pointing towards human var toHumanVec = new Vector2(hDisp.X, hDisp.Y) - new Vector2(rDisp.X, rDisp.Y); toHumanVec.Normalize(); // Next we would like to align the X-Axis of the robot with that of this unit vector var yUnit = Vector2.UnitY; var xUnit = Vector2.UnitX; // Now we find the angle of rotation needed to do this alignment //var angle = Math.Acos(Vector2.Dot(toHumanVec, yUnit)); var angle = GetRelativeAngle(xUnit, toHumanVec); if (rWorldYaw > 0) angle += rWorldYaw; else angle -= rWorldYaw; // Update the values of X,Y,Theta var xDict = behaviorInfo.Parameters.TryGetAndReturn("x") as Dictionary<string, object>; var yDict = behaviorInfo.Parameters.TryGetAndReturn("y") as Dictionary<string, object>; var thetaDict = behaviorInfo.Parameters.TryGetAndReturn("theta") as Dictionary<string, object>; Log.InfoFormat("Move To Rotation Angle : {0}", MathUtil.RadiansToDegrees((float) angle)); if (xDict != null) { xDict["value"] = 0.0f; } if (yDict != null) { yDict["value"] = 0.0f; } if (thetaDict != null) { thetaDict["value"] = angle; } } else if (isHuman > 0 && isTranslation > 0) { // Get Robot String var robotString = GetRobotInfo(contextServer); // Get World String var worldFrame = GetWorldFrame(contextServer); Matrix3x3 robotRot; Matrix3x3 worldRot; Matrix3x3 humanRot; Quaternion robotQ; Quaternion worldQ; Quaternion humanQ; Vector3 robotTrans; Vector3 worldTrans; Vector3 humanTrans; // Get the transformation from the JSON strings GetHumanPoseFromJson(humanInfo, out humanTrans, out humanRot, out humanQ); GetLocalizationFromRobotJson(robotString, out robotTrans, out robotRot, out robotQ); GetWorldFrameMatrix(worldFrame, out worldTrans, out worldRot, out worldQ); var humanMat = GetMatrixFromPose(humanQ, new Vector3(0, 0, 0)); var worldMat = GetMatrixFromPose(worldQ, new Vector3(0, 0, 0)); var robotMat = GetMatrixFromPose(robotQ, new Vector3(0, 0, 0)); worldMat.Invert(); var hWorld = worldMat*humanMat; var hRobot = worldMat*robotMat; var hWorldQ = Quaternion.RotationMatrix(hWorld); var rWorldQ = Quaternion.RotationMatrix(hRobot); var hWorldYaw = GetHeading(hWorldQ); var rWorldYaw = GetHeading(rWorldQ); // Compute the displacement of Robot and Human wrt to world frame worldRot.Invert(); var hDisp = new Vector3(Vector3.Dot(worldRot.Column1, humanTrans), Vector3.Dot(worldRot.Column2, humanTrans), Vector3.Dot(worldRot.Column3, humanTrans)) - new Vector3(Vector3.Dot(worldRot.Column1, worldTrans), Vector3.Dot(worldRot.Column2, worldTrans), Vector3.Dot(worldRot.Column3, worldTrans)); var rDisp = new Vector3(Vector3.Dot(worldRot.Column1, robotTrans), Vector3.Dot(worldRot.Column2, robotTrans), Vector3.Dot(worldRot.Column3, robotTrans)) - new Vector3(Vector3.Dot(worldRot.Column1, worldTrans), Vector3.Dot(worldRot.Column2, worldTrans), Vector3.Dot(worldRot.Column3, worldTrans)); // We get the unit vector from Robot pointing towards human var toHumanVec = new Vector2(hDisp.X, hDisp.Y) - new Vector2(rDisp.X, rDisp.Y); var distance = toHumanVec.Length(); var threshold = distance; if (distDict != null) { float.TryParse(humanDict.TryGetAndReturn("value").ToString(), out threshold); } var residual = 0.0f; if (distance > threshold) { residual = distance - threshold; } // Unit Vector toHumanVec.Normalize(); //var residualVector = toHumanVec*residual; var residualVector = Vector2.UnitX*residual; // Update the values of X,Y,Theta var xDict = behaviorInfo.Parameters.TryGetAndReturn("x") as Dictionary<string, object>; var yDict = behaviorInfo.Parameters.TryGetAndReturn("y") as Dictionary<string, object>; var thetaDict = behaviorInfo.Parameters.TryGetAndReturn("theta") as Dictionary<string, object>; Log.InfoFormat("Move To X : {0}, Y:{1}", residualVector.X, residualVector.Y); if (xDict != null) { xDict["value"] = 0.75*residualVector.X; } if (yDict != null) { yDict["value"] = 0.75*residualVector.Y; } if (thetaDict != null) { thetaDict["value"] = 0.0f; } } } SyncExecuteBehavior(behaviorInfo); } } } if (behavior.BehaviorType == BehaviorType.Behavior) { if (behavior.ExecutionLifetime == BehaviorExecutionLifetime.once) { behavior.CyclicActionsComplete = true; } if (behavior.RobotActions.Count == 0) { behavior.CyclicActionsComplete = true; } if (behavior.ExecutionLifetime == BehaviorExecutionLifetime.until) { if (!string.IsNullOrEmpty(behavior.ExecutionEvalExpression) && !string.IsNullOrEmpty(behavior.TriggerCountVariable)) { // Evaluating Termination condition var expression = new Expression(behavior.ExecutionEvalExpression); expression.Parameters.Add(behavior.TriggerCountVariable, count + 1); var result = expression.Evaluate(); bool complete; if (bool.TryParse(result.ToString(), out complete)) { behavior.CyclicActionsComplete = !complete; } } } } // Execute exit actions only once if (behavior.CyclicActionsComplete && !behavior.ExitActionsComplete) { SyncExecuteBehavior(contextServer, behavior.ExitActions); behavior.ExitActionsComplete = true; } } } catch (Exception ex) { Log.ErrorFormat("Simple behavior error : {0}", ex.Message); Log.ErrorFormat("Simple behavior stack_trace : {0}", ex.StackTrace); } }
/// <summary> /// returns the signed angle between the two vectors /// </summary> /// <param name="v0"></param> /// <param name="v1"></param> /// <returns></returns> public static double SignedAngle(this Vector2 v0, Vector2 v1) { var v0Length = v0.Length(); if (v0Length == 0) { throw new ArgumentException("Length must be greater than 0.", nameof(v0)); } var v1Length = v1.Length(); if (v1Length == 0) { throw new ArgumentException("Length must be greater than 0.", nameof(v1)); } var sign = Math.Sign(Vector3.Cross(v0.To3D(), v1.To3D()).Z); var acos = Math.Acos(Vector2.Dot(v0, v1) / v0Length / v1Length); return Double.IsNaN(acos) ? 0 : acos * sign; }
public static float CosAngle(this PointF c) { return(c.X / c.Length()); }
/// <summary> /// Calculates the unit length right-hand normal of v. /// </summary> /// <param name="v">Vector to find the normal of.</param> public static Vector2 GetNormal(Vector2 v) { //Avoid division by zero/returning a zero vector if (Math.Abs(v.Y) < 0.0001) return new Vector2(0, Math.Sign(v.X)); if (Math.Abs(v.X) < 0.0001) return new Vector2(-Math.Sign(v.Y), 0); float r = 1 / v.Length(); return new Vector2(-v.Y * r, v.X * r); }
public void DoProcess() { Main.IsRunning = true; this.GameWindowHandle = this.GameMemory.Process.MainWindowHandle; Native.SetForegroundWindow(this.GameWindowHandle); while (this.GameWindowHandle != IntPtr.Zero && Main.IsRunning && this.GameMemory.IsOpen) { this.GameWindowRect = GetWindowRect(this.GameWindowHandle); this.GameWindowSize.X = this.GameWindowRect.Right - this.GameWindowRect.Left; this.GameWindowSize.Y = this.GameWindowRect.Bottom - this.GameWindowRect.Top; this.GameWindowCenter.X = this.GameWindowRect.Left + (this.GameWindowSize.X / 2); this.GameWindowCenter.Y = this.GameWindowRect.Top + (this.GameWindowSize.Y / 2) + 11; DXDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1f, 0); DXDevice.SetRenderState(RenderState.ZEnable, false); DXDevice.SetRenderState(RenderState.Lighting, false); DXDevice.SetRenderState<Cull>(RenderState.CullMode, Cull.None); DXDevice.BeginScene(); long entityOffset = this.GameMemory.ReadInt64(CGameOffset); long playerOffset = this.GameMemory.ReadInt64(entityOffset + 0x11D8); if ((player_rad >=-11.25) && (player_rad <=11.25)) {player_C ="E";} else if ((player_rad >=11.25) && (player_rad <=33.75)) { player_C ="ENE"; } else if ((player_rad >=33.75) && (player_rad <=56.25)) { player_C ="NE"; } else if ((player_rad >=56.25) && (player_rad <=78.75)) { player_C ="NNE"; } else if ((player_rad >=78.75) && (player_rad <=101.25)) { player_C ="N"; } else if ((player_rad >=101.25) && (player_rad <=123.75)) { player_C ="NNW"; } else if ((player_rad >=123.75) && (player_rad <=146.25)) { player_C ="NW"; } else if ((player_rad >=146.25) && (player_rad <=168.75 )) { player_C ="WNW"; } else if ((player_rad >=168.75) && (player_rad <=180)) { player_C ="W"; } else if ((player_rad >=-180) && (player_rad <=-168.75)) { player_C ="W"; } else if ((player_rad >=-168.75) && (player_rad <=-146.25)) { player_C ="WSW"; } else if ((player_rad >=-146.25) && (player_rad <=-123.75)) { player_C ="SW"; } else if ((player_rad >=-123.75) && (player_rad <=-101.25)) { player_C ="SSW"; } else if ((player_rad >=-101.25) && (player_rad <=-78.75)) { player_C ="S"; } else if ((player_rad >=-78.75) && (player_rad <=-56.25)) { player_C ="SSE"; } else if ((player_rad >=-56.75) && (player_rad <=-33.75)) { player_C ="SE"; } else if ((player_rad >=-33.75) && (player_rad <=-11.25)) { player_C ="ESE"; } player_X = this.GameMemory.ReadFloat(playerOffset + 0x200); player_Y = this.GameMemory.ReadFloat(playerOffset + 0x204); player_Z = this.GameMemory.ReadFloat(playerOffset + 0x208); player_D = this.GameMemory.ReadFloat(playerOffset + 0x2D0); player_rad = player_D * (180.0/Math.PI); PlayerPosition.X = player_X; PlayerPosition.Y = player_Y; PlayerPosition.Z = player_Z; TextRegion = new POINT(this.GameWindowRect.Left + 15, this.GameWindowRect.Top + 35); if (ShowPosition) { DrawText("Position X: " + player_X.ToString("F1") + " Y: " + player_Y.ToString("F1") + " Z: " + player_Z.ToString("F1"), ref TextRegion, Color.White); DrawText("Direction: " + player_D.ToString("F2"), ref TextRegion, Color.White); DrawText("方向:" + player_C, ref TextRegion, Color.White); DrawText("*Greenshot為免費程式請勿商業行為*", ref TextRegion, Color.SkyBlue); } ShowESP = (!HideESPWhenAiming || Convert.ToBoolean(Native.GetAsyncKeyState(2) & 0x8000) == false); Entity.Clear(); Aimed = false; int entityCount = this.GameMemory.ReadInt32(entityOffset + 0x688); long entityEntry = this.GameMemory.ReadInt64(playerOffset + 0x420); for (int i = 1; i < entityCount; i++) { float EntityX = 0; float EntityY = 0; float EntityZ = 0; float EntityYaw = 0; float EntityPitch = 0; float EntitySpeed = 0; IsCorpse = false; InVehicle = false; IsDriving = false; /* //XYZ// posOffset = this.GameMemory.ReadInt64(entityEntry + 0x198); if (EntityType == 0x04 || EntityType == 0x05) { EntityX = this.GameMemory.ReadFloat(posOffset + 0x100); EntityY = this.GameMemory.ReadFloat(posOffset + 0x104); EntityZ = this.GameMemory.ReadFloat(posOffset + 0x108); EntitySpeed = this.GameMemory.ReadFloat(entityEntry + 0x2C8); EntityYaw = this.GameMemory.ReadFloat(entityEntry + 0x2E0); }*/ int EntityType = this.GameMemory.ReadInt32(entityEntry + 0x5E0); if (EntityType == 0) continue; int EntityId = this.GameMemory.ReadInt32(entityEntry + 0x638); long _nameEntry = this.GameMemory.ReadInt64(entityEntry + 0x4F8); String EntityName = this.GameMemory.ReadString(_nameEntry, this.GameMemory.ReadInt32(entityEntry + 0x500)); // Get Player Pos // if (EntityType == 0x04 || EntityType == 0x05) { EntityX = this.GameMemory.ReadFloat(entityEntry + 0x3E0); EntityY = this.GameMemory.ReadFloat(entityEntry + 0x3E4); EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x3E8); } else { EntityX = this.GameMemory.ReadFloat(entityEntry + 0x3C90); EntityY = this.GameMemory.ReadFloat(entityEntry + 0x3C94); EntityZ = this.GameMemory.ReadFloat(entityEntry + 0x3C98); } // Create New Entity // ENTITY currentEntity = new ENTITY() { Id = EntityId, Type = EntityType, Name = EntityName, Pos = new Vector3(EntityX, EntityY, EntityZ), Distance = Vector3.Distance(new Vector3(EntityX, EntityY, EntityZ), PlayerPosition), Yaw = EntityYaw, Pitch = EntityPitch, Speed = EntitySpeed }; // Append New Entity // Entity.Add(currentEntity); Int32 EntityState = this.GameMemory.ReadInt32(entityEntry + 0x5D8); // 自瞄及顯示用 // Detect type of Loot (Corpse or Loot) // if (currentEntity.Type == 0x2E && this.GameMemory.ReadByte(entityEntry + 0x1D88) == 0xE4) { IsCorpse = true; currentEntity.Name = "Corpse"; } /* // display EntityType // if (ShowESP) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "\n" + "[" + BoneID.ToString("X2") + "]" + "[" + EntityType.ToString("X4") + "]", Color.Red, true, false, false, 2f, EntityYaw, EntityPitch); break;*/ switch (EntityType) { case 0x04/*Player*/: case 0x05/*BR Player*/: /* case 0x11: // OffRoad case 0x72: // Pickup case 0x76: // PoliceCar*/ #region // Aiming // Vector3 aimingTo = Vector3.Zero; if (Aimed == true || currentEntity.Distance > 200f || this.GameMemory.ReadByte(entityEntry + 0x13AC) != 1) { /* Already aimed, not in range, entity is dead */ } else if (ModifierKeys.HasFlag(Keys.Control) == true) { if (AimedEntity != null && AimedEntity.Id == currentEntity.Id) { if (Convert.ToBoolean(this.GameMemory.ReadByte(entityEntry + 0x13AC)) == false) //old 0x137C { // Target is dead // AimedEntity = null; } else { Aimed = true; AimedEntity = currentEntity; Vector3 AIM; float offsetY = 0f; { switch (EntityState) { case 0: offsetY = 1.75f; ; break; // Standing [站立] case 1: offsetY = 1.05f; ; break; // Crouched [坐著] case 2: offsetY = 1.55f; break; // Walking [走路] case 3: offsetY = 1.55f; break; // Running [跑步] case 4: offsetY = 1.60f; break; // Jumping [跳躍] case 5: offsetY = 1.05f; break; // Crouching [蹲著] case 6: offsetY = 0.3f; break; // Prone [趴著] case 7: offsetY = 0.3f; break; // Crawling [爬行] } } if (WorldToScreen(new Vector3(AimedEntity.Pos.X, AimedEntity.Pos.Y + offsetY, AimedEntity.Pos.Z), out AIM)) { int moveOffsetX = (int)(Math.Round(AIM.X) - this.GameWindowCenter.X) / AimC; int moveOffsetY = (int)(Math.Round(AIM.Y) - this.GameWindowCenter.Y) / AimC; DrawText("Aimed at " + AimedEntity.Name + ": " + moveOffsetX + ", " + moveOffsetY, ref TextRegion, Color.Red); if (moveOffsetX != 0 || moveOffsetY != 0) Native.mouse_event(0x0001, (short)moveOffsetX, (short)moveOffsetY, 0, 0); } } } else if (AimedEntity == null && WorldToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), out aimingTo)) // EntityY + 1f old { float distance = Vector2.Distance(new Vector2(aimingTo.X, aimingTo.Y), new Vector2(this.GameWindowCenter.X, this.GameWindowCenter.Y)); if (distance < 100f) { AimedEntity = currentEntity; Aimed = true; float moveOffsetX = aimingTo.X - this.GameWindowCenter.X; float moveOffsetY = aimingTo.Y - this.GameWindowCenter.Y; Native.mouse_event(0x0001, (short)moveOffsetX, (short)moveOffsetY, 0, 0); } } } // AIM 2 // else if (Convert.ToBoolean(Native.GetAsyncKeyState(Keys.CapsLock) & 0x8000) || Convert.ToBoolean(Native.GetAsyncKeyState(Keys.XButton1) & 0x8000) == true) { if (AimedEntity != null && AimedEntity.Id == currentEntity.Id) { if (Convert.ToBoolean(this.GameMemory.ReadByte(entityEntry + 0x13AC)) == false) { // Target is dead // AimedEntity = null; } else { Aimed = true; AimedEntity = currentEntity; Vector3 AIM; float offsetY = 0f; { switch (EntityState) { case 0: offsetY = 1.75f; ; break; // Standing [站立] case 1: offsetY = 1.05f; ; break; // Crouched [坐著] case 2: offsetY = 1.65f; break; // Walking [走路] case 3: offsetY = 1.65f; break; // Running [跑步] case 4: offsetY = 1.55f; break; // Jumping [跳躍] case 5: offsetY = 1.05f; break; // Crouching [蹲著] case 6: offsetY = 0.3f; break; // Prone [趴著] case 7: offsetY = 0.3f; break; // Crawling [爬行] } } if (WorldToScreen(new Vector3(AimedEntity.Pos.X, AimedEntity.Pos.Y + offsetY, AimedEntity.Pos.Z), out AIM)) { int moveOffsetX = (int)(Math.Round(AIM.X) - this.GameWindowCenter.X) * 2; // /1 int moveOffsetY = (int)(Math.Round(AIM.Y) - this.GameWindowCenter.Y) * 2; // /1 DrawText("Aimed at " + AimedEntity.Name + ": " + moveOffsetX + ", " + moveOffsetY, ref TextRegion, Color.Red); if (moveOffsetX != 0 || moveOffsetY != 0) Native.mouse_event(0x0001, (short)moveOffsetX, (short)moveOffsetY, 0, 0); } } } else if (AimedEntity == null && WorldToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), out aimingTo)) // EntityY + 1f old { float distance = Vector2.Distance(new Vector2(aimingTo.X, aimingTo.Y), new Vector2(this.GameWindowCenter.X, this.GameWindowCenter.Y)); if (distance < 50f) { AimedEntity = currentEntity; Aimed = true; float moveOffsetX = aimingTo.X - this.GameWindowCenter.X; float moveOffsetY = aimingTo.Y - this.GameWindowCenter.Y; Native.mouse_event(0x0001, (short)moveOffsetX, (short)moveOffsetY, 0, 0); } } } else { AimedEntity = null; } # endregion */ // Player Behavior // if (EntityType == 0x04 || EntityType == 0x05) { switch (EntityState) { case 0: EntityName += " [站立]"; break; // Standing case 1: EntityName += " [坐著]"; break; // Crouched case 2: EntityName += " [走路]"; break; // Walking case 3: EntityName += " [跑步]"; break; // Running case 4: EntityName += " [跳躍]"; break; // Jumping case 5: EntityName += " [蹲著]"; break; // Crouching case 6: EntityName += " [趴著]"; break; // Prone case 7: EntityName += " [爬行]"; break; // Crawling } } //* // Show Entity when ESP enabled // if (ShowESP) // && this.GameMemory.ReadFloat(entityEntry + 0x1CC) == 1f) { Byte EntityAlive = this.GameMemory.ReadByte(entityEntry + 0x13AC); Byte EntityAlive2 = (this.GameMemory.ReadUInt32(this.GameMemory.ReadInt64(entityEntry + 0x4098L) + 0xB0L) / 100 == 30) && (EntityType == 0x0C || EntityType == 0x5B) ? (byte)0 : (byte)1; if (HideDead == false || Convert.ToBoolean(EntityAlive) == true) { // Player // if (EntityType == 0x04 || EntityType == 0x05) { // Show HP if(ShowESP) { long HPoffset = this.GameMemory.ReadInt64(entityEntry + 0x4098L); // old 0x4058L oldold 0x3fa8L uint playerHP = this.GameMemory.ReadUInt32(HPoffset + 0xb0L) / 100; { HPoffset = this.GameMemory.ReadInt64(HPoffset + 0xF8); } int Hue = (int)(120f * (float)playerHP / 100f); // Hue red at 0° green at 120° Color color = ColorTranslator.FromWin32(ColorHLSToRGB(Hue, 120, 240)); // H,L,S; string playerNameHP = EntityName + " " + playerHP.ToString() + "%"; /* long HPoffset = this.GameMemory.ReadInt64(entityEntry + 0x4068L); uint eHP = this.GameMemory.ReadUInt32(HPoffset + 0xb0L); uint maxHP = this.GameMemory.ReadUInt32(HPoffset + 0xb4L); if (maxHP != 0) { uint entityHP = 100 * eHP / maxHP; EntityName = EntityName + " " + entityHP.ToString() + "%" + " " + "[" + state + "]"; }*/ if (ShowPlayers) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), playerNameHP, color, true, false, BoxedPlayers, 2f, EntityYaw, EntityPitch); } else { if (ShowPlayers) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.SkyBlue, true, false, BoxedPlayers, 2f, EntityYaw, EntityPitch); } } // Aggressive NPC (Wolf, Bear, Zombies) // else { if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.Red, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); } } } break; // Deer or Rabbit // case 0x13: // Deer if (ShowAnimals) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.DarkGreen, true, false, BoxedAnimals, 2f, EntityYaw, EntityPitch); break; case 0x55: // Rabbit if (ShowAnimals) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.DarkGreen, true, false, BoxedAnimals, 2f, EntityYaw, EntityPitch); break; // Aggressive NPC (Wolf, Bear, Zombies) // case 0x0C: // Zombies if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Thistle, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); break; case 0x5b: // Zombies if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Red, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); break; case 0x14: // Wolf if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Red, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); break; case 0x50: // Bear if (ShowAggressive) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Red, true, false, BoxedAggressive, 2f, EntityYaw, EntityPitch); break; case 0x2E: // Loot if (ShowESP && ShowRoot) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "\n" + "[" + EntityType.ToString("X2") + "]" + "[" + EntityType.ToString("X4") + "]", Color.GreenYellow, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); break; /* if (ShowRoot) { if (IsCorpse == false) { if (ShowESP && ShowItems) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.GreenYellow, true, false, BoxedItems, 1f, EntityYaw, EntityPitch); } else if (ShowCorpse == true) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), currentEntity.Name, Color.Olive, true, false, BoxedItems, 1f, EntityYaw, EntityPitch); } }*/ case 0x1B: // Campfire case 0x6D: // Stash case 0x9C: // Land Mine if (ShowESP && ShowItems && !BRMode) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.SaddleBrown, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); break; case 0x2F: // Furnace // case 0x33: // Storage Container case 0x35: // Animal Trap case 0x36: // Dew Collector case 0x53: // Barbeque if (ShowESP && ShowContainers) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Gray, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); break; case 0x34: // Weapons if (ShowESP && ShowWeapons) { if (EntityName.Contains("M1911") || EntityName.Contains("AR15") || EntityName.Contains(".308 Hunting Rifle") || EntityName.Contains("12GA Pump Shotgun") || EntityName.Contains("M9") || EntityName.Contains("R380") || EntityName.Contains("Recurve Bow") || EntityName.Contains("Crowbar")) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "\n" + "[" + EntityType.ToString("X2") + "]", Color.GreenYellow, true, false, BoxedItems, 1f, 0f, 0f); } break; case 0x15: // Ammo if (ShowESP && ShowAmmo) { if (EntityName.Contains(".45 Round") || EntityName.Contains(".308 Round") || EntityName.Contains(".223 Round") || EntityName.Contains("Shotgun Shell") || EntityName.Contains(".380 round") || EntityName.Contains("9mm Round")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Orange, true, false, BoxedItems, 1f, 0f, 0f); } else this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Moccasin, true, false, BoxedItems, 1f, 0f, 0f); } break; case 0x11: // OffRoad case 0x72: // Pickup case 0x76: // PoliceCar if (ShowESP && ShowVehicles) { if (EntityType == 0x11 || EntityType == 0x72 || EntityType == 0x76) { if (ShowVehicles) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.HotPink, true, false, BoxedVehicles, 2f, EntityYaw, EntityPitch); } } if (ShowESP && ShowVehicles) this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.HotPink, true, false, BoxedVehicles, 2f, 0f, 0f); break; case 0x2C: // Resources, Battary, Turbo, Sparkplugs if (ShowESP && ShowItems) { if (ShowFirstAid || ShowBackpack || ShowHelmet) { if (ShowFirstAid && EntityName.Contains("First")) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.LimeGreen, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); if (ShowBackpack && EntityName.Contains("Backpack") || EntityName.Contains("Waist Pack")) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.CornflowerBlue, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); if (ShowHelmet && EntityName.Contains("Helmet") || EntityName.Contains("Body Armor")) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.IndianRed, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); } else { if (EntityName.Contains("Battery") || EntityName.Contains("Turbo") || EntityName.Contains("Headlights") || EntityName.Contains("Sparkplugs")) { this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.Plum, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); } else this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.White, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); } } break; case 0x16: // Dresser case 0x17: // Armoire case 0x19: // World Doors case 0x1D: // Cabinets case 0x1E: // Cabinets case 0x21: // Cabinets case 0x22: // Cabinets case 0x23: // Cabinets case 0x25: // Refrigerator case 0x26: // Garbage Can case 0x28: // Cabinets case 0x29: // Desk case 0x27: // Dumpster case 0x30: // File Cabinet case 0x31: // Tool Cabinet case 0x37: // Recycle Bin (with fire) case 0x38: // Punji Sticks case 0x3D: // Wooded Barricade case 0x3E: // Water Well case 0x3F: // Armoire case 0x40: // Dresser case 0x42: // Chest case 0x44: // Wrecked Sedan case 0x45: // Wrecked Van case 0x46: // Wrecked Truck case 0x49: // Ottoman case 0x4A: // Ottoman case 0x4F: // Designer-placed(?) Door case 0x5D: // File Cabinet case 0x61: // Cabinets case 0x63: // Cabinets case 0x6F: // Locker case 0x70: // Weapon Locker case 0x71: // Glass Cabinet case 0x79: // Designer-placed(?) Door case 0x7A: // Resting (Bed) case 0x7B: // Designer-placed(?) Door case 0x7C: // Designer-placed(?) Door case 0x80: // Cabinets case 0x81: // Cabinets case 0x82: // Cabinets case 0x83: // Cabinets case 0x84: // Cabinets case 0x85: // Cabinets case 0x86: // Cabinets case 0x87: // Cabinets case 0x88: // Cabinets case 0x8D: // Military_Cache case 0x8F: // BR_Military_Cache case 0xA1: // Washing Machine case 0xA2: // Dryer case 0x7D: // IO.FireHydrant case 0x7E: // IO.FireHydrant //this.WorldToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityId.ToString("X2") + "]", Color.Gray, true, false, false, 0f, 0f); break; case 0x8E: // 空頭 if (ShowESP && ShowItems && !BRMode) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName, Color.SaddleBrown, true, false, BoxedItems, 0.15f, 0.15f, 0.15f); break; case 0x4C: // Shed case 0x5F: // Metal Wall/Gate case 0x62: // Basic Shack Door case 0x6E: // Desk Foundation case 0x9E: // Metal Door case 0xA6: // Large Shelter case 0xA7: // Shed //this.WorldToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityId.ToString("X2") + "]", Color.Gray, true, false, false, 0f, 0f); break; /* // display EntityType // if (ShowESP) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), "\n" + "[" + EntityType + "]" + "[" + EntityType.ToString("X2") + "]", Color.Red, true, false, false, 1f, 0.30f, 0.30f); break;*/ case 0x2A: //手銬key if (ShowAmmo) { this.EntityToScreen(new Vector3(EntityX, EntityY + 1f, EntityZ), EntityName, Color.White, true, false, BoxedVehicles, 2f, EntityYaw, EntityPitch); } break; default: // Other Items /* if (ShowESP && ShowItems && !BRMode) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "[" + EntityType.ToString("X2") + "]" + "\n" + "[" + EntityType + "]", Color.White, true, false, false, 0.15f, 0.30f, 0.30f); break; // +"\n"+"["+ EntityType +"]"*/ // display EntityType // if (Convert.ToBoolean(Native.GetAsyncKeyState(Keys.XButton2) & 0x8000) == true) this.EntityToScreen(new Vector3(EntityX, EntityY, EntityZ), EntityName + "\n" + "[" + EntityType.ToString("X2") + "]" + "[" + EntityType.ToString("X4") + "]", Color.Red, true, false, false, 2f, EntityYaw, EntityPitch); break; } entityEntry = this.GameMemory.ReadInt64(entityEntry + 0x420); } if (Aimed == false) AimedEntity = null; if (ShowEntityLists) { ENTITY[] playerList = Entity.Where(E => E.Type == 0x04 || E.Type == 0x05).OrderBy(E => E.Distance).ToArray(); ENTITY[] aggressiveList = Entity.Where(E => E.Type == 0x0C || E.Type == 0x14 || E.Type == 0x50 || E.Type == 0x5b).OrderBy(E => E.Distance).ToArray(); ENTITY[] animalsList = Entity.Where(E => E.Type == 0x13 || E.Type == 0x55).OrderBy(E => E.Distance).ToArray(); ENTITY[] vehiclesList = Entity.Where(E => E.Type == 0x11 || E.Type == 0x72 || E.Type == 0x76).OrderBy(E => E.Distance).ToArray(); ENTITY[] ammoList = Entity.Where(E => E.Type == 0x15).OrderBy(E => E.Distance).ToArray(); int itemY = (aggressiveList.Length > 10 ? 150 : aggressiveList.Length * 15); foreach (ENTITY entity in aggressiveList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 20, this.GameWindowRect.Bottom - itemY - 15, Color.Red); itemY -= 15; if (itemY <= 0) break; } itemY = (animalsList.Length > 10 ? 150 : animalsList.Length * 15); foreach (ENTITY entity in animalsList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 120, this.GameWindowRect.Bottom - itemY - 15, Color.Green); itemY -= 15; if (itemY <= 0) break; } itemY = (vehiclesList.Length > 10 ? 150 : vehiclesList.Length * 15); foreach (ENTITY entity in vehiclesList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 220, this.GameWindowRect.Bottom - itemY - 15, Color.HotPink); itemY -= 15; if (itemY <= 0) break; } itemY = (playerList.Length > 10 ? 150 : playerList.Length * 15); foreach (ENTITY entity in playerList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 340, this.GameWindowRect.Bottom - itemY - 15, Color.SkyBlue); itemY -= 15; if (itemY <= 0) break; } itemY = (ammoList.Length > 10 ? 150 : ammoList.Length * 15); foreach (ENTITY entity in ammoList) { DrawText(entity.Name + " [" + Math.Round(entity.Distance).ToString() + " m]", this.GameWindowRect.Left + 440, this.GameWindowRect.Bottom - itemY - 15, Color.Orange); itemY -= 15; if (itemY <= 0) break; } } /* if (ShowRadar) { DrawFilledBox(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, Color.LightSlateGray, RadarTransparency); DrawBoxAbs(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 50, this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 251, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 150, this.GameWindowRect.Right - 24, this.GameWindowRect.Top + 150, 1f, Color.Black); RadarCenter = new Vector2(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 125 + 25); DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White); if (RadarCenter.Length() > 0f) { foreach (ENTITY entity in Entity) { Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z); Vector2 vector3 = new Vector2(player_X, player_Z); pointToRotate = vector3 - pointToRotate; float num30 = pointToRotate.Length() * 0.5f; num30 = Math.Min(num30, 90f); pointToRotate.Normalize(); pointToRotate = (Vector2)(pointToRotate * num30); pointToRotate += RadarCenter; pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true); if ((entity.Type == 0x04 || entity.Type == 0x05) && RadarPlayers) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.SkyBlue); } if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red); } if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen); } if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles) { //DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.HotPink); DrawBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, 1f, Color.HotPink); } } } } */ if (ShowRadar) { if (RadarMap) { int marginRight = 50; int marginTop = 50; // place the radar in the top right (-50px) corner of the screen int radarRadius = 128; // max display distance in [m] float mapScale = 0.5f; // = Texture.Width / 8192f (if you use image of size 4096x4096 then mapScale = 0.5f, if 2048x2048 then mapScale = 0.25f) if (DXTextureGameMap != null) { Matrix mRT = Matrix.RotationZ(-(player_D - 1.57079632679f)) * Matrix.Translation(-this.Width / 2 + GameWindowRect.Right - marginRight - radarRadius, this.Height / 2 - GameWindowRect.Top - marginTop - radarRadius, 0); Matrix mView = Matrix.Identity; Matrix mProj = Matrix.OrthoLH(this.Width, this.Height, 0f, 1.0f); DXDevice.SetTransform(TransformState.World, mRT); DXDevice.SetTransform(TransformState.View, mView); DXDevice.SetTransform(TransformState.Projection, mProj); // Transform in-game player position to the image map, (x,y) in [-4096,4096]x[-4096,4096]->[0,4096]x[0,4096] float mapX = (4096 + player_Z) * mapScale; float mapY = (4096 - player_X) * mapScale; // and now to texture coordinates [0,4096] -> [0,1] mapX = mapX / (float)4096; mapY = mapY / (float)4096; Vector2 playerPosition = new Vector2(mapX, mapY); float scale = radarRadius / (float)4096; DataStream stream = CircleVertices.Lock(0, 0, LockFlags.None); stream.WriteRange(BuildVertexCircle(Vector2.Zero, playerPosition, radarRadius, scale, circleComplexity)); CircleVertices.Unlock(); DXDevice.SetStreamSource(0, CircleVertices, 0, TexVertex.SizeBytes); DXDevice.VertexFormat = TexVertex.Format; DXDevice.SetTexture(0, DXTextureGameMap); /* alpha blending not working as expected DXDevice.SetRenderState(RenderState.AlphaBlendEnable, true); DXDevice.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.BlendFactor); DXDevice.SetRenderState(RenderState.BlendFactor, 0xffffff); */ DXDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); DXDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear); DXDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear); DXDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, circleComplexity); } else // just paint green background { DrawFilledBox(this.GameWindowRect.Right - marginRight - radarRadius * 2, this.GameWindowRect.Top + marginTop, radarRadius * 2, radarRadius * 2, Color.DarkOliveGreen, RadarTransparency); DrawBoxAbs(this.GameWindowRect.Right - marginRight - radarRadius * 2, this.GameWindowRect.Top + marginTop, radarRadius * 2, radarRadius * 2, 1f, Color.Black); } RadarCenter = new Vector2(this.GameWindowRect.Right - marginRight - radarRadius, this.GameWindowRect.Top + marginTop + radarRadius); if (RadarCenter.Length() > 0f) { // vertical line DrawLine(RadarCenter.X, this.GameWindowRect.Top + marginTop, RadarCenter.X, this.GameWindowRect.Top + marginTop + radarRadius * 2, 1f, Color.Black); // horizontal line DrawLine(this.GameWindowRect.Right - marginRight - radarRadius * 2, RadarCenter.Y, this.GameWindowRect.Right - marginRight, RadarCenter.Y, 1f, Color.Black); // center point DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White); if (RadarLine) { //動物 DrawLine(RadarCenter.X - 3, RadarCenter.Y - 10, RadarCenter.X + 3, RadarCenter.Y - 10, 1f, Color.White); DrawLine(RadarCenter.X - 3, RadarCenter.Y + 10, RadarCenter.X + 3, RadarCenter.Y + 10, 1f, Color.White); DrawLine(RadarCenter.X - 10, RadarCenter.Y - 3, RadarCenter.X - 10, RadarCenter.Y + 3, 1f, Color.White); DrawLine(RadarCenter.X + 10, RadarCenter.Y - 3, RadarCenter.X + 10, RadarCenter.Y + 3, 1f, Color.White); //物品 DrawLine(RadarCenter.X - 5, RadarCenter.Y - 80, RadarCenter.X + 5, RadarCenter.Y - 80, 1f, Color.White); DrawLine(RadarCenter.X - 5, RadarCenter.Y + 80, RadarCenter.X + 5, RadarCenter.Y + 80, 1f, Color.White); DrawLine(RadarCenter.X - 80, RadarCenter.Y - 5, RadarCenter.X - 80, RadarCenter.Y + 5, 1f, Color.White); DrawLine(RadarCenter.X + 80, RadarCenter.Y - 5, RadarCenter.X + 80, RadarCenter.Y + 5, 1f, Color.White); } //Display each entity in correct relational position foreach (ENTITY entity in Entity) { if (entity.Type == 0x04 || entity.Type == 0x05 || entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b || entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b || entity.Type == 0x13 || entity.Type == 0x55 || entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) { Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z); Vector2 playerPosition = new Vector2(player_X, player_Z); pointToRotate = playerPosition - pointToRotate; float distance = pointToRotate.Length(); distance = Math.Min(distance, (float)radarRadius * 2); pointToRotate.Normalize(); pointToRotate = (Vector2)(pointToRotate * distance * mapScale); pointToRotate += RadarCenter; pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true); if ((entity.Type == 0x05 || entity.Type == 0x04) && RadarPlayers) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 4f, 4f, Color.Black); DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.DeepSkyBlue); } if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red); } if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen); } if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles) { DrawBox(pointToRotate.X, pointToRotate.Y, 4f, 4f, 2f, Color.HotPink); } } } } } else { DrawFilledBox(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, Color.DimGray, RadarTransparency); DrawBoxAbs(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 50, this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 251, 1f, Color.Black); DrawLine(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 150, this.GameWindowRect.Right - 24, this.GameWindowRect.Top + 150, 1f, Color.Black); RadarCenter = new Vector2(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 125 + 25); DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White); if (RadarCenter.Length() > 0f) { foreach (ENTITY entity in Entity) { Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z); Vector2 vector3 = new Vector2(player_X, player_Z); pointToRotate = vector3 - pointToRotate; float num30 = pointToRotate.Length() * 0.5f; num30 = Math.Min(num30, 90f); pointToRotate.Normalize(); pointToRotate = (Vector2)(pointToRotate * num30); pointToRotate += RadarCenter; pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true); if ((entity.Type == 0x04 || entity.Type == 0x05) && RadarPlayers) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.SkyBlue); } if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red); } if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen); } if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles) { DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.HotPink); } } } } } if (ShowCities) { this.EntityToScreen(new Vector3(-129f, 40f, -1146f), "Pleasant Valley", Color.HotPink, true, false, false, 1f, 0f, 0f); this.EntityToScreen(new Vector3(-1233f, 90f, 1855f), "Cranberry", Color.HotPink, true, false, false, 1f, 0f, 0f); this.EntityToScreen(new Vector3(2003f, 50f, 2221f), "Ranchito", Color.HotPink, true, false, false, 1f, 0f, 0f); } if (Main.ShowMap && (DXTextrureMap != null || DXTextrureMapLarge != null)) { DXSprite.Begin(SpriteFlags.AlphaBlend); if (Main.ShowMapLarge && DXTextrureMapLarge != null) { map_pos_x = RemapValue(player_X, 4000f, -4000f, -512f, 512f); map_pos_z = RemapValue(player_Z, -4000f, 4000f, -512f, 512f); DXSprite.Draw(DXTextrureMapLarge, new Vector3(512f, 512f, 0f), new Vector3(this.GameWindowCenter.X, this.GameWindowCenter.Y, 0f), Color.FromArgb(MapTransparency, 0xff, 0xff, 0xff)); } else if (DXTextrureMap != null) { map_pos_x = RemapValue(player_X, 4000f, -4000f, -265f, 265f); map_pos_z = RemapValue(player_Z, -4000f, 4000f, -265f, 265f); DXSprite.Draw(DXTextrureMap, new Vector3(256f, 256f, 0f), new Vector3(this.GameWindowCenter.X, this.GameWindowCenter.Y, 0f), Color.FromArgb(MapTransparency, 0xff, 0xff, 0xff)); } DXSprite.End(); float direction = Main.player_D * -1f; float fromX = (float)((this.GameWindowCenter.X + map_pos_z) + (20.0 * Math.Cos(direction))); float fromY = (float)((this.GameWindowCenter.Y + map_pos_x) + (20.0 * Math.Sin(direction))); DrawFilledBox((this.GameWindowCenter.X + map_pos_z) - 2f, (this.GameWindowCenter.Y + map_pos_x) - 2f, 6f, 6f, Color.Magenta); DrawLine(fromX, fromY, (this.GameWindowCenter.X + map_pos_z) + 1f, (this.GameWindowCenter.Y + map_pos_x) + 1f, 1f, Color.PaleVioletRed); } DXDevice.EndScene(); DXDevice.Present(); Thread.Sleep(1); } DXDevice.Dispose(); Application.Exit(); }
public bool shouldSplit(ref Matrix wvp, ref TgcFrustum bf) { //[!]Cambiar para que los cambios no sean tan bruscos /* * Determina si un triángulo debe dividirse o no, midiendo la distancia *(screen distance) entre su left point y su center point. Cerca del frustum, esta *distancia es más grande. Si supera un threshold se considera suficiente para dividirlo. */ bool shouldSplit = false; if (TgcCollisionUtils.testPointFrustum(bf, centerPos) //si colisiona con center, left, o right... || TgcCollisionUtils.testPointFrustum(bf, lPos) || TgcCollisionUtils.testPointFrustum(bf, rPos)) { Vector4 lScreenPos = Vector4.Transform(new Vector4(lPos.X, lPos.Y, lPos.Z, 1), wvp); Vector4 aScreenPos = Vector4.Transform(new Vector4(centerPos.X, centerPos.Y, centerPos.Z, 1), wvp); lScreenPos = lScreenPos * (1 / lScreenPos.W); aScreenPos = aScreenPos * (1 / aScreenPos.W); Vector4 difference = lScreenPos - aScreenPos; Vector2 screenDifference = new Vector2(difference.X, difference.Y); //(menos tolerancia => más calidad) if (screenDifference.Length() > map.Threshold) shouldSplit = true; } return shouldSplit; }
public void TestStaticFn_Length_i () { Vector2 a = new Vector2(3, -4); Double expected = 5; Double result = a.Length(); Assert.That(result, Is.EqualTo(expected)); }
public float GetPlayerKMH() { Player currentPlayer = GetCurrentPlayer(); if (currentPlayer == null) return 0f; Vector2 velXY = new Vector2(currentPlayer.Velocity.X, currentPlayer.Velocity.Y); float length = velXY.Length(); float speedPercent = 100f / 320f * (length % 320f); float speedMeters = length * 0.01905f; float speedKiloMetersPerHour = speedMeters * 60f * 60f / 1000f; return speedKiloMetersPerHour; }
private bool XYMovement() { bool res = false; myPos = GetSimPosition(); myPos0.X = myPos.X; myPos0.Y = myPos.Y; diff = Vector2.Distance(target0, myPos0); Vector2 vvel = new Vector2(Client.Self.Velocity.X, Client.Self.Velocity.Y); float vel = vvel.Length(); if (diff >= 10.0) { Client.Self.Movement.AtPos = true; // Client.Self.Movement.AtNeg = false; //if (Math.Abs(diff - olddiff) > 1.5) { // Client.Self.Movement.AtPos = diff < olddiff; // Client.Self.Movement.AtNeg = diff > olddiff; //} else if (!Client.Self.Movement.AtPos && !Client.Self.Movement.AtNeg) { // Client.Self.Movement.AtPos = true; // Client.Self.Movement.AtNeg = false; //} res = true; } else if (diff >= 2 && vel < 5) { Client.Self.Movement.AtPos = true; } else { Client.Self.Movement.AtPos = false; Client.Self.Movement.AtNeg = false; } saveolddiff = olddiff; olddiff = diff; return res; }
protected override void TickCore(Entity host, RealmTime time, ref object state) { FollowState s; if (state == null) s = new FollowState(); else s = (FollowState)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return; var player = (Player)host.GetNearestEntity(acquireRange, null); Vector2 vect; switch (s.State) { case F.DontKnowWhere: if (player != null && s.RemainingTime <= 0) { s.State = F.Acquired; if (duration > 0) s.RemainingTime = duration; goto case F.Acquired; } else if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; break; case F.Acquired: if (player == null) { s.State = F.DontKnowWhere; s.RemainingTime = 0; break; } else if (s.RemainingTime <= 0 && duration > 0) { s.State = F.DontKnowWhere; s.RemainingTime = coolDown.Next(Random); Status = CycleStatus.Completed; break; } if (s.RemainingTime > 0) s.RemainingTime -= time.thisTickTimes; vect = new Vector2(player.X - host.X, player.Y - host.Y); if (vect.Length() > range) { Status = CycleStatus.InProgress; vect.X -= Random.Next(-2, 2) / 2f; vect.Y -= Random.Next(-2, 2) / 2f; vect.Normalize(); float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist); host.UpdateCount++; } else { Status = CycleStatus.Completed; s.State = F.Resting; s.RemainingTime = 0; } break; case F.Resting: if (player == null) { s.State = F.DontKnowWhere; if (duration > 0) s.RemainingTime = duration; break; } Status = CycleStatus.Completed; vect = new Vector2(player.X - host.X, player.Y - host.Y); if (vect.Length() > range + 1) { s.State = F.Acquired; s.RemainingTime = duration; goto case F.Acquired; } break; } state = s; }
/// <summary> /// Frame update method. /// </summary> /// <param name="gameTime">Time since last update.</param> public override void Update(GameTime gameTime) { // Check if still alive if(hitpoints <= 0) { game.score += 1; game.Add(new TransientLight(this.game, this.pos)); game.Remove(this); } int time = gameTime.ElapsedGameTime.Milliseconds; fireTimer -= time; Vector3 playerpos = game.getPlayerPos(); Vector3 playervel = game.getPlayerVel(); Vector2 toPlayer = new Vector2(playerpos.X-this.pos.X, playerpos.Y-this.pos.Y); //Determines if the enemy can see the player ship or not if (!this.detected && toPlayer.Length() <= detectrange) { this.detected = true; this.maxspeed = 0.5f; } //Determines if the player has escaped or not if (this.detected && toPlayer.Length() > escaperange) { this.detected = false; this.maxspeed = 0.2f; searchloc = controller.newSearch(this, pos); } //Behaviour if player is detected if (this.detected) { if (this.etype == EnemyType.galleon) { // Move away from the player if too close if (toPlayer.Length() <= range / 2f) { this.acceleration.X = -toPlayer.X; this.acceleration.Y = -toPlayer.Y; acceleration.Normalize(); acceleration /= 1.5f; } //Move towards the player if too far if (toPlayer.Length() > range / 2f) { this.acceleration.X = toPlayer.X; this.acceleration.Y = toPlayer.Y; } // Check if the enemy can engage the player and do so if(toPlayer.Length() <= fireDistance && fireTimer <= 0) { fire(toPlayer); fireTimer = 3000; } } //I'm a demoship and I hate life, CHARGE FORWARD if(this.etype == EnemyType.demoship) { this.acceleration.X = toPlayer.X; this.acceleration.Y = toPlayer.Y; this.acceleration.Normalize(); } } //Behaviour if player is not detected else { if (Vector3.Distance(searchloc, this.pos) < detectrange) { searchloc = controller.newSearch(this, pos); } this.acceleration.X = searchloc.X - this.pos.X; this.acceleration.Y = searchloc.Y - this.pos.Y; acceleration.Normalize(); } //Handle the in-game physics physicsUpdate(gameTime); //Handle the following light updateLight(); //Handle the graphics transforms for this update transform(); }
/// <summary> /// Handling scrollbar's input /// </summary> /// <param name="input"></param> /// <param name="hasKeyboardActiveControl"></param> /// <param name="hasKeyboardActiveControlPrevious"></param> /// <param name="receivedFocusInThisUpdate"></param> /// <returns></returns> public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate) { bool captureInput = false; // still scrolling if (IsScrolling() && input.IsLeftMousePressed()) { if (m_mouseLastPosition != null) { Vector2 distance = new Vector2(0.0f, 0.0f); Vector2 sliderDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value; switch (m_scrollDirection) { case MyScrollDirection.Horizontal: distance.X = sliderDistanceFromLastUpdate.X; break; case MyScrollDirection.Vertical: distance.Y = sliderDistanceFromLastUpdate.Y; break; } if (distance.Length() > 0.00001f) { Vector2 newScrollSliderPosition = m_scrollSliderPosition + distance; FixScrollSliderPosition(ref newScrollSliderPosition); if (newScrollSliderPosition != m_scrollSliderPosition) { SetScrollSliderPosition(newScrollSliderPosition); m_mouseLastPosition = MyGuiManager.MouseCursorPosition; } } captureInput = true; } } // start scrolling else if (!IsScrolling() && input.IsNewLeftMousePressed() && IsMouseOverScrollSlider()) { m_isScrollSliderDragging = true; m_mouseLastPosition = MyGuiManager.MouseCursorPosition; captureInput = true; } // no scrolling else { m_mouseLastPosition = null; m_isScrollSliderDragging = false; } return captureInput; }
/// <summary> /// Draws a trail consisting of provided texture in given line /// </summary> /// <param id="tex">Texture used for the trail</param> /// <param id="c">Color tint of the texture</param> /// <param id="start">Start position of the trail</param> /// <param id="vector">End position of the trail</param> private void DrawTrail(Texture2D tex, Color c, Vector2 start, Vector2 vector) { vector += tex.Size() / 2; int length = (int)vector.Length(); int step = 10; int parts = length / step; Vector2 vectorStep = vector / parts; for (int i = 0; i < parts; i++) { UI.Instance.Draw(start + i * vectorStep, tex, c, 1f); } }
private bool XYMovement() { bool res = false; myPos = Client.Self.SimPosition; myPos0.X = myPos.X; myPos0.Y = myPos.Y; diff = Vector2.Distance(target0, myPos0); Vector2 vvel = new Vector2(Client.Self.Velocity.X, Client.Self.Velocity.Y); float vel = vvel.Length(); if (diff >= 10.0) { Client.Self.Movement.AtPos = true; res = true; } else if (diff >= 2 && vel < 5) { Client.Self.Movement.AtPos = true; } else { Client.Self.Movement.AtPos = false; Client.Self.Movement.AtNeg = false; } saveolddiff = olddiff; olddiff = diff; return res; }
/// <summary> /// Handles the input and movement of the character. /// </summary> /// <param name="dt">Time since last frame in simulation seconds.</param> /// <param name="previousKeyboardInput">The last frame's keyboard state.</param> /// <param name="keyboardInput">The current frame's keyboard state.</param> /// <param name="previousGamePadInput">The last frame's gamepad state.</param> /// <param name="gamePadInput">The current frame's keyboard state.</param> public void Update(float dt, KeyboardState previousKeyboardInput, KeyboardState keyboardInput, GamePadState previousGamePadInput, GamePadState gamePadInput) { if (IsActive) { //Note that the character controller's update method is not called here; this is because it is handled within its owning space. //This method's job is simply to tell the character to move around. CameraControlScheme.Update(dt); Vector2 totalMovement = Vector2.Zero; #if XBOX360 totalMovement += new Vector2(gamePadInput.ThumbSticks.Left.X, gamePadInput.ThumbSticks.Left.Y); CharacterController.HorizontalMotionConstraint.SpeedScale = Math.Min(totalMovement.Length(), 1); //Don't trust the game pad to output perfectly normalized values. CharacterController.HorizontalMotionConstraint.MovementDirection = totalMovement; CharacterController.StanceManager.DesiredStance = gamePadInput.IsButtonDown(Buttons.RightStick) ? Stance.Crouching : Stance.Standing; //Jumping if (previousGamePadInput.IsButtonUp(Buttons.LeftStick) && gamePadInput.IsButtonDown(Buttons.LeftStick)) { CharacterController.Jump(); } #else //Collect the movement impulses. if (keyboardInput.IsKeyDown(Keys.E)) { totalMovement += new Vector2(0, 1); } if (keyboardInput.IsKeyDown(Keys.D)) { totalMovement += new Vector2(0, -1); } if (keyboardInput.IsKeyDown(Keys.S)) { totalMovement += new Vector2(-1, 0); } if (keyboardInput.IsKeyDown(Keys.F)) { totalMovement += new Vector2(1, 0); } if (totalMovement == Vector2.Zero) CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero; else CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(totalMovement); CharacterController.StanceManager.DesiredStance = keyboardInput.IsKeyDown(Keys.Z) ? Stance.Crouching : Stance.Standing; //Jumping if (previousKeyboardInput.IsKeyUp(Keys.A) && keyboardInput.IsKeyDown(Keys.A)) { CharacterController.Jump(); } #endif CharacterController.ViewDirection = Camera.WorldMatrix.Forward; } }
public static PointF Normalized(this PointF c) { var l = c.Length(); return(new PointF(c.X / l, c.Y / l)); }