Problem rotating a Maya object.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Problem rotating a Maya object.

Post by neil_123 »

Hi,

I bought a Maya object, a model of a dice. I was able to display it properly using a small Irrlicht program.

Next, I tried to rotate it about X-axis, it rotates fine, but for the small problem that, it doesnt rotate about the geometrical center of the dice, it appears to be rotating about a line lying on one of the surfaces of the dice.

I have similar problem when I tried to rotate about Z-axis.

It rotates perfectly symmetrically about the Y-axis.

Here is the program,

Code: Select all


//
//
// g++ -I/home/laeeq/irrl/irrlicht-1.7.1/include -L/home/laeeq/irrl/irrlicht-1.7.1/lib/Linux  fl_pyr_2.cc -lIrrlicht -lGL -lXxf86vm -lXext -lX11
//
//


#include <unistd.h>
#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IrrlichtDevice  *device;
IVideoDriver    *driver;
ISceneManager   *smgr;

IMesh          *whale_mesh;
IMeshSceneNode *node;

int ang = 0;

int main()
{
  device = createDevice(EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, 0);
  if(!device)
  {
    printf("%s:%u Device couldn't be created.\n", __FILE__, __LINE__);
    return 1;
  }
  printf("%s:%u Device created.\n", __FILE__, __LINE__);
 
  driver = device->getVideoDriver();
  smgr   = device->getSceneManager();
  
  whale_mesh = smgr->getMesh("Dice.obj");
  if( !whale_mesh )
  {
    printf("%s:%u Whale Mesh couldn't be loaded.\n", __FILE__, __LINE__);
    return 1;
  }

  node = smgr->addMeshSceneNode(whale_mesh);
  if(node)
  {
    node->setMaterialFlag(EMF_LIGHTING, false);
    node->setMaterialTexture(0, driver->getTexture("Graphic1.jpg") );    
    // node->setPosition( vector3df(0, -0.5, 0) );
  }
  
  smgr->addCameraSceneNode(0, vector3df(0, 0, -3), vector3df(0, 0, 0) );
  
  while(device->run())
  {
    ang++;
    if(ang >= 360)
      ang -= 360;
    node->setRotation( vector3df(ang, 0, 0) );
  
    driver->beginScene(true, true, SColor(255, 100, 101, 140) );
    
    smgr->drawAll();
    
    driver->endScene();
  }
  
  device->drop();
  
   
  return 0;
}


I dont know how to attach the maya object, but I might be able to e-mail to any one wanting to duplicate the issue.

I tried experimenting with setPosition() betore rotating, but that didnt help.

Am I missing something here?

Regards
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

I've not tried it with a Maya object, but I presume once it's loaded int Irrlicht, it should be like any other mesh.

You could smgr->getMeshManipulator() at load-time then call transform() on it to move all the vertices so they are centered around the origin in model space.

If you needed to know how transform the vertices you could use the mesh's bounding box getCenter() and create a matrix with setInverseTranslation(BBCenter).

Also, you bought a model of dice? :shock: Hopefully, you used someone else's credit card!:lol: :wink:

I hope that helps. Good luck.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

Thanks BIAarg,

So, it is more complicated than I thought. I will give that a try.

So, it is a problem with the way the dice object was created by the artist. He/She did not center it around the origin, right.

Yes, I bought the dice's model from Flat Pyramid for $5. And used my own credit card. Not knowing anything about modeling, I thought that was the only way to go. Is there a better way?

Regards
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

There is a better way, just google for free dice models. Also most dice models in this expensive range are not made for realtime use.

greetings
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Yeah, I was just teasing about the dice because most people do at least a little bit of modelling and if you get blender for free, making dice is one of the first tutorials you stumble across. What you got probably looks better anyway.

Also, the method I described will work for models that are modeled off-center, but now that I look at your code more closely, it's possible that you're just setting the camera too close to the dice with a wide FOV. Rotating things that are too close to the near plane of the camera's frustum tend to distort a lot.

Also, at that speed, it's spinning so fast it seems there's a pulsating effect that has more to do with a close, wide-angle lens that does make it look off center. With the camera moved back enough, the FOV zoomed back in and the rotation slowed there's not so much wobble, it seems.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

Thanks bIArrg,

Yes, you are right, I am a total newbie, don't know anything about 3D modeling.

I tried the the changes in the program you suggested, moving camera back, slowing down the speed of rotation, but it is unmistakable, the dice indeed rotates about the center of a face, there is no question about it. It has to do with the geometry of the dice, not th camera settings.

Also, why do you think I am rotating the dice too fast? I am incrementing it by only one degree each iteration. Also the dice doesnt appear to be spinning wildly.

I began to spend some time learning blender each day. But the way it is going, I think it will be many months, before I will be able to import a Maya object in blender, edit it, fix its pivot and save it out. Well, you do what you have to do.

Regards,
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Most apparently the model itself is off-centered. The easiest way to cope with this is download Blender and move the dice to be centered around (0,0,0).
beer->setMotivationCallback(this);
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

You are absolutely right Polylux, the model is indeed off-centered.
I have installed blender and have learned the basic object selection and vertex editing etc.

But looks like, I have a long way to go before I will be able to load an external maya object in the blender, edit it and save it out again.

If someone can point to a tutorial etc, more geared toward this specific problem, I will really appreciate it.

Best regards
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

This is dead easy. :)
Just open up Blender, press Ctrl+X to erase the scene. Then load your Object (most likely Import). Right-click it to select it. Then just "drag" on the arrows you should see now to move the object axis aligned around that point, where the coloured lines intersect (this is 0,0,0). Use the numpad keys to change perspectives. When you're done, export it to a file type of your choice and it should work well in your irrlicht scene.
beer->setMotivationCallback(this);
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Hey, neil, I feel your pain when it comes to blender. :cry: It's very powerful but can be powerfully counter-intuitive, too. :x

In addition to polylux's suggestion, you might find hitting the 'n' key in Blender to be useful (after you've imported your dice) as it brings up a window that shows you the MedianX/Y/Z of the model after you toggle the 'tab key' to get into 'edit mode' (not object mode). Just toggle the 'a key' a few times once you're in 'edit mode' and change the median to 0.000 (or whatever).
Also, why do you think I am rotating the dice too fast? I am incrementing it by only one degree each iteration. Also the dice doesnt appear to be spinning wildly.
I initially assumed it was the model but later I was playing with the Irrlicht addCubeSceneNode() using your code mostly. The Irrlicht cube is centered but I noticed that spinning too close to a perspective camera created a sort of optical illusion of wobbling probably due to the fact that the edges nearest the camera appear to move faster than the edges farther away. A couple hundred FPS x 4 edges flying past the camera can make 1 degree per loop move fast enough to wobble. I just mentioned it in case your model turned out to be centered.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
joshcryer
Posts: 46
Joined: Thu Sep 13, 2007 8:57 am
Contact:

Post by joshcryer »

While in Object Mode go to Object->Transform->Center New if you want to change the center of an object to its median center. :)
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

Thanks guys for all kind suggestions.

I contacted a very helpful artist Brian Rowe from game-artist.net forum. He fixed this Maya object for me. He can be reached at brow301@gmail.com

Now the dice rotates with perfect symmetry.

Best Regards
Post Reply