libGDX set rotation point 3D

后端 未结 1 1614
独厮守ぢ
独厮守ぢ 2021-01-13 12:57

I have two objects base and weapon and I need to set rotate point of weapon to position of base.

public Test(){
position1 = new Vector3(0,0,0);
baseModel = m         


        
相关标签:
1条回答
  • 2021-01-13 13:31

    A rotation around a point is the same as translating to that point, rotating and then translating back.
    So this process consists of 3 steps:

    1. Translate to the rotationPoint, for example translate(3, 0, 0)
    2. Rotate arround the center (which is now the rotationPoint), for example rotate(0,1,0, 45*delta)
    3. Translate back (the translation is relative to the rotation), for example translate(-3, 0, 0);

    In this case the code then looks like this:

    weapon.transform.translate(3, 0, 0).rotate(0,1,0, 45*delta).translate(-3, 0, 0); 
    
    0 讨论(0)
提交回复
热议问题