JPCT-AE for Android 3D (1) ---- Hello world create your own cube

Source: Internet
Author: User
Tags gety
Understanding JPCT-AE jpct is a 3D graphics engine based on OpenGL technology (PC environment as the standard OpenGL, Android for OpenGL ES), based on Java language, has powerful Java 3D solutions. This engine is similar to lgame (a 2D game engine) and currently has two development versions: PC (j2se) and Android. Jpct-AE
Is A porting version of jpct on the Android platform. Web site: http://www.jpct.net/jpct-ae/ Hello world there are already two examples of drawing cubes in the JPCT-AE installation package (rather than using a fixed assembly line and a programmable assembly line ). Some unnecessary code exists in the example. Here we will create our own cube. Activity_main.xml:
<LinearLayout xmlns:tools="http://schemas.android.com/tools"    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <com.leoy.CBoxView        android:id="@+id/BoxView"        android:layout_width="match_parent"        android:layout_height="match_parent" />      </LinearLayout>

Cboxview. Java

Public class cboxview extends glsurfaceview {private float xpos =-1; private float ypos =-1; cboxrander mrander; Public cboxview (context, attributeset attrs) {super (context ); // todo auto-generated constructor stub // use the self-implemented eglconfigchooser, which must be called before setrenderer (Renderer) // by default, the view will select. view. the surface is compatible with at least 16-bit deep buffer eglconfig. New eglconfigchooser () {public eglconfig chooseconfig (egl10 EGL, egldisplay display) {int [] attributes = new int [] {egl10.egl _ depth_size, 16, egl10.egl _ None }; eglconfig [] configs = new eglconfig [1]; int [] result = new int [1]; EGL. eglchooseconfig (display, attributes, configs, 1, result); Return configs [0] ;}}); mrander = new cboxrander (context); setrenderer (mrander );} public Boolean ontouchevent (motionevent me) {If (Me. getaction () = motionevent. action_down) {xpos = me. getx (); ypos = me. gety (); Return true;} If (Me. getaction () = motionevent. action_up) {xpos =-1; ypos =-1; mrander. touchturn = 0; mrander. touchturnup = 0; return true;} If (Me. getaction () = motionevent. action_move) {float XD = me. getx ()-xpos; float YD = me. gety ()-ypos; xpos = me. getx (); ypos = me. gety (); mrander. touchturn = XD/-100f; mrander. touchturnup = YD/-100f; return true;} Try {thread. sleep (15);} catch (exception e) {// no need for this ...} return super. ontouchevent (me );}}

Cboxrander. Java

Public class cboxrander implements Renderer {public mainactivity mactivity = NULL; private framebuffer Fb = NULL; private world = NULL; camera cam = NULL; // cube private object3d cube = NULL; private object3d Yi, Shi, Zhu, Xing, Wan, Wen; // illumination class private light sun = NULL; private rgbcolor back = new rgbcolor (255,255,255 ); // rotate public float touchturn = 0; public float touchturnup = 0; Public cboxrander (contex T context) {mactivity = (mainactivity) Context ;}@ overridepublic void ondrawframe (gl10 GL) {// todo auto-generated method stubif (touchturn! = 0) {cube. rotatey (touchturn); touchturn = 0;} If (touchturnup! = 0) {cube. rotatex (touchturnup); touchturnup = 0;} FB. clear (back); World. renderscene (FB); World. draw (FB); FB. display () ;}@ overridepublic void onsurfacechanged (gl10 GL, int W, int h) {// todo auto-generated method stubif (FB! = NULL) {FB. dispose ();} // create a framebufferfb = new framebuffer (GL, W, H);} @ overridepublic void onsurfacecreated (gl10 GL, eglconfig config) with W width and H height) {// todo auto-generated method stubworld = New World (); World. setambientlight (100,100,100); Sun = new light (World); Sun. setintensity (250,250,250); // texture = new texture (bitmaphelper. rescale (bitmaphelper. convert (mactivity. getresources (). getdrawable (R. drawable. icon), 64, 64); texturemanager. getinstance (). addtexture ("texture", texture); // cube = primitives. getcube (10); cube. calctexturewrapspherical (); cube. settexture ("texture"); cube. strip (); cube. build (); World. addobject (cube); // camera cam = World. getcamera (); cam. movecamera (camera. camera_moveout, 50); cam. lookat (cube. gettransformedcenter (); simplevector SV = new simplevector (); Sv. set (cube. gettransformedcenter (); Sv. y-= 100; Sv. z-= 100; Sun. setposition (SV); memoryhelper. compact ();}}


PS: I started to learn about the bad Java code style. Please forgive me if the structure is not optimized enough.

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.