coord reset for extremely high pointer velocity, core implementation
This commit is contained in:
@@ -14,10 +14,9 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NativeTouchHandler : UIResponder
|
||||
@property (nonatomic, assign) bool BoundaryReached;
|
||||
@property (nonatomic, assign) bool flipFlag;
|
||||
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -44,8 +44,7 @@
|
||||
|
||||
[NativeTouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
|
||||
[NativeTouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
|
||||
[NativeTouchPointer initContextWithView:self->streamView andNativeTouchHandler:self];
|
||||
_flipFlag = true;
|
||||
[NativeTouchPointer initContextWithView:self->streamView];
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -55,7 +54,7 @@
|
||||
uintptr_t memAddrValue = (uintptr_t)touch;
|
||||
unassignedPointerIds = [pointerIdPool mutableCopy]; //reset unassignedPointerIds
|
||||
[unassignedPointerIds minusSet:activePointerIds];
|
||||
uint8_t pointerId = [[unassignedPointerIds anyObject] intValue];
|
||||
uint8_t pointerId = [[unassignedPointerIds anyObject] unsignedIntValue];
|
||||
[pointerIdDict setObject:@(pointerId) forKey:@(memAddrValue)];
|
||||
[activePointerIds addObject:@(pointerId)];
|
||||
}
|
||||
@@ -72,7 +71,7 @@
|
||||
|
||||
// 从字典中获取UITouch事件对应的pointerId
|
||||
// called in method of sendTouchEvent
|
||||
- (uint32_t) retrievePointerIdFromDict:(UITouch*)touch{
|
||||
- (uint8_t) retrievePointerIdFromDict:(UITouch*)touch{
|
||||
return [[pointerIdDict objectForKey:@((uintptr_t)touch)] unsignedIntValue];
|
||||
}
|
||||
|
||||
@@ -87,13 +86,11 @@
|
||||
CGFloat normalizedY = location.y / videoSize.height;
|
||||
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(_BoundaryReached){
|
||||
LiSendTouchEvent(LI_TOUCH_EVENT_UP, pointerId, normalizedX, normalizedY, 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]]);
|
||||
|
||||
if([NativeTouchPointer getPointerObjFromDict:touch].boundaryReached){ // access whether the current pointer has reached the boundary.
|
||||
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_DOWN, pointerId, 0.3, 0.4, 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]]);
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
@@ -108,6 +105,7 @@
|
||||
for (UITouch* touch in touches){
|
||||
if(activateCoordSelector) [NativeTouchPointer updatePointerObjInDict:touch];
|
||||
[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;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,15 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NativeTouchPointer : NSObject
|
||||
@property (nonatomic, assign) bool boundaryReached;
|
||||
|
||||
+ (void)initContextWithView:(StreamView *)view andNativeTouchHandler:(NativeTouchHandler*)handler;
|
||||
+ (void)initContextWithView:(StreamView *)view;
|
||||
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation;
|
||||
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor;
|
||||
|
||||
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch;
|
||||
- (bool)doesReachBoundary;
|
||||
|
||||
+ (void)populatePointerObjIntoDict:(UITouch*)touch;
|
||||
+ (void)removePointerObjFromDict:(UITouch*)touch;
|
||||
+ (void)updatePointerObjInDict:(UITouch *)touch;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "NativeTouchPointer.h"
|
||||
#import "NativeTouchHandler.h"
|
||||
#include <Limelight.h>
|
||||
|
||||
// native touch pointer ojbect that stores & manipulates touch coordinates
|
||||
@@ -18,9 +17,10 @@ static NSMutableDictionary *pointerObjDict;
|
||||
static CGFloat pointerVelocityFactor;
|
||||
static CGFloat pointerVelocityDivider;
|
||||
static CGFloat pointerVelocityDividerLocationByPoints;
|
||||
static NativeTouchHandler* nativeTouchHandler;
|
||||
static CGFloat halfScreenHeightInPoints;
|
||||
static CGFloat halfScreenWidthInPoints;
|
||||
static CGFloat screenHeightInPoints;
|
||||
static CGFloat screenWidthInPoints;
|
||||
static CGFloat fixedResetCoordX;
|
||||
static CGFloat fixedResetCoordY;
|
||||
|
||||
StreamView *streamView;
|
||||
|
||||
@@ -32,15 +32,6 @@ StreamView *streamView;
|
||||
CGPoint previousRelativePoint;
|
||||
}
|
||||
|
||||
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
|
||||
pointerVelocityDivider = dividerLocation;
|
||||
}
|
||||
|
||||
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
|
||||
pointerVelocityFactor = velocityFactor;
|
||||
}
|
||||
|
||||
|
||||
- (instancetype)initWithTouch:(UITouch *)touch{
|
||||
self = [super init];
|
||||
self->initialPoint = [touch locationInView:streamView];
|
||||
@@ -49,29 +40,44 @@ StreamView *streamView;
|
||||
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{
|
||||
previousPoint = latestPoint;
|
||||
latestPoint = [touch locationInView:streamView];
|
||||
previousRelativePoint = latestRelativePoint;
|
||||
if(nativeTouchHandler.BoundaryReached){ // reset
|
||||
previousRelativePoint.x = halfScreenWidthInPoints;
|
||||
previousRelativePoint.y = halfScreenHeightInPoints;
|
||||
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 = fixedResetCoordX;
|
||||
previousRelativePoint.y = fixedResetCoordY;
|
||||
}
|
||||
latestRelativePoint.x = previousRelativePoint.x + pointerVelocityFactor * (latestPoint.x - previousPoint.x);
|
||||
latestRelativePoint.y = previousRelativePoint.y + pointerVelocityFactor * (latestPoint.y - previousPoint.y);
|
||||
}
|
||||
|
||||
+ (void)initContextWithView:(StreamView *)view andNativeTouchHandler:(NativeTouchHandler*)handler {
|
||||
+ (void)initContextWithView:(StreamView *)view {
|
||||
streamView = view;
|
||||
nativeTouchHandler = handler;
|
||||
halfScreenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds])/2;
|
||||
halfScreenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds])/2;
|
||||
screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
|
||||
fixedResetCoordX = screenWidthInPoints * 0.3;
|
||||
screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
|
||||
fixedResetCoordY = screenHeightInPoints * 0.4;
|
||||
pointerObjDict = [NSMutableDictionary dictionary];
|
||||
pointerVelocityDividerLocationByPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]) * pointerVelocityDivider;
|
||||
NSLog(@"pointerVelocityDivider: %.2f", pointerVelocityDivider);
|
||||
NSLog(@"pointerVelocityDividerLocationByPoints: %.2f", pointerVelocityDividerLocationByPoints);
|
||||
}
|
||||
|
||||
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
|
||||
pointerVelocityDivider = dividerLocation;
|
||||
}
|
||||
|
||||
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
|
||||
pointerVelocityFactor = velocityFactor;
|
||||
}
|
||||
|
||||
|
||||
+ (void)populatePointerObjIntoDict:(UITouch*)touch{
|
||||
[pointerObjDict setObject:[[NativeTouchPointer alloc] initWithTouch:touch] forKey:@((uintptr_t)touch)];
|
||||
}
|
||||
@@ -82,9 +88,13 @@ StreamView *streamView;
|
||||
if(pointer != nil){
|
||||
[pointerObjDict removeObjectForKey:@(memAddrValue)];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch{
|
||||
return [pointerObjDict objectForKey:@((uintptr_t)touch)];
|
||||
}
|
||||
|
||||
|
||||
+ (void)updatePointerObjInDict:(UITouch *)touch{
|
||||
[[pointerObjDict objectForKey:@((uintptr_t)touch)] updatePointerCoords:touch];
|
||||
}
|
||||
@@ -99,6 +109,4 @@ StreamView *streamView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user