Bone Point Manipulation

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Bone Point Manipulation

Post by dartsman »

Hey,

I'm wanting to access the point in between two bones (and/or at the end/start of a bone). I have no idea how to do this, any help would be appreciated.

ie.

o====o====o====o

where:
o is a point between a bone, and ==== is the bone.

i want to find the o parts (world or local coords)

Thanks in advance,

dartsman
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

A bone is an abstract concept, it doesn't actually look like a bone. The bone definition is actually the 'joint' you see when drawing them in the modeller - the lines joining them are just to help you visualise, they are not really there.

Bones just define a space, like any node. You're inferring that the 'bone' goes from one joint to the next - what that's actually doing though is joining a bone and it's parent. If you want to do this, use childBone->_getDerivedPosition() - parentBone->_getDerivedPosition() to get the line between one bone and another, what you interpret to be the actual bone (but isn't). Just interpolate from the parent to the child using that value as a difference.
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

ok cool... i'll give that a go.

thanks and keep up the good work on OGRE, this rendering engine is awesome.
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

that worked, but now i have another problem, i need to set the position of the bone manually. I have a line that i move, and the bones need to be updated by that line.

I've tried "bone->setPosition(lineEnd.position);" but it isn't updating it right. I'm pretty sure theres something i've missed.
User avatar
bal
Greenskin
Posts: 100
Joined: Thu Dec 09, 2004 7:29 pm
Location: Geluwe, Belgium

Post by bal »

Have you called bone->setManuallyControlled(true) ?
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

hehe, yeah, i'll show u what i have so far...

Code: Select all

	Ogre::SceneNode *node = m_sceneManager->getRootSceneNode()->createChildSceneNode();
	Ogre::Entity *entity = m_sceneManager->createEntity("bone", "boneTest.mesh");
	entity->setMaterialName("Examples/Grass");
	node->attachObject(entity);
	//node->setScale(0.15f, 0.15f, 0.15f);

	entity->setDisplaySkeleton(true);

	Ogre::Skeleton *skeleton = entity->getSkeleton();
	Ogre::Bone *bone;

	for(int i = 1; i < 8; i++)
	{
		char buf[80];
		sprintf(buf, "Bone0%d", i);
		bone = skeleton->getBone(string(buf));
		bone->setManuallyControlled(true);
		bone->setInheritScale(true);
	}
So that should be setting everything right, and i know that the names of the bones are correct, as i modelled the mesh and put the bones on it. Also it doesn't crash, being a good sign of things working ;)

Later on i try and access the points of the bones and then move them to a point that i have (on a line). I'm using...

Code: Select all

	Ogre::Entity *entity = m_sceneManager->getEntity("bone");
	Ogre::Skeleton *skeleton = entity->getSkeleton();
	Ogre::Bone *bone;

	bone = skeleton->getBone("Bone01");
	bone->setPosition(lineEnd.position);
But what happens is that the bone position isn't at the same position as the lineEnd point. and it doesn't seem to be at any common angle either, like 90, 180, 270 etc.

Any help would be great, thanks.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

setPosition is relative to the parent bone. Make sure the position you're setting is in the same space.
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

yeah, i just realised that, cause when i move a bone, then i move the next one it will move the second one by both the first and the second. How can i get it to work??

The line is in world coordinates but the bones seem to need to be updated by the local space. Do i need to keep an accumalated positions, of all the positions that it has been moved before??

Thanks again for the help.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Easiest way is to call bone->_getFullTransform().Inverse() and apply that to your world position. That will map it back into local space.
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

Cool, thanks heaps, i got it working.

thanks again
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

If anyone needs to know the solution i can post it up here.
User avatar
sjcomp
Gnome
Posts: 315
Joined: Sat Apr 23, 2005 2:35 pm
Location: Dover, NH
Contact:

Post by sjcomp »

It would be nice to see the solution! Thanks.
Regards, Alexander. http://sjcomp.com
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

ok, i'll post it once i get home. can't remember it off by heart.
moramatte
Gnoblar
Posts: 11
Joined: Mon Jun 06, 2005 1:40 pm

Are you home yet?

Post by moramatte »

I am interested in seeing that solution of yours.
Can you post it please?
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

lol, sorry about not post like a month or two ago.

anywho, heres the bone manipulation code for updating a bone to a point.

bone = skeleton->getBone("Bipe01");
bone->setManuallyControlled(true);
Ogre::Matrix4 mat = bone->_getFullTransform().inverse();
Ogre::Vector3 position(0.0f, 1.0f, 0.0f);
Ogre::Vector3 temp = mat * position;
bone->translate(temp, Ogre::Node::TransformSpace::TS_LOCAL);

that should work... havn't used it in a month or two.

What are you going to use it for?
moramatte
Gnoblar
Posts: 11
Joined: Mon Jun 06, 2005 1:40 pm

Post by moramatte »

Thank you.

Well, my situation could be described as the trunk of an elephant. The user should be able to click on a location on the ground and the leading bone of the trunk should be placed there. The user should get the impression of controlling what the elephant is touching.
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

kool...

how are you doing orientation?? i'm finding that orientation is the annoying part. if you could post any code for orientation then that'd be great.

so far i'm thinking of using quaternions (cause they rock) and using a base unit quaternion as a reference point. from the base point the new orientation (quaternion) can be calculated with 2 cross products and a direction vector.

if anyone knows of another way of doing this i'd really like to know, code examples or just a description is fine.

i should have it done by monday though, i might post code, or else just a description (most people learn better from doing it themselves, though code is always great to get the theory down to practice).
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

hey... well it's been a while. I did get that working, unfortunately it didn't end up in the end game. But I do have some some screenshots of the test app...

you can see it at....

http://www.projectnresource.com/phpbb/v ... c.php?t=88

Credits are at the bottom of the above post...
Post Reply