[SOVED][deutrius] capsule - modify radius and length

mironix

14-01-2011 15:57:51

I have no idea with that one - how to modify capsule radius and height when i have only body stored in a map :)

i don't want to delete all shapes and create them from begining :)

betajaen

14-01-2011 16:10:26

You can get the shape using RigidBody::getShape(), where index is the position of the shape internally. If you have one shape, then it would be 0...If it's the second shape placed in then 1, etc.


You need to make sure that the Shape is a Capsule before casting it into one (Shape::getShapeFunctionType)

mironix

14-01-2011 21:31:15

is it needed to send some update signal by some method? i don't see any changes in the visual debugger :)




void Player::ReloadBones()
{
Ogre::ConfigFile c;
c.loadDirect("Players\\"+_name+"\\bones.cfg", "\t:=", true);
std::vector<std::string>::iterator it = bones.begin();
int i=0;
for(i=0;i<bones.size();i++)
{
body bod = physyx[i];
NxOgre::Shape * shape = bod.b->getShape(0);

//yey
int type = shape->getShapeFunctionType();
if(shape->getShapeFunctionType() == NxOgre::Enums::ShapeFunctionType_Capsule)
{


NxOgre::Capsule * capsule = (NxOgre::Capsule*)shape;
double f;
Ogre::String field = bones[i]+"s";
f = atof(field.c_str());
f = blengths[i]*f;
capsule->setHeight(f);
field = bones[i]+"d";
f = atof(field.c_str());
capsule->setRadius(f);
}
i++;
}

}


the function type as i debug seems to be a joint... i dont have any joints there :)

mironix

15-01-2011 00:08:10

betajean what's the best method to store bodies in a vector, map or anything else, that seems to be the problem, cannot use the prt_vector from boost because the destructor is private.

it doesnt matter if i do it before or after render, stored pointers don't make any changes to the capsules.

EDIT: k found youre map container.

when i use youre containers i get that:



TRY TO UPDATE INSERTED CODE:

Ogre::ConfigFile c;
c.loadDirect("Players\\"+_name+"\\bones.cfg", "\t:=", true);
int i=0;
for(i=0;i<bones.size();i++)
{
NxOgre::Shape * shape = physyx.at(bones[i])->getShape(0);

//yey
int type = shape->getShapeFunctionType();
//if(shape->getShapeFunctionType() == NxOgre::Enums::JointFunctionType_Count)
//{

int num =physyx.at(bones[i])->getNbShapes();
NxOgre::Capsule * capsule = (NxOgre::Capsule*)shape;
double f,radius;
Ogre::String field = bones[i]+"s";
f = atof(c.getSetting(field).c_str());

field = bones[i]+"d";
radius = atof(c.getSetting(field).c_str());
capsule->setRadius(radius);//problem,random
f = blengths[i]- (radius*f);

if( f <= 0 )
f = 0.01f;
capsule->setHeight(f);//problem, random
//}
i++;
}

}



INSERT CODE:

Critter::BodyDescription bodyDescription;
bodyDescription.mMass = 40.9f;
bodyDescription.mName = b->getName()+gamer;//gamer = "p1" or "p2"
bodyDescription.mLinearVelocity = NxOgre::Vec3(0.0f,0.0f,0.0f);
Critter::Body * mBody;
NxOgre::CapsuleDescription d;
NxOgre::Quat q;
q.w = b->_getDerivedOrientation().w;
q.x = b->_getDerivedOrientation().x;
q.y = b->_getDerivedOrientation().y;
q.z = b->_getDerivedOrientation().z;
mBody = NULL;
mBody = nxrender->createBody(NxOgre::CapsuleDescription(boneRadius,boneLength),
NxOgre::Matrix44(q),"cube.1m.mesh",bodyDescription);
if(gamer == "p1")
{
mBody->setGlobalPosition(midpoint.x,midpoint.y,midpoint.z);
}
else
{
mBody->setGlobalPosition(midpoint.x+20,midpoint.y+20,midpoint.z+20);
}
int z=mBody->getShape(0)->getShapeFunctionType();
NxOgre::Capsule* capz = (NxOgre::Capsule*) mBody->getShape(0);
capz->setRadius(0.4);//here it works
physyx.insert(b->getName(),mBody);
bones.push_back(b->getName());


CONFIG

bacinos=2.0
bacinod=1.5
avambraccio.Ls=2.0
avambraccio.Ld=1.5
colloGius=2.0
colloGiud=1.5
pollice1.Ls=2.0
pollice1.Ld=1.5
dita1.Ls=2.0
dita1.Ld=1.5
polpaccio.Ls=2.0
polpaccio.Ld=1.5
polpaccio.Rs=2.0
polpaccio.Rd=1.5
dita1.Rs=2.0
dita1.Rd=1.5
pollice1.Rs=2.0
pollice1.Rd=1.5
pollice2.Rs=2.0
pollice2.Rd=1.5
avambraccio.Rs=2.0
avambraccio.Rd=1.5
spalla.Rs=2.0
spalla.Rd=1.5
pollice2.Ls=2.0
pollice2.Ld=1.5
gonna.Ls=2.0
gonna.Ld=1.5
addomes=2.0
addomed=1.5
gonna.Rs=2.0
gonna.Rd=1.5
spalla.Ls=2.0
spalla.Ld=1.5
piede.Ls=2.0
piede.Ld=1.5
gamba.Ls=2.0
gamba.Ld=1.5
tallone.Ls=2.0
tallone.Ld=1.5
mano.Rs=2.0
mano.Rd=1.5
colloSus=2.0
colloSud=1.5
testas=2.0
testad=1.5
mano.Ls=2.0
mano.Ld=1.5
tallone.Rs=2.0
tallone.Rd=1.5
piede.Rs=2.0
piede.Rd=1.5
gamba.Rs=2.0
gamba.Rd=1.5
dita3.Rs=2.0
dita3.Rd=1.5
schienas=2.0
schienad=1.5
bicipite.Ls=2.0
bicipite.Ld=1.5
PiedeDita.Rs=2.0
PiedeDita.Rd=1.5
dita2.Rs=2.0
dita2.Rd=1.5
dita2.Ls=2.0
dita2.Ld=1.5
PiedeDita.Ls=2.0
PiedeDita.Ld=1.5
bicipite.Rs=2.0
bicipite.Rd=1.5
dita3.Ls=2.0
dita3.Ld=1.5

betajaen

15-01-2011 10:21:13

Congratulations! you indirectly found a bug in NxOgre!

I had a go at what you was trying to do. This is my efforts:

Class header setup:
NxOgre::map<Ogre::String, NxOgre::Capsule*, NxOgre::GC::NoGarbageCollection> mCapsules;

Creation
NxOgre::vector<Ogre::String> names;
names.push_back("baldrick");
names.push_back("edmund");
names.push_back("percy");
names.push_back("melchett");

float z = 0;
for (NxOgre::vector_iterator<Ogre::String> name = names.elements(); name != name.end(); name++)
{
NxOgre::CapsuleDescription cap_desc;
cap_desc.mHeight = 2;
cap_desc.mRadius = 0.2f;

Critter::BodyDescription b_desc;
b_desc.mName = (*name);
b_desc.mMass = 100.0f;

NxOgre::Matrix44 pose(NxOgre::Vec3(0,5,z), NxOgre::Quat(1,0,0,0));
z += cap_desc.mRadius + 1.5;

Critter::Body* body = mRenderSystem->createBody(cap_desc, pose, b_desc);
NxOgre::Shape* shape = body->getShape(0);
std::cout << "Shape type is : " << shape->getShapeFunctionType() << "\n";
if (shape->getShapeFunctionType() == NxOgre::Enums::ShapeFunctionType_Capsule)
{
std::cout << "Inserting " << (*name) << "\n";
mCapsules.insert( (*name), static_cast<NxOgre::Capsule*>(shape) );
}

}


Usage
for (NxOgre::map_iterator<Ogre::String, NxOgre::Capsule*> capsule = mCapsules.elements(); capsule != capsule.end(); capsule++)
{
capsule->setHeight(NxOgre::Math::random(1, 5));
capsule->setRadius(NxOgre::Math::random(0.25, 2));
std::cout << capsule->getRigidBody()->getName() << " has now been changed!\n";
}



If you download the latest BuggySwires (assuming you are), otherwise just prefix "virtual" to the same function in Detritus, your code should work. But have a look at mine, so you know the proper way of doing some things; i.e. your position/orientation code could be improved.

mironix

15-01-2011 17:21:39



ty for the help :)

final result: