【发布时间】:2014-10-31 21:48:57
【问题描述】:
我在 Blender 中创建了一个带有一个炮塔的船的模型,炮塔有 1 门枪。 为了清楚起见,这些是搅拌机中的 3 个独立对象。 在 g3dj 文件中,这显示为 3 个节点:一个用于船,一个用于炮塔,一个用于火炮。
"nodes": [
{
"id": "gun1",
"rotation": [ 0.000000, 0.000000, 0.707107, 0.707107],
"scale": [ 0.100000, 0.984755, 0.100000],
"translation": [-3.526966, 1.428384, 0.191505],
"parts": [
{
"meshpartid": "Cylinder_part1",
"materialid": "gunMaterial"
}
]
},
{
"id": "turret1",
"scale": [ 1.000000, 0.300000, 0.395389],
"translation": [-1.603167, 1.406584, 0.000000],
"parts": [
{
"meshpartid": "Cube.001_part1",
"materialid": "turretMaterial"
}
]
},
{
"id": "ship",
"scale": [ 3.000000, 1.000000, 1.000000],
"parts": [
{
"meshpartid": "Cube_part1",
"materialid": "shipMaterial",
"uvMapping": [[]]
}
]
}
],
"animations": []
}
使用 Libgdx,我尝试将炮塔旋转 30 度(rotAngle=30)。 所以我翻译成我认为是模型的起源(我认为那是船的起源?)。 然后我旋转。然后最后我会翻译回来。 但是我已经把那个翻译出来了,因为旋转不是围绕正确的点? 代码如下(基于一个xoppa教程):
Vector3 dimensions = new Vector3();
for (int i = 0; i < model.nodes.size; i++) {
String id = model.nodes.get(i).id;
ModelInstance instance = new ModelInstance(model, id);
instance.transform.getTranslation(position);
Node node = instance.getNode(id);
node.calculateLocalTransform();
node.localTransform.getTranslation(position);
node.calculateBoundingBox(bounds).mul(node.localTransform);
node.localTransform.getScale(scale);
bounds.getDimensions(dimensions);
centre=bounds.getCenter(centre);
//float radius;
//radius = dimensions.x / 2f;
if (id.equals("ship")) {
///instance.transform.rotate(Vector3.Y,rotAngle);
ship = instance;
instances.add(ship);
continue;
}
if (id.startsWith("gun")) {
guns.add(instance);
instances.add(instance);
continue;
}
if (id.startsWith("turret")) {
//movement on Y is based on Z from blender
instance.transform.trn(-centre.x,-centre.z,0).
rotate(Vector3.Y,rotAngle); // ???z???
turrets.add(instance);
instances.add(instance);
continue;
}
}
怎么了?
【问题讨论】:
-
你为什么要创建所有这些可渲染对象?
-
然而,一旦你告诉他们这样做:stackoverflow.com/questions/26656334/…;关键是在您的枢轴点上平移,旋转并向后平移
-
@Xoppa 抱歉,刚刚看到回复。我当时正在关注您使用可渲染的教程!
-
@cfrick 谢谢。我知道这是理论,但我仍然有问题。我想我需要重申一下这个问题。
-
@xoppa 我已经重置了我的代码/问题。你能再看看吗?
标签: rotation libgdx coordinates nodes