Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

HOw to first scale and then rotate a model instance in libgdx

I need to scale a model instance (a 1x1x1 qube) in the y axis and then rotate it around the z axis. So basically it should look like a beam that is rotating in the middle. Unfortunately what ever I do, rotation is always executed before scaling and the result is a dear shape. what I get and what I want

    instance.transform.setToScaling(JUMP_GATE_SIZE, JUMP_GATE_SIZE * 5, JUMP_GATE_HIGHT);
    instance.transform.setTranslation(x, y, 0);
    rotationMatrix.setToRotation(zVector, r);
    instance.transform.rotate(rotation);

Any idea how to do that? I am trying to scale the cube to bride between 2 locations in space.

question from:https://stackoverflow.com/questions/65857776/how-to-first-scale-and-then-rotate-a-model-instance-in-libgdx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution was found by my wife, who is a mathematician. The order of matrix operations is the key. Basically all matrix operations that are applied are reverse applied to the model during draw operation. This means that because I execute the rotation operation last to the matrix, it is actually first applied to the model. Code that works

    instance.transform.setToRotation(zVector,r);
    instance.transform.scale(JUMP_GATE_SIZE, JUMP_GATE_SIZE * 5, JUMP_GATE_HIGHT);
    instance.transform.setTranslation(x, y, 0);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...