0

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.

Jeux
  • 5
  • 5
  • 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 Jul 15 '15 at 16:34

1 Answers1

0

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.

  • Thank you for your fast and detailed answer, however currently i am stuck with obj and yes i am using the ASSIMP plugin.
    I don’t think the problem resides in the models but rather in my code, as it also happens for the pirate model !?
    Solution 2 did work tough. PS: I understand that lookat should not affect the orientation of the mesh, but shouldn’t it affect the view ? I mean isn t it supposed to be like from the same position of ur eye ur looking downward or upward ? Thx
    – Jeux Jul 08 '15 at 18:19
  • Thx for the update, solution3 didnt work, i will try to dig deeper in my code to see what is the real issue... As for the cam i cant seem to move it, neither upon creation (third param of lookAt, neither on asset load complete callback (using : `camera->component()->matrix()->appendRotationY(0.5f); `, neither on enterframe callback. The only way to move it is thru the mouse wheel callback (yaw, pitch...) as per Minko example code. – Jeux Jul 11 '15 at 05:14
  • You should post your entire code then, also try the 'dev' branch since a lot of bugs have been fixed. Also did you try running the animation of the pirate model ? Animated models sometime look weird when the animation is not enabled because the pose matrix is not used. – Jean-Marc Le Roux Jul 11 '15 at 07:53