Page 1 of 2

CollisionResponseAnimator probelm

Posted: Sat Sep 06, 2008 12:57 pm
by B@z
Hi!
i have a problem with createCollisionResponse animator.
it works cool, collisioning, and eveything, it's inaccurate.
i mean, too high.

using that code:

Code: Select all

	aabbox3d<f32> bbox = node->getTransformedBoundingBox();
	ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta,node,
		bbox.MaxEdge - bbox.getCenter(),vector3df(0,-1,0),vector3df(0,0,0),0.0005f);
and here is a pic:
http://dotdotdot.extra.hu/FTP/bboxerror.JPG

as you can see, my model is flying. but it isn't the problem of my model, as you can see, my bouning box is correct.
I'm using bsp map.

if i make that:

Code: Select all

	aabbox3d<f32> bbox = node->getTransformedBoundingBox();
	ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta,node,
		bbox.MaxEdge - bbox.getCenter(),vector3df(0,-1,0),vector3df(0,-bbox.MaxEdge.Y/2,0),0.0005f);
it works cool, but not every model... and i think it isn't a sollution.
what's the problem?

Posted: Sat Sep 06, 2008 2:24 pm
by happilylazy
Have you tried default use of "createCollisionResponseAnimator" function and what are the results then.

Code: Select all

aabbox3d<f32> bbox = node->getTransformedBoundingBox();
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta,node, bbox.MaxEdge - bbox.getCenter(),vector3df(0,-1,0));

Posted: Sat Sep 06, 2008 2:35 pm
by B@z
tried and same

Posted: Sat Sep 06, 2008 4:16 pm
by happilylazy
Then try using the normal bounding box (it is OK, at least you said it)

Code: Select all

aabbox3d<f32> bbox = node->getBoundingBox(); 
if the error still is there, maybe something wrong with the 3d model, out of ideas.

Posted: Sat Sep 06, 2008 6:44 pm
by Dark_Kilauea
keep in mind, the collision animator's ellipse for calculating collision begins at the top. That is to say, that the position of the ellipse is not in the center, like most other scenenodes, but at the very top point of the ellipse.

You need to translate the ellipse upwards half of your bounding box. The collision example does cover this briefly.

Posted: Sat Sep 06, 2008 8:37 pm
by B@z
happilylazy: yeah, tried that, same

Dark_Kilauea: but my problem is that not every character does that.
which i don't have problem, that wont work cool, if i change the translation.
if you read my post, i did that ^^b

Posted: Sun Sep 14, 2008 11:28 am
by happilylazy
I made some model also in .3ds and run in the same problem.
Radius for my CollisionResponseAnimator is stuck to 47 all the time, so he calculates with that value no matter how I rescale my model (how big the bounding box really is).
So if you got the solution to this problem I would like to know it too.

Code: Select all

IAnimatedMesh* npcMesh = smgr->getMesh("./data/beduin_v0_1.3DS");
IAnimatedMeshSceneNode* npc = smgr->addAnimatedMeshSceneNode(npcMesh);

const aabbox3d<f32>& box = npc->getTransformedBoundingBox();
vector3df radius = box.MaxEdge - box.getCenter();
No matter the scale or the size of the model and his bounding box, this value is 47, uh... frustrating

p.s. also the box is the same no matter the scale or the size of the model

Posted: Sun Sep 14, 2008 3:33 pm
by B@z
srry, i dont have sollution either

using that code:

Code: Select all


   aabbox3d<f32> bbox = node->getTransformedBoundingBox();
   ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta,node,
      bbox.MaxEdge - bbox.getCenter(),vector3df(0,-1,0),vector3df(0,-bbox.MaxEdge.Y/2,0),0.0005f); 
but dont think it solve your problem.

how did you scale the model? within the 3d editor, or in the irrlicht?
and did you try it with other file format?

Posted: Sun Sep 14, 2008 10:10 pm
by happilylazy
I scaled it in IrrLicht, calld setScale on my IAnimatedMeshSceneNode* npc but even with that radius stays the same, but the model is much smaller, and after I draw the bounding box of a model it fits perfectly, ah...

I'll try with different type now ... back to the drawing board.

Posted: Sun Sep 14, 2008 11:04 pm
by happilylazy
:evil:
Ok! After one device->run() the bounding box refits itself perfectly.
But before and during the first run trough the while the bounding box is totally wrong.

That's why you're drawn bounding box is perfect but collisions are badly calculated, because it calculates with the wrong one (because you create collision calculator before the first device->run() loop) and after the first loop it draws the perfect one.

Try catching image of the bounding box during or before the FIRST while loop, you'll see what I'm talking about.

So here's the question to everybody, is there a way to manualy order rifiting or recalculation of the bounding box so we have the correct one before few while loops?

Posted: Mon Sep 15, 2008 6:24 am
by Dark_Kilauea
call OnRegisterSceneNode before the first loop?

Posted: Mon Sep 15, 2008 7:41 am
by B@z
hi!
there is a function, called recalculateBoundingBox()
node->getMesh()->getMesh(0)->recalculateBoundingBox();

i made before a function, to recalculate the box not to the 0 frame, but to the first frame.
but you can change it easily xD

Code: Select all

IAnimatedMeshSceneNode* Characters::RepairBoundingBox(IAnimatedMeshSceneNode* node)
{
	IAnimatedMesh * mesh = node->getMesh();
		
	aabbox3df box;
	for (u32 i = 0; i < mesh->getMeshBufferCount(); i++)
	{
		mesh->getMesh(1)->getMeshBuffer(i)->recalculateBoundingBox();
		box.addInternalBox(mesh->getMesh(1)->getMeshBuffer(i)->getBoundingBox());
	}
	mesh->setBoundingBox(box);
	node->setMesh(mesh);
	return node;
}
just change the getMesh(1) to getMesh(0) if you wanna make it like the model, not the first frame
(for me the first frame was better, because, in the simple model, my model had extended her hand, so the collision would be very innacurate :D)

Posted: Mon Sep 15, 2008 8:26 am
by JP
Yeah this is because OnAnimate is where the updates are actually done to a node and this gets called during smgr->drawAll().

Posted: Mon Sep 15, 2008 8:52 pm
by happilylazy
Unfortunately both solutions didn't help.

I called OnRegisterSceneNode before seting collision data and first loop, and used the RepairBoundingBox method, but no cigar.

Damn.

Posted: Tue Sep 16, 2008 7:43 am
by kornwaretm
check in irrEdit see if the boundingbox is corect. i'm using blender and when exporting if i activate flip z and swap y-z option, then bounding box will stay untransform (if i'm not mistaken) and can't be fixed using recalculateBoundingBox(). try to re-export your model without such an option activated of course if they are exist. sorry for being faith based.