how to create body in manually?

valvalval

30-03-2008 10:34:36

I do not use createBody()
because, I have to name created scenenode with its own name.

so, I used this code below.

// first, create entity.
m_pEntity = GetGameWorld()->GetSceneMgr()->createEntity(String(temp_name) + "Robot", "robot.mesh");

// create scenenode
m_pSceneNode = GetGameWorld()->GetSceneMgr()->getRootSceneNode()->createChildSceneNode(String(temp_name) + "EnemyRobot" , this->Pos(), this->Orientation());

// make a body using new Body()
m_pBody = new Body(String(temp_name) + "EnemyRobot", this->GetGameWorld()->GetScene());

// cretaed Entity and SceneNode to be attached.
m_pBody->setEntity(m_pEntity);
m_pBody->setNode(m_pSceneNode);

// Last, I need to a shape? this is problem..
// there is a method for create shape?
m_pBody->addShape(new CubeShape(1));



Important thing is that, I don't have to use createBody().
because, SceneNode Name is used in stl::map.
if there is a collision between Entities, I'm going to get a name of them.

what am I supposed to do? create body manually.

betajaen

30-03-2008 11:43:46

m_pEntity = GetGameWorld()->GetSceneMgr()->createEntity(String(temp_name) + "Robot", "robot.mesh");

m_pSceneNode = GetGameWorld()->GetSceneMgr()->getRootSceneNode()->createChildSceneNode(String(temp_name) + "EnemyRobot" , this->Pos(), this->Orientation());

m_pSceneNode->attachObject(m_pEntity);

mScene->createBody("Robot", new CubeShape(1), NxOgre::Pose(m_pBody->getPosition(), m_pBody->getOrientation), "mass: 10, node: " + m_pBody->getName());

valvalval

30-03-2008 12:06:15

m_pEntity = GetGameWorld()->GetSceneMgr()->createEntity(String(temp_name) + "Robot", "robot.mesh");

m_pSceneNode = GetGameWorld()->GetSceneMgr()->getRootSceneNode()->createChildSceneNode(String(temp_name) + "EnemyRobot" , this->Pos(), this->Orientation());

m_pSceneNode->attachObject(m_pEntity);

mScene->createBody("Robot", new CubeShape(1), NxOgre::Pose(m_pBody->getPosition(), m_pBody->getOrientation), "mass: 10, node: " + m_pBody->getName());


Thank you. ^_^)b, but I think this code use createBody instead of new Body()?
m_pBody->getPosition() is correct? m_pBody is not initialize before createBody() ; how coud it has Position, Orientation, and name?

maybe it is m_pSceneNode?

valvalval

30-03-2008 12:26:16

whole code is below.. (modified after seeing your code)

m_pEntity = GetGameWorld()->GetSceneMgr()->createEntity(String(temp_name) + "Robot", "robot.mesh");

m_pSceneNode = GetGameWorld()->GetSceneMgr()->getRootSceneNode()->createChildSceneNode(String(temp_name) + "EnemyRobot" , this->Pos(), this->Orientation());

m_pSceneNode->attachObject(m_pEntity);

m_pBody = this->GetGameWorld()->GetScene()->createBody("Robot", new CubeShape(1), NxOgre::Pose(m_pSceneNode->getPosition(), m_pSceneNode->getOrientation()), "mass: 10, node: " + m_pSceneNode->getName());
// and if this is right, there is no need for setEntity? it is because of m_pEntity attached to m_pSceneNode?

betajaen

30-03-2008 12:49:11

Yes.

sir_nacnud

07-04-2008 03:20:49

I can't get this to work. When I run my program, my mesh shows up, but it doesn't move with the body. I verified this with the remote debugger as the bodies move, but the meshes don't. Also the name for the node of the body is not the name of the node I created. What am I doing wrong?
entity = mSceneMgr->createEntity(name+"Entity",_mesh);
entity->setCastShadows(true);
entity->setQueryFlags(BOID_QUERY_MASK);
AxisAlignedBox meshBoundingBox = entity->getBoundingBox();
Vector3 sizeOfBox = meshBoundingBox.getSize();
node = mSceneMgr->getRootSceneNode()->createChildSceneNode(name+"Node");
node->attachObject(entity);
node->setPosition(_position);
node->setScale(scale);
NxOgre::CubeShape* boundShape = new NxOgre::CubeShape(sizeOfBox.x*scale.x,sizeOfBox.y*scale.y,sizeOfBox.z*scale.z);
body = scene->createBody(name, boundShape,_position,"node: "+node->getName()+", mass: "+StringConverter::toString(mass)+", group: "+BOID_ACTOR_GROUP);