使用min3d/Rajawali框架(Android)在3D对象上旋转时,可以通过以下步骤实现:
dependencies {
implementation 'org.rajawali3d:rajawali:1.1.309'
}
<org.rajawali3d.view.SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
public class MainActivity extends AppCompatActivity {
private GLSurfaceView mGLSurfaceView;
private MyRenderer mRenderer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGLSurfaceView = findViewById(R.id.surface_view);
mRenderer = new MyRenderer(this);
mGLSurfaceView.setEGLContextClientVersion(2);
mGLSurfaceView.setRenderer(mRenderer);
mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
public class MyRenderer extends RajawaliRenderer {
public MyRenderer(Context context) {
super(context);
}
@Override
protected void initScene() {
// 添加3D对象
Sphere sphere = new Sphere(1, 20, 20);
sphere.setMaterial(new Material());
sphere.setPosition(0, 0, -3);
getCurrentScene().addChild(sphere);
// 设置相机
getCurrentCamera().setPosition(0, 0, 6);
getCurrentCamera().setLookAt(sphere.getPosition());
}
}
}
public class MyRenderer extends RajawaliRenderer {
private Sphere mSphere;
public MyRenderer(Context context) {
super(context);
}
@Override
protected void initScene() {
// 添加3D对象
mSphere = new Sphere(1, 20, 20);
mSphere.setMaterial(new Material());
mSphere.setPosition(0, 0, -3);
getCurrentScene().addChild(mSphere);
// 设置相机
getCurrentCamera().setPosition(0, 0, 6);
getCurrentCamera().setLookAt(mSphere.getPosition());
}
@Override
protected void onRender(long elapsedRealTime, double deltaTime) {
super.onRender(elapsedRealTime, deltaTime);
// 在每一帧更新3D对象的旋转属性
mSphere.setRotY(mSphere.getRotY() + 1);
}
}
通过以上步骤,可以在min3d/Rajawali框架(Android)中实现3D对象的旋转。
领取专属 10元无门槛券
手把手带您无忧上云