search
HomeBackend DevelopmentPHP TutorialJ2ME Mobile 3D introductory tutorial series article two

Here I would like to first thank you all for your support for the previous article, one of the J2ME Mobile 3D introductory tutorial series. It is with your support that I decided to share my Mobile3D learning process with you. I hope you can Let’s discuss Mobile3D.
 
 In the last tutorial, I gave you a detailed introduction to creating 3D graphics through real-time calculations in Moble3D, and gave a brief introduction to importing models from *.m3g files. This time I want to pass it on here. The use of *.m3g files briefly introduces Mobile3D's control of animation and some operations on the model.
 
First of all, let me briefly talk about the creation of m3g files. This is actually very simple. You only need to choose a 3D graphics production software that you are familiar with and install the corresponding plug-in. The software I use here is Maya. and 3DS MAX, the plug-in uses H3T EXPort Plugin, which is available for maya and 3ds max. You also need to download a software M3G Tools kit.
 
 These can be found on the Sony EriCSSon website. There should be no problem installing the plug-in. After the plug-in is installed, you can create the model, set the texture map, set the camera, set the key frame, etc., and finally just export it to an H3T file. Then open M3G Tools kit can output h3t files into m3g files. It is best to use M3G Tools before using m3g files Kit browses the file to record the corresponding information, such as userid and tree structure of the scene, which are very important. If you do this, you will find that the camera in the m3g file exported in this way is not under the world tree, but is at the same level as the world tree.
 
In fact, I also said in the previous article that camera and rendering information do not need to be placed under the world tree, but all model information must be placed under the tree. When we look at the m3g file, it is more important to see clearly the location of the world node and the userid of the model that we need to operate.
  
  The preparatory work is almost done, now let’s look at Mobile3D. In the previous article, I said that m3g files are loaded through javax.microedition.m3g.Loader.load(String url), and this method returns javax. Array of microedition.m3g.Object3D, some people may ask that since world is the root node, why not directly return a World?
 
 When I just showed you the structure of the m3g file, I already explained that the camera and animation settings are not placed in the book with the World node, but are at the same level as the World node. The World node is the root node of the scene. So how do we correctly remove the World node? There are two methods:
 
 1. Traverse the Object3D array and compare the useid of each element. If the useid of the official World node is used, the element will be taken out.
 
 2. Traverse the Object3D array and compare whether each element is an instance of the World class. Since the World node is the root node of the scene, there should be only one instance object of the World class in the Object3D array.
 
 The first method is relatively simple. I only give a fragment of the code of the second method here. (actually the same)
  
 PRivate void loadWorld(){
 System.out.println("now loading...");
 try{
 buffer=Loader.load("/img/TmpMicroFile.m3g");
  for(int i=0;i if(buffer[i] instanceof World){
 world=(World)buffer[i];
  return ;
  }
  }
  }catch(Exception e){
 buffer=null;
 System.out.println("thorw an exception when loading");
 e.printStackTrace();
 }
 }
 
  Then we set the camera. The difference is that this time we get the camera information from World. After obtaining We can make some basic settings, which I won’t go into details here. Let’s focus on the animation part. When we import this m3g file, we actually already have animation information, and this animation information may be It's very complicated. I tested the movement of the two axes of the connecting rod and it works fine. From some information, there is no problem with the IK reverse movement. Maybe you are already worried. Why don't you tell me how to control the animation playback? Simply put, World.animate() updates animation information. This method needs to pass in an int type parameter. When you call this method for the first time, the system will record this value, and it will be compared with every subsequent call. This value is compared, and then the system calculates for us where to update the animation. At the same time, this method will return an int type parameter, which represents a recommended value for the next update (in milliseconds)
.
 At this time, we can let the thread that calls this method sleep for this time so that the animation data can be updated next time. You may have questions here. My animation obviously only has dozens of frames, but it is played repeatedly here; although this is a Good news, but what if we need to control the length and time of playback in many cases?
 
At this time we need to use the javax.microedition.m3g.AnimationController class. In fact, each movable model in each animation has its own AnimationController object. Like the model animation, we can use World.find(int controllerID), in this class we can use setActiveInterval(int activeTime,int unactiveTime) to set the start and focus time of animation playback in the system, and setPosition(int startTime,int endTime) method controls which paragraph of this animation needs to be played.
 
 Sorry that I did not use the two methods in this tutorial example, but if you want to know about the use of these two methods, I suggest you take a look at the kangaroo example in Demo3D of WTK2.2. It's pretty specific in there. Here I give code snippets for animation and drawing. g .setColor(0x00);
 g.fillRect(0,0,getWidth(), getHeight());
 
 g.setClip(0,0,getWidth(),getHeight());
 g3d.bindTarget(g, true,Graphics3D.DITHERGraphics3D.TRUE_COLOR);
 g3d.setViewport(0,0,getWidth(),getHeight());
 
 g3d.render(world);
 
 g3d.releaseTarget();
 
 framePor=(int )1000/((int)System.currentTimeMillis()-perFrameTime);
 
 System.out.println("3D demo frame/sn:"+framePor);
 
 if(validity  { // The validity too small; allow a minimum of 1ms.
   validity = 1;
}
b public void run () {
while (isrun) {
repaint ();
try {
thread.sleep (value);
} Catch (Exception E) {}}}

If you if you if you, if you If you don't like using threads, you can switch to Timer. It's a matter of personal preference. I'm familiar with threads, so I use threads here.
 
 It seems that I only understand these animations now, and I share them all with you. Next I want to talk about several methods in the Transformable class. First, let’s introduce the Transformable class. The Transformable class is a very important class, and Node is its subclass. Do you know its importance?
 
 There are four methods in Transformable that I will briefly talk about today: postRotate(float, float, float, float) is related to the rotation of the object. In Mobile3D, the rotation axis of all objects is at its own center by default, so when rotating an object, it must be rotating on its own axis, not around a certain point or axis. Revolution, this must be clarified. Maybe this is a bit abstract, so let me put it another way: the rotation here only changes the orientation of the object, but does not change the position of the object.
  
 Now you understand, maybe someone wants to ask, "Isn't this exactly what we need? Why should we emphasize it?" The reason is actually this. In some 3D engines, rotation is based on the origin. That is to say, if you need to perform rotational motion, you must move, rotate, and move again. In fact, the advantage of doing this is that it can facilitate point calculations, because there is no concept of rotation for points. To some extent, our Mobile3D cannot operate on points, so its smallest unit is Mesh. So how does it achieve rotation? You will understand if you look at a matrix
  
  90, 0, 0, 0
  0, 0, 0, 0
  0, 0, 1, 0
  0, 0, 0, 0
  
  This matrix represents the current model There is a 90 degree rotation on the Y axis. Now let's go back and look at postRotate(float a, float x, float y, float z) method, which has 4 parameters. The first one is the angle that needs to be rotated this time. The last three are actually the axis of this rotation, which is represented by a vector. The postRotate method continues in the original orientation. The new rotation, if expressed by a mathematical formula, is to use the original matrix multiplied by
 
 a,0,0,0
 0,x,0,0
 0,0,y,0
 0,0,0 ,z
 
 This matrix is ​​the new direction matrix. If this method sounds difficult to understand from a mathematical perspective, you only need to remember the four parameters. The first is the angle of this rotation, and the last three determine the axis of rotation.
Similar to the postRotate method is setOrientation(float a, float x, float y, float z). The difference is that this time it is no longer rotated but directly set to this orientation.
 
 After talking about rotation, let’s look at movement. This seems to be much simpler translate(float x, float y, float z) This refers to translation according to the specified vector; setTranslation(float x, float y, float z) This is simpler, move directly to the specified position.
 
In fact, there is another method scale(float sx, float sy, float sz) is used for scaling, as well as setScale(float sx, float sy, float sz) Set the scale directly. These six methods are for direct manipulation of objects and are very useful. Especially the first four are often used when writing games. The latter two seem to be used less frequently because there are many Sometimes we directly operate the distance of the camera (unless there is an extraordinary need). Let me give an example of using the first four methods below.
 
 public void keyPressed(int keycode){
 float[] camerTra;
 float x;
 float z;
 switch(keycode){
 case GameCanvas.DOWN:
 break;
case GameCanvas.UP:
 break;
 case 52:
 dir=dir-2;
 System.out.println(dir);
 2. For more related content, please pay attention to the PHP Chinese website (www.php.cn)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!