void UmlDesktop::limitsize_move(QWidget * who, QSize & previous, double max_w, double max_h) { if (previous.width() > 0) who->resize(previous); else { int wi = (int)(w * max_w); int he = (int)(h * max_h); // warning who->width() or who->height() // may be greater than the reality if ((who->width() > wi) || (who->height() > he)) { previous.setWidth((who->width() > wi) ? wi : who->width()); previous.setHeight((who->height() > he) ? he : who->height()); who->resize(previous); } } if (fixedp) tocenter(who); // under Windows the dialog may go out of the screen else who->move(QCursor::pos()); }
void UmlDesktop::setsize_center(QWidget * who, QSize & previous, double pw, double ph) { if (previous.width() <= 0) { previous.setWidth((int)(w * pw)); previous.setHeight((int)(h * ph)); } who->resize(previous); if (fixedp) tocenter(who); }
void UmlDesktop::limitsize_center(QWidget * who, QSize & previous, double max_w, double max_h) { if (previous.width() > 0) who->resize(previous); else { int wi = (int)(w * max_w); int he = (int)(h * max_h); // warning who->width() or who->height() // may be greater than the reality if ((who->width() > wi) || (who->height() > he)) { previous.setWidth((who->width() > wi) ? wi : who->width()); previous.setHeight((who->height() > he) ? he : who->height()); who->resize(previous); } } if (fixedp) tocenter(who); }
bool ViewableSphere::QuickIntersectTest( const VectorR3& viewPos, const VectorR3& viewDir, double maxDist, double *intersectDistance, const VectorR3& centerPos, double radiusSq ) { VectorR3 tocenter(centerPos); tocenter -= viewPos; // Vector view position to the center // D = Distance to pt on view line closest to sphere // v = vector from sphere center to the closest pt on view line // ASq = the distance from v to sphere center squared double D = (viewDir^tocenter); VectorR3 v(viewDir); v *= D; v -= tocenter; double ASq = v.NormSq(); // Ray-line completely misses sphere, or just grazes it. if ( ASq >= radiusSq ) { return false; } double BSq = radiusSq-ASq; if ( D>0.0 && D*D>BSq && (D<maxDist || BSq>Square(D-maxDist) ) ) { // It hits the sphere as it enters. *intersectDistance = D-sqrt(BSq); return true; } else if ( (D>0.0 || D*D<BSq) && D<maxDist && BSq<Square(D-maxDist) ) { // it hits the sphere as it exits *intersectDistance = D+sqrt(BSq); return true; } else { return false; } }
// Returns an intersection if found with distance maxDistance // viewDir must be a unit vector. // intersectDistance and visPoint are returned values. bool ViewableSphere::FindIntersectionNT ( const VectorR3& viewPos, const VectorR3& viewDir, double maxDist, double *intersectDistance, VisiblePoint& returnedPoint ) const { VectorR3 tocenter(Center); tocenter -= viewPos; // Vector view position to the center // D = Distance to pt on view line closest to sphere // v = vector from sphere center to the closest pt on view line // ASq = the distance from v to sphere center squared double D = (viewDir^tocenter); VectorR3 v(viewDir); v *= D; v -= tocenter; double ASq = v.NormSq(); // Ray-line completely misses sphere, or just grazes it. if ( ASq >= RadiusSq ) { return false; } double BSq = RadiusSq-ASq; if ( D>0.0 && D*D>BSq && (D<maxDist || BSq>Square(D-maxDist) ) ) { // Return the point where view intersects with the outside of // the sphere. *intersectDistance = D-sqrt(BSq); v = viewDir; v *= *intersectDistance; v += viewPos; // Position of intersection returnedPoint.SetPosition( v ); v -= Center; v /= Radius; // Normalize: normal out from intersection pt v.ReNormalize(); returnedPoint.SetNormal( v ); returnedPoint.SetMaterial ( *OuterMaterial ); returnedPoint.SetFrontFace(); // Front face direction CalcUV( v, &(returnedPoint.GetUV()) ); returnedPoint.SetFaceNumber( 0 ); return true; } else if ( (D>0.0 || D*D<BSq) && D<maxDist && BSq<Square(D-maxDist) ) { // return the point where view exits the sphere *intersectDistance = D+sqrt(BSq); v = viewDir; v *= *intersectDistance; v += viewPos; returnedPoint.SetPosition( v ); v -= Center; v /= Radius; // Normalize, but still points outward v.ReNormalize(); // Just in case returnedPoint.SetNormal( v ); returnedPoint.SetMaterial ( *InnerMaterial ); returnedPoint.SetBackFace(); CalcUV( v, &(returnedPoint.GetUV()) ); return true; } else { return false; } }