0
\$\begingroup\$

I'm working on a 3d game in LibGDX, got help on here with my model rotation. Worked great. But now I'm dealing with the model's roll, and it's not behaving as expected. It's controlled by:

handPos.set(cam.position);
        handPos.add(forwardTemp.set(cam.direction).scl(2.5f));
        
        handInst.transform.setToRotation(Vector3.Z, cam.direction);
                
        handInst.transform.getRotation(handRot, true);
        handAngle = handRot.getRoll();
        
        camAngle = getCameraRotation();
        float h = (camAngle-handAngle);
        handInst.transform.rotate(Vector3.Z, h);
        
        
        handInst.transform.setTranslation(handPos);
        

Moving it works great, and I've had no difficulty getting my camera roll - I've made a method to do that. I have a label onscreen that shows current camAngle, and current handAngle. CamAngle looks right, but the handAngle doesn't match what I'm seeing, and so my math to keep hands stationary in the view isn't working. I've tried getting the yaw or pitch instead, in case the axes are messed up, but it isn't better.

I'm trying to keep the roll of the model in front of the camera to match the roll of the camera - so if you look around, your hands don't spin. Any ideas on what's wrong here?

Edit, here's my getCameraRotation method

public float getCameraRotation()
    {      
        Quaternion p = new Quaternion();
        cam.combined.getRotation(p);
        float cammy = p.getRoll(); 
        return cammy;
    }

The camera can look in full 3d space, controlled by touch gestures. When doing so, it rolls around. I'm fine with that, kinda like the effect, but I want to match the hands model in front of the camera to it. The number I get from this method seems to match visually what I'm seeing pretty well.

Edit again - had code trying to getYaw. I want getRoll, that was just there from me experimenting with different axes to fix the problem.

\$\endgroup\$
2
  • \$\begingroup\$ Can you show us your code for getCameraRotation? It's not obvious from this code what angle it's measuring. \$\endgroup\$
    – DMGregory
    Commented May 28, 2021 at 16:24
  • \$\begingroup\$ Added the getCameraRotation method. \$\endgroup\$ Commented May 28, 2021 at 17:42

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.