Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Raycast on Physx with ofRay

$
0
0

@spinzero wrote:

Hi list!

I trying to pick Physx model on scene with ofEasyCam and ofRay

void ofApp::mousePressed(int x, int y, int button){

   ofVec3f screenToWorld = cam.screenToWorld(ofVec3f(x,y,0.0));
   ofRay ray(cam.getPosition(),screenToWorld - cam.getPosition());

PxRaycastBuffer hit1;
    bool intersection = false;
    float t = 0;
       intersection = ray.calcPlaneIntersection(ofVec3f(0,0,0), ofVec3f(0,0,1), &t);
    if (intersection) {
     ofVec3f sTw=cam.getPosition();
     ofVec3f mTw= ray.calcPosition(t);
   orig= PxVec3(sTw[0], sTw[1], sTw[2]);//PxVec3(0.0f);
    dir = PxVec3(mTw[0], mTw[1], mTw[2]);

   bool status =   gScene->raycast(orig, dir.getNormalized(), length, hit1, PxHitFlag::eDEFAULT, fd);
     if (status)

        hit0 = hit1.block;
    if( hit0.shape )
    {
        const char* shapeName = hit0.shape->getName();
        if(shapeName)

        PxRigidActor* actor = hit0.actor;
            PX_ASSERT(actor);

            mSelectedActor = static_cast<PxRigidActor*>(actor->is<PxRigidDynamic>());
            gSelectedActor = static_cast<PxRigidDynamic*>(actor->is<PxRigidDynamic>());
    }
}

On scene of 200 obj i succed pick just one or two, so i guess the space conversion is wrong.

Any suggestions ?

ps: did you succed to pick model just with Physx and Glut (from SDK exemples), using ViewProject() , ViewUnProject() ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles