draw3DLine problem

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.
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

draw3DLine problem

Post by Kaki »

Hello I try to draw a line. I use the draw3DLine functions.
I see in the forum there are many discussions about this function.
I don't see my line. I use Newton in my project.
My code is :

Code: Select all

matrix4 mat1; 
SMaterial material; 
material.Texture1 = 0; 
material.Lighting = false; 
driver->setTransform(ETS_WORLD, mat1); 
driver->setMaterial(material);	
core::line3d<f32> lineDir;
lineDir.start=vector3df(0.0f,50.0f,0.0f);
lineDir.end=vector3df(0.0f,100.0f,0.0f);
driver->draw3DLine(lineDir.start, lineDir.end, video::SColor(255, 255, 255, 255)); 

Code: Select all


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

Post by hybrid »

You have to put the draw3DLine call inside the main loop, because it does not create an object which is drawn all the time automatically, but only upon your request. So it would be drawn before the first screeen is shown, but with the first frame your line is lost.
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

Now I draw the line at each frame but I don't see it.

Maybe it's a color problem ? Or a size problem ? Can we decide the "radius" of the line ?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

No, you can't change the radius of a 3DLine !!!

try it like this:

Code: Select all

while(device->run()){
  driver->beginScene(true, true, SColor(255,100,100,150));
  smgr->drawAll();

  // here comes the 3DLine
  SMaterial mat;
  mat.Lighting = false;
  driver->setMaterial(mat);
  driver->setTransform(ETS_WORLD, matrix4());
  driver->draw3DLine(posStart, posEnd, col);

  guienv->drawAll();
  driver->endScene();
}
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

I do that but always nothing
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmmm, strange... :shock:
could you please post your main loop and the drawing function as they are now !?!?! :wink:
just guessing is always hard... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

Here my main loop (in CDemo.h)

Code: Select all

while(device->run() && driver)
	{
	if (device->isWindowActive())
	{
  	Move();
	if (debug)  
	    showCollision();

	matrix4 mat1; 
	SMaterial material; 
	material.Texture1 = 0; 
	material.Lighting = false; 
	driver->setTransform(ETS_WORLD, mat1); 
	driver->setMaterial(material);
	core::line3d<f32> lineDir;
	lineDir.start=vector3df(0.0f,50.0f,0.0f);
	lineDir.end=vector3df(0.0f,100.0f,0.0f);
	driver->draw3DLine(lineDir.start, lineDir.end, video::SColor(255, 255, 255, 255)); 

	if (device->getTimer()->getTime() > MyNewtonWorld->lasttick + 10) {	
	MyNewtonWorld->lasttick = device->getTimer()->getTime();
				NewtonUpdateMyNewtonWorld->nWorld, 0.01f);
	float pos[3];
	NewtonBodyGetVelocity(monCube->body,pos);
	}

	driver->beginScene(true, true, backColor);

	smgr->drawAll();
	guienv->drawAll();

	driver->endScene();
	swprintf(tmp, 255, L"%ls fps:%d", driver->getName(),	driver->getFPS());

	}
                }


The showCollision() function is yours.
Acky says :
just guessing is always hard...
I'm agree.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

driver->setTransform(ETS_WORLD, matrix4());
this is a 3D line - surely you need to set up world/view/projection matrices as per any other 3D object?
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

surely you need to set up world/view/projection matrices as per any other 3D object?
Sorry but my English is not very good. I don't understand your answer.

I do that before drawing.

Code: Select all

	nWorld = NewtonCreate(NULL, NULL);
	int i = NewtonMaterialGetDefaultGroupID(nWorld);
	NewtonMaterialSetDefaultFriction   (nWorld, i, i, 1.0f, 0.5f);
	NewtonMaterialSetDefaultElasticity (nWorld, i, i, 0.4f);
	NewtonMaterialSetDefaultSoftness   (nWorld, i, i, 0.05f);
	NewtonMaterialSetCollisionCallback (nWorld, i, i, NULL, NULL, NULL, NULL);
	lasttick = 0;

	g_newtonmap = NewtonCreateTreeCollision(nWorld, NULL);
	NewtonTreeCollisionBeginBuild(g_newtonmap);

	int cMeshBuffer, j;
	int v1i, v2i, v3i;
	IMeshBuffer *mb;

	float vArray[9]; // vertex array (3*3 floats)

	int tmpCount = 0;

	for (cMeshBuffer=0; cMeshBuffer< mymeshSol->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
	{	
		mb = mymeshSol->getMesh(0)->getMeshBuffer(cMeshBuffer);

		video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();

		u16* mb_indices  = mb->getIndices();

		// add each triangle from the mesh
		for (j=0; j<mb->getIndexCount(); j+=3)
		{
			v1i = mb_indices[j];
			v2i = mb_indices[j+1];
			v3i = mb_indices[j+2];
	
			vArray[0] = mb_vertices[v1i].Pos.X;
			vArray[1] = mb_vertices[v1i].Pos.Y;
			vArray[2] = mb_vertices[v1i].Pos.Z;
			vArray[3] = mb_vertices[v2i].Pos.X;
			vArray[4] = mb_vertices[v2i].Pos.Y;
			vArray[5] = mb_vertices[v2i].Pos.Z;
			vArray[6] = mb_vertices[v3i].Pos.X;
			vArray[7] = mb_vertices[v3i].Pos.Y;
			vArray[8] = mb_vertices[v3i].Pos.Z;

			NewtonTreeCollisionAddFace(g_newtonmap, 3, (float*)vArray, 12, 1);
		}

	}
	NewtonTreeCollisionEndBuild(g_newtonmap, 1);
	g_newtonmapbody = NewtonCreateBody(nWorld, g_newtonmap);

	float boxP0[3]; 
	float boxP1[3]; 
	float matrix[4][4]; 
	NewtonBodyGetMatrix (g_newtonmapbody, &matrix[0][0]); 
	NewtonCollisionCalculateAABB (g_newtonmap, &matrix[0][0],  &boxP0[0], &boxP1[0]); 
	// you can pad the box here if you wish
	//boxP0.y -= somevalue; 
	//boxP1.y += somevaluef; 
	boxP0[1] -= 50; 
    boxP1[1] += 50;
	NewtonSetWorldSize (nWorld, (float*)boxP0, (float*)boxP1);
maybe it's not what you say
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

Sorry I made an error. This reply is about :
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=18128
But the problem is certainly the same
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, the error is that you have to draw the line after beginScene(...) and before endScene() !!!

You draw it befor beginScene(...) !!!

it has to be like this (as I posted before, I thought you saw this):

Code: Select all

  beginScene(true, true, backColor); 
   smgr->drawAll();

  // draw the line after beginScene and befor endScene !!!
  driver->draw3DLine(lineDir.start, lineDir.end, video::SColor(255, 255, 255, 255)); 

  guienv->drawAll(); 
  driver->endScene(); 
sio2 wrote:this is a 3D line - surely you need to set up world/view/projection matrices as per any other 3D object?
AFAIK yes...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Post by Kaki »

Thanks for your help. All right.

It was beginner error :P
goaty
Posts: 46
Joined: Wed Oct 25, 2006 3:06 pm

Post by goaty »

You have to draw the line before the 'endscene' but after the 'drawall'
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

goaty wrote:You have to draw the line before the 'endscene' but after the 'drawall'
You're a little bit late... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
goaty
Posts: 46
Joined: Wed Oct 25, 2006 3:06 pm

Post by goaty »

Arrrrrrrrrr but with most, better late than never eh! :oops:
Post Reply