Material&Picking

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
s0rcer0r
Posts: 11
Joined: Wed Nov 03, 2004 10:48 pm
Location: Bucharest

Material&Picking

Post by s0rcer0r »

Hi all !

I will start very soon working on a project which will use Irrlicht and I have some questions regarding Material and Picking.

Material :
1. I want at the moment when I select an object to draw a wireframe coloured outline of the object. Using OpenGL i can do this by using glPolygonMode() with GL_LINE.
In Irrlicht I saw that you can only set the EMF_WIREFRAME either to 0 or 1, obtaining a wireframed object or a solid one.
Is there any way in which I can obtain a selection effect as the one described above ?
2. Is there any way to draw only/or the points where the vertices are ? (in OpenGL I would use GL_POINT to draw them)
There is no material type of flag as far as I know to do this.

Picking:
1. Looking at the collision tutorial I must say that the node picking wasn't working very accurately...in the documentation it's saying that it uses a bounding box for each scene node...is there a way to do something similar to the OpenGL selection mechanism that uses a selection buffer and special render mode for this ?
Also is there possible to do a vertex selection with Irrlicht (and then drawing a point if a vertex was picked...this is related to the material questions above)...in OpenGL it's easy enough to do this by using the OpenGL Feedback mode.

As you can see you can do all this things if you work directly with the OpenGL lib but I would be glad to do all this dirrectly with the Irrlicht API because it's such a great engine already and because I want to work as clean as I can and possibly without modifying the Irrlicht source code !

Thanks for your time
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Well, although I am not extremely versed in materials, I dont believe you can set two material flags that conflict with each other.

Why not render two meshes and add a transparency to the solid one?

-----
Sorry I cannot answer any of the other questions.
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

take a look at the wiki irrforge.org for an example of mixing opengl with irrlicht. The beginscene and endscene in irrlicht correspond to the similar commands in OPENGL , and you can issue opengl commands right in between them. It sounds like you've used opengl so why reinvent the wheel when you can steel it? :lol:
Guest

Post by Guest »

Thank you for your answers !

@krama757
Well...that was exactly my point that you can't somehow mix EMF_WIREFRAME with something else...that would be an interesting option !
Duplicating the mesh is not an option due to efficency reasons :( If I have let's say a 10k poly mesh I really don't want to render it again only for the selection effect :)
Looking again through the API maybe there is a solution getting somehow the mesh triangles and using draw3DTriangle() where I can also provide the colour for the selection...but again I'm wondering how efficient this is...so...I'm still open for suggestions !

@dhenton9000
I will look at the wiki, but as I said I would like to work as clean as I can and using only the engine (the Irrlicht API) because I don't want to have problems in the later stages of the development and with the integration with the new releases of Irrlicht.
Indeed it would be a solution to use OpenGL dirrectly but I don't know yet how fine it will work with engine itself(I don't want to use only the OpenGL mode of the engine)...right now I think that it would be better to add/extend the engine than to do OpenGL calls.
Still waiting for other suggestions though !
s0rcer0r
Posts: 11
Joined: Wed Nov 03, 2004 10:48 pm
Location: Bucharest

Post by s0rcer0r »

Sry...it was me above...but somehow I wasn't logged !
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

I'm developing a nav graph editor for my project. I notidec that node picking using bb is really not accurate..... so I'm interested in alternate methods too.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Snake
Posts: 9
Joined: Sun Jan 08, 2006 2:15 am

Post by Snake »

About picking:
BB node picking is quite unaccurate. Then you must consider that any node in the scene will be picked up, unless you use a bitmask to filter nodes that you don't want to pick.
I use this very simple algotrithm, wich is quite accurate:

Entity is a wrapper class for a game object. it has a ->getSceneNode() method to retirieve its IrrlichtScene node.
Ambient is the class representing the current game scene. It has a protected ISceneNode *levelMesh wich is the static mesh of the "level", and a vector of entities wich are cointained in the scene. (the ones I want to be "sensible" to node picking)

First of all, this simple method returns if the line of sight intersects the level mesh. The line is a simple line starting from the player point of view and pointiing forward. If you use a cam as point of view, you can obtain the line with this:

line.start=camera->getAbsolutePosition();
line.end=line.start + (camera.getTarget() - line.start).normalize() * length;

where length is how far you want to reach

Code: Select all

bool Ambient::getIntersection(line3d<f32> line, vector3df &intersection)
{
	triangle3df tri;
	ISceneCollisionManager *cm=sceneManager->getSceneCollisionManager();
	bool returnValue = cm->getCollisionPoint(linea, levelMesh->getTriangleSelector(), intersection, tri);
	return returnValue;
}


This methods performs the nodepicking

Code: Select all

Entity* Ambient::getEntity(line3d<f32> sightLine, vector3df &intersection)
{
	unsigned int t;  // just a counter
	double distance, shortestDistance=-1;
	triangle3df tri;  // triangle used for collision method
	Entity *erv=0;     // return value of the function

	ISceneCollisionManager* cm  = sceneManager()->getSceneCollisionManager();


/* if I get an intersection with the ambient mesh (using the method shown above), I store the distance in the shortestDistance. This prevents the algorithm to pick an entity wich lays behind a "wall" or something */
	if (getIntersection(sightLine,intersection))
		shortestDistance=sightLine.start.getDistanceFrom(intersection);

	/* the Ambient class has a vector where it stores pointers to all the game entities in the scene. We just scan the list looking for entities colliding with the sight line */
 	for (t=0;t<entityVector.size();t++)
	{
		Entity *entity=entityVector[t];

// if the line intersects this entity
		if (cm->getCollisionPoint(sightLine, en->getSceneNode()->getTriangleSelector(), intersection, tri))
		{
// we get the distance from the starting point of the sight line
			distance = sightLine.start.getDistanceFrom(intersection);

// then, if the distance is lesser than the shortestDistance (or we don't have a shortest distance yet)
			if (shortestDistance==-1 || distance < shortestDistance) 
			{
				shorterDistance=distance;
// this entity is the candidate for the return value
				erv=entity;
			}
		}

// then we proceed on scanning, to look if there are nearest entities
	}

// and finally we return the entity found (if we found one)
	return erv; 
}
[/code]

In this way I test only the scene nodes I want (the ones in the vector). Besides, if a "wall" is between the point of view and a game entity, this will not be selected. The cost of the method is linear, proportional to the number of entities you have in the entity vector.

Hope it helps :)
La vita è una tempesta, prenderlo nel culo è un lampo!
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

An option you could try would be to integrate a physics engine, most of them support picking. I have picking working with Newton, and it's pixel-perfect.
Post Reply