Created
September 16, 2022 07:14
-
-
Save daddyYukio/837dc130d13b23c20a76ed445e68cc19 to your computer and use it in GitHub Desktop.
スマホでVR写真表示アプリを作る(Xamarin) - OpenGLView OnTouchEvent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __ANDROID__ | |
public override bool OnTouchEvent(MotionEvent e) | |
{ | |
base.OnTouchEvent(e); | |
if (e.Action == MotionEventActions.Down) | |
{ | |
prevx = e.GetX(); | |
prevy = e.GetY(); | |
} | |
if (e.Action == MotionEventActions.Move) | |
{ | |
float e_x = e.GetX(); | |
float e_y = e.GetY(); | |
float xdiff = (prevx - e_x); | |
float ydiff = (prevy - e_y); | |
_viewAngleX += 90.0f * xdiff / (float)Size.Width; | |
_viewAngleY -= 90.0f * ydiff / (float)Size.Height; | |
while (_viewAngleX >= 360) _viewAngleX -= 360; | |
while (_viewAngleX < 0) _viewAngleX += 360; | |
_viewAngleY = Math.Max(-80, _viewAngleY); | |
_viewAngleY = Math.Min(80, _viewAngleY); | |
prevx = e_x; | |
prevy = e_y; | |
SetupProjection(); | |
RenderSphere(); | |
} | |
return true; | |
} | |
#endif | |
#if __IOS__ | |
public override void TouchesBegan(NSSet touches, UIEvent e) | |
{ | |
var touch = (UITouch)e.TouchesForView(this).AnyObject; | |
CGPoint pt = touch.LocationInView(this); | |
prevx = (float)pt.X; | |
prevy = (float)pt.Y; | |
} | |
public override void TouchesMoved(NSSet touches, UIEvent e) | |
{ | |
var touch = (UITouch)e.TouchesForView(this).AnyObject; | |
CGPoint pt = touch.LocationInView(this); | |
float e_x = (float)pt.X; | |
float e_y = (float)pt.Y; | |
float xdiff = (prevx - e_x); | |
float ydiff = (prevy - e_y); | |
_viewAngleX += 90.0f * xdiff / (float)Size.Width; | |
_viewAngleY -= 90.0f * ydiff / (float)Size.Height; | |
while (_viewAngleX >= 360) _viewAngleX -= 360; | |
while (_viewAngleX < 0) _viewAngleX += 360; | |
_viewAngleY = Math.Max(-80, _viewAngleY); | |
_viewAngleY = Math.Min(80, _viewAngleY); | |
prevx = e_x; | |
prevy = e_y; | |
SetupProjection(); | |
RenderSphere(); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment