2017-06-19 117 views
0

我一直在使用StreamingTexture在Alpha通道屏幕上显示视频。视频的上半部分有实际内容,下半部分包含Alpha通道。Rajawali 3D:围绕枢轴点旋转

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并剪切视频的下半部分,但没有办法做到这一点。

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

回答

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); 
}