void MainWindow::OpenProject(const QString &filename) { if (!is_project_open_ || project_widget_->Close()) { QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, "Error", "Could not open file " + filename); } else { QDataStream ds(&file); ds >> *project_; file.close(); ViewProject(filename, true); // Update recent projects. RecentProject recent_project(project_->name(), filename); int ind = recent_projects_.indexOf(recent_project); if (ind != -1) recent_projects_.remove(ind); recent_projects_.insert(0, recent_project); UpdateRecentProjects(true); } }
void Pick(int x, int y) { LetGo(); NxRay ray; ViewUnProject(x, y, 0.0f, ray.orig); ViewUnProject(x, y, 1.0f, ray.dir); ray.dir -= ray.orig; ray.dir.normalize(); NxRaycastHit hit; NxShape* closestShape = gScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit); NxVec3 origin = ray.orig; NxVec3 impact = hit.worldImpact; NxReal distRB = NX_MAX_REAL; if (closestShape && closestShape->getActor().isDynamic()) { distRB = (impact.x - origin.x) * (impact.x - origin.x) + (impact.y - origin.y) * (impact.y - origin.y) + (impact.z - origin.z) * (impact.z - origin.z); } NxVec3 hitcloth, hitRecord; NxU32 vertexId; NxReal distCloth, closest= NX_MAX_REAL; NxU32 indexCloth, indexClothVertex; NxCloth **cloths = gScene->getCloths(); for (NxU32 i = 0; i < gScene->getNbCloths(); i++) { if (cloths[i]->raycast(ray, hitcloth, vertexId)) { distCloth = (hitcloth.x - origin.x) * (hitcloth.x - origin.x) + (hitcloth.y - origin.y) * (hitcloth.y - origin.y) + (hitcloth.z - origin.z) * (hitcloth.z - origin.z); if(distCloth < closest) { closest = distCloth; indexCloth = i; indexClothVertex = vertexId; hitRecord = hitcloth; } } } if (distRB > closest) // Pick cloth { gHitCloth = cloths[indexCloth]; gHitClothVertex = indexClothVertex; int hitx, hity; ViewProject(hitRecord, hitx, hity, gMouseDepth); } else if (distRB < closest) // Pick actor { gHitActor = &closestShape->getActor(); gHitActor->wakeUp(); int hitx, hity; gMouseSphere = CreateSphere(hit.worldImpact, 0.1, 1); gMouseSphere->raiseBodyFlag(NX_BF_KINEMATIC); gMouseSphere->raiseActorFlag(NX_AF_DISABLE_COLLISION); ViewProject(hit.worldImpact, hitx, hity, gMouseDepth); NxDistanceJointDesc desc; desc.actor[0] = gMouseSphere; desc.actor[1] = gHitActor; gMouseSphere->getGlobalPose().multiplyByInverseRT(hit.worldImpact, desc.localAnchor[0]); gHitActor->getGlobalPose().multiplyByInverseRT(hit.worldImpact, desc.localAnchor[1]); desc.spring.damper = 1; desc.spring.spring = 200; desc.flags |= NX_DJF_MAX_DISTANCE_ENABLED | NX_DJF_SPRING_ENABLED; NxJoint* joint = gScene->createJoint(desc); gMouseJoint = (NxDistanceJoint*)joint->is(NX_JOINT_DISTANCE); } }