However, I cant do the same with the attached Bullet btBoxShape collision mesh. For example if I have my pivot point glm::vec3 rsPivot at (1.f, 0.f, 0.f) and scale (obviously it doesnt work here). I've tried various things but either the scale or the rotation don't both work at the same time.
How can I use a pivot point for scaling and rotation with bullet collision object (and preferably keep the GLM workflow I have ) ?
Code: Select all
void Object::render(glm::mat4 PV)
{
scaleM = glm::scale(glm::mat4(), s->val_3);
rotationM = glm::toMat4(r_quat);
translationM = glm::translate(glm::mat4(), t->val_3);
transLocal1M = glm::translate(glm::mat4(), -rsPivot->val_3);
transLocal2M = glm::translate(glm::mat4(), rsPivot->val_3);
MVP = PV * translationM * transLocal2M * rotationM * scaleM * transLocal1M;
}
void Object::autoBB() //called during a mesh update IE: changing scaleX value from gui
{
bbMin = bbMax = glm::vec3(0.f);
vector<glm::vec3> bbCheck;
if (type->val_s == "triDebug")
bbCheck = meshV;
for (int i = 0; i < bbCheck.size(); ++i)
{
if (bbCheck[i].x < bbMin.x)
bbMin.x = bbCheck[i].x;
if (bbCheck[i].y < bbMin.y)
bbMin.y = bbCheck[i].y;
if (bbCheck[i].z < bbMin.z)
bbMin.z = bbCheck[i].z;
if (bbCheck[i].x > bbMax.x)
bbMax.x = bbCheck[i].x;
if (bbCheck[i].y > bbMax.y)
bbMax.y = bbCheck[i].y;
if (bbCheck[i].z > bbMax.z)
bbMax.z = bbCheck[i].z;
}
bbCenter = .5f * (bbMin + bbMax);
bbSize = .5f * (bbMax - bbMin);
bbScaleM = glm::scale(glm::mat4(), s->val_3 * bbSize);
r_quat = glm::quat(glm::radians(r->val_3));
bbRotationM = glm::toMat4(r_quat);
bbTranslationM = glm::translate(glm::mat4(), t->val_3 + bbCenter);
bbMVP = bbTranslationM * bbRotationM * bbScaleM;
bbXform = mat4ToBullet(bbMVP); //btTransform !!!
for (int i = 0; i < myWin.myEtc->bulletDynW->getNumCollisionObjects(); ++i)
{
QString *bulletPtrName = static_cast<QString*>(myWin.myEtc->bulletDynW->getCollisionObjectArray()[i]->getUserPointer());
if (name->val_s == bulletPtrName)
myWin.myEtc->bulletDynW->getCollisionObjectArray()[i]->setWorldTransform(bbXform);
}
}
btTransform Object::mat4ToBullet(glm::mat4 transform)
{
const float* data = glm::value_ptr(transform);
btTransform bulletTransform;
bulletTransform.setFromOpenGLMatrix(data);
return bulletTransform;
}