Search the Community
Showing results for tags 'lookrotation'.
-
Working on a CCD/Fabrik IK for skeleton, the main fonction used is to point in direction of a target (as position), already tryed joint that don't work with bones As i did see on https://www.leadwerks.com/community/topic/16360-quaternion-lookat/#comment-107368 ,AlignToVector i tryed to make it work but with weird things going on without any conclusive result " #include "Leadwerks.h" using namespace Leadwerks; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); auto world = CreateWorld(); auto camera = CreateCamera(world); camera->SetPosition(0, 2, -10); auto model = LoadModel(world, "https://github.com/Leadwerks/Documentation/raw/master/Assets/Models/Characters/Fox.glb"); model->SetScale(0.05); model->SetRotation(0, -90, 0); model->SetPosition(0, 0, 0); auto bone = model->skeleton->FindBone("b_Neck_04"); auto target = CreateBox(world); target->SetPosition(3, 0, 0); while (window->Closed() == false) { if (window->KeyHit(KEY_W)) { target->Move(0, 1, 0); } if (window->KeyHit(KEY_S)) { target->Move(0, -1, 0); } if (window->KeyHit(KEY_A)) { target->Move(-1, 0, 0); } if (window->KeyHit(KEY_D)) { target->Move(1, 0, 0); } world->Update(); Vec3 bonePos = bone->GetPosition(); Vec3 targetPos = target->GetPosition(); Vec3 direction = (targetPos - bonePos).Normalize(); bone->AlignToVector(direction, 2, 10.0f, 0.0f); world->Render(framebuffer); } return 0; } " In a book i got, they use a function called Quat lookRotation that is mainly used for IK Its implemented this way (for they own editor) " Quat lookRotation(const vec3& direction, const vec3& up) { // Find orthonormal basis vectors vec3 f = normalized(direction); //Object Forward vec3 u = normalized(up); //Desired Up vec3 r = cross(u, f); //Object Right u = cross(f, r); // Object Up // From world forward to object forward quat worldToObject = fromTo(vec3(0, 0, 1), f); //what direction is the new object up vec3 objectUp = worldToObject * vec3(0, 1, 0); // From object up to desired up quat u2u = fromTo(objectUp, u); // Rotate to forward direction first then twist to correct up quat result = worldToObject * u2u; " if that help or anybody has a int on how i could do it differently ?