well, i prepared these functions for those who have problems with newton..
dont forget to put newton.dll in the project folder.
you just have to copy paste the functions and newton subs in your project.
Rem ***** Main Source File *****
GOSUB typesSetGlobalAndDefault
REM SET MAXIMUM DIMS
`GLOBAL DIM Files(1000, 2) As entityProperties
`GLOBAL DIM Sounds(50) As entityProperties
`GLOBAL DIM Musics(50) As entityProperties
`GLOBAL DIM Sprites(1000) As entityProperties
`GLOBAL DIM Images(1000) As entityProperties
`GLOBAL DIM Animations(10) As entityProperties
`GLOBAL DIM Lights(7) As entityProperties
`GLOBAL DIM Cameras(7) As entityProperties
GLOBAL DIM Objects(100,2) As entityProperties
`GLOBAL DIM Matrix(8) As entityProperties
`GLOBAL DIM Particles(10, 200) As entityProperties
`GLOBAL DIM Timers(10) As entityProperties
`GLOBAL DIM menuChecklist(10, 500) As checklist
`GLOBAL DIM Skies(2) As entityProperties
GLOBAL DIM Doors(100,2) As entityProperties
REM SET CAMERA VIEW
AUTOCAM OFF : BACKDROP ON
SET CAMERA RANGE 0, 0.1, 100000
SET CAMERA FOV 0, 62
`HIDE MOUSE
SET IMAGE COLORKEY 0, 0, 0
RANDOMIZE TIMER()
SYNC RATE 60 : SYNC ON
SET CURSOR 0, 0
POSITION CAMERA 0, 5, -100
GOSUB newtonPrepare
REM PREPARE YOUR GAME LEVEL HERE
ground = freeObject()
make object plain ground, 1000, 1000
xrotate object ground, 90
ground = nCollisionBox(ground, 0, 0, 0, nMatDefault)
makeDoorRotate(1, 10, 40, 10, 2, 40, 20, 0) `makes a rotating door
makeDoorRotate(2, -50, 40, 0, 2, 40, 20, 90) `makes a rotating door
makeDoorSlide(3, -151, 40, 10, 2, 40, 20, 90) `makes a sliding door
makeDoorSlide(4, -149, 40, 10, 2, 40, 20, -90) `makes a sliding door
makeLift(5, 0.0, 2, -40, 20, 2, 20, 0) `makes a lift
REM START GAME LOOP
mmx = mousemovex() : mmy = mousemovey()
GOSUB newtonTimerSet
DO
GOSUB newtonTimerLoop
timer1 = timer()
`TODO LOOP HERE
REM BASIC CAMERA MOTION
mmx = mousemovex() : mmy = mousemovey()
ax# = wrapvalue(ax# + mmy)
ay# = wrapvalue(ay# + mmx)
rotate camera ax#, ay#, 0.0
`position camera cx#, get ground height(mnum, cx#, cz#)+10, cz#
if mouseclick()=1 then move camera 10
if mouseclick()=2 then move camera -10
REM CONTROL NEWTON OBJECTS
`-----------MAKE BUTTON (Z)------------
if keystate(44) > 0 and BUTTON_Z = 0 then BUTTON_Z = 1
if BUTTON_Z = 1
BUTTON_Z = 2
REM START VALUES HERE
inc STATEMENT_Z, 1
if STATEMENT_Z > 1 then STATEMENT_Z = 0
endif
if keystate(44) = 0 then BUTTON_Z = 0
if STATEMENT_Z = 0
for f = 1 to 2
if NDB_BodyActive(Doors(f,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(f,1).num
NDB_SetHingeMotorAccel Doors(f,2).num, -1
next f
for f = 3 to 4
if NDB_BodyActive(Doors(f,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(f,1).num
NDB_SetSliderMotorAccel Doors(f,2).num, -5
next f
if NDB_BodyActive(Doors(5,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(5,1).num
NDB_SetSliderMotorAccel Doors(5,2).num, -10
endif
if STATEMENT_Z = 1
for f = 1 to 2
if NDB_BodyActive(Doors(f,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(f,1).num
NDB_SetHingeMotorAccel Doors(f,2).num, 1
next f
for f = 3 to 4
if NDB_BodyActive(Doors(f,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(f,1).num
NDB_SetSliderMotorAccel Doors(f,2).num, 5
next f
if NDB_BodyActive(Doors(5,1).num) = 0 then NDB_NewtonWorldUnfreezeBody Doors(5,1).num
NDB_SetSliderMotorAccel Doors(5,2).num, 10
endif
SET CURSOR 0, 0
PRINT "USE MOUSE TO MOVE AROUnD"
PRINT "PRESS Z KEY to ACTIVATE NEWTON OBJECTS"
PRINT "PRESS F12 KEY TO DEBUG NEWTON OBJECTS"
GOSUB newtonDebug
timer2 = timer()
timerR = timer2 - timer1
LOOP
GOSUB newtonDestroy
typesSetGlobalAndDefault:
REM LEVEL SPECIFIC VARIABLES
GLOBAL gGravity As Float
GLOBAL gBuoyX As Float
GLOBAL gBuoyY As Float
GLOBAL gBuoyZ As Float
GLOBAL gWorldSizeX As Float
GLOBAL gWorldSizeY As Float
GLOBAL gWorldSizeZ As Float
gGravity = -98.0
gBuoyX = 0.0
gBuoyY = 0.0
gBuoyZ = 0.0
gWorldSizeX = 5000.0
gWorldSizeY = 5000.0
gWorldSizeZ = 5000.0
Type entityProperties
num As Integer `sprite - object - light
exist As Integer `sprite - object - light
typeL As Integer `light
range As Integer `light
dirX As Integer `light
dirY As Integer `light
dirZ As Integer `light
visible As Integer `sprite - object - light
posX As Float `sprite - object
posY As Float `sprite - object
posZ As Float `sprite - object
vecX As Float `sprite - object - particles
vecY As Float `sprite - object - particles
vecZ As Float `sprite - object - particles
offX As Integer `sprite
offY As Integer `sprite
scaleX As Integer `sprite
scaleY As Integer `sprite
size As Float `object
sizeX As Float `object
sizeY As Float `object
sizeZ As Float `object
width As Integer `sprite
height As Integer `sprite
image As Integer `sprite
mirrored As Integer `sprite
flipped As Integer `sprite
hit As Integer `sprite - object
col As Integer `sprite - object
colX As Float `object
colY As Float `object
colZ As Float `object
ang As Float `sprite
angX As Float `object
angY As Float `object
angZ As Float `object
frame As Integer `sprite - object
speed As Integer `object
alpha As Integer `sprite
red As Integer `sprite
green As Integer `sprite
blue As Integer `sprite
interpolation As Integer `object
totalFrames As Integer `object
inScreen As Integer `object
screenX As Integer `object
screenY As Integer `object
fade As Integer `particles
EndType
RETURN
REM NEWTON SUBS
newtonPrepare:
`---------------------------------------------------------
REM Default VARIABLES
`---------------------------------------------------------
Rem set some default variables if not set in program
if scrFps = 0 then scrFps = 60
if gGravity = 0 then gGravity = -98.0
if nWorldSizeX# = 0.0 then nWorldSizeX# = 5000.0
if nWorldSizeY# = 0.0 then nWorldSizeY# = 5000.0
if nWorldSizeZ# = 0.0 then nWorldSizeZ# = 5000.0
nFps = scrFps
nGravity# = gGravity
nFluidDensity# = 0.9
nFluidLinearVisc# = 0.5
nFluidAngularVisc# = 0.5
GLOBAL nBuoyX# = gBuoyX
GLOBAL nBuoyY# = gBuoyY
GLOBAL nBuoyZ# = gBuoyZ
nWorldSizeX# = gWorldSizeX
nWorldSizeY# = gWorldSizeY
nWorldSizeZ# = gWorldSizeZ
GLOBAL nBody
GLOBAL nJoint
`---------------------------------------------------------
REM CREATE NEWTON AND SET GRAVITY, BUOYANCY AND FRAME RATE
`---------------------------------------------------------
NDB_NewtonCreate
NDB_SetVector 0.0, nGravity#, 0.0
NDB_SetStandardGravity
NDB_GetStandardGravity
NDB_SetStandardLiquid nFluidDensity#, nFluidLinearVisc#, nFluidAngularVisc#
NDB_NewtonSetMinimumFrameRate nFps
`---------------------------------------------------------
REM SET NEWTON WORLD
`---------------------------------------------------------
NDB_SetVector 1, -nWorldSizeX#, -nWorldSizeY#, -nWorldSizeZ#
NDB_SetVector 2, nWorldSizeX#, nWorldSizeY#, nWorldSizeZ#
NDB_NewtonSetWorldSize
NDB_NewtonSetBodyLeaveWorldEvent 1
`---------------------------------------------------------
REM SET NEWTON MATERIALS
`---------------------------------------------------------
Rem HERE WE CREATE SEVERAL DIFFERENT MATERIAL GROUPS
nMatDefault = NDB_NewtonMaterialGetDefaultGroupID()
GLOBAL nMatPlayer = NDB_NewtonMaterialCreateGroupID()
GLOBAL nMatWater = NDB_NewtonMaterialCreateGroupID()
GLOBAL nMatWood = NDB_NewtonMaterialCreateGroupID()
GLOBAL nMatMetal = NDB_NewtonMaterialCreateGroupID()
REM AND HERE WE SET UP THESE MATERIALS AND THE RELATIONS BETWEEN THEM
REM HERE I JUST LET NEWTON KNOW THAT IT SHOULD KEEP TRACK OF nMatPlayer to other materials
`what happens when nMatPlayer has collision with nMatDefault
NDB_NewtonMaterialSetDefaultFriction nMatPlayer, nMatDefault, 0.7, 0.5
NDB_NewtonMaterialSetDefaultElasticity nMatPlayer, nMatDefault, 0.5
`what happens when nMatPlayer has collision with nMatWater
NDB_NewtonMaterialSetDefaultFriction nMatPlayer, nMatWater, 0.7, 0.5
NDB_NewtonMaterialSetDefaultElasticity nMatPlayer, nMatWater, 0.5
`what happens when nMatPlayer has collision with nMatWood
NDB_NewtonMaterialSetDefaultFriction nMatPlayer, nMatWood, 0.7, 0.5
NDB_NewtonMaterialSetDefaultElasticity nMatPlayer, nMatWood, 0.5
`what happens when nMatPlayer has collision with nMatMetal
NDB_NewtonMaterialSetDefaultFriction nMatPlayer, nMatMetal, 0.7, 0.5
NDB_NewtonMaterialSetDefaultElasticity nMatPlayer, nMatMetal, 0.5
`---------------------------------------------------------
REM FINISH NEWTON CREATION
`---------------------------------------------------------
RETURN
newtonTimerSet:
`---------------------------------------------------------
REM GET TIMERS
`---------------------------------------------------------
GLOBAL nTime# = NDB_GetElapsedTimeInSec()
GLOBAL nTime# = NDB_GetElapsedTimeInSec()
RETURN
newtonTimerLoop:
`---------------------------------------------------------
REM START LOOP
`---------------------------------------------------------
nTime# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate nTime#
RETURN
newtonDebug:
`---------------------------------------------------------
REM DEBUG NEWTON - F12 KEY
`---------------------------------------------------------
if scancode() = 88 and N_DEBUG_ON = 0 then N_DEBUG_ON = 1
if N_DEBUG_ON = 1
N_DEBUG_ON = 2
inc N_Debug, 1
if N_Debug > 1 then N_Debug = 0
endif
if keystate(88) = 0 then N_DEBUG_ON = 0
if N_Debug = 1
obj = NDB_DebugMakeNewtonObject()
SET OBJECT LIGHT obj, 0
else
obj = 0
endif
`---------------------------------------------------------
REM SYNC SCREEN
`---------------------------------------------------------
sync
if obj <> 0
DELETE OBJECT obj
endif
`---------------------------------------------------------
REM FINISH NEWTON DEBUGGING
`---------------------------------------------------------
RETURN
newtonDestroy:
`---------------------------------------------------------
REM DESTROY NEWTON AND END THE PROGRAM
`---------------------------------------------------------
NDB_NewtonDestroy
END
`---------------------------------------------------------
REM BYE BYE
`---------------------------------------------------------
RETURN
REM NEWTON FUNCTIONS
`---------------------------------------------------------
Function nCollisionBox(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateBox(sx#, sy#, sz#) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMIBoxSolid Mass, sx#, sy#, sz#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionSphere(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj) / 2.0
sy# = object size y(obj) / 2.0
sz# = object size z(obj) / 2.0
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateSphere(sx#, sy#, sz#) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMISphereSolid Mass, rd#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionCylinder(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateCylinder(rd#, sy#) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMICylinderSolid Mass, rd#, sy#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionCapsule(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateCapsule(rd#, sy#) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMICylinderSolid Mass, rd#, sy#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionCone(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateCone(rd#, sy#) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMICylinderSolid Mass, rd#, sy#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionConvex(obj As Integer, Mass As Float, Gravity As Boolean, Buoyancy As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateConvexHull(obj) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_CalculateMIBoxSolid Mass, sx#, sy#, sz#
NDB_NewtonBodySetMassMatrix nBody, Mass
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_BodySetGravity nBody, Gravity
if Not Buoyancy = 0
NDB_BodySetBuoyancy nBody, Buoyancy
NDB_SetVector 1, nBuoyX#, nBuoyY#, nBuoyZ#, 0.0 `buoyancy plain is at y=10, you can change this value to your need.
NDB_BodySetBuoyancyPlane nBody
endif
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nCollisionTree(obj As Integer, Limbs As Boolean, nMaterial As Integer)
x# = object position x(obj)
y# = object position y(obj)
z# = object position z(obj)
sx# = object size x(obj)
sy# = object size y(obj)
sz# = object size z(obj)
rd# = object size (obj) / 2.0
rx# = object angle x(obj)
ry# = object angle y(obj)
rz# = object angle z(obj)
Col = NDB_NewtonCreateTreeCollision(obj, Limbs) `Col newton primitive
nBody = NDB_NewtonCreateBody(Col) `nBody is the collision data
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix nBody
NDB_NewtonReleaseCollision Col `we dont need newton primitive anymore
NDB_BodySetDBProData nBody, obj `we link the newton obj to visual obj
NDB_NewtonBodySetDestructorCallback nBody `if newton obj leaves the world borders, it destroys itself and the linked visual object as well
NDB_NewtonBodySetMaterialGroupID nBody, nMaterial
EndFunction nBody
`---------------------------------------------------------
Function nBallJoint(nBody1 As Integer, nBody2 As Integer, direction As String, coneLmt As Float, twistLmt As Float, collision As Boolean)
x# = Object Position X( NDB_GetDBPro(nBody2) )
y# = Object Position Y( NDB_GetDBPro(nBody2) )
z# = Object Position Z( NDB_GetDBPro(nBody2) )
sx# = Object Size X( NDB_GetDBPro(nBody2) ) / 2.0
sy# = Object Size Y( NDB_GetDBPro(nBody2) ) / 2.0
sz# = Object Size Z( NDB_GetDBPro(nBody2) ) / 2.0
ax# = Object Angle X( NDB_GetDBPro(nBody2) )
ay# = Object Angle Y( NDB_GetDBPro(nBody2) )
az# = Object Angle Z( NDB_GetDBPro(nBody2) )
if direction = "UP"
NDB_SetVector 1, x#, y#+sy#, z#
NDB_SetVector 2, 0.0, 1.0, 0.0
endif
if direction = "DOWN"
NDB_SetVector 1, x#, y#-sy#, z#
NDB_SetVector 2, 0.0, -1.0, 0.0
endif
if direction = "LEFT"
NDB_SetVector 1, x#-sx#, y#, z#
NDB_SetVector 2, -1.0, 0.0, 0.0
endif
if direction = "RIGHT"
NDB_SetVector 1, x#+sx#, y#, z#
NDB_SetVector 2, 1.0, 0.0, 0.0
endif
if direction = "FRONT"
NDB_SetVector 1, x#, y#, z#+sz#
NDB_SetVector 2, 0.0, 0.0, 1.0
endif
if direction = "BACK"
NDB_SetVector 1, x#, y#, z#-sz#
NDB_SetVector 2, 0.0, 0.0, -1.0
endif
if direction = "CENTER"
NDB_SetVector 1, x#, y#, z#
NDB_SetVector 2, 0.0, 0.0, 0.0
endif
nJoint = NDB_NewtonConstraintCreateBall( nBody1, nBody2 )
if coneLmt <> 0.0 or twistLmt <> 0.0
NDB_NewtonBallSetConeLimits nJoint, coneLmt, twistLmt
endif
NDB_NewtonJointSetCollisionState nJoint, collision
NDB_BuildMatrix ax#, ay#, az#, x#, y#, z#
NDB_NewtonBodySetMatrixRecursive nBody2
EndFunction nJoint
`---------------------------------------------------------
Function nHingeJoint(nBody1 As Integer, nBody2 As Integer, direction As String, limitMin As Float, limitMax As Float, collision As Boolean)
x# = Object Position X( NDB_GetDBPro(nBody2) )
y# = Object Position Y( NDB_GetDBPro(nBody2) )
z# = Object Position Z( NDB_GetDBPro(nBody2) )
sx# = Object Size X( NDB_GetDBPro(nBody2) ) / 2.0
sy# = Object Size Y( NDB_GetDBPro(nBody2) ) / 2.0
sz# = Object Size Z( NDB_GetDBPro(nBody2) ) / 2.0
ax# = Object Angle X( NDB_GetDBPro(nBody2) )
ay# = Object Angle Y( NDB_GetDBPro(nBody2) )
az# = Object Angle Z( NDB_GetDBPro(nBody2) )
if direction = "UP"
NDB_SetVector 1, x#, y#+sy#, z#
NDB_SetVector 2, 0.0, 1.0, 0.0
endif
if direction = "DOWN"
NDB_SetVector 1, x#, y#-sy#, z#
NDB_SetVector 2, 0.0, -1.0, 0.0
endif
if direction = "LEFT"
NDB_SetVector 1, x#-sx#, y#, z#
NDB_SetVector 2, -1.0, 0.0, 0.0
endif
if direction = "RIGHT"
NDB_SetVector 1, x#+sx#, y#, z#
NDB_SetVector 2, 1.0, 0.0, 0.0
endif
if direction = "FRONT"
NDB_SetVector 1, x#, y#, z#+sz#
NDB_SetVector 2, 0.0, 0.0, 1.0
endif
if direction = "BACK"
NDB_SetVector 1, x#, y#, z#-sz#
NDB_SetVector 2, 0.0, 0.0, -1.0
endif
if direction = "CENTER"
NDB_SetVector 1, x#, y#, z#
NDB_SetVector 2, 0.0, 0.0, 0.0
endif
nJoint = NDB_NewtonConstraintCreateHinge( nBody1, nBody2 )
if limitMin <> 0.0 or limitMax <> 0.0
NDB_SetHingeLimits nJoint, limitMin, limitMax
endif
NDB_NewtonJointSetCollisionState nJoint, collision
NDB_BuildMatrix ax#, ay#, az#, x#, y#, z#
NDB_NewtonBodySetMatrixRecursive nBody2
EndFunction nJoint
`---------------------------------------------------------
Function nSliderJoint(nBody1 As Integer, nBody2 As Integer, direction As String, limitMin As Float, limitMax As Float, collision As Boolean)
x# = Object Position X( NDB_GetDBPro(nBody2) )
y# = Object Position Y( NDB_GetDBPro(nBody2) )
z# = Object Position Z( NDB_GetDBPro(nBody2) )
sx# = Object Size X( NDB_GetDBPro(nBody2) ) / 2.0
sy# = Object Size Y( NDB_GetDBPro(nBody2) ) / 2.0
sz# = Object Size Z( NDB_GetDBPro(nBody2) ) / 2.0
ax# = Object Angle X( NDB_GetDBPro(nBody2) )
ay# = Object Angle Y( NDB_GetDBPro(nBody2) )
az# = Object Angle Z( NDB_GetDBPro(nBody2) )
if direction = "UP"
NDB_SetVector 1, x#, y#+sy#, z#
NDB_SetVector 2, 0.0, 1.0, 0.0
endif
if direction = "DOWN"
NDB_SetVector 1, x#, y#-sy#, z#
NDB_SetVector 2, 0.0, -1.0, 0.0
endif
if direction = "LEFT"
NDB_SetVector 1, x#-sx#, y#, z#
NDB_SetVector 2, -1.0, 0.0, 0.0
endif
if direction = "RIGHT"
NDB_SetVector 1, x#+sx#, y#, z#
NDB_SetVector 2, 1.0, 0.0, 0.0
endif
if direction = "FRONT"
NDB_SetVector 1, x#, y#, z#+sz#
NDB_SetVector 2, 0.0, 0.0, 1.0
endif
if direction = "BACK"
NDB_SetVector 1, x#, y#, z#-sz#
NDB_SetVector 2, 0.0, 0.0, -1.0
endif
if direction = "CENTER"
NDB_SetVector 1, x#, y#, z#
NDB_SetVector 2, 0.0, 0.0, 0.0
endif
nJoint = NDB_NewtonConstraintCreateSlider( nBody1, nBody2 )
if limitMin <> 0.0 or limitMax <> 0.0
NDB_SetSliderLimits nJoint, limitMin, limitMax
endif
NDB_NewtonJointSetCollisionState nJoint, collision
NDB_BuildMatrix ax#, ay#, az#, x#, y#, z#
NDB_NewtonBodySetMatrixRecursive nBody2
EndFunction nJoint
`---------------------------------------------------------
Function nCorkscrewJoint(nBody1 As Integer, nBody2 As Integer, direction As String, angleMin As Float, angleMax As Float, distMin As Float, distMax As Float, collision As Boolean)
x# = Object Position X( NDB_GetDBPro(nBody2) )
y# = Object Position Y( NDB_GetDBPro(nBody2) )
z# = Object Position Z( NDB_GetDBPro(nBody2) )
sx# = Object Size X( NDB_GetDBPro(nBody2) ) / 2.0
sy# = Object Size Y( NDB_GetDBPro(nBody2) ) / 2.0
sz# = Object Size Z( NDB_GetDBPro(nBody2) ) / 2.0
ax# = Object Angle X( NDB_GetDBPro(nBody2) )
ay# = Object Angle Y( NDB_GetDBPro(nBody2) )
az# = Object Angle Z( NDB_GetDBPro(nBody2) )
if direction = "UP"
NDB_SetVector 1, x#, y#+sy#, z#
NDB_SetVector 2, 0.0, 1.0, 0.0
endif
if direction = "DOWN"
NDB_SetVector 1, x#, y#-sy#, z#
NDB_SetVector 2, 0.0, -1.0, 0.0
endif
if direction = "LEFT"
NDB_SetVector 1, x#-sx#, y#, z#
NDB_SetVector 2, -1.0, 0.0, 0.0
endif
if direction = "RIGHT"
NDB_SetVector 1, x#+sx#, y#, z#
NDB_SetVector 2, 1.0, 0.0, 0.0
endif
if direction = "FRONT"
NDB_SetVector 1, x#, y#, z#+sz#
NDB_SetVector 2, 0.0, 0.0, 1.0
endif
if direction = "BACK"
NDB_SetVector 1, x#, y#, z#-sz#
NDB_SetVector 2, 0.0, 0.0, -1.0
endif
if direction = "CENTER"
NDB_SetVector 1, x#, y#, z#
NDB_SetVector 2, 0.0, 0.0, 0.0
endif
nJoint = NDB_NewtonConstraintCreateCorkscrew( nBody1, nBody2 )
if angleMin <> 0.0 or angleMax <> 0.0 or distMin <> 0.0 or distMax <> 0.0
NDB_SetCorkscrewLimits nJoint, angleMin, angleMax, distMin, distMax
endif
NDB_NewtonJointSetCollisionState nJoint, collision
NDB_BuildMatrix ax#, ay#, az#, x#, y#, z#
NDB_NewtonBodySetMatrixRecursive nBody2
EndFunction nJoint
`---------------------------------------------------------
Function nUniversalJoint(nBody1 As Integer, nBody2 As Integer)
x# = Object Position X( NDB_GetDBPro(nBody2) )
y# = Object Position Y( NDB_GetDBPro(nBody2) )
z# = Object Position Z( NDB_GetDBPro(nBody2) )
sx# = Object Size X( NDB_GetDBPro(nBody2) ) / 2.0
sy# = Object Size Y( NDB_GetDBPro(nBody2) ) / 2.0
sz# = Object Size Z( NDB_GetDBPro(nBody2) ) / 2.0
ax# = Object Angle X( NDB_GetDBPro(nBody2) )
ay# = Object Angle Y( NDB_GetDBPro(nBody2) )
az# = Object Angle Z( NDB_GetDBPro(nBody2) )
NDB_SetVector 1, x#, y#-sy#, z#
NDB_SetVector 2, 0.0, -1.0, 0.0
NDB_SetVector 3, 0.0, 1.0, 0.0
nJoint = NDB_NewtonConstraintCreateUniversal( nBody1, nBody2 )
NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
NDB_NewtonBodySetMatrixRecursive nBody2
EndFunction nJoint
`---------------------------------------------------------
Function nUpvectorJoint(nBody1 As Integer)
NDB_SetVector 1, 0.0, 1.0, 0.0
nJoint = NDB_NewtonConstraintCreateUpVector( nBody1 )
EndFunction nJoint
`---------------------------------------------------------
`---------------------------------------------------------
Function NewtonNeverCalled()
if memblock exist(1) then end
if mesh exist (1) then end
EndFunction
`---------------------------------------------------------
REM GAME FUNCTIONS
`---------------------------------------------------------
Rem Function to find 3d distance
Function distanceObjects(obj1 As Integer, obj2 As Integer)
x1#=object position x(obj1)
y1#=object position y(obj1)
z1#=object position z(obj1)
x2#=object position x(obj2)
y2#=object position y(obj2)
z2#=object position z(obj2)
xd# = x1# - x2#
yd# = y1# - y2#
zd# = z1# - z2#
Distance# = ((xd#*xd#) + (yd#*yd#) + (zd#*zd#))^0.5
EndFunction Distance#
`---------------------------------------------------------
Function distancePositions(x1# As Float, y1# As Float, z1# As Float, x2# As Float, y2# As Float, z2# As Float)
xd# = x1# - x2#
yd# = y1# - y2#
zd# = z1# - z2#
Distance# = ((xd#*xd#) + (yd#*yd#) + (zd#*zd#))^0.5
EndFunction Distance#
`---------------------------------------------------------
Function randomColor()
repeat
r = rnd(1)*255
g = rnd(1)*255
b = rnd(1)*255
until r<>0 or g<>0 or b<> 0
color = rgb(r,g,b)
endfunction color
`---------------------------------------------------------
Function freeDll()
Repeat
Inc i
Until DLL Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeMemblock()
Repeat
Inc i
Until MemBlock Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeObject()
Repeat
Inc i
Until Object Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeSound()
Repeat
Inc i
Until Sound Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeMusic()
Repeat
Inc i
Until Music Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeAnimation()
Repeat
Inc i
Until Animation Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeBitmap()
Repeat
Inc i
Until Bitmap Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeEffect()
Repeat
Inc i
Until Effect Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeImage()
Repeat
Inc i
Until Image Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeLight()
Repeat
Inc i
Until Light Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeLimb()
Repeat
Inc i
Until Limb Exist(i,i) = 0
EndFunction i
`---------------------------------------------------------
Function freeMatrix()
Repeat
Inc i
Until Matrix Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeMesh()
Repeat
Inc i
Until Mesh Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freePixelshader()
Repeat
Inc i
Until Pixel Shader Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeParticles()
Repeat
Inc i
Until Particles Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeSprite()
Repeat
Inc i
Until Sprite Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeTerrain()
Repeat
Inc i
Until Terrain Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeVertexshader()
Repeat
Inc i
Until Vertex Shader Exist(i) = 0
EndFunction i
`---------------------------------------------------------
Function freeFile()
Repeat
Inc i
Until File Open(i) = 0
EndFunction i
`---------------------------------------------------------
REM LEVEL SPECIFIC FUNCTIONS
Function makeDoorRotate(n As Integer, px As Float, py As Float, pz As Float, depth As Float, height As Float, width As Float, yAng As Float)
door = freeObject()
Doors(n,0).num = door
Make Object Box door, depth, height, width
Position Object door, px, py-(height/2.0), pz
YRotate Object door, yAng
Move Object door, width/2.0
Doors(n,1).num = nCollisionBox(Doors(n,0).num, 10, 1, 0, nMatDefault)
`YRotate Object door, -yAng
Move Object door, -width/2.0
NDB_SetVector 1, px, py, pz
NDB_SetVector 2, 0.0, -1.0, 0.0
Doors(n,2).num = NDB_NewtonConstraintCreateHinge( Doors(n,1).num, 0 )
NDB_SetHingeLimits Doors(n,2).num, -135.0, 135.0
EndFunction
`---------------------------------------------------------
Function makeDoorSlide(n As Integer, px As Float, py As Float, pz As Float, depth As Float, height As Float, width As Float, yAng As Float)
door = freeObject()
Doors(n,0).num = door
Make Object Box door, depth, height, width
Position Object door, px, py-(height/2.0), pz
YRotate Object door, yAng
Move Object door, width/2.0
Doors(n,1).num = nCollisionBox(Doors(n,0).num, 10, 1, 0, nMatDefault)
`YRotate Object door, -yAng
Move Object door, -width/2.0
NDB_SetVector 1, px, py, pz
NDB_SetVector 2, sin(yAng), 0.0, -cos(yAng)
Doors(n,2).num = NDB_NewtonConstraintCreateSlider( Doors(n,1).num, 0 )
NDB_SetSliderLimits Doors(n,2).num, 0.01, width
EndFunction
`---------------------------------------------------------
Function makeLift(n As Integer, px As Float, py As Float, pz As Float, depth As Float, height As Float, width As Float, yAng As Float)
lift = freeObject()
Doors(n,0).num = lift
Make Object Box lift, depth, height, width
Position Object lift, px, py-(height/2.0), pz
YRotate Object lift, yAng
Doors(n,1).num = nCollisionBox(Doors(n,0).num, 10, 0, 0, nMatDefault)
NDB_SetVector 1, px, py, pz
NDB_SetVector 2, 0.0, 1.0, 0.0
Doors(n,2).num = NDB_NewtonConstraintCreateSlider( Doors(n,1).num, 0 )
NDB_SetSliderLimits Doors(n,2).num, py, py+50
EndFunction
`---------------------------------------------------------