B4A Library 3D Bodies - Four libraries

Discussion in 'Additional libraries, classes and official updates' started by derez, Dec 18, 2014.

  1. derez

    derez Expert Licensed User

    Reuse of something I did in B4ppc days and got a round tuit now for B4a.
    There are three libraries, doing similar thing with variations:
    1. A 3D cube, with or without dice numbers on, can roll by touch or by command or provide a throw result by click.
    2. A 3D library for any body, provided that you know how to define its verteces and polygons. There are examples of several bodies which may help, see photos.
    3. A 3D library for any body (like 2 above), using Open_GL 1 library (thanks to Agraham). Note that I have very limited knowledge on the use of Open_GL and this implementation is very basic, however the user of this 3D library does not need any knowhow of Open_gl at all.

    In all libraries you can create a view which is a base panel and the body on it. The panel may be transparent or with a bitmap.

    A demo application is attached, including the bodies in the photos and a surprise.
    The documentation is inherent and simple.
    Important: The demo with the BodyGL library has some code with a timer - the specific item will fail when running in rapid debugger or even in legacy, but runs well in release mode (probably due to heavy load of Open_GL).

    The three libraries use a coordinate system in which X is to the right, Y is up and Z is into the device. Flattened to 2D, z is diagonal from bottom-left to top-right.
    The units of this system are much larger than the pixels, few units cover the display (depends on the z coordinate and the ViewAngle.

    Edit: Cube3D updated to ver 1.01 , now its possible to define it as custom view.
    see post 3 for details.

    Edit: Ver 1.02 - CubeGL added , doing what Cube3D does but using openGL.
    Cube3D and CubeGL both are also CustomView in the designer. See post #5 for details.
    Edit: Frame line option added to BodyGL.
    Edit: Body3D version is updated to 1.1, removing a limit of the number of points in a body and adding ViewAngle method. It is updated in 3D.zip file.
    Edit: all libraries updayed to ver 1.2, inclusion of LineWidth method.
     

    Attached Files:

    Last edited: Jan 9, 2015
  2. derez

    derez Expert Licensed User

    The attached is a b4ppc program for windows, enabling view and rotation of some of the bodies in the demo above. It also enables to see the body with the verteces numbers without color and to move the verteces for new design of the body. When design is complete - save, the file is "body.txt" in the application folder.

    A special for Hanuka - a Svivon photo :) and code:
    Code:
    Sub svivon_Click
        vert.x = 
    Array As Float(2222,-2,-2,-2,-20 , .5.5.5.5,-.5,-.5,-.5,-.5 )
        vert.y = 
    Array As Float(22,-2,-222,-2,-2, -5,  55,2,255,2,2 )
        vert.z = 
    Array As Float(2,-2,-222,-2,-220.5,-.5,-.5.5.5,-.5,-.5.5  )
        pitch = 
    0
        Yaw = 
    45
        roll = 
    45
        posx = 
    0
        posy = 
    1.5
        posz = 
    30
    viewangle = 
    45
        posx = 
    0
        posy = 
    1.5
        posz = 
    30

        
    Dim pol(14As String
        
    Dim color(14As Int
        pol(
    0) = "3,2,1,0"
        pol(
    1) = "2,6,5,1"
        pol(
    2) = "6,7,4,5"
        pol(
    3) = "0,4,7,3"
        pol(
    4) = "0,1,5,4"
    '    pol(5) = "2,3,7,6"
        pol(5) = "2,3,8"
        pol(
    6) = "6,2,8"
        pol(
    7) = "7,6,8"
        pol(
    8) = "3,7,8"
        pol(
    9) = "12,11,10,9"
        pol(
    10) = "11,15,14,10"
        pol(
    11) = "15,16,13,14"
        pol(
    12) = "9,13,16,12"
        pol(
    13) = "9,10,14,13"
     
        color(
    0) = Colors.Blue
        color(
    1) = Colors.cyan
        color(
    2) = Colors.Red
        color(
    3) = Colors.Rgb(255,128,192)
        color(
    4) = Colors.Green
        color(
    5) = Colors.Rgb(255,128,192)
        color(
    6) = Colors.Red
        color(
    7) =  Colors.White
        color(
    8) = Colors.blue
        color(
    9) = Colors.blue
        color(
    10) = Colors.cyan
        color(
    11) = Colors.Red
        color(
    12) = Colors.Rgb(255,128,192)
        color(
    13) = Colors.Red
        Set_body
    End Sub
     

    Attached Files:

    Last edited: Dec 21, 2014
    ilan and Jaames like this.
  3. derez

    derez Expert Licensed User

    Cube3D updated to ver 1.01 , now its possible to define it as custom view.
    In case of definition by IDE as custom view the first method should be Start.
    In case of creation by code the sequence of commands is like this:

    Code:
    c3d.Initialize("Main","c3d")
    c3d.CodeCreateView(wh)
    Activity.AddView(c3d.AsView, 50%x,10%y,wh,wh)
    c3d.Start( color, 
    Colors.black, 0.10)
     
  4. Tom Christman

    Tom Christman Active Member Licensed User

    Thank you David!
     
  5. derez

    derez Expert Licensed User

    Ver 1.02 - CubeGL added , doing what Cube3D does but using openGL.
    Cube3D and CubeGL both are also CustomView in the designer.
    Instructions:
    - create CubeGL object by code
    you cannot set the background to color, it is either transparent (when bmp Is Null) or a Bitmap.
    - creation by designer :
    Set the drawable to bitmap and set the bitmap to blank if you want the background To be transparent, otherwise set the picture File from the assets as bitmap.
    If you want a colored background - set a color drawable with the color.
    Set Textcolor to be the Dot color.
    - Linecolor default is black, you can set it by a method to another color.
     

    Attached Files:

  6. derez

    derez Expert Licensed User

    Frame line option added to BodyGL.
     
  7. Sia

    Sia Member Licensed User

    @derez ,
    hi,
    i saw your example code for drawing surface chart with axis and title, it's very nice.

    can you shear you code ?
    very thanks.
     

    Attached Files:

  8. derez

    derez Expert Licensed User

    Sia said:
    The work I do there is being paid for so I will not share it.
    The background of the chart is just "hard work" of drawing lines and text to form the 3D axis.
    The surface is a 3d body which can be created and rotated by the published library (the body3D). Currently there is a limit on the number of points but I'll remove it soon by new versin.
     
  9. derez

    derez Expert Licensed User

    Body3D version is updated to 1.1, removing a limit of the number of points in a body and adding ViewAngle method. It is updated in 3D.zip file in the first post.
     
    Last edited: Jan 8, 2015
  10. derez

    derez Expert Licensed User

    All libraries updayed to ver 1.2, inclusion of LineWidth method.
     
    Sia likes this.
  11. derez

    derez Expert Licensed User

    Sia said:
    I got permission to share. Send me your database and I'll show you how to do it with Body3D.
     
    Sia likes this.
  12. Sia

    Sia Member Licensed User

    in my file first line "10" is x and "60" is Y and after it every 60 line is Y Mean Y1,Y2,Y3
    you must use for to read this and insert to your array
     

    Attached Files:

    • a1.txt
      File size:
      2.9 KB
      Views:
      27
  13. Sia

    Sia Member Licensed User

    Please See this picture
     

    Attached Files:

    • idea.jpg
      idea.jpg
      File size:
      248.4 KB
      Views:
      119
  14. derez

    derez Expert Licensed User

    Attached
    upload_2015-1-10_22-16-52.png
     

    Attached Files:

    ellpopeb4a and eps like this.
  15. tonga

    tonga Member Licensed User

    Hi Derez,

    I see your good works. Now I wish to translate in the screen the cube of "Body3Demo", but is very difficult for me to understand the mean of coordinates of verteces in the "Sub Cube_Click":

    vert.x = Array As Float(2, 2, 2, 2,-2,-2,-2,-2)
    vert.y = Array As Float(2, 2,-2,-2, 2, 2,-2,-2)
    vert.z = Array As Float(2,-2,-2, 2, 2,-2,-2,2)

    Can you explain me or show me where I can find any documentations?

    Thanks!
     
  16. rkwan

    rkwan Member Licensed User

    Hello, I am a newbie trying to use this good example to plot 3D scatter points like this:-
    https://matplotlib.org/examples/mplot3d/scatter3d_demo.html
    I can get the elevation and azimuth view change with sliders.

    However, when I tried the Surface example with
    cnvs.DrawCircle() or cnvs.DrawOval(),
    I cannot get good effect like as in matplot3d.

    Any suggestion please?

    Thanks & Best Regards,
     
  17. derez

    derez Expert Licensed User

    The library is for drawing 3D bodies or surfaces, not for showing scatter points. Each object that you want to show is made of surfaces, unlike points.
    Seems to me that you should use something else.
     
  18. rkwan

    rkwan Member Licensed User

    Oh, I see. Thanks for your advice, Derez! By the way, any idea on what else I can try please? I am also trying the LibGDX now... Thanks & Best Regards,
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice