[Android interface implementation] implementation of a rotated 3D car model, android3d
Reprinted please indicate the source: http://blog.csdn.net/zhaokaiqiang1992
Today we will introduce how to implement a rotated 3D car model.
First look at the Implementation Effect
This is only a static graph. In fact, this model can be rotated Based on gestures, and the effect is also acceptable.
The following describes the implementation principles. First, the rotation effect of this 3D model is completed by switching different images. In this example, a total of 52 images are displayed, showing the rotation effect of 360 degrees, almost every 6 degrees. Then, we only need to listen to the onTouch event of the ImageView that holds the image. This effect can be achieved after switching the image.
The following is an example of several images.
Next, let's take a look at the code implementation
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 car model * @ author zhaokaiqiang * @ date 8:51:59 **/public class MainActivity extends Activity {protected static final String TAG = "MainActivity "; // The currently displayed bitmap object private static Bitmap bitmap; // The image container private ImageView imageView; // start to press the position private int startX; // The current position private int currentX; // Number of the current image private int scrNum; // total number of images private static int maxNum = 52; // resource image set 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. drawable. p22, R. drawable. p23, R. drawable. p24, R. drawable. p25, R. drawable. p26, R. drawable. p2, 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. spO2, 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); // initialize the currently displayed Image number 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 (); // determines the sliding direction of the gesture, and switches the image if (currentX-startX> 10) {modifySrcR ();} else if (currentX-startX <-10) {modifySrcL ();} // reset start position startX = (int) event. getX (); break;} return true ;}}) ;}// slide to the right to modify the resource private void modifySrcR () {if (scrNum> maxNum) {scrNum = 1 ;} if (scrNum> 0) {bitmap = BitmapFactory. decodeResource (getResources (), srcs [scrNum-1]); imageView. setImageBitmap (bitmap); scrNum ++; }}// slide to the left to modify the resource private void modifySrcL () {if (scrNum <= 0) {scrNum = maxNum ;} if (scrNum <= maxNum) {bitmap = BitmapFactory. decodeResource (getResources (), srcs [scrNum-1]); imageView. setImageBitmap (bitmap); scrNum --;}}}
Download project to https://github.com/ZhaoKaiQiang/car3d
How to display 3D models in a three-dimensional rotation mode in pdf
It was converted with some professional engineering software, such as solidworks and pro/E. You can also use adobe acrobat to create PDF files embedded with 3D models.
# A bunch of nonsense upstairs, it's really hateful. I can't see it anymore #
How can I create a 3D model for taking multiple angles of an object?
Yes, it is very simple. There is no need for too much. The method is as follows:
1. Preparation: A monochrome background with obvious contrast with an object, a pan-light source and a point light source, a rotating unit, and a SLR camera
2. Shooting: Adjust the light source, object, fixed camera, fixed focal length and focus, and rotate the rotating station to take a picture at every 15 °.
3. If you want to display a three-degree view, adjust the camera position and repeat it two or three times.
4. Specialized software synthesis. Many of them can do this. We recommend a simple Panorama Maker.