Animation Libgdx-Tween引擎的不直接模型旋转值

Animation Libgdx-Tween引擎的不直接模型旋转值,animation,3d,rotation,libgdx,tween,Animation,3d,Rotation,Libgdx,Tween,我正在尝试使用libgdx中的通用tween引擎旋转一个三维模型实例。这是我的屏幕课程: public class WallpaperScreen implements Screen { private PerspectiveCamera camera; private ModelBatch modelBatch; private Model modelBody, modelHead; private ModelInstance bodyModelInstance, headModelInst

我正在尝试使用libgdx中的通用tween引擎旋转一个三维模型实例。这是我的屏幕课程:

public class WallpaperScreen implements Screen {

private PerspectiveCamera camera;
private ModelBatch modelBatch;
private Model modelBody, modelHead;
private ModelInstance bodyModelInstance, headModelInstance;
private Environment environment;
private TweenManager tweenManager;

@Override
public void show() {
    tweenManager = new TweenManager();
    Tween.registerAccessor(ModelInstance.class, new Accesor());

    camera = new PerspectiveCamera(75, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

    camera.position.set(-10f, 2f, 0f);
    camera.lookAt(0f, 0f, 0f);

    camera.near = 0.1f;
    camera.far = 300.0f;

    modelBatch = new ModelBatch();

    UBJsonReader jsonReader = new UBJsonReader();
    G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
    modelBody = modelLoader.loadModel(Gdx.files.getFileHandle(
            "data/IS3/IS3_body.g3db", FileType.Internal));
    modelHead = modelLoader.loadModel(Gdx.files.getFileHandle(
            "data/IS3/IS3_tur.g3db", FileType.Internal));
    bodyModelInstance = new ModelInstance(modelBody);
    headModelInstance = new ModelInstance(modelHead);

    bodyModelInstance.transform.rotate(0, 1, 0, -90);
    headModelInstance.transform.rotate(0, 1, 0, -90);

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f,
            1f, 1.0f));

    Tween.to(bodyModelInstance, 0, 2).target(45).start(tweenManager);
    Tween.to(headModelInstance, 0, 2).target(45).start(tweenManager);
}

@Override
public void render(float delta) {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    Gdx.gl.glClearColor(0, 128, 255, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    tweenManager.update(delta);

    camera.update();

    modelBatch.begin(camera);
    modelBatch.render(bodyModelInstance, environment);
    modelBatch.render(headModelInstance, environment);
    modelBatch.end();
}
这是我的Tweenaccessor:

public class Accesor implements TweenAccessor<ModelInstance> {

private Quaternion quat = new Quaternion();

@Override
public int getValues(ModelInstance target, int tweenType,
        float[] returnValues) {
    quat = target.transform.getRotation(quat);
    returnValues[0] = quat.getAxisAngle(Vector3.Y);
    return 1;
}

@Override
public void setValues(ModelInstance target, int tweenType, float[] newValues) {
    target.transform.rotate(Vector3.Y, newValues[0]);
}
公共类访问或实现tweenacessor{
私有四元数quat=新四元数();
@凌驾
public int getValues(模型实例目标、int tweenType、,
浮动[]返回值){
quat=target.transform.getRotation(quat);
returnValues[0]=quat.getAxisAngle(Vector3.Y);
返回1;
}
@凌驾
公共void集合值(ModelInstance目标、int-tweenType、float[]newValues){
target.transform.rotate(Vector3.Y,newValues[0]);
}

问题是这些模型的旋转速度非常快(它们在这2秒内旋转了两个360度),我只需要它们在2秒内从Y轴上的0度慢慢旋转到45度,我在accesor中做了什么没有错?

是一个
四元数
无状态?对于所有的孩子,只有一个
accesor
实例


执行
target.transform.rotate(Vector3.Y,newValues[0])
旋转X度或旋转到X度。每次调用都会慢慢增加到45度。你是否看到旋转越来越快?也许你想要
设置旋转

是的,旋转X度不到,改为设置旋转,效果很好。谢谢你指出这一点