tengil
01-02-2007 16:49:25
Hi!
The Body becomes invisible by binding it to a SceneNode...
My short Question: Why???
The code without a given SceneNode (so a new node is made in nxOgre_body.cpp with this code: owner->mSceneMgr->getRootSceneNode()->createChildSceneNode()):
Ogre::SceneNode* mNode;
mNode = this->mSceneMgr->createSceneNode("myNode");
mNode->setPosition(0,0,0);
mScene->createBody(
"something", // Name
"cube.1m.mesh", // Mesh to use
new nxOgre::cubeShape(1.00f), // Collision Model to use
0.3f, // Density of the body
//params<rigidbody>("node: myNode"),
Vector3( 0.0f , 1.0f , 0.0f) // Where to put it. (In Metres)
);
mScene->findBody("something")->mEntity->setCastShadows( true );
mScene->findBody("something")->setAngularDamping(0.0);
mScene->findBody("something")->setKinematic(true);
mScene->findBody("something")->setLinearDamping(0.0);
The "invisible code":
Ogre::SceneNode* mNode;
mNode = this->mSceneMgr->createSceneNode("myNode");
mNode->setPosition(0,0,0);
mScene->createBody(
"something", // Name
"cube.1m.mesh", // Mesh to use
new nxOgre::cubeShape(1.00f), // Collision Model to use
0.3f, // Density of the body
params<rigidbody>("node: myNode"),
Vector3( 0.0f , 1.0f , 0.0f) // Where to put it. (In Metres)
);
mScene->findBody("something")->mEntity->setCastShadows( true );
mScene->findBody("something")->setAngularDamping(0.0);
mScene->findBody("something")->setKinematic(true);
mScene->findBody("something")->setLinearDamping(0.0);
regards
Tengil
betajaen
01-02-2007 17:36:16
You got the Ogre bit wrong, it goes:
Ogre::SceneNode* mNode;
mNode = this->mSceneMgr->getRootSceneNode()->createChildSceneNode("myNode");
mNode->setPosition(0,0,0);
body* something = mScene->createBody(
"something", // Name
"cube.1m.mesh", // Mesh to use
new nxOgre::cubeShape(1.00f), // Collision Model to use
0.3f, // Density of the body
params<rigidbody>("node: myNode"),
Vector3( 0.0f , 1.0f , 0.0f) // Where to put it. (In Metres)
);
something>mEntity->setCastShadows( true );
something->setAngularDamping(0.0);
something->setKinematic(true);
something->setLinearDamping(0.0);
tengil
02-02-2007 10:26:12
Ah, yes of course - addChild(..) is missing. Thank you!
tengil
02-02-2007 13:51:45
Hi!
Another problem: Node manipulation doesn't effect the shapes...
Here I manipulate the root node - everything is fine:
Ogre::SceneNode* mNode;
mNode = this->mSceneMgr->getRootSceneNode()->createChildSceneNode("myNode");
mNode->createChildSceneNode("myNode2");
mScene->createBody(
"x", // Name
"cube.1m.mesh", // Mesh to use
new nxOgre::cubeShape(1.00f), // Collision Model to use
0.3f, // Density of the body
params<rigidbody>("node: myNode2"),
Vector3( 0.0f , 0.5f , 0.0f) // Where to put it. (In Metres)
);
mScene->findBody("x")->mEntity->setCastShadows( true );
mScene->findBody("x")->setAngularDamping(0.0);
mScene->findBody("x")->setKinematic(true);
mScene->findBody("x")->setLinearDamping(0.0);
mNode->createChildSceneNode("myNode3");
mScene->createBody(
"y",
"cube.1m.mesh",
new nxOgre::cubeShape(Vector3( 1.0f , 1.0f , 0.2f)),
0.3f,
params<rigidbody>("node: myNode3"),
Vector3( 1.0f , 0.5f , 0.0f)
);
mScene->findBody("y")->mEntity->setCastShadows( true );
mScene->findBody("y")->mNode->scale(Vector3( 1.0f , 1.0f , 0.2f));
mScene->findBody("y")->setAngularDamping(0.0);
mScene->findBody("y")->setKinematic(false);
mScene->findBody("y")->setLinearDamping(0.0);
mScene->findBody("y")->freezeAll();
mScene->findBody("x")->freezeAll();
mScene->findBody("y")->mNode->getParent()->getParent()->setPosition(4,0.5,4);
mScene->findBody("y")->mNode->getParent()->getParent()->setOrientation(Quaternion(Radian(Degree(90)),Vector3::UNIT_Y));
mScene->findBody("y")->unFreezeAll();
mScene->findBody("x")->unFreezeAll();
Here I manipulate a child node of the root node - the visible part moves, but the shape not:
Ogre::SceneNode* mNode;
mNode = this->mSceneMgr->getRootSceneNode()->createChildSceneNode("myNode");
mNode->createChildSceneNode("myNode2");
mScene->createBody(
"x", // Name
"cube.1m.mesh", // Mesh to use
new nxOgre::cubeShape(1.00f), // Collision Model to use
0.3f, // Density of the body
params<rigidbody>("node: myNode2"),
Vector3( 0.0f , 0.5f , 0.0f) // Where to put it. (In Metres)
);
mScene->findBody("x")->mEntity->setCastShadows( true );
mScene->findBody("x")->setAngularDamping(0.0);
mScene->findBody("x")->setKinematic(true);
mScene->findBody("x")->setLinearDamping(0.0);
mNode->createChildSceneNode("myNode3");
mScene->createBody(
"y",
"cube.1m.mesh",
new nxOgre::cubeShape(Vector3( 1.0f , 1.0f , 0.2f)),
0.3f,
params<rigidbody>("node: myNode3"),
Vector3( 1.0f , 0.5f , 0.0f)
);
mScene->findBody("y")->mEntity->setCastShadows( true );
mScene->findBody("y")->mNode->scale(Vector3( 1.0f , 1.0f , 0.2f));
mScene->findBody("y")->setAngularDamping(0.0);
mScene->findBody("y")->setKinematic(false);
mScene->findBody("y")->setLinearDamping(0.0);
mScene->findBody("y")->freezeAll();
mScene->findBody("x")->freezeAll();
///////////////////// changed part ///////////////////////////////////////
mScene->findBody("y")->mNode->getParent()->setPosition(4,0.5,4);
mScene->findBody("y")->mNode->getParent()->setOrientation(Quaternion(Radian(Degree(90)),Vector3::UNIT_Y));
///////////////////// changed part ///////////////////////////////////////
mScene->findBody("y")->unFreezeAll();
mScene->findBody("x")->unFreezeAll();
Of course, one solution would be to use the body-methods setGlobalPosition(..) and setGlobalOrientation(..), but I don't know how to rescale a body... - node rescaling is possible with the node-method scale(..)
regards
Tengil
betajaen
02-02-2007 16:04:59
The body wouldn't move with the node like that, the body just sets the orders and assumes the node will move it. As it's a one way process the body wouldn't even dream at looking at the node to adjust it's position.
You can move the body like you said using the setGlobalPosition and Orientation, and you don't scale the body. If you wanted to scale anything you'd scale the collision model or shape. But they can't be scaled once tied to a body.
I think you need to brush up on your NxOgre tutorials a little, as it seems your getting a little confused between the relationships of body, NxActor, node, entity and shape.
Also, use this code:
body *x = mScene->createBody()..
x->unFreezeAll();
Instead of:
mScene->findBody("x")->unFreezeAll();
It's a lot quicker
tengil
04-02-2007 09:08:55
Okey, I think I get it now...
If I get you right then there isn't a way to change the size of bodies after creating it. Right? So if I want to shrink a body I have to create a complete new one and have to destroy the old one. Right? When I want a smooth transition from one size to the other I have to create a mesh animation (or calling the node-method scale(..) and change only the "visible size" of the body). While the animation is going on the shape can't be changed, so the collision modell doesn't fit to the "visible model" until I replace the old body with the newly created one in the new size at the end of animation... Hm...
Also, use this code:
body *x = mScene->createBody()..
x->unFreezeAll();
Instead of:
mScene->findBody("x")->unFreezeAll();
It's a lot quicker
Yes, you're right, the performance would be better, but in "experiment period" I feel better to see which object I am manipulating in the same line of code as the method-call (less accidental strange behaviors)
best regards
Tengil
betajaen
04-02-2007 10:19:44
You may be able to directly insert and remove shapes into the NxActor directly, but every time you do that you need to recalculate the mass. Also, I don't know if PhysX will work like that, it may work it may not.
There may be a few other ways to do what you want without using a body, may I ask what is it exactly your doing?
tengil
05-02-2007 11:53:06
may I ask what is it exactly your doing?
Just playing around a little bit
Actually I have a lot of the same objects which are only a little bit different in size, so first I was going to make a "normalized version" of the object and modify it on runtime. Now I have a absolut different solution, but I'm nevertheless interested in shrinking and increasing, perhaps I will need it in future (i.e. a balloon which will filled more and more with gas - or making some sort of 'Alice in Wonderland' *grin* - do you remember shrinking in Duke Nukem 3D?)
betajaen
05-02-2007 12:19:19
No, I never played it.
I was thinking you may be able to get around it by creating a trigger or some sort, that would be the maximum size of say; The balloon, since it's round it should be easy to determine the collision points in the balloon for your Alice. Then you just add the required force or velocity.
I'll have an experiment the direct way though, but I'm sure deleting and adding shapes like that may make the body go a little crazy.