Posted: 3rd Sep 2003 11:03
I made this quickly to help someone but it lacks real physics.

any guru want to add some so we have a nice demo for air flight.?


+ Code Snippet
rem ----------------------------------------
rem PROGRAM NAME   INDIS WIDDLE AIRPWAYNE
rem author INDI
rem info A SIMPLE PLANE EXAMPLE
rem date SEPTEMBER 3 2003
rem ----------------------------------------

rem ----------------------------------------
rem SETUP
rem ----------------------------------------
sync on : sync rate 60 : autocam off : hide mouse
set text size 13 : set text font "verdana" : set text to bold

rem ----------------------------------------
rem DECLARE VARIABLES
rem ----------------------------------------

rem ----------------------------------------
rem INIT MEDIA
rem ----------------------------------------

make matrix 1,5000,5000,20,20
position matrix 1,-2500,0,-2500

rem the body
make object cube 1,1
scale object 1,75,75,400
position object 1,0,0,0

rem the wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,1,1
offset limb 1,1,0,0.2,0.3

rem the tail wing
make object cube 100,1
scale object 100,250,15,40
make mesh from object 1,100
delete object 100
add limb 1,2,1
offset limb 1,2,0,0.3,-0.3

rem the tail rudder
make object cube 100,1
scale object 100,10,100,20
make mesh from object 1,100
delete object 100
add limb 1,3,1
offset limb 1,3,0,1,-0.3

rem the propellar
make object cube 100,1
scale object 100,30,200,10
make mesh from object 1,100
delete object 100
add limb 1,4,1
offset limb 1,4,0,0,0.6

rem ----------------------------------------
rem PRE MAIN
rem ----------------------------------------

ink rgb(255,255,255),1

rem ----------------------------------------
rem MAIN
rem ----------------------------------------
disable escapekey
while escapekey()=0

if leftkey()=1 then roll object left 1,1.0
if rightkey()=1 then roll object right 1,1.0
if upkey()=1 then pitch object down 1,1
if downkey()=1 then pitch object up 1,1
if inkey$()="[" then turn object left 1,1
if inkey$()="]" then turn object right 1,1


if shiftkey()=1
speed# = speed# +0.1
endif


if shiftkey()=0
speed# = speed# -0.0001
if speed# < 0.0 then speed# = 0.0
endif

move object 1,speed#

r = r +6
rotate limb 1,4,0,0,wrapvalue(r)


position camera Object position x(1),Object position y(1)+5,Object position z(1)-25

point camera Object position x(1),Object position y(1),Object position z(1)

rem ----------------------------------------
rem DEBUG OUTPUT
rem ----------------------------------------

text 10,10,"FPS:"+STR$(screen fps())

sync
endwhile

rem ----------------------------------------
rem CLEAN UP
rem ----------------------------------------

delete matrix 1

delete object 1

end
Posted: 3rd Sep 2003 13:35
heres another plane if you want a red one!

they go faster



+ Code Snippet
rem the body
make object cube 1,1
scale object 1,75,75,400
position object 1,0,0,0
color object 1, rgb(255,0,0)


rem the top wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,1,1
offset limb 1,1,0,0.8,0.3
color limb 1,1,rgb(255,0,0)

rem the bottom wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,2,1
offset limb 1,2,0,-0.5,0.3
color limb 1,2,rgb(255,0,0)


rem the tail wing
make object cube 100,1
scale object 100,250,15,20
make mesh from object 1,100
delete object 100
add limb 1,3,1
offset limb 1,3,0,0.3,-0.5
color limb 1,3,rgb(255,0,0)


rem the propellar
make object cube 100,1
scale object 100,30,200,10
make mesh from object 1,100
delete object 100
add limb 1,4,1
offset limb 1,4,0,0,0.6


rem the tail rudder
make object cube 100,1
scale object 100,10,100,20
make mesh from object 1,100
delete object 100
add limb 1,5,1
offset limb 1,5,0,1,-0.5
color limb 1,5,rgb(255,0,0)



rem landing gear left
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,6,1
offset limb 1,6,1,-0.5,0.3
color limb 1,6,rgb(255,0,0)



rem landing gear right
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,7,1
offset limb 1,7,-1,-0.5,0.3
color limb 1,7,rgb(255,0,0)
Posted: 3rd Sep 2003 15:18
the Darthster did some most excellent work with the new sound addition and added a shifting routine I added some fog and inbuilt texture and viola it looks good


+ Code Snippet
Rem Project: indi plane
Rem Created: 03/09/03 11:01:13
rem ----------------------------------------
rem ----------------------------------------
rem PROGRAM NAME   INDIS WIDDLE AIRPWAYNE
rem author INDI
rem info A SIMPLE PLANE EXAMPLE
rem date SEPTEMBER 3 2003
rem ----------------------------------------

rem ----------------------------------------
rem SETUP
rem ----------------------------------------
sync on : sync rate 60 : autocam off : hide mouse
set text size 13 : set text font "verdana" : set text to bold
color backdrop rgb(0,0,0)

set camera range 1,9000
if fog available() =1
fog on
fog distance 9000
endif

rem ----------------------------------------
rem DECLARE VARIABLES
rem ----------------------------------------

rem ----------------------------------------
rem INIT MEDIA
rem ----------------------------------------

ink rgb(0,155,0),1
box 0,0,32,32
for i = 1 to 200
ink rgb(0,rnd(155)+100,0),1
dot rnd(32),rnd(32)
next i

get image 1,0,0,31,31
cls






make matrix 1,20000,20000,40,40
position matrix 1,-10000,0,-500
prepare matrix texture 1,1,1,1
randomize matrix 1,2000

update matrix 1

smooth_matrix(1,40,40,1)
update matrix 1

rem the body
make object cube 1,1
scale object 1,75,75,400
position object 1,0,0,0
color object 1, rgb(255,0,0)


rem the top wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,1,1
offset limb 1,1,0,0.8,0.3
color limb 1,1,rgb(255,0,0)

rem the bottom wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,2,1
offset limb 1,2,0,-0.5,0.3
color limb 1,2,rgb(255,0,0)


rem the tail wing
make object cube 100,1
scale object 100,250,15,20
make mesh from object 1,100
delete object 100
add limb 1,3,1
offset limb 1,3,0,0.3,-0.5
color limb 1,3,rgb(255,0,0)


rem the propellar
make object cube 100,1
scale object 100,30,200,10
make mesh from object 1,100
delete object 100
add limb 1,4,1
offset limb 1,4,0,0,0.6


rem the tail rudder
make object cube 100,1
scale object 100,10,100,20
make mesh from object 1,100
delete object 100
add limb 1,5,1
offset limb 1,5,0,1,-0.5
color limb 1,5,rgb(255,0,0)



rem landing gear left
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,6,1
offset limb 1,6,1,-0.5,0.3
color limb 1,6,rgb(255,0,0)



rem landing gear right
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,7,1
offset limb 1,7,-1,-0.5,0.3
color limb 1,7,rgb(255,0,0)


make memblock 1,12+1378
write memblock dword 1,0,352800
write memblock dword 1,4,1378
write memblock dword 1,8,10
for i#=0.0 to 1377.0
write memblock byte 1,i#+12,int((sin(i#*16.71)*((sin(i#*190.91)*50)+(sin(i#*90.91)*50)+(sin(i#*160.43)*27)))+128)
next i#
make sound from memblock 1,1
loop sound 1
a=300


speed# = 0.5

rem ----------------------------------------
rem PRE MAIN
rem ----------------------------------------

position object 1,0,2000,0

ink rgb(255,255,255),1

rem ----------------------------------------
rem MAIN
rem ----------------------------------------
disable escapekey
while escapekey()=0

if leftkey()=1 then roll object left 1,1.0
if rightkey()=1 then roll object right 1,1.0
if upkey()=1 then pitch object down 1,1
if downkey()=1 then pitch object up 1,1
if inkey$()="[" then turn object left 1,1
if inkey$()="]" then turn object right 1,1


if shiftkey()=1
speed# = speed# +0.1
endif


if shiftkey()=0
speed# = speed# -0.0001
if speed# < 0.0 then speed# = 0.0
endif

move object 1,speed#

if object position x(1)>500
position object 1,object position x(1)-500,object position y(1),object position z(1)
shift matrix left 1
update matrix 1
endif

if object position x(1)<-500
position object 1,object position x(1)+500,object position y(1),object position z(1)
shift matrix right 1
update matrix 1
endif

if object position z(1)>500
position object 1,object position x(1),object position y(1),object position z(1)-500
shift matrix up 1
update matrix 1
endif

if object position z(1)<-500
position object 1,object position x(1),object position y(1),object position z(1)+500
shift matrix down 1
update matrix 1
endif

r = wrapvalue(r + 6 + speed#)
rotate limb 1,4,0,0,r

set sound speed 1,300+(speed#*5)

position camera Object position x(1),Object position y(1)+5,Object position z(1)-25
point camera Object position x(1),Object position y(1),Object position z(1)

rem ----------------------------------------
rem DEBUG OUTPUT
rem ----------------------------------------

text 10,10,"FPS:"+STR$(screen fps())

sync
endwhile

rem ----------------------------------------
rem CLEAN UP
rem ----------------------------------------

delete matrix 1

delete object 1

end






function smooth_matrix(matnum,tilex,tilez,times)
for multiple=1 to times

for x=1 to tilex-1
for z=1 to tilez-1

a=get matrix height(matnum,x-1,z+1)
b=get matrix height(matnum,x,z+1)
c=get matrix height(matnum,x+1,z+1)
d=get matrix height(matnum,x+1,z)
e=get matrix height(matnum,x+1,z-1)
f=get matrix height(matnum,x,z-1)
g=get matrix height(matnum,x-1,z-1)
h=get matrix height(matnum,x-1,z)
total=a+b+c+d+e+f+g+h
av#=total/8
set matrix height matnum,x,z,av#
next z
next x
next multiple

for x=0 to tilex
set matrix height matnum,x,0,get matrix height(matnum,x,1)
next x

for x=0 to tilex
set matrix height matnum,x,tilez,get matrix height(matnum,x,tilez-1)
next x

for z=0 to tilez
set matrix height matnum,0,z,get matrix height(matnum,1,z)
next z

for z=0 to tilez
set matrix height matnum,tilex,z,get matrix height(matnum,tilex-1,z)
next z

update matrix matnum
endfunction
Posted: 3rd Sep 2003 16:47
heres one with crappy gravity

+ Code Snippet
Rem Project: indi plane
Rem Created: 03/09/03 11:01:13
rem ----------------------------------------
rem ----------------------------------------
rem PROGRAM NAME   INDIS WIDDLE AIRPWAYNE
rem author INDI
rem info A SIMPLE PLANE EXAMPLE
rem date SEPTEMBER 3 2003
rem
rem credits to The Darthster for memblock sin wave sound idea
rem and shift matrix solution
rem david 89 and red-eye for matrix smoothing
rem ----------------------------------------

rem ----------------------------------------
rem SETUP
rem ----------------------------------------
sync on : sync rate 60 : autocam off : hide mouse
set text size 13 : set text font "verdana" : set text to bold
color backdrop rgb(0,0,0)



set camera range 1,9000
if fog available() =1
fog on
fog distance 9000
endif

rem ----------------------------------------
rem DECLARE VARIABLES
rem ----------------------------------------

rem ----------------------------------------
rem INIT MEDIA
rem ----------------------------------------

ink rgb(0,155,0),1
box 0,0,32,32
for i = 1 to 200
ink rgb(0,rnd(155)+100,0),1
dot rnd(32),rnd(32)
next i

get image 1,0,0,31,31
cls






make matrix 1,20000,20000,40,40
position matrix 1,-10000,0,-10000
prepare matrix texture 1,1,1,1
randomize matrix 1,5000

update matrix 1

smooth_matrix(1,40,40,2)

rem Use matrix normals to make it smooth

`for z=1 to 39
`   for x=1 to 39
      rem Get matrix heights
`      h8#=get matrix height(1,x,z-1)
`      h4#=get matrix height(1,x-1,z)
`      h#=get matrix height(1,x,z)
`      h2#=get matrix height(1,x,z)
      rem Calculate projected angle X using heights
`      x1#=(x-1)*25.0 : y1#=h#
`      x2#=(x+0)*25.0 : y2#=h4#
`      dx#=x2#-x1#
`      dy#=y2#-y1#
`      ax#=atanfull(dx#,dy#)
`      ax#=wrapvalue(90-ax#)

      rem Calculate projected angle Z using heights
`      z1#=(z-1)*25.0 : y1#=h2#
`      z2#=(z+0)*25.0 : y2#=h8#
`      dz#=z2#-z1#
`      dy#=y2#-y1#
`      az#=atanfull(dz#,dy#)
`      az#=wrapvalue(90-az#)

      rem Make normal from projected angle
`      nx#=sin(ax#)
`      ny#=cos(ax#)
`      nz#=sin(az#)

      rem Setting matrix normal for smoothness
`      set matrix normal 1,x,z,nx#,ny#,nz#

`   next x
`next z
update matrix 1


update matrix 1

rem the body
make object cube 1,1
scale object 1,75,75,400
position object 1,0,0,0
color object 1, rgb(255,0,0)


rem the top wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,1,1
offset limb 1,1,0,0.8,0.3
color limb 1,1,rgb(255,0,0)

rem the bottom wing
make object cube 100,1
scale object 100,500,15,40
make mesh from object 1,100
delete object 100
add limb 1,2,1
offset limb 1,2,0,-0.5,0.3
color limb 1,2,rgb(255,0,0)


rem the tail wing
make object cube 100,1
scale object 100,250,15,20
make mesh from object 1,100
delete object 100
add limb 1,3,1
offset limb 1,3,0,0.3,-0.5
color limb 1,3,rgb(255,0,0)


rem the propellar
make object cube 100,1
scale object 100,30,200,10
make mesh from object 1,100
delete object 100
add limb 1,4,1
offset limb 1,4,0,0,0.6


rem the tail rudder
make object cube 100,1
scale object 100,10,100,20
make mesh from object 1,100
delete object 100
add limb 1,5,1
offset limb 1,5,0,1,-0.5
color limb 1,5,rgb(255,0,0)



rem landing gear left
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,6,1
offset limb 1,6,1,-0.5,0.3
color limb 1,6,rgb(255,0,0)



rem landing gear right
make object cube 100,1
scale object 100,50,50,50
make mesh from object 1,100
delete object 100
add limb 1,7,1
offset limb 1,7,-1,-0.5,0.3
color limb 1,7,rgb(255,0,0)


make memblock 1,12+1378
write memblock dword 1,0,352800
write memblock dword 1,4,1378
write memblock dword 1,8,10
for i#=0.0 to 1377.0
write memblock byte 1,i#+12,int((sin(i#*16.71)*((sin(i#*190.91)*50)+(sin(i#*90.91)*50)+(sin(i#*160.43)*27)))+128)
next i#
make sound from memblock 1,1
loop sound 1
a=300


speed# = 15

rem ----------------------------------------
rem PRE MAIN
rem ----------------------------------------
`set shadow shading on 1
set light range 0,16000


position object 1,0,5000,0

ink rgb(255,255,255),1

rem ----------------------------------------
rem MAIN
rem ----------------------------------------
disable escapekey
while escapekey()=0

if leftkey()=1 then roll object left 1,1.0
if rightkey()=1 then roll object right 1,1.0
if upkey()=1 then pitch object down 1,1
if downkey()=1 then pitch object up 1,1
if inkey$()="[" then turn object left 1,1
if inkey$()="]" then turn object right 1,1


if shiftkey()=1
speed# = speed# +0.1
endif


if shiftkey()=0
speed# = speed# -0.01
if speed# < 0.0 then speed# = 0.0
endif

move object 1,speed#


if speed# < 10
position object 1,Object position x(1),Object position y(1)-1,Object position z(1)
endif
if speed# < 8
position object 1,Object position x(1),Object position y(1)-2,Object position z(1)
endif
if speed# < 6
position object 1,Object position x(1),Object position y(1)-3,Object position z(1)
endif
if speed# < 4
position object 1,Object position x(1),Object position y(1)-4,Object position z(1)
endif


if object position x(1)>500
position object 1,object position x(1)-500,object position y(1),object position z(1)
shift matrix left 1
update matrix 1
endif

if object position x(1)<-500
position object 1,object position x(1)+500,object position y(1),object position z(1)
shift matrix right 1
update matrix 1
endif

if object position z(1)>500
position object 1,object position x(1),object position y(1),object position z(1)-500
shift matrix up 1
update matrix 1
endif

if object position z(1)<-500
position object 1,object position x(1),object position y(1),object position z(1)+500
shift matrix down 1
update matrix 1
endif

r = wrapvalue(r + 8 + speed#)
rotate limb 1,4,0,0,r

set sound speed 1,300+(speed#*5)


position camera Object position x(1),Object position y(1)+5,Object position z(1)-25
point camera Object position x(1),Object position y(1),Object position z(1)

rem ----------------------------------------
rem DEBUG OUTPUT
rem ----------------------------------------


box 11,11,INT(speed#),21
text 10,30,"speed"+STR$(speed#)
text 10,50,"FPS:"+STR$(screen fps())

text 10,70,"y"+STR$(Object position y(1))

sync
endwhile

rem ----------------------------------------
rem CLEAN UP
rem ----------------------------------------

delete matrix 1

delete object 1

end






function smooth_matrix(matnum,tilex,tilez,times)
for multiple=1 to times

for x=1 to tilex-1
for z=1 to tilez-1

a=get matrix height(matnum,x-1,z+1)
b=get matrix height(matnum,x,z+1)
c=get matrix height(matnum,x+1,z+1)
d=get matrix height(matnum,x+1,z)
e=get matrix height(matnum,x+1,z-1)
f=get matrix height(matnum,x,z-1)
g=get matrix height(matnum,x-1,z-1)
h=get matrix height(matnum,x-1,z)
total=a+b+c+d+e+f+g+h
av#=total/8
set matrix height matnum,x,z,av#
next z
next x
next multiple

for x=0 to tilex
set matrix height matnum,x,0,get matrix height(matnum,x,1)
next x

for x=0 to tilex
set matrix height matnum,x,tilez,get matrix height(matnum,x,tilez-1)
next x

for z=0 to tilez
set matrix height matnum,0,z,get matrix height(matnum,1,z)
next z

for z=0 to tilez
set matrix height matnum,tilex,z,get matrix height(matnum,tilex-1,z)
next z

update matrix matnum
endfunction


Posted: 4th Sep 2003 3:34
Awesome.
Posted: 4th Sep 2003 7:07
tried to add machine gunfire last night but havent solved a few things. Going to have to wait to see if the Darthster has as a possible solution.
Posted: 4th Sep 2003 11:21
very cool, could you make it so that if you crash the plane into the ground,the plane explodes and all the bits fall off.
Posted: 4th Sep 2003 12:13
I tell you, Indi is bored! Isn't there some kind of Dwarven game thing you should be coding?
Posted: 4th Sep 2003 12:25
if you only knew bro. It may appear im doing random things away from DT but I can asure you im not. I wont let the cat out of the bag just yet tho.
Posted: 4th Sep 2003 23:26
oooh will we be able to fly planes???? that'll be cool!!!
Posted: 12th Sep 2003 5:18
Is there a way to have flight sim controls with just the camera?

when i tried it the controls didnt work right

+ Code Snippet
Rem Project: Flight Sim
Rem Created: 9/11/2003 5:59:47 PM

Rem ***** Main Source File *****

autocam off : hide mouse : sync on : sync rate 60 : backdrop on
make matrix 1,20000,20000,50,50
randomize matrix 1,20
position camera 500,200,500

do
`controls
if leftkey()=1 then roll camera left 1
if rightkey()=1 then roll camera right 1
if upkey()=1 then pitch camera down 1
if downkey()=1 then pitch camera up 1
if inkey$()="," then turn camera left 1
if inkey$()="." then turn camera right 1
sync
loop



even though i use the camera pitch and roll commands, it only seems to be rotating the camera along the x , y , z axis... not "free motion"
Posted: 13th Sep 2003 0:56
Your code works for me. Your definition of 'free motion' is obviously not what you think it means! In DBPro terms, it means rotate camera round its own axis, ignoring the world axis.
Posted: 13th Sep 2003 5:14
Yes... i know what it means!
Thats exactly what Indi used, execpt in place of "camera" was "object", and Indi's "free motion" plane works fine. But when I use camera, it ONLY moves around the xyz axis releative to the WORLD not the camera. When i run it, initialy it works fine (because all the axis are oriented right) but when I roll upside down, its very apparent that it only rotates around the axis. in a true free motion i should be able to roll the camera, then pitch up and be able to turn around in a circle. Unfortunatly this does not work for me.


Just to be sure our definition of "free motion" is the same, I want the camera to control like a flight sim.
Posted: 13th Sep 2003 5:17
Nope, i just tried it again

dosent work right...

is this a bug?? cause i wonder why it works on your computer...
Posted: 13th Sep 2003 14:38
"Roll camera, pitch up and turn in circle"

But that works perfectly in your code.

1. You roll camera left by 90 degrees.

2. Keep finger on pitch up key (down arrow). and you spin on cameras exis in a circle.

If you mean you want camera to 'move' in a circle, you need to move camera forward as you pitch. Need to introduce some 'speed' into the equation.
Posted: 13th Sep 2003 22:07
nope,
I still won't work...
I have tried making the camera move forward, but it still dosent work right.

Heres my exact code
+ Code Snippet
Rem Project: Flight Sim
Rem Created: 9/11/2003 5:59:47 PM

Rem ***** Main Source File *****

autocam off : hide mouse : sync on : sync rate 60 : backdrop on
make matrix 1,20000,20000,50,50
randomize matrix 1,20
position camera 500,200,500

do
`controls
move camera 4

if leftkey()=1 then roll camera left 1
if rightkey()=1 then roll camera right 1
if upkey()=1 then pitch camera down 1
if downkey()=1 then pitch camera up 1
if inkey$()="," then turn camera left 1
if inkey$()="." then turn camera right 1
sync
loop


I have no clue why it will work on your computer and not mine. What version of DBpro do you have? Im going to try updating mine to see if that fixes anything.
Posted: 13th Sep 2003 22:11
Ha,

That was the problem. I needed to update. Everything works fine now.
Posted: 14th Sep 2003 8:25
next time make a seperate post thanks.
code snippets isnt the place to have a discussion.
Posted: 14th Sep 2003 22:24
Very nice Indi. I found myself messing around with it for quite a while.

Posted: 15th Sep 2003 6:44
enjoy