Android 3D Game Development tutorial-Part I

Source: Internet
Author: User

The original Android 3D Game Development articles are from Martin, a German.
In droidnova.com, lixinso is translated into Chinese.

The first part first introduces OpenGL-related terms and guides you to start the first step of 3D development.

This series of 3D games is called Vortex.
.

This tutorial focuses on 3D programming. Other things, such as menus and program lifecycles, are part of the code but will not be mentioned here.

First, we will introduce the terminology of OpenGL.
Vertex

A vertex is a point in a 3D space and a basic element of many objects. In OpenGL, you can live less than two-dimensional coordinates (x, y) and four-dimensional coordinates (x, y, z, W ). the W axis is optional and the default value is 1.0. the Z axis is optional. The default value is 0. in this series, we will use three major coordinates x, y, and z, because W is generally used as placeholders. Vertices is the plural of vertex (this is important for non-native English speakers because it is prone to ambiguity ). All objects use vertices as their vertices, because vertex is the vertex.

Triangle triangle

A triangle can be created only at three points. Therefore, in OpenGL, we use three vertices to create a triangle.

Polygon

A polygon is an object composed of at least three connected points. A triangle is also a polygon.

Primitives

A primitive is a three-dimensional object created using a triangle or polygon. In terms of image, a very fine Model With 50000 vertices is a primitive, and a low model with only 500 vertices is also called a primitive.

Now we can start to change.

Create a project and submit it to vortex. This is also the name of activity. Our project should look like this:

As shown in, we have added a view. Let's take a look at the vortexview class.

As shown above, we inherit glsurfaceview because it will help us draw 3D images. Next, let's look at the vortexrenderer class. A Renderer contains everything necessary to draw a frame. Reference from references
.

Renderer is responsible for the OpenGL call to render a frame.

Let's take a look at this class. :

 

Okay. What have we done?

First, we implemented the glsurfaceview. Renderer interface, mainly implementing three methods: onsurfacecreated (), onsurfacechanged () and ondrawframe (). These methods are easy to understand. The first method is called after the surface is created, and the second method is called after the surface is changed. For example, when switching from a portrait screen to a landscape screen, the last method is to call a drawing method at any time.

From row 11 to row 13, we use floating point numbers to define each color in the RGB color system.

In the 28 rows, we use the glclearcolor () method to define the background color. The background color is behind all the things we can see, so all things behind the background color are invisible. It can be imagined that this kind of thing is thick fog, blocking all things. Then we will set a distance for it to show how it is used. Then you will understand how it exists.

To make the color changes visible, we must call glclear () and the color buffer mask to clear the buffer, and then use a new background color for our background color.
To see that it is working, we create a response for the motionevent and use it to change the color. First, create a color setting function in vortexrenderer.

The following describes the methods created in the vortexview class to process motionevent.

We have created an anonymous runnable object. Here, the run () method calls the setcolor method in Renderer. This will make some small calculations based on the motionevent coordinates.

Now we have a small program to use OpenGL to change our background color.
In German, we call this small case "mit kanonen auf spatzen schie ß en". The translation should be "you killed a fly on the wheel ". This is just right. This is just the smallest example. To learn OpenGL, you need to prepare more and more.

This part finally mentions the OpenGL Documentation for OpenGL.
. Although this item is not highly usable, it is at least a document.

Download the Eclipse project source code here (original address): vortex Part I

Here are several:

Related Article

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.