6
I'm making a program to draw and process thousands of 3D points obtained by a machine, this is in Windows. The amount of points can be some thousands at once. I use the X_DOT order to draw the points in the screen, but nothing appears, only the axes. In GLB v10.283 (last v10) the points are drawn some frames and then dissapears forever in few seconds. In last v11 Beta the points are not shown never, only the axis (for testing). With 1,000 points can work, but with 10,000 points you can see this error.
If I don't use X_DOT command and I draw the points with X_WORLD2SCREEN and SETPIXEL (it's the same calculation, in theory to project the points) all works ok and the points are shown ok. I don't know if this is a GLB or OpenGL limitation, or something goes wrong and fails in X_DOT. I tested other 3D orders like STARTPOLY/ENDPOLY with the points and fails too. Drawing in 2D with calculations plot the points good in their position (but its not hardware accelerated).
Here is the code I use, I changed data reading part for random functions, but the result is the same.
This shows 10,000 random 3d points using 2d drawing and calculations. If you comment the calling to PaintPixels() and uncomment the PaintDots() not works. This way uses 3d drawing funtions.
// test with 10 thousand points
LOCAL nptos = 10000
// 3d point type with colour
TYPE TPunto
x#; y#; z#; irgb%
ENDTYPE
LOCAL puntos[] AS TPunto
GLOBAL xmin#, xmax#, ymin#, ymax#, zmin#, zmax#
GLOBAL med AS TPunto
LIMITFPS 30
SETSCREEN 800, 600, 0
SYSTEMPOINTER TRUE
SEEDRND GETTIMERALL()
// create and fill the 3d points array
CreatePoints(puntos[], nptos)
// calculate the center point for camera
CalculateBounds(puntos[])
// draws the point array
DrawPoints(puntos[])
END
// create the points and fills the array
FUNCTION CreatePoints: puntos[] AS TPunto, num%
LOCAL i%
DEBUG "Creating points...\n"
REDIM puntos[num]
FOR i=0 TO num-1
ALIAS p AS puntos[i]
// coordinates from -50 to +50
p.x = RND(100) - 50
p.y = RND(100) - 50
p.z = RND(100) - 50
p.irgb = RGB(0,RND(256),0)
NEXT //i
ENDFUNCTION
// calculate the limits and central point of the array
FUNCTION CalculateBounds: puntos[] AS TPunto
LOCAL i%
DEBUG "Calculate bounds...\n"
xmin = 9999; ymin = 9999; zmin = 9999
xmax = 0; ymax = 0; zmax = 0
FOREACH p IN puntos[]
IF p.x < xmin THEN xmin = p.x
IF p.x > xmax THEN xmax = p.x
IF p.y < ymin THEN ymin = p.y
IF p.y > ymax THEN ymax = p.y
IF p.z < zmin THEN zmin = p.z
IF p.z > zmax THEN zmax = p.z
NEXT //i
// calculate center of the object
med = MediumPoint(xmin, xmax, ymin, ymax, zmin, zmax)
DEBUG "Center point: " + med.x +", "+ med.y +", "+ med.z +"\n"
ENDFUNCTION
// give the medium point of the 3d bounds
FUNCTION MediumPoint AS TPunto: xmin#, xmax#, ymin#, ymax#, zmin#, zmax#
LOCAL med AS TPunto
med.x = (xmax + xmin) / 2
med.y = (ymax + ymin) / 2
med.z = (zmax + zmin) / 2
RETURN med
ENDFUNCTION
FUNCTION DrawPoints: puntos[] AS TPunto
LOCAL i%, dist% = 100
DEBUG "Drawing points\n"
REPEAT
X_MAKE2D
IF KEY(200) THEN INC dist // ^
IF KEY(208) THEN DEC dist // v
PRINT "Distance: " + dist, 0, 0
//X_MAKE3D 1, 2500, -1
X_MAKE3D 1, 2000, 45
X_AMBIENT_LT 0, RGB(255,255,0)
X_CAMERA med.x+dist, med.y+dist, med.z+dist, med.x, med.y, med.z
X_DRAWAXES med.x, med.y, med.z
// test the drawing methods
//PaintDots(puntos[])
PaintPixels(puntos[])
SHOWSCREEN
UNTIL KEY(1)
ENDFUNCTION
FUNCTION PaintDots: puntos[] AS TPunto
LOCAL xx#, yy#, front#
FOREACH p IN puntos[]
X_DOT p.x, p.y, p.z, 1, p.irgb
NEXT //p
ENDFUNCTION
FUNCTION PaintPixels: puntos[] AS TPunto
LOCAL xx#, yy#, front#
X_MAKE2D
FOREACH p IN puntos[]
X_WORLD2SCREEN p.x, p.y, p.z, xx, yy, front
SETPIXEL xx, yy, p.irgb
NEXT //p
ENDFUNCTION