In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example fix of J2ME 3D graphics technology, which is very detailed and has certain reference value. Friends who are interested must finish it!
3D graphics technology has been more and more used in various fields, of course, this also includes the field of J2ME. In J2ME, we are provided with an optional package like JSR184, which implements the programming of 3D graphics on mobile phones with API. At the same time, with the development of mobile device hardware, there are more and more mobile phones that support the optional package, such as Sony EriCSSon K-series, S-series and so on.
Coincidentally, some time ago, I simply studied 3D graphics, so I recently began to learn Mobile 3D. I hope I can share what I have learned here with you. I hope it will be helpful to you. At the same time, I hope you can learn JSR184 together.
First of all, let's imagine how we observe the world in real life. We see through our eyes that we live in a world made up of three-dimensional coordinates. In Mobile3D, there is also a World class that allows you to construct the world you want, of course, it is professional here, in 3D drawing we call it "scene"; in addition, there is a Camera class as your eye, you can set its position angle and other parameters to show different images.
How to display 3D images in Mobile 3D? First of all, you need to create or load a 3D model, and then set up a series of parameters such as the environment and rendering mode of the scene as needed, and then generate and set a camera and adjust the light you want. Adjust the position and angle you need. What else does OK need? Press the shutter, this step is called "rendering" everything is done, which sounds simple but not difficult, in fact, it is not difficult.
Let's explain these steps step by step:
First of all, when it comes to the establishment of the model, there are two ways in Mobile 3D and most 3D programming API: (1) timely operation generation; (2) external modeling import. As the external modeling import will import the environmental information at the same time, so I will give you a specific introduction later, here is an important part of "just-in-time operation generation", which will help you to understand the working principle of Mobile 3D. VertexArray and VertexBuffer classes are provided for us in Mobile 3D, which are used to store vertex information of 3D models.
Among them, the VertexArray class is more useful and flexible. There are three most commonly used uses of this class: 1 to save vertex coordinate information; 2 to save normal information; 3 to save post map information. One might ask, how does this class govern three different things? First, the constructor of the class has three parameters: 1 the number of elements to be included in the instance, 2 the number of elements to be included in each element, and 3 the number of bytes occupied by each child element. This seems to make it clear why this class can be used on three things.
In addition, this class also has a more commonly used method set (int index,int length,short [] array0). This method is used to store data to the instance object of this class. The first parameter refers to which element it starts from; the second parameter refers to how many elements to set; and the third parameter refers to the actual setting.
Here's a brief introduction to the VertexBuffer class, which is the class that really holds the frame information for polygons. Change the class by setting vertex location, discovery, post map information, to establish graphics. Among them
SetPositions (VertexBuffer v float sm float [] b)
Is used to set the vertex position, in this method you will find that there are three parameters, the first needless to say, is the vertex coordinate information, the last two are used to do coordinate offset and other operations, the operation is like this mathematical formula:
V'=v*s+b
There's another one.
SetNormals (vertexBuffer norm)
Method to set the normal. There is also a very important way.
SetTexCoords (int, VertexArray, float, float [])
In this method, except for the first parameter, the last three and
SetPositions (VertexBuffer v float sm float [] b)
It's the same, and the first parameter is the starting element number. Isn't that a little abstract? Let's give you an example so that you can understand.
Short x = 20; short y = 20; short z = 20; short fx = (short)-x; short fy = (short)-y; short fz = (short)-z / / fixed-point coordinates short [] vert = {xrecedence z, fx,y,z, xrecedence fypenz, fx,fy,z, / / D fx,y,fz, xrecedence FZ, fx,fy,fz, xlemagenfz, / / C fx,y,z, fx,y,fz, fx,fy,z, fx,fy,fz, / / B xrecinceyparentin FZ, xrecinceyrecentz, xrecedence FZ X,fy,z, / / F x,y,fz, fx,y,fz, x,y,z, fx,y,z, / / A x,fy,z, fx,fy,z, x,fy,fz, fx,fy,fz} / / E try {vertArray=new VertexArray (vert.length/3,3,2); vertArray.set (0rect vert.revert);} catch (Exception e) {System.out.PRintln ("vert") } / / hair line byte [] norm = {0meme 0meme 127,0meme 0je 127,0meme 0mae 127,0meme 0mae 127,0meme 0mae 127,0mae 0mae 127pence 0,-127pence 0meme 0,-127pint 0meme 0,-127pr 0meme 0,-127pr 0pr 0,127e 0pr 0,127e 0pr 0,127e 0pr 0,127e 0,07prime0,07prime0,0127prime0,010recers0,05lml0,051127l0, 0127mae 0,0,127mae 0,0,0,0. -127Pol 0,0pr Rue 127Pol 0} Try {normArray=new VertexArray (norm.length/3,3,1); normArray.set;} catch (Exception e) {System.out.println ("norm"); e.printStackTrace () } / / give the vertices corresponding to the points on the picture (the vert and tex arrays are one to one) short [] tex = {1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0 0, 1, 1, 0, 0, 0, 1, 1, 0, 1} Try {texArray=new VertexArray (tex.length/2,2,2); texArray.set (0rect tex.futhpx2tex);} catch (Exception e) {System.out.println ("tex");} / / create cube vb=new VertexBuffer (); vb.setPositions (vertArray,1.0f,null); vb.setNormals (normArray); vb.setTexCoords (0memeTech Array 1.0fNull)
In the above code, I need information about all the vertices and faces I need to build a cube, but we should note that there is no corresponding model generated here. The reason is that we have not set up other information to generate the model, so let's take a look at the TriangleStripArray class, which is the information class that constitutes the triangular surface needed by the face. people who are familiar with 3D drawing all know that the construction of 3D graphics is to construct a 3D entity through multiple faces, and the triangular face is a more commonly used method. I will not elaborate on the details here.
Next we also need to set up some environment and material information, here to use more classes Appearance, Texture2D, Material. Let's take a look at an example:
Appearnce=new Appearance (); / / create post map Texture2D texture=new Texture2D (image2d); texture.setBlendColor (Texture2D.FUNC_DECAL); texture.setWrapping (Texture2D.WRAP_REPEAT,Texture2D.WRAP_REPEAT); texture.setFiltering (Texture2D.FILTER_NEAREST,Texture2D.FILTER_NEAREST); material=new Material (); material.setColor (Material.DIFFUSE, 0xFFFFFFFF); material.setColor (Material.SPECULAR, 0xFFFFFFFF); material.setShininess (100.0f); appearnce.setTexture (0Curry) Appearnce.setMaterial (material); mesh=new Mesh (vb,tsa,appearnce); mesh.setAppearance (0meme appearnce)
Personally, I feel that the Appearance class is similar to the VertexBuffer class and is also the holder of a variety of properties; to emphasize here, the settings of the Appearance class are much more than those given above, but there are also a lot of settings (for example, FOG, that is, the fog setting). Texture2D is the post map class, which is used to set the post map information, such as the way the post map is tiled and so on. The name of Material refers to the material, here you can set "shininess", "color" and other information. In addition, I would also like to introduce a method of setting rendering parameters.
/ / set poly mode to set PolygonMode polygonMode=new PolygonMode (); polygonMode.setShading (PolygonMode.SHADE_SMOOTH); polygonMode.setCulling (PolygonMode.CULL_NONE); / / generate appearance appearnce=new Appearance (); appearnce.setPolygonMode (polygonMode)
Looking at the code just given, it seems simpler than the one above, doesn't it? In fact, a lot of work has been done for us in PolygonMode. This setting is very similar to the use of Poly in 3D MAX.
Just now the code also gives a Mesh class, this kind of material finally we want the model. After building the model, we need to build Camera. In Camera, I only briefly introduce two methods, setParallel (float, float) and setPerspective (float, float). We first look at setParallel (float, float) the method is to set the view method of Camera to flat view; the first parameter is to set the height of the viewing angle, focusing on height, not angle, because it is flat view; the second parameter is the aspect ratio of Camera, for example, our TV is 4:3, and the wide-screen movie is 16setParallel 9; the third and fourth parameters are the range of the nearest and farthest rendering, respectively. The same setPerspective is to set Camera as the perspective, this view is closer to the perspective of our daily life, and the last three parameters of this method and the last three parameters of setParallel are the same, and the first parameter is the angle, you can not ignore this angle here, this angle is an important parameter in the calculation of projection in the perspective.
Everything seems to be set up, but it's not. So far we've just got all the material we need. Let's take a look at the governance mechanism of Mobile 3D, people who are familiar with 3D graphics are aware of most 3D software, 3D API is through the tree structure to manage the material, this advantage is that each model, model group, camera and other elements as nodes can set their own axis of rotation and other attributes, and can move according to their own animation information. It is stipulated for us in Mobile 3D that the root node of the tree must be an instance object of the World class, in which the camera and light are extraordinary and can not be placed in the tree, but can be set through the object of the Graphics3D class.
The above is all the contents of the article "sample fix of J2ME 3D graphics technology". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.