Posted: 6th Dec 2024 17:51
Been a while since I last used AppGameKit so am a bit rusty. Here is AppGameKit code for Mandelbulb (arrow keys at moment). Camera needs more work. DIMEN of 128 causes program to bomb out unlike DBPro, but is ok with values 32 and 64. [edit]- DIMEN 128 works better in x64 AGKStudio, but unable to move camera around , lots of "not responding"

+ Code Snippet
// Project: MandelBulb01 
// Created: 2024-12-05

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "MandelBulb v0.1" )
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

#constant DIMEN 64 ` AGK runs out of memory using value of 128 (not a problem in DBPro), value of 64 is ok so far, 
#constant MAXITERATIONS 20
#constant N 16
#constant TRUE 1
#constant FALSE 0

type Pvector 
	x# 
	y# 
	z# 
endtype

Setup()
Draw()

do
    Print( ScreenFPS() )
    print ( GetRawLastKey( ) )
		if GetRawKeyState( 38 ) 
			MoveCameraUp(1, -10.0)
			`MoveCameraLocalY(1,10.0)
 		endif
 		
 		`S key
		if GetRawKeyState( 40 ) 
			MoveCameraDown(1, -10.0) 
			`MoveCameraLocalY(1,-10.0)
 		endif
	
		`A key
		if GetRawKeyState( 37 )
			`MoveCameraLeft(1, 10.0) 
			MoveCameraLocalX(1,-10.0)
 		endif
 		
 		`D key
		if GetRawKeyState( 39 )
			`MoveCameraRight(1, 10.0) 
			MoveCameraLocalX(1,10.0)
 		endif

	`control camera using arrowkeys 0,10.0,10.0

	`if inkey$()=","
	`	dec camz#, 10.0
	`endif
	
	`if inkey$()="."
	`	inc camz#, 10.0
	`endif
	
	`if inkey$()="n"
	`	dec camx#, 10.0
	`endif
	
	`if inkey$()="m"
	`	inc camx#, 10.0
	`endif

   SetCameraRotation( 1, cx#,cy#,cz#)
    
    Sync()
loop

function Setup()
	global cx#=0 : global cy#=0 : global cz#=-500  
	SetCameraPosition(1,cx#,cy#,cz#)
	SetCameraRotation(1,0,0,0)

	global Mandelbulb as Pvector[] // creates an empty array
	global zeta as integer 
	zeta = createvector3( 0, 0, 0)
	global c as integer 
	c = createvector3()
	vec as integer
	vec = 0
	global iteration as integer

	for i = 0 to DIMEN
		for j = 0 to DIMEN
			edge = FALSE
			for k = 0 to DIMEN
				x# = map(i, 0 , DIMEN, -1.0, 1.0 )
				y# = map(j, 0 , DIMEN, -1.0, 1.0 )
				z# = map(k, 0 , DIMEN, -1.0, 1.0 )

				setvector3(zeta,0,0,0)
				
				`n = 8			
				`n = 16 ` fractal death star :-)			
				`maxiterations = 10
				`maxiterations = 20
				iteration = 0

				while TRUE
					spherical(c, getvector3x(zeta), getvector3y(zeta), getvector3z(zeta))
					newx# = (getvector3x(c)^N) * sin(getvector3y(c)*N) * cos(getvector3z(c)*N)
					newy# = (getvector3x(c)^N) * sin(getvector3y(c)*N) * sin(getvector3z(c)*N)
					newz# = (getvector3x(c)^N) * cos(getvector3y(c)*N)				
					
					setvector3(zeta, newx#+x#, newy#+y#, newz#+z#) 
					inc iteration
					
					cr# = getvector3x(c) 
					if cr# > 16
						if edge
							edge = FALSE
						endif
						exit
					endif
					
					if iteration > MAXITERATIONS
						if not edge
							edge = TRUE
							Mandelbulb.length=vec
							Mandelbulb[vec].x#=x#*100.0 : Mandelbulb[vec].y#=y#*100.0 : Mandelbulb[vec].z#=z#*100.0  
							inc vec
						endif
						exit
					endif
				endwhile
			next k
		next j
	next i
endfunction

function map(n1 as float , oldlow as float , oldhigh as float , newlow as float , newhigh as float  )
	r1 as float
	n1=n1+0.0 : oldlow=oldlow+0.0 : oldhigh=oldhigh+0.0 : : newlow=newlow+0.0 : newhigh=newhigh+0.0
	r1 = ( ( n1 - oldlow ) / (oldhigh - oldlow) ) * (newhigh - newlow) + newlow
endfunction r1

function spherical(c, x#, y#, z#)
	r# = sqrt(x#*x# + y#*y# + z#*z#)
    `ATANFULL - This command will return the angle of two points in degrees between 0 and 360. 
	`theta# = atanfull(sqrt(x#*x#+y#*y#),z#)
	`phi# = atanfull(y#,x#)
	theta# = atan2(sqrt(x#*x#+y#*y#),z#)
	phi# = atan2(y#,x#)
	`theta# = atan2rad(sqrt(x#*x#+y#*y#),z#)
	`phi# = atan2rad(y#,x#)
	setvector3(c,r#,theta#,phi#)		
endfunction 

function Draw()
	CreateObjectBox(1,1,1,1)
	o=2
	for i = 0 to Mandelbulb.length
		cloneobject(o,1)
		fixobjectpivot(o)
		setobjectcolor(o,255,0,0,255) 
		setobjectposition(o,MandelBulb[i].x#, MandelBulb[i].y#, MandelBulb[i].z#)
		inc o
	next i
	deleteobject(1)
endfunction

function MoveCameraUp(camID as integer, dist as float)
   local sx as float
   local sy as float
   local sz as float
 
   sx = getcameraanglex(camID)
   sy = getcameraangley(camID)
   sz = getcameraanglez(camID)
 
   SetCameraRotation( camID, WrapValue(sx-90), 0, 0)
   movecameralocaly( camID, dist)
   SetCameraRotation( camID, sx, sy, sz)
endfunction

function MoveCameraDown(camID as integer, dist as float)
   local sx as float
   local sy as float
   local sz as float
 
   sx = getcameraanglex(camID)
   sy = getcameraangley(camID)
   sz = getcameraanglez(camID)

   SetCameraRotation( camID, WrapValue(sx+90), 0, 0)
   movecameralocaly( camID, dist)
   SetCameraRotation( camID, sx, sy, sz)
endfunction

function MoveCameraRight(camID as integer, dist as float)
   local sx as float
   local sy as float
   local sz as float
 
   sx = getcameraanglex(camID)
   sy = getcameraangley(camID)
   sz = getcameraanglez(camID)
 
   SetCameraRotation( camID, 0, WrapValue(sy+90), 0)
   movecameralocaly( camID, dist)
   SetCameraRotation( camID, sx, sy, sz)
endfunction
 
function MoveCameraLeft(camID as integer, dist as float)
   local sx as float
   local sy as float
   local sz as float
 
   sx = getcameraanglex(camID)
   sy = getcameraangley(camID)
   sz = getcameraanglez(camID)
 
   SetCameraRotation( camID, 0, WrapValue(sy-90), 0)
   movecameralocaly( camID, dist)
  SetCameraRotation( camID, sx, sy, sz)
endfunction

Function WrapValue( value As Float )
    value = value / 360.0
    value = 360.0 + ( 360.0 * ( value - Trunc( value ) ) )
EndFunction value
Posted: 15th Jan 2025 16:36
forums shutting , 10 feb2025. been here since 2005 , signed BOTR - see ya.