Drawing lines between 2 nodes

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.
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Drawing lines between 2 nodes

Post by cp51 »

Hi all,

Im working on a molecular simulation and i need a way of drawing bonds between atoms in a material.

I am currently using the draw3Dline method but i was just wondering if anyone knows of a better way to accomplish this or should I stick with the draw3Dline?

One other thing i noticed is that if i have my first atom in a list of atoms at position (1,1,1) and try to draw a line from that atom to another the lines are shifted back to (0,0,0)... I have to subtract out the position of the first atom inorder to move the lines to their correct position. Can anyone tell me why this is?

Thanks a lot.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Drawing lines between 2 nodes

Post by Acki »

cp51 wrote:I am currently using the draw3Dline method but i was just wondering if anyone knows of a better way to accomplish this or should I stick with the draw3Dline?
I think it's the easiest way...
or maybe create a mesh, scale it as needed, place and rotate it... :lol:
cp51 wrote:One other thing i noticed is that if i have my first atom in a list of atoms at position (1,1,1) and try to draw a line from that atom to another the lines are shifted back to (0,0,0)... I have to subtract out the position of the first atom inorder to move the lines to their correct position.
A wild guess: you don't set the tranformation before you draw the lines... :lol:
use this before you draw the lines:

Code: Select all

      matrix4 tmat;
      pVideoDriver->setTransform(ETS_WORLD, tmat);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Using a manually rendered line mesh is probably far more efficient. Simply use the positions as vertex list and add each conincident vertex indices into the list (i.e. if node 5 and 8 are connected, add both 5 and 8 consecutively to the index list, assuming you start numbering at 0). Then call drawVertexPrimitiveList, which will draw all the lines in one call.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah you definetly will need to do some optimisations in terms of rendering if you're drawing lots of links and lots of atoms.

In IrrAI i was drawing waypoints as cube scene nodes and an individual call to draw3DLine for every waypoint that was linked together. Fine for small numbers of waypoints but as they grew the performance drop was pretty big. Now i have a meshbuffer which i add cubes to for the waypoints and add the links in as arrows drawn from 3 triangles and it works much much better! If you need any help with it i can send you my class which draws my waypoint graph.
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

JP wrote:In IrrAI i was drawing waypoints as cube scene nodes and an individual call to draw3DLine for every waypoint that was linked together. Fine for small numbers of waypoints but as they grew the performance drop was pretty big. Now i have a meshbuffer which i add cubes to for the waypoints and add the links in as arrows drawn from 3 triangles and it works much much better!
yes, something like this I had in mind... ;)
but isn't it strange, that drawing 3 triangles is more efficient than drawing 1 3dline !?!?! :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Is it? I didn't know it was... But it's definetly better to batch up all ya draw calls!

Maybe 3D lines are actually drawn as triangles or something.... In DX they can have thickness (or is it OGL.. or both?) so that's certainly something more fancy going on than a simple 3D line from one point to another with 2 verts!
Image Image Image
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Post by cp51 »

Hey all,

thanks for all your help. Ive been away from the comp for a few days doing some studying so i havent gotten around to trying out your suggestions yet, but thanks a lot, youve all been most helpful. Ill let you know how it goes and if i have any trouble.

Btw, i have around 3500 atoms and about 100,000 lines i believe in my last version, so any optimization is very useful.

Thanks again,
-CP51
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

When we use draw3DLine method to draw a line, can we change the line width?

Thanks,
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

humorstar wrote:When we use draw3DLine method to draw a line, can we change the line width?
no
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

In the help file, it says it supports some material's line thickness in some platform. I wonder what that is. What material is it?

If we cannot change the thickness, what is the get-around? Do we instead have to draw a cylinder and update its position, rotation and scale every time we want to draw it?

Thank you,
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Actually, you can change the line thickness, but you have to do it with SMaterial.Thickness;

Set the material for the driver before drawing the lines you'd like thicker.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Doesn't work for D3D, though, as it can only change point thickness :roll:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Dark_Kilauea wrote:Actually, you can change the line thickness, but you have to do it with SMaterial.Thickness;
no, it's only for 2d lines !!! ;)
f32 irr::video::SMaterial::Thickness
Thickness of non-3dimensional elements such as lines and points.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Works for 3D lines too though, in OGL only as hybrid points out.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

There's a bug report open about it. Does anyone fancy changing the D3D9 implementation to draw quads instead of lines? ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply