coord reset for extremely high pointer velocity, core implementation
This commit is contained in:
1 parent
01718282ff
commit
31b3df08cc
4 files changed
+47
-37
No files matched your search
@@ -14,10 +14,9 @@
|
|||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface NativeTouchHandler : UIResponder
|
@interface NativeTouchHandler : UIResponder
|
||||||
@property (nonatomic, assign) bool BoundaryReached;
|
|
||||||
@property (nonatomic, assign) bool flipFlag;
|
|
||||||
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings;
|
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
@@ -44,8 +44,7 @@
|
|||||||
|
|
||||||
[NativeTouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
|
[NativeTouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
|
||||||
[NativeTouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
|
[NativeTouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
|
||||||
[NativeTouchPointer initContextWithView:self->streamView andNativeTouchHandler:self];
|
[NativeTouchPointer initContextWithView:self->streamView];
|
||||||
_flipFlag = true;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@
|
|||||||
uintptr_t memAddrValue = (uintptr_t)touch;
|
uintptr_t memAddrValue = (uintptr_t)touch;
|
||||||
unassignedPointerIds = [pointerIdPool mutableCopy]; //reset unassignedPointerIds
|
unassignedPointerIds = [pointerIdPool mutableCopy]; //reset unassignedPointerIds
|
||||||
[unassignedPointerIds minusSet:activePointerIds];
|
[unassignedPointerIds minusSet:activePointerIds];
|
||||||
uint8_t pointerId = [[unassignedPointerIds anyObject] intValue];
|
uint8_t pointerId = [[unassignedPointerIds anyObject] unsignedIntValue];
|
||||||
[pointerIdDict setObject:@(pointerId) forKey:@(memAddrValue)];
|
[pointerIdDict setObject:@(pointerId) forKey:@(memAddrValue)];
|
||||||
[activePointerIds addObject:@(pointerId)];
|
[activePointerIds addObject:@(pointerId)];
|
||||||
}
|
}
|
||||||
@@ -72,7 +71,7 @@
|
|||||||
|
|
||||||
// 从字典中获取UITouch事件对应的pointerId
|
// 从字典中获取UITouch事件对应的pointerId
|
||||||
// called in method of sendTouchEvent
|
// called in method of sendTouchEvent
|
||||||
- (uint32_t) retrievePointerIdFromDict:(UITouch*)touch{
|
- (uint8_t) retrievePointerIdFromDict:(UITouch*)touch{
|
||||||
return [[pointerIdDict objectForKey:@((uintptr_t)touch)] unsignedIntValue];
|
return [[pointerIdDict objectForKey:@((uintptr_t)touch)] unsignedIntValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,13 +86,11 @@
|
|||||||
CGFloat normalizedY = location.y / videoSize.height;
|
CGFloat normalizedY = location.y / videoSize.height;
|
||||||
uint8_t pointerId = [self retrievePointerIdFromDict:touch];
|
uint8_t pointerId = [self retrievePointerIdFromDict:touch];
|
||||||
|
|
||||||
_BoundaryReached = (normalizedX == 1.0f || normalizedX == 0.f || normalizedY == 1.0f || normalizedY == 0.f);
|
|
||||||
//if(_XBoundaryReached || _YBoundaryReached) LiSendTouchEvent(LI_TOUCH_EVENT_UP,pointerId, normalizedX, normalizedY, 0, 0, 0, 0);
|
if([NativeTouchPointer getPointerObjFromDict:touch].boundaryReached){ // access whether the current pointer has reached the boundary.
|
||||||
if(_BoundaryReached){
|
LiSendTouchEvent(LI_TOUCH_EVENT_UP, pointerId, normalizedX, normalizedY, 0, 0, 0, 0); //event must sent from the lowest level directy by LiSendTouchEvent to simulate continous dragging to another point on screen
|
||||||
LiSendTouchEvent(LI_TOUCH_EVENT_UP, pointerId, normalizedX, normalizedY, 0, 0, 0, 0);
|
LiSendTouchEvent(LI_TOUCH_EVENT_DOWN, pointerId, 0.3, 0.4, 0, 0, 0, 0);
|
||||||
LiSendTouchEvent(LI_TOUCH_EVENT_MOVE, pointerId, 0.5, 0.5, 0, 0, 0, 0);
|
}else LiSendTouchEvent(touchType, pointerId, normalizedX, normalizedY,(touch.force / touch.maximumPossibleForce) / sin(touch.altitudeAngle),0.0f, 0.0f,[streamView getRotationFromAzimuthAngle:[touch azimuthAngleInView:streamView]]);
|
||||||
}
|
|
||||||
else LiSendTouchEvent(touchType, pointerId, normalizedX, normalizedY,(touch.force / touch.maximumPossibleForce) / sin(touch.altitudeAngle),0.0f, 0.0f,[streamView getRotationFromAzimuthAngle:[touch azimuthAngleInView:streamView]]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
@@ -108,6 +105,7 @@
|
|||||||
for (UITouch* touch in touches){
|
for (UITouch* touch in touches){
|
||||||
if(activateCoordSelector) [NativeTouchPointer updatePointerObjInDict:touch];
|
if(activateCoordSelector) [NativeTouchPointer updatePointerObjInDict:touch];
|
||||||
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_MOVE];
|
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_MOVE];
|
||||||
|
[[NativeTouchPointer getPointerObjFromDict:touch] doesReachBoundary]; // execute the judging of doesReachBoundary for current pointer instance. (happens after the event is sent to Sunshine service)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,15 @@
|
|||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface NativeTouchPointer : NSObject
|
@interface NativeTouchPointer : NSObject
|
||||||
|
@property (nonatomic, assign) bool boundaryReached;
|
||||||
|
|
||||||
+ (void)initContextWithView:(StreamView *)view andNativeTouchHandler:(NativeTouchHandler*)handler;
|
+ (void)initContextWithView:(StreamView *)view;
|
||||||
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation;
|
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation;
|
||||||
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor;
|
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor;
|
||||||
|
|
||||||
|
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch;
|
||||||
|
- (bool)doesReachBoundary;
|
||||||
|
|
||||||
+ (void)populatePointerObjIntoDict:(UITouch*)touch;
|
+ (void)populatePointerObjIntoDict:(UITouch*)touch;
|
||||||
+ (void)removePointerObjFromDict:(UITouch*)touch;
|
+ (void)removePointerObjFromDict:(UITouch*)touch;
|
||||||
+ (void)updatePointerObjInDict:(UITouch *)touch;
|
+ (void)updatePointerObjInDict:(UITouch *)touch;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "NativeTouchPointer.h"
|
#import "NativeTouchPointer.h"
|
||||||
#import "NativeTouchHandler.h"
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
|
|
||||||
// native touch pointer ojbect that stores & manipulates touch coordinates
|
// native touch pointer ojbect that stores & manipulates touch coordinates
|
||||||
@@ -18,9 +17,10 @@ static NSMutableDictionary *pointerObjDict;
|
|||||||
static CGFloat pointerVelocityFactor;
|
static CGFloat pointerVelocityFactor;
|
||||||
static CGFloat pointerVelocityDivider;
|
static CGFloat pointerVelocityDivider;
|
||||||
static CGFloat pointerVelocityDividerLocationByPoints;
|
static CGFloat pointerVelocityDividerLocationByPoints;
|
||||||
static NativeTouchHandler* nativeTouchHandler;
|
static CGFloat screenHeightInPoints;
|
||||||
static CGFloat halfScreenHeightInPoints;
|
static CGFloat screenWidthInPoints;
|
||||||
static CGFloat halfScreenWidthInPoints;
|
static CGFloat fixedResetCoordX;
|
||||||
|
static CGFloat fixedResetCoordY;
|
||||||
|
|
||||||
StreamView *streamView;
|
StreamView *streamView;
|
||||||
|
|
||||||
@@ -32,15 +32,6 @@ StreamView *streamView;
|
|||||||
CGPoint previousRelativePoint;
|
CGPoint previousRelativePoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
|
|
||||||
pointerVelocityDivider = dividerLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
|
|
||||||
pointerVelocityFactor = velocityFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (instancetype)initWithTouch:(UITouch *)touch{
|
- (instancetype)initWithTouch:(UITouch *)touch{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
self->initialPoint = [touch locationInView:streamView];
|
self->initialPoint = [touch locationInView:streamView];
|
||||||
@@ -49,29 +40,44 @@ StreamView *streamView;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (bool)doesReachBoundary{
|
||||||
|
_boundaryReached = (pointerVelocityFactor > 1.0f) && (latestRelativePoint.x > screenWidthInPoints || latestRelativePoint.x < 0.0f || latestRelativePoint.y > screenHeightInPoints || latestRelativePoint.y < 0.0f); // boundary detection & coordinates reset to the central screen point for HK:StarTrail(needs a very high pointer velocity); // boundary detection & coordinates reset to the specific point for HK:StarTrail(needs a very high pointer velocity)
|
||||||
|
return _boundaryReached;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)updatePointerCoords:(UITouch *)touch{
|
- (void)updatePointerCoords:(UITouch *)touch{
|
||||||
previousPoint = latestPoint;
|
previousPoint = latestPoint;
|
||||||
latestPoint = [touch locationInView:streamView];
|
latestPoint = [touch locationInView:streamView];
|
||||||
previousRelativePoint = latestRelativePoint;
|
previousRelativePoint = latestRelativePoint;
|
||||||
if(nativeTouchHandler.BoundaryReached){ // reset
|
if(_boundaryReached){// boundary detection & coordinates reset to the central screen point for HK:StarTrail(needs a very high pointer velocity); // boundary detection & coordinates reset to specific point for HK:StarTrail(needs a very high pointer velocity)
|
||||||
previousRelativePoint.x = halfScreenWidthInPoints;
|
previousRelativePoint.x = fixedResetCoordX;
|
||||||
previousRelativePoint.y = halfScreenHeightInPoints;
|
previousRelativePoint.y = fixedResetCoordY;
|
||||||
}
|
}
|
||||||
latestRelativePoint.x = previousRelativePoint.x + pointerVelocityFactor * (latestPoint.x - previousPoint.x);
|
latestRelativePoint.x = previousRelativePoint.x + pointerVelocityFactor * (latestPoint.x - previousPoint.x);
|
||||||
latestRelativePoint.y = previousRelativePoint.y + pointerVelocityFactor * (latestPoint.y - previousPoint.y);
|
latestRelativePoint.y = previousRelativePoint.y + pointerVelocityFactor * (latestPoint.y - previousPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)initContextWithView:(StreamView *)view andNativeTouchHandler:(NativeTouchHandler*)handler {
|
+ (void)initContextWithView:(StreamView *)view {
|
||||||
streamView = view;
|
streamView = view;
|
||||||
nativeTouchHandler = handler;
|
screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
|
||||||
halfScreenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds])/2;
|
fixedResetCoordX = screenWidthInPoints * 0.3;
|
||||||
halfScreenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds])/2;
|
screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
|
||||||
|
fixedResetCoordY = screenHeightInPoints * 0.4;
|
||||||
pointerObjDict = [NSMutableDictionary dictionary];
|
pointerObjDict = [NSMutableDictionary dictionary];
|
||||||
pointerVelocityDividerLocationByPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]) * pointerVelocityDivider;
|
pointerVelocityDividerLocationByPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]) * pointerVelocityDivider;
|
||||||
NSLog(@"pointerVelocityDivider: %.2f", pointerVelocityDivider);
|
NSLog(@"pointerVelocityDivider: %.2f", pointerVelocityDivider);
|
||||||
NSLog(@"pointerVelocityDividerLocationByPoints: %.2f", pointerVelocityDividerLocationByPoints);
|
NSLog(@"pointerVelocityDividerLocationByPoints: %.2f", pointerVelocityDividerLocationByPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
|
||||||
|
pointerVelocityDivider = dividerLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
|
||||||
|
pointerVelocityFactor = velocityFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+ (void)populatePointerObjIntoDict:(UITouch*)touch{
|
+ (void)populatePointerObjIntoDict:(UITouch*)touch{
|
||||||
[pointerObjDict setObject:[[NativeTouchPointer alloc] initWithTouch:touch] forKey:@((uintptr_t)touch)];
|
[pointerObjDict setObject:[[NativeTouchPointer alloc] initWithTouch:touch] forKey:@((uintptr_t)touch)];
|
||||||
}
|
}
|
||||||
@@ -82,9 +88,13 @@ StreamView *streamView;
|
|||||||
if(pointer != nil){
|
if(pointer != nil){
|
||||||
[pointerObjDict removeObjectForKey:@(memAddrValue)];
|
[pointerObjDict removeObjectForKey:@(memAddrValue)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch{
|
||||||
|
return [pointerObjDict objectForKey:@((uintptr_t)touch)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+ (void)updatePointerObjInDict:(UITouch *)touch{
|
+ (void)updatePointerObjInDict:(UITouch *)touch{
|
||||||
[[pointerObjDict objectForKey:@((uintptr_t)touch)] updatePointerCoords:touch];
|
[[pointerObjDict objectForKey:@((uintptr_t)touch)] updatePointerCoords:touch];
|
||||||
}
|
}
|
||||||
@@ -99,6 +109,4 @@ StreamView *streamView;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
Reference in new issue
Block a user