void VrmlNodeTransform::inverseTransform(Viewer *viewer) { VrmlNode *parentTransform = getParentTransform(); if (parentTransform) parentTransform->inverseTransform(viewer); // Build the inverse float trans[3] = { -d_translation.x(), -d_translation.y(), -d_translation.z() }; float rot[4] = { d_rotation.x(), d_rotation.y(), d_rotation.z(), -d_rotation.r() }; // Invert scale (1/x) float scale[3] = { d_scale.x(), d_scale.y(), d_scale.z() }; if (!FPZERO(scale[0])) scale[0] = 1.0f / scale[0]; if (!FPZERO(scale[1])) scale[1] = 1.0f / scale[1]; if (!FPZERO(scale[2])) scale[2] = 1.0f / scale[2]; // Apply transforms (this may need to be broken into separate // calls to perform the ops in reverse order...) viewer->setTransform(d_center.get(), rot, scale, d_scaleOrientation.get(), trans, true); }
void VrmlNodeTransform::inverseTransform(double *m) { VrmlNode *parentTransform = getParentTransform(); if (strncmp(name(), "StaticCave", 10) == 0) { Midentity(m); } else { if (parentTransform) { parentTransform->inverseTransform(m); } else Midentity(m); } // Invert this transform float rot[4] = { d_rotation.x(), d_rotation.y(), d_rotation.z(), -d_rotation.r() }; float nsrot[4] = { d_scaleOrientation.x(), d_scaleOrientation.y(), d_scaleOrientation.z(), -d_scaleOrientation.r() }; float srot[4] = { d_scaleOrientation.x(), d_scaleOrientation.y(), d_scaleOrientation.z(), d_scaleOrientation.r() }; float trans[3] = { (-d_translation.x()), (-d_translation.y()), (-d_translation.z()) }; float center[3] = { (d_center.x()), (d_center.y()), (d_center.z()) }; float ncenter[3] = { (-d_center.x()), (-d_center.y()), (-d_center.z()) }; double M[16]; Mtrans(M, trans); MM(m, M); Mtrans(M, ncenter); MM(m, M); // Invert scale (1/x) float scale[3] = { d_scale.x(), d_scale.y(), d_scale.z() }; if (!FPZERO(scale[0])) scale[0] = 1.0f / scale[0]; if (!FPZERO(scale[1])) scale[1] = 1.0f / scale[1]; if (!FPZERO(scale[2])) scale[2] = 1.0f / scale[2]; Mrotation(M, rot); MM(m, M); if (!FPEQUAL(scale[0], 1.0) || !FPEQUAL(scale[1], 1.0) || !FPEQUAL(scale[2], 1.0)) { //fprintf(stderr, "invTr: scale\n"); if (!FPZERO(srot[3])) { //fprintf(stderr, "invTr: rot\n"); Mrotation(M, nsrot); MM(m, M); Mscale(M, scale); MM(m, M); Mrotation(M, srot); MM(m, M); } else { Mscale(M, scale); MM(m, M); } } Mtrans(M, center); MM(m, M); }