Hi guys ! I come up this time with an easy way to make a torus withing AppGameKit . I hope you like it !
// Project: torus
// Created: 2018-12-15
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "torus" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
`
`
` Creating and saving an empty image of 15*32 pixeles
` never understood why we have to get 1,1,17,32 to obtain an image of 15*32 PIXELS
drawbox(1,1,17,36,0,0,0,0,1)
getimage(1000,1,1,17,36)
gosub texture
`Creating rings of 16 vertex
thick=5 `no more than 8
for i= 1 to 16
createobjectbox(i,0.1,0.1,0.1)
setobjectrotation(i,0,i*25.72,0) `rotating all vertex to close the ring
moveobjectlocalz(i,thick)
next
`making an object to fix them all to it
createobjectbox(5000,0.1,0.1,0.1)
`fixing all objects to object 5000
for i= 1 to 16
FixObjectToObject(i,5000)
setobjectposition(i,getobjectworldx(i)+10,getobjectworldy(i),getobjectworldz(i))
next
`creating vertex
obj=1000
for t= 1 to 32
for i= 1 to 15
inc obj,1
createobjectbox(obj,0.1,0.1,0.1)
setobjectposition(obj,GetObjectWorldx(i),getobjectworldy(i),getobjectworldz(i))
next i
setobjectrotation(5000,0,0,t*11.615) `revolving object 5000 in z axis to get all vertex x,y,z
next t
`saving black image just to force creating an object with a flat mesh of 15*31 = 480 VERTEX
saveimage(1000,"raw:D:media\torus.png")
CreateObjectFromHeightMap(60000,"torus.png",300,0,300,1,1)
setobjectimage(60000,10,0)
mesh = CreateMemblockFromObjectMesh(60000,1)
`Getiong number of vertex
verts= GetMemblockInt( mesh, 0 )
o=1000
for i= 0 to verts-1
inc o,1
x#=Getobjectx(o)
y#=Getobjecty(o)
z#=getobjectz(o)
`fixing mesh vertex in objects x,y,z
SetMeshMemblockVertexPosition(mesh,i, x#,y#,z#)
SetMeshMemblockVertexNormal(mesh,i,x#,y#,z#)
next i
DeleteMemblock(1)
`fixing mesh
SetObjectMeshFromMemblock(60000,1,mesh)
setcameraposition(1,0,10,-80)
SetCameraLookAt(1,0,0,0,0)
do
gosub camara
turn#=turn#+2
setobjectrotation(60000,turn#,turn#,turn#)
// Print( ScreenFPS() )
// print(obj-1000)
// print(verts)
Sync()
loop
camara:
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 1 ) // cursor up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -1 ) // cursor down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -1 ) // cursor iz
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 1 ) // cursor derecha
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/1.0
fDiffY# = (GetPointerY() - starty#)/1.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
return
Texture:
red=makecolor(155,155,0)
drawbox(0,0,640,480,red,red,red,red,1)
x=300
y=200
g=0
c=0
for i= 1 to 800
inc g,5
inc c,1
if c>255 then c=50
x=x+(cos(g)*i/50)
y=Y+(sin(g)*i/50)
col=makecolor(c*2,c,0)
drawbox(x,y,x+i/10,y+i/30,col,col,col,col,1)
next i
getimage(10,220,120,170,170)
return
Cheers.
I'm not a grumpy grandpa
