Hi,
As you might remember, I published a small 3D engine for windows mobile. (as found here: http://www.b4x.com/forum/share-your-creations/3125-3d-plotter.html)
Today i rewrote it in Basic4Android. The engine animates a cube which rotates. Can you guys please test it? I just tested it in the emulator and I dont have any android device yet.
Just paste the below code in a new project.
Thanks
Ps.: I also appreciate hints and tips
As you might remember, I published a small 3D engine for windows mobile. (as found here: http://www.b4x.com/forum/share-your-creations/3125-3d-plotter.html)
Today i rewrote it in Basic4Android. The engine animates a cube which rotates. Can you guys please test it? I just tested it in the emulator and I dont have any android device yet.
Just paste the below code in a new project.
Thanks
Ps.: I also appreciate hints and tips
B4X:
Sub Process_Globals
Dim time As Timer
End Sub
Sub Globals
globxrot=0
globyrot=0
globzrot=0
framecount=0
zoom = 200
depth = 40
Dim matrix(64,64) As Boolean
Dim xarr(8) As Int
Dim yarr(8) As Int
Dim zarr(8) As Int
Dim xpoints(8) As Float
Dim ypoints(8) As Float
counteri=0
Dim testbtn As Button
Dim Label1 As Label
Dim ProgressBar1 As ProgressBar
Dim can As Canvas
End Sub
Sub init
xarr(0)=10: yarr(0)=10: zarr(0)=10
xarr(1)=10: yarr(1)=10: zarr(1)=-10
xarr(2)=10: yarr(2)=-10:zarr(2)=-10
xarr(3)=-10:yarr(3)=-10:zarr(3)=-10
xarr(4)=-10:yarr(4)=-10:zarr(4)=10
xarr(5)=-10:yarr(5)=10: zarr(5)=10
xarr(6)=-10:yarr(6)=10: zarr(6)=-10
xarr(7)=10: yarr(7)=-10:zarr(7)=10
matrix(1,0)=True
matrix(5,0)=True
matrix(7,0)=True
matrix(2,1)=True
matrix(6,1)=True
matrix(3,2)=True
matrix(7,2)=True
matrix(4,3)=True
matrix(6,3)=True
matrix(7,4)=True
matrix(5,4)=True
matrix(6,5)=True
End Sub
Sub Activity_Create(FirstTime As Boolean)
init
can.Initialize(Activity)
time.Initialize("Time",50)
time.Enabled=True
End Sub
Sub Activity_Resume
time.Enabled=True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
time.Enabled=False
End Sub
Sub plot_object(xrot,yrot,zrot)
counteri=0
For i=0 To 7
threedpoints(xarr(i),yarr(i),zarr(i),xrot,yrot,zrot)
Next
linecon
End Sub
Sub threedpoints(xthreed,ythreed,zthreed,rotx,roty,rotz)
x2 = (xthreed * Cos(rotZ)) - (ythreed * Sin(rotZ))
y2 = (xthreed * Sin(rotZ)) + (ythreed * Cos(rotZ))
x3 = (x2 * Cos(rotY)) - (zthreed * Sin(rotY))
z2 = (x2 * Sin(rotY)) + (zthreed * Cos(rotY))
y3 = (y2 * Cos(rotX)) - (z2 * Sin(rotX))
z3 = (y2 * Sin(rotX)) + (z2 * Cos(rotX))
xtwod = zoom * (x3 / (z3 + depth)) + 120
ytwod = zoom * (y3 / (z3 + depth)) + 130
xpoints(counteri)=xtwod
ypoints(counteri)=ytwod
counteri=counteri+1
End Sub
Sub linecon
For n=0 To 7
For i=n To 7
If matrix(i,n)=True Then
can.DrawLine(xpoints(n),ypoints(n),xpoints(i),ypoints(i),Colors.White,1)
End If
Next
Next
End Sub
Sub time_Tick
can.DrawColor(Colors.Black)
globxrot=globxrot+0.1
globyrot=globyrot+0.1
plot_object(globxrot,globyrot,globzrot)
Activity.Invalidate
End Sub
Last edited: