Skip to content

Commit

Permalink
added ios tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
HEAVYPOLY committed Sep 5, 2024
1 parent 72c3dfb commit 50f5736
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion platform/iphone/godot_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGFloat force = touch.force;

if (touch.type == UITouchTypeStylus) {
OSIPhone::get_singleton()->pencil_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, force);
CGVector azimuth = [touch azimuthUnitVectorInView:self];
// CGFloat altitudeAngle = (1.0 - ((3.14159/2.0) / [touch altitudeAngle])) / 3.14159;
OSIPhone::get_singleton()->pencil_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, force, -azimuth.dx , -azimuth.dy);
} else {
OSIPhone::get_singleton()->touch_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor);
}
Expand Down
2 changes: 1 addition & 1 deletion platform/iphone/os_iphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class OSIPhone : public OS_Unix {
virtual int get_screen_dpi(int p_screen = -1) const;
virtual float get_screen_refresh_rate(int p_screen = -1) const;

void pencil_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick, float p_tilt_x, float p_tilt_y);
void pencil_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick);
void touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick);
void pencil_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, float p_force, float p_tilt_x, float p_tilt_y);
void touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y);
Expand Down
5 changes: 2 additions & 3 deletions platform/iphone/os_iphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,14 @@
perform_event(ev);
};

void OSIPhone::pencil_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick, float p_tilt_x, float p_tilt_y) {
void OSIPhone::pencil_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick) {
Ref<InputEventMouseButton> ev;
ev.instance();
ev->set_button_index(1);
ev->set_pressed(p_pressed);
ev->set_position(Vector2(p_x, p_y));
ev->set_global_position(Vector2(p_x, p_y));
ev->set_doubleclick(p_doubleclick);
ev->set_tilt(Vector2(p_tilt_x, p_tilt_y));
perform_event(ev);
}

Expand All @@ -293,7 +292,7 @@
}

void OSIPhone::pencil_cancelled(int p_idx) {
pencil_press(p_idx, -1, -1, false, false, 0, 0);
pencil_press(p_idx, -1, -1, false, false);
}

void OSIPhone::touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick) {
Expand Down

0 comments on commit 50f5736

Please sign in to comment.