once a mesh has been loaded in , you are given its position and normals, i was wondering without using a shader , can you randomly get a position and it will give you its normal for that position
in doing a particle system , and would like to use a mesh for the shape of the emiotter , and would like a , my program to get a random position and normal , for the particls start point and verlosity?
is there a way to pic a random position and normal in a mesh?
You can make pick a random position by first picking a random triangle in the mesh, where the probability of each triangle is proportional to its area. Now you pick a random point in the triangle. Interpolate -say, using barycentric coordinates- between the normals at the vertices of the triangle to obtain the normal at your point.
Is that what you were looking for?
Is that what you were looking for?
You can make pick a random position by first picking a random triangle in the mesh, where the probability of each triangle is proportional to its area. Now you pick a random point in the triangle. Interpolate -say, using barycentric coordinates- between the normals at the vertices of the triangle to obtain the normal at your point.
Is that what you were looking for?
thats what i need , just cant figure out how to do it, ie access the mesh data to get at it. there put into the vertex buffer, and can get the number of vertx but how do you pull out the information form there, in c++
When the mesh is loaded from a file, you'll see it contains vertex and index data.
It's most likely that the index data is formatted as a triangle strip.
i.e: 0,1,2 makes a triangle (0,1,2), then 3, makes the triangle (1,2,3) and so on...
With this, you'll be able to work out which vertices are used to make which triangles, by accessing the vertex list using the index values...
If you want to choose random triangles, you can select random indices, and just use the previous (or next) 2 indices in the index array to form a triangle of 3 vertices.
With this triangle you can calculate the position by adding the positions of the vertices together and dividing by three.
(Note, this will be in local space - instead of world space - you'll need to multiply this by the worldmatrix to make it world space)
To get the normal, assuming you want the face normal, you can calculate this by taking the normalized vector from vertex A -> vertex B, and performing the cross product of this with the normalized vector from vertex B -> vertex C. (Note, you may need to flip the order for the cross product to make sure it faces the right way. )
You'll also need to multiply this normal vector by the world matrix to transform it into worldspace.
This should give you a random triangle's position and normal.
Hope this helps.
It's most likely that the index data is formatted as a triangle strip.
i.e: 0,1,2 makes a triangle (0,1,2), then 3, makes the triangle (1,2,3) and so on...
With this, you'll be able to work out which vertices are used to make which triangles, by accessing the vertex list using the index values...
If you want to choose random triangles, you can select random indices, and just use the previous (or next) 2 indices in the index array to form a triangle of 3 vertices.
With this triangle you can calculate the position by adding the positions of the vertices together and dividing by three.
(Note, this will be in local space - instead of world space - you'll need to multiply this by the worldmatrix to make it world space)
To get the normal, assuming you want the face normal, you can calculate this by taking the normalized vector from vertex A -> vertex B, and performing the cross product of this with the normalized vector from vertex B -> vertex C. (Note, you may need to flip the order for the cross product to make sure it faces the right way. )
You'll also need to multiply this normal vector by the world matrix to transform it into worldspace.
This should give you a random triangle's position and normal.
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement