3 DMAX Model Application in OpenGL

Source: Internet
Author: User

3 DMAX Model Application in OpenGL

Fang Bin

(Aircraft Design Institute of guihang group, Anshun 561000, Guizhou)

Abstract: This article describes how to implement 3 DMAX data model program control in OpenGL 3D programming. The results can be used in aircraft flight motion simulation and real-time flight monitoring. OpenGL; 3 DMAX; ASE file; projection and Transformation

Graph classification:

Tp391.72; th311.52Document ID:B

0 Preface

OpenGL is a hardware and graphics software interface. Due to its excellent performance in 3D Realistic Graphics Production, computer-led companies such as Microsoft, SGI, IBM, Dec, and sun all adopt OpenGL standards, openGL has become a de facto high-performance and interactive visual standard. Before Microsoft supports OpenGL in Windows 95/NT operating systems, OpenGL programs can be run only on expensive graphics workstations. With the emergence of OpenGL graphics accelerator cards and the improvement of PC performance, openGL is widely used on PCs. OpenGL can easily implement various transformations, coloring, illumination, textures, interactions, and animations of models. However, it can only provide modeling functions of basic geometric elements, Making Modeling of complex models relatively difficult. 3dmax is a kinetix 3D graphic modeling and animation software. It is easy to build complex object models, but it is difficult to implement program control. Therefore, we naturally think that after creating a complex model in 3dmax, we can easily control and transform it in OpenGL.

1. Basic operations of OpenGL

① Draw an object through points, lines, and polygon.

② Transformation: projection transformation, geometric transformation, cropping transformation, and view transformation.

③ Coloring: OpenGL provides rgba and Color Indexing modes, and provides 224 colors.

④ Texture ing: adding the texture of objects in the real world to the surface of a specific model makes the 3D model more vivid.

⑤ Interactive operations and Animation: the OpenGL auxiliary function library provides message response functions to facilitate interaction program control.

⑥ Others: lighting, reverse sampling, mixing, atomization, and other functions.

2 3 dmax ase model description and OpenGL Control

 

After creating a model in 3dmax, save the model as an ASE file (ASCII file) in a triangular mesh mode. in the program, we need to create a corresponding model data structure. This article uses the C language data structure as an example.

The example ASE file contains a simple pyramid and sphere. The specific content is as follows (the header is omitted ):

* Geomobject {// start of a single object model

* Nodename "pyramid01" // Object Name

····

* Mesh {// Mesh

* Timevalue 0

* Meshnumvertex 6 // Number of vertex numbers of Objects

* Meshnumfaces 8 // Number of triangles of an object

* Meshvertexlist {

* Meshvertex00.20.0.20.30.0000 // vertex Coordinate

····

* Meshvertex50.00000.00000.0000

}

* Meshfacelist {// vertex of the surface number and composition plane

* Meshface0: A: 0 B: 1 C: 2 AB: 1 BC: 1 CA: 0

····

* Meshface7: A: 4 B: 5 C: 1 AB: 0 BC: 1 CA: 1

}

}

····

}

* Geomobject {// the same format as the preceding object

* Nodename "sphere01"

····

}

By analyzing the above ASE file structure, we can obtain the General C model data structure of the corresponding ASE file as follows:

Point definition: typedef struct pointtype {Double X, X, Y;} pointtype;

Triangle Surface definition typedef struct facetype {int A, B, C;} facetype;

Definition of a single object

Typedef struct objecttype {

Int vertexnum; // Number of vertices

Pointtype * pointlist; // point list

Int facenum; // Number of faces

Facetype * facelist; // The list of faces.

Objecttype * Next; // pointer to the next object

} Objecttype;

Multiple objects

Typedef struct objectshead {

Int objectnum; // number of objects

Objecttype * objectlist; Object List

} Objectshead;

 

■ Import object data from the ASE File

Int getobjects (char * filename, objectshead * objects) // read from the object to objects

{File FP; // file pointer

Char line [200]; // stores the data of a row in the file

Objecttype * p, q; pointtype tempoint; facetype tempface;

If (FP = open (filename, "R") <= 0) then return-1; // failed to read the file

Objects → objectlist = NULL; objects-> objectnum = 0;

While (not EOF (FP )){

Getlint (FP, line); // read a row from the file to line; custom function; If (judgein (line, "geomobject ")) {// The head defined by the object q = malloc sizeof (objecttype); // allocate space for the object

Q → next: = NULL;

If (Objects → objectlist = NULL) P = objectlist = Q;

Else {P → next: = Q; P = P → next ;}

++ Objects → objectnum ;}

If (judgein (line, "* meshnumvertex ")){

Q → vertexnum = getvertexnum (line); // Number of read points

Q → pointlist = (pointtype *) malloc (sizeof (pointtype) * q → vertexnum );}

If (judgein (line, "* meshnumfaces ")){

Q → facenum = getfacenum (line); // Number of read faces

Q → facelist = (facetype *) malloc (sizeof (facetype) * q → facenum );}

If (judgein (line, "* meshvertex ")){

Getpoint (line, tempoint); // read the coordinate points

Addpoint (Q-> pointlist, tempoint);} // Add a vertex to the vertex list

If (judgein (line, "* meshface ")){

Getface (line, temface); // read surface

Addface (Q-> pointlist, temface);} // Add a plane to the surface list

} // The while statement ends.

Fclose (FP); return 1;

}

■ Implement animation control in OpenGL

# Include <Gl/Gl. h> // OpenGL core library

# Include <Gl/Glu. h> // OpenGL utility Library

# Include <Gl/Glaux. h> // OpenGL auxiliary Library

Objectshead * objects; gldouble RX = 0, Ry = 0, Rz = 0; // RX, Ry, and RZ indicate the Rotation Angle of an object.

Void callback myreshape (glsize W, glsize h) // callback function for window size change

{Glviewport (0, 0, W, H );}

Void callback display () // Display object callback function

{Int J, K; objecttype * P;

Delay (1000); RX = RX + 0.1; ry = ry + 0.1; rz = RZ + 0.1;

Glclear (glcolorbufferbit); // clear the OpenGL color buffer.

Glpushmatrix ();

Glrotate (RX, Ry, Rz, 0.0); // rotate an object

P = objects → objectlist;

For (j = 1; j <objects → num; j ++ ){

For (k = 1; k <p → facenum; k ++ ){

Glbegin (gltriangles); // use OpenGL commands to draw a triangle mesh

Glvertex3f (P → pointlist [(P → face-list [I]). A], p → pointlist [(P → face-list [I]). B]);

Glvertex3f (P → pointlist [(P → face-list [I]). B], p → pointlist [(P → face-list [I]). c]);

Glvertex3f (P → pointlist [(P → face-list [I]). c], p → pointlist [(P → face-list [I]). A]);

Glend ();

}

P = P → next;

}

Glpopmatrix ();

Glflush () L; // exchange data with the display area

}

Void main (void)

{

Auxinitdisplaymode (auxsingle | auxrgb); // initialize the Display Mode

Auxinitposition (400,400,); // initialize the window position and size

Auinitwindow ("OPENGL-3DMAX example"); // Title

Glclearcolor (0.0, 0.0, 0.0, 0.0); // clear the display area

Auxreshapefunc (myreshape );

Auxmainloop (Display );

}

2.2 read 3 DMAX object data to implement OpenGL Animation

3 conclusion

Applying the 3dmax model to OpenGL reduces the difficulty of OpenGL complex modeling, and we can obtain a more realistic complex object model. In the specific application of aircraft motion simulation and remote attitude monitoring, we introduced the 3dmax airplane model in the OpenGL program to achieve satisfactory 3D animation effects. Similarly, we can also compile various graphic interface programs such as AutoCAD and UG, and introduce the object models created in CAD software such as AutoCAD and UG into the OpenGL application program, it can be applied to flight simulation, motion virtual simulation, commercial advertising, game production, film and video collection and other fields.

References

 

[2] [us] by S. ellion. P. Miller, translated by Zhang ruoqing and Gu Mei. 3 DMAX studio technical essence [M]. Beijing: Tsinghua University Press. 1997.9.

[1] Bai Yanbin and Shi Huikang; OpenGL 3D graphics library Programming Guide [M]. Beijing: Machinery Industry Press. 1998.11.

The Application of 3 DMAX modelling to OpenGL

Fang Bin

(Aircraft Design Institute, Guizhou aviation group, Anshun, Guizhou, China, 561000)

Abstract:

Key words:

(Editor of this article: Zhou Xiaonan)

OpenGL; 3 DMAX; ASE file, projection and transformThis paper introduces the program control of 3 DMAX Data Model in OpenGL, which finds application in Kinematic Simulation and real time monitoring of airplanes.2.1 use the C language data structure to describe the 3dmax Model

Keywords:

 

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.