有谁能在模拟手表样本中解释表盘的这种逻辑吗?



嗨,我正在看模拟手表的样本。在onDraw方法中,我遇到了这个逻辑

 @Override
    public void onDraw(Canvas canvas, Rect bounds) {
        mTime.setToNow();
        // Draw the background.
        if (isInAmbientMode()) {
            canvas.drawColor(Color.BLACK);
        } else {
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
        }
        // Find the center. Ignore the window insets so that, on round watches with a
        // "chin", the watch face is centered on the entire screen, not just the usable
        // portion.
        float centerX = bounds.width() / 2f;
        float centerY = bounds.height() / 2f;
        float secRot = (mTime.second / 30f) * (float) Math.PI;
        int minutes = mTime.minute;
        float minRot = minutes / 30f * (float) Math.PI;
        float hrRot = ((mTime.hour + (minutes / 60f)) / 6f) * (float) Math.PI;
        float secLength = centerX - 20;
        float minLength = centerX - 40;
        float hrLength = centerX - 80;
        if (!mAmbient) {
            float secX = (float) Math.sin(secRot) * secLength;
            float secY = (float) -Math.cos(secRot) * secLength;
            canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mHandPaint);
        }
        float minX = (float) Math.sin(minRot) * minLength;
        float minY = (float) -Math.cos(minRot) * minLength;
        canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mHandPaint);
        float hrX = (float) Math.sin(hrRot) * hrLength;
        float hrY = (float) -Math.cos(hrRot) * hrLength;
        canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHandPaint);
    }

我不明白这几行是什么意思

float secRot = (mTime.second / 30f) * (float) Math.PI;
    int minutes = mTime.minute;
    float minRot = minutes / 30f * (float) Math.PI;
    float hrRot = ((mTime.hour + (minutes / 60f)) / 6f) * (float) Math.PI;

它似乎在试图计算每个手的旋转角度。它的秒针和分针是独立运动的,但时针的运动也依赖于分针。在"12:30"时,时针应该在12和1之间。

相关内容

  • 没有找到相关文章

最新更新