Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - matty47

#1
Just getting back into GLBasic after a long hiatus. I wrote some 3d testing code a long time ago (looks like 2007). When I recompile these programs with V15.238 it seems that the .dd models are not being found. I tried adding GetCurrentPath$ to the file name and made sure that the files were in the executable directory but no luck. I also tried loading from a media directory but still no luck.
This is the code. I recently added the GetCurrentDir$ when the original would not work.
Code (glbasic) Select
// --------------------------------- //
// Project: 3dtry
// Start: Monday, September 10, 2007
// IDE Version: 4.279


LOADSPRITE GETCURRENTDIR$()+"floor.png", 0

X_LOADOBJ GETCURRENTDIR$()+"floor1.dda", 0

cam_x =0;cam_y=0.5;cam_z=1.5 //camera postion
cam_dir=0  //camera direction
player_x=0;player_y=0;player_z=0
sz=2 //camera step size
WHILE TRUE
dtime=GETTIMER()
//IF INKEY$="Q" THEN END

X_MAKE3D 0.1,500,60
//X_CULLMODE 0
X_CAMERA cam_x,cam_y,cam_z,cam_x+COS(cam_dir)*sz,cam_y,cam_z+SIN(cam_dir)*sz
X_AMBIENT_LT 0, RGB(200,200,200)
X_SPOT_LT 0,RGB(255,255,255),0,40,0,0,-1,0,100
X_MOVEMENT player_x,player_y,Player_z
//X_SCALING 2,0.25,2
X_SETTEXTURE 0,-1
X_DRAWOBJ 0,0
X_DRAWAXES 0,0,0
X_DOT 2,0,0,10,RGB(255,0,0)
X_DOT 0,0,2,10,RGB(0,0,255)
MoveCam()
//X_3rd_Person(Player_x,Player_y,Player_z,10,1)
//player_x=player_x-0.05
X_MAKE2D
//show the frames per second
fps=((1000/dtime)+fps)/2
delay=delay+dtime
IF delay>1000
delay=0
showFPS=fps
ENDIF
PRINT "FPS: "+INTEGER(showFPS)+"  CamY= "+height,0,0
SHOWSCREEN
WEND







FUNCTION  X_3rd_Person: Player_x, Player_y, Player_z, Max_Cam_dist, Min_Cam_Dist
   IF ein_durchlauf = FALSE
      Distance = Max_Cam_dist
      my = 45
      ein_durchlauf = TRUE
   ENDIF


   X_CAMERA cam_x+Player_x, cam_y+Player_y, cam_z+Player_z,    Player_x, Player_y, Player_z



   INC Distance,MOUSEAXIS(2)*5
   IF Distance < Min_Cam_Dist THEN Distance = Min_Cam_Dist
   IF Distance > Max_Cam_dist THEN Distance = Max_Cam_dist

   mx = mx + MOUSEAXIS(0)/20
   my = my + MOUSEAXIS(1)/20

   IF my < -40 THEN my = -40
   IF my > 80 THEN my = 80

   cam_x = Distance * COS(mx)
   cam_z = Distance * SIN(mx)
   cam_y = Distance * SIN(my)
ENDFUNCTION


FUNCTION MoveCam:
mx=MOUSEAXIS(0)*dtime/5
my=0

IF KEY(200) THEN my=0.06*dtime
IF KEY(208) THEN my=-0.06*dtime
cam_x=cam_x + my*COS(cam_dir)*sz*dtime/500
cam_z=cam_z + my*SIN(cam_dir)*sz*dtime/500

height=X_COLLISIONRAY(0,0,cam_x,cam_y,cam_z,0,-1,0)
cam_y=cam_y+0.5-height
cam_dir=cam_dir+mx*dtime/600
ENDFUNCTION

Any ideas? It would have been great if the X_LoadObj returned something that indicated success or not. The help file does not indicate any return value.
Thanks for any pointers.
#2
I currently have pre Steam version 15..238 which Webupdate tells me is the latest version. I purchased the full key some 15 years ago. I was thinking that I may update to the Steam version (as this is the only way I will get future updates it seems). I would like to know if the compilers on the Steam version include Linux 64, Android 64, Raspberry Pi 64. I have read forum posts that indicate that both Win32 and Win64 compilers are present. I tried to find further info on Steam but was unsuccessful. Could someone please tell me which platform compilers are included in the Steam version. Thanks for your help.
#3
Hopefully not too dumb a question but I need a drawing surface that has 0,0 at the bottom left corner and increases in x and y across and up respectfully. I think I could use a 3d screen with an orthographic camera to implement this however I can't seem to find a command that would make the camera orthographic and not perspective. Is this possible in GLBasic? and (of course) some guidance on how to do it would be greatly appreciated.
Thanks in advance
Matthew
#4
Is there a way to make x_line or x_dot objects pickable with x_collisionray?
I want to be able to draw lines and points on a screen and then pick ( and adjust) individual items.
Thanks for any pointers.
#5
Are they allowed.
For instance I want to do something like this
Code (glbasic) Select

CONSTANT MaxDims=3

TYPE Point
     Loc[MaxDims]
ENDTYPE

.....................................
//then later do

LOCAL P1 AS POINT
.......................................
FOR i = 0 to MaxDims
      IF P1.Loc[i] ................

Now I know this code won't work but the compiler issues an error for the Loc[MaxDims] line
Any answers greatly appreciated
Thanks
Matthew
#6
Has anyone else had trouble with the degugger? If I enable building with the debugger and then do a compile/run the project compiles, links and then a message appears that the debug session has started but there is no application running. If I turn off the debugger and do a compile/run the application runs fine. I have tried this with various of the samples and always seems to do the same thing. Any ideas??
using the latest version 7.242, Win XP.
THanks
MAtthew
#7
GLBasic - en / Size of Mesh
2009-Jun-15
Is there any way to determine the size of a mesh? Looking for something that would give say height, width, depth of a loaded mesh.
#8
Does GLBasic support the above platform? Looking at purchasing a smartphone with this operating system (320 x 240 display) and wondering if I can use GLB to make programs for it?
Thanks
Matthew
#9
I believe that GLBasic uses the Newton Library as a dynamic library rather than statically linking. I have the libraries for Windows and Linux, but am not sure how to obtain / make the library for OS X. I am trialling on an Emac with System 10.5 installed. XCode is installed (Although I don't profess to really know how to use it). Has anyone used Newton and GLBasic on OS X? If so could you please give some advice on how to get Newton working or post the newton.dylib somewhere for download.
Thanks for your patience
Matthew
#10
GLBasic - en / Newton Error
2008-Jul-17
Hi, I have been fiddling with the Newton examples and am sure that the dddCollision sample worked previously however now when I compile and run this file the ball drops throught the "ground" object. I am sure that I have note changed the code but here it is anyway
Code (glbasic) Select
LOCAL dtime
LOCAL org[] // just a dummy
LOCAL force[]

X_LOADOBJ  "ground.ddd", 0
LOADSPRITE "ground.bmp", 0
X_LOADOBJ  "sphere.ddd", 1
DIM force[3]

// initialize Newton Engine
NewtonCreate()

// default material
NewtonMaterialSetDefaults( 1, .9, .2, .9, .9)

ball = NewtonCreateSphere(.8, .8, .8, org[])
// position ball
NewtonBodySetPosition(ball, 0,12,3)
// enable dynamics
NewtonConvexCollisionCalculateInertialMatrix(ball, 1)
// enable gravity for ball
NewtonBodySetForceAndTorqueCallback(ball)
NewtonBodySetGravity(ball,0,-9.81,0)
NewtonBodySetAutoFreeze(ball, FALSE)


// solid, static ground
ground = NewtonCreateDDD(0, 0)

WHILE TRUE
NewtonUpdate(GETTIMER(), 6)
force[0] = -MOUSEAXIS(0)*3
force[2] = -MOUSEAXIS(1)*3
NewtonBodyAddTorque(ball, force[])
X_MAKE3D 1,100, 45
X_CAMERA 20, 20, -10, 0,0,0

X_AMBIENT_LT 0, RGB(255,255,255)

X_SCALING .8, .8, .8
NewtonDrawBody(ball, 1,0)
X_SCALING 1,1,1
X_SETTEXTURE 0,-1
NewtonDrawBody(ground, 0,0)
SHOWSCREEN
WEND


Using version 5.322
Thanks
Matthew
#11
Hi, can anyone tell me what are the required frameworks on os x to run glbasic apps? I tried running an executable and found that it required SDL. I installed the SDL.Framework in my home directory and next time apparently libpng was needed. To save trial and error can anyone tell me what I need to install
Thanks greatly for any help you can give.
Matthew
#12
I tried compiling a program using entity lib for osx ppc and got the following error
Code (glbasic) Select

*** Configuration: OS-X_UNI ***
precompiling:
GPC - GLBasic Precompiler V.2008.093 - 3D, NET
Wordcount:332 commands

compile+link:
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glAttachObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glAttachObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glAttachObjectARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glCompileShaderARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glCompileShaderARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glCompileShaderARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glCreateProgramObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glCreateProgramObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glCreateProgramObjectARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glCreateShaderObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glCreateShaderObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glCreateShaderObjectARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glDeleteObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glDeleteObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glDeleteObjectARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glGetBufferParameterivARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glGetBufferParameterivARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glGetBufferParameterivARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glGetInfoLogARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glGetInfoLogARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glGetInfoLogARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glGetObjectParameterivARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glGetObjectParameterivARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glGetObjectParameterivARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glGetUniformLocationARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glGetUniformLocationARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glGetUniformLocationARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glLinkProgramARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glLinkProgramARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glLinkProgramARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glShaderSourceARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glShaderSourceARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glShaderSourceARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glUniform1fARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glUniform1fARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glUniform1fARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glUniform1iARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glUniform1iARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glUniform1iARB in section (__DATA,__data)
/cygdrive/c/Program Files/GLBasic/Compiler/platform/Mac/Bin/../libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: multiple definitions of symbol _glUseProgramObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib(gll_api.o) definition of _glUseProgramObjectARB
/cygdrive/C/Program Files/GLBasic/Compiler/platform/Mac/OSX/Lib/libGLBasicUni.a(OpenGLRainbows.o) definition of _glUseProgramObjectARB in section (__DATA,__data)
collect2: ld returned 1 exit status
*** FATAL ERROR - Please post this output in the forum

Any idea??
THanks
Matthew
#13
Hi, I have been playing with the Entity System code but am having trouble with the light direction. The lights are drawn in the following code
Code (glbasic) Select
X_SPOT_LT iLight, o.color, o.Mg[12], o.Mg[13], o.Mg[14], _
o.Mg[12]+o.Mg[0], o.Mg[13]+o.Mg[1], o.Mg[14]+o.Mg[2], o.cutoff

and I know that the first three entries on the second line are supposed to give the vector of the light direction. Note that I have added a new field to the entity type (cutoff) with a couple of functions tha allow me to change the cutoff angle of the spotlight. My problem is that if I set the cutoff to say 45 to make a regular spotlight and then do an entity rotate in the main loop the light doesn't seem to rotate. I suspect this line as the camera uses the same code but with the camera you are specifying the point to which the camera is pointed whereas with the light I believe you are specifying a vector from the light (not a point). Before I go off writing separate light routines can anyone tell me the correct entries for the vector - or have I missed something again.
Thanks for any help
Matthew
#14
A few functions to extract the component values of a 32 colour and an example of how to use them. I have adapted the example code from a DarkbasicPro tutorial so if you feel this infringes any copyright please remove. Hopefully the code is commented enough to work out. You will need a 200 x 200 pixel image with a spectrum of colours for the sprite.
Code (glbasic) Select
// --------------------------------- //
// Project: RGB_Tute2
// Start: Thursday, February 28, 2008
// IDE Version: 5.179
//load our image
LOADSPRITE "rgb.png",1
//drawing to 2d screen
X_MAKE2D
//draw our base picture
DRAWSPRITE 1,0,0
LOCAL x=190
LOCAL y=190
LOCAL col,tx,ty,r,g,b,timer,TimeTaken
GLOBAL blue,green,red,alph
timer=GETTIMERALL()
FOR ty=0 TO y
FOR tx=0 TO x
col=GETPIXEL(tx,ty) //get the colour at tx,ty
//now split the colour into its components
r=rgbr(col)
g=rgbg(col)
b=rgbb(col)

//now use these to draw 3 images
SETPIXEL tx+200,ty,RGB(r,0,0)
SETPIXEL tx+400,ty,RGB(0,g,0)
SETPIXEL tx+600,ty,RGB(0,0,b)

//now draw another 3
SETPIXEL tx+200,ty+200,RGB(r,g,0)
SETPIXEL tx+400,ty+200,RGB(r,0,b)
SETPIXEL tx+600,ty+200,RGB(0,g,b)

//and finally another three
SETPIXEL tx+200,ty+400,RGB(r*2,g*2,b*2)
SETPIXEL tx+400,ty+400,RGB(r-tx,tx,b-tx)
SETPIXEL tx+600,ty+400,RGB(150,g/2,b/2)


NEXT
NEXT
TimeTaken=GETTIMERALL()-timer
PRINT "Time Taken = "+TimeTaken,10,550
SHOWSCREEN
KEYWAIT
END


//*************************************
//Function rgbr(col) - return the red component of a 32 bit colour
//*************************************
FUNCTION rgbr: col
red=bAND(col,0xff)
RETURN red
ENDFUNCTION
//*************************************
//Function rgbg(col) - return the green component of a  32 bit colour
//*************************************
FUNCTION rgbg: col
green=bAND(col/0x100,0xff)
RETURN green
ENDFUNCTION
//*************************************
//Function rgbb(col) - return the blue component of a  32 bit colour
//*************************************
FUNCTION rgbb: col
blue=bAND(col/0x10000,0xff)
RETURN blue
ENDFUNCTION
//*************************************
//Function rgba(col) - return the alpha component of a  32 bit colour
//*************************************
FUNCTION rgba: col
alph=bAND(col/0x1000000,0xff)
RETURN alph
ENDFUNCTION
The image I used had that transparent colour (pink) in it so the effect was a bit marred. (Is there a way to turn off the pink transparency??) You need to set the resolutuin to at least 800x600
I tested the speed in both DarkBasic Pro and GLBasic. - DBP 11.44secs, GLB - 1.84secs.
Hope this may be useful
M
#15
Hi,
please look at the project in the zip
//members.optusnet.com.au/~ingle.m/3droom.zip
When I run this I can see the model OK even though I have not made any lights. If I add a light nothing changes. I think I am missing something fundamental here. (Note I have added extra stuff to the T3DEntity file)
Any help appreciated
Matthew
#16
Bug Reports / KeyCode 08
2007-Dec-09
Hi,
just tried to use Key(08) and Key(09) in a program and the following error appeared for the latter

invalid digit "9" in octal constant

Key(10) seems to work OK
Thanks
Matthew
#17
I know that color 128,0,255 is treated as transparent when creating images for GLBasic sprites. How do I achieve a "fuzzy" edge for sprites. I created a 128 x 128 png with a pink background. I then drew a white circle on this. I then applied a gaussian blur to geve the edges a blurred effect. When I use this as a sprite there are pink tinges at the edge of the white. (Obviously the blur changes some of the pink background). I also tried doing this with a transparent background. With the transparent background the sprite looked as though it had sharp edges. I must be misunderstanding something. Any help please?
THanks
Matthew
#18
Code Snippets / Plane Lib
2007-Oct-29
Hi, after being inspired by the Entity Library/System on the German forum I have been experimenting with a plane lib. Probably best just to look at the code. You need a texture for the water in the example. Can't remember where I got the camera code but it was on this forum.
The plane library
Code (glbasic) Select
// --------------------------------- //
// Project: Plane
// Start: Sunday, October 28, 2007
// IDE Version: 5.055
//Matthew Ingle - October 2007
//A set of functions to implement a plane object
//Add to as you see fit however share the code!!
TYPE Plane_vertex
plx
ply
plz
tx
tz
col
ENDTYPE

TYPE TPlane
Plane_pts[] AS Plane_vertex
xverts
zverts
smooth
ENDTYPE
//--------------------------------------------//
//! Create a plane of z length, x width and having x and z divisions
//! Use smooth= TRUE to smooth the plane
//! you can reference any vertex by it's x,z number 0 to division -1
//--------------------------------------------//
FUNCTION CreatePlane AS TPlane:length,width,secx,secz,smooth
LOCAL name AS TPlane
LOCAL z_count,x_count
LOCAL delta_x=width/secx
LOCAL delta_z=length/secz
REDIM name.Plane_pts[secx+1][secz+1]
FOR x_count=0 TO secx
FOR z_count=0 TO secz
name.Plane_pts[x_count][z_count].plx=delta_x*x_count
name.Plane_pts[x_count][z_count].ply=0
name.Plane_pts[x_count][z_count].plz=delta_z*z_count
name.Plane_pts[x_count][z_count].tx=MOD(x_count,2)
name.Plane_pts[x_count][z_count].tz=MOD(z_count,2)
name.Plane_pts[x_count][z_count].col=RGB(255,255,255)
NEXT
NEXT
name.smooth=smooth
name.xverts=secx+1
name.zverts=secz+1
RETURN name
ENDFUNCTION

//--------------------------------------//
//!Draw the plane
//--------------------------------------//
FUNCTION DrawPlane:name AS TPlane,objnum
LOCAL ix,iz
X_OBJSTART objnum
FOR ix=0 TO name.xverts-2
X_OBJNEWGROUP
FOR iz= 0 TO name.zverts-1
X_OBJADDVERTEX name.Plane_pts[ix][iz].plx,name.Plane_pts[ix][iz].ply,name.Plane_pts[ix][iz].plz,name.Plane_pts[ix][iz].tx,name.Plane_pts[ix][iz].tz,name.Plane_pts[ix][iz].col
X_OBJADDVERTEX name.Plane_pts[ix+1][iz].plx,name.Plane_pts[ix+1][iz].ply,name.Plane_pts[ix+1][iz].plz,name.Plane_pts[ix+1][iz].tx,name.Plane_pts[ix+1][iz].tz,name.Plane_pts[ix+1][iz].col
NEXT
NEXT
X_OBJEND
IF name.smooth=TRUE
X_AUTONORMALS 2
ELSE
X_AUTONORMALS 1
ENDIF

X_DRAWOBJ objnum,0
RETURN 1
ENDFUNCTION

//-------------------------------------//
//! Set the height of a particular plane vertex
//-------------------------------------//
FUNCTION SetPlaneHeight: name AS TPlane,x,z,height
name.Plane_pts[x][z].ply=height
ENDFUNCTION

//------------------------------------//
//! Get the height of the plane at x,z
//------------------------------------//
FUNCTION GetPlaneHeight: name AS TPlane,x,z
RETURN name.Plane_pts[x][z].ply
ENDFUNCTION

//------------------------------------//
//! Assign a random value between 0 and h to each vertex in the plane
//------------------------------------//
FUNCTION RandomisePlane: name AS TPlane,h
LOCAL ix,iz
FOR ix=0 TO name.xverts-1
FOR iz=0 TO name.zverts-1
SetPlaneHeight(name,ix,iz,RND(h))
NEXT
NEXT
ENDFUNCTION
The camera code
Code (glbasic) Select
UNCTION MoveCam:
INC phiXZ,MOUSEAXIS(0)/10 //left-right turn
INC phiXY,MOUSEAXIS(1)/10 //up-down turn

IF phiXZ > 360 THEN phiXZ=phiXZ-360
IF phiXZ < 0 THEN  phiXZ=phiXZ+360

IF phiXY < -up_down_limit THEN phiXY=-up_down_limit
IF phiXY > up_down_limit  THEN phiXY=up_down_limit

IF KEY(17) //forward -- w key
INC camz,SIN(phiXZ)*WalkSpeed
INC camx,COS(phiXZ)*WalkSpeed
ENDIF

IF KEY(31) //back -- s key
DEC camz,SIN(phiXZ)*WalkSpeed
DEC camx,COS(phiXZ)*WalkSpeed
ENDIF

IF KEY(30) //left -- a key
INC camz,SIN(phiXZ-90)*WalkSpeed
INC camx,COS(phiXZ-90)*WalkSpeed
ENDIF

IF KEY(32) //right --d key
INC camz,SIN(phiXZ+90)*WalkSpeed
INC camx,COS(phiXZ+90)*WalkSpeed
ENDIF

ENDFUNCTION
And a program to test the code
Code (glbasic) Select
// --------------------------------- //
// Project: Plane
// Start: Saturday, October 27, 2007
// IDE Version: 5.047
//Test of the plane functions as an ocean swell
//Matthew Ingle October 2007
//Code adapted from a Darkbasic example
//Use and improve!!!
//------------Declarations------------//
//Variables for camera
LIMITFPS 25
GLOBAL up_down_limit=30
GLOBAL camy=20,camx=15,camz=15
GLOBAL WalkSpeed=0.5
GLOBAL phiXZ=0
GLOBAL phiXY=0

//Variable for ground plane
LOCAL ground AS TPlane
LOCAL size=2000 // the x and z size of the plane
LOCAL divisions=20 //the number of divisions in the plane
LOCAL waveheight=2
DIM ripple[divisions*divisions] // an array to hold ripple data for the plane

//Fill the ripple array with data
LOCAL t
FOR t=0 TO divisions*divisions-1
ripple[t]=RND(359)
NEXT

//Create a plane object and assign random heights to the vertices
ground=CreatePlane(size,size,divisions,divisions,TRUE)
RandomisePlane(ground,waveheight)
//load a sprite FOR the water
LOADSPRITE "water.bmp",500

//draw a plain blue background
GETSCREENSIZE sx,sy
DRAWRECT 0,0,sx,sy,RGB(0x38, 0x8e, 0xc2)
GRABSPRITE 100,0,0,sx,sy

//main loop
WHILE TRUE
DRAWSPRITE 100,0,0
X_MAKE3D 0.1,1000,45
X_CAMERA camx, camy, camz,   camx+COS(phiXZ), camy+SIN(-phiXY), camz+SIN(phiXZ)
X_AMBIENT_LT 0,RGB(255,255,255)
X_FOG RGB(240,240,255),FALSE,200,1000
X_DRAWAXES 0,0,0
//update the ripple data for the plane
LOCAL ix,iz
FOR ix =1 TO divisions-2
FOR iz=1 TO divisions-2
//Get the current height of the plane vertex
h=GetPlaneHeight(ground,ix,iz)
//Match the vertex to a member of the ripple array
tt=ix+(iz*divisions-1)
//set the new height of the vertex
SetPlaneHeight(ground,ix,iz,h+(COS(ripple[tt])*1))
//and change the ripple height for next time
ripple[tt]=MOD(ripple[tt]+5,360)
NEXT
NEXT
//Set the water texture and draw the plane
X_SETTEXTURE 500,-1
DrawPlane(ground,500)
//check the camera for movement
MoveCam()
X_MAKE2D
PRINT "Camera X:"+camx,0,30
PRINT "Camera Z:"+camz,0,50
PRINT "Camera Y:"+camy,0,70
//show it
SHOWSCREEN
WEND
END
About time I contributed hope this is OK (I am not flameproof!!)
Thanks
Matthew
#19
GLBasic - en / Entity Code
2007-Oct-15
Gernot,
I tried the entity code from the German forum. My model displays ok but it doesn't seem to move ( as the code would suggest). I added some functions to get the position of the entity and displayed this on the screen. The position value of the entity changes on each loop so I can only think that the X-Multmatrix or the X-Drawanim instructions are not working (for me anyway). This code looks like a good start to a scene manager library. Any ideas??
Code I added to Entity.gbas
Code (glbasic) Select
// ------------------------------------------ //
//! Return the x position of the entity
// ------------------------------------------ //
FUNCTION GetEntityX: entity
RETURN g3DObj[entity].x
ENDFUNCTION

// ------------------------------------------ //
//! Return the y position of the entity
// ------------------------------------------ //
FUNCTION GetEntityY: entity
RETURN g3DObj[entity].y
ENDFUNCTION

// ------------------------------------------ //
//! Return the z position of the entity
// ------------------------------------------ //
FUNCTION GetEntityZ: entity
RETURN g3DObj[entity].z
ENDFUNCTION
Thanks
Matthew
#20
Hi,
I am having troubles with files exported from Blender. They seem to export with a one unit maximum size. I created a plane in Blender, with size 20 units on each side, subdivided it and made a sort of terrain,exported it to .dda and loaded it into a GLBasic program. The size in the program is one unit each side and the z axis seems exaggerated about two to one. Because scaling interferes with collision functions I found that I must deal in small x,y values. Any ideas? Am I doing something wrong? Any troubles with .3ds files? I suppose I could go to that format.
Thanks for any assistance
Matthew