Jump to content
  • Advertisement
Sign in to follow this  
mrMatrix

Dynamic AABB with bone animation ?

This topic is 584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble with generating an AABB for an object with multiple bones that animate. I used a pre-calculated local space bounding box for each bone that I transform at render time with the per-frame bone matrix to get dynamic bounding box movement. 
 
To get a static AABB in the bind pose I just do a min/max check like this, with bbSkelAll being a vertex with that has a greater than zero influence for the bone.
 
glm::vec3 aabbMin = (obj->bbSkelAll.empty()) ? glm::vec3(0.f) : obj->bbSkelAll[0].min;
glm::vec3 aabbMax = (obj->bbSkelAll.empty()) ? glm::vec3(0.f) : obj->bbSkelAll[0].max;


for (auto &i : obj->bbSkelAll)
{
aabbMin = glm::min(i.min, aabbMin);
aabbMax = glm::max(i.max, aabbMax);
}


glm::vec3 aabbSize = aabbMax - aabbMin;
glm::vec3 aabbCenter = .5f * (aabbMin + aabbMax);
obj->aabbMVP = glm::translate(glm::mat4(), aabbCenter) * glm::scale(glm::mat4(), aabbSize);
 
This works for a static pose, but I want a dynamic AABB that translates and scales. The bounding boxes for the bones are at different rotations now so I have to loop through them, but I cant conceptualize what space I should be in or how to get the bones' world space positions given that I only have their pre-calculated local BB and per-frame bone matrix. Any help would be appreciated. This video and image shows what I'm talking about
 
2554aj5.jpg
 

Share this post


Link to post
Share on other sites
Advertisement

Got it working by multiplying each skeleton BB vector by the bone animation matrix and then doing min/max

 

glUseProgram2("pBB", myAbj);


for (auto &i : myAbj.frustumObjs)
{
if (i->bb->val_b)
{
i->aabbV4.clear();


for (auto &j : i->bbSkelAll)
{
for (auto &k : i->aiGbones)
{
if (k.name == j.name)
{
i->obbMVP = glm::transpose(k.animatedXform) * j.obbMVP;

////////
//AABB - STEP 1 - GATHER / STORE
///////

//gather objects' transformed bone oobb
glm::vec4 bbSkelXformMin = glm::transpose(k.animatedXform) * glm::vec4(j.min, 1.f);
glm::vec4 bbSkelXformMax = glm::transpose(k.animatedXform) * glm::vec4(j.max, 1.f);
i->aabbV4.push_back(bbSkelXformMin);
i->aabbV4.push_back(bbSkelXformMax);


//break;
}
}


i->mvpGet();
i->render();
}
}
}


////////
//AABB - STEP 2 - MIN / MAX
///////
for (auto &i : myAbj.frustumObjs)
{
if (i->bb->val_b)
{
glm::vec4 aabbMin = (i->aabbV4.empty()) ? glm::vec4(0.f) : i->aabbV4[0];
glm::vec4 aabbMax = (i->aabbV4.empty()) ? glm::vec4(0.f) : i->aabbV4[0];


for (uint j = 0; j < i->aabbV4.size(); ++j)
{
aabbMin = glm::min(i->aabbV4[j], aabbMin);
aabbMax = glm::max(i->aabbV4[j], aabbMax);
}


glm::vec3 aabbSize = aabbMax - aabbMin;
glm::vec3 aabbCenter = .5f * (aabbMin + aabbMax);
i->aabbMVP = glm::translate(glm::mat4(), aabbCenter) * glm::scale(glm::mat4(), aabbSize);
i->obbMVP = glm::translate(glm::mat4(), aabbCenter) * glm::scale(glm::mat4(), aabbSize);
//i->obbMVP = i->aabbMVP;


i->aabbTgl = 1;
i->mvpGet();
i->render();
i->aabbTgl = 0;
}


}

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!