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.


Topics - matty47

Pages: 1 [2]
16
Code Snippets / Plane Lib
« on: 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

17
GLBasic - en / Entity Code
« on: 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

18
GLBasic - en / Blender Export
« on: 2007-Sep-15 »
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

19
GLBasic - en / GLBasic under Virtual Machine
« on: 2007-Aug-22 »
My win2k died ( well really I killed it) so I tried running GLBAsic in win2k under both VMWare and Virtualbox in Ubuntu but did not have any success. Windows programmes compiled and ran OK although a dialog appeared saying I should update my video driver to provide hardware OpenGL acceleration, but when i tried a linux compile I kept getting an error saying that lib.so.6 could not be found. iInote that this lib is a link to another file in the linux lib directory so maybe the links don't work in the virtual environment.
Anyway I will just have to reinstall windoze.........ah well.
Hope this info is of some use to someone.
Matt

20
GLBasic - en / Blender Models
« on: 2007-Jun-09 »
Hi, do I have to do anything "special" to export models from blender? I have tried a few models but I think that I may have trouble with the scaling. Is there anyway to read the size (x,y,z) from the ddd file so that placement of the camera is in a suitable location?
Thanks
I will persevere.
Matthew

21
GLBasic - en / Linux Executable
« on: 2007-May-05 »
I am having rouble running linux executables. I had created some programs with an earlier demo of glbasic and these ran OK. Now having registered for full version I find programs compiled for linux won't run. (Puppy Linux and Kubuntu Dapper). On both there is a segmentation error with a message about SDL parachute deployed. Is anyone else having this problem ? Do I need to install some other package?
Thanks
Matthew
PS Should give specs. Athlon 2600, 512mb, Radeon 9600SE, Video driver fglrx.
Note that I have a similar problem with "Purebasic" which uses "Ogre" as its 3d engine.
PPS Note that executables are being compiled under Windows 2000. Seem to compile OK and run under Windows but the linux executables don't work under linux.

Pages: 1 [2]