/// <summary>
        /// Sets/Resets the crosshair picture
        /// </summary>
        /// <param name="filePath">The filepath for the crosshair's image</param>
        /// <returns>True if success, else false</returns>
        public bool SetCrosshairPic(string filePath)
        {
            if (String.IsNullOrWhiteSpace(filePath))
            {
                crosshairMode      = CrosshairMode.Default;
                CrosshairImagePath = "";
            }
            else
            {
                if (File.Exists(filePath))
                {
                    try
                    {
                        img_crosshair.Source = new BitmapImage(new UriBuilder(filePath).Uri);
                        crosshairMode        = CrosshairMode.Custom;
                        CrosshairImagePath   = filePath;
                    }
                    catch
                    {
                        MessageBox.Show("Invalid image file selected", "Oops!");
                        return(false);
                    }
                }
                else
                {
                    // this block of code will never actually execute(at-least IMO)
                    MessageBox.Show("No image file selected", "Oops!");
                    return(false);
                }
            }

            SetCrosshairScale(CrosshairScale);
            SetCrosshairTransparency = crosshairTransparency;
            if (grid_crosshair.Visibility != img_crosshair.Visibility)
            {
                HideWindows();
                DisplayWindow();
            }
            return(true);
        }
Esempio n. 2
0
    /// <summary>
    /// Updates the position of the crosshair.
    /// </summary>
    void LateUpdate()
    {
#if CROSSHAIR_TESTING
        if (Input.GetButtonDown("RightShoulder"))
        {
            //*************************
            // toggle the crosshair mode .. dynamic -> dynamic objects -> fixed depth
            //*************************
            switch (mode)
            {
            case CrosshairMode.Dynamic:
                mode = CrosshairMode.DynamicObjects;
                crosshairMaterial.color = Color.red;
                break;

            case CrosshairMode.DynamicObjects:
                mode = CrosshairMode.FixedDepth;
                crosshairMaterial.color = Color.blue;
                break;

            case CrosshairMode.FixedDepth:
                mode = CrosshairMode.Dynamic;
                crosshairMaterial.color = Color.white;
                break;
            }
            Debug.Log("Mode: " + mode);
        }
#endif
        Ray        ray;
        RaycastHit hit;

        // get the camera forward vector and position
        Vector3 cameraPosition = cameraController.centerEyeAnchor.position;
        Vector3 cameraForward  = cameraController.centerEyeAnchor.forward;

        GetComponent <Renderer>().enabled = true;

        //*************************
        // position the cursor based on the mode
        //*************************
        switch (mode)
        {
        case CrosshairMode.Dynamic:
            // cursor positions itself in 3D based on raycasts into the scene
            // trace to the spot that the player is looking at
            ray = new Ray(cameraPosition, cameraForward);
            if (Physics.Raycast(ray, out hit))
            {
                thisTransform.position = hit.point + (-cameraForward * offsetFromObjects);
                thisTransform.forward  = -cameraForward;
            }
            break;

        case CrosshairMode.DynamicObjects:
            // similar to Dynamic but cursor is only visible for objects in a specific layer
            ray = new Ray(cameraPosition, cameraForward);
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject.layer != objectLayer)
                {
                    GetComponent <Renderer>().enabled = false;
                }
                else
                {
                    thisTransform.position = hit.point + (-cameraForward * offsetFromObjects);
                    thisTransform.forward  = -cameraForward;
                }
            }
            break;

        case CrosshairMode.FixedDepth:
            // cursor positions itself based on camera forward and draws at a fixed depth
            thisTransform.position = cameraPosition + (cameraForward * fixedDepth);
            thisTransform.forward  = -cameraForward;
            break;
        }

        if (Input.GetButtonDown(OVRGamepadController.ButtonNames[(int)OVRGamepadController.Button.A]))
        {
            ray = new Ray(cameraPosition, cameraForward);
            if (Physics.Raycast(ray, out hit))
            {
                hit.transform.gameObject.BroadcastMessage("OnClick", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Esempio n. 3
0
	/// <summary>
	/// Updates the position of the crosshair.
	/// </summary>
	void LateUpdate()
	{
#if CROSSHAIR_TESTING
		if (Input.GetButtonDown("RightShoulder"))
		{
			//*************************
			// toggle the crosshair mode .. dynamic -> dynamic objects -> fixed depth
			//*************************
			switch(mode)
			{
			case CrosshairMode.Dynamic:
				mode = CrosshairMode.DynamicObjects;
				crosshairMaterial.color = Color.red;
				break;
			case CrosshairMode.DynamicObjects:
				mode = CrosshairMode.FixedDepth;
				crosshairMaterial.color = Color.blue;
				break;
			case CrosshairMode.FixedDepth:
				mode = CrosshairMode.Dynamic;
				crosshairMaterial.color = Color.white;
				break;
			}
			Debug.Log("Mode: " + mode);
		}
#endif
		Ray ray;
		RaycastHit hit;

		// get the camera forward vector and position
		Vector3 cameraPosition = cameraController.centerEyeAnchor.position;
		Vector3 cameraForward = cameraController.centerEyeAnchor.forward;

		GetComponent<Renderer>().enabled = true;

		//*************************
		// position the cursor based on the mode
		//*************************
		switch (mode)
		{
		case CrosshairMode.Dynamic:
			// cursor positions itself in 3D based on raycasts into the scene
			// trace to the spot that the player is looking at
			ray = new Ray(cameraPosition, cameraForward);
			if ( Physics.Raycast(ray, out hit))
			{
				thisTransform.position = hit.point + (-cameraForward * offsetFromObjects);
				thisTransform.forward = -cameraForward;
			}
			break;
		case CrosshairMode.DynamicObjects:
			// similar to Dynamic but cursor is only visible for objects in a specific layer
			ray = new Ray(cameraPosition, cameraForward);
			if (Physics.Raycast(ray, out hit))
			{
				if (hit.transform.gameObject.layer != objectLayer)
				{
					GetComponent<Renderer>().enabled = false;
				}
				else
				{
					thisTransform.position = hit.point + (-cameraForward * offsetFromObjects);
					thisTransform.forward = -cameraForward;
				}
			}
			break;
		case CrosshairMode.FixedDepth:
			// cursor positions itself based on camera forward and draws at a fixed depth
			thisTransform.position = cameraPosition + (cameraForward * fixedDepth);
			thisTransform.forward = -cameraForward;
			break;
		}

		if (Input.GetButtonDown(OVRGamepadController.ButtonNames[(int)OVRGamepadController.Button.A]))
		{
			ray = new Ray(cameraPosition, cameraForward);
			if (Physics.Raycast(ray, out hit))
			{
				hit.transform.gameObject.BroadcastMessage("OnClick", SendMessageOptions.DontRequireReceiver);
			}
		}
	}
Esempio n. 4
0
		public void SetCrosshairMode(bool addMode)
		{
			mode = addMode ? CrosshairMode.Add : CrosshairMode.Subtract;
		}
Esempio n. 5
0
		public void SetCrosshairMode(CrosshairMode interactionMode)
		{
			mode = interactionMode;
		}
Esempio n. 6
0
		//protected void FixedUpdate()
		//{
		//	//transform.position = Vector3.Lerp(transform.position, newPosition, LerpSpeed);

		//}

		/// <summary>
		/// Updates the position of the crosshair.
		/// </summary>
		private void LateUpdate()
		{
			if (mode != lastMode)
			{
				ChangeTexture();
			}

			lastMode = mode;

			//Ray ray;
			//RaycastHit hit;

			transform.position = Vector3.Lerp(transform.position, newPosition, LerpSpeed);


			//transform.position = newPosition;


			// get the camera forward vector and position
			//var cameraPosition = VoxManager.ViewPosition;
			//var cameraForward = VoxManager.ViewForward;

			return;

			//GetComponent<Renderer>().enabled = true;


			//var plane = VoxUser.GetXYZPlaneFacingDirection(cameraForward, Vector3.zero);

			//transform.forward = plane.normal;


			//transform.position = cameraPosition + cameraForward*10f;

			//ConstructionPlane = VoxUser.GetXYZPlaneFacingDirection(cameraForward, cameraPosition + cameraForward*5f);
			//transform.forward = ConstructionPlane.normal;










			//if (!lockToPlane)
			//{

			//	ray = new Ray(cameraPosition, cameraForward);
			//	if (Physics.Raycast(ray, out hit))
			//	{
			//		CanDoubleClickToOpenMenu = false;

			//		//myRenderer.enabled = true;
			//		//newPosition = cameraPosition + cameraForward * hit.distance;

			//		transform.forward = hit.normal;

			//		newPosition = VoxTerrain.GetUnityPosition(VoxTerrain.GetBlockPos(hit.point - hit.normal * World.UnitScale * 0.5f)) + hit.normal * World.UnitScale * 0.5f;

			//		if (Input.GetButtonDown(OVRGamepadController.ButtonNames[(int)OVRGamepadController.Button.A]))
			//		{
			//			hit.transform.gameObject.BroadcastMessage("OnClick", SendMessageOptions.DontRequireReceiver);
			//		}
			//	}
			//	else
			//	{
			//		CanDoubleClickToOpenMenu = true;

			//		transform.forward = ConstructionPlane.normal;

			//		float enter = 0f;
			//		if (ConstructionPlane.Raycast(ray, out enter))
			//		{
			//			var pointOnPlane = ray.origin + ray.direction*enter;
			//			newPosition = pointOnPlane;
			//		}
			//	}
			//}










			//else
			//{
			//	//newPosition = cameraPosition + cameraForward*distanceFromCamera;
			//	//newPosition = cameraPosition - cameraForward * 10f;
			//	//transform.position = newPosition;
			//	//float enter;
			//	//if (ConstructionPlane.Raycast(ray, out enter))
			//	//{
			//	//	//Debug.Log("Enter = " + enter);
			//	//	var pointOnPlane = ray.origin + ray.direction * enter;

			//	//	//newPosition = pointOnPlane;

			//	//	//transform.position = pointOnPlane;

			//	//	//transform.forward = ConstructionPlane.normal;
			//	//}

			//}


			

			//if (OVRManager.display.isPresent)
			//{
				
			//}
			//else
			//{
			//	GetComponent<Renderer>().enabled = false;
			//}
		}