On the design of interactive virtual 3D environment

On the design of interactive virtual 3D environment

O Introduction

Virtual reality refers to a virtual environment generated by a computer, which enables people to enter a three-dimensional, multimedia virtual world, interact with virtual objects in it through some operation interfaces, and then cooperate with various sensors and mechanical parts. Bring people an immersive feeling. With the development of computer hardware and software and the enhancement of graphics processing capabilities, the application of virtual reality technology in military, medical, educational, industrial, and gaming has become more and more extensive.

The virtual three-dimensional environment is an extremely important part of the virtual reality technology. Although it can be produced with a ready-made three-dimensional engine, most of the three-dimensional engines are expensive, and they are mainly oriented to the three-dimensional game market. Therefore, if the problem to be solved is not particularly complicated, it can be done by programming and using some tool software.

1 Development environment and software

1.1 Microsoft Visual C ++ 6.0

Microsoft Visual C ++ 6.0 (hereinafter referred to as vC ++ 6.0) is one of the powerful visual development platforms produced by Microsoft. We can use it to complete the creation and coding of application programs on the Windows operating system. , Testing, improvement and other stages of work.

I. 2 OpenGL

OpenGL (Open Graphics Library) is a 3DAPI, which is independent of the hardware system and operating system. It is a cross-platform "software interface for graphics hardware" and has a high degree of portability. It includes a large number of drawing and display functions, used to quickly create real-time 3D graphics, mainly used in the graphics professional field, has become an industry standard, the current latest version is OpenGL2.0.

1.3 3dsmax 7

3ds max 7 is a software for making 3D models and animations produced by Autcdesk. Using it, you can create various 3D models and animations such as vivid characters, animals, plants and buildings. We use 3ds max 7 to make some 3D models of animals, plants and buildings, and export them as 3ds files, and then call them in the virtual three-dimensional environment.

1. 4 Vue 5 Infinite

Vue5 Infinite (hereinafter referred to as vue5) is produced by e-on software company, it can also be used to make 3D models and animations, its specialty lies in the simulation of 3D natural environment. In the virtual three-dimensional environment, the realism of the sky is one of the important factors that affect the visual effect. We use the environment simulation function of Vue5 to make pictures of the sky under various atmospheric conditions, and then use these pictures as the virtual three-dimensional environment. The texture map of the "sky box" shows a realistic atmospheric environment effect. In addition, we can also use Vue5's powerful terrain editing function to create some terrain models with different characteristics to enrich the virtual 3D scene.

2 Production of 3D models in virtual scenes

2.1 Sky box model

We use tools such as 3ds max 7 to make elements such as 3D models in virtual three-dimensional scenes. First, start with the sky, open 3ds max 7, create a cube, adjust its side length to a relatively large value (such as 2000 meters). We call this cube the sky box. Then make a texture map of the sky box, which is a picture of the atmospheric environment. Open Vue5, select the "Manned Atmosphere" option, and then select the atmospheric environment you need from the pop-up dialog box (of course, you can also use its editing function to create the atmospheric effect you want), and then click the File menu "Export sky" option, export the atmospheric environment as a bitmap, and then use the image processing tool to decompose the entire bitmap into six bitmaps corresponding to the six faces of the cube; enter 3ds max 7 again, select the cube just now, use The material editor assigns the sky image just exported to the cube and makes some adjustments, and the sky box model is complete. The final step is to export the model of the sky box as a "3dS" type file for calling in the program.

2.2 Models of various entities such as buildings

According to needs, some 3D models such as buildings should also be added to the scene. Of course, these models are also made by us using 3ds max 7. The specific production methods will not be repeated here. However, it should be noted that the produced 3D model should be drawn in real time in the program. Therefore, when making the model, you cannot blindly pursue fineness. You should consciously control the number of polygons to increase the rendering speed when the program runs. Similarly, save the created model as a "3ds" type file.

2.3 Trees and other plants

Generally, 2D pictures are used to display plants, so that even if there is a large forest in the scene, it will not affect the rendering speed. When making a plant picture, you should first choose a suitable plant picture (preferably a head-up photo) to do some simple processing on the picture to meet the following requirements: 1) The picture size is 2 to the Nth power (32, 64 ...); 2) The background color of the picture and the places that do not need to be displayed are pure black. In order to process these places into a transparent state in the program. Finally, save the picture in "bmp" format, and the plants in the virtual 3D scene are ready.

2.4 Generating terrain data

The creation of terrain no longer uses the method of pre-modeling, but adopts the method of real-time drawing in the program, which is convenient for detecting and calculating the ground height of the location when roaming in the scene. The specific steps are as follows: First, create a three-dimensional floating-point array to store the coordinates of the vertices of the terrain. The three components are the x, Y, and z coordinates of the vertices of the terrain. Then, we build two more arrays to store the vertices. The index value (integer) and the surface coordinates of the surface map (floating point); then, a loop code is used to randomly generate the height value of the ground and assign values ​​to the three arrays; finally, the function glEnableClientState () and OpenGL are called glVertexPointev () to load the terrain vertex coordinate array, and use glEnableClientState () and glTexCoordPointer () functions to load the vertex index array. In this way, the initialization of the terrain is completed. You can write this process as a function called lniin (), which is easy to call in the program.

3 Create an application framework based on OpenGL

All drawing functions in OpenGL must run in the OpenGL environment, which is called the OpenGL framework. The OpenGL framework must also run in the Windows application framework. In other words, we must first establish a Windows application framework, use it to respond to and process various messages and commands, and then establish the OpenGI operating environment framework, and call various OpenOL drawing functions in it.

3.1 Create a Windows application framework

First, create a new Win32 application (Win32 ApplicaTIon) in VC 10 + 6.0; then, add four global variables htX2, hRC, hWnd and hlnstance, which are used to save the device description table, coloring description table, window handle and The instance handle of the program; next include g1 in the application. h, glu. h, glaux. h three header files and opengl32.1ib, glu32.1ib, glaux. 1ib three static link library files; finally, add winMain () function and WndProc () function in the program (for specific methods, please refer to MSDN). Among them, the WinMain () function is the entrance of the main program, we add some code to create a Windows window, and use the PeekMessage () function in the WinMain () function to complete the message loop (that is, the main loop of the program, which is repeatedly executed by the program), It is used to monitor and pass the Xiao Xi to the WndProc () function. WndProc () is a window callback function used to process various window messages and respond to external events. In this way, a basic Windows framework is built.

3.2 Create OpenGL running environment framework

The steps are as follows: 1) Initialize the OpenGL operating environment; 2) Call the functions in the OpenGL function library to complete the drawing and display work and refresh the screen, you can write the code to complete these tasks into a function, named DrawScene (), in order to Called in the program; 3) Release various resources before the program exits, disconnect OpenGL from the Windows window 121.

3.3 The relationship between framework programs

The winMain () function is the entry point of the program. We use it to create a window and set its size and style. The WndProc () callback function will respond to the "create window" message, immediately call the SetPixelFomat () function in the OpenGL framework to detect the machine's support for OpenGL, and install the OpenGL display interface. When the window is successfully created, the WndProc () function responds to the window size change message and calls gluPerspecTIve () and other functions in the OpenGL framework to transform and adjust the OpenGL 12I. After the Windows window is generated, it enters the main loop of the program, calls the DrawScene () function to draw the scene, and monitors and distributes various messages at the same time. When the program exits, call the wglDeleteContext () function in OpenGL to cut off the connection between OpenGL and the Windows window.

4 Virtual 3D scene display and human-computer interaction

After building the application framework, we can add code to draw the scene. We want to draw the sky, ground, plants and buildings in the scene, so as to gradually create a virtual three-dimensional environment, and then add the function of roaming in it to achieve simple interaction.

4.1 Drawing and displaying terrain

After the OpenOL framework is initialized, the InitTerrain () function needs to be called to generate an array of terrain data to initialize the terrain. Write a function to draw the terrain, named DrawTerrain (), and call glDrawgle in it. The ments () function draws the terrain by drawing triangles. If the terrain has texture, you can call the glBindTexture () function to map the ground. Add DrawTerrain () to the DrawScene () function, so that the terrain can be redrawn automatically every time the screen refreshes.

4.2 Load and display the model file in 3ds format

Virtual objects such as sky and buildings are created using pre-modeling methods, and we have saved them as a "3ds" format file. We also need to include a header file named "3ds.h" in the program, and its corresponding source file is called "3ds.cpp", both of which can be found on the Internet. For each 3ds file, you can use 3ds first. The loading function in the h file calls it into the program and assigns its own number, and then calls the display model function to display the corresponding 3D model in the OpenGL environment. The parameters of the display model function also define the position, direction and scale of the model display. The work of loading the model can be completed when the program is initialized, and the function of displaying the model should be added to the DrawScene () function.

4.3 Loading and displaying plants

According to the aforementioned method, displaying a plant in a virtual three-dimensional scene is actually displaying a picture of a plant (instead of a 3D model). We first load the picture in the program, then draw a quad on the screen, and display the picture of the plant as a texture. When roaming in a virtual 3D scene, we know our line of sight direction, and we can also calculate our position coordinates. Then, we can write a piece of code so that the quadrilateral with plant texture will always be consistent with our every time it is redrawn. The direction of sight is vertical, thus forming the effect of a three-dimensional model.

4.4 Add roaming function

After the creation and drawing of the virtual three-dimensional scene is completed, the roaming function needs to be added to the program. With the roaming function, we can not only see the virtual three-dimensional scene, but also participate in the first person, and experience the virtual world more "really".

In reality, the picture effect people see depends mainly on two aspects: the position of the observation point and the direction of the line of sight. In OpenGL, there is something similar to our eyes. We can use the function gluLookAt () to change the position and line of sight of the observation point in the OpenGL scene. We add this function to the DrawScene () function. While the program is running, use the keyboard, mouse, etc. to change the coordinates of the observation point and the direction of the line of sight. Each time the screen is refreshed, change the parameter value in the function gluLookAt (), and OpenGL will redraw the screen on the screen with a new perspective, thereby producing the effect of roaming in the scene.

So far, a simple interactive virtual three-dimensional environment has been built. It can be used as the basic module of any practical virtual three-dimensional environment. On this basis, we can continue to enrich the scene content, add other functions, and gradually improve the program.

5 Introduction to program optimization and other functions

In the design of virtual three-dimensional environment, there are many methods worth learning. For example, the terrain grayscale image is used to generate height data, the area block display technology is used to increase the rendering speed, the M0D (outline display) technology is used to speed up the texture display speed and produce better results, and the bitmap font and outline font are used to display Chinese characters, use display lists to display multiple repetitive models to improve efficiency, use particle animation to simulate explosions, smoke and other scenes, add collision detection to the program to meet physical principles, and so on.

6 Summary

With the development of computer technology to this day, the close connection between the virtual world and the real world can no longer be ignored. The virtual world is more and more realistically reproducing the grass and trees in the real world. As the main body of the virtual world, the virtual three-dimensional environment directly determines the reality of the virtual world. The application of OpenGL and other technologies has made 3D graphics technology more and more widely used in the fields of virtual reality, 3D simulation, simulation training, electronic entertainment, etc. Some of the natural environment and working environment simulation that are usually impossible or difficult to achieve are in virtual It is commonplace in the world. While it brings more realistic feelings to the experiencer, it also greatly reduces various costs, improves work efficiency, and has a broad space for development.

Sport In-ear Bluetooth Headset

Creative Sports Earphones,Wireless Sport Earbuds,Bluetooth Sports Earbuds,Best Wireless Earbuds For Running

Dongguang Vowsound Electronics Co., Ltd. , https://www.vowsound.com

This entry was posted in on