Hi, I’m trying to position a texture whenever there is a touch / mouse move, and
updates the texture relative to the touch / mouse coordinates.
Using the TUIO protocol, I’m receiving touch event and thereby updates the touches events which in turn store them to the dictionary.
The problem is: (Note: All coordinates be it touch or mouse is exactly the same.)
- GUI.DrawTexture + Touch Coordinates = Bad rendering texture while moving.
- GUI.DrawTexture + Mouse Coordinates = No rendering problem.
Can anyone pin point me to where might be the cause of the issue
Here is my code:
public Texture2D texture;
private Dictionary<int, int> activeTouchInput;
private string HandID = "1000";
private float width = 100.0f;
private float height = 100.0f;
private void OnGUI()
{
// Position only if there are active tags.
if (activeTouchInput.Count > 0)
PositionTexture();
}
private void PositionTexture()
{
// Linq Query to the get the touch value from the dictionary
TouchInput activeTouch = (from activeTouch in activeTouchInput.Values
where activeTouch.ID == this.ID
select activeTouch).FirstOrDefault();
float halfX = width * 0.5f;
float halfY = height * 0.5f;
// This line of code creates a very bad rendering of the texture while moving.
// Basically it just takes the touch value from the dictionary and display a texture over it.
GUI.DrawTexture(new Rect((activeTouch.X - 1) - halfX, (activeTouch.Y - 1) - halfX, width, height), texture, ScaleMode.ScaleToFit, true, 0.0f);
// This line of code creates a very smooth rendering of the texture while moving.
// The input is from mouse position.
GUI.DrawTexture(new Rect(Input.mousePosition.x - halfX, (Screen.height - Input.mousePosition.y) - halfY, 300, 300), texture, ScaleMode.ScaleToFit, true, 0.0f);
}