private static void OnFrameUpdate() { if (FrameUpdate != null) { FrameUpdate.Invoke(); } }
/// <summary> /// Updates pose for our entity. We override default implementation /// since we control our own rendering when no file mesh is supplied, which means /// we dont need world transform updates /// </summary> /// <param name="update"></param> public override void Update(FrameUpdate update) { float leftFront = _leftFrontWheel.Wheel.AxleSpeed + _leftFrontTargetVelocity; float rightFront = _rightFrontWheel.Wheel.AxleSpeed + _rightFrontTargetVelocity; float leftRear = _leftRearWheel.Wheel.AxleSpeed + _leftRearTargetVelocity; float rightRear = _rightRearWheel.Wheel.AxleSpeed + _rightRearTargetVelocity; float timeStep = (float)update.ElapsedTime; ModulateWheelSpeed(leftFront, _leftFrontWheel, timeStep); ModulateWheelSpeed(rightFront, _rightFrontWheel, timeStep); ModulateWheelSpeed(leftRear, _leftRearWheel, timeStep); ModulateWheelSpeed(rightRear, _rightRearWheel, timeStep); // update state for us and all the shapes that make up the rigid body PhysicsEntity.UpdateState(true); // update entities in fields _leftFrontWheel.Update(update); _rightFrontWheel.Update(update); _leftRearWheel.Update(update); _rightRearWheel.Update(update); // sim engine will update children base.Update(update); }
// Use this for initialization void Start() { Sprites = new Sprite[] { Blue, Red, Purple }; Panels = new GameObject[] { CEnPanel, PEnPanel, PCPanel }; CurrentPanel = Panels[0]; FrameScript = GetComponent <FrameUpdate>(); }
/// <summary> /// Feature:Number /// </summary> /// <param name="number">number</param> /// <returns>FrameUpdate</returns> public FrameUpdate AddNumber(char number) { Feature CurrentFeature = Feature.NUMBER; return(ThrowOrderException <FrameUpdate>(CurrentFeature, () => { FrameUpdate frameUpdate = NumberMachine.AddNumber(number); //等號後輸入數字 if (PreviousFeature == Feature.EQUAL) { frameUpdate.RemoveLength = ExpUpdate.REMOVE_ALL; //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return frameUpdate; } //backspace或clearerror之後的數字處理 if ((PreviousFeature == Feature.BACKSPACE || PreviousFeature == Feature.CLEAR_ERROR) && NumberMachine.NumberField.Number == 0) { frameUpdate.RemoveLength += 1; //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return frameUpdate; } //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return frameUpdate; })); }
public void OnDispatch(FrameUpdate args) { if (player2D.Playing == false) { player2D.Play(); } }
/// <summary> /// 注册帧管理器) M/ n0 {7 G. o8 ?( ^6 g0 p /// </summary>6 r- _1 s9 a, C# f/ e- Y" E /// <param name="objectItem">Object item.</param> /// <param name="callback">Callback.</param>* }+ r! K1 I3 b8 l. g& m6 R+ N2 r public static void Register(object objectItem, Action callback = null) { if (!FrameList.ContainsKey(objectItem)) { FrameUpdate frameItem = new FrameUpdate(callback); FrameList.Add(objectItem, frameItem); } }
/// <summary> /// 依功能回傳畫面物件 /// </summary> /// <param name="boardObject">面板物件</param> /// <param name="frameUpdate">畫面更新</param> /// <returns>畫面物件</returns> public override FrameObject GetFrameObject(BoardObject boardObject, FrameUpdate frameUpdate) { //完整運算式的刷新 boardObject.CompleteExpression = frameUpdate.Refresh(boardObject.CompleteExpression); //panel, subpanel設定 boardObject.FrameObject.SubPanel = boardObject.CompleteExpression; boardObject.FrameObject.Panel = frameUpdate.Answer; return(boardObject.FrameObject); }
/// <summary> /// 右括號事件 /// </summary> /// <returns>FrameUpdate</returns> public FrameUpdate RightBracket() { Feature CurrentFeature = Feature.RIGHT_BRACKET; return(ThrowOrderException <FrameUpdate>(CurrentFeature, () => { FrameUpdate frameUpdate = NumberMachine.RightBracket(); //執行成功時記錄下這次的Cast PreviousFeature = Feature.RIGHT_BRACKET; return frameUpdate; })); }
/// <summary> /// 依計畫內容回傳畫面更新 /// </summary> /// <param name="computeObject">計算物件</param> /// <returns>畫面更新</returns> public override FrameUpdate Compute(ComputeObject computeObject) { computeObject.TreeStack.Push(new ExpressionTree()); var frameUpdate = new FrameUpdate(removeLength: 0, updateString: "("); if (computeObject.LastFeature == typeof(Equal)) { frameUpdate.RemoveLength = FrameUpdate.REMOVE_ALL; } return(frameUpdate); }
/// <summary> /// 依功能回傳畫面物件 /// </summary> /// <param name="boardObject">面板物件</param> /// <param name="frameUpdate">畫面更新</param> /// <returns>畫面物件</returns> public override FrameObject GetFrameObject(BoardObject boardObject, FrameUpdate frameUpdate) { string answer = frameUpdate.Answer; //完整運算式的刷新 boardObject.CompleteExpression = frameUpdate.Refresh(boardObject.CompleteExpression); //panel, subpanel設定 boardObject.FrameObject.SubPanel = boardObject.CompleteExpression.Substring(0, boardObject.CompleteExpression.Length - answer.Length); boardObject.FrameObject.Panel = answer; return(boardObject.FrameObject); }
public override void Update(FrameUpdate update) { // The joint member in each joint description needs to be set after all of the joints // have been created. If this has not been done yet, do it now. if (_joints[0].Joint == null) { int index = 0; foreach (VisualEntity child in Children) { // no joints in the camera //if (child.GetType() == typeof(AttachedCameraEntity)) // continue; _joints[index + 0].Joint = (PhysicsJoint)child.ParentJoint; // _joints[index + 1].Joint = (PhysicsJoint)child.Children[0].ParentJoint; // _joints[index + 2].Joint = (PhysicsJoint)child.Children[0].Children[0].ParentJoint; // _joints[index + 3].Joint = (PhysicsJoint)child.Children[0].Children[0].Children[0].ParentJoint; // _joints[index + 4].Joint = (PhysicsJoint)child.Children[0].Children[0].Children[0].Children[0].ParentJoint; // _joints[index + 5].Joint = (PhysicsJoint)child.Children[0].Children[0].Children[0].Children[0].Children[0].ParentJoint; index += 6; } } base.Update(update); // update joints if necessary if (_moveToActive) { bool done = true; // Check each joint and update it if necessary. for (int index = 0; index < _joints.Length; index++) { if (_joints[index].NeedToMove(_epsilon)) { done = false; Vector3 normal = _joints[index].Joint.State.Connectors[0].JointAxis; _joints[index].UpdateCurrent(_prevTime); _joints[index].Joint.SetAngularDriveOrientation( Quaternion.FromAxisAngle(1, 0, 0, DegreesToRadians(_joints[index].Current))); } } if (done) { // no joints needed to be updated, the movement is finished _moveToActive = false; _moveToResponsePort.Post(new SuccessResult()); } } _prevTime = update.ElapsedTime; }
public void OnDispatch(FrameUpdate args) { int frame = Time.frame_count - 1; for (int i = 0; i < mouse_buttons.Length; ++i) { if (mouse_buttons[i].frame == frame) { mouse_buttons[i] = (0, 0); } } }
//factory層 public FrameObject Layer1() { FrameUpdate frameUpdate = Layer2(); //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定 var subPanel = CompleteExpression; var panel = frameUpdate.Answer; return(new FrameObject(subPanel, panel)); }
/// <summary> /// 调用函数1 @$ @" v4 g! `$ U! a, a /// </summary>2 ^' N& q" x8 [# t public static void Run() { FrameUpdate[] objectList = new FrameUpdate[FrameList.Values.Count]; FrameList.Values.CopyTo(objectList, 0); // 锁定 foreach (FrameUpdate frameItem in objectList) { if (frameItem != null) { frameItem.Update(); } } }
/// <summary> /// 依功能回傳畫面物件 /// </summary> /// <param name="boardObject">面板物件</param> /// <param name="frameUpdate">畫面更新</param> /// <returns>畫面物件</returns> public override FrameObject GetFrameObject(BoardObject boardObject, FrameUpdate frameUpdate) { //全資訊初始化 boardObject.Init(); //完整運算式的刷新 boardObject.CompleteExpression = string.Empty; //panel, subpanel設定。 boardObject.FrameObject.SubPanel = boardObject.CompleteExpression; boardObject.FrameObject.Panel = "0"; return(boardObject.FrameObject); }
/// <summary> /// The frameUpdate method gets called every frame iteration to frameUpdate all values /// </summary> /// <param name="frameUpdate">Additional data provided with the current frame</param> public override void Update(FrameUpdate update) { ProcessDeferredTaskQueue(); // Update the pose to the position of the multicopter base if (Parent != null) { State.Pose = Parent.State.Pose; } // Update the propeller rotation to simulate a moving propeller meshRotationVector.Y = MeshRotation.Y + pitchRate; MeshRotation = meshRotationVector; }
public FrameObject Layer1() { //OrderingChecker會回傳Update與要給Panel的numberString //FrameUpdate frameUpdate = OrderingChecker.AddBinary(Content); FrameUpdate frameUpdate = Layer2(); //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定 var subPanel = CompleteExpression; var panel = frameUpdate.Answer; return(new FrameObject(subPanel, panel)); }
//factory層 public FrameObject Layer1() { //OrderingChecker會回傳FrameUpdate //FrameUpdate frameUpdate = OrderingChecker.AddNumber(Content); FrameUpdate frameUpdate = Layer2(); string answer = frameUpdate.Answer; //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定 var subPanel = CompleteExpression.Substring(0, CompleteExpression.Length - answer.Length); var panel = answer; return(new FrameObject(subPanel, panel)); }
/// <summary> /// Feature:RightBracket。輸入右括號 /// </summary> /// <returns>FrameObject</returns> public FrameObject RightBracket() { return(CatchException(() => { FrameUpdate frameUpdate = OrderingChecker.RightBracket(); //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定。 FrameObject.SubPanel = CompleteExpression; FrameObject.Panel = frameUpdate.Answer; return FrameObject; })); }
/// <summary> /// Frame update /// </summary> /// <param name="update"></param> public override void Update(FrameUpdate update) { if (_raycastProperties == null) { base.Update(update); return; } _appTime = (float)update.ApplicationTime; // assume pose of parent if (Parent != null) { State.Pose = Parent.State.Pose; } _elapsedSinceLastScan += (float)update.ElapsedTime; // only retrieve raycast results every SCAN_INTERVAL. // For entities that are compute intenisve, you should consider giving them // their own task queue so they dont flood a shared queue if (_elapsedSinceLastScan > SCAN_INTERVAL) { _elapsedSinceLastScan = 0; // the LRF looks towards the negative Z axis (towards the user), not the positive Z axis // which is the default orientation. So we have to rotate its orientation by 180 degrees _raycastProperties.OriginPose.Orientation = TypeConversion.FromXNA( TypeConversion.ToXNA(State.Pose.Orientation) * xna.Quaternion.CreateFromAxisAngle(new xna.Vector3(0, 1, 0), (float)Math.PI)); // to calculate the position of the origin of the raycast, we must first rotate the LocalPose position // of the raycast (an offset from the origin of the parent entity) by the orientation of the parent entity. // The origin of the raycast is then this rotated offset added to the parent position. xna.Matrix parentOrientation = xna.Matrix.CreateFromQuaternion(TypeConversion.ToXNA(State.Pose.Orientation)); xna.Vector3 localOffset = xna.Vector3.Transform(TypeConversion.ToXNA(_sonarBox.State.LocalPose.Position), parentOrientation); _raycastProperties.OriginPose.Position = State.Pose.Position + TypeConversion.FromXNA(localOffset); _raycastResultsPort = PhysicsEngine.Raycast2D(_raycastProperties); _raycastResultsPort.Test(out _lastResults); if (_serviceNotification != null && _lastResults != null) { _serviceNotification.Post(_lastResults); } } base.Update(update); }
/// <summary> /// Feature:Unary。輸入為Setting中的單元運算子。 /// </summary> /// <param name="content">單元運算子</param> /// <returns>FrameObject</returns> public FrameObject AddUnary(char content) { return(CatchException(() => { //OrderingChecker會回傳FrameUpdate FrameUpdate frameUpdate = OrderingChecker.AddUnary(content); //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定 FrameObject.SubPanel = CompleteExpression; FrameObject.Panel = frameUpdate.Answer; return FrameObject; })); }
public void OnDispatch(FrameUpdate args) { if (toggle_console.on_pressed) { if (!Node.IsInstanceValid(node)) { node = new Console_GUI(); Scene.Tree.CurrentScene.AddChild(node); node.PauseMode = Node.PauseModeEnum.Process; update_log = true; } else { node.QueueFree(); node = null; } } }
/// <summary> /// Feature:Number。輸入為數字或小數點。 /// </summary> /// <param name="content">數字或小數點</param> /// <returns>FrameObject</returns> public FrameObject AddNumber(char content) { return(CatchException(() => { //OrderingChecker會回傳FrameUpdate FrameUpdate frameUpdate = OrderingChecker.AddNumber(content); string answer = frameUpdate.Answer; //完整運算式的刷新 CompleteExpression = frameUpdate.Refresh(CompleteExpression); //panel, subpanel設定 FrameObject.SubPanel = CompleteExpression.Substring(0, CompleteExpression.Length - answer.Length); FrameObject.Panel = answer; System.Diagnostics.Debug.WriteLine(FrameObject.Panel); return FrameObject; })); }
static void thrusterSizer(float i) { if (thrusterSize >= 20) { thrusterSize = 20; } if (thrusterSize <= 0) { thrusterSize = 0; } if (thrusterSize <= 20 && thrusterSize >= 0) { thrusterSize += i; //Debug.Log(thrusterSize); } thrusterFrame = (int)thrusterSize / 1; FrameUpdate.updateFrame(thrusterFrame); fuelLeft -= (int)(thrusterFrame / 12); //Player.Play(AnimationClip[thrusterFrame]); }
//order層 public FrameUpdate Layer2() { Feature CurrentFeature = Feature.NUMBER; if (FeatureSet.Contains(PreviousFeature)) { //FrameUpdate frameUpdate = NumberMachine.AddNumber(Content); FrameUpdate frameUpdate = Layer3(); //等號後輸入數字 if (PreviousFeature == Feature.EQUAL) { frameUpdate.RemoveLength = ExpUpdate.REMOVE_ALL; //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return(frameUpdate); } //backspace或clearerror之後的數字處理 if ((PreviousFeature == Feature.BACKSPACE || PreviousFeature == Feature.CLEAR_ERROR) && NumberField.Number == 0) { frameUpdate.RemoveLength += 1; //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return(frameUpdate); } //執行成功時記錄下這次的Cast PreviousFeature = CurrentFeature; return(frameUpdate); } else { throw new OrderException(FeatureRule.ORDER_EXCEPTION_MSG); } }
/// <summary> /// Writes a new state to the stream. /// </summary> /// <param name="state">New state</param> public void Write(SimulationState state) { serializer.Write(BlockType.FrameStart); int[] keys; #region Framestart // The first call creates the frame if (frame == null) { // Create new frame frame = new Frame(state); serializer.Write(BlockType.Frame, frame); } else { // Send frame-update FrameUpdate update = frame.GenerateUpdate(state); if (update != null) { serializer.Write(BlockType.FrameUpdate, update); } } #endregion #region Teams and ColonyStates #region ant-reset // reset alive-flag foreach (Ant ant in antList.Values) { ant.IsAlive = false; } #endregion #region marker-reset // reset alive-flag foreach (Marker marker in markerList.Values) { marker.IsAlive = false; } #endregion // Teams are static and need no update // enumerate all teams foreach (TeamState teamState in state.TeamStates) { // Check, if team is known if (teamList.ContainsKey(teamState.Id)) { // No Teamupdate needed } else { Team team = new Team(teamState); serializer.Write(BlockType.Team, team); teamList.Add(teamState.Id, team); } // ColonyStates are static and need no update // enumerate all colonies foreach (ColonyState colonyState in teamState.ColonyStates) { // Check, if colony is known if (colonyList.ContainsKey(colonyState.Id)) { // colony-update ColonyUpdate update = colonyList[colonyState.Id].GenerateUpdate(colonyState); if (update != null) { serializer.Write(BlockType.ColonyUpdate, update); } colonyList[colonyState.Id].Interpolate(); } else { // new colony Colony colony = new Colony(colonyState, teamState.Id); serializer.Write(BlockType.Colony, colony); colonyList.Add(colonyState.Id, colony); casteList.Add(colonyState.Id, new Dictionary <int, Caste>()); #region Castes // Casts are static and need no update Dictionary <int, Caste> castes = casteList[colonyState.Id]; // enumerate casts for (ushort i = 0; i < colonyState.CasteStates.Count; i++) { // Check, if caste is known if (!castes.ContainsKey(i)) { // add caste Caste caste = new Caste(colonyState.CasteStates[i]); serializer.Write(BlockType.Caste, caste); } } #endregion #region Anthills // Anthills are static and need no update // enumerate anthills foreach (AnthillState anthill in colonyState.AnthillStates) { if (!anthillList.ContainsKey(anthill.Id)) { Anthill hill = new Anthill(anthill); serializer.Write(BlockType.Anthill, hill); anthillList.Add(anthill.Id, hill); } } #endregion } #region Ants // enumerate ants foreach (AntState antState in colonyState.AntStates) { // Check, if ant is known if (antList.ContainsKey(antState.Id)) { // ant-update AntUpdate update = antList[antState.Id].GenerateUpdate(antState); if (update != null) { serializer.Write(BlockType.AntUpdate, update); } antList[antState.Id].Interpolate(); } else { // create ant Ant ant = new Ant(antState); serializer.Write(BlockType.Ant, ant); antList.Add(ant.Id, ant); } antList[antState.Id].IsAlive = true; } #endregion #region Marker // enumerate marker foreach (MarkerState markerState in colonyState.MarkerStates) { // Check, if marker is known if (markerList.ContainsKey(markerState.Id)) { // marker-update MarkerUpdate update = markerList[markerState.Id].GenerateUpdate(markerState); if (update != null) { serializer.Write(BlockType.MarkerUpdate, update); } markerList[markerState.Id].Interpolate(); } else { // create marker Marker marker = new Marker(markerState); serializer.Write(BlockType.Marker, marker); markerList.Add(markerState.Id, marker); } markerList[markerState.Id].IsAlive = true; } #endregion } } #region Ant-Cleanup // remove dead ants keys = new int[antList.Keys.Count]; antList.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { if (!antList[keys[i]].IsAlive) { serializer.Write(BlockType.AntLost, new Lost(keys[i])); antList.Remove(keys[i]); } } #endregion #region Marker-Cleanup // remove dead marker keys = new int[markerList.Keys.Count]; markerList.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { if (!markerList[keys[i]].IsAlive) { serializer.Write(BlockType.MarkerLost, new Lost(keys[i])); markerList.Remove(keys[i]); } } #endregion #endregion #region Fruit // reset alive-flag foreach (Fruit fruit in fruitList.Values) { fruit.IsAlive = false; } // enumerate fruit foreach (FruitState fruitState in state.FruitStates) { // Check, if fruit is known if (fruitList.ContainsKey(fruitState.Id)) { // fruit-update FruitUpdate update = fruitList[fruitState.Id].GenerateUpdate(fruitState); if (update != null) { serializer.Write(BlockType.FruitUpdate, update); } fruitList[fruitState.Id].Interpolate(); } else { // create fruit Fruit fruit = new Fruit(fruitState); serializer.Write(BlockType.Fruit, fruit); fruitList.Add(fruitState.Id, fruit); } fruitList[fruitState.Id].IsAlive = true; } // remove dead fruits keys = new int[fruitList.Keys.Count]; fruitList.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { if (!fruitList[keys[i]].IsAlive) { serializer.Write(BlockType.FruitLost, new Lost(keys[i])); fruitList.Remove(keys[i]); } } #endregion #region Sugar // reset alive-flag foreach (Sugar sugar in sugarList.Values) { sugar.IsAlive = false; } // enumerate sugar foreach (SugarState sugarState in state.SugarStates) { // Check, if sugar is known if (sugarList.ContainsKey(sugarState.Id)) { // sugar-update SugarUpdate update = sugarList[sugarState.Id].GenerateUpdate(sugarState); if (update != null) { serializer.Write(BlockType.SugarUpdate, update); } sugarList[sugarState.Id].Interpolate(); } else { // create sugar Sugar sugar = new Sugar(sugarState); serializer.Write(BlockType.Sugar, sugar); sugarList.Add(sugarState.Id, sugar); } sugarList[sugarState.Id].IsAlive = true; } // remove dead sugar keys = new int[sugarList.Keys.Count]; sugarList.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { if (!sugarList[keys[i]].IsAlive) { serializer.Write(BlockType.SugarLost, new Lost(keys[i])); sugarList.Remove(keys[i]); } } #endregion #region Bugs // reset alive-flag foreach (Bug bug in bugList.Values) { bug.IsAlive = false; } // enumerate bugs foreach (BugState bugState in state.BugStates) { // Check, if bug is known if (bugList.ContainsKey(bugState.Id)) { // bug-update BugUpdate update = bugList[bugState.Id].GenerateUpdate(bugState); if (update != null) { serializer.Write(BlockType.BugUpdate, update); } bugList[bugState.Id].Interpolate(); } else { // create bug Bug bug = new Bug(bugState); serializer.Write(BlockType.Bug, bug); bugList.Add(bugState.Id, bug); } bugList[bugState.Id].IsAlive = true; } // remove dead bugs keys = new int[bugList.Keys.Count]; bugList.Keys.CopyTo(keys, 0); for (int i = 0; i < keys.Length; i++) { if (!bugList[keys[i]].IsAlive) { serializer.Write(BlockType.BugLost, new Lost(keys[i])); bugList.Remove(keys[i]); } } #endregion serializer.Write(BlockType.FrameEnd); }
public override void Update(FrameUpdate update) { base.Update(update); if (_moveToActive) { bool done = true; // Check each joint and update it if necessary. for (int i = 0; i < _joints.Count; i++) { if (_joints[i].Update(_prevTime, _epsilon)) done = false; } /*// gripper is special case if (_joints[5].NeedToMove(_epsilon / 100f)) { done = false; _joints[5].UpdateCurrent(_prevTime); float jointValue = _joints[5].Current / 2; if (_joints[5].Joint != null) _joints[5].Joint.SetLinearDrivePosition(new Vector3(-jointValue, 0, 0)); if (_joints[5].Joint2 != null) _joints[5].Joint2.SetLinearDrivePosition(new Vector3(jointValue, 0, 0)); } */ if (done) { // move completed; send the completion message _moveToActive = false; _moveToResponsePort.Post(new SuccessResult()); } } _prevTime = update.ElapsedTime; }
/// <summary> /// Frame update /// </summary> /// <param name="update"></param> public override void Update(FrameUpdate update) { if (_raycastProperties == null) { base.Update(update); return; } _appTime = (float)update.ApplicationTime; // assume pose of parent if (Parent != null) State.Pose = Parent.State.Pose; _elapsedSinceLastScan += (float)update.ElapsedTime; // only retrieve raycast results every SCAN_INTERVAL. // For entities that are compute intenisve, you should consider giving them // their own task queue so they dont flood a shared queue if (_elapsedSinceLastScan > SCAN_INTERVAL) { _elapsedSinceLastScan = 0; // the LRF looks towards the negative Z axis (towards the user), not the positive Z axis // which is the default orientation. So we have to rotate its orientation by 180 degrees _raycastProperties.OriginPose.Orientation = TypeConversion.FromXNA( TypeConversion.ToXNA(State.Pose.Orientation) * xna.Quaternion.CreateFromAxisAngle(new xna.Vector3(0, 1, 0), (float)Math.PI)); // to calculate the position of the origin of the raycast, we must first rotate the LocalPose position // of the raycast (an offset from the origin of the parent entity) by the orientation of the parent entity. // The origin of the raycast is then this rotated offset added to the parent position. xna.Matrix parentOrientation = xna.Matrix.CreateFromQuaternion(TypeConversion.ToXNA(State.Pose.Orientation)); xna.Vector3 localOffset = xna.Vector3.Transform(TypeConversion.ToXNA(_sonarBox.State.LocalPose.Position), parentOrientation); _raycastProperties.OriginPose.Position = State.Pose.Position + TypeConversion.FromXNA(localOffset); _raycastResultsPort = PhysicsEngine.Raycast2D(_raycastProperties); _raycastResultsPort.Test(out _lastResults); if (_serviceNotification != null && _lastResults != null) { _serviceNotification.Post(_lastResults); } } base.Update(update); }
/// <summary> /// Reads the next block out of stream. /// </summary> /// <param name="block">the found block</param> /// <returns>type of found block</returns> public BlockType Read(out ISerializable block) { BlockType blockType = (BlockType)stream.ReadByte(); block = null; switch (blockType) { case BlockType.Ant: block = new Ant(this); break; case BlockType.Anthill: block = new Anthill(this); break; case BlockType.AnthillLost: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.AnthillUpdate: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.AntLost: block = new Lost(this); break; case BlockType.AntUpdate: block = new AntUpdate(this); break; case BlockType.Bug: block = new Bug(this); break; case BlockType.BugLost: block = new Lost(this); break; case BlockType.BugUpdate: block = new BugUpdate(this); break; case BlockType.Team: block = new Team(this); break; case BlockType.TeamLost: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.TeamUpdate: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.Colony: block = new Colony(this); break; case BlockType.ColonyLost: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.ColonyUpdate: block = new ColonyUpdate(this); break; case BlockType.Frame: block = new Frame(this); break; case BlockType.StreamEnd: break; case BlockType.FrameLost: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.FrameUpdate: block = new FrameUpdate(this); break; case BlockType.Fruit: block = new Fruit(this); break; case BlockType.FruitLost: block = new Lost(this); break; case BlockType.FruitUpdate: block = new FruitUpdate(this); break; case BlockType.Marker: block = new Marker(this); break; case BlockType.MarkerLost: block = new Lost(this); break; case BlockType.MarkerUpdate: block = new MarkerUpdate(this); break; case BlockType.Caste: block = new Caste(this); break; case BlockType.CasteLost: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.CasteUpdate: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); case BlockType.Sugar: block = new Sugar(this); break; case BlockType.SugarLost: block = new Lost(this); break; case BlockType.SugarUpdate: block = new SugarUpdate(this); break; case BlockType.FrameStart: break; case BlockType.FrameEnd: break; default: throw new InvalidOperationException(string.Format(Resource.AntvideoSerializerInvalidBlockType, blockType)); } return(blockType); }
/// <summary> /// 更新命令 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void grdList_Execute(object source, DataGridCommandEventArgs e) { try { string UpdateGuid = grdList.DataKeys[e.Item.ItemIndex].ToString(); DataView dv = new FrameUpdate().SelectUpdate(UpdateGuid); if (dv.Count > 0) { string PathSet = Server.MapPath(dv[0]["FILEPATH"].ToString()) + "PathSet.txt"; //读取配置文件 PathSet.txt string PathConfig = ""; if (File.Exists(PathSet)) { StreamReader reader = new StreamReader(PathSet, System.Text.Encoding.Default); PathConfig = reader.ReadToEnd().ToLower(); reader.Dispose(); } else { ShowJsMessage("该更新缺乏路径配置文件,请手工更新!"); return; } //具体的信息格式为:aa.dll=/bin/; bb.aspx=/ccc/; string[] FileList = dv[0]["FILENAMELIST"].ToString().Split(';'); for (int i = 0; i < FileList.Length; i++) { string FileName = FileList[i].Trim().ToLower(); if (FileName != "" && PathConfig.IndexOf(FileName) != -1) { string FromPath = Server.MapPath(dv[0]["FILEPATH"].ToString()) + FileList[i].Trim(); int begin = PathConfig.IndexOf("/", PathConfig.IndexOf(FileName) + 1); int end = PathConfig.IndexOf("/", begin + 1); string ToPath = PathConfig.Substring(begin, end - begin + 1); ToPath = Server.MapPath(ToPath); if(!Directory.Exists(ToPath)) //如果目录不存在,则创建目录 { Directory.CreateDirectory(ToPath); } ToPath = ToPath + FileList[i].Trim(); //具体文件名 File.Copy(FromPath, ToPath, true); } } new FrameUpdate().UpdateStatus(UpdateGuid); ShowJsMessage("更新完成,请重新刷新!"); } } catch (Exception a) { ShowJsMessage(a.Message); } }
/// <summary> /// 从数据库中获取数据并绑定 /// </summary> protected void Refresh() { DataView dv = new FrameUpdate().SelectUpdate(); for (int i = 0; i < dv.Count; i++) { if (dv[i]["ISEXECUTED"].ToString() == "N") { dv[i]["ISEXECUTED"] = "<span style='color:Red'>否</span>"; } else dv[i]["ISEXECUTED"] = "是"; dv[i]["FILENAMELIST"] = dv[i]["FILENAMELIST"].ToString().Replace(";","<br />"); } grdList.DataSource = dv; grdList.DataBind(); CallJsFun("ChangeColor();"); }
/// <summary> /// Updates pose for our entity. We override default implementation /// since we control our own rendering when no file mesh is supplied, which means /// we dont need world transform updates /// </summary> /// <param name="update"></param> public override void Update(FrameUpdate update) { float left = _leftWheel.Wheel.AxleSpeed + _leftTargetVelocity; float right = _rightWheel.Wheel.AxleSpeed + _rightTargetVelocity; if (Math.Abs(left) > 0.1) { if (left > 0) { _leftWheel.Wheel.AxleSpeed -= SPEED_DELTA; } else { _leftWheel.Wheel.AxleSpeed += SPEED_DELTA; } } if (Math.Abs(right) > 0.1) { if (right > 0) { _rightWheel.Wheel.AxleSpeed -= SPEED_DELTA; } else { _rightWheel.Wheel.AxleSpeed += SPEED_DELTA; } } // update state for us and all the shapes that make up the rigid body PhysicsEntity.UpdateState(true); ///////////////////////////////////////////////////////////// // TT May-2007 // Handle RotateDegrees if (IsRotating) { double current; double diff; // Get the current heading current = this.Rotation.Y; // This is tricky because the angle wraps around // so it is always in the range 0-360. // This is probably unnecessary because the Simulator // does it for us, but just to be sure ... while (current > 360) current -= 360; while (current < 0) current += 360; // Figure out how far we have turned // NOTE: You cannot simply compare the current heading // with a target angle because the simulation moves in // steps and might skip over the target angle. diff = current - TurnStartDegrees; if (TurnAngle > 0) { if (diff < 0) diff += 360; if (diff >= TurnAngle) IsRotating = false; } else { if (diff > 0) diff -= 360; if (diff <= TurnAngle) IsRotating = false; } if (!IsRotating) { SetMotorTorque(0, 0); SetVelocity(0); // This is overkill, but AllStop does it! // This is cheating! Eliminates inertia _rightWheel.Wheel.AxleSpeed = 0; _leftWheel.Wheel.AxleSpeed = 0; IsRotating = false; } } // TT May-2007 // Handle DriveDistance if (IsTranslating) { double dist; // Calculate the SQUARED distance so far // This avoids taking a square root every time dist = (this.Position.X - TranslateStartX) * (this.Position.X - TranslateStartX) + (this.Position.Z - TranslateStartZ) * (this.Position.Z - TranslateStartZ); // Check if we have reached the end of the travel if (dist >= TranslateDistanceSquared) { SetMotorTorque(0, 0); SetVelocity(0); // This is overkill, but AllStop does it! // This is cheating! Eliminates inertia _rightWheel.Wheel.AxleSpeed = 0; _leftWheel.Wheel.AxleSpeed = 0; IsTranslating = false; } } ///////////////////////////////////////////////////////////// // update entities in fields _leftWheel.Update(update); _rightWheel.Update(update); // sim engine will update children if (State.Assets.Mesh != null) { base.Update(update); } }
/// <summary> /// Reads a new simulation-state out of stream. /// </summary> /// <returns>New simulation-state or null, if stream is over</returns> public SimulationState Read() { // if stream is at his end, return null if (complete) { return(null); } // first block have to be a frame-start ISerializable block; BlockType blockType = serializer.Read(out block); // detect stream-end if (blockType == BlockType.StreamEnd) { complete = true; return(null); } // unexpected block-type if (blockType != BlockType.FrameStart) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resource.AntvideoReaderInvalidBlockType, blockType)); } // block-loop while (blockType != BlockType.FrameEnd) { blockType = serializer.Read(out block); switch (blockType) { case BlockType.Ant: Ant ant = (Ant)block; antList.Add(ant.Id, ant); break; case BlockType.Anthill: Anthill anthill = (Anthill)block; anthillList.Add(anthill.Id, anthill); break; case BlockType.AntLost: Lost antLost = (Lost)block; antList.Remove(antLost.Id); break; case BlockType.AntUpdate: AntUpdate antUpdate = (AntUpdate)block; antList[antUpdate.Id].Update(antUpdate); break; case BlockType.Bug: Bug bug = (Bug)block; bugList.Add(bug.Id, bug); break; case BlockType.BugLost: Lost bugLost = (Lost)block; bugList.Remove(bugLost.Id); break; case BlockType.BugUpdate: BugUpdate bugUpdate = (BugUpdate)block; bugList[bugUpdate.Id].Update(bugUpdate); break; case BlockType.Caste: Caste caste = (Caste)block; casteList[caste.ColonyId].Add(caste.Id, caste); break; case BlockType.Team: Team team = (Team)block; teamList.Add(team.Id, team); colonyList.Add(team.Id, new Dictionary <int, Colony>()); break; case BlockType.Colony: Colony colony = (Colony)block; colonyList[colony.TeamId].Add(colony.Id, colony); casteList.Add(colony.Id, new Dictionary <int, Caste>()); break; case BlockType.ColonyUpdate: ColonyUpdate colonyUpdate = (ColonyUpdate)block; colonyList[colonyUpdate.TeamId][colonyUpdate.Id].Update(colonyUpdate); break; case BlockType.Frame: frame = (Frame)block; break; case BlockType.FrameUpdate: FrameUpdate frameUpdate = (FrameUpdate)block; frame.Update(frameUpdate); break; case BlockType.Fruit: Fruit fruit = (Fruit)block; fruitList.Add(fruit.Id, fruit); break; case BlockType.FruitLost: Lost fruitLost = (Lost)block; fruitList.Remove(fruitLost.Id); break; case BlockType.FruitUpdate: FruitUpdate fruitUpdate = (FruitUpdate)block; fruitList[fruitUpdate.Id].Update(fruitUpdate); break; case BlockType.Marker: Marker marker = (Marker)block; markerList.Add(marker.Id, marker); break; case BlockType.MarkerLost: Lost markerLost = (Lost)block; markerList.Remove(markerLost.Id); break; case BlockType.MarkerUpdate: MarkerUpdate markerUpdate = (MarkerUpdate)block; markerList[markerUpdate.Id].Update(markerUpdate); break; case BlockType.Sugar: Sugar sugar = (Sugar)block; sugarList.Add(sugar.Id, sugar); break; case BlockType.SugarLost: Lost sugarLost = (Lost)block; sugarList.Remove(sugarLost.Id); break; case BlockType.SugarUpdate: SugarUpdate sugarUpdate = (SugarUpdate)block; sugarList[sugarUpdate.Id].Update(sugarUpdate); break; } } // Detect streamend if ((BlockType)serializer.Peek() == BlockType.StreamEnd) { complete = true; } // Interpolate all elements and buildup state frame.Interpolate(); SimulationState state = frame.GenerateState(); foreach (Bug bug in bugList.Values) { bug.Interpolate(); state.BugStates.Add(bug.GenerateState()); } foreach (Fruit fruit in fruitList.Values) { fruit.Interpolate(); state.FruitStates.Add(fruit.GenerateState()); } foreach (Sugar sugar in sugarList.Values) { sugar.Interpolate(); state.SugarStates.Add(sugar.GenerateState()); } foreach (Team team in teamList.Values) { TeamState teamState = team.GenerateState(); state.TeamStates.Add(teamState); foreach (Colony colony in colonyList[team.Id].Values) { colony.Interpolate(); ColonyState colonyState = colony.GenerateState(); teamState.ColonyStates.Add(colonyState); foreach (Caste caste in casteList[colony.Id].Values) { colonyState.CasteStates.Add(caste.GenerateState()); } foreach (Anthill anthill in anthillList.Values) { if (anthill.ColonyId == colony.Id) { colonyState.AnthillStates.Add(anthill.GenerateState()); } } foreach (Ant ant in antList.Values) { if (ant.ColonyId == colony.Id) { ant.Interpolate(); colonyState.AntStates.Add(ant.GenerateState()); } } foreach (Marker marker in markerList.Values) { if (marker.ColonyId == colony.Id) { marker.Interpolate(); colonyState.MarkerStates.Add(marker.GenerateState()); } } } } // deliver return(state); }
///// <summary> ///// 回傳此功能前面可以接的功能集 ///// </summary> ///// <returns>前面可以接的功能集</returns> //public abstract HashSet<Type> LegitPreviousType(); ///// <summary> ///// 回傳此功能後面可以接的功能集 ///// </summary> ///// <returns>後面可以接的功能集</returns> //public abstract HashSet<Type> LegitAfterWardType(); /// <summary> /// 依功能回傳畫面物件 /// </summary> /// <param name="boardObject">面板物件</param> /// <param name="frameUpdate">畫面更新</param> /// <returns>畫面物件</returns> public abstract FrameObject GetFrameObject(BoardObject boardObject, FrameUpdate frameUpdate);
/// <summary> /// Custom update that follows the entity the PursuitCamera is targeting /// </summary> /// <param name="update"></param> public override void Update(FrameUpdate update) { if (Target != null) { // // vector to the camera, used for computing the new position // var entityToCamera = Location - Target.Position; var distance = entityToCamera.Length(); if (distance > 0.1) { float scale = 1; // // scale the vector if the distance is outside the bounds // if (distance > MaxDistance) { scale = MaxDistance / distance; } else if (distance < MinDistance) { scale = MinDistance / distance; } var scaled = xna.Vector3.Multiply(entityToCamera, scale); // // set the new camera position, although the altitude will be off. // var newCamera = Target.Position + scaled; // // constrain the altitude. // newCamera.Y = Target.Position.Y + Altitude; if (PreventOcclusion) { // // rotate this new position around the target position 32 times. // in each iteration perform an occlusion test. Find the direction // that is furthest from an occluded direction (i.e. is in the // most free space) // var clearest = FindClearest(newCamera, Target.Position, 32); // // interpolate these two positions together. The weight is given // predominantly to the first position, this weighting is scaled // by the elapsed frame time to try and keep camera motion approximately // constant. for example at 50 fps, the weight is 2%, at 10 fps the // weight is 10% etc. // newCamera = xna.Vector3.Lerp( newCamera, clearest, (float)update.ElapsedTime); } base.SetViewParameters(newCamera, Target.Position); } } base.Update(update); }