0
votes

using minko version 3.0, i am creating a camera as the samples :

auto camera = scene::Node::create("camera")
->addComponent(Renderer::create(0x000000ff))
->addComponent(Transform::create(
    //test
    Matrix4x4::create()->lookAt(Vector3::zero(), Vector3::create(0.f, 0.f, 3.f))  //ori
    //Matrix4x4::create()->lookAt(Vector3::zero(), Vector3::create(0.f, 0.f, 30.f))
))
->addComponent(PerspectiveCamera::create(canvas->aspectRatio()));

Then loading my obj using a similar method :

RotateMyobj(const char *objName,float rotX, rotY, float rotZ)
{
...
    auto myObjModel = sceneMan->assets()->symbol(objName);
    auto clonedobj = myObjModel->clone(CloneOption::DEEP);
    ...
    clonedobj->component<Transform>()->matrix()->prependRotationX(rotX); //test - ok
    clonedobj->component<Transform>()->matrix()->prependRotationY(rotY);
    clonedobj->component<Transform>()->matrix()->prependRotationZ(rotZ);
...
    //include adding child to rootnode
}

calling it from asset complete callback :

auto _ = sceneManager->assets()->loader()->complete()->connect([=](file::Loader::Ptr loader)
{
...
RotateMyobj(0,0,0);
...
}

The obj does load however it is rotated "to the left" (compared when loaded within blender for example). if i call my method using RotateMyobj(0,1.5,0); the obj is diaplyed at the right angle, however i think this shouldn't be needed.

PS: tested with many obj, all giving same results.

PS2 : commenting / turning off Matrix4x4::create()->lookAt leads to the same result

PS3 : shouldn't create cam with a position of 30 (Z axis) feels like looking at the ground from the top of a building ?

Any idea if this from the camera creation code or the obj loading one ?

Thx.

Update :

I found the source of my problem, it is being caused by calling this method inside enterFrame callback: UpdateSceneOnMouse( camera );

void UpdateSceneOnMouse(  std::shared_ptr<scene::Node> &cam ){
yaw += cameraRotationYSpeed;
cameraRotationYSpeed *= 0.9f;

pitch += cameraRotationXSpeed;
cameraRotationXSpeed *= 0.9f;
if (pitch > maxPitch)
{
    pitch = maxPitch;
}
else if (pitch < minPitch)
{
    pitch = minPitch;
}

cam->component<Transform>()->matrix()->lookAt(
        lookAt,
        Vector3::create(
        lookAt->x() + distance * cosf(yaw) * sinf(pitch),
        lookAt->y() + distance * cosf(pitch),
        lookAt->z() + distance * sinf(yaw) * sinf(pitch)
        )
        );}

with the following initialization parameters :

float CallbackManager::yaw = 0.f;

float CallbackManager::pitch = (float)M_PI * 0.5f;

float CallbackManager::minPitch = 0.f + 1e-5;

float CallbackManager::maxPitch = (float)M_PI - 1e-5;

std::shared_ptr CallbackManager::lookAt = Vector3::create(0.f, .8f, 0.f);

float CallbackManager::distance = 10.f;

float CallbackManager::cameraRotationXSpeed = 0.f;

float CallbackManager::cameraRotationYSpeed = 0.f;

If i turn off the call (inspired by the clone example), the object loads more or less correctly (still a bit rotated to the left but better than previously). I am no math guru, can anyone suggest better default parameters so the object / cameras aren't rotated at startup ?

Thx.

1
I'm not an expert and don't really know what math minko uses under the covers but I had similar problems in opengl some times ago. This is just a pointer on what you might want to investigate: do you know about quaternion rotations as opposed to euler angles? If minko uses euler angles you might have stumbled in what is called a "gimbal lock"dogiordano

1 Answers

0
votes

Many 3D/CAD tools will export files - including OBJ - with coordinates system different from the one used by Minko:

  • Minko 3 beta 2 uses a left-handed coordinates system
  • Minko 3 beta 3 uses the OpenGL coordinates system, which is right-handed.

For example, in a right handed coordinates system x+ goes "right", y+ goes "up" and z+ goes "out from the screen".

Your Minko app likely loads 3D files using the ASSIMP library through the Minko/ASSIMP plugin. If the 3D file (format) provides the information about the coordinate system it was used upon export, then ASSIMP will convert the coordinates to the right-handed system. But the OBJ file format standard does not include such information.

Solution 1 : Try exporting your 3D models using a more versatile format such as Collada (*.dae).

Commenting/turning off Matrix4x4::create()->lookAt() does not affect the orientation of your 3D model because there is no reason for it to do so. Changing the position of the camera has no reason to affect the orientation of a mesh. If you want to change the up axis of the camera you have to use the 3rd parameter of the Matrix4x4::lookAt() method.

Solution 2 : The best thing to do is to properly rotate your mesh** using RotateMyobj(0, PI / 2, 0).

I also recommend using the dev branch (Minko beta 3 instead of beta 2) because there are some API changes -especially math wise - and a tremendous performance boost.

Solution 3 : Try adding the symbol without cloning it, see if it makes any difference.