-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


, 03 2017 . 21:37 +
! - - Flash. : , . , , .

. .



1: . 2: ( ).

: .

: :

canvas.drawRect(x1, y1, x2, y2, paint);

.

public boolean isTouched(float x, float y){
    return (x>x1)&&(xy1)&&(ycode>

: .

Path path = new Path();
paint.setStyle(Paint.Style.FILL);
path.moveTo(x1, y1);
path.lineTo(x2, y2);
path.lineTo(x3, y3);
.....
path.lineTo(x1, y1); // 
path.close();
canvas.drawPath(path, paint);

. , :

.



.



, . .

.

private boolean isLeftHandSituated(float dotX, float dotY, float x1, float y1, float x2, float y2){
    float d = (dotX - x1) * (y2 - y1) - (dotY - y1) * (x2 - x1);
    return d>0;
}

, ( BC) , .

3: . , . (distance) :

float dx = dotX - smileX;
float dy = dotY - smileY;
double distance = Math.sqrt((dx * dx + dy * dy));

. ? ( ) . . speed.



:

private float speed=5;
double rate = speed / distance;
newSmileX = smileX + (float) (dx * rate);
newSmileY = smileY + (float) (dy * rate);

4: . ? . atan2.

float dx = dotX - cannonX;
float dy = dotY - cannonY;
double theta = Math.atan2(dx, dy); //   
angle = Math.toDegrees(theta); //   .

: , , , . !
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/334848/


: [1] []
 

:
: 

: ( )

:

  URL