Ogre Position vs NxOgre Position
cruzdanilo
01-07-2007 09:51:29
This is my first post here, and i really want to thank you guys for doing the realy great job, programmin and solving problems =D
So, my problem is this one (i think its very basic, but i cant solve it)
I've figured out (maybe im wrong) that nxogre uses the position relative to the center of the node, while ogre uses the position relative to the center on x and z axis and to the base on the y axis.
I was correcting it using a offset on the cube shapes, adding size.y/2 to the y offset, and everything was working great.
But now i need to put a character on the scene, and it dont have a offset, i dont know what to do.
Maybe everything i've said sounds stupid, but if i'm wrong, the universe of the coincidences is conspiring against me =D
Please, help me
betajaen
01-07-2007 11:08:03
It's the same with Ogre; 0,0,0 is the center of the Scene as the same with 0,0,0 is the same as the center in the SceneManager.
You have it right there; Since the Mesh Center of the Cube is inside the Cube and not on one of the corners, to place it on the Ground then it would be (x, y + (cubeHeight / 2) + z).
It's the same with the Character, just get the height (You can get this from the Bounding box of the Mesh) half it, and just add it to y.
BTW: That is a very scary picture you have there.
cruzdanilo
01-07-2007 13:02:19
Yeah, al least i was right
Thanx for the quick answer!!
I just dont know how to change the character position without change the node position together, i think its because of the render function of the character:
void Character::render(float) {
if (mNode) {
mNode->setPosition(getGlobalPosition());
mNode->setOrientation(getGlobalOrientation());
}
}
So, my code is this, please, tell me what to do:
char params[100];
sprintf(params,"dimensions: %lf %lf %lf, up: 0 1 0, type: box",size.x,size.y,size.z);
mCharacter = mScene->createCharacter(pName, pPose, params);
mCharacter->attachMesh(pMesh);
mCharacter->getNode()->setScale(scale);
BTW: It's me and my dreadlocks on the photo
betajaen
01-07-2007 13:10:23
I'm guessing you've used this.
mCharacter->setPosition(...)
So your probably talking about the mesh used, has an offset so the feet of the character isn't at x,y,z but at x,y - (height / 2), z?
If that is correct, then that's how it works. The Pelvis of the Character should be at x,y,z, and the feet of the character would be at x,y - (height /2),z.
cruzdanilo
01-07-2007 15:02:04
The Pelvis of the Character should be at x,y,z, and the feet of the character would be at x,y - (height /2),z.
Yeah, but how to do it without setPosition method?
Can you write me a piece of code showing how to create and positionate a character using the coordinates you've said??
Thanx
betajaen
01-07-2007 15:19:12
char params[100];
sprintf(params,"dimensions: %lf %lf %lf, up: 0 1 0, type: box",size.x,size.y,size.z);
mCharacter = mScene->createCharacter(pName, pPose, params);
mCharacter->attachMesh(pMesh);
mCharacter->getNode()->setScale(scale);
mCharacter->setPosition(x, y - (size.y * 0.5f), z);
cruzdanilo
01-07-2007 15:29:46
I've tried this code and doesnt work, the mesh still size.y/2 above the ground
char params[100];
sprintf(params,"dimensions: %lf %lf %lf, up: 0 1 0, type: box",size.x,size.y,size.z);
mCharacter = mScene->createCharacter(pName, pPose, params);
mCharacter->attachMesh(pMesh);
mCharacter->getNode()->setScale(scale);
mCharacter->setPosition(pPose.getVector3()-Vector3(0,size.y/2,0));
I dont know what to do now
betajaen
01-07-2007 15:37:10
What is the mesh?
cruzdanilo
01-07-2007 15:43:38
robot.mesh, the one from ogre samples
betajaen
01-07-2007 16:09:44
The centre of the Robot and Ninja meshes that come with Ogre are offset (they are actually 0.5 metres up from the origin).
So to "fix" it. You need to make sure the node is -0.5 metres down from the Characters origin. To do this you cheat; Don't use attachMesh (leave it out), and add a Node to the CharactersNode, offset it by 0, -0.5,0. mCharacter->getNode()->createChildNode(.....);
In short; It's a stupid bug with those Ogre meshes that have never been fixed.
ANdys
01-07-2007 16:17:56
Maybe Your problem is the mesh's CenterPoint. The mesh's CenterPoint are under the mesh's foot. So,The mesh always floating on the ground. Because the shape's CenterPoint was on shape's Center, the mesh still size.y/2 above the ground. The problem made Position matching fault between Mesh and Actor(Character).
My change code add a Vector3 and a Quaternion to match it in Character::render().
NxOgreCharacter.h
Add this~
public:
Ogre::Vector3 getPositionOffSet();
Ogre::Quaternion getOrientationOffSet();
void setPositionOffSet(const Ogre::Vector3&);
void setOrientationOffSet(const Ogre::Quaternion&);
protected:
NxVec3 mPositionOffSet;
NxQuat mOrientationOffSet;
NxOgreCharacter.cpp
Add this and Change "Character::render" ~
////////////////////////////////////////////////////////////////////////////////////////////////
void Character::render(float) {
if (mNode) {
//mNode->setPosition(getGlobalPosition());
//mNode->setOrientation(getGlobalOrientation());
mNode->setPosition(getGlobalPosition() + getPositionOffSet());
mNode->setOrientation(getGlobalOrientation() * getOrientationOffSet() );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Character::setPositionOffSet(const Ogre::Vector3& v) {
mPositionOffSet = toNxVec3(v);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Character::setOrientationOffSet(const Ogre::Quaternion& v) {
mOrientationOffSet = toNxQuat(v);
}
////////////////////////////////////////////////////////////////////////////////////////////////
Ogre::Vector3 Character::getPositionOffSet() {
return toVector3(mPositionOffSet);
}
////////////////////////////////////////////////////////////////////////////////////////////////
Ogre::Quaternion Character::getOrientationOffSet() {
return toQuaternion(mOrientationOffSet);
}
////////////////////////////////////////////////////////////////////////////////////////////////
Example:
mPlayer=mScene->createCharacter("chr", Vector3(1586.56,160,2329.06), "type: Box, dimensions: 0.2 1.8 0.4");
mPlayer->attachMesh("SpiderMan.mesh");
mPlayer->setPositionOffSet(Vector3(0, -1, 0));
mPlayer->setOrientationOffSet(Quaternion(0.7071, 0, -0.7071,0));
mPlayer->getNode()->scale(0.011265,0.011265,0.011265);
I'm not sure this change is good. But I think it can help you~
betajaen
01-07-2007 16:24:58
Wouldn't it just be easier to do my fix, or just reset it in the modeler?
ANdys
01-07-2007 16:33:12
In my opinion,the way can help the mesh if the mesh can't reduce.
betajaen
01-07-2007 16:40:08
It seems to me to be more efficient just to reset the origin of the mesh inside the modeler, or at least offset it through a SceneNode. Your way constantly performs an addition of three floats there, which is inefficient to me.
I don't think it really matters anyway, nobody would use the Robot or Ninja meshes in a completed game/application anyway.
cruzdanilo
01-07-2007 17:20:57
WOW, great, that is just what i needed!!!!
i just dont like too much to change NxOgre code because of future versions, but i think that those functions shoul be added to the NxOgre code so it can be compatible with every mesh.
A lot of exporters export their meshes with the centerpoint "under the foot", so it would be nice to have an offset so every mesh can fit easily on a NxOgre Scene
Thanks to both of you for helping me. I'm new here, but i want to can help others like you helped me
Bye, and congrats again for the nice work
betajaen
01-07-2007 17:26:32
I disagree. These functions however useful they can be, introduce laziness. The position of the Character is the exact center of the shape used with the Character. Likewise a mesh origin should be the center of the mesh, and not the bottom or feet.
cruzdanilo
01-07-2007 17:49:38
Sorry, i just dont know how to export them using the centerpoint as the position. Do you know how to do it using oFusion for 3dsmax???
As i've said, i dont like to change NxOgre code, so i will keep betajaen sugestion, that work perfectly too
Thank you very much, and sorry for this lot of questions
betajaen
01-07-2007 18:05:12
I don't know 3DSMax. You should use my code or ANdys' solution until you switch to more suited model, when you do just center the origin of the mesh, and move it to 0,0,0.
Aiursrage2k
07-07-2007 10:40:29
ANdys
07-07-2007 12:55:44
This is a so nice tool. Very thank you for share that!!