[XUI] 3D, rotations and pivots

Star-Dust

Expert
Licensed User
Longtime User
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Another thought: Don't pass Point (a MyVertices object) to the AddVertice_If_not_Exist method, but the coordinates. This way you do not allocate a MyVertices object in case it does not need allocation. The method can decide if it needs to create a a MyVertices object or return an existing MyVertices object.

B4X:
Dim newPoint as MyVertices = AddVertice_If_not_Exist(ArrayVertices, X, Y, Z)
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
B4X:
For i=0 To (360*Precision)-1
        MySin(i)=SinD(i/Precision)
        MyCos(i)=CosD(i/Precision)
    Next

Calc Sin / Cos
B4X:
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:

Star-Dust

Expert
Licensed User
Longtime 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.
 

Star-Dust

Expert
Licensed User
Longtime 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???
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
 

Star-Dust

Expert
Licensed User
Longtime User
little animation created with my library
33.gif


Code:
B4X:
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(2) As 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(2) As 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:

Star-Dust

Expert
Licensed User
Longtime 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???
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
 

Star-Dust

Expert
Licensed User
Longtime 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?
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Time load: 3476 Vertices: 432534
Start Draw to View
Time Priority Z calc: 130
Sort for Z: 579
Time Draw: 2015
Total Time: 2724
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Time load: 3384 Vertices: 432534
Start Draw to View
Time Priority Z calc: 92
Sort for Z: 482
Time Draw: 2108
Total Time: 2682

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:

Star-Dust

Expert
Licensed User
Longtime User
To sort by the Z axis use ListVertices.SortType ("Z", True) .. is there a faster method?
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:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Time load: 3384 Vertices: 432534
Start Draw to View
Time Priority Z calc: 0
Sort for Z: 362
Time Draw: 1744
Total Time: 2106
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime 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:
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
 

Star-Dust

Expert
Licensed User
Longtime 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:

Star-Dust

Expert
Licensed User
Longtime User
PACMAN
37.gif


B4X:
Dim Base() As String = Array As String( _
    "*************", _
    "*           *", _
    "* **     ** *", _
    "* *       * *", _
    "*   ** **   *", _
    "*   *   *   *", _
    "*           *", _
    "*   *   *   *", _
    "*   ** **   *", _
    "* *       * *", _
    "* **     ** *", _
    "*           *", _
    "*************" _
    )

B4X:
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:

Star-Dust

Expert
Licensed User
Longtime 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:

Star-Dust

Expert
Licensed User
Longtime 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:

Star-Dust

Expert
Licensed User
Longtime User
My library used to create a simple animation. Maybe an intro to an App.
38.gif

B4X:
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
 
Top