Android 3D物体的碰撞——正方体的碰撞


3D物体的碰撞和2D类似,都是根据坐标来计算物体的距离,判断是否碰撞。下面举个简单的列子吧,我这个列子比较局限,简单,只是为了说明这个方法而已,大家可以参照方法进行改进,下面看看代码吧。

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:id="@+id/main_liner"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent">  
  7. </LinearLayout>  
  1. package yy.cal;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.widget.LinearLayout;  
  6.   
  7. public class GLSurfaceViewActivity extends Activity {  
  8.     private MySurfaceView mSurfaceView;//声明MySurfaceView对象  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.main);       
  12.         mSurfaceView=new MySurfaceView(this);//创建MySurfaceView对象  
  13.         mSurfaceView.requestFocus();//获取焦点  
  14.         mSurfaceView.setFocusableInTouchMode(true);//设置为可触控  
  15.         LinearLayout ll=(LinearLayout)this.findViewById(R.id.main_liner);//获得线性布局的引用  
  16.         ll.addView(mSurfaceView);  
  17.     }  
  18.     @Override  
  19.     protected void onPause() {  
  20.         // TODO Auto-generated method stub  
  21.         super.onPause();  
  22.         mSurfaceView.onPause();  
  23.     }  
  24.     @Override  
  25.     protected void onResume() {  
  26.         // TODO Auto-generated method stub  
  27.         super.onResume();  
  28.         mSurfaceView.onResume();  
  29.     }    
  30. }  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 下一页

相关内容