| 103 | } |
| 104 | |
| 105 | bool Picking::pick(int x, int y) |
| 106 | { |
| 107 | PxScene& scene = mFrame.getActiveScene(); |
| 108 | |
| 109 | PxVec3 rayOrig, rayDir; |
| 110 | computeCameraRay(rayOrig, rayDir, x, y); |
| 111 | |
| 112 | // raycast rigid bodies in scene |
| 113 | PxRaycastHit hit; hit.shape = NULL; |
| 114 | PxRaycastBuffer hit1; |
| 115 | scene.raycast(rayOrig, rayDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION); |
| 116 | hit = hit1.block; |
| 117 | |
| 118 | if(hit.shape) |
| 119 | { |
| 120 | const char* shapeName = hit.shape->getName(); |
| 121 | if(shapeName) |
| 122 | shdfnd::printFormatted("Picked shape name: %s\n", shapeName); |
| 123 | |
| 124 | PxRigidActor* actor = hit.actor; |
| 125 | PX_ASSERT(actor); |
| 126 | mSelectedActor = static_cast<PxRigidActor*>(actor->is<PxRigidDynamic>()); |
| 127 | if(!mSelectedActor) |
| 128 | mSelectedActor = static_cast<PxRigidActor*>(actor->is<PxArticulationLink>()); |
| 129 | |
| 130 | //ML::this is very useful to debug some collision problem |
| 131 | PxTransform t = actor->getGlobalPose(); |
| 132 | PX_UNUSED(t); |
| 133 | shdfnd::printFormatted("id = %i\n PxTransform transform(PxVec3(%f, %f, %f), PxQuat(%f, %f, %f, %f))\n", reinterpret_cast<size_t>(actor->userData), t.p.x, t.p.y, t.p.z, t.q.x, t.q.y, t.q.z, t.q.w); |
| 134 | } |
| 135 | else |
| 136 | mSelectedActor = 0; |
| 137 | |
| 138 | if(mSelectedActor) |
| 139 | { |
| 140 | shdfnd::printFormatted("Actor '%s' picked! (userData: %p)\n", mSelectedActor->getName(), mSelectedActor->userData); |
| 141 | |
| 142 | //if its a dynamic rigid body, joint it for dragging purposes: |
| 143 | grabActor(hit.position, rayOrig); |
| 144 | } |
| 145 | |
| 146 | #ifdef VISUALIZE_PICKING_RAYS |
| 147 | Ray ray; |
| 148 | ray.origin = rayOrig; |
| 149 | ray.dir = rayDir; |
| 150 | mRays.push_back(ray); |
| 151 | #endif |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | //----------------------------------------------------------------------------// |
nothing calls this directly
no test coverage detected