public static bool[] GenerateRoomCut(VMArchitecture target, sbyte floor, WorldRotation dir, HashSet <uint> cutRooms) { var result = new bool[target.Width * target.Height]; var offset = 0; var roommap = target.Rooms[floor - 1].Map; var cutDir = CutCheckDir[(int)dir]; var walls = target.Walls[floor - 1]; var width = target.Width; for (int y1 = 0; y1 < target.Height; y1++) { for (int x1 = 0; x1 < target.Width; x1++) { if (walls[offset].Segments == 0 && (offset + width < walls.Length && walls[offset + width].Segments == 0) && (offset + 1 < walls.Length && walls[offset + 1].Segments == 0) && (offset - width > 0 && walls[offset - width].Segments == 0) && (offset - 1 > 0 && walls[offset - 1].Segments == 0) ) { offset++; continue; //ignore empty tiles as an optimisation } bool cut = false; for (int i = 0; i < 3; i++) { var x = x1 + ((i == 1) ? cutDir[0] : 0); var y = y1 + ((i == 2) ? cutDir[1] : 0); for (int j = 0; j < ((i > 0)?4:5); j++) { if (x < 0 || x >= target.Width || y < 0 || y >= target.Height) { break; } if (cutRooms.Contains(roommap[y * target.Width + x] & 65535)) { cut = true; break; } x += cutDir[0]; y += cutDir[1]; } if (cut) { break; } } result[offset++] = cut; } } return(result); }
/// <summary> /// Creates another track section after this one (as 'next') and adds it to the TrackCollection /// </summary> /// <param name="length"></param> /// <param name="curved"></param> /// <param name="angle"></param> /// <returns></returns> public TrackSection CreateNext(float length, bool curved, float angle) { if (NextSectionIndex == 0) { WorldPosition nextPos = GetPositionOnTrack(this.length); WorldRotation nextRot = GetRotationOnTrack(this.length); TrackSection nextTrackSection = new TrackSection(nextPos, nextRot, length, curved, angle); this.NextSectionIndex = TrackCollection.instance.Add(nextTrackSection); nextTrackSection.PreviousSectionIndex = this.index; return(nextTrackSection); } return(null); }
protected void SetPhysicsFromLoadedMesh() { if (m_physicsMesh != null) { m_physicsMesh.Shape = m_meshAssetReference.GetAsset().GetPhysicsInstancedMesh(); m_physicsMesh.Sidedness = TriangleSidedness.Clockwise; } else { m_physicsMesh = new InstancedMesh(m_meshAssetReference.GetAsset().GetPhysicsInstancedMesh()); } m_physicsMesh.WorldTransform = new AffineTransform(WorldScale.ToBepu(), WorldRotation.ToBepu(), WorldPosition.ToBepu()); }
/// <summary> /// Sets the parent (particle system's) translation, rotation and scale (uniform) /// The module can choose to inherit, use or ignore any of the elements /// </summary> /// <param name="translation">Particle System's translation (from the Transform component)</param> /// <param name="rotation">Particle System's quaternion rotation (from the Transform component)</param> /// <param name="scale">Particle System's uniform scale (from the Transform component)</param> public virtual void SetParentTrs(ref Vector3 translation, ref Quaternion rotation, float scale) { var hasPos = InheritLocation.HasFlag(InheritLocation.Position); var hasRot = InheritLocation.HasFlag(InheritLocation.Rotation); var hasScl = InheritLocation.HasFlag(InheritLocation.Scale); WorldScale = (hasScl) ? ParticleLocator.Scale * scale : ParticleLocator.Scale; WorldRotation = (hasRot) ? ParticleLocator.Rotation * rotation : ParticleLocator.Rotation; var offsetTranslation = ParticleLocator.Translation * WorldScale; WorldRotation.Rotate(ref offsetTranslation); WorldPosition = (hasPos) ? translation + offsetTranslation : offsetTranslation; }
private Vector4 BackOffForRot(WorldRotation rot) { switch (rot) { case WorldRotation.TopLeft: return(new Vector4(0, 0, 0, 0)); case WorldRotation.TopRight: return(new Vector4(0, 0, 3, 0)); case WorldRotation.BottomRight: return(new Vector4(3, 0, 3, 0)); case WorldRotation.BottomLeft: return(new Vector4(3, 0, 0, 0)); } return(new Vector4(0, 0, 0, 0)); }
private Vector3 FrontDirForRot(WorldRotation rot) { switch (rot) { case WorldRotation.TopLeft: return(new Vector3(3, 0, 3)); case WorldRotation.TopRight: return(new Vector3(3, 0, -3)); case WorldRotation.BottomRight: return(new Vector3(-3, 0, -3)); case WorldRotation.BottomLeft: return(new Vector3(-3, 0, 3)); } return(new Vector3(3, 0, 3)); }
public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Position) || !pool.FieldExists(ParticleFields.Velocity) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } var posField = pool.GetField(ParticleFields.Position); var velField = pool.GetField(ParticleFields.Velocity); var rndField = pool.GetField(ParticleFields.RandomSeed); var range = (float)(Angle * Math.PI / 180f); var magnitude = WorldScale.X; var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var x = (randSeed.GetFloat(RandomOffset.Offset2A + SeedOffset) - 0.5f) * range; var z = (randSeed.GetFloat(RandomOffset.Offset2B + SeedOffset) - 0.5f) * range; var u = (randSeed.GetFloat(RandomOffset.Offset2A + SeedOffset) - 0.5f) * range; var v = (randSeed.GetFloat(RandomOffset.Offset2B + SeedOffset) - 0.5f) * Math.PI; // var particleRandPos = new Vector3(x, 1, z); var xz = (float)Math.Sin(u); var particleRandPos = new Vector3((float)Math.Cos(v) * xz, (float)Math.Sqrt(1 - u * u), (float)Math.Sin(v) * xz); particleRandPos.Normalize(); particleRandPos *= magnitude; WorldRotation.Rotate(ref particleRandPos); (*((Vector3 *)particle[posField])) = particleRandPos + WorldPosition; (*((Vector3 *)particle[velField])) = particleRandPos * Strength; i = (i + 1) % maxCapacity; } }
public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Position) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } var posField = pool.GetField(ParticleFields.Position); var rndField = pool.GetField(ParticleFields.RandomSeed); var leftCorner = PositionMin * WorldScale; var xAxis = new Vector3(PositionMax.X * WorldScale.X - leftCorner.X, 0, 0); var yAxis = new Vector3(0, PositionMax.Y * WorldScale.Y - leftCorner.Y, 0); var zAxis = new Vector3(0, 0, PositionMax.Z * WorldScale.Z - leftCorner.Z); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref leftCorner); WorldRotation.Rotate(ref xAxis); WorldRotation.Rotate(ref yAxis); WorldRotation.Rotate(ref zAxis); } leftCorner += WorldPosition; var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var particleRandPos = leftCorner; particleRandPos += xAxis * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandPos += yAxis * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandPos += zAxis * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); (*((Vector3 *)particle[posField])) = particleRandPos; i = (i + 1) % maxCapacity; } }
public List <BlueprintOccupiedTile> GetOccupiedTiles(WorldRotation order) { if (OccupiedTilesDirty) { OccupiedTiles.Clear(); foreach (var tile in IsometricTileIterator.Tiles(order, 0, 0, (short)Width, (short)Height)) { var offset = GetOffset(tile.TileX, tile.TileY); var hasFloor = Floor[offset] != null; var hasObject = Objects[offset] != null && Objects[offset].Objects.Count > 0; if (hasFloor || hasObject) { var inst = new BlueprintOccupiedTile(); inst.TileX = tile.TileX; inst.TileY = tile.TileY; if (hasFloor) { inst.Type |= BlueprintOccupiedTileType.FLOOR; } if (hasObject) { inst.Type |= BlueprintOccupiedTileType.OBJECT; } OccupiedTiles.Add(inst); } } OccupiedTilesOrder = order; OccupiedTilesDirty = false; } /** Has rotation changed? **/ if (order != OccupiedTilesOrder) { /** Re-sort **/ OccupiedTiles.Sort(new IsometricTileSorter <BlueprintOccupiedTile>(order)); OccupiedTilesOrder = order; } return(OccupiedTiles); }
private Vector4 BackOffForRot(WorldRotation rot) { const float bias = 0.15f; //all 2d graphics are slightly offset forwards switch (rot) { case WorldRotation.TopLeft: return(new Vector4(bias, 0, bias, 0)); case WorldRotation.TopRight: return(new Vector4(bias, 0, 3 - bias, 0)); case WorldRotation.BottomRight: return(new Vector4(3 - bias, 0, 3 - bias, 0)); case WorldRotation.BottomLeft: return(new Vector4(3 - bias, 0, bias, 0)); } return(new Vector4(0, 0, 0, 0)); }
public void OnspeedChange(bool isUp) { world = GetComponent <MainButtons>().rotateWorld; speed = GetComponent <ResourcesInner>().gameData.speed; if (isUp) { speed = speed * 15; } else { speed = speed / 15; } if (speed < 1) { speed = 1250; } if (speed > 1250) { speed = 5; } GetComponent <ResourcesInner>().gameData.speed = speed; world.worldturnforce = speed; }
//code to run on start of state private static void OnStart() { //looks for the proper prep code for the current state switch (currentState) { case GameState.MainMenu: WorldRotation.SetRotation(0.0f); break; case GameState.GameStart: ObstacleManager.Create(); WorldRotation.SetRotation(20.0f); break; case GameState.GameOver: break; default: break; } }
private TestModel ProcessModel(JObject obj) { var id = obj["Id"].ToObject <string>(); var token = obj["Token"].ToObject <string>(); var lo = obj["Location"].ToObject <WorldLocation>(); var commandType = obj["CommandType"].ToObject <int>(); var isShooting = obj["IsShooting"].ToObject <bool>(); var isDead = obj["IsDead"].ToObject <bool>(); var rr = new WorldRotation(); rr.Rotation = obj["Rotation"].ToObject <WorldPoint>(); TestModel newModel = InitPlayerModel(); newModel.CommandType = commandType; newModel.Id = id; newModel.RoomId = obj["RoomId"].ToObject <int>(); newModel.Rotation = rr; newModel.Location = lo; newModel.IsShooting = isShooting; newModel.IsDead = isDead; return(newModel); }
private WallTile RotateWall(WorldRotation rot, WallTile input, short x, short y, sbyte level) { int rotN = (int)rot; var output = new WallTile(); if (rot != 0) { if (input.Segments == WallSegments.HorizontalDiag) { output.Segments = ((rotN % 2) == 0) ? WallSegments.HorizontalDiag : WallSegments.VerticalDiag; output.TopRightStyle = input.TopRightStyle; switch (rotN) { case 1: output.BottomRightPattern = input.BottomLeftPattern; output.BottomLeftPattern = input.BottomRightPattern; output.TopLeftStyle = input.TopLeftPattern; output.TopLeftPattern = input.TopLeftStyle; break; case 2: output.BottomRightPattern = input.BottomLeftPattern; //flip sides output.BottomLeftPattern = input.BottomRightPattern; output.TopLeftStyle = input.TopLeftPattern; output.TopLeftPattern = input.TopLeftStyle; break; case 3: output.BottomRightPattern = input.BottomRightPattern; output.BottomLeftPattern = input.BottomLeftPattern; output.TopLeftStyle = input.TopLeftStyle; output.TopLeftPattern = input.TopLeftPattern; break; } } else if (input.Segments == WallSegments.VerticalDiag) { output.Segments = ((rotN % 2) == 0) ? WallSegments.VerticalDiag : WallSegments.HorizontalDiag; output.TopRightStyle = input.TopRightStyle; switch (rotN) { case 1: output.BottomRightPattern = input.BottomRightPattern; output.BottomLeftPattern = input.BottomLeftPattern; output.TopLeftStyle = input.TopLeftStyle; output.TopLeftPattern = input.TopLeftPattern; break; case 2: output.BottomRightPattern = input.BottomLeftPattern; //flip sides output.BottomLeftPattern = input.BottomRightPattern; output.TopLeftStyle = input.TopLeftPattern; output.TopLeftPattern = input.TopLeftStyle; break; case 3: output.BottomRightPattern = input.BottomLeftPattern; output.BottomLeftPattern = input.BottomRightPattern; output.TopLeftStyle = input.TopLeftPattern; output.TopLeftPattern = input.TopLeftStyle; break; } } else { switch (rotN) { case 1: if ((input.Segments & WallSegments.TopLeft) > 0) output.Segments |= WallSegments.TopRight; if ((input.Segments & WallSegments.TopRight) > 0) output.Segments |= WallSegments.BottomRight; if ((input.Segments & WallSegments.BottomRight) > 0) output.Segments |= WallSegments.BottomLeft; if ((input.Segments & WallSegments.BottomLeft) > 0) output.Segments |= WallSegments.TopLeft; output.TopLeftPattern = input.BottomLeftPattern; output.TopRightPattern = input.TopLeftPattern; output.BottomRightPattern = input.TopRightPattern; output.BottomLeftPattern = input.BottomRightPattern; if (y + 1 < blueprint.Height) { var newLeft = blueprint.GetWall(x, (short)(y + 1), level); output.TopLeftStyle = newLeft.TopRightStyle; output.ObjSetTLStyle = newLeft.ObjSetTRStyle; output.TopLeftDoor = newLeft.TopRightDoor; } output.TopRightStyle = input.TopLeftStyle; output.ObjSetTRStyle = input.ObjSetTLStyle; output.TopRightDoor = input.TopLeftDoor; break; case 2: if ((input.Segments & WallSegments.TopLeft) > 0) output.Segments |= WallSegments.BottomRight; if ((input.Segments & WallSegments.TopRight) > 0) output.Segments |= WallSegments.BottomLeft; if ((input.Segments & WallSegments.BottomRight) > 0) output.Segments |= WallSegments.TopLeft; if ((input.Segments & WallSegments.BottomLeft) > 0) output.Segments |= WallSegments.TopRight; output.TopLeftPattern = input.BottomRightPattern; output.TopRightPattern = input.BottomLeftPattern; output.BottomRightPattern = input.TopLeftPattern; output.BottomLeftPattern = input.TopRightPattern; if (y + 1 < blueprint.Height) { var newRight = blueprint.GetWall(x, (short)(y + 1), level); output.TopRightStyle = newRight.TopRightStyle; output.ObjSetTRStyle = newRight.ObjSetTRStyle; output.TopRightDoor = newRight.TopRightDoor; } if (x + 1 < blueprint.Width) { var newLeft = blueprint.GetWall((short)(x + 1), y, level); output.TopLeftStyle = newLeft.TopLeftStyle; output.ObjSetTLStyle = newLeft.ObjSetTLStyle; output.TopLeftDoor = newLeft.TopLeftDoor; } break; case 3: if ((input.Segments & WallSegments.TopLeft) > 0) output.Segments |= WallSegments.BottomLeft; if ((input.Segments & WallSegments.TopRight) > 0) output.Segments |= WallSegments.TopLeft; if ((input.Segments & WallSegments.BottomRight) > 0) output.Segments |= WallSegments.TopRight; if ((input.Segments & WallSegments.BottomLeft) > 0) output.Segments |= WallSegments.BottomRight; output.TopLeftPattern = input.TopRightPattern; output.TopRightPattern = input.BottomRightPattern; output.BottomRightPattern = input.BottomLeftPattern; output.BottomLeftPattern = input.TopLeftPattern; output.TopLeftStyle = input.TopRightStyle; output.TopLeftDoor = input.TopRightDoor; output.ObjSetTLStyle = input.ObjSetTRStyle; if (x + 1 < blueprint.Width) { var newRight = blueprint.GetWall((short)(x + 1), y, level); output.TopRightStyle = newRight.TopLeftStyle; output.ObjSetTRStyle = newRight.ObjSetTLStyle; output.TopRightDoor = newRight.TopLeftDoor; } break; } } } else { output = input; } return output; }
private Vector3 RotateOffset(WorldRotation rot, Vector3 off) { switch (rot) { case WorldRotation.TopLeft: return off; case WorldRotation.TopRight: return new Vector3(off.Y, -off.X, off.Z); case WorldRotation.BottomRight: return new Vector3(-off.X, -off.Y, off.Z); case WorldRotation.BottomLeft: return new Vector3(-off.Y, off.X, off.Z); } return off; }
/// <summary> /// Gets rotated junctions and segements /// </summary> private JunctionFlags RotateJunction(WorldRotation rot, JunctionFlags input) { var rotN = (int)rot; int rotLower = (((int)input & 15) << rotN); int rotHigher = (((int)input & 240) << rotN); return (JunctionFlags)((rotLower & 15) | (rotLower >> 4) | ((rotHigher | rotHigher>>4) & 240)); }
public override void Update(UpdateState state) { base.Update(state); Cheats.Update(state); if (!vm.Ready) return; if (ActiveEntity == null || ActiveEntity.Dead || ActiveEntity.PersistID != SelectedSimID) { ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar && x.PersistID == SelectedSimID); //try and hook onto a sim if we have none selected. if (ActiveEntity == null) ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar); if (!FoundMe && ActiveEntity != null) { vm.Context.World.State.CenterTile = new Vector2(ActiveEntity.VisualPosition.X, ActiveEntity.VisualPosition.Y); vm.Context.World.State.ScrollAnchor = null; FoundMe = true; } Queue.QueueOwner = ActiveEntity; } if (GotoObject == null) GotoObject = vm.Context.CreateObjectInstance(GOTO_GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true).Objects[0]; if (ActiveEntity != null && BlockingDialog != null) { //are we still waiting on a blocking dialog? if not, cancel. if (ActiveEntity.Thread != null && (ActiveEntity.Thread.BlockingState == null || !(ActiveEntity.Thread.BlockingState is VMDialogResult))) { UIScreen.RemoveDialog(BlockingDialog); LastDialogID = 0; BlockingDialog = null; } } if (Visible) { if (ShowTooltip) state.UIState.TooltipProperties.UpdateDead = false; bool scrolled = false; if (RMBScroll) { World.State.ScrollAnchor = null; Vector2 scrollBy = new Vector2(); if (state.TouchMode) { scrollBy = new Vector2(RMBScrollX - state.MouseState.X, RMBScrollY - state.MouseState.Y); RMBScrollX = state.MouseState.X; RMBScrollY = state.MouseState.Y; scrollBy /= 128f; scrollBy /= FSOEnvironment.DPIScaleFactor; } else { scrollBy = new Vector2(state.MouseState.X - RMBScrollX, state.MouseState.Y - RMBScrollY); scrollBy *= 0.0005f; } World.Scroll(scrollBy); scrolled = true; } if (MouseIsOn) { if (state.MouseState.RightButton == ButtonState.Pressed) { if (RMBScroll == false) { RMBScroll = true; RMBScrollX = state.MouseState.X; RMBScrollY = state.MouseState.Y; } } else { RMBScroll = false; if (!scrolled && GlobalSettings.Default.EdgeScroll && !state.TouchMode) scrolled = World.TestScroll(state); } } if (LiveMode) LiveModeUpdate(state, scrolled); else if (CustomControl != null) CustomControl.Update(state, scrolled); else ObjectHolder.Update(state, scrolled); //set cutaway around mouse if (vm.Context.Blueprint != null) { World.State.DynamicCutaway = (WallsMode == 1); //first we need to cycle the rooms that are being cutaway. Keep this up even if we're in all-cut mode. var mouseTilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor); var roomHover = vm.Context.GetRoomAt(LotTilePos.FromBigTile((short)(mouseTilePos.X), (short)(mouseTilePos.Y), World.State.Level)); var outside = (vm.Context.RoomInfo[roomHover].Room.IsOutside); if (!outside && !CutRooms.Contains(roomHover)) CutRooms.Add(roomHover); //outside hover should not persist like with other rooms. while (CutRooms.Count > 3) CutRooms.Remove(CutRooms.ElementAt(0)); if (LastWallMode != WallsMode) { if (WallsMode == 0) //walls down { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); for (int i = 0; i < LastCuts.Length; i++) LastCuts[i] = true; } else if (WallsMode == 1) { MouseCutRect = new Rectangle(); LastCutRooms = new HashSet<uint>() { uint.MaxValue }; //must regenerate cuts } else //walls up or roof { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastWallMode = WallsMode; } if (WallsMode == 1) { int recut = 0; var finalRooms = new HashSet<uint>(CutRooms); var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5); newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][0]*2; newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][1]*2; if (newCut != MouseCutRect) { MouseCutRect = newCut; recut = 1; } if (LastFloor != World.State.Level || LastRotation != World.State.Rotation || !finalRooms.SetEquals(LastCutRooms)) { LastCuts = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.Rotation, finalRooms); recut = 2; LastFloor = World.State.Level; LastRotation = World.State.Rotation; } LastCutRooms = finalRooms; if (recut > 0) { var finalCut = new bool[LastCuts.Length]; Array.Copy(LastCuts, finalCut, LastCuts.Length); var notableChange = VMArchitectureTools.ApplyCutRectangle(vm.Context.Architecture, World.State.Level, finalCut, MouseCutRect); if (recut > 1 || notableChange || LastRectCutNotable) { vm.Context.Blueprint.Cutaway = finalCut; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastRectCutNotable = notableChange; } } } } }
public IsometricTileSorter(WorldRotation rotation) { this.Rotation = rotation; }
public TrackSection(WorldPosition position, WorldRotation rotation) : this(position, rotation, 0, false, 0) { }
/// <inheritdoc /> public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Velocity) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } // Collect the total number of living particles in the parent pool which have a Velocity field var parentPool = Parent?.Pool; var parentParticlesCount = parentPool?.LivingParticles ?? 0; var velFieldParent = parentPool?.GetField(ParticleFields.Velocity) ?? ParticleFieldAccessor <Vector3> .Invalid(); if (!velFieldParent.IsValid()) { parentParticlesCount = 0; } var spawnControlField = GetSpawnControlField(); var velField = pool.GetField(ParticleFields.Velocity); var rndField = pool.GetField(ParticleFields.RandomSeed); var leftCorner = VelocityMin * WorldScale; var xAxis = new Vector3(VelocityMax.X * WorldScale.X - leftCorner.X, 0, 0); var yAxis = new Vector3(0, VelocityMax.Y * WorldScale.Y - leftCorner.Y, 0); var zAxis = new Vector3(0, 0, VelocityMax.Z * WorldScale.Z - leftCorner.Z); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref leftCorner); WorldRotation.Rotate(ref xAxis); WorldRotation.Rotate(ref yAxis); WorldRotation.Rotate(ref zAxis); } var sequentialParentIndex = 0; var sequentialParentParticles = 0; var parentIndex = 0; var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var particleRandVel = leftCorner; particleRandVel += xAxis * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandVel += yAxis * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandVel += zAxis * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); if (parentParticlesCount > 0) { var parentParticleVelocity = new Vector3(0, 0, 0); // Spawn is fixed - parent particles have spawned a very specific number of children each if (spawnControlField.IsValid()) { while (sequentialParentParticles == 0) { // Early out - no more fixed number children. Rest of the particles (if any) are skipped intentionally if (sequentialParentIndex >= parentParticlesCount) { return; } parentIndex = sequentialParentIndex; var tempParentParticle = parentPool.FromIndex(parentIndex); sequentialParentIndex++; var childrenAttribute = (*((ParticleChildrenAttribute *)tempParentParticle[spawnControlField])); sequentialParentParticles = (int)childrenAttribute.ParticlesToEmit; } sequentialParentParticles--; var parentParticle = parentPool.FromIndex(parentIndex); parentParticleVelocity = (*((Vector3 *)parentParticle[velFieldParent])); } // Spawn is not fixed - pick a parent at random else { parentIndex = (int)(parentParticlesCount * randSeed.GetFloat(RandomOffset.Offset1A + ParentSeedOffset)); var parentParticle = parentPool.FromIndex(parentIndex); parentParticleVelocity = (*((Vector3 *)parentParticle[velFieldParent])); } // Convert from Local -> World space if needed if (Parent.SimulationSpace == EmitterSimulationSpace.Local) { WorldRotation.Rotate(ref parentParticleVelocity); parentParticleVelocity *= WorldScale.X; } particleRandVel += parentParticleVelocity * ParentVelocityFactor; } (*((Vector3 *)particle[velField])) = particleRandVel; i = (i + 1) % maxCapacity; } }
/// <inheritdoc /> public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Position) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } var posField = pool.GetField(ParticleFields.Position); var oldField = pool.GetField(ParticleFields.OldPosition); var rndField = pool.GetField(ParticleFields.RandomSeed); var leftCorner = PositionMin * WorldScale; var xAxis = new Vector3(PositionMax.X * WorldScale.X - leftCorner.X, 0, 0); var yAxis = new Vector3(0, PositionMax.Y * WorldScale.Y - leftCorner.Y, 0); var zAxis = new Vector3(0, 0, PositionMax.Z * WorldScale.Z - leftCorner.Z); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref leftCorner); WorldRotation.Rotate(ref xAxis); WorldRotation.Rotate(ref yAxis); WorldRotation.Rotate(ref zAxis); } leftCorner += WorldPosition; var i = startIdx; if (Interpolate) { // Interpolate positions between the old and the new one var positionDistance = (hasBegun) ? oldPosition - WorldPosition : Vector3.Zero; oldPosition = WorldPosition; hasBegun = true; var totalCountLessOne = (startIdx < endIdx) ? (endIdx - startIdx - 1) : (endIdx - startIdx + maxCapacity - 1); var stepF = (totalCountLessOne > 1) ? (1f / totalCountLessOne) : 1f; var step = 0f; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var particleRandPos = leftCorner; particleRandPos += xAxis * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandPos += yAxis * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandPos += zAxis * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); particleRandPos += positionDistance * step; step += stepF; (*((Vector3 *)particle[posField])) = particleRandPos; if (oldField.IsValid()) { (*((Vector3 *)particle[oldField])) = particleRandPos; } i = (i + 1) % maxCapacity; } } else { // Do not interpolate position while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var particleRandPos = leftCorner; particleRandPos += xAxis * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandPos += yAxis * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandPos += zAxis * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); (*((Vector3 *)particle[posField])) = particleRandPos; if (oldField.IsValid()) { (*((Vector3 *)particle[oldField])) = particleRandPos; } i = (i + 1) % maxCapacity; } } }
private WallCuts RotateCuts(WorldRotation rot, WallCuts input, short x, short y) { int rotN = (int)rot; var output = new WallCuts(); switch (rotN) { case 0: return input; case 1: output.TRCut = input.TLCut; if (y + 1 < blueprint.Height) output.TLCut = Cuts[(y + 1) * blueprint.Width + x].TRCut; if (output.TLCut == WallCut.DownLeftUpRight) output.TLCut = WallCut.DownRightUpLeft; //flip cut else if (output.TLCut == WallCut.DownRightUpLeft) output.TLCut = WallCut.DownLeftUpRight; return output; case 2: output.TRCut = input.TLCut; if (y + 1 < blueprint.Height) output.TRCut = Cuts[(y + 1) * blueprint.Width + x].TRCut; if (x + 1 < blueprint.Width) output.TLCut = Cuts[y * blueprint.Width + x + 1].TLCut; if (output.TLCut == WallCut.DownLeftUpRight) output.TLCut = WallCut.DownRightUpLeft; //flip cuts else if (output.TLCut == WallCut.DownRightUpLeft) output.TLCut = WallCut.DownLeftUpRight; if (output.TRCut == WallCut.DownLeftUpRight) output.TRCut = WallCut.DownRightUpLeft; else if (output.TRCut == WallCut.DownRightUpLeft) output.TRCut = WallCut.DownLeftUpRight; return output; case 3: output.TLCut = input.TRCut; if (x + 1 < blueprint.Width) output.TRCut = Cuts[y * blueprint.Width + x+1].TLCut; if (output.TRCut == WallCut.DownLeftUpRight) output.TRCut = WallCut.DownRightUpLeft; //flip cut else if (output.TRCut == WallCut.DownRightUpLeft) output.TRCut = WallCut.DownLeftUpRight; return output; } return output; }
public static bool[] GenerateRoomCut(VMArchitecture target, sbyte floor, WorldRotation dir, HashSet<uint> cutRooms) { var result = new bool[target.Width*target.Height]; var offset = 0; var roommap = target.Rooms[floor-1].Map; var cutDir = CutCheckDir[(int)dir]; var walls = target.Walls[floor - 1]; var width = target.Width; for (int y1=0;y1<target.Height; y1++) { for (int x1=0; x1<target.Width; x1++) { if (walls[offset].Segments == 0 && (offset + width < walls.Length && walls[offset + width].Segments == 0) && (offset + 1 < walls.Length && walls[offset + 1].Segments == 0) && (offset - width > 0 && walls[offset - width].Segments == 0) && (offset - 1 > 0 && walls[offset - 1].Segments == 0) ) { offset++; continue; //ignore empty tiles as an optimisation } bool cut = false; for (int i=0; i<3; i++) { var x = x1 + ((i == 1) ? cutDir[0] : 0); var y = y1 + ((i == 2) ? cutDir[1] : 0); for (int j=0; j<((i>0)?4:5); j++) { if (x < 0 || x >= target.Width || y < 0 || y >= target.Height) break; if (cutRooms.Contains(roommap[y * target.Width + x] & 65535)) { cut = true; break; } x += cutDir[0]; y += cutDir[1]; } if (cut) break; } result[offset++] = cut; } } return result; }
public override void Update(UpdateState state) { base.Update(state); Cheats.Update(state); if (!vm.Ready) { return; } if (ActiveEntity == null || ActiveEntity.Dead || ActiveEntity.PersistID != SelectedSimID) { ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar && x.PersistID == SelectedSimID); //try and hook onto a sim if we have none selected. if (ActiveEntity == null) { ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar); } if (!FoundMe && ActiveEntity != null) { vm.Context.World.State.CenterTile = new Vector2(ActiveEntity.VisualPosition.X, ActiveEntity.VisualPosition.Y); vm.Context.World.State.ScrollAnchor = null; FoundMe = true; } Queue.QueueOwner = ActiveEntity; } if (GotoObject == null) { GotoObject = vm.Context.CreateObjectInstance(GOTO_GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true).Objects[0]; } if (ActiveEntity != null && BlockingDialog != null) { //are we still waiting on a blocking dialog? if not, cancel. if (ActiveEntity.Thread != null && (ActiveEntity.Thread.BlockingState == null || !(ActiveEntity.Thread.BlockingState is VMDialogResult))) { UIScreen.RemoveDialog(BlockingDialog); LastDialogID = 0; BlockingDialog = null; } } if (Visible) { if (ShowTooltip) { state.UIState.TooltipProperties.UpdateDead = false; } bool scrolled = false; if (KBScroll) { World.State.ScrollAnchor = null; int KeyboardAxisX = 0; int KeyboardAxisY = 0; Vector2 scrollBy = new Vector2(); if (state.KeyboardState.IsKeyDown(Keys.Up) || state.KeyboardState.IsKeyDown(Keys.W)) { KeyboardAxisY -= 1; } if (state.KeyboardState.IsKeyDown(Keys.Left) || state.KeyboardState.IsKeyDown(Keys.A)) { KeyboardAxisX -= 1; } if (state.KeyboardState.IsKeyDown(Keys.Down) || state.KeyboardState.IsKeyDown(Keys.S)) { KeyboardAxisY += 1; } if (state.KeyboardState.IsKeyDown(Keys.Right) || state.KeyboardState.IsKeyDown(Keys.D)) { KeyboardAxisX += 1; } scrollBy = new Vector2(KeyboardAxisX, KeyboardAxisY); scrollBy *= 0.05f; World.Scroll(scrollBy * (60f / 60)); } if (RMBScroll) { World.State.ScrollAnchor = null; Vector2 scrollBy = new Vector2(); if (state.TouchMode) { scrollBy = new Vector2(RMBScrollX - state.MouseState.X, RMBScrollY - state.MouseState.Y); RMBScrollX = state.MouseState.X; RMBScrollY = state.MouseState.Y; scrollBy /= 128f; scrollBy /= FSOEnvironment.DPIScaleFactor; } else { scrollBy = new Vector2(state.MouseState.X - RMBScrollX, state.MouseState.Y - RMBScrollY); scrollBy *= 0.0005f; var angle = (Math.Atan2(state.MouseState.X - RMBScrollX, (RMBScrollY - state.MouseState.Y) * 2) / Math.PI) * 4; angle += 8; angle %= 8; CursorType type = CursorType.ArrowUp; switch ((int)Math.Round(angle)) { case 0: type = CursorType.ArrowUp; break; case 1: type = CursorType.ArrowUpRight; break; case 2: type = CursorType.ArrowRight; break; case 3: type = CursorType.ArrowDownRight; break; case 4: type = CursorType.ArrowDown; break; case 5: type = CursorType.ArrowDownLeft; break; case 6: type = CursorType.ArrowLeft; break; case 7: type = CursorType.ArrowUpLeft; break; } GameFacade.Cursor.SetCursor(type); } World.Scroll(scrollBy * (60f / 60)); scrolled = true; } var nofocus = state.InputManager.GetFocus() == null; var keyst = state.KeyboardState; if (nofocus && (keyst.IsKeyDown(Keys.Up) || keyst.IsKeyDown(Keys.Left) || keyst.IsKeyDown(Keys.Down) || keyst.IsKeyDown(Keys.Right) || (keyst.IsKeyDown(Keys.W) || keyst.IsKeyDown(Keys.A) || keyst.IsKeyDown(Keys.S) || keyst.IsKeyDown(Keys.D)))) { KBScroll = true; } else { KBScroll = false; } if (MouseIsOn) { if (state.MouseState.RightButton == ButtonState.Pressed) { if (RMBScroll == false) { RMBScroll = true; state.InputManager.SetFocus(null); RMBScrollX = state.MouseState.X; RMBScrollY = state.MouseState.Y; } } else { RMBScroll = false; if (!scrolled && GlobalSettings.Default.EdgeScroll && !state.TouchMode) { scrolled = World.TestScroll(state); } } } if (state.MouseState.RightButton != ButtonState.Pressed) { if (RMBScroll) { GameFacade.Cursor.SetCursor(CursorType.Normal); } RMBScroll = false; } if (LiveMode) { LiveModeUpdate(state, scrolled); } else if (CustomControl != null) { CustomControl.Update(state, scrolled); } else { ObjectHolder.Update(state, scrolled); } //set cutaway around mouse if (vm.Context.Blueprint != null) { World.State.DynamicCutaway = (WallsMode == 1); //first we need to cycle the rooms that are being cutaway. Keep this up even if we're in all-cut mode. var mouseTilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor); var roomHover = vm.Context.GetRoomAt(LotTilePos.FromBigTile((short)(mouseTilePos.X), (short)(mouseTilePos.Y), World.State.Level)); var outside = (vm.Context.RoomInfo[roomHover].Room.IsOutside); if (!outside && !CutRooms.Contains(roomHover)) { CutRooms.Add(roomHover); //outside hover should not persist like with other rooms. } while (CutRooms.Count > 3) { CutRooms.Remove(CutRooms.ElementAt(0)); } if (LastWallMode != WallsMode) { if (WallsMode == 0) //walls down { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); for (int i = 0; i < LastCuts.Length; i++) { LastCuts[i] = true; } } else if (WallsMode == 1) { MouseCutRect = new Rectangle(); LastCutRooms = new HashSet <uint>() { uint.MaxValue }; //must regenerate cuts } else //walls up or roof { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastWallMode = WallsMode; } if (WallsMode == 1) { int recut = 0; var finalRooms = new HashSet <uint>(CutRooms); var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5); newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][0] * 2; newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][1] * 2; if (newCut != MouseCutRect) { MouseCutRect = newCut; recut = 1; } if (LastFloor != World.State.Level || LastRotation != World.State.Rotation || !finalRooms.SetEquals(LastCutRooms)) { LastCuts = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.Rotation, finalRooms); recut = 2; LastFloor = World.State.Level; LastRotation = World.State.Rotation; } LastCutRooms = finalRooms; if (recut > 0) { var finalCut = new bool[LastCuts.Length]; Array.Copy(LastCuts, finalCut, LastCuts.Length); var notableChange = VMArchitectureTools.ApplyCutRectangle(vm.Context.Architecture, World.State.Level, finalCut, MouseCutRect); if (recut > 1 || notableChange || LastRectCutNotable) { vm.Context.Blueprint.Cutaway = finalCut; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastRectCutNotable = notableChange; } } } } }
public TrackSection(WorldPosition position, WorldRotation rotation, float length) : this(position, rotation, length, false, 0) { }
public double Radians; // Just store the angle in radians public WorldRotationSerializer(WorldRotation rot) { Radians = rot.Radians; }
/// <inheritdoc /> public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Position) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } // Collect the total number of living particles in the parent pool which have a Position field var parentPool = Parent?.Pool; var parentParticlesCount = parentPool?.LivingParticles ?? 0; var posFieldParent = parentPool?.GetField(ParticleFields.Position) ?? ParticleFieldAccessor <Vector3> .Invalid(); if (!posFieldParent.IsValid()) { parentParticlesCount = 0; } var oldPosFieldParent = parentPool?.GetField(ParticleFields.OldPosition) ?? ParticleFieldAccessor <Vector3> .Invalid(); var spawnControlField = GetSpawnControlField(); var posField = pool.GetField(ParticleFields.Position); var rndField = pool.GetField(ParticleFields.RandomSeed); var oldField = pool.GetField(ParticleFields.OldPosition); var leftCorner = PositionMin * WorldScale; var xAxis = new Vector3(PositionMax.X * WorldScale.X - leftCorner.X, 0, 0); var yAxis = new Vector3(0, PositionMax.Y * WorldScale.Y - leftCorner.Y, 0); var zAxis = new Vector3(0, 0, PositionMax.Z * WorldScale.Z - leftCorner.Z); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref leftCorner); WorldRotation.Rotate(ref xAxis); WorldRotation.Rotate(ref yAxis); WorldRotation.Rotate(ref zAxis); } // Already inheriting from parent if (parentParticlesCount == 0) { leftCorner += WorldPosition; } var sequentialParentIndex = 0; var sequentialParentParticles = 0; var parentIndex = 0; // Interpolation - if parent particle has OldPosition field var stepF = 0f; var stepTotal = 0f; var positionDistance = new Vector3(0, 0, 0); var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var particleRandPos = leftCorner; particleRandPos += xAxis * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandPos += yAxis * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandPos += zAxis * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); if (parentParticlesCount > 0) { var parentParticlePosition = new Vector3(0, 0, 0); // Spawn is fixed - parent particles have spawned a very specific number of children each if (spawnControlField.IsValid()) { // Interpolation - if parent particle has OldPosition field while (sequentialParentParticles == 0) { // Early out - no more fixed number children. Rest of the particles (if any) are skipped intentionally if (sequentialParentIndex >= parentParticlesCount) { return; } parentIndex = sequentialParentIndex; var tempParentParticle = parentPool.FromIndex(parentIndex); sequentialParentIndex++; var childrenAttribute = (*((ParticleChildrenAttribute *)tempParentParticle[spawnControlField])); sequentialParentParticles = (int)childrenAttribute.ParticlesToEmit; if (oldPosFieldParent.IsValid()) { stepF = (sequentialParentParticles > 0) ? (1f / (float)sequentialParentParticles) : 1; stepTotal = 0f; positionDistance = ((*((Vector3 *)tempParentParticle[oldPosFieldParent])) - (*((Vector3 *)tempParentParticle[posFieldParent]))); } } sequentialParentParticles--; var parentParticle = parentPool.FromIndex(parentIndex); parentParticlePosition = (*((Vector3 *)parentParticle[posFieldParent])); parentParticlePosition += positionDistance * stepTotal; stepTotal += stepF; } // Spawn is not fixed - pick a parent at random else { parentIndex = (int)(parentParticlesCount * randSeed.GetFloat(RandomOffset.Offset1A + ParentSeedOffset)); var parentParticle = parentPool.FromIndex(parentIndex); parentParticlePosition = (*((Vector3 *)parentParticle[posFieldParent])); } // Convert from Local -> World space if needed if (Parent.SimulationSpace == EmitterSimulationSpace.Local) { WorldRotation.Rotate(ref parentParticlePosition); parentParticlePosition *= WorldScale.X; parentParticlePosition += WorldPosition; } particleRandPos += parentParticlePosition; } (*((Vector3 *)particle[posField])) = particleRandPos; if (oldField.IsValid()) { (*((Vector3 *)particle[oldField])) = particleRandPos; } i = (i + 1) % maxCapacity; } }
private void UpdateCutaway(UpdateState state) { if (vm.Context.Blueprint != null) { World.State.DynamicCutaway = (WallsMode == 1); //first we need to cycle the rooms that are being cutaway. Keep this up even if we're in all-cut mode. var mouseTilePos = World.EstTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor); var roomHover = vm.Context.GetRoomAt(LotTilePos.FromBigTile((short)(mouseTilePos.X), (short)(mouseTilePos.Y), World.State.Level)); var outside = (vm.Context.RoomInfo[roomHover].Room.IsOutside); if (!outside && !CutRooms.Contains(roomHover)) { CutRooms.Add(roomHover); //outside hover should not persist like with other rooms. } while (CutRooms.Count > 3) { CutRooms.Remove(CutRooms.ElementAt(0)); } if (LastWallMode != WallsMode) { if (WallsMode == 0) //walls down { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); for (int i = 0; i < LastCuts.Length; i++) { LastCuts[i] = true; } } else if (WallsMode == 1) { MouseCutRect = new Rectangle(); LastCutRooms = new HashSet <uint>() { uint.MaxValue }; //must regenerate cuts } else //walls up or roof { LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height]; vm.Context.Blueprint.Cutaway = LastCuts; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastWallMode = WallsMode; } if (WallsMode == 1) { if (RMBScroll || !MouseIsOn) { return; } int recut = 0; var finalRooms = new HashSet <uint>(CutRooms); var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5); newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][0] * 2; newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][1] * 2; if (newCut != MouseCutRect) { MouseCutRect = newCut; recut = 1; } if (LastFloor != World.State.Level || LastRotation != World.State.CutRotation || !finalRooms.SetEquals(LastCutRooms)) { LastCuts = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.CutRotation, finalRooms); recut = 2; LastFloor = World.State.Level; LastRotation = World.State.CutRotation; } LastCutRooms = finalRooms; if (recut > 0) { var finalCut = new bool[LastCuts.Length]; Array.Copy(LastCuts, finalCut, LastCuts.Length); var notableChange = VMArchitectureTools.ApplyCutRectangle(vm.Context.Architecture, World.State.Level, finalCut, MouseCutRect); if (recut > 1 || notableChange || LastRectCutNotable) { vm.Context.Blueprint.Cutaway = finalCut; vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED)); } LastRectCutNotable = notableChange; } } } }
public override void GetStaticCollidablesWithScale(List <Collidable> outCollidables) { UpdateScaledShape(); m_scaledStaticCollidable.WorldTransform = new RigidTransform(WorldPosition.ToBepu(), WorldRotation.ToBepu()); outCollidables.Add(m_scaledStaticCollidable); }
public List<BlueprintOccupiedTile> GetOccupiedTiles(WorldRotation order) { if (OccupiedTilesDirty){ OccupiedTiles.Clear(); foreach (var tile in IsometricTileIterator.Tiles(order, 0, 0, (short)Width, (short)Height)) { var offset = GetOffset(tile.TileX, tile.TileY); var hasObject = Objects[offset] != null && Objects[offset].Objects.Count > 0; if (hasObject) { var inst = new BlueprintOccupiedTile(); inst.TileX = tile.TileX; inst.TileY = tile.TileY; if (hasObject){ inst.Type |= BlueprintOccupiedTileType.OBJECT; } OccupiedTiles.Add(inst); } } OccupiedTilesOrder = order; OccupiedTilesDirty = false; } /** Has rotation changed? **/ if (order != OccupiedTilesOrder){ /** Re-sort **/ OccupiedTiles.Sort(new IsometricTileSorter<BlueprintOccupiedTile>(order)); OccupiedTilesOrder = order; } return OccupiedTiles; }
// Start is called before the first frame update public void adjustPosition(GameObject obj, WorldLocation location, WorldRotation rotation) { obj.transform.position = new Vector3(); }
/// <inheritdoc /> public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Position) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } var posField = pool.GetField(ParticleFields.Position); var rndField = pool.GetField(ParticleFields.RandomSeed); var arcOffset = new Vector3(0, ArcHeight, 0); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref arcOffset); } var leftCorner = PositionMin * WorldScale; var xAxis = new Vector3(PositionMax.X * WorldScale.X - leftCorner.X, 0, 0); var yAxis = new Vector3(0, PositionMax.Y * WorldScale.Y - leftCorner.Y, 0); var zAxis = new Vector3(0, 0, PositionMax.Z * WorldScale.Z - leftCorner.Z); if (!WorldRotation.IsIdentity) { WorldRotation.Rotate(ref leftCorner); WorldRotation.Rotate(ref xAxis); WorldRotation.Rotate(ref yAxis); WorldRotation.Rotate(ref zAxis); } var targetCornerAdd = Target?.WorldMatrix.TranslationVector - WorldPosition ?? FallbackTarget; var totalCountLessOne = (FixedLength > 0) ? (FixedLength - 1) : (startIdx < endIdx) ? (endIdx - startIdx - 1) : (endIdx - startIdx + maxCapacity - 1); var stepF = (totalCountLessOne > 1) ? (1f / totalCountLessOne) : 1f; var step = -stepF; var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); if (Sequential) { step += stepF; if (FixedLength > 0) { step = (i % FixedLength) * stepF; } } else { step = randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset); } var positionOffsetFactor = (float)Math.Sin(step * Math.PI); var particleRandPos = leftCorner * positionOffsetFactor + targetCornerAdd * step + arcOffset * positionOffsetFactor + WorldPosition; particleRandPos += xAxis * positionOffsetFactor * randSeed.GetFloat(RandomOffset.Offset3A + SeedOffset); particleRandPos += yAxis * positionOffsetFactor * randSeed.GetFloat(RandomOffset.Offset3B + SeedOffset); particleRandPos += zAxis * positionOffsetFactor * randSeed.GetFloat(RandomOffset.Offset3C + SeedOffset); (*((Vector3 *)particle[posField])) = particleRandPos; i = (i + 1) % maxCapacity; } }
public static IEnumerable <IsometricTile> Tiles(WorldRotation rotation, short startX, short startY, short width, short height) { return(Tiles(rotation, startX, startY, width, height, 1, 1)); }
public void DrawFloor(GraphicsDevice gd, Effect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass, Matrix?lightWorld = null, WorldState state = null, int minFloor = 0) { var parallax = WorldConfig.Current.Complex; //assumes the effect and all its parameters have been set up already //we just need to get the right texture and offset var flrContent = Content.Content.Get().WorldFloors; e.Parameters["TexOffset"].SetValue(new Vector2());// TexOffset[zoom]*-1f); var tmat = TexMat[rot]; e.Parameters["TexMatrix"].SetValue(tmat); var f = 0; foreach (var floor in Floors) { if (!floors.Contains((sbyte)(f++))) { continue; } Matrix worldmat; if (lightWorld == null) { worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0); } else { worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value; e.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f); } e.Parameters["World"].SetValue(worldmat); e.Parameters["Level"].SetValue((float)(f - ((lightWorld == null)?0.999f:1f))); if (roommaps != null) { e.Parameters["RoomMap"].SetValue(roommaps[f - 1]); } foreach (var type in floor.GroupForTileType) { bool water = false; var dat = type.Value.GPUData; if (dat == null) { continue; } gd.Indices = dat; var id = type.Key; var doubleDraw = false; Texture2D SPR = null; Texture2D pSPR = null; if (id == 0) { e.Parameters["UseTexture"].SetValue(false); e.Parameters["IgnoreColor"].SetValue(false); e.Parameters["GrassShininess"].SetValue(0.02f);// (float)0.25); } else { e.Parameters["GrassShininess"].SetValue((id >= 65503)?0.02f:0f); if (id >= 65503) { if (id == 65503) { water = true; var airTiles = TextureGenerator.GetAirTiles(gd); switch (zoom) { case WorldZoom.Far: SPR = airTiles[2]; break; case WorldZoom.Medium: SPR = airTiles[1]; break; case WorldZoom.Near: SPR = airTiles[0]; break; } } else { e.Parameters["Water"].SetValue(true); var pool = id >= 65520; water = true; if (!pool) { e.Parameters["UseTexture"].SetValue(false); e.Parameters["IgnoreColor"].SetValue(false); //quickly draw under the water pass.Apply(); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); e.Parameters["UseTexture"].SetValue(true); e.Parameters["IgnoreColor"].SetValue(true); if (lightWorld == null) { e.Parameters["World"].SetValue(worldmat * Matrix.CreateTranslation(0, 0.05f, 0)); } id -= 65504; } else { id -= 65520; } e.Parameters["TexMatrix"].SetValue(CounterTexMat[rot]); var roti = (int)rot; roti = (4 - roti) % 4; id = (ushort)(((id << roti) & 15) | (id >> (4 - roti))); //pools & water are drawn with special logic, and may also be drawn slightly above the ground. int baseSPR; int frameNum = 0; if (state != null) { if (PoolReplace != null && pool) { SPR = PoolReplace[id]; if (parallax) { pSPR = PoolReplaceParallax[id]; } } else { switch (zoom) { case WorldZoom.Far: baseSPR = (pool) ? 0x400 : 0x800; frameNum = (pool) ? 0 : 2; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; case WorldZoom.Medium: baseSPR = (pool) ? 0x410 : 0x800; frameNum = (pool) ? 0 : 1; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; default: baseSPR = (pool) ? 0x420 : 0x800; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; } } } } } else { var flr = flrContent.Get(id); if (flr == null) { continue; } if (state != null) { switch (zoom) { case WorldZoom.Far: SPR = state._2D.GetTexture(flr.Far.Frames[0]); break; case WorldZoom.Medium: SPR = state._2D.GetTexture(flr.Medium.Frames[0]); break; default: SPR = state._2D.GetTexture(flr.Near.Frames[0]); break; } } } //e.Parameters["UseTexture"].SetValue(SPR != null); } e.Parameters["BaseTex"].SetValue(SPR); if (SPR != null && SPR.Name == null) { doubleDraw = true; SPR.Name = Alt.ToString(); } if (pSPR != null) { var parallaxPass = e.CurrentTechnique.Passes[4]; e.Parameters["ParallaxTex"].SetValue(pSPR); e.Parameters["ParallaxUVTexMat"].SetValue(new Vector4(0.7071f, -0.7071f, 0.7071f, 0.7071f)); e.Parameters["ParallaxHeight"].SetValue(0.1f); parallaxPass.Apply(); } else { pass.Apply(); } if (Alt && !FSOEnvironment.DirectX) { //opengl bug workaround. For some reason, the texture is set to clamp mode by some outside force on first draw. //Monogame then thinks the texture is wrapping. gd.SamplerStates[1] = CustomWrap; } gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); //gd.SamplerStates[1] = SamplerState.LinearWrap; if (id == 0) { e.Parameters["UseTexture"].SetValue(true); e.Parameters["IgnoreColor"].SetValue(true); } if (water) { e.Parameters["World"].SetValue(worldmat); e.Parameters["TexMatrix"].SetValue(tmat); e.Parameters["Water"].SetValue(false); } } } e.Parameters["Water"].SetValue(false); Alt = !Alt; }
public void DrawFloor(GraphicsDevice gd, Effect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass, Matrix?lightWorld = null, WorldState state = null, int minFloor = 0) { //assumes the effect and all its parameters have been set up already //we just need to get the right texture and offset var flrContent = Content.Content.Get().WorldFloors; e.Parameters["TexOffset"].SetValue(new Vector2());// TexOffset[zoom]*-1f); var tmat = TexMat[rot]; e.Parameters["TexMatrix"].SetValue(tmat); var f = 0; foreach (var floor in Floors) { if (!floors.Contains((sbyte)(f++))) { continue; } Matrix worldmat; if (lightWorld == null) { worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0); } else { worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value; e.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f); } e.Parameters["World"].SetValue(worldmat); e.Parameters["Level"].SetValue((float)(f - ((lightWorld == null)?0.999f:1f))); if (roommaps != null) { e.Parameters["RoomMap"].SetValue(roommaps[f - 1]); } foreach (var type in floor.GroupForTileType) { bool water = false; var dat = type.Value.GPUData; if (dat == null) { continue; } gd.Indices = dat; var id = type.Key; if (id == 0) { e.Parameters["UseTexture"].SetValue(false); e.Parameters["IgnoreColor"].SetValue(false); } else { Texture2D SPR = null; if (id >= 65503) { if (id == 65503) { water = true; var airTiles = TextureGenerator.GetAirTiles(gd); switch (zoom) { case WorldZoom.Far: SPR = airTiles[2]; break; case WorldZoom.Medium: SPR = airTiles[1]; break; case WorldZoom.Near: SPR = airTiles[0]; break; } } else { e.Parameters["Water"].SetValue(true); var pool = id >= 65520; water = true; if (!pool) { e.Parameters["UseTexture"].SetValue(false); e.Parameters["IgnoreColor"].SetValue(false); //quickly draw under the water pass.Apply(); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); e.Parameters["UseTexture"].SetValue(true); e.Parameters["IgnoreColor"].SetValue(true); if (lightWorld == null) { e.Parameters["World"].SetValue(worldmat * Matrix.CreateTranslation(0, 0.05f, 0)); } id -= 65504; } else { id -= 65520; } e.Parameters["TexMatrix"].SetValue(CounterTexMat[rot]); var roti = (int)rot; roti = (4 - roti) % 4; id = (ushort)(((id << roti) & 15) | (id >> (4 - roti))); //pools & water are drawn with special logic, and may also be drawn slightly above the ground. int baseSPR; int frameNum = 0; if (state != null) { switch (zoom) { case WorldZoom.Far: baseSPR = (pool) ? 0x400 : 0x800; frameNum = (pool) ? 0 : 2; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; case WorldZoom.Medium: baseSPR = (pool) ? 0x410 : 0x800; frameNum = (pool) ? 0 : 1; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; default: baseSPR = (pool) ? 0x420 : 0x800; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; } } } } else { var flr = flrContent.Get(id); if (flr == null) { continue; } if (state != null) { switch (zoom) { case WorldZoom.Far: SPR = state._2D.GetTexture(flr.Far.Frames[0]); break; case WorldZoom.Medium: SPR = state._2D.GetTexture(flr.Medium.Frames[0]); break; default: SPR = state._2D.GetTexture(flr.Near.Frames[0]); break; } } } //e.Parameters["UseTexture"].SetValue(SPR != null); e.Parameters["BaseTex"].SetValue(SPR); } pass.Apply(); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); if (id == 0) { e.Parameters["UseTexture"].SetValue(true); e.Parameters["IgnoreColor"].SetValue(true); } if (water) { e.Parameters["World"].SetValue(worldmat); e.Parameters["TexMatrix"].SetValue(tmat); e.Parameters["Water"].SetValue(false); } } } e.Parameters["Water"].SetValue(false); }
public override void UpdateStaticCollider() { RigidTransform shapeTransform = new RigidTransform(WorldPosition.ToBepu(), WorldRotation.ToBepu()); m_scaledStaticCollidable.UpdateBoundingBoxForTransform(ref shapeTransform); }
public TrackJunction(WorldPosition pos, WorldRotation rot) { position = pos; rotation = rot; sections = new List <int>(); }