Rajawali 3d:绕枢轴点旋转

时间:2017-06-19 10:59:55

标签: android 3d rotation rajawali

我一直在使用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并剪切视频的下半部分,也没有方法可以这样做。

  3. 请建议我可以选择哪些其他选项,或者是否有使用上述选项的解决方案。

1 个答案:

答案 0 :(得分:0)

我使用第二个平面实现了这个,该平面与第一个平面完全相同但不旋转。然后我使用第二个平面的坐标来计算旋转后的正确位置值。

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);
}
相关问题