Jump to content

How to get the amount of touches on the touchpad?


photo

Recommended Posts

You can check corresponding sample in C# Component Samples: https://developer.unigine.com/en/docs/2.18.1/sdk/demos/csharp_component_samples/input?rlang=cpp

public class InputTouches : Component
{
	public ivec2[] TouchesPositions { get; private set; } = new ivec2[Input.NUM_TOUCHES];

	private void Init()
	{
		for (int i = 0; i < Input.NUM_TOUCHES; i++)
			TouchesPositions[i] = -ivec2.ONE;
	}

	private void Update()
	{
		for (int i = 0; i < Input.NUM_TOUCHES; i++)
		{
			if (Input.IsTouchPressed(i))
				TouchesPositions[i] = Input.GetTouchPosition(i);

			if (Input.IsTouchUp(i))
				TouchesPositions[i] = -ivec2.ONE;
		}
	}
}

 

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
4 hours ago, silent said:

You can check corresponding sample in C# Component Samples: https://developer.unigine.com/en/docs/2.18.1/sdk/demos/csharp_component_samples/input?rlang=cpp

public class InputTouches : Component
{
	public ivec2[] TouchesPositions { get; private set; } = new ivec2[Input.NUM_TOUCHES];

	private void Init()
	{
		for (int i = 0; i < Input.NUM_TOUCHES; i++)
			TouchesPositions[i] = -ivec2.ONE;
	}

	private void Update()
	{
		for (int i = 0; i < Input.NUM_TOUCHES; i++)
		{
			if (Input.IsTouchPressed(i))
				TouchesPositions[i] = Input.GetTouchPosition(i);

			if (Input.IsTouchUp(i))
				TouchesPositions[i] = -ivec2.ONE;
		}
	}
}

 

Good day silent,

I have used your code, but it doesn't work. When I click it doesn't print out how many fingers are touching the touchpad and staying. Clicking also doesn't work because this part of the code is just a const int which is equal to 16:

Input.NUM_TOUCHES

It is the same as writing:

const int inputNumTouch = 16;
	public ivec2[] TouchesPositions { get; private set; } = new ivec2[inputNumTouch];

	private void Init(){
		Unigine.Console.Onscreen = true;
		for (int i = 0; i < inputNumTouch; i++) TouchesPositions[i] = -ivec2.ONE;
	}

	private void Update(){
		for (int i = 0; i < inputNumTouch; i++) {
			if (Input.IsTouchPressed(i)) Log.Warning($"{i}\n");
			if (Input.IsTouchUp(i)) Log.Warning($"{i}\n");
		}
	}

This won't work.

I need the code which will let me get the amount of fingers touching the touchpad. For example,

image.thumb.jpeg.3463b803647cb7ac8fb3d4f96aea599c.jpeg

This should print out as 3 touches and as long as my fingers are on the touchpad it should remain as 3 touches. That way we can make unique set of motions depending on how many fingers are on the touchpad.

Link to comment

I'm afraid, current SDL2 touch API is not designed to work with laptop touchpad, but rather with multi-touch screen panels or monitors. Also probably touchpad driver is simply trying to emulate this device as regular mouse and doesn't send exact fingers touches / positions.

Probably, implementing a custom touchpad input via 3rd party libraries specifically designed for that would be easier: https://github.com/yabadabu/touchpad

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
1 hour ago, silent said:

I'm afraid, current SDL2 touch API is not designed to work with laptop touchpad, but rather with multi-touch screen panels or monitors. Also probably touchpad driver is simply trying to emulate this devices as regular mouse and doesn't send exact fingers touches / positions.

Probably, implementing a custom touchpad input via 3rd party libraries specifically designed for that would be easier: https://github.com/yabadabu/touchpad

Thanks!

Good day silent,

After a long search I found this post on stackoverflow: https://stackoverflow.com/questions/26089337/delphi-x-y-position-of-finger-on-laptop-touchpad

The answer to do it lies here:

"Upon receiving a WM_TOUCH message you can obtain detailed information by immediately passing the touch handle to GetTouchInputInfo. Which returns an array of TOUCHINPUT structures, each carrying information about each active touch point on the digitizer surface."

This is the microsft guide: https://learn.microsoft.com/en-us/windows/win32/wintouch/guide-multi-touch-input

This makes sense because windows already supports multitouch functionality:

image.png.e2182b1adaa30d573a176c4005b34bfd.png

Could you guys implement this to Unigine please?

Link to comment
On 7/16/2024 at 1:47 PM, silent said:

Right now we have no plans to implement extended touchpad controls, sorry. Maybe in the future when we will switch to SDL3 or something like that.

Good day silent,

How can I import SDL library into Unigine and code the touchpad for multitouch or for any type of motion using SDL? I found these which can help me create the code, but I don't know how to get started:

1) Tutorial: https://lazyfoo.net/tutorials/SDL/55_multitouch/index.php

2) SDL_MultiGestureEvent: https://wiki.libsdl.org/SDL2/SDL_MultiGestureEvent

Link to comment

First of all you need to link with SDL library and after that you can use it's API in your application. Since you are developing a regular windows application there is basically no limitations on how you can do it. Just check SDL2 documentation how to use it's API in C++ app.

If you plan to use it in C# I guess you can use DLLImport: https://stackoverflow.com/questions/60466771/how-to-load-dll-for-sdl2-in-c-sharp-problem-with-dllimport

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
2 hours ago, silent said:

First of all you need to link with SDL library and after that you can use it's API in your application. Since you are developing a regular windows application there is basically no limitations on how you can do it. Just check SDL2 documentation how to use it's API in C++ app.

If you plan to use it in C# I guess you can use DLLImport: https://stackoverflow.com/questions/60466771/how-to-load-dll-for-sdl2-in-c-sharp-problem-with-dllimport

Good day silent,

I downloaded the library and added it to the project: https://github.com/flibitijibibo/SDL2-CS

image.png.9ac30c4cdfe484119524199bafb913f4.png

From what I understood, I have to use dllImport like this: https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime

[DllImport("MyAppDll.dll")] // relative path; just give the DLL's name
static extern bool MyGreatFunction(int myFirstParam, int mySecondParam);

but I'm not sure if I'm doing things right because there is errors in the SDL2:

image.png.4d70d6df884a5aaa3d74e2fac6eecdfc.png

What do you mean by linking SDL library? Did I import the files correctly?

Link to comment
Posted (edited)
3 hours ago, silent said:

I believe it would be better to contact SDL2 dev team (or even C# port author) in order to get clarifications for that unknown method. You don't need link anything if you are using C#.

Good day silent,

I got lucky and managed to get it to work using this post: https://stackoverflow.com/questions/41799214/error-in-visual-studio-code-dotnet-core-c-the-type-or-namespace-name-system

image.png.93fba7ccbca5ee62f93c53ad7f2b71f4.png

The issue was vscode and C#. In order to fix the issue, I did the fallowing:

image.png.7b6cc8f7492a034d2a0bfa47ec76d539.png

After I imported the project, I got the errors that unsafe code blocks aren't allowed to be used.

image.png.3c8ec49c5fef8f014a786bca06458cfa.png

In order to fix this, this code needs to be added to .csproj: https://stackoverflow.com/questions/50636693/how-to-run-unsafe-code-in-visual-studio-code

image.png.111059205f6175e864203d096a2d2ff3.png

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

image.png.716497c6eb2737e60375a2f94c8d38b6.png

Is using this project safe?

Using DLLImport, how may I implement SDL for touch functions? Could you give me some examples please?

Do I need the entire github SDL project in Unigine Asset Browser or just the scripts in src folder?

image.png.2c03f7d135b19f5dfc9e0f1ccd7aac8c.png

Edited by Sevdat
Link to comment
×
×
  • Create New...