better collisions?

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
RadSun
Posts: 7
Joined: Thu Sep 14, 2006 5:58 am

better collisions?

Post by RadSun »

Hi
With the examples i created a simple model with 3rd camera. But the collisions are not very good. Model is blocking sometimes. and i hace two another problems but its easyer to show :roll:
Image

Code: Select all

scene::ISceneNodeAnimator * anim = smgr->createCollisionResponseAnimator(selector,hero, vector3df(25,25,25),core::vector3df(0,-1,0),core::vector3df(0,0,0));
hero->addAnimator(anim);
anim->drop();

Code: Select all

if (key_left==1)
		{ direction-=2; hero->setRotation(core::vector3df(0,direction,0));}
if (key_right==1)
		{ direction+=2; hero->setRotation(core::vector3df(0,direction,0));}
if (key_up==1)
		{
			core::vector3df v = hero->getPosition();
			v.X += sin(degtorad(dir))*5;
			v.Z += cos(degtorad(dir))*5;

			hero->setPosition(v);
		}
:?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

If you want a better collision you should use a good physics engine, like Newton !!! ;)

The collision system of Irrlicht is basic and not really good... :cry:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
RadSun
Posts: 7
Joined: Thu Sep 14, 2006 5:58 am

Post by RadSun »

Can you give me link to toutrial/example for Irrlicht&Newton? I found on site but its for Irrlict 0.6
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, I think you wont fine an up to date tutorial for Newton + Irrlicht, because Irrlicht is growing preaty fast with many changes... ;)

I think best would be to take an out of date tutorial and try to adapt it to the newer Irrlicht version... ;)

Their are other physics engines, too...
ODE, Tokamak and PhysX, for example...
But I prefere Newton, it is really versatile and has many features like ragdolls and cars, and you can define materials and such for each collision shape... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
RadSun
Posts: 7
Joined: Thu Sep 14, 2006 5:58 am

Post by RadSun »

I getting error :?

Code: Select all

e:\irrlicht-1.3.1\marshinto\game.cpp(92) : error C2248: 'irr::core::CMatrix4<T>::M' : cannot access private member declared in class 'irr::core::CMatrix4<T>'
        with
        [
            T=irr::f32
        ]
        e:\irrlicht-1.3.1\include\matrix4.h(275) : see declaration of 'irr::core::CMatrix4<T>::M'
        with
        [
            T=irr::f32
        ]
in this:

Code: Select all

void _cdecl CGame::SetMeshTransformEvent(const NewtonBody* body, const float* matrix)
{
	// copy the matrix into an irrlicht matrix4
	matrix4 mat;
	memcpy(mat.M, matrix, sizeof(float)*16);

	// Retreive the user data attached to the newton body
	ISceneNode *tmp = (ISceneNode *)NewtonBodyGetUserData(body);
	if (tmp)
	{
		// Position the node
		tmp->setPosition(mat.getTranslation());		// set position
		tmp->setRotation(mat.getRotationDegrees());	// and rotation
	}
}
Perceval
Posts: 158
Joined: Tue May 30, 2006 2:42 pm

Post by Perceval »

Replace mat.M by mat.pointer() ;)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

if you do what your compiler told you:

Code: Select all

see declaration of 'irr::core::CMatrix4<T>::M'
you'll see that matrix4 needs a template... ;)
this is since Irrlicht 1.3 !!!
I'm using Irrlicht v1.2 and there it's like you did...
So I'm not sure, but try it like this:

Code: Select all

matrix4<float> mat;
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, matrix4 is still a proper type for a float matrix4. CMatrix4 is the template. So it's still ok, just as before. Perceval is completely right.
RadSun
Posts: 7
Joined: Thu Sep 14, 2006 5:58 am

Post by RadSun »

Thanks, now its work. :wink:
But i have two warnings:

Code: Select all

e:\irrlicht-1.3.1\marshinto\game.cpp(44) : warning C4018: '<' : signed/unsigned mismatch
e:\irrlicht-1.3.1\marshinto\game.cpp(52) : warning C4018: '<' : signed/unsigned mismatch
in this:

Code: Select all

for (cMeshBuffer=0; cMeshBuffer<g_map->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)

Code: Select all

for (j=0; j<mb->getIndexCount(); j+=3)
It compile and run but than it show error "Unhandled exception..." :(
RadSun
Posts: 7
Joined: Thu Sep 14, 2006 5:58 am

Post by RadSun »

This is code from toutrial for Newton&irrlicht v.6. Do soeone now how to make its work in 1.3.1??

Code: Select all

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<g_map->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
	{	
		mb = g_map->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, 0);
	g_newtonmapbody = NewtonCreateBody(nWorld, g_newtonmap);
:?:
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Not all mesh buffers use the 2TCoords vertex type. The following _should_ work a little better. I'm not absolutely sure it will compile because I don't have a compiler on this PC and I don't use Newton.

Travis

Code: Select all

template <typename VertexType, typename IndexType>
void CreateCollisionTree_AddFaces(NewtonCollision* tree, const scene::IMeshBuffer* const mb)
{
    const VertexType* const vertices = (const VertexType*)mb->getVertices();
    const IndexType * const indices  = (const IndexType *)mb->getIndices(); 

    u32 j;
    for (j = 0; j < mb->getIndexCount(); j += 3) 
    { 
      const IndexType i1 = indices[j+0]; 
      const IndexType i2 = indices[j+1]; 
      const IndexType i3 = indices[j+2];

      f32 floats[9];
    
      floats[0] = vertices[i1].Pos.X; 
      floats[1] = vertices[i1].Pos.Y; 
      floats[2] = vertices[i1].Pos.Z; 

      floats[3] = vertices[i2].Pos.X; 
      floats[4] = vertices[i2].Pos.Y; 
      floats[5] = vertices[i2].Pos.Z;
 
      floats[6] = vertices[i3].Pos.X; 
      floats[7] = vertices[i3].Pos.Y; 
      floats[8] = vertices[i3].Pos.Z; 

      NewtonTreeCollisionAddFace(tree, 3, floats, 3 * sizeof(f32), 1); 
   }
}

NewtonCollision* CreateCollisionTree(NewtonWorld* nWorld, const scene::IMesh* const mesh) 
{
   NewtonCollision* tree = NewtonCreateTreeCollision(nWorld, NULL); 
   NewtonTreeCollisionBeginBuild(tree); 

   u32 j;
   for (j = 0; j < mesh->getMeshBufferCount(); ++j) 
   {    
      const scene::IMeshBuffer* const mb = mesh->getMeshBuffer(j);

      switch (mb->getVertexType())
      {
      case video::EVT_STANDARD:
        CreateCollisionTree_AddFaces<video::S3DVertex, u16>(tree, mb);
        break;
      case video::EVT_2TCOORDS:
        CreateCollisionTree_AddFaces<video::S3DVertex2TCoords, u16>(tree, mb);
        break;
      case video::EVT_TANGENTS:
        CreateCollisionTree_AddFaces<video::S3DVertexTangents, u16>(tree, mb);
        break;
      default:
        // unexpected vertex type!
        break;
      }
   } 

   NewtonTreeCollisionEndBuild(tree, 1);

   return tree;
}
Post Reply