[XUI] 3D, rotations and pivots

Discussion in 'Chit Chat' started by Star-Dust, May 17, 2018.

  1. Star-Dust

    Star-Dust Expert Licensed User

    Last edited: Jun 29, 2018
  2. Star-Dust

    Star-Dust Expert Licensed User

    Unfortunately I had little time and I stopped.

    Today I did a test inserting the values of Sin Cos into two arrays so as to find the values already calculated, as you suggested.

    Unfortunately, the yield in terms of time is low because the calculations do not decrease.
    The reason is that you have to do the MOD of the degrees because sometimes I could have degrees of enegative value or grai higher than the maximum value (ie higher than 360° or 2π)

    On the one hand I speed up on the other slow down.

    If I have time I will try other solutions

    eg.
    Insert value into array
    Code:
    For i=0 To (360*Precision)-1
            MySin(i)=
    SinD(i/Precision)
            MyCos(i)=
    CosD(i/Precision)
        
    Next
    Calc Sin / Cos
    Code:
    Private Sub apSin(Degree As Float) As Double
        
    Return MySin(((360+Degree) Mod 360)* Precision)
    End Sub

    Private Sub apCos(Degree As Float) As Double
        
    Return MyCos(((360+Degree) Mod 360)* Precision)
    End Sub
     
    Last edited: Jul 2, 2018
  3. Star-Dust

    Star-Dust Expert Licensed User

    They are like a child and my attention is continually captured by new things ... I echo a new thing created in Java

    ezgif.com-video-to-gif.gif

    I am going to translate it for B4X XUI and if I can merge it with my 3D.
     
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    Okay now that would be good. @Star-Dust that sounds rather difficult to implement and also to keep it running relatively smoothly will take some doing will it not???
     
  5. Star-Dust

    Star-Dust Expert Licensed User

    Strangely enough it is a very small code, unfortunately it is I who do not have the time but I think it could be done in just one day
     
  6. Informatix

    Informatix Expert Licensed User

    ilan, Peter Simpson and Star-Dust like this.
  7. Star-Dust

    Star-Dust Expert Licensed User

    little animation created with my library
    33.gif

    Code:
    Code:
    For Q=0 To 1080 Step 10 ' 1080 = 360 *3
                    P3D.clear
                    
    Dim ID As Int = 0
                    
    For z=-120 To 120 Step 10
                        
    For x=-120 To 120 Step 10
                            
    Dim y1 As Int =50 * CosD(z*2+q) * SinD(x*2)
                            
    Dim y2 As Int =50 * CosD(z*2+q) * SinD(x*2+20)

                            
    Dim NewPointList(2As Point_Type
                            NewPointList(
    0)=(P3D.CtP(X,y1,z))
                            NewPointList(
    1)=(P3D.CtP(X+10,y2,z))
                            P3D.AddPolygon(
    ID,NewPointList,xui.Color_White,xui.Color_Transparent)
                            
    ID=ID+1
                        
    Next
                    
    Next
                
                    
    For x=-120 To 120 Step 10
                        
    For z=-120 To 120 Step 10
                            
    Dim y1 As Int =50 * CosD(z*2+q) * SinD(x*2)
                            
    Dim y2 As Int =50 * CosD(z*2+20+q) * SinD(x*2)

                            
    Dim NewPointList(2As Point_Type
                            NewPointList(
    0)=(P3D.CtP(X,y1,z))
                            NewPointList(
    1)=(P3D.CtP(X,y2,z+10))
                            P3D.AddPolygon(
    ID,NewPointList,xui.Color_White,xui.Color_Transparent)
                            
    ID=ID+1
                        
    Next
                    
    Next
                    P3D.RenderToView(
    Panel)
                    Sleep(
    0)
    Next
     
    Last edited: Jul 5, 2018
    ilan, Beja and Johan Hormaza like this.
  8. Star-Dust

    Star-Dust Expert Licensed User

    It seems more complicated than I imagined, but I translated 9 classes out of 11.

    Two are still missing, but then it should be tested. I do not know how long it will take
     
    Peter Simpson likes this.
  9. Star-Dust

    Star-Dust Expert Licensed User

    I'm doing tests to speed up the design of the polygons.
    Now I have uploaded the same obj file twice, but every time it takes different times.

    The points order them by priority on a and Z so as to understand which point should be drawn before and after.

    I wonder why these variations, if the file is always the same.

    To sort by the Z axis use ListVertices.SortType ("Z", True) .. is there a faster method?
    After much discourse, as seen from the logs, the calculation time of the vertices is not excessive, while the sorting of the Z axis and the actual design is the one that slows down everything.

    update Apk and Jar at post#48
     
    Last edited: Jul 5, 2018
    Peter Simpson likes this.
  10. Star-Dust

    Star-Dust Expert Licensed User

    I've tried other algorithms, Bubble Sort, Quick Sort, Split & Merge ... but none of them is just as fast. Times quadruple.

    I tried to sort by priority as I insert the vertices in the object list, but even so the situation gets worse. Because a sort is made for each vertex inserted, even modifying the Bubble sort to insert only one element so reducing to a single cycle, the times become enormous.

    I could save time, only by calculating the priority value as I insert the points and sorting the polygons/objects only at the time of rendering/Draw

    Now:
     
    Last edited: Jul 6, 2018
    Peter Simpson and Johan Hormaza like this.
  11. Peter Simpson

    Peter Simpson Expert Licensed User

    Hey you've been an extremelebusy busy little bumble bee @Star-Dust. What are you doing inside your home coding, shouldn't you be outside in the sun tanning it up :cool:
     
    JordiCP and Johan Hormaza like this.
  12. Star-Dust

    Star-Dust Expert Licensed User

    I like the mountains, my wife the sea. We have found a compromise, we are at home; I put a mountain background on my PC and she watches films that portray beaches.

    Joke, I will go there soon
     
  13. Star-Dust

    Star-Dust Expert Licensed User

    Today I could not go to sea so I improved the example app
    35.gif 36.gif
    With this new example I mixed a still Background-Image with a moving sphere.
     
    Last edited: Jul 7, 2018
    Beja, jimmyF, ilan and 4 others like this.
  14. Star-Dust

    Star-Dust Expert Licensed User

    PACMAN
    37.gif

    Code:
    Dim Base() As String = Array As String( _
        
    "*************", _
        
    "*           *", _
        
    "* **     ** *", _
        
    "* *       * *", _
        
    "*   ** **   *", _
        
    "*   *   *   *", _
        
    "*           *", _
        
    "*   *   *   *", _
        
    "*   ** **   *", _
        
    "* *       * *", _
        
    "* **     ** *", _
        
    "*           *", _
        
    "*************" _
        )
    Code:
    P3D.Initialize

    'Draw Base of the labyrinth
    Dim Center as float = Base.Length/2
    For y=0 To Base.Length-1
        
    For x=0 To Base(Y).Length-1
            
    If Base(y).CharAt(x)="*" Then P3D.AddCube(0,-(Large*Center)+y*Large,-(Large*Center)+x*Large,Large,-(Large*(Center-1))+y*Large,-(Large*(Center-1))+x*Large,0,xui.Color_Gray,Array As Int(xui.Color_White))
        
    Next
    Next

    'Draw PacMan
    P3D.AddSpere2(1,PacManX,PacManY,Large/2,.Large/2,xui.Color_Gray,xui.Color_Yellow,0,225,0,180,10,10)


     
    Last edited: Jul 9, 2018
    ilan, Erel, Peter Simpson and 3 others like this.
  15. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    :eek: extraordinary my friend!
     
  16. Star-Dust

    Star-Dust Expert Licensed User

    With the help of others I'm testing the library for IOS.
    We have to overcome some unexpected obstacle with BitmapCreator.

    I will show you a few screenshots of IOS.

    I can tell you that it is working well, but is slow to draw.
     
    Last edited: Jul 12, 2018
    ilan and Beja like this.
  17. Star-Dust

    Star-Dust Expert Licensed User

    You can download a demo version of the library (for B4A and B4J) in this thread
     
    Last edited: Jul 10, 2018
    Peter Simpson, Erel and Johan Hormaza like this.
  18. Star-Dust

    Star-Dust Expert Licensed User

    First version for iOS. I can not provide you any more for the moment because I'm not working on it. But the interesting thing will be to evaluate the performance:D
    1 i.png 2 i.png 3 i.png 4 i.png 5 i.png 6 i.png

    Thanks and applause to @sorex who compiled library for ios and translated the example. ;)

    At this point I pass on other projects thanks for the attention :)
     
    Last edited: Jul 11, 2018
    Peter Simpson, Beja, JordiCP and 2 others like this.
  19. Star-Dust

    Star-Dust Expert Licensed User

  20. Star-Dust

    Star-Dust Expert Licensed User

    My library used to create a simple animation. Maybe an intro to an App.
    38.gif
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("Layout1")
        P3D.Initialize
       
        P3D.AddImage(
    1,xui.LoadBitmap(File.DirAssets,"StarDust.png"),P3D.CtP(-50,-50,0),P3D.CtP(50,-50,0),P3D.CtP(50,50,0),P3D.CtP(-50,50,0))
       
        
    For i=0 To 360 Step 10
            P3D.Rotate2(
    Null,0,i,i).RenderToView(PanelPresentation,PanelPresentation.Width/2,PanelPresentation.Height/2,i/180,1)
            Sleep(
    20)
        
    Next
       
        P3D.RenderToView(PanelPresentation,PanelPresentation.Width/
    2,PanelPresentation.Height/2,2,1)
        ButtonStart.SetVisibleAnimated(
    1000,True)
    End Sub

    Sub ButtonStart_Click
        PanelPresentation.Visible=
    False
        
    Activity.LoadLayout("Layout2")
    End Sub
     
    andymc, Erel and inakigarm like this.
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