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
Material&Picking
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
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?
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 !
@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 !
-
- Posts: 206
- Joined: Thu Sep 01, 2005 9:26 pm
- Location: France
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
This methods performs the nodepicking
[/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
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;
}
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!
-
- Posts: 370
- Joined: Mon Aug 29, 2005 10:54 pm
- Location: http://web.utk.edu/~pfox1