# [XUI] 3D, rotations and pivots

Longtime User
Last edited:

#### Star-Dust

##### Expert
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
Longtime User
They are like a child and my attention is continually captured by new things ... I echo a new thing created in Java

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

#### Peter Simpson

##### Expert
Longtime User
I am going to translate it for B4X XUI and if I can merge it with my 3D.

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???

#### Star-Dust

##### Expert
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
Longtime User
little animation created with my library

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))
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))
ID=ID+1
Next
Next
P3D.RenderToView(Panel)
Sleep(0)
Next``````

Last edited:

#### Star-Dust

##### Expert
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
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 **
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 **
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
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 **
Start Draw to View
Time Priority Z calc: 0
Sort for Z: 362
Time Draw: 1744
Total Time: 2106

Last edited:

#### Peter Simpson

##### Expert
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

#### Star-Dust

##### Expert
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
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
Longtime User
Today I could not go to sea so I improved the example app

With this new example I mixed a still Background-Image with a moving sphere.

Last edited:

#### Star-Dust

##### Expert
Longtime User
PACMAN

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

Last edited:

#### Johan Hormaza

##### Well-Known Member
Longtime User
extraordinary my friend!

#### Star-Dust

##### Expert
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:

Longtime User

Last edited:

#### Star-Dust

##### Expert
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

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:

Longtime User

#### Star-Dust

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

B4X:
``````Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
P3D.Initialize

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