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
For me both works. Maybe its your graphic card that has problems with that many 3D-Dots?
I tested in two computers with the same results, but I'm going to test in more machines. The first computer has a bad graphics card, but the second has a gaming card.
Err...i get the same effect, but they arent disappearing.
They are spreading out away from the bounds of the cubed area.
When i switch X_DOT to X_DRAWAXES, it works fine.
I think maybe you should create your own object, like a 4 point pyramid or 8 point cube.
This bug has me going, i will look further and see what the problem is because i use x_dot in one of my current projects(although i didnt have this effect), but then again i dont think i used so many dots either.
Quote from: Hemlos on 2012-Nov-08
Err...i get the same effect, but they arent disappearing.
They are spreading out away from the bounds of the cubed area.
I see the same effect in my other pc, the points are fixed in the background and they don't move with the arrow keys (this change the camera distance), like the axis. They are few points than in the first frame too. Something is wrong with this 3d points.
With 10,000 points as in the example, the points drawing is very slow compared with the pixel method, and if you wait for some frames (1 minute o a little more), they dissapear. If you put 1,000 points (nptos=1000), you can see better the effect, they are showed and dissapear faster.
Quote from: Hemlos on 2012-Nov-08
I think maybe you should create your own object, like a 4 point pyramid or 8 point cube.
My solution was using the X_WORLD2SCREEN and SETPIXEL method.
Quote from: Hemlos on 2012-Nov-08
This bug has me going, i will look further and see what the problem is because i use x_dot in one of my current projects(although i didnt have this effect), but then again i dont think i used so many dots either.
I think this can be a memory leak in X_DOT or an uncaught exception wich skips the drawing, or part of the drawing.
Sorry, i did a few more tests and now I can confirm your problem.
Try this :
// 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_CAMERA med.x+dist, med.y+dist, med.z+dist, med.x, med.y, med.z
X_AMBIENT_LT 0, RGB(255,255,0)
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
The 3D commands have to be done in a specific order - the sudden disappearance of objects denotes that they aren't :)
A YouTube video of it :
camera then lights, i assume was the issue?
myself, i use small functions to handle these orderings in groups
(make3d cameraup and camera)
(alpha lights)
(scale move rotate)
(cull texture object)
Quote from: MrTAToad on 2012-Nov-08
Try this :
.....
The 3D commands have to be done in a specific order - the sudden disappearance of objects denotes that they aren't :)
Thank you MrTAToad, now works ok. The order of 3d commands is important, now I've learned the lesson.
:nw: :nw:
Quote from: Hemlos on 2012-Nov-08
camera then lights, i assume was the issue?
Yes, thats pretty much the problem...