GLGE API setRot/setRotX doesn't work

▼魔方 西西 提交于 2019-12-07 20:30:18

问题


I'm trying to make a little scene for viewing 3D models.

I modified the GLGE Collada example to add a .dae model from code.

http://goleztrol.nl/SO/GLGE/01/

What I've got
So far it works. The camera is rotated using an animation.

Using the buttons 'Add' and 'Remove' the model is added and removed from the scene, using the following code (Don't mind 'duck'. It was a duck in the original example.)

var duck = null;
function addDuck()
{
    if (duck) return;
    duck = new GLGE.Collada();

    doc.getElement("mainscene").addCollada(duck);

    duck.setId("duck");
    duck.setDocument("amyrose.dae");
    duck.setLocY(-15);
    duck.setRotX(1);
    duck.setScale(2);
}

function removeDuck()
{
    if (!duck) return;
    doc.getElement("mainscene").removeChild(duck);
    duck = null;
}

Problem
Now the model is lying down, while it should stand up. The various methods of the element seem to work. The location is set, and the scale is set, but the call to setRotX seems to be ignored. I tried various others methods from the api, but setRotY, setRot, setQuatX and setDRotX all seem to fail. I don't get any errors (well not about this method). I tried values of 1.57 (which should be about 90 degrees), but other values as well, ranging from 1 to 180.

I can't find out what I'm doing wrong. Of course I could rotate the model itself in Blender, but I'd like to do it using the GLGE API.

Update
When I load the demo-model, seymourplane_triangulate.dae, the rotation works. Apparently my model differs in that it cannot be rotated. I just don't understand why. I figured it may be because the model is built of various separate meshes, but I don't understand why scaling and moving does work.

Does anyone know what's wrong with this model, and what I could do to fix it (maybe using Blender)?

Setting an initial rotation in the XML file that contains the scene does work. Setting rotation on another element (like the whole scene) works as well.


回答1:


You need to rotate it after it has been loaded.

You can do this in the callback to setDocument

duck.setDocument("amyrose.dae", null, function() {
    duck.setLocY(-15);
    duck.setScale(2);
    duck.setRotX(0);
    duck.setRotY(0);
    duck.setRotZ(3);
});


来源:https://stackoverflow.com/questions/7730121/glge-api-setrot-setrotx-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!