public override void AgentAction(float[] vectorAction, string textAction) { YellowLightRemaining--; if (YellowLightRemaining <= 0) { if (lightColor == LightColor.Green) { if (vectorAction[0] >= vectorAction[1]) { nextDirection = LightDirection.CrossNorthSouth; } else if (vectorAction[0] < vectorAction[1]) { nextDirection = LightDirection.CrossEastWest; } } if (lightColor == LightColor.Yellow) { SetLightColor(LightColor.Green); lightDirection = nextDirection; }//If yellow, switch the next direction else if (lightDirection != nextDirection) { SetLightColor(LightColor.Yellow); YellowLightRemaining = yellowTime; } } }
private static async Task LightAsync(KeyboardNames key, LightDirection direction, int steps, int stepDelay = 50) { int value = 0; for (int i = 0; i < steps; i++) { int step = direction == LightDirection.Up ? i : steps - i; value = (int)((double)step / steps * 100); LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(key, value, 0, 0); await Task.Delay(stepDelay, cancellationToken); } int?last = null; if (direction == LightDirection.Up) { if (value != 100) { last = 100; } } else { if (value != 0) { last = 0; } } if (last != null) { LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(key, last.Value, 0, 0); } }
public override void AgentReset() { SetReward(reward); lightColor = LightColor.Green; lightDirection = LightDirection.CrossNorthSouth; frameChanged = 0; }
public void SetLightDirection(float yaw, float pitch, float roll) { this.Yaw = yaw; this.Pitch = pitch; this.Roll = roll; this.RotationMatrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll); LightDirection = Vector3.Transform(Vector3.Up, this.RotationMatrix); LightDirection.Normalize(); }
//Greedy algorithm choose either crossNorthSouth or crossEastWest every x ticks. If that direction has the most cars in queue, then the light does not change, else it changes to the opposite direction void Update() { lightRemaining--; if (0 >= lightRemaining) { if (LightColor.Green == lightColor) { Nullable <int> northStraightOccupants = intersection?.inboundNorthRoad?.straightRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> northLeftOccupants = intersection?.inboundNorthRoad?.leftRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> eastStraightOccupants = intersection?.inboundEastRoad?.straightRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> eastLeftOccupants = intersection?.inboundEastRoad?.leftRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> southStraightOccupants = intersection?.inboundSouthRoad?.straightRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> southLeftOccupants = intersection?.inboundSouthRoad?.leftRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> westStraightOccupants = intersection?.inboundWestRoad?.straightRoadScript.occupants.Where(car => null != car).Count(); Nullable <int> westLeftOccupants = intersection?.inboundWestRoad?.leftRoadScript.occupants.Where(car => null != car).Count(); //Get cars in each lane int northSouthLanes = (null == intersection?.inboundNorthRoad ? 0 : 1) + (null == intersection?.inboundSouthRoad ? 0 : 1); int eastWestLanes = (null == intersection?.inboundEastRoad ? 0 : 1) + (null == intersection?.inboundWestRoad ? 0 : 1); //Get number of lanes int northSouthOccupants = (northStraightOccupants ?? 0) + (northLeftOccupants ?? 0) + (southStraightOccupants ?? 0) + (southLeftOccupants ?? 0); int eastWestOccupants = (eastStraightOccupants ?? 0) + (eastLeftOccupants ?? 0) + (westStraightOccupants ?? 0) + (westLeftOccupants ?? 0); //Add number of cars in each cross amount northSouthOccupants *= (1 == northSouthLanes ? 2 : 1); eastWestOccupants *= (1 == eastWestLanes ? 2 : 1); //Multiply by 2 if only 1 lane present so values can be comparable if (northSouthOccupants > eastWestOccupants) { nextDirection = LightDirection.CrossNorthSouth; } else if (eastWestOccupants > northSouthOccupants) { nextDirection = LightDirection.CrossEastWest; }//Next direction is direction with most cars } if (LightColor.Yellow == lightColor) { SetLightColor(LightColor.Green); lightRemaining = greenTime; lightDirection = nextDirection; }//If yellow, switch the next direction else if (lightDirection == nextDirection) { lightRemaining = greenTime; }//If green, but not changing continue else { SetLightColor(LightColor.Yellow); lightRemaining = yellowTime; }//If green and changing, switch to yellow } }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// <span class="keyword"> /// <span class="languageSpecificText"> /// <span class="cs">true</span> /// <span class="vb">True</span> /// <span class="cpp">true</span> /// </span> /// </span> /// <span class="nu"> /// <span class="keyword">true</span> (<span class="keyword">True</span> in Visual Basic)</span> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <span class="keyword"><span class="languageSpecificText"><span class="cs">false</span><span class="vb">False</span><span class="cpp">false</span></span></span><span class="nu"><span class="keyword">false</span> (<span class="keyword">False</span> in Visual Basic)</span>. /// </returns> public bool Equals(Gorgon2DLight other) { if (other == null) { return(false); } return((LightType == other.LightType) && (Attenuation.EqualsEpsilon(other.Attenuation)) && (Intensity.EqualsEpsilon(other.Intensity)) && (SpecularPower.EqualsEpsilon(other.SpecularPower)) && (SpecularEnabled == other.SpecularEnabled) && (Color.Equals(other.Color)) && (Position.Equals(other.Position)) && (LightDirection.Equals(other.LightDirection))); }
//Helper function for FloydBigBrain private bool IsNeighbor(Road r, IntersectionTwoLane i, LightDirection incomingDirection) { bool TurnIntersection = false; if (i.lightController is Turn) { TurnIntersection = true; } if (r == i.outboundNorthRoad?.straightRoadScript) { if (TurnIntersection && incomingDirection == LightDirection.South) { return(false); } return(true); } if (r == i.outboundEastRoad?.straightRoadScript) { if (TurnIntersection && incomingDirection == LightDirection.West) { return(false); } return(true); } if (r == i.outboundSouthRoad?.straightRoadScript) { if (TurnIntersection && incomingDirection == LightDirection.North) { return(false); } return(true); } if (r == i.outboundWestRoad?.straightRoadScript) { if (TurnIntersection && incomingDirection == LightDirection.East) { return(false); } return(true); } return(false); }
// calculate an arbitrary up vector perpendicular to the light direction void CalculateUp() { var abs = LightDirection.Abs(); var max = abs.Max(); Vector3 up = Vector3.UnitY; if (max == abs.X) { up = new Vector3(0, 1, 0); } if (max == abs.Y) { up = new Vector3(0, 0, 1); } if (max == abs.Z) { up = new Vector3(1, 0, 0); } LightUp = up.ProjectPlane(LightDirection).Normalized(); }
protected override void OnApply() { if (_paletteDirty) { _paletteParam.SetValue(Palette); _paletteDirty = false; } if (!ManualLightMatrix && _lightMatrixDirty) { var mat = LightDirection.GetViewProjectionMatrix(new BoundingFrustum(_view * _projection)); _dirLightMatrixParam?.SetValue(mat); _lightMatrixDirty = false; } if (_cameraDirty) { _positionParam?.SetValue(ChunkPosition); _viewParam?.SetValue(View); _projectionParam?.SetValue(Projection); _cameraDirty = false; } if (_lightDirty) { _lightDirParam?.SetValue(LightDirection); _diffuseLightParam?.SetValue(DiffuseLight); _ambientLightParam?.SetValue(AmbientLight.ToVector3()); _lightDirty = false; } if (_shadowMapDirty) { _shadowMapParam?.SetValue(_shadowMap); _shadowMapDirty = false; } }
void Awake() { Transform firstItem = transform.GetChild(0); Transform secondItem = transform.GetChild(1); if (firstItem.name.Equals("StraightLane")) { straightRoad = firstItem.gameObject; straightRoadScript = straightRoad.GetComponent <Road>(); } else if (firstItem.name.Equals("LeftLane")) { leftRoad = firstItem.gameObject; leftRoadScript = leftRoad.GetComponent <Road>(); } if (secondItem.name.Equals("StraightLane")) { straightRoad = secondItem.gameObject; straightRoadScript = straightRoad.GetComponent <Road>(); } else if (secondItem.name.Equals("LeftLane")) { leftRoad = secondItem.gameObject; leftRoadScript = leftRoad.GetComponent <Road>(); } if (!leftRoad || !straightRoad || !leftRoadScript || !straightRoadScript) { Debug.LogError("cannot load inner Road objects. Make sure they are named 'LeftLane' and 'StraightLane'"); Destroy(this); } leftLaneLength = leftRoadScript.occupants.Length - 1; if (leftLaneLength == -1) { leftAvailable = false; } straightLaneLength = straightRoadScript.occupants.Length - 1; LightDirection direction = straightRoadScript.direction; if (direction == LightDirection.North) { leftShift = new Vector3(-1, 0, 0); leftDirection = LightDirection.West; uTurnDirection = LightDirection.South; } else if (direction == LightDirection.East) { leftShift = new Vector3(0, 1, 0); leftDirection = LightDirection.North; uTurnDirection = LightDirection.West; } else if (direction == LightDirection.South) { leftShift = new Vector3(1, 0, 0); leftDirection = LightDirection.East; uTurnDirection = LightDirection.North; } else if (direction == LightDirection.West) { leftShift = new Vector3(0, -1, 0); leftDirection = LightDirection.South; uTurnDirection = LightDirection.East; } }
public void SetLightDirection(LightDirection d) { lightDirection = d; }
void Start() { lightRemaining = greenTime; nextDirection = lightDirection; }