0
비트 맵 이미지를 내 모션 이벤트의 이동 방향에 따라 회전하려고하는 중입니다. 톱 뷰에서 자동차 이미지를 가지고 있습니다. 차가 내 움직임의 방향으로 향하게합니다. 메신저는 180의 degress를 켜고해야 우 이동하는 경우, 그것은 90에 설정해야 등등, PLS 내 나쁜 영어를 excuss, IV는 이미지가 방법에서 중심비트 맵을 이동 방향으로 회전
//this is how i rotate
double ComputeAngle(float x, float y){
final double RADS_TO_DEGREES = 360/(Math.PI * 2);
double result = Math.atan2(y,x) * RADS_TO_DEGREES;
if (result < 0){
result = 360 + result;
}
return result;
}
//bitmap to rotate pretend its a car from top view
Bitmap bitmap;
//draws bitmap
private final RectF tmpRF = new RectF();
final void drawStrokePoint(Canvas c, float x, float y, float r) {
tmpRF.set(x-r,y-r,x+r,y+r);
//compute rotation
float rotation = (float)ComputeAngle(x, y);
Matrix matrix = new Matrix();
matrix.postTranslate(-bitmap.getWidth()/2, -bitmap.getHeight()/2);
matrix.postRotate(rotation);
matrix.postTranslate(x, y);
//draw bitmap
c.drawBitmap(mAirbrushBits, matrix, null);
}
//get x y cords and draw at x y position
@Override
public boolean onTouchEvent(MotionEvent event)
{
float x = event.getX();
float y = event.getY();
switch (event.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
strokeX = x;
strokeY = y;
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_MOVE:
drawStrokePoint(drawCanvas, x, y, currentWidth);
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
}
return true;
}
감사를 너무 빨리 재생, 나는, PLZ 내 영어 감사를 용서 것을 내가 어떻게해야합니까 oldx, 오래된 Y와 조금 혼란 스러워요 –