这几天在Android项目中需要加载三维模型,找了多种方法,最后决定使用jpct引擎。话不多说,上代码。
一、代码解析
首先创建一个活动MainActivity,活动布局如下:
包括五个button,一个ImageView作为背景,一个GLSurfaceView显示模型,布局代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBg"/>
<android.opengl.GLSurfaceView
android:id="@+id/surfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dip"
android:orientation="vertical">
<Button
android:id="@+id/btnLoadModel"
android:layout_width="match_parent"
android:layout_height="60dip"
android:text="loadModel"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dip"
android:orientation="horizontal">
<Button
android:id="@+id/btnLeft"
android:layout_width="180dip"
android:layout_height="60dip"
android:text="left"/>
<Button
android:id="@+id/btnRight"
android:layout_width="180dip"
android:layout_height="60dip"
android:text="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dip"
android:orientation="horizontal">
<Button
android:id="@+id/btnTop"
android:layout_width="180dip"
android:layout_height="60dip"
android:text="top"/>
<Button
android:id="@+id/btnDown"
android:layout_width="180dip"
android:layout_height=