Pick vertex of cloth for tearing

Vineeth@nxOgre

26-03-2008 06:38:50

how dop i do it .I want to place the mouse on the pressurized cloth and then press the left button of mouse and then the particular vertex should be pulled untill it tears .

I was working with glut in ageia and it had
ool PickCloth(int x, int y)
{
NxRay ray;
ViewUnProject(x,y,0.0f, ray.orig);
ViewUnProject(x,y,1.0f, ray.dir);
ray.dir -= ray.orig; ray.dir.normalize();

NxVec3 hit;
NxU32 vertexId;
gSelectedClothVertex = -1;
NxReal distance = NX_MAX_REAL;

NxCloth **cloths = gScene->getCloths();
for (NxU32 i = 0; i < gScene->getNbCloths(); i++) {
if (cloths[i]->raycast(ray, hit, vertexId)) {
if(hit.magnitude() < distance)
{
#if 1
gSelectedCloth = cloths[i];
gSelectedClothVertex = vertexId;
int hitx, hity;
ViewProject(hit, hitx, hity, gMouseDepth);
distance = hit.magnitude();
#else
cloths[i]->wakeUp();
cloths[i]->tearVertex(vertexId, NxVec3(0,1,0));
cloths[i]->tearVertex(vertexId, NxVec3(1,0,0));
#endif
}
}
}

return distance < NX_MAX_REAL;
}

// ------------------------------------------------------------------------------------
void MoveCloth(int x, int y)
{
if (gSelectedCloth && gSelectedClothVertex >= 0) {
NxVec3 pos;
ViewUnProject(x,y, gMouseDepth, pos);
gSelectedCloth->attachVertexToGlobalPosition(gSelectedClothVertex, pos);
}
}


What can I add in the onframe method of cake box.How can i work with
ogre .i know get mousestate().mousebutton and iskeyreleased.But just anyone please help me out with this

Vineeth@nxOgre

26-03-2008 12:33:03

I heard that it can be done using raycaster .But an algorithm of how it can be done would be helpful

I have tutorials of 0.42RC.In that there is a mouse picker in 701 or 801 .i will have alook at it

Vineeth@nxOgre

27-03-2008 12:32:38

yep

I found a class called Frosting even it has a onFrame got a ClothrayCaster

Vineeth@nxOgre

31-03-2008 13:23:52

World *mWorldInstance;
Actor* mTargetActor;
Cloth* mTargetCloth;
ClothVertex mTargetClothVertex;


While baking you have only initialized mWorldInstance



mCake->mTargetActor = 0;
mCake->mTargetCloth = 0;

By initializing others we can play with them right :wink:

#if 0

ClothVertex cv = mClothRay->getClothVertex();
mRay->castShape(RayCaster::AF_NONE);
Ogre::Plane p(mRay->getClosestRaycastHit().mWorldNormal, mRay->getClosestRaycastHit().mWorldImpact);
cv.cloth->addForceAtVertex(mOgreRay.getPoint(mOgreRay.intersects(p).second) * 10, cv.vertex);

if (mCake->mTargetCloth && ms.buttonDown(OIS::MB_Left)) {
mOgreRay = mCamera->getCameraToViewportRay(float(mCursor->getLeft() / mRenderer->getWindow()->getWidth()),float(mCursor->getTop() / mRenderer->getWindow()->getHeight()));
if (mClothRay) {
/*ClothVertex cv = mClothRay->getClothVertex();
mRay->castShape(RayCaster::AF_NONE);
Ogre::Plane p(mRay->getClosestRaycastHit().mWorldNormal, mRay->getClosestRaycastHit().mWorldImpact);
*/
std::cout << "Vertex Pos => " << mCake->mTargetClothVertex.getGlobalPosition() << std::endl;
/*
mCake->mTargetCloth->addForceAtVertex(force, cv.vertex);
NxVec3 fc = mOgreRay.getPoint(mOgreRay.intersects(p).second) - cv.getGlobalPosition();
fc *= 10;
//fc -= mActor->getPointVelocity(mActor->getGlobalPosition());
mActor->addForceAtPos(fc, mActor->getGlobalPosition());*/

}
//return;
}
}
//#endif


what is this doing How can I utilize clothraycaster class methods
What does castallcloths do :roll:

When I create new clothray caster to pick with mouse coordinates.The cloth member of this clothvertex is not initialized.the constructor accepts only scene of the sponge cake class.But the cloth that i have created is not visible in clothvertex object

Vineeth@nxOgre

01-04-2008 10:24:31

ClothVertex cv = mClothRay->getClothVertex();
NxOgre::Cloth* my=mClothRay->getClosestCloth();


the first function is not a linker error why is the second one showing linker error when both methods are in the same header :roll: