Page 1 of 2

draw3DLine problem

Posted: Fri Dec 29, 2006 2:19 pm
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

Posted: Fri Dec 29, 2006 4:43 pm
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.

Posted: Fri Dec 29, 2006 9:40 pm
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 ?

Posted: Fri Dec 29, 2006 10:17 pm
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();
}

Posted: Fri Dec 29, 2006 11:07 pm
by Kaki
I do that but always nothing

Posted: Sat Dec 30, 2006 1:16 am
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:

Posted: Sat Dec 30, 2006 9:49 am
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.

Posted: Sat Dec 30, 2006 10:36 am
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?

Posted: Sat Dec 30, 2006 12:24 pm
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

Posted: Sat Dec 30, 2006 12:27 pm
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

Posted: Sat Dec 30, 2006 1:12 pm
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...

Posted: Sat Dec 30, 2006 11:57 pm
by Kaki
Thanks for your help. All right.

It was beginner error :P

Posted: Sun Dec 31, 2006 1:43 pm
by goaty
You have to draw the line before the 'endscene' but after the 'drawall'

Posted: Sun Dec 31, 2006 2:28 pm
by Acki
goaty wrote:You have to draw the line before the 'endscene' but after the 'drawall'
You're a little bit late... :lol:

Posted: Sun Dec 31, 2006 7:17 pm
by goaty
Arrrrrrrrrr but with most, better late than never eh! :oops: