draw3DLine

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.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

draw3DLine

Post by Bate »

Can someone tell me why the 3DLine is always black, no matter what I use for SColor?

Code: Select all

  driver->beginScene(true, true, SColor(255,0,0,0));
    smgr->drawAll();

	driver->draw3DLine(vector3df(0,0,-50), vector3df(0,0,-100), SColor(255,255,0,0));

    guienv->drawAll();
  driver->endScene();
Is there maybe a better way to create 3d lines? Because I don't know how to manage (switch on/off) several lines inside the main loop. Also, I need to draw lines on a circular path and right now I have no idea how to realize that. :oops:

thanks in advance
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: draw3DLine

Post by Seven »

Bate wrote:Can someone tell me why the 3DLine is always black, no matter what I use for SColor?

Code: Select all

  driver->beginScene(true, true, SColor(255,0,0,0));
    smgr->drawAll();

	driver->draw3DLine(vector3df(0,0,-50), vector3df(0,0,-100), SColor(255,255,0,0));

    guienv->drawAll();
  driver->endScene();
Is there maybe a better way to create 3d lines? Because I don't know how to manage (switch on/off) several lines inside the main loop. Also, I need to draw lines on a circular path and right now I have no idea how to realize that. :oops:

thanks in advance

Code: Select all

//! Draws a 3d line.
		/** For some implementations, this method simply calls
		drawIndexedTriangles for some triangles.
		Note that the line is drawn using the current transformation
		matrix and material. So if you need to draw the 3D line
		independently of the current transformation, use
		\code
		driver->setMaterial(unlitMaterial);
		driver->setTransform(video::ETS_WORLD, core::matrix4());
		\endcode
		for some properly set up material before drawing the line.
		Some drivers support line thickness set in the material.
		\param start Start of the 3d line.
		\param end End of the 3d line.
		\param color Color of the line. */
		virtual void draw3DLine(const core::vector3df& start,
			const core::vector3df& end, SColor color = SColor(255,255,255,255)) =0;
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

a search on the forums can do miracles !!! :roll:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=30076
you also will run into this problem with your code:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=29276
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Thanks guys.

I did a search, even more than one but the miracle here is if you find something useful.

However, I'm still not sure how to draw a 3d line on a circular path (or basically any curve). The math is rather easy but I don't see a good approach, should I use a BeamSceneNode and how could I modify it to go on a curve? The only thing I can think of is putting a lot of tiny beam "pieces" on the circle but that doesn't feel right.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I think the best way is to use a VertexPrimitiveList...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

ah cool, that looks promising.

with pType EPT_LINE_STRIP all vertices form a single connected line.

A question on parameters: vertices and indexList
"a pointer to array of vertices/indices"

how do I create these arrays and what are the types?

like this?

Code: Select all

irr::core::array<vector3df> arrayVertices[100];
irr::core::array<u32 /* OR s32 */> arrayIndices[100];
(I'm not home so can't test)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, vertices are S3DVertex or one of the other vertex types, index list is either u16 (the default) or u32 (for those platforms that support it, by using EIT_32BIT).
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

thanks but now I'm confused :)

S3DVertex(x,y,z,nx,ny,nz,c,tu,tv)
position, normal vector, color, texture coordinates

and i only have a position since I simply want to connect 3 coordinates with a (visible) line, let's say:
(0,0,0)
(0,1,0)
(1,2,0)

how do I make this work?

Code: Select all

irr::core::array<S3DVertex> arrayVertices[3];
arrayVertices[0] = S3DVertex(/* NO IDEA */);
arrayVertices[1] = S3DVertex(/* NO IDEA */);
arrayVertices[2] = S3DVertex(/* NO IDEA */);

irr::core::array<u16> arrayIndices[3];
arrayIndices[0] = 0;
arrayIndices[1] = 1;
arrayIndices[2] = 2;

// main loop
driver->drawVertexPrimitiveList(arrayVertices, 3, arrayIndices, 3, EVT_STANDARD, EPT_LINE_STRIP, EIT_16BIT);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

normals and texture coords are probably not really important for you. positions are those values you showed one post above, color is on your choice.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Bate wrote:like this?

Code: Select all

irr::core::array<vector3df> arrayVertices[100];
irr::core::array<u32 /* OR s32 */> arrayIndices[100];
no, beside what hybrid already told you, this two lines will create 200 arrays and not 2 arrays with 100 elements each !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Alright, I just tried to compile it but nothing works.

So how do I create one array with a number of elements or is it just dynamic?

Is this basically a correct creation and value assignment?

Code: Select all

irr::core::array<S3DVertex> arrayVertices;
arrayVertices[0] = S3DVertex(/* not working */);
arrayVertices[1] = S3DVertex(/* not working */);
arrayVertices[2] = S3DVertex(/* not working */);

irr::core::array<u16> arrayIndices;
arrayIndices[0] = 0;
arrayIndices[1] = 1;
arrayIndices[2] = 2;
Well, whatever I use for S3DVertex, it throws an error. No overloaded function accepts 3 (or 6 -- depending on what I used) arguments. Or it says cannot convert 'irr::core::vector3d<T>' to 'irr::video::S3DVertex' if I put in something like S3DVertex( vector3df(0,1,1) ).

That's really frustrating. Could someone of you guys please provide me with an example code; it's no more than 2or3 lines, so come on.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Bate wrote:Is this basically a correct creation and value assignment?

Code: Select all

irr::core::array<S3DVertex> arrayVertices;
arrayVertices[0] = S3DVertex(/* not working */);
arrayVertices[1] = S3DVertex(/* not working */);
arrayVertices[2] = S3DVertex(/* not working */);

irr::core::array<u16> arrayIndices;
arrayIndices[0] = 0;
arrayIndices[1] = 1;
arrayIndices[2] = 2;
no, it isn't !!! :roll:
the arrays have a size of 0 elements so you can't assign the values like that...

well, you have 2 choices:
1st with Irr arrays:

Code: Select all

irr::core::array<S3DVertex> arrayVertices;
arrayVertices.push_back(S3DVertex(p1x, p1y, p1z, 0,0,0, SColor(255, 255,0,0),0,0));
arrayVertices.push_back(S3DVertex(p2x, p2y, p2z, 0,0,0, SColor(255, 255,0,0),0,0));
arrayVertices.push_back(S3DVertex(p3x, p3y, p3z, 0,0,0, SColor(255, 255,0,0),0,0));

irr::core::array<u16> arrayIndices;
arrayIndices.push_back(0);
arrayIndices.push_back(1);
arrayIndices.push_back(2);
or 2nd with normal arrays:

Code: Select all

S3DVertex arrayVertices[3];
arrayVertices[0] = S3DVertex(p1x, p1y, p1z, 0,0,0, SColor(255, 255,0,0),0,0);
arrayVertices[1] = S3DVertex(p2x, p2y, p2z, 0,0,0, SColor(255, 255,0,0),0,0);
arrayVertices[2] = S3DVertex(p3x, p3y, p3z, 0,0,0, SColor(255, 255,0,0),0,0);

u16 arrayIndices[3];
arrayIndices[0] = 0;
arrayIndices[1] = 1;
arrayIndices[2] = 2;
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Yaye it finally works :)

thanks a lot Acki.



Here's the full example in case someone needs something similar:

Code: Select all

S3DVertex arrayVertices[3];
arrayVertices[0] = S3DVertex(0, 0, -100, 0,0,0, SColor(255, 255,0,0),0,0);
arrayVertices[1] = S3DVertex(0, 50, -85, 0,0,0, SColor(255, 255,0,0),0,0);
arrayVertices[2] = S3DVertex(25, 0, -75, 0,0,0, SColor(255, 255,0,0),0,0);

u16 arrayIndices[3];
arrayIndices[0] = 0;
arrayIndices[1] = 1;
arrayIndices[2] = 2;

// Use Material Color since SColor in S3DVertex doesn't do anything
SMaterial mt;
mt.AmbientColor = mt.DiffuseColor = mt.EmissiveColor = SColor(255, 255, 0, 0);
driver->setMaterial(mt);

// Main Loop
driver->drawVertexPrimitiveList(arrayVertices, 3, arrayIndices, 3, EVT_STANDARD, EPT_LINE_STRIP, EIT_16BIT);
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

maybe this thread is of interest for you:
http://irrlicht.sourceforge.net/phpBB2/ ... p?p=211035
I first thought it was you... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

nice, thats gonna save a lot of time :)
Post Reply