[英]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)旋转,这是应该的,但是由于视频仅在上半部分显示,因此看起来很奇怪。 看起来视频从下半部分开始旋转。
解决方案选项:
从(0.5,0.5)而不是(0.5,1)旋转,但是没有方法可以这样做。
将平面的大小设置为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.