void setRopeLengthRelative(float value) { limitHinge(PendulumWeight.GetComponent <HingeJoint>(), 0); Vector3 currPos = PendulumWeight.transform.position; var obj = PendulumWeight.transform.Find("weight_obj"); var pos = obj.transform.position; float newVal = Math.Max(-RopeMaxLength, -ropeLength + value); newVal = Math.Min(newVal, -RopeMinLength); ropeLength = -newVal; pos.Set(transform.position.x, transform.position.y - ropeLength, transform.position.z); obj.transform.position = pos; /* * double theoretical_freq = 1 / (2 * Math.PI) * Math.Sqrt(Physics.gravity.magnitude / ropeLength); * var ec = GameEventBuilder.EnvironmentVariable( * this.name, * "theoretical_frequency", * theoretical_freq * ).Add( * GameEventBuilder.EnvironmentVariable( * this.name, * "theoretical_period", * 1 / theoretical_freq * ) * ); */ GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("operation", "ropelength_change") ).Feedback ); }
private void checkKeyboardInput() { if (!Input.anyKeyDown) { return; } if (GuiPendulum.isFocused()) { return; } if (Input.GetKeyDown(KeyCode.W)) { } if (Input.GetKeyDown(KeyCode.S)) { } if (Input.GetKeyDown(KeyCode.A)) { weight -= WeightChangeStepSize; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("pendulum_weight", "decrease") ).Feedback ); } if (Input.GetKeyDown(KeyCode.D)) { weight += WeightChangeStepSize; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("pendulum_weight", "increase") ).Feedback ); } if (Input.GetKeyDown(KeyCode.Q)) { Stopwatch.SendMessage("SWStart"); } if (Input.GetKeyDown(KeyCode.E)) { Stopwatch.SendMessage("SWStop"); } if (Input.GetKeyDown(KeyCode.Space)) { ExitExperiment(); } }
private void CalculatorButtonPressed(Calculator.CalculatorButtonPressedEvent evt) { if (evt.Name != "enter") { return; } var ge = GameEventBuilder .EnvironmentVariable(name, "calculated_value", evt.CurrentNumber) .Add(GameEventBuilder.UseObject("operation", "submit-value")); var res = AssessmentManager.Instance.Send(ge); GuiPendulum.ShowFeedback(res.Feedback); }
public void Update() { HingeJoint joint = PendulumWeight.GetComponent <HingeJoint>(); joint.GetComponent <Rigidbody>().WakeUp(); if (Input.GetMouseButtonUp(0) && mouseDown) { Debug.Log("Sending Release action"); IterationResult res = AssessmentManager.Instance.Send(GameEventBuilder.UseObject("operation", "release")); GuiPendulum.ShowFeedback(res.Feedback); mouseDown = false; joint.useLimits = false; //AssessmentManager.Instance.PrintSummary(); } else if (Input.GetMouseButtonDown(0) || mouseDown) { if (!mouseDown) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.name == PendulumWeight.name) { mouseDown = true; mouseStart = Input.mousePosition; } else if (hit.transform.name == Stopwatch.name) { if (Stopwatch.GetComponent <StopWatch>().isRunning) { Stopwatch.SendMessage("SWStop"); } else { Stopwatch.SendMessage("SWStart"); } } else if (hit.transform.name == SlowMoObject.name) { if (slow) { Time.timeScale = 1.0f; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("timelaps", "deactivate") ).Feedback ); } else { Time.timeScale = 0.2f; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("timelaps", "activate") ).Feedback ); } Time.fixedDeltaTime = 0.02F * Time.timeScale; slow = !slow; } } } if (mouseDown) { //relative mouse movement / (scaling factor for easy use) var angle = ((mouseStart.x - Input.mousePosition.x) / (ropeLength * 10)); //Everything above 140 degrees seems to freak out unity enormously, just don't allow it angle = Math.Min(Math.Max(-140f, angle), 140f); limitHinge(joint, angle); } } else if (Input.GetMouseButtonDown(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.name == Stopwatch.name) { Stopwatch.SendMessage("SWReset"); } } } if (Input.GetAxis("Mouse ScrollWheel") > 0) { setRopeLengthRelative(RopeLengthChangeStepSize); } else if (Input.GetAxis("Mouse ScrollWheel") < 0) { setRopeLengthRelative(-RopeLengthChangeStepSize); } checkKeyboardInput(); assertPosition(); drawRopeAndAngle(); adjustWeight(); setText(); }
private void StopWatchStop(StopWatch.StopWatchEvent evt) { var res = AssessmentManager.Instance.Send(GameEventBuilder.UseObject("operation", "sw-stop")); GuiPendulum.ShowFeedback(res.Feedback); }