Pick node

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
djoker
Posts: 39
Joined: Thu Dec 22, 2005 10:25 pm
Location: Portugal

Pick node

Post by djoker »

hi ppl i want to share this code from IRR4Delphi

Code: Select all


IRRFRAMEWORK_API bool Mesh_RayHitNodeTriangles (IAnimatedMeshSceneNode* Node,IAnimatedMesh* mesh,core::line3df Ray,core::vector3df &intersection)
{
int nMeshBuffer = 0; 
int v_index[3] = {0,0,0}; 
core::triangle3df triangle;
IMeshBuffer *mesh_buffer = NULL;
if (Node->getTransformedBoundingBox().intersectsWithLine(Ray))
{
int frame=(int)Node->getFrameNr();
IMesh* irr_mesh=mesh->getMesh(frame);
for( nMeshBuffer=0 ; nMeshBuffer < irr_mesh->getMeshBufferCount() ; nMeshBuffer++ )
{
mesh_buffer = irr_mesh->getMeshBuffer(nMeshBuffer);
S3DVertex *vertices = (S3DVertex*)mesh_buffer->getVertices();
u16 *indices = mesh_buffer->getIndices();
for(int i=0; i<mesh_buffer->getIndexCount()/3; i++)
{
v_index[0] = indices[i*3 ];
v_index[1] = indices[i*3+1];
v_index[2] = indices[i*3+2];
triangle.pointA=vertices[ v_index[0] ].Pos;
triangle.pointB=vertices[ v_index[1] ].Pos;
triangle.pointC=vertices[ v_index[2] ].Pos;
Node->getAbsoluteTransformation().transformVect(triangle.pointA);
Node->getAbsoluteTransformation().transformVect(triangle.pointB);
Node->getAbsoluteTransformation().transformVect(triangle.pointC);
if (triangle.getIntersectionWithLine(Ray.start,Ray.end,intersection))
 {
            driver->setTransform(video::ETS_WORLD, core::matrix4());
			material.Lighting=false;
			material.setTexture(0,0);
			driver->setMaterial(material);
		    driver->draw3DTriangle(triangle, video::SColor(255,255,0,0));
			return true;
  }
  }
 }
}
return false;
} 

Image
Image
Image
Image
Image
Image
Never underestimate the power of Delphi....Ignorance is bliss, but knowledge is power...
gbox
Posts: 37
Joined: Mon May 01, 2006 3:41 am
Location: jeonju, korea
Contact:

Post by gbox »

cool~
thanks :D
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

You may want to re-title this as "collision detection on an animated mesh".

Note that it (currently) won't work with the new skinned meshes, since getMesh(frame) is borked.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply