簡體   English   中英

拉賈瓦利3d:繞樞軸點旋轉

[英]Rajawali 3d: Rotate around a pivot point

我一直在使用StreamingTexture在具有Alpha通道的屏幕上顯示視頻。 視頻的上半部分包含實際內容,下半部分包含Alpha頻道。

plane = new Plane(1, 2, 1, 1);//Plane height is 2 times the plane width due to the video size.
try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setLooping(true);
        Uri videoUrl = Uri.parse("android.resource://" + getContext().getPackageName() + "/"
                + R.raw.angel);
        mMediaPlayer.setDataSource(getContext(), Uri.parse(videoUrl.toString()));
        mMediaPlayer.prepareAsync();    //prepare the player (asynchronous)
        mMediaPlayer.setOnPreparedListener(mp -> {
            mp.start(); //start the player only when it is prepared
        });
    } catch (IOException e) {
        e.printStackTrace();
    }


    // create texture from media player video
    mVideoTexture = new StreamingTexture("video", mMediaPlayer);

    // set material with video texture
    Material material =
            new Material(new VertexShader(R.raw.custom_vertix_shader),
                    new FragmentShader(R.raw.custom_fragment_shader));
    material.setColorInfluence(0f);

    try {
        material.addTexture(mVideoTexture);
    } catch (ATexture.TextureException e) {
        e.printStackTrace();
    }
    plane.setMaterial(material);
    getCurrentScene().addChild(plane);

現在當我使用

plane.setRotation(Vector3.Axis.Z, angle); 

矩形平面尺寸(1、2)從中心(0.5、1)旋轉,這是應該的,但是由於視頻僅在上半部分顯示,因此看起來很奇怪。 看起來視頻從下半部分開始旋轉。

解決方案選項:

  1. 從(0.5,0.5)而不是(0.5,1)旋轉,但是沒有方法可以這樣做。

  2. 將平面的大小設置為1,1,然后裁剪視頻的下半部分,也沒有方法。

請提出我可以選擇的其他選項,或者是否有使用上述選項的解決方案。

我使用與第二個平面完全相同但不會旋轉的第二個平面實現了此功能。 然后,我使用第二個平面的坐標來計算旋轉后的正確位置值。

private void setPlanePosition() {

    double radius = (0.5 * plane2.getScaleY());
    double circleCenterX = plane2.getX();
    double circleCenterY = plane2.getY() - radius;

    double xNewValue = (plane2.getX()) - radius * Math.sin(Math.toRadians(angle));
    double yNewValue = plane2.getY() - radius * Math.cos(Math.toRadians(angle)) + radius;
    plane.setPosition(xNewValue, yNewValue, -10);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM