Skip to content

Instantly share code, notes, and snippets.

@daddyYukio
Created September 16, 2022 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daddyYukio/837dc130d13b23c20a76ed445e68cc19 to your computer and use it in GitHub Desktop.
Save daddyYukio/837dc130d13b23c20a76ed445e68cc19 to your computer and use it in GitHub Desktop.
スマホでVR写真表示アプリを作る(Xamarin) - OpenGLView OnTouchEvent
#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