Hmm.. Can't seem to get it working with Newton:
Rem Project: GameKwadraat
Rem Created: Sunday, March 01, 2009
Rem ***** Main Source File *****
// Setup screen
Sync on
Sync rate 0
Autocam off
Set camera range 0.5, 50000
PrintW("")
// Setup variables/types
Type vec3
X as float
Y as float
Z as float
Endtype
Type Player
Position as vec3
Scale as vec3
Rotation as vec3
ObjectID as integer
Endtype
Player as Player
Type Map
Position as vec3
Scale as vec3
BaseTexture as integer
DetailTexture as integer
ObjectID as integer
AdvID as integer
HeightmapID as integer
Heightmap as string
Endtype
Map as Map
Global Debug as boolean = 1
ObjPlace as boolean = 0
Global objects
Map.Heightmap = "Data/Maps/maps.bmp"
Map.AdvID = 1
Map.Scale.X = 12
Map.Scale.Y = 2
Map.Scale.Z = 12
Dim Body(100)
PrintW("Loading imgs")
// Load images [advanced terrain]
Map.BaseTexture = Find Free Image()
Load image "Data/Textures/texture.jpg", Map.BaseTexture
Map.DetailTexture = Find Free Image()
Load image "Data/Textures/detail.tga", Map.DetailTexture
Map.HeightMapID = Find Free Image()
Load image Map.Heightmap, Map.HeightmapID
// Init Newton
NDB_NewtonCreate
// Set gravity
NDB_SetVector 0.0, -50.0, 0.0
NDB_SetStandardGravity
Gosub _SetupBT
PrintW("Done")
Wait 1000
position camera 1000,350,1000
Do
time# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate Time#
Point Camera 0,0,0
Gosub _GetUserInput
Sync
Loop
Function PrintW(String$)
If Debug = 1
Print String$
Sync
Endif
Endfunction
function MakeSphere(x#,y#,z#,s#,mass#)
Col = NDB_NewtonCreateSphere( s# )
Body = NDB_NewtonCreateBody(Col)
`Set initial position and rotation
NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
NDB_NewtonBodySetMatrix Body
`notice that I calculate the MI (moment of inertia) for a sphere shape this time.
NDB_CalculateMISphereSolid mass#, s#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "Data\Objects\sphere.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
position object obj, x#, y#, z#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function FreeObject()
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
function GetColor()
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 NeverCalled()
if memblock exist(1) then delete memblock 1
endfunction
_SetupBT:
PrintW("Setting up Advanced Terrain")
// Advanced terrain setup
`Make a Terrain
terrain=UT MakeTerrain()
`Set the heightmap image
UT SetTerrainHeightmap terrain, Map.HeightmapID
`Set the texture
UT SetTerrainTexture terrain, Map.BaseTexture
`Set the detailmap
UT SetTerrainDetail terrain, Map.DetailTexture
`Set how many LOD levels there are
UT SetTerrainLOD terrain, 4
`Set The Scale
UT SetTerrainScale terrain, 12
`Set the Y Scale
UT SetTerrainYScale terrain, 2
`Set the split (the terrain will be 8x8 so it will generate 64 sectors)
UT SetTerrainSplit terrain, 8
`Set the Tiling of the detailmap
UT SetTerrainDetailTile terrain,4
`Set The LOD Distances (as were only using 4 LOD levels, we only need to fill in the first 3)
UT SetTerrainLODDistances terrain,1000,3000,5500,0,0,0
`Start Building
UT BuildTerrain terrain
`Build
Building=1
while Building
`The visual object
object=find free Object()
`The Physics Object
phyobject=find Free Object()+1
`Generate a sector
progress=UT ContinueBuild(object,phyobject,0) `Generates a sector, phyobject can be ignored in normal physics mode
col = NDB_NewtonCreateTreeCollision( phyobject, 1 )
Body = NDB_NewtonCreateBody( col )
`Example showing that you can set it to any physics/collision system you want
if progress=-1
`Stop building
Building=0
else
`Print the progress
center text screen width()/2,screen height()/2,"Loading Terrain: "+str$(progress)+"%"
sync
endif
endwhile
return
_GetUserInput:
if mouseclick() = 1 and M_CLICK = 0
M_CLICK = 1
`left mouse button clicked, so let's create a tennis ball, and throw it!
`camera is always at (0,0,-100), we'll create it just below the camera.
NewBall = MakeSphere( camera position x(), camera position y(), camera position z(), 2.0, 10.0 )
`now we need to set an initial velocity for the body, as if we've thrown it.
`we want to throw in the direction we are looking, so we'll use the camera to get
`a simple vector in our look direction, and multiply that by the throw power.
x1# = camera position x() : y1# = camera position y() : z1# = camera position z()
move camera 1.0
x2# = camera position x() : y2# = camera position y() : z2# = camera position z()
move camera -1.0
unit_x# = x2# - x1#
unit_y# = y2# - y1#
unit_z# = z2# - z1#
`now, to get the initial velocity, we multiply by the throw power!
vel_x# = unit_x# * 100.0
vel_y# = unit_y# * 100.0
vel_z# = unit_z# * 100.0
NDB_SetVector vel_x#, vel_y#, vel_z#
NDB_NewtonBodySetVelocity NewBall
endif
if mouseclick()=0 then M_CLICK = 0
Return
Balls just go straight through, meaning the object is not made...
You're the
'th to view this signature!