Example #1
0
 public void ForceWorkspaceUpdate()
 {
     if (HapticWorkspace != null)
     {
         UnityHaptics.SetHapticWorkspace(HapticWorkspace);
     }
 }
Example #2
0
    // Update is called once per frame
    private void Update()
    {
        //Debug.Log(UnityHaptics.GetToolVelocity());
        LoopNumber += 1;
        if (LoopNumber % 100 == 0)
        {
            LoopFrequencyHz = HapticNativePlugin.get_loop_frequency();
            if (Verbosity > 1)
            {
                Debug.Log(LoopFrequencyHz);
            }
        }
        if (EnableTick == Tick.Update)
        {
            HapticNativePlugin.tick();
        }

        if (!Started || !Running)
        {
            int res = HapticNativePlugin.start();
            UnityHaptics.LogMessage(res, true);
            Started = res == HapticNativePlugin.SUCCESS;
            Running = Started;

            UpdateToolPositionAndRotation();
        }
    }
    // FIXME: set_world_translation() has no wrappers. Do we need one?
    // FIXME: set_world_scale() has no wrappers. Do we need one?

    public static double[] GetToolProxyPosition()
    {
        double[] position = new double[3];
        int      res      = get_tool_proxy_position(position);

        UnityHaptics.LogMessage(res, true);
        return(position);
    }
Example #4
0
 private void UpdateToolPositionAndRotation()
 {
     // Debug.Log(UnityHaptics.GetToolPosition());
     transform.SetPositionAndRotation(UseProxyPosition ?
                                      UnityHaptics.GetToolProxyPosition() :
                                      UnityHaptics.GetToolPosition(),
                                      UnityHaptics.GetToolRotation());
 }
Example #5
0
    private void Awake()
    {
        CheckCompatibility();
        if (UseSphereRadius)
        {
            //// This can only render a sphere.
            //// Warn if attached to something else (maybe they just want to get the input position)
            if (GetComponent <MeshFilter>().name != "Sphere" &&
                Verbosity > 0)
            {
                Debug.LogWarning("This script is not attached to a sphere " +
                                 "but you are trying to use the sphere radius. You should" +
                                 "instead set the radius manually");
            }
            // The sphere size in unity is 0.5 units.
            // We use the Transform scale on the X axis to get the real size
            Radius = transform.lossyScale.x * 0.5f;
        }

        SetWaitForForces();

        // FIXME: what to do with workspace radius?
        UnityHaptics.SetUnityWorldCoordinates();

        int res = HapticNativePlugin.Initialize(DeviceId, WorkspaceSize, Radius);

        if (res != HapticNativePlugin.SUCCESS)
        {   // success silently, fail loudly
            Debug.LogError("Could not start haptics");
            UnityHaptics.LogMessage(res, false);
            return;
        }

        //  ForceWorkspaceUpdate();

        if (EnableDynamicObjects)
        {
            HapticNativePlugin.enable_dynamic_objects();
        }
        else
        {
            HapticNativePlugin.disable_dynamic_objects();
        }

        // FIXME: move to UnityHaptics, enable things we want to log and so on
        if (EnableLog && LogDownsampling != 0)
        {
            HapticNativePlugin.SetupLogging(LogDownsampling, DeviceCoordinates);
        }
        // Set initial position
        UpdateToolPositionAndRotation();
    }
    private void SetTexture()
    {
	// Here texture can be null
    Texture2D texture = UseObjectTexture ? GetMeshTexture() : material.textureImage;
	if (texture == null) { return; } // no more
    if (Verbosity > 1) { Debug.Log("Setting Texture"); }

	if (UnityHaptics.SetTexture(ObjectId, texture, material.ReverseTexture)
	    != HapticNativePlugin.SUCCESS)
	{
	    Debug.LogWarning("Could not set Texture");
	}
    }
Example #7
0
    private int UpdateScale()
    {
        int status = 0;

        if (lastScale != transform.lossyScale)
        {
            status =
                UnityHaptics.SetObjectScale(ObjectId, transform.lossyScale);
            lastScale = transform.lossyScale;
        }

        return(status);
    }
    public bool UpdateMaterial() {
	if (material == null)
	{
	    Debug.LogWarning("Empty material on object: " + name);
	    return false;
	}
	if (Verbosity > 2) { Debug.Log("Updating " + name + " material"); }

	bool success = UnityHaptics.SetMaterial(ObjectId, material) ==
	    HapticNativePlugin.SUCCESS;

	SetTexture();

	return success;
    }
Example #9
0
 void Update()
 {
     if (HapticNativePlugin.IsRunning())
     {
         if (UpdatePosition)
         {
             transform.position = (UseProxyPosition) ? UnityHaptics.GetToolProxyPosition() :
                                  UnityHaptics.GetToolPosition();
         }
         if (UpdateRotation)
         {
             transform.rotation = UnityHaptics.GetToolRotation();
         }
     }
 }
Example #10
0
 override protected void CreateObject()
 {
     if (ObjectId < 0)
     {
         if (Verbosity > 2)
         {
             Debug.Log("Creating the mesh: " + name);
         }
         ObjectId = UnityHaptics.CreateUnityMesh
                        (GetComponent <MeshFilter>().sharedMesh,
                        transform);
         if (ObjectId < 0)
         {
             Debug.LogError("Failed to add the object");
         }
     }
 }
Example #11
0
    private void OnDestroy()
    {
        if ((!HapticNativePlugin.IsInitialized() ||
             !HapticNativePlugin.IsRunning()))
        {
            Started = false;
            return;
        }

        int res = HapticNativePlugin.deinitialize();

        UnityHaptics.LogMessage(res, true);
        SaveLogIfLogging();

        HapticNativePlugin.stop();
        Started = false;
        Running = false;
    }
Example #12
0
    private bool UpdateRotation()
    {
        bool success = false;

        if (lastRot != transform.rotation)
        {
            if (Verbosity > 2)
            {
                Debug.Log("Updating rotation");
            }

            success =
                UnityHaptics.SetObjectRotationEuler(ObjectId, transform.rotation)
                == HapticNativePlugin.SUCCESS;
            lastRot = transform.rotation;
        }
        return(success);
    }
Example #13
0
    private bool UpdatePosition()
    {
        bool success = false;

        if (lastPos != transform.position)
        {
            if (Verbosity > 2)
            {
                Debug.Log("Updating position");
            }

            success =
                UnityHaptics.SetObjectPosition(ObjectId, transform.position)
                == HapticNativePlugin.SUCCESS;
            lastPos = transform.position;
        }
        return(success);
    }
Example #14
0
 override protected void CreateObject()
 {
     if (ObjectId < 0)
     {
         if (Verbosity > 2)
         {
             Debug.Log("Creating the shape: " + name);
         }
         if (Verbosity > 0 &&
             (transform.lossyScale.x != transform.lossyScale.y ||
              transform.lossyScale.y != transform.lossyScale.z))
         {
             Debug.LogWarning("This kind of object does not support scaling on different sizes! " +
                              "Only X will be used");
         }
         // FIXME: rename the function called, and simplify the passing (single meshfilter)
         ObjectId = UnityHaptics.CreateUnityShape
                        (GetComponent <MeshFilter>().sharedMesh, transform);
         if (ObjectId < 0)
         {
             Debug.LogError("Failed to add the object");
         }
     }
 }