Sevdat Posted July 15 Posted July 15 (edited) Good evening, I read the documentation, but I can't figure out how to get the amount of touches on the touchpad: https://developer.unigine.com/en/docs/future/api/library/controls/class.input?rlang=cs When I print: Input.NUM_TOUCHES the value only 16 prints out. How do I get 0,1,2 etc depending on the amount of fingers on the touchpad. Edited July 15 by Sevdat
silent Posted July 16 Posted July 16 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Sevdat Posted July 16 Author Posted July 16 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, 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.
silent Posted July 16 Posted July 16 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! 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Sevdat Posted July 16 Author Posted July 16 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: Could you guys implement this to Unigine please?
silent Posted July 16 Posted July 16 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. 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Sevdat Posted July 17 Author Posted July 17 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
silent Posted July 18 Posted July 18 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Sevdat Posted July 18 Author Posted July 18 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 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: What do you mean by linking SDL library? Did I import the files correctly?
silent Posted July 18 Posted July 18 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#. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Sevdat Posted July 18 Author Posted July 18 (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 The issue was vscode and C#. In order to fix the issue, I did the fallowing: After I imported the project, I got the errors that unsafe code blocks aren't allowed to be used. 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 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> 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? Edited July 18 by Sevdat
Recommended Posts