Here's the code. Perhaps it's something else in this program.
[#Constant TYPE_NGC_ELLIP=1
#Constant TYPE_NGC_MESH=2
#Constant ELLIP_2_ELLIP=1
#Constant ELLIP_2_POLY=2
#Constant RESP_STICK=1
#Constant RESP_SLIDE=2
#Constant RESP_SLIDE_NO_SLOPES=6
#Constant RESP_SLIDE_NO_GRAV=10
#Constant RESP_SLIDE_NO_ACCEL=18
#Constant RESP_NONE=32
#Constant DYN_NO_RESP=1
#Constant DYN_RESP=2
#Constant DYN_RESP_LOCK=4
#Constant DYN_RESP_LOCK_NOTURN=12
#Constant NCULL_CLOCK 0
#Constant NCULL_COUNTER_CLOCK 1
#Constant NCULL_NONE 2
rem End globals
startBlue "???","??????"
`Global Variable Declarations for Gadgets
`----------------------------------------
global West1
global East1
global North1
global South1
global Panel1
global Input1
global Exit1
global InputText1
global OutputText1
INPUTSource1#=1.11
INPUTSource2#=1.11
`Menu Gloals
`-----------
rem
rem Startup settings
rem
rem sets our display mode
`Set Window On
SET DISPLAY MODE 800, 600, 16
rem sync on
sync on : sync rate 60 : Autocam off
`hide mouse
rem
rem Scene settings
rem
rem Starts the collision system, this MUST be called before you can call any other
rem collision commands
StartCollisionPRO(?????????,?????????,?????????)
rem This line puts the collision system in Debug mode. If there is an error
rem (like you try to set an object that doesn't exist) this will make a box
rem popup notifying you of the error. If you take this line out, the system
rem will do its best to silently stop any errors that occur. (without crashing
rem your program) It's recommended that you leave this line in while you're
rem developing the application, then take it out before you make the final release
StartCollisionDebugPRO()
rem These are constants to hold our "collision types". One type represents a "group"
rem of objects. (for instance: world objects, enemy objects, etc.)
rem The are Constant to make things clean, it is not required to use constants.
rem These can be anything, as long as their value is less than 300 and greater than 0.
#Constant TYPE_CAM = 10
#Constant TYPE_WORLD = 11
rem This line is VERY VERY important. It sets the collision between 2 different
rem collision types (defined above). You can call the function "SetCollisionsPRO" as many
rem times as you need. Not many should be needed for an entire game.
rem The below line says this:
rem Make (TYPE_CAM) collide against (TYPE_WORLD) using ellipsoid to poly collision,
rem set the response system to slide (RESP_SLIDE), and set no dynamic response (DYN_NO_RESP).
rem NOTE: At this point, the last 3 params MUST be set to the settings you see below
rem This is planned for expansion, that's the reason for it.
SetCollisionsPro( TYPE_CAM, TYPE_WORLD, ELLIP_2_POLY, RESP_SLIDE, DYN_NO_RESP )
rem *** Begin some world setup stuff
rem defines some global variables
global camera=0, cam_obj=1
global cam_speed# = 2.0 `Set this to the initial movement speed of the camera
global dim KeyHold(256) `global array to hold the "hold status" of each key pressed
global dim LastKeyHold(256) `global array to hold the "hold status" of each key pressed
rem turns on the backdrop
backdrop on
rem creates our camera and inits the properties
Set Camera Range 4, 15000
color backdrop camera, rgb(255,255,255)
make object sphere cam_obj, 2
position object cam_obj,15,20,95
rotate object cam_obj,0,-90,0
rem OKAY, collision system back at work here. This is the command you use to
rem stick objects with a "collision type ID" This ID would be you own defined
rem TYPE_ID from above. This line simply says:
rem Give the object (camera) the "collision type ID" of (TYPE_CAM)
rem (NOTE: This also gives the camera object an ellipsoid shape)
CollisionTypePRO( cam_obj, TYPE_CAM )
rem This sets the dimensions of the ellipsoid shape of our object.
rem The format is: object number, XSize, YSize, ZSize
SetObjRadiusPRO( cam_obj, 6, 7, 6 )
rem SetEllipMaxEdgePRO( cam_obj, 10 )
rem loads the level
level = 2
load object "C:ImportantStuffDBstuffTerrainmountain1.x",level
position object level,20,5,0
rem Okay, now we set the "collision type ID" for the world. Notice it's the same
rem exact command as above for our camera object. However, the system knows this
rem is a mesh and not an ellipsoid.
rem
rem How can that be when the last command was the same and made the object an ellip?
rem
rem Well, if you recall from our collision definition at the top. It says:
rem "Make (TYPE_CAM) collide against (TYPE_WORLD) using ellipsoid to poly collision"
rem So the system knows that all TYPE_CAM definitions are ellipsoids and all
rem TYPE_WORLD definitions are meshes.
rem
rem Therefore, below when we set the "level" object to (TYPE_WORLD) it recognizes
rem this object is a mesh, and reads the mesh into memory for you. Pretty neat eh?
CollisionTypePRO( level, TYPE_WORLD )
rem Scales the level object
rem REPLACEMENT FOR: scale object level, 1200, 1200, 1200
ScaleObjectPRO( level, 1200, 1200, 1200 )
createUI()
rem SetFastStackPRO( 1 )
do
getevent
if eventsource()=Panel1 and eventtype()=MOUSE_CLICK
Print "You clicked Panel1!!!"
endif
if eventsource()=West1 and eventtype()=MOUSE_CLICK
Print "You clicked West1!!!"
endif
if eventsource()=East1 and eventtype()=MOUSE_CLICK
Print "You clicked East1!!!"
endif
if eventsource()=North1 and eventtype()=MOUSE_CLICK
Print "You clicked North1!!!"
endif
if eventsource()=South1 and eventtype()=MOUSE_CLICK
Print "You clicked South1!!!"
endif
if eventsource()=Input1 and eventtype()=MOUSE_CLICK
Print "You clicked Input1!!!"
`INPUTSource1#=VAL(getGadgetText(InputText1))
`INPUTSource2#=VAL(getGadgetText(OutputText1))
`POSITION OBJECT 1, INPUTSource2#, INPUTSource2#, INPUTSource2#
setGadgetText OutputText1, STR$(INPUTSource1#)
endif
if eventsource()=Exit1 and eventtype()=MOUSE_CLICK
`Print "You clicked Exit1!!!"
end
endif
set text size 20
text 0,0,"Cam speed: "+str$(cam_speed#)
text 0,40,"Use A/Z to change camera speed"
text 0,60,"Use mouse to rotate camera and arrow keys to move"
text 0,80,"Press 0 to de-activate the meshes, press 9 to activate them"
text 300, 0, "Camera X Pos: "+str$(object position x(cam_obj))
text 300, 20, "Camera Z Pos: "+str$(object position z(cam_obj))
UpdateKeyHold()
UpdateCamera()
if KeyHit(11) `if 0 is hit
rem This is the command to de-activate an object for collision.
rem This will speed things up if you disable objects that are
rem "out of range" or "invisible" for instance.
DeActivateObjPRO( level )
DeActivateObjPRO( level2 )
endif
if KeyHit(10) `if 9 is pressed
rem This command re-activates your collision object.
rem Hence, your object will be tested for collision again.
rem This command and the command above could be used to
rem improve performance with visibility scenes.
ActivateObjPRO( level )
ActivateObjPRO( level2 )
endif
rem And here's the best line! This commands runs the entire collision system
rem and updates all of your objects for you. Easy enough?
rem
rem I hear you ask, "But wait, what if I delete an object? Won't it crash?"
rem Well, we already thought of that (apparently). The system will recognize
rem that the object is gone and safely remove it from collision memory for you
rem RunCollisionExPRO()
RunCollisionPRO()
rem Now what are we up to? Well, we're getting collision feedback
rem information about our camera. As you may have use for this info
rem in your own applications
CollCount = CountCollisionsPRO( cam_obj )
text 0, 20, "Collision Count: "+str$(CollCount)
rem this loop will now go through each collision that we had
rem and get information about it
for t=0 to CollCount-1
rem Gets the collision point of contact
rem Paramaters: object, collision index
xhit# = CollisionHitPointPRO( cam_obj, t, 1 )
yhit# = CollisionHitPointPRO( cam_obj, t, 2 )
zhit# = CollisionHitPointPRO( cam_obj, t, 3 )
rem Gets the collision point of contact normal
rem NOTE: This normal points toward the center of the ellipsoid
rem Paramaters: object, collision index
ynorm# = CollisionHitNormPRO( cam_obj, t, 2 )
rem displays screen information
msg$ = "Collision "+str$(t)+ " info: "
msg$ = msg$ + "XHit: "+str$(xhit#)+" "
msg$ = msg$ + "YHit: "+str$(yhit#)+" "
msg$ = msg$ + "YNorm: "+str$(ynorm#)+" "
text 0, 550+(-18*t),msg$
next t
`position our camera back in the "camera object" position,
`since the collision system only uses objects (not cameras)
camx# = object position x(cam_obj) : camy# = object position y(cam_obj) : camz# = object position z(cam_obj)
camrx# = object angle x(cam_obj) : camry# = object angle y(cam_obj) : camrz# = object angle z(cam_obj)
position camera camera, camx#, camy#, camz#
rotate camera camera, camrx#, camry#, camrz#
sync
getevent
loop
``***********
```**** INPUT FUNCTIONS ********
``***********
rem Checks keys down to notify us if a key is being held
function UpdateKeyHold()
for t=0 to 256
LastKeyHold(t) = KeyHold(t)
next t
for t=0 to 256
KeyHold(t) = Keystate(t)
next t
endfunction
rem Checks if a Key has been hit
function KeyHit(t)
retval=0
if not LastKeyHold(t)
if KeyHold(t)
retval=1
endif
endif
endfunction retval
``***********
```**** Control/Display FUNCTIONS ********
``***********
rem Camera handling function
function UpdateCamera()
` Mousemove code
movex# = mousemovex() / 2
movey# = mousemovey() / 2
dx#=dx#+movey#/4 : cy#=wrapvalue(cy#+movex#*0.2)
if dx#>90 then dx#=90
if dx#<-90 then dx#=-90
cx#=wrapvalue(dx#)
` Gets the new rotation values for the camera
cx# = cx# + object angle x(cam_obj)
cy# = cy# + object angle y(cam_obj)
` Rotate the camera
rem Rotate Object cam_obj, cx#, cy#, 0
RotateObjectPRO( cam_obj, cx#, cy#, 0 )
`Move the camera from keyboard input
rem if UpKey() then move object cam_obj, cam_speed#
rem if DownKey() then move object cam_obj, -cam_speed#
if UpKey() then MoveObjectPRO( cam_obj, cam_speed# )
if DownKey() then MoveObjectPRO( cam_obj, -cam_speed# )
`set camera speed
if KeyHold(30) then cam_speed#=cam_speed#+0.1
if KeyHold(44) then cam_speed#=cam_speed#-0.1
endfunction
function createUI()
If Not GUI_CONSTANTS Then errorMessage "GUI Constants not defined. Please include gui.dba when you compile" : end
Panel1=createPanel(210,620,605,95,0)
setPanelBorderStyle Gadget1,2
West1=createButton(12,32,35,25,"West",0,Panel1)
North1=createButton(47,7,35,25,"North",0,Panel1)
East1=createButton(82,32,35,25,"East",0,Panel1)
South1=createButton(47,57,35,25,"South",0,Panel1)
Input1=createButton(517,17,75,25,"Input",0,Panel1)
Exit1=createButton(517,57,75,25,"Exit",0,Panel1)
InputText1=createEdit(147,12,325,30,0,Panel1)
OutputText1=createEdit(147,52,325,30,0,Panel1)
endfunction
`Create Main Menu
`----------------
function createMainMenu()
menu=createMenu(0)
endfunction]
?..?..?..?