private void WindowsManager_Event(string cmd, object o) { try { Log.Debug("Window command received :" + cmd); if (cmd != WindowsCmdConsts.Next_Image && cmd != WindowsCmdConsts.Prev_Image && cmd != WindowsCmdConsts.Select_Image && !cmd.StartsWith("Zoom")) { ServiceProvider.Analytics.Command(cmd, o as string); } if (cmd == CmdConsts.All_Close) { ServiceProvider.WindowsManager.Event -= WindowsManager_Event; ServiceProvider.Analytics.Stop(); ServiceProvider.Database.EndEvent(EventType.App); if (ServiceProvider.Settings != null) { ServiceProvider.Settings.Save(ServiceProvider.Settings.DefaultSession); ServiceProvider.Settings.Save(); if (ServiceProvider.Trigger != null) { ServiceProvider.Trigger.Stop(); } } ServiceProvider.ScriptManager.Stop(); ServiceProvider.DeviceManager.CloseAll(); Thread.Sleep(1000); Dispatcher.Invoke(new Action(() => Current.Shutdown())); } switch (cmd) { case CmdConsts.Capture: Thread thread = new Thread(new ThreadStart(CameraHelper.Capture)); thread.Start(); break; case CmdConsts.CaptureNoAf: CameraHelper.CaptureNoAf(); break; case CmdConsts.CaptureAll: CameraHelper.CaptureAll(0); break; case CmdConsts.NextSeries: if (ServiceProvider.Settings != null) { ServiceProvider.Settings.DefaultSession.Series++; } break; } ICameraDevice device = ServiceProvider.DeviceManager.SelectedCameraDevice; if (device != null && device.IsConnected) { switch (cmd) { //case CmdConsts.ResetDevice: // device.ResetDevice(); // break; case CmdConsts.NextAperture: if (device.FNumber != null) { device.FNumber.NextValue(); } break; case CmdConsts.PrevAperture: if (device.FNumber != null) { device.FNumber.PrevValue(); } break; case CmdConsts.NextIso: if (device.IsoNumber != null) { device.IsoNumber.NextValue(); } break; case CmdConsts.PrevIso: if (device.IsoNumber != null) { device.IsoNumber.PrevValue(); } break; case CmdConsts.NextShutter: if (device.ShutterSpeed != null) { device.ShutterSpeed.NextValue(); } break; case CmdConsts.PrevShutter: if (device.ShutterSpeed != null) { device.ShutterSpeed.PrevValue(); } break; case CmdConsts.NextWhiteBalance: if (device.WhiteBalance != null) { device.WhiteBalance.NextValue(); } break; case CmdConsts.PrevWhiteBalance: if (device.WhiteBalance != null) { device.WhiteBalance.PrevValue(); } break; case CmdConsts.NextExposureCompensation: if (device.ExposureCompensation != null) { device.ExposureCompensation.NextValue(); } break; case CmdConsts.PrevExposureCompensation: if (device.ExposureCompensation != null) { device.ExposureCompensation.PrevValue(); } break; case CmdConsts.NextCamera: ServiceProvider.DeviceManager.SelectNextCamera(); break; case CmdConsts.PrevCamera: ServiceProvider.DeviceManager.SelectPrevCamera(); break; } } } catch (Exception ex) { Log.Error("Error processing comand", ex); } }
/// <summary> /// Entry point of program /// </summary> /// <param name="args"></param> /// <returns></returns> static void Main(string[] args) { Console.WriteLine("Skeletal Detector .NetCore 3.0 Console App: Please place your body in front of the camera"); Task.Run(async() => { var skillDescriptor = new SkeletalDetectorDescriptor(); var skill = await skillDescriptor.CreateSkillAsync() as SkeletalDetectorSkill; var skillDevice = skill.Device; Console.WriteLine("Running Skill on : " + skillDevice.ExecutionDeviceKind.ToString() + ": " + skillDevice.Name); var binding = await skill.CreateSkillBindingAsync() as SkeletalDetectorBinding; m_cameraHelper = await CameraHelper.CreateCameraHelperAsync( // Register a failure callback new CameraHelper.CameraHelperFailedHandler(message => { var failureException = new Exception(message); Console.WriteLine(message); Environment.Exit(failureException.HResult); }), // Register the main loop callback to handlke each frame as they come in new CameraHelper.NewFrameArrivedHandler(async(videoFrame) => { try { // Process 1 frame at a time, if busy return right away if (0 == Interlocked.Exchange(ref m_lock, 1)) { m_evalPerfStopwatch.Restart(); // Update input image and run the skill against it await binding.SetInputImageAsync(videoFrame); var inputBindTime = (float)m_evalPerfStopwatch.ElapsedTicks / Stopwatch.Frequency * 1000f; m_evalPerfStopwatch.Restart(); await skill.EvaluateAsync(binding); var detectionRunTime = (float)m_evalPerfStopwatch.ElapsedTicks / Stopwatch.Frequency * 1000f; m_evalPerfStopwatch.Stop(); // Display bind and eval time string outText = $"bind: {inputBindTime.ToString("F2")}ms, eval: {detectionRunTime.ToString("F2")}ms | "; if (binding.Bodies == null) { // If no face found, hide the rectangle in the UI outText += "No body found"; } else // Display the objects detected on the console { outText += $"Found {binding.Bodies.Count} bodies:"; for (int i = 0; i < binding.Bodies.Count; i++) { outText += $"<-B{i + 1}->"; var result = binding.Bodies[i]; foreach (var limb in result.Limbs) { outText += $"{limb.Joint1.Label}-{limb.Joint2.Label}|"; } } } Console.Write("\r" + outText); // Release the lock Interlocked.Exchange(ref m_lock, 0); } } catch (Exception e) { Console.WriteLine("Error:: " + e.Message.ToString() + e.TargetSite.ToString() + e.Source.ToString() + e.StackTrace.ToString()); Environment.Exit(e.HResult); } })); }).Wait(); Console.WriteLine("\nPress Any key to stop\n\n"); var key = Console.ReadKey(); Console.WriteLine("\n\n\nExiting...\n\n\n"); m_cameraHelper.CleanupAsync().Wait(); }
void snapToMouse() { Vector3 position = CameraHelper.getCursorPosition(); transform.position = new Vector3(position.x, position.y, transform.position.z) + (Vector3)grabOffset; }
public void Render(Vector3 Origin, int drawLayer = 8) { Render(CameraHelper.Main(), Origin, drawLayer); }
void Update() { switch (state) { case (State.Waiting): if (Input.GetMouseButtonDown(0) && CameraHelper.isMouseOver(collide)) { state = State.Grabbed; cursorOffset = (Vector2)transform.position - (Vector2)CameraHelper.getCursorPosition(); snapToMouse(); animator.enabled = false; head.transform.localScale = initialScale; backString.gameObject.SetActive(false); audio.Play(); audio.pitch = getStretchPitch(); updateAudioPan(); } break; case (State.Grabbed): Vector2 diff = (Vector2)initialPosition - (Vector2)transform.position; transform.rotation = Quaternion.Euler(0f, 0f, .5f * diff.getAngle() * Mathf.Lerp(0f, 1f, Mathf.Abs(diff.y)) * Mathf.Lerp(0f, 1f, diff.x)); if (!Input.GetMouseButton(0)) { audio.Stop(); //audio.pitch = Time.timeScale; if (diff.magnitude > 0f) { rigidThing.isKinematic = false; rigidThing.velocity = diff * flingSpeedMult; rigidThing.gravityScale = 0f; state = State.Flinging; updateAudioPan(); audio.pitch -= .5f * Time.timeScale; audio.volume = (getStretchPitch() / Time.timeScale) - .75f; audio.PlayOneShot(launchClip); head.GetComponent <Vibrate>().vibrateOn = false; } else { state = State.Waiting; animator.enabled = true; } } else { snapToMouse(); audio.pitch = getStretchPitch(); updateAudioPan(); if (transform.position.x > 3.3f) { state = State.Broken; rigidThing.isKinematic = false; rigidThing.velocity = brokenVelocity; rigidThing.gravityScale = brokenGravity; MicrogameController.instance.setVictory(false, true); audio.Stop(); updateAudioPan(); audio.volume = 1f; audio.pitch = Time.timeScale; audio.PlayOneShot(breakClip); } } tiltSlingShot(); break; case (State.Flinging): Vector2 originDiff = (Vector2)initialPosition - (Vector2)transform.position; tiltSlingShot(); if (originDiff.magnitude < rigidThing.velocity.magnitude * 1.5f * Time.deltaTime) { leftString.gameObject.SetActive(false); rightString.gameObject.SetActive(false); rigidThing.gravityScale = flingGravity; state = State.Flung; setSlingshotAngle(0f); backString.gameObject.SetActive(true); } //transform.Translate((Vector3)MathHelper.getVectorFromAngle(flingAngle, flingSpeed * Time.deltaTime)); break; case (State.Flung): updateAudioPan(); if (!MicrogameController.instance.getVictory() && rigidThing.velocity.x > 0f) { transform.rotation = Quaternion.Euler(0f, 0f, rigidThing.velocity.getAngle() * .5f); } if (transform.position.x > lossX || (rigidThing.velocity.y < 0f && transform.position.y < lossY)) { MicrogameController.instance.getTraits().failureVoiceDelay = 0f; MicrogameController.instance.setVictory(false, true); enabled = false; } break; case (State.Broken): rigidThing.MoveRotation(rigidThing.rotation + (brokenRotateSpeed * 5f * Time.deltaTime)); break; default: break; } }
public CameraVM(CaptureElement previewControl) { Camera = new CameraHelper(previewControl); Camera.InitializeCameraAsync(); Uslikaj = new RelayCommand(uslikaj, (object parametar) => true); }
void OnTap(TapGesture gesture) { m_Player.MoveTo(gesture.Position); Debug.Log("tap Screen pos:" + gesture.Position); Debug.Log("tap Obj pos:" + CameraHelper.ScreenPosToBackgroundPos(gesture.Position)); }
public void Render() { if (Ring == null) { return; } if (Ring.RingSegmentMesh == null) { return; } if (Ring.RingMaterial == null) { return; } var SegmentTRS = Matrix4x4.TRS(Ring.transform.position, transform.rotation, Vector3.one); Graphics.DrawMesh(Ring.RingSegmentMesh, SegmentTRS, Ring.RingMaterial, Ring.planetoid.DrawLayer, CameraHelper.Main()); }
// move sight gameObject to cursor Position void moveSightToMousePosition() { Vector2 mousePosition = CameraHelper.getCursorPosition(); transform.position = mousePosition; }
// cast CircleCast and destroy every meteor which collider was captured by the CircleCast void CastRay() { var position = new Vector2(transform.position.x, transform.position.y); var radius = GetComponent <CircleCollider2D>().radius; RaycastHit2D[] colliders = Physics2D.CircleCastAll(position, radius, new Vector2(0, 0)); foreach (RaycastHit2D r in colliders) { var objCollider = r.collider; if (objCollider.name.Contains("Meteor")) { var objScript = objCollider.gameObject.GetComponent <FlanGrab_Meteor_BehaviourScript>(); objScript.destroyMeteor(); MicrogameController.instance.playSFX(hitClip, AudioHelper.getAudioPan(CameraHelper.getCursorPosition().x) * .75f); return; } } MicrogameController.instance.playSFX(missClip, AudioHelper.getAudioPan(CameraHelper.getCursorPosition().x) * .75f); }
protected override void Draw() { #if UNITY_EDITOR if (UnityEditor.SceneView.currentDrawingSceneView != null) { return; //Do not draw at Scene tab in editor. } #endif for (int i = 0; i < Planet.Quads.Count; i++) { var q = Planet.Quads[i]; if (q.Generated && q.ShouldDraw) { var lineColor = Color.blue; if (!useColorPerMainQuad) { lineColor = Color.blue; } else { colorsForQuad.ForEach(delegate(ColorForQuad c) { if (q.Position == c.quadPosition) { lineColor = c.color; } }); } if (useLODCriticalColoring) { if (q.LODLevel == q.Planetoid.LODMaxLevel) { lineColor = Color.white; } } var ORDER = new[, ] { { 1, 0 }, { 2, 3 }, { 0, 2 }, { 3, 1 } }; var verts = q.QuadAABB.AABB; //q.GetVolumeBox(q.Planetoid.TerrainMaxHeight * 3); if (verts == null) { return; } GL.PushMatrix(); GL.LoadIdentity(); GL.MultMatrix(CameraHelper.Main().worldToCameraMatrix *q.Planetoid.OriginTransform.localToWorldMatrix); GL.LoadProjectionMatrix(CameraHelper.Main().projectionMatrix); lineMaterial.renderQueue = 5000; lineMaterial.SetPass(0); GL.Begin(GL.LINES); GL.Color(lineColor); for (byte j = 0; j < 4; j++) { //Draw bottom quad GL.Vertex3((float)verts[ORDER[j, 0]].x, (float)verts[ORDER[j, 0]].y, (float)verts[ORDER[j, 0]].z); GL.Vertex3((float)verts[ORDER[j, 1]].x, (float)verts[ORDER[j, 1]].y, (float)verts[ORDER[j, 1]].z); //Draw top quad GL.Vertex3((float)verts[ORDER[j, 0] + 4].x, (float)verts[ORDER[j, 0] + 4].y, (float)verts[ORDER[j, 0] + 4].z); GL.Vertex3((float)verts[ORDER[j, 1] + 4].x, (float)verts[ORDER[j, 1] + 4].y, (float)verts[ORDER[j, 1] + 4].z); //Draw verticals GL.Vertex3((float)verts[ORDER[j, 0]].x, (float)verts[ORDER[j, 0]].y, (float)verts[ORDER[j, 0]].z); GL.Vertex3((float)verts[ORDER[j, 0] + 4].x, (float)verts[ORDER[j, 0] + 4].y, (float)verts[ORDER[j, 0] + 4].z); } GL.End(); GL.PopMatrix(); } } }
void grab(Collider2D other) { grabbed = true; foreach (var obj in enableOnGrab) { obj.SetActive(true); } foreach (var obj in disableOnGrab) { obj.SetActive(false); } var otherGrabbable = other != null?other.GetComponent <MouseGrabbable>() : null; if (otherGrabbable != null) { //otherGrabbable.grabbed = false; letterHitBoxGrabbable.grabbed = true; } letterHitBoxGrabbable.enabled = true; if (!grabAtStart) { MicrogameController.instance.playSFX(grabClip, panStereo: AudioHelper.getAudioPan(CameraHelper.getCursorPosition().x)); } }
/* * void Start() { * // NoteFactory.CreateCircle(new CircleProperty()); * StartCoroutine(RunLineIntro()); * // StartCoroutine(RunShapes()); * StartCoroutine(RunSquareBeats()); * StartCoroutine(RunHorizontalLines()); * StartCoroutine(RunDiagonalLines()); * StartCoroutine(RunRisingGraph()); * StartCoroutine(RunCamera()); * StartCoroutine(RunCameraZoom()); * //StartCoroutine(RunCameraPosition()); * // * StartCoroutine(RunCircles()); * } */ IEnumerator RunCircles() { Color[] colors = { orange, red, purple }; System.Action MakeCircle = () => { var randomColor = Color.Lerp(peach, blue, Random.Range(0.0f, 0.5f)); var diameter = CameraHelper.Height * Random.Range(0.7f, 0.8f); var cp = new CircleProperty(color: randomColor, diameter: diameter, center: CameraHelper.RandomPositionNearCenter(diameter / 2)); var anim = NoteFactory.CreateCircle(cp); Keyframe[] kff = KeyframeHelper.CreateKeyframes( 0, 0, Beat * 4, 1, Beat * 6, 1, Beat * 8, 0 ); anim.DestroyIn(Beat * 9); anim.AddAnimationCurve(AnimationKeyPath.Opacity, new AnimationCurve(kff)); }; // until measure 40 foreach (var rest in Loop(64, 0, 2, 0)) { MakeCircle(); yield return(rest); } }
public void Render(int drawLayer = 8) { Render(CameraHelper.Main(), drawLayer); }
/// <summary> /// Initializes a new UserProfileObject with relevant information /// </summary> public UserProfileObject(Visitor visitor, CameraHelper webcamHelper) { Visitor = visitor; WebcamHelper = webcamHelper; }
public void Update() { UpdateNode(); if (ViewPortPosition.z > 0) { if (Atmosphere == null) { return; } Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, SunGlareMaterial, 10, CameraHelper.Main(), 0, Atmosphere.planetoid.QuadAtmosphereMPB, false, false); } }
public void Render() { Graphics.DrawMesh(StarfieldMesh, transform.localToWorldMatrix, StarfieldMaterial, 0, CameraHelper.Main(), 0, null, false, false); }
private static void CustomTimeBarCityEventClick(object sender, CustomTimeBarClickEventArgs e) { CameraHelper.NavigateToBuilding(e.CityEventBuildingId, true); }
public void Render() { if (CloudsphereMesh == null) { return; } var CloudsTRS = Matrix4x4.TRS(planetoid.OriginTransform.position, transform.rotation, Vector3.one * (Radius + Height)); Graphics.DrawMesh(CloudsphereMesh, CloudsTRS, CloudMaterial, planetoid.DrawLayer, CameraHelper.Main(), 0, planetoid.MPB); }
// Handle dragging and dropping the fragments void HandleDragging() { // Grabbing a fragment if (grabbedFragmentGroup == null && Input.GetMouseButtonDown(0)) { // Get an array of all the fragments under the cursor Ray mouseRay = MainCameraSingleton.instance.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(mouseRay, float.PositiveInfinity, 31 << 14); RaycastHit topHit = new RaycastHit(); MaskPuzzleMaskFragment fragmentHit, topHitFragment = null; float topHitDepth = -1f; float topHitDistance = 0f; // There might be multiple fragments under the cursor // We need to determine which one is on top - that one will be grabbed // We pick the one whose assigned camera has the highest depth // In case of equal depth we pick the fragment closest to the camera foreach (RaycastHit hit in hits) { fragmentHit = hit.collider.GetComponent <MaskPuzzleMaskFragment>(); if (fragmentHit.fragmentGroup.assignedCamera.depth <= topHitDepth) { continue; } if (fragmentHit.fragmentGroup.assignedCamera.depth == topHitDepth && hit.distance >= topHitDistance) { continue; } topHit = hit; topHitFragment = fragmentHit; topHitDepth = fragmentHit.fragmentGroup.assignedCamera.depth; topHitDistance = hit.distance; } if (topHitFragment) { grabbedFragmentGroup = topHitFragment.fragmentGroup; shiftGroupScale(grabbedFragmentGroup, grabScaleIncrease); // Grabbed fragment group should be on top grabbedFragmentGroup.assignedCamera.depth = (topDepth += .005f); // Save the grabbed point's coordinates needed for calculating position when dragging grabZ = topHit.point.z; grabOffset = topHitFragment.transform.position - CameraHelper.getCursorPosition(grabZ); print("Top hit=" + topHitFragment + "; depth=" + topHitDepth + "; dist=" + topHitDistance + "; z=" + topHit.point.z); MicrogameController.instance.playSFX( grabSound, volume: 1f, panStereo: AudioHelper.getAudioPan(topHitFragment.transform.position.x) ); } } // Dropping a fragment else if (grabbedFragmentGroup != null && !Input.GetMouseButton(0)) { shiftGroupScale(grabbedFragmentGroup, -grabScaleIncrease); MicrogameController.instance.playSFX( dropSound, volume: 1f, pitchMult: dropPitchMult, panStereo: AudioHelper.getAudioPan(grabbedFragmentGroup.fragments[0].transform.position.x) ); if (grabbedFragmentGroup.SnapToOtherFragments()) { MicrogameController.instance.playSFX( placeSound, volume: 1f, panStereo: AudioHelper.getAudioPan(grabbedFragmentGroup.fragments[0].transform.position.x) ); if (CheckVictory()) { MicrogameController.instance.playSFX( victorySound, volume: 1f, panStereo: 0f ); } } grabbedFragmentGroup = null; } // Dragging fragments else if (grabbedFragmentGroup != null) { Vector3 position = CameraHelper.getCursorPosition(grabZ); position += grabOffset; foreach (MaskPuzzleMaskFragment fragment in grabbedFragmentGroup.fragments) { fragment.transform.position = position; } } }
void Start() { cameraHelper = new CameraHelper(Camera.main); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { m_faceDetector = await FaceDetector.CreateAsync(); MaskDetect = new Helpers.CustomVision.MaskDetection(new string[] { "mask", "no-mask" }); // Load and create the model var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/facemask.onnx")); await MaskDetect.Init(modelFile); } catch (Exception ex) { Debug.WriteLine($"error: {ex.Message}"); MaskDetect = null; } for (int i = 0; i < 4; i++) { LastSaved[i] = DateTime.MinValue; } if (Sounds.Count <= 0) { //Sounds.Add("wengi.mp3"); //Sounds.Add("setan.wav"); //Sounds.Add("setan2.wav"); //Sounds.Add("zombie.wav"); //Sounds.Add("zombie2.wav"); //Sounds.Add("scream.mp3"); //Sounds.Add("monster.mp3"); } m_processedBitmapSource[0] = new SoftwareBitmapSource(); CCTV1.Source = m_processedBitmapSource[0]; // Initialize helper class used to render the skill results on screen m_bboxRenderer[0] = new BoundingBoxRenderer(UIOverlayCanvas1); m_lock.Wait(); { NotifyUser("Initializing skill..."); m_descriptor = new ObjectDetectorDescriptor(); m_availableExecutionDevices = await m_descriptor.GetSupportedExecutionDevicesAsync(); await InitializeObjectDetectorAsync(); await UpdateSkillUIAsync(); } m_lock.Release(); // Ready to begin, enable buttons NotifyUser("Skill initialized. Select a media source from the top to begin."); //Loop(); var availableFrameSourceGroups = await CameraHelper.GetFrameSourceGroupsAsync(); if (availableFrameSourceGroups != null) { CameraHelper cameraHelper = new CameraHelper() { FrameSourceGroup = availableFrameSourceGroups.FirstOrDefault() }; CameraPreviewControl.PreviewFailed += CameraPreviewControl_PreviewFailed; await CameraPreviewControl.StartAsync(cameraHelper); CameraPreviewControl.CameraHelper.FrameArrived += CameraPreviewControl_FrameArrived; } }
void click() { _rigidBody.velocity = ((Vector2)transform.position - (Vector2)CameraHelper.getCursorPosition()).resize(clickSpeed); }
//void disableCollision() //{ // foreach (PotionIngredient ingredient in pot.ingredients) // { // if (ingredient != this) // { // Physics2D.IgnoreCollision(collider, ingredient.collider); // } // } //} void Update() { switch (state) { case (State.Idle): { if (pot.state == PotionPot.State.Default && Input.GetMouseButtonDown(0) && CameraHelper.isMouseOver(theCollider)) { rigidThing.isKinematic = true; grabOffset = (Vector2)(transform.position - CameraHelper.getCursorPosition()); snapToMouse(); pot.moveToFront(this); _audioSource.panStereo = AudioHelper.getAudioPan(transform.position.x); _audioSource.PlayOneShot(carryClip); lastPosition = (Vector2)CameraHelper.getCursorPosition(); state = State.Grabbed; } } break; case (State.Grabbed): updateSound(); if (pot.state != PotionPot.State.Default || !Input.GetMouseButton(0)) { rigidThing.isKinematic = false; rigidThing.velocity = Vector2.zero; soundDistance = 0f; state = State.Idle; } else { snapToMouse(); } break; case (State.Used): rigidThing.bodyType = RigidbodyType2D.Static; transform.moveTowards(pot.transform.position + new Vector3(0f, -.5f, 0f), speedToPot); break; default: break; } }
public bool isMouseOver() { return(!GameMenu.shifting && CameraHelper.isMouseOver(backupCollider)); }
/// <summary> /// Handle application wide messages which /// isn't handled by a specific window /// </summary> /// <param name="cmd">The command.</param> /// <param name="o">The o.</param> /// <exception cref="System.Exception"></exception> private void WindowsManager_Event(string cmd, object o) { try { Log.Debug("Window command received :" + cmd); if (cmd != WindowsCmdConsts.Next_Image && cmd != WindowsCmdConsts.Prev_Image && cmd != WindowsCmdConsts.Select_Image && !cmd.StartsWith("Zoom")) { ServiceProvider.Analytics.Command(cmd, o as string); } if (cmd == CmdConsts.All_Close) { ServiceProvider.WindowsManager.Event -= WindowsManager_Event; ServiceProvider.Analytics.Stop(); ServiceProvider.Database.EndEvent(EventType.App); if (ServiceProvider.Settings != null) { ServiceProvider.Settings.Save(ServiceProvider.Settings.DefaultSession); ServiceProvider.Settings.Save(); if (ServiceProvider.Trigger != null) { ServiceProvider.Trigger.Stop(); } } ServiceProvider.ScriptManager.Stop(); ServiceProvider.DeviceManager.CloseAll(); Thread.Sleep(1000); Environment.Exit(0); //Dispatcher.begi(new Action(() => Current.Shutdown())); } switch (cmd) { case CmdConsts.Capture: Thread thread = new Thread(new ThreadStart(CameraHelper.Capture)); thread.Start(); break; case CmdConsts.CaptureNoAf: CameraHelper.CaptureNoAf(); break; case CmdConsts.CaptureAll: CameraHelper.CaptureAll(0); break; case CmdConsts.StartBulb: if (ServiceProvider.DeviceManager.SelectedCameraDevice.GetCapability(CapabilityEnum.Bulb)) { ServiceProvider.DeviceManager.LastCapturedImage[ServiceProvider.DeviceManager.SelectedCameraDevice] = "-"; ServiceProvider.DeviceManager.SelectedCameraDevice.IsBusy = true; ServiceProvider.DeviceManager.SelectedCameraDevice.LockCamera(); ServiceProvider.DeviceManager.SelectedCameraDevice.StartBulbMode(); } else { throw new Exception(TranslationStrings.MsgBulbModeNotSupported); } break; case CmdConsts.EndBulb: ServiceProvider.DeviceManager.SelectedCameraDevice.EndBulbMode(); break; case CmdConsts.NextSeries: if (ServiceProvider.Settings != null) { ServiceProvider.Settings.DefaultSession.Series++; } break; } ICameraDevice device = ServiceProvider.DeviceManager.SelectedCameraDevice; if (device != null && device.IsConnected) { switch (cmd) { //case CmdConsts.ResetDevice: // device.ResetDevice(); // break; case CmdConsts.NextAperture: device.FNumber?.NextValue(); break; case CmdConsts.PrevAperture: device.FNumber?.PrevValue(); break; case CmdConsts.NextIso: device.IsoNumber?.NextValue(); break; case CmdConsts.PrevIso: device.IsoNumber?.PrevValue(); break; case CmdConsts.NextShutter: device.ShutterSpeed?.NextValue(); break; case CmdConsts.PrevShutter: device.ShutterSpeed?.PrevValue(); break; case CmdConsts.NextWhiteBalance: device.WhiteBalance?.NextValue(); break; case CmdConsts.PrevWhiteBalance: device.WhiteBalance?.PrevValue(); break; case CmdConsts.NextExposureCompensation: device.ExposureCompensation?.NextValue(); break; case CmdConsts.PrevExposureCompensation: device.ExposureCompensation?.PrevValue(); break; case CmdConsts.NextCamera: ServiceProvider.DeviceManager.SelectNextCamera(); break; case CmdConsts.PrevCamera: ServiceProvider.DeviceManager.SelectPrevCamera(); break; case CmdConsts.StartZoomIn: device.StartZoom(ZoomDirection.In); break; case CmdConsts.StopZoomIn: device.StopZoom(ZoomDirection.In); break; } } } catch (Exception ex) { Log.Error("Error processing comand", ex); } }
// Use this for initialization void Start() { grid = new Grid(); cameraHelper = new CameraHelper(Camera.main); }
// Set the initial position of gameObject according to the position of the cursor private void setInitialPosition() { Vector2 mousePosition = CameraHelper.getCursorPosition(); transform.position = new Vector2(mousePosition.x, transform.position.y); }
public void UpdateNode() { if (Atmosphere == null || Sun == null) { return; } float distance = (CameraHelper.Main().transform.position - Sun.transform.position).magnitude; RaycastHit hit; ViewPortPosition = CameraHelper.Main().WorldToViewportPoint(Sun.transform.position); Scale = distance / 2266660f; Fade = FadeCurve.Evaluate(Mathf.Clamp(Scale, 0.0f, 100.0f)); //Fade = FadeCurve.Evaluate(Mathf.Clamp01(VectorHelper.AngularRadius(Sun.transform.position, CameraHelper.Main().transform.position, 250000.0f))); Eclipse = false; Eclipse = Physics.Raycast(CameraHelper.Main().transform.position, (Sun.transform.position - CameraHelper.Main().transform.position).normalized, out hit, Mathf.Infinity); if (!Eclipse) { Eclipse = Physics.Raycast(CameraHelper.Main().transform.position, (Sun.transform.position - CameraHelper.Main().transform.position).normalized, out hit, Mathf.Infinity); } if (InitUniformsInUpdate) { InitUniforms(SunGlareMaterial); } SetUniforms(SunGlareMaterial); }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { _itemOptions = new ItemOptions(); _itemOptions.Thruster_StrengthRatio *= 4.5; _itemOptions.FuelToThrustRatio *= .03; _itemOptions.Projectile_Color = UtilityWPF.ColorFromHex("FFE330"); // using bee/wasp colors, because white looks too much like the stars _progressBars = new ShipProgressBarManager(pnlProgressBars); _progressBars.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("BBB")); #region Init World // Set the size of the world to something a bit random (gets boring when it's always the same size) double halfSize = 325 + StaticRandom.Next(500); //halfSize *= 2; _boundryMin = new Point3D(-halfSize, -halfSize, -35); _boundryMax = new Point3D(halfSize, halfSize, 35); _world = new World(); _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating); List<Point3D[]> innerLines, outerLines; _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax); // Draw the lines _boundryLines = new ScreenSpaceLines3D(true); _boundryLines.Thickness = 1d; _boundryLines.Color = WorldColors.BoundryLines; _viewport.Children.Add(_boundryLines); foreach (Point3D[] line in innerLines) { _boundryLines.AddLine(line[0], line[1]); } #endregion #region Materials _materialManager = new MaterialManager(_world); // Ship Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material(); _material_Ship = _materialManager.AddMaterial(material); // Exploding Ship material = new Game.Newt.v2.NewtonDynamics.Material(); material.IsCollidable = false; _material_ExplodingShip = _materialManager.AddMaterial(material); // Space Station (force field) material = new Game.Newt.v2.NewtonDynamics.Material(); material.IsCollidable = false; //material.Elasticity = .99d; // uncomment these if it should be collidable (it's an ellipse, and briefly shows a force field) //material.StaticFriction = .02d; //material.KineticFriction = .01d; _material_SpaceStation = _materialManager.AddMaterial(material); //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Asteroid, Collision_SpaceStation); //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Mineral, Collision_SpaceStation); // Mineral material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .5d; material.StaticFriction = .9d; material.KineticFriction = .4d; _material_Mineral = _materialManager.AddMaterial(material); // Asteroid material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .25d; material.StaticFriction = .9d; material.KineticFriction = .75d; _material_Asteroid = _materialManager.AddMaterial(material); // Projectile material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .95d; _material_Projectile = _materialManager.AddMaterial(material); // Swarmbot material = new Game.Newt.v2.NewtonDynamics.Material(); material.Elasticity = .95d; _material_SwarmBot = _materialManager.AddMaterial(material); // Collisions _materialManager.RegisterCollisionEvent(_material_Ship, _material_Mineral, Collision_ShipMineral); _materialManager.RegisterCollisionEvent(_material_Ship, _material_Asteroid, Collision_ShipAsteroid); _materialManager.RegisterCollisionEvent(_material_Ship, _material_Projectile, Collision_ShipProjectile); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Projectile, Collision_AsteroidProjectile); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_SwarmBot, Collision_AsteroidSwarmBot); _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Asteroid, Collision_AsteroidAsteroid); #endregion #region Trackball //TODO: Only use this when debugging the scene //// Trackball //_trackball = new TrackBallRoam(_camera); //_trackball.KeyPanScale = 15d; //_trackball.EventSource = grdViewPort; //NOTE: If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null) //_trackball.AllowZoomOnMouseWheel = true; //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft)); ////_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius); //_trackball.ShouldHitTestOnOrbit = true; #endregion #region Map _map = new Map(_viewport, null, _world); //_map.SnapshotFequency_Milliseconds = 250; // just use the map's default values //_map.SnapshotMaxItemsPerNode = 13; _map.ShouldBuildSnapshots = true; _map.ShouldShowSnapshotLines = false; _map.ShouldSnapshotCentersDrift = true; _map.ItemRemoved += new EventHandler<MapItemArgs>(Map_ItemRemoved); #endregion #region Radiation //TODO: Make radiation sources instead of a constant ambient -- sort of mini stars, or something manmade looking _radiation = new RadiationField() { AmbientRadiation = 1, }; #endregion #region UpdateManager //TODO: UpdateManager needs to inspect types as they are added to the map (map's ItemAdded event) _updateManager = new UpdateManager( new Type[] { typeof(ShipPlayer), typeof(SpaceStation2D), typeof(Projectile), typeof(Asteroid), typeof(SwarmBot1b) }, new Type[] { typeof(ShipPlayer), typeof(SwarmBot1b) }, _map); #endregion #region Brush Strokes _brushStrokes = new SwarmObjectiveStrokes(_world.WorldClock, _itemOptions.SwarmBay_BirthSize * 4, 6); // This would be for drawing the strokes //_brushStrokes.PointsChanged += BrushStrokes_PointsChanged; #endregion #region Player _player = new Player(); _player.Credits = 10; _player.ShipChanged += new EventHandler<ShipChangedArgs>(Player_ShipChanged); #endregion #region Minimap _miniMap = new MinimapHelper(_map, _viewportMap); #endregion #region Camera Helper _cameraHelper = new CameraHelper(_player, _camera, _cameraMap, _miniMap); #endregion #region MapPopulationManager _mapPopulationManager = new MapPopulationManager(_map, _world, new Point3D(_boundryMin.X, _boundryMin.Y, 0), new Point3D(_boundryMax.X, _boundryMax.Y, 0), _material_Asteroid, _material_Mineral, GetAsteroidMassByRadius, GetMineralsFromDestroyedAsteroid, ItemOptionsAstMin2D.MINASTEROIDRADIUS); _updateManager.AddNonMapItem(_mapPopulationManager, TokenGenerator.NextToken()); #endregion #region MapForcesManager _mapForcesManager = new MapForcesManager(_map, _boundryMin, _boundryMax); _updateManager.AddNonMapItem(_mapForcesManager, TokenGenerator.NextToken()); #endregion #region BackImageManager _backImageManager = new BackImageManager(backgroundCanvas, _player); #endregion #region Ship Extra _shipExtra = new ShipExtraArgs() { Options = _editorOptions, ItemOptions = _itemOptions, Material_Projectile = _material_Projectile, Material_SwarmBot = _material_SwarmBot, SwarmObjectiveStrokes = _brushStrokes, RunNeural = false, Radiation = _radiation, }; #endregion CreateStars3D(); //TODO: Move this to BackImageManager //CreateStars3DGrid(); //CreateShip(UtilityCore.GetRandomEnum<DefaultShipType>()); if (!LoadLatestSession()) { CreateNewSession(); } CreateAsteroids(); CreateMinerals(); //CreateProjectile(); _world.UnPause(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
//void disableCollision() //{ // foreach (PotionIngredient ingredient in pot.ingredients) // { // if (ingredient != this) // { // Physics2D.IgnoreCollision(collider, ingredient.collider); // } // } //} void Update() { switch (state) { case (State.Idle): { if (pot.state == PotionPot.State.Default && Input.GetMouseButtonDown(0) && CameraHelper.isMouseOver(theCollider)) { rigidThing.isKinematic = true; grabOffset = (Vector2)(transform.position - CameraHelper.getCursorPosition()); snapToMouse(); pot.moveToFront(this); state = State.Grabbed; } } break; case (State.Grabbed): snapToMouse(); if (pot.state != PotionPot.State.Default || !Input.GetMouseButton(0)) { rigidThing.isKinematic = false; state = State.Idle; } break; case (State.Used): MathHelper.moveTowards2D(transform, pot.transform.position + new Vector3(0f, -.5f, 0f), speedToPot); break; default: break; } }