|
Post by Kjelle69 on Jul 14, 2004 5:23:20 GMT 1
this has been posted before on The GameCreators forum, but here it is for completeness. source code included, should compile with version 1.23 of the wrapper: EXE + SOURCE DOWNLOAD HERE - 1.2MB RAR file
|
|
Wings
Newton User
Posts: 46
|
Post by Wings on Sept 15, 2004 10:58:08 GMT 1
but the source isn't! and I want it but I seem to have downloaded the code for the version before (one without the huge walker in the middle) off the newton thread at the darkbasic site
source here
remstart -------------------------------------------------- NEWTON PHYSICS SDK WRAPPER v1.23 WALKING MACHINE -------------------------------------------------- remend sync on sync rate 60 autocam off
`Three D Point in space, used for positions, velocities, etc TYPE ThreeD x as float y as float z as float ENDTYPE
` Basic Camera setup, Position and Point-Position (what we're looking at) TYPE Cam Pos as ThreeD Pnt as ThreeD Rot as ThreeD ENDTYPE
Cam as cam Cam_YAngle# = 0.0 Cam_XAngle# = 35.0 Cam.Pos.x = 0.0 Cam.Pos.y = 3.0 Cam.Pos.z = -3.0 position camera Cam.Pos.x, Cam.Pos.y, Cam.Pos.z Cam_Speed# = 0.5 set camera range 0.2,1000000
TOP:
rem INITIALIZE PHYSICS WORLD!
rem Initialize the Physics world. this must be called before any other commands. NDB_NewtonCreate
NDB_SetVector 0.0, -9.8, 0.0, 1.0 NDB_SetStandardGravity
col = NDB_NewtonCreateBox(25.0, 2.0, 25.0) Floor = NDB_NewtonCreateBody(col)
ObjNum = FindFreeObject() make object box ObjNum, 25.0, 2.0, 25.0 load image "floor1.bmp", ObjNum texture object ObjNum, ObjNum position object ObjNum, 0.0,-1.0, 0.0
NDB_SetMatrixIdentityMatrix NDB_SetVector 0.0, -1.0, 0.0 NDB_SetMatrixPosRow NDB_NewtonBodySetMAtrix Floor
NDB_BodySetDBProData Floor, ObjNum NDB_NewtonBodySetDestructorCallback Floor
NDB_NewtonReleaseCollision col
dim TheHinges(1024) global hcount
for i=1 to 10 s# = (rnd(1)+2)*0.5 MakeBug(s#, rnd(10)-5, 0.0, rnd(10)-5, s#*1.0) next i
dec hcount,1
rem ----------------------------------- rem MAIN LOOP rem ----------------------------------- do
time# = NDB_GetElapsedTimeInSec()
rem Here's the big command that updates the Physics system. Objects are moved and positioned automatically. NDB_NewtonUpdate time#
text 10,10,"-------------------------------------------------------------" text 10,20,"Newton Game Dynamics SDK DBPro Wrapper v"+str$(NDB_GetVersion()) text 10,40,"WALKING MACHINE!!" text 10,60,"Mouse to look | Arrows to move | Space to (un)pause" text 10,70,"Press "r" to reset | press "q" to quit" text 10,80,"FPS "+str$(screen fps()) text 10,90,"Polycount "+str$(statistic(1)) text 10,100,"-------------------------------------------------------------"
if inkey$() = "q" then exit
if inkey$() = "r" NDB_NewtonDestroy goto TOP endif
for i=1 to hcount omega# = NDB_NewtonHingeGetJointOmega(TheHinges(i))
NDB_SetHingeMotorAccel TheHinges(i), (4.0 - omega#)*10.0 next i
`------------------------- `CAMERA `------------------------- Mmx = mousemovex() Mmy = mousemovey() Mx = Mx + Mmx My = My + Mmy Cam_YAngle# = oldy# + (Mx - basex) Cam_XAngle# = oldx# + (My - basey)
if upkey() then move camera Cam_Speed# if downkey() then move camera Cam_Speed# * (-1.0) if leftkey() rotate camera 0.0,Cam_YAngle#-90.0,0.0 move camera Cam_Speed# endif if rightkey() rotate camera 0.0,Cam_YAngle#+90.0,0.0 move camera Cam_Speed# endif rotate camera Cam_XAngle#,Cam_YAngle#,0.0
sync loop
rem Destory the Physics world and all bodies in it. NDB_NewtonDestroy
end
function MakeBug(s#, px#, py#, pz#, m#)
sx# = s# sy# = 6.0*s# / 20.0 sz# = 8.0*s# / 20.0
px# = px# py# = py# + (1.5*sy#) + (sy#/12.0) pz# = pz#
` FIRST MAKE THE MAIN BODY (A BOX) Body = PrimBox(sx#, sy#, sz#, px#, py#, pz#, 0.0, 0.0, 0.0, 4*m#/10.0, rgb(150,23,186))
for i=-1 to 1 step 2 for j=-1 to 1 step 2
`MAKE THE COG tx# = px# + ((sx#*0.3) * i) ty# = py# + ((sy#*2.0/6.0)) tz# = pz# + ((sz#/2.0) + (sz#/16.0)) * j tsx# = 3.0*sx#/20.0 tsy# = 3.0*sy#/6.0 tsz# = sz#/8.0
CAM = PrimBox(tsx#, tsy#, tsz#, tx#, ty#, tz#, 0.0, 0.0, 45.0, m#*0.24*0.5, rgb(168,119,222)) `ATTACH WITH A HINGE NDB_SetVector 1, tx#, ty#, tz# NDB_SetVector 2, 0.0, 0.0, 1.0 Hinge = NDB_NewtonConstraintCreateHinge(CAM, Body) NDB_NewtonHingeSetUserCallback Hinge, 2 TheHinges(hcount) = Hinge inc hcount
`MAKE THE GUIDE tx# = px# + ((sx#*0.3) * i) ty# = py# - (2.5 * sy# / 6.0) tz# = pz# + ((sz#/2.0) + (3.0*sz#/16.0)) * j tsx# = sx#/10.0 tsy# = sy#/6.0 tsz# = 3.0*sx#/16.0
GUIDE = PrimBox(tsx#, tsy#, tsz#, tx#, ty#, tz#, 0.0, 0.0, 0.0, m#*0.24*0.1, rgb(168,119,222)) `ATTACH WITH A HINGE NDB_SetVector 1, tx#, ty#, tz# NDB_SetVector 2, 0.0, 0.0, j Hinge = NDB_NewtonConstraintCreateHinge(GUIDE, Body)
`MAKE THE LEG tx# = px# + ((sx#*0.3) * i) ty# = py# - (sy#/2.0) - (sy#/6.0) if i=-1 and j=-1 then inc ty#, (2.0*sy#/6.0) if i=1 and j=1 then inc ty#, (2.0*sy#/6.0) tz# = pz# + ((sz#/2.0) + (3.0*sz#/16.0)) * j tsx# = sx#/20.0 tsy# = 10.0*sy#/6.0 tsz# = sz#/8.0
LEG = PrimBox(tsx#, tsy#, tsz#, tx#, ty#, tz#, 0.0, 0.0, 0.0, m#*0.24*0.3, rgb(231,237,70))
`ATTACH TO THE COG inc ty#, (5.0*sy#/6.0) NDB_SetVector 1, tx#, ty#, tz# NDB_SetVector 2, 0.0, 0.0, j Hinge = NDB_NewtonConstraintCreateHinge(LEG, CAM)
`ATTACH TO THE GUIDE ty# = py# - (2.5 * sy# / 6.0) NDB_SetVector 1, tx#, ty#, tz# NDB_SetVector 2, 0.0, -1.0, 0.0 Hinge = NDB_NewtonConstraintCreateSlider(LEG, GUIDE)
`MAKE THE FOOT tx# = px# + ((sx#*0.3) * i) ty# = py# - (9.0*sy#/6.0) - (sy#/12.0) if i=-1 and j=-1 then inc ty#, (2.0*sy#/6.0) if i=1 and j=1 then inc ty#, (2.0*sy#/6.0) tz# = pz# + ((sz#/2.0) + (3.0*sz#/16.0)) * j tsx# = 4.0*sx#/20.0 tsy# = sy#/6.0 tsz# = 4.0*sz#/8.0
FOOT = PrimBox(tsx#, tsy#, tsz#, tx#, ty#, tz#, 0.0, 0.0, 0.0, m#*0.24*0.2, rgb(246,161,40))
`ATTACH TO THE LEG inc ty#, sy# / 12.0 NDB_SetVector tx#, ty#, tz# Ball = NDB_NewtonConstraintCreateBall(FOOT, LEG)
NDB_SetVector 0.0, -1.0, 0.0 NDB_NewtonBallSetConeLimits Ball, 45.0, 10.0
next j next i
endfunction
function PrimBox(sx#, sy#, sz#, px#, py#, pz#, rx#, ry#, rz#, m#, color)
col = NDB_NewtonCreateBox(sx#,sy#,sz#) Body = NDB_NewtonCreateBody(col) NDB_SetVector rx#, ry#, rz# NDB_SetVectorToRadians NDB_NewtonSetEulerAngle NDB_SetVector px#, py#, pz# NDB_SetMatrixPosRow NDB_NewtonBodySetMatrix Body
NDB_CalculateMIBoxSolid m#, sx#, sy#, sz# NDB_NewtonBodySetMassMatrix Body, m#
NDB_NewtonBodySetTransformCallback Body NDB_NewtonBodySetForceAndTorqueCallback Body NDB_NewtonBodySetDestructorCallback Body
ObjNum = FindFreeObject() make object box ObjNum, sx#, sy#, sz# color object ObjNum, color position object ObjNum, tempx#, tempy#, tempz#
NDB_BodySetDBProData Body, ObjNum
endfunction Body
function FindFreeObject() for i=1 to 10000 if object exist(i) = 0 then exit next i endfunction i
|
|
|
Post by Kjelle69 on Sept 15, 2004 12:11:34 GMT 1
the source is in the download... [edit] or at least I thought it was. re-download, it's in there now!
|
|
Wings
Newton User
Posts: 46
|
Post by Wings on Sept 15, 2004 12:46:30 GMT 1
I've already nicked the bits I want (got two lovely bright pink wheels on my tank now!)
|
|