I am a super rookie in 3D programming, because the project needs to be exposed to some of the open Scene Graph (OSG) engine related programming work. First I have to admit, OSG this engine super cow, whether it is rendering effect and efficiency, not to say, is great. However, the Android example provided by OSG is really not flattering, and the code logic there is a lot of redundancy +bug (at least on my three Test machines).
Gossip less, in order not to let others into the pit & make a record in the future convenient to consult, say osgAndroidExampleGLES1 this project pit. Java layer Code There is nothing to say, directly to JNI below the C + + code.
Problem 1
A example involves too many operations and is intertwined, with little comment. For beginners, the true variety can not understand. Here is a brief introduction, Osgandroidnotifyhandler This class and the Android log Class A function, is to print some information in the Logcat. In fact OsgAndroidNotifyHandler.cpp the content of this file is to use Osgandroidnotifyhandler to __android_log_write function to do a simple package. OsgNativeLib.cpp This file contains all the interface functions that people who have worked on the NDK development should be able to read easily. The essence of the entire JNI folder is in the Osgmainapp class, where _viewer is used to set the projection matrix, which is equivalent to the camera, and the model is eventually projected onto the device screen through a series of matrix transformations (the phone is the glsurfaceview of the phone). _root is the root node of all models, and the model that needs to be displayed is added to the _root or _root child nodes. _state is used to set some OpenGL ES options, such as whether to turn on lights or not. _manipulator is used to control the camera, that is, to control the trajectory of the cameras used to display the scene containing the model.
Problem 2
Example inside added is the mouse response event, and the Android touch screen event corresponding to the very bad, my side effect is, lightly touch the screen, the model does not know where to fly, the response is too sensitive. If it is a beginner osg+android, it is recommended to comment out the OsgMainApp.cpp from 101 to 104 lines and related codes. This will not be afraid to touch the screen can not see the model. If the model can respond to touch screen, I think it is better to write the touch screen event myself, and then add the transformation matrix according to the corresponding parameters to control the model attitude.
Problem 3
Problems with the logic of loading models, clearing models, and other functions in code can cause example to appear abnormally. At least on my side of the test, if a model is loaded, but not clean before exiting the program, the next time you open the app, loading the model will not show anything. This is because after the application exits, in some cases the Android system does not kill it completely, and then open into the time, due to the example in the wonderful, dazzling variety of temporary model vector design, resulting in logic errors, can not be displayed correctly. Even more strangely, this example is clearly not necessary to reload all the models before calling the _viewer->frame () function to display each frame. In view of the above problems, change the amplitude is relatively large, it is recommended to directly remove the code in the Loadobject function, instead of directly loading the model and added to the _root node.
In short, OSG This Android example is really very difficult to do, want to develop their own words, the best most of them do not refer to the code in this project and to learn about the basic knowledge of OSG.
OSG Pit Daddy's Android example