Browse Source

fix iOS touch: added scale factor

- without scale factor the wrong area is hit
- the cast to long is only necessary if you want to test your app in the simulator (x86_64):  Java receives parameters in the wrong order and/or with completely wrong values
revvv 5 years ago
parent
commit
ac4a2e2d0d
1 changed files with 7 additions and 3 deletions
  1. 7 3
      jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m

+ 7 - 3
jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m

@@ -275,7 +275,9 @@ getEnv(JavaVM* vm)
     if (e) {
     if (e) {
     	UITouch *touch = [touches anyObject];
     	UITouch *touch = [touches anyObject];
     	CGPoint position = [touch locationInView: nil];
     	CGPoint position = [touch locationInView: nil];
-        (*e)->CallVoidMethod(e, self.harness, self.injectTouchBegin, 0, touch.timestamp, position.x, position.y);
+        float scale = _glview.contentScaleFactor;
+        // NOTE: cast to long is only required for x86_64/simulator, otherwise JmeAppHarness receives non-sense values (Avian!?)
+        (*e)->CallVoidMethod(e, self.harness, self.injectTouchBegin, 0, (long) touch.timestamp, position.x * scale, position.y * scale);
         if ((*e)->ExceptionCheck(e)) {
         if ((*e)->ExceptionCheck(e)) {
             NSLog(@"Could not invoke iOS Harness injectTouchBegin");
             NSLog(@"Could not invoke iOS Harness injectTouchBegin");
             (*e)->ExceptionDescribe(e);
             (*e)->ExceptionDescribe(e);
@@ -290,7 +292,8 @@ getEnv(JavaVM* vm)
     if (e) {
     if (e) {
     	UITouch *touch = [touches anyObject];
     	UITouch *touch = [touches anyObject];
     	CGPoint position = [touch locationInView: nil];
     	CGPoint position = [touch locationInView: nil];
-        (*e)->CallVoidMethod(e, self.harness, self.injectTouchMove, 0, touch.timestamp, position.x, position.y);
+        float scale = _glview.contentScaleFactor;
+        (*e)->CallVoidMethod(e, self.harness, self.injectTouchMove, 0, (long) touch.timestamp, position.x * scale, position.y * scale);
         if ((*e)->ExceptionCheck(e)) {
         if ((*e)->ExceptionCheck(e)) {
             NSLog(@"Could not invoke iOS Harness injectTouchMove");
             NSLog(@"Could not invoke iOS Harness injectTouchMove");
             (*e)->ExceptionDescribe(e);
             (*e)->ExceptionDescribe(e);
@@ -305,7 +308,8 @@ getEnv(JavaVM* vm)
     if (e) {
     if (e) {
     	UITouch *touch = [touches anyObject];
     	UITouch *touch = [touches anyObject];
     	CGPoint position = [touch locationInView: nil];
     	CGPoint position = [touch locationInView: nil];
-        (*e)->CallVoidMethod(e, self.harness, self.injectTouchEnd, 0, touch.timestamp, position.x, position.y);
+        float scale = _glview.contentScaleFactor;
+        (*e)->CallVoidMethod(e, self.harness, self.injectTouchEnd, 0, (long) touch.timestamp, position.x * scale, position.y * scale);
         if ((*e)->ExceptionCheck(e)) {
         if ((*e)->ExceptionCheck(e)) {
             NSLog(@"Could not invoke iOS Harness injectTouchEnd");
             NSLog(@"Could not invoke iOS Harness injectTouchEnd");
             (*e)->ExceptionDescribe(e);
             (*e)->ExceptionDescribe(e);