Displaying points

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
FreeFrags
Posts: 16
Joined: Thu Mar 25, 2010 2:04 pm

Displaying points

Post by FreeFrags »

Hi,

I want to display a large number of points, which are updated. The idea is to remove the oldest points each time the buffer is updated.

i have tried the following to display the points:

Code: Select all

	video::SMaterial Material; 
	Material.Lighting = false; 
	Material.Wireframe = false;
	Material.PointCloud = true;

	scene::SMesh *smesh = new scene::SMesh(); 

	const int numberOfPoints = 100;
	for(int id = 0; id < 2000; id++) 
	{ 
		scene::SMeshBuffer *buffer = new scene::SMeshBuffer(); 

		video::S3DVertex Vertices[numberOfPoints ];
		for(int pointCounter = 0; pointCounter < numberOfPoints; ++pointCounter)
		{
			Vertices[pointCounter ] = video::S3DVertex(pointCounter, 0, id, 
										   0, 0, -1, 
										   video::SColor(255,0,0,0), 
										   0, 1);
			buffer->Vertices.push_back(Vertices[pointCounter]);
			buffer->Material = Material; 

			buffer->Indices.push_back(id * pointCounter + pointCounter -1);
		}

		smesh->addMeshBuffer(buffer); 
	} 

	smesh->setHardwareMappingHint(scene::EHM_STREAM, scene::EBT_VERTEX_AND_INDEX); 

	smgr->addMeshSceneNode(smesh); 
	    
	smesh->drop();
This displays the points as I would like, now i would like to update the mesh in such a way that the oldest points get deleted while i add a new set of points (Creating a max displayed points).

Now i have a few questions about this:
- Is this approach any good or is there easier or better ways?
- How would i delete the old points as i add new ones
- This approach displays the points on the screen as a single pixel is there a way to increase the amount of pixels?

Thanks in advance
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can set the material.Thickness to make the points bigger. Also make sure you recalculate the bounding box of the meshbuffer and the mesh in order to get correct clipping of the whole node. What I don't understand is why you create the array of s3dvertex elements. This is stored in Vertices automatically, so just push_back the actual s3dvertex element. Also call buffer->Vertices.reallocate(numberOfPoints) before the loop to speed up the creation.
The update depends on your notion of age. If in the first place vertex[0] is the oldest, you can simply store a pointer to store the oldest element (and wrap around after reaching the last one). Otherwise you may have t go through all points and determine if that's the oldest one.
Are you sure you don't want to use the particle system?
FreeFrags
Posts: 16
Joined: Thu Mar 25, 2010 2:04 pm

Post by FreeFrags »

Thank you for your quick reply

I must admit array i created was just stupid :) i had edited a piece of code i found on this forum but just forgot to remove that array, it as you said has no function what so ever :D

The thickness was exactly what i was looking for i overlooked that variable in the SMaterial

Reallocate yes missed that

Im pretty sure IParticleSystemSceneNode is not what im looking for. (I used an example of points placed in a rectangular shape just for testing purposes in the real situation the points wont be arranged like this)

What i want to do is show a million of these points and have another thread update the array. removing the first added 100.000 points and adding 100.000 new points.

Im using the buffers because i got a warning that i was using too many vertices in one buffer and artifacts may occur.

like you said i will be able to use a pointer to update the vertices in another thread.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For this huge amount of points you definitely need some more meshbuffers. Each buffer can take up to 65535 points. After that, the next meshbuffer has to be used. If you always know that exactly 100.000 points are changed, you should use two buffers with 50.000 points each and just switch the buffers. And don't forget to setDirty after updating the points.
If you target at certain classes of gfx cards, you could check if using 32bit indices (and hence many more points per meshbuffer) works better. In general, uploading more than 50000 points per buffer is not a good idea, so the first suggestion might be better.
FreeFrags
Posts: 16
Joined: Thu Mar 25, 2010 2:04 pm

Post by FreeFrags »

So if i understand correctly splitting up the points into meshbuffers of 50.000 points would do the trick?

something like this:

Code: Select all

for each 50.000 points 

  if mesh contains 1 million points
    erase meshbuffer 0 (50.000 points)
    pushback new meshbuffer
    setDirty on each meshbuffer
  end if
  else
    pushback new meshbuffer
  end else

end for each
Then i should use
smesh->setHardwareMappingHint(scene::EHM_STREAM, scene::EBT_VERTEX_AND_INDEX);
as the meshbuffers in the mesh are updated frequently is that right?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you push_back new meshbuffers each time you could even use EHM_STATIC. However, the GPU memory could fill up that way, because VBOs are not deleted immediately (except if you do take care of this). So maybe updating the positions of the points in the next meshbuffer would do a better job.
I don't get the actual reasoning behind your pseudo-code, I think the logic should be different. At first you create the meshbuffers with all points that should be visible at the same time. Next comes your update loop, which updates the oldest points to new positions each time an update is triggered.
Post Reply