A preliminary study on Unity3d game development-2. Preliminary understanding of 3D model Basics

Source: Internet
Author: User

First, what is a 3D model? 1.1 3D Model Overview

In short, 3D model is three-dimensional , three-dimensional model, D is the abbreviation of English Dimensions .

3D models can also be said to be built with 3Ds Max stereoscopic model, including a variety of buildings, people, vegetation, machinery and so on, such as a building 3D model diagram. The 3D model also includes the field of toys and computer modelling.

The form of the internet has always been 2D mode, but with the continuous progress of 3D technology, in the future, more and more Internet applications will be presented to users in the form of web video, electronic reading, online games, virtual community, e-commerce, distance education and so on. Even for the tourism industry, 3D Internet can also play a role, some of the world's attractions, sculptures, antiques will be on the Internet in the form of the user experience, this experience is much more real shock than the current 2D environment.

1.2 How to build a 3D modelThere are three main types of 3D models: ① building 3D models with artificial software: This approach requires operators to have a wealth of professional knowledge, skilled use of modeling software, and the operation of complex, long cycle, while the final component of the 3D model is not strong sense of reality; ② three-dimensional scanners build 3D models: This approach requires hardware devices such as expensive three-dimensional scanners. Moreover, the three-dimensional scanner can only obtain the position information of the object now, most of the texture features of the surface of the object still need to assist a lot of manual work to complete. The whole process cost is high, the period is long; ③ building 3D models based on images: This method only needs to provide a set of objects of different angles of the sequence of photos in the computer-assisted automatic generation of objects 3D model. Simple operation, high degree of automation, low cost, strong sense of reality. Ii. Fundamentals of 3D models in Unity 2.1 understanding game Objects

(1) I believe that we have passed the previous blog "Unity3d Game development"-1. Cross-platform game engine let. NET programmer freshmen "after the initial understanding of Unity3d, the hierarchy in the game objects have a preliminary understanding of it." Hierarchy shows the gameobject-game object, each game has at least one camera, click on camera to see the camera in Preview view screen view.

(2) Each gameobject has three groups of properties:Position(position),Rotation(rotation, angle), and scale (smaller) three groups of properties. Position controls the coordinates of the game object in three-dimensional space, rotation controls the angle of the game object display, and the scale controls the scaling of the game object.

2.2 Understanding the left-hand coordinate system

The Unity3d uses a left-handed coordinate system: the X-axis along the screen, the y-axis along the screen, and the z-axis in the vertical screen direction. Right, top, and back to the audience of the three direction is the positive direction . It may not be clear, but it's okay, let's take a look at the common coordinate system types for space geometry.

  ① Space Cartesian coordinate system

The space point O for the origin, the establishment of three 22 vertical axis, x-axis (horizontal), y-axis (longitudinal), z-axis (vertical axis), at this time the establishment of a spatial Cartesian coordinate system oxyz, where Point o is called the coordinates of the origin , three axis is called Axis , the plane called the coordinate plane determined by the axis.

The order between the axes requires the right-hand rule , that is, holding the z-axis in the right hand, so that the right hand four refers from the positive direction of the x-axis to the positive of the y-axis at a 90-degree angle, when the thumb refers to the z-axis forward. Such a coordinate system of three axes is called right-hand space Cartesian coordinate system. Corresponding to this is the left-hand space Cartesian coordinate system.

Generally, the right-hand space Cartesian coordinate system is more commonly used in mathematics, which is different in other disciplines because of its convenient application. Any two of the three axes can determine a plane, called the coordinate plane. They are x o y planes determined by X-and Y-axes, y-oZ-planes determined by the y-axis and z-axis, and X-o-Z planes determined by the x-axis and z-axis.

These three mutually perpendicular coordinate planes divide the space into eight parts, each of which is called a gua. The GUA limit in the positive half axis of the x, Y, Z axis is called the first Gua limit, from the first Gua limit, in the Xoy plane above the gua limit, according to the counter-clockwise direction is called the second, three, four-gua limit; the first, two, three, four-gua limit is called the next five, six, seven, gossip limit

  ② right-hand coordinate system

The right-handed coordinate system is often used when studying spatial geometry in secondary school. In a three-dimensional coordinate system, the positive axis direction of the z axis is determined by the right hand rule. The right-hand rule also determines the positive rotation direction of any axis in a three-dimensional space. To label the positive axes of the x, y, and z axes, place the right hand back to the screen, and the thumb points to the positive direction of the x-axis. Extend the index finger and middle finger, as shown, the index finger points to the positive direction of the Y axis, the direction indicated by the middle finger is the positive direction of the Z axis. To determine the positive rotation direction of the shaft, as shown, use your right thumb to point to the positive direction of the axis and bend your finger. Then the direction indicated by the finger is the positive rotation direction of the axis.

③ left-handed coordinate system

Extend the left hand, let the thumb and forefinger into an "L" shape, thumb right, forefinger upward. The rest of the fingers point to the front. As shown, this establishes a left-handed coordinate system. The thumb, forefinger, and remaining fingers represent the positive direction of the X, Y, Z axis. Judging method: In the space right angle coordinate system, let the left thumb point to the positive direction of the x-axis, the index finger to the positive direction of the y-axis, if the middle finger can point to the positive direction of the z axis, the coordinate system is called the left-angle coordinate system. The inverse is the right-hand Cartesian coordinate system.

  Comparison of ④ left-handed coordinate system and right-handed coordinate system

The left-hand coordinate system is the x-axis to the right, the y-axisupward, the Z-axis forward, the z-axis of the right-hand coordinate system is the opposite, is pointing to "self ", in the computer usually uses the left-handed coordinate system, and mathematics usually uses the right-hand In fact, many of the computer also useful right-handed coordinate system, this is based on the actual application of different, did not say which is better.

Now, I believe that you have at least a left-handed coordinate system has a comparative image of the understanding, then the purpose of the introduction here is achieved. (Stickers for trouble, huh?)

2.3 Meet Vector3

If we have a heart, we will find that in the first blog in the code written in the reference to a Vector3 class, then what is this class used to do? Let's take a look at the preliminary.

Vector3 is a class defined in unity that contains X, Y, and Z three fields that can represent a location point or a vector .

Vector3 times the numeric value to multiply the three values of the vector by the corresponding values, assuming that v1,v2 is two vectors, the v1-v2 represents a vector from V2 to V1, as shown in. extension : Back when we were doing a box game, when a small ball was launched into a designated area, it was a typical application of vector subtraction. It is known that the ball is in the camera position (that is, a vector of the camera, assuming that it is V2), and the position of the mouse point coordinates (that is, the target ground vector, assuming it is V1), through the v1-v2 can be emitted by the specific direction of the vector (equivalent to tell the ball to which target direction to launch!) )。

Third, learn to go before learning to fly-the second Unity3d program

In the Hellocube program in the first blog post, we let Cube flip. This time, we moved the cube back and forth to let the game object learn to "walk" the skill.

(1) Create a cube (cube) in hierarchy, and add a direction light (parallel), and then set the cube's Position property to (0,0,-4) so that the lens is closer. ; Set the scale property of Cube to (1,1,1) so that cube zooms in a bit;

(2) Add a C # Script to project and take a name, named: Cubecontroller. Double-click the script and enter the following code in the Update method:

View Code

(3) Click the Preview button: Press the keyboard up key, Cube will move forward; press down key, Cube will move backwards;

  

Iv. case in Depth: The Earth revolves around the sun

With the above basic 3D theoretical Foundation, let's do a unity3d small case: The Earth revolves around the sun . The so-called Earth revolves around the sun, referring to the Earth's cyclical rotation around the sun. (If you ask why the Earth revolves around the sun, ask Mr. Copernicus and the Newton Children's shoes)

  

(1) First create the following game objects: Two sphere, a direction light; and one sphere named Earth, the other sphere named Sun; set Sun's scale to (3,3,3), Let the sun this big sphere appear bigger, and the Earth's position set to (5,0,0), let Earth show on the right side of the sun;

(2) In order to make the sun more like the sun, we create a material in project (material, the so-called material is to modify the game object), named Sunmaterial, here is mainly for the sun to add a color.

With Sunmaterial selected, double-click Main color, pop up the Color picker, and select a dark yellow area in the color picker.

(3) to make the earth a little more like Earth, here we add a background image to Earth-the Earth map. (You can search from the Internet, or download the URL given at the bottom of this article), drag the Earth map to the project, and finally drag the map onto the Earth object. The final effect is as shown.

(4) Add a C # Script, named Earthcontrol. Double-click the script file to write the following code in the editor. It is important to note that commonly used game objects are generally set to global variables and initialized in the Start method (this is obtained through Gameobject's Find static method, which you can understand as JavaScript dom manipulation getElementById ("Earth "))。 The transform component of the game object controls the position, rotation, and scaling of the object.

View Code

PS: Use the Rotatearound () method to let the Earth always revolve around the sun in the y-axis direction. The parameter 1 represents the position around the rotation reference point (the position of the sun), the parameter 2 represents the angle around the rotation, vector3.up is the Y axis rotation, and the parameter 3 represents the speed of the rotation (long type, the greater the faster).

(5) After the script is written, drag the script onto Earth to bind. Finally, click the Preview button to see the effect of the earth turning around the sun.

  

V. Summary

This article mainly introduces the game development in some of the 3D Model Foundation, involves a little secondary school space Geometry knowledge, review for follow-up study will be beneficial. The physics engine and GUI are explored later, but only initially. Finally, I still thank the author of the reference, standing on your shoulders I can see farther, thank you!

References and literature

(1) 3D model Baidu Encyclopedia: http://baike.baidu.com/link?url= Dfgpg-8l3efnqybygkrse-0fwd3oye2jckyqmyhv8mfxrylijym0-nsnkekjmq0rtgzc5ir6zdbnl0srzyxsnk

(2) Bubble Hall, left-hand coordinate system and right-hand coordinate system: http://www.cnblogs.com/mythou/p/3327046.html

(3) Space Cartesian coordinate system courseware: http://wenku.baidu.com/link?url= 3RPRMVEZIU8BEQGIFAXW3W4HNMHV0ZJCEVUKVEEVAWYMACIL5SRVAMZC4WWN9XUARVNXICYWQIDZHCQSY8BGY0TLGZIZWLJ7QMXOJNWVW2U (4) Analysis of Unity3d class Vector3:http://wenku.baidu.com/link?url= YKVWCRBXJEALMC55FXHRVBG-AUKDLLZNAZQB7YKDSLCY1RSCGIDCZBFNAUSCO4RWNG3L3ZPH8CJYUQ52LPFN3PJDWRBHLGEAYWAUDYXSJH (5) Wisdom Podcast Unity3d Public Commencement: Http://net.itcast.cn/subject/Unity3D/index.html Accessories (1) Earth map: HTTP://PAN.BAIDU.COM/S/1C069VVQ

Zhou Xurong

Source: http://www.cnblogs.com/edisonchou/

The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to give the original link.

A preliminary study on Unity3d game development-2. Preliminary understanding of 3D model Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.