CollisionResponseAnimator probelm

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.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

CollisionResponseAnimator probelm

Post 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?
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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));
What now??? =_=''
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

tried and same
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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.
What now??? =_=''
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post 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.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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
What now??? =_=''
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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?
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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.
What now??? =_=''
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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?
What now??? =_=''
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

call OnRegisterSceneNode before the first loop?
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah this is because OnAnimate is where the updates are actually done to a node and this gets called during smgr->drawAll().
Image Image Image
happilylazy
Posts: 53
Joined: Sun Aug 31, 2008 3:16 pm
Location: Split, Croatia

Post 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.
What now??? =_=''
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Post 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.
Post Reply