Post by Supermonkey on Feb 19, 2004 19:48:58 GMT -5
Hi all, Just downloaded the new version of BASIC4GL and well vast improvements from V1.01 I'm amazed! (All we need now is standalone .exe file creation! which I'm sure Tom is working at). Due to this leap from V2.1.3 I have decided to have a real go at creating a decent looking yet simple game in BASIC4GL (and then possibly porting it to C++). I have decided to start off by making a simple engine which allows me to handle different object and there properties (i.e colour, position, type etc). I have quickly coded up a simple starting point which can create and position five cubes. I have then gone on to using a distance formula to check for collisions with the camera and the object created. This distance formula works fine for the 1 object but for all the other objects it is giving me false results.
I was wondering If anyone could check through the code and see if they can see why?
Thanks alot!
Jonny
P.S Code below
I was wondering If anyone could check through the code and see if they can see why?
Thanks alot!
Jonny
P.S Code below
textmode(TEXT_OVERLAID)
'Declare Object Variables
dim Object#(100)(4), object, o#, o, ObjX#, ObjZ#, ObjY#
'Declare Player/Camera Varibales
dim x#, xd#, z#, zd#, y#, ay#
'Declare Distance formula Variables
dim distance#, dx#, dz# , dy#
'Assign Values to object Variables
ObjX# = 0
ObjZ# = 0
ObjY# = 0
'Assign Values to Player Variables
x# = -1.5
y# = 0.0
z# = -6.0
'Quick test, creates 5 objects and positions them 30 units away from each other
for object = 1 to 5
o# = o# + 1
Object#(0)(0) = o#
Object#(o#)(1) = ObjX#
Object#(o#)(2) = ObjZ#
Object#(o#)(3) = ObjY#
Object#(o#)(4) = 1
ObjX# = ObjX# + 5
next
'Main Loop
while true
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glrotatef(-ay#,0,1,0)
glTranslatef(x#,y#,z#)
for object = 1 to 5
'Goes to the Cube sub-routine which draws and places the cubes
gosub Cube
next
' Goes to the Camera Control Sub routine
gosub ControlCam
'Assigns variables to be used in the distance formula. Here in the example you can see the
'distance is increasing as you get closer to the object :S Change the object number to 1 to see
'it working properly
dx# = object#(3)(1) - x#
dz# = object#(3)(2) - z#
dy# = object#(3)(3) - y#
'The distance formula which does'nt seem to be working :S
distance# = sqrt((dx# * dx#) + (dy# * dy#) + (dz# * dz#))
'Prints distance on screen
locate 0,6
print distance#
drawtext()
swapbuffers()
wend
ControlCam:
if scankeydown(VK_LEFT) then ay#=ay#+1:endif
if scankeydown(VK_RIGHT) then ay#=ay#-1:endif
if scankeydown(VK_DOWN) then
xd# = -sin(ay#*m_pi/180)
zd# = -cos(ay#*m_pi/180)
x# = x# + xd# * 0.1
z# = z# + zd# * 0.1
ENDIF
if scankeydown(VK_UP) then
xd# = -sin(ay#*m_pi/180)
zd# = -cos(ay#*m_pi/180)
x# = x# + xd# * -0.1
z# = z# + zd# * -0.1
endif
return
Cube:
glBegin(GL_QUADS)
glVertex3f(object#(object)(1) + 1.0, object#(object)(3) + 1.0,object#(object)(2) -1.0)
glVertex3f(object#(object)(1) - 1.0, object#(object)(3) + 1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0, object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0, object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) - 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) -1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) + 1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) + 1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) + 1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) - 1.0,object#(object)(3) -1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) + 1.0,object#(object)(3) -1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) + 1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) + 1.0)
glVertex3f(object#(object)(1) + 1.0,object#(object)(3) -1.0,object#(object)(3) -1.0)
glEnd()
return