J2_3d programming-the first 3D Program (with source code)
For more articles visit: http://blog.csdn.net/mailbomb
Refer to the demo provided by WTK2.2 and complete the first 3D program. Although it is very simple and some problems are not very clear, we still need to share the Code with our friends who are willing to learn the 3D programming of j2s.
For more information about 3D programming, see my blog.
Code compilation and running are described as follows:
1. the following code is compiled under j2-wtk2.2.
2. The code is divided into two files: First3DCanvas. java and First3DMIDlet. java.
3. Use j2-wtk2.2 to create a new project. The main MIDlet class is first3d. First3DMIDlet.
4. Save the code to the first3d directory under your project directory.
5. Install
Copy the swerve. m3g file in the includemo3descomsuperscapem3gwtksamplesetainedmodecontent directory to the res directory under your project directory.
6. After your project is created, set the project and open the setting window through the "Settings" button on the WTK interface. In "API selection", set "Target Platform" to "Custom; "Profile" is "MIDP2.0", "configuration" is "CLDC1.1", and "Mobile 3D Graphics for j2r184" is selected )".
7. You can compile and run the following code.
The source code is as follows:
// First3DMIDlet. java
Package first3d;
Import javax. microedition. midlet .*;
Import javax. microedition. lcdui .*;
Public class First3DMIDlet extends MIDlet {
Private First3DCanvas displayable = new First3DCanvas ();
Public void startApp (){
Display. getDisplay (this). setCurrent (displayable );
}
Public void pauseApp (){}
Public void destroyApp (boolean unconditional ){}
}
// First3Dcanvas. java
Package first3d;
Import javax. microedition. lcdui .*;
Import javax. microedition. m3g .*;
Import java. util .*;
/**
* The first 3D Program
*/
Public class First3DCanvas
Extends Canvas
Implements Runnable {
/** World object */
Private World myWorld = null;
/** Graphics3D object */
Private Graphics3D g3d = Graphics3D. getInstance ();
/** Camera object */
Private Camera cam = null;
Private int viewport_x;
Private int viewport_y;