【Android介面實現】可旋轉的汽車3D模型效果的實現,android3d
轉載請註明出處:http://blog.csdn.net/zhaokaiqiang1992
今天要給大家介紹的是如何?可旋轉的汽車3D模型。
先看實現效果
這隻是靜態圖,實際上,這個模型是可以根據手勢進行旋轉的,效果還可以。
下面我說一下實現的原理。首先,這種3D模型的旋轉效果是通過切換不同的圖片完成的,在這個例子中,一共有52張圖片,展示了360度的旋轉效果,差不多每6度一張照片。然後,我們只需要監聽盛放圖片的ImageView的onTouch事件,完成圖片的切換就可以實現這種效果。
下面是幾張圖片的例子
下面,看一下代碼實現
package com.example.car3d;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageView;/** * * @ClassName: com.example.car3d.MainActivity * @Description: 3D汽車模型 * @author zhaokaiqiang * @date 2014-10-31 上午8:51:59 * */public class MainActivity extends Activity {protected static final String TAG = "MainActivity";// 當前顯示的bitmap對象private static Bitmap bitmap;// 圖片容器private ImageView imageView;// 開始按下位置private int startX;// 當前位置private int currentX;// 當前圖片的編號private int scrNum;// 圖片的總數private static int maxNum = 52;// 資源圖片集合private int[] srcs = new int[] { R.drawable.p1, R.drawable.p2,R.drawable.p3, R.drawable.p4, R.drawable.p5, R.drawable.p6,R.drawable.p7, R.drawable.p8, R.drawable.p9, R.drawable.p10,R.drawable.p11, R.drawable.p12, R.drawable.p13, R.drawable.p14,R.drawable.p15, R.drawable.p16, R.drawable.p17, R.drawable.p18,R.drawable.p19, R.drawable.p20, R.drawable.p21, R.drawable.p22,R.drawable.p23, R.drawable.p24, R.drawable.p25, R.drawable.p26,R.drawable.p27, R.drawable.p28, R.drawable.p29, R.drawable.p30,R.drawable.p31, R.drawable.p32, R.drawable.p33, R.drawable.p34,R.drawable.p35, R.drawable.p36, R.drawable.p37, R.drawable.p38,R.drawable.p39, R.drawable.p40, R.drawable.p41, R.drawable.p42,R.drawable.p43, R.drawable.p44, R.drawable.p45, R.drawable.p46,R.drawable.p47, R.drawable.p48, R.drawable.p49, R.drawable.p50,R.drawable.p51, R.drawable.p52 };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.imageView);// 初始化當前顯示圖片編號scrNum = 1;imageView.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:startX = (int) event.getX();break;case MotionEvent.ACTION_MOVE:currentX = (int) event.getX();// 判斷手勢滑動方向,並切換圖片if (currentX - startX > 10) {modifySrcR();} else if (currentX - startX < -10) {modifySrcL();}// 重設起始位置startX = (int) event.getX();break;}return true;}});}// 向右滑動修改資源private void modifySrcR() {if (scrNum > maxNum) {scrNum = 1;}if (scrNum > 0) {bitmap = BitmapFactory.decodeResource(getResources(),srcs[scrNum - 1]);imageView.setImageBitmap(bitmap);scrNum++;}}// 向左滑動修改資源private void modifySrcL() {if (scrNum <= 0) {scrNum = maxNum;}if (scrNum <= maxNum) {bitmap = BitmapFactory.decodeResource(getResources(),srcs[scrNum - 1]);imageView.setImageBitmap(bitmap);scrNum--;}}}
下載項目請到https://github.com/ZhaoKaiQiang/car3d
怎在pdf中將3D模型實現立體旋轉展示
那是用一些工程上專業的軟體轉的,比如solidworks、pro/E。同時你也可以用adobe acrobat來製做內嵌3D模型的pdf檔案。
#樓上的一堆廢話,實在可恨,看不過去了#
對一個物體拍攝多張個角度的相片,可以做一個3D模型?
可以,很簡單,不需要太多,方法如下:
1,準備工作:與物體對比明顯的單色背景,泛光源和點光源,旋轉檯,單反相機
2,拍攝工作:調整光源、物體,固定相機,固定焦距、焦點,轉動旋轉檯每隔15°拍攝一張
3,如果想呈現三自由度觀看,調整相機位置重複2步三次
4,專用軟體合成,有很多可以完成此項工作,推薦一個簡單的Panorama Maker。