Пример #1
0
SBezier SBezier::From(Vector4 p0, Vector4 p1) {
    SBezier ret;
//**walter steffe--begin
    Vector pp0=p0.PerspectiveProject();
    Vector pp1=p1.PerspectiveProject();
    TColgp_Array1OfPnt AP(0,1);
    TColStd_Array1OfReal AW(0,1);
    AW.SetValue(0,p0.w);
    AW.SetValue(1,p1.w);
    AP.SetValue(0,gp_Pnt(pp0.x,pp0.y,pp0.z));
    AP.SetValue(1,gp_Pnt(pp1.x,pp1.y,pp1.z));
    gp_Pnt P0=AP.Value(0);
    gp_Pnt P1=AP.Value(1);
    double W0=AW.Value(0);
    double W1=AW.Value(1);
    Vector dpp=pp0.Minus(pp1);
    if(dpp.Magnitude() > 1.e-10)
      ret.hCurve=new Geom_BezierCurve(AP, AW);
//      ret.hCurve=new Geom_BezierCurve(AP);
//**walter steffe--end
    ZERO(&ret);
    ret.deg = 1;
    ret.weight[0] = p0.w;
    ret.ctrl  [0] = p0.PerspectiveProject();
    ret.weight[1] = p1.w;
    ret.ctrl  [1] = p1.PerspectiveProject();
    return ret;
}
Пример #2
0
SBezier SBezier::From(Vector4 p0, Vector4 p1) {
    SBezier ret;
    ZERO(&ret);
    ret.deg = 1;
    ret.weight[0] = p0.w;
    ret.ctrl  [0] = p0.PerspectiveProject();
    ret.weight[1] = p1.w;
    ret.ctrl  [1] = p1.PerspectiveProject();
    return ret;
}
Пример #3
0
SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3) {
    SBezier ret;
    ZERO(&ret);
    ret.deg = 3;
    ret.weight[0] = p0.w;
    ret.ctrl  [0] = p0.PerspectiveProject();
    ret.weight[1] = p1.w;
    ret.ctrl  [1] = p1.PerspectiveProject();
    ret.weight[2] = p2.w;
    ret.ctrl  [2] = p2.PerspectiveProject();
    ret.weight[3] = p3.w;
    ret.ctrl  [3] = p3.PerspectiveProject();
    return ret;
}
Пример #4
0
SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3) {
    SBezier ret;
//**walter steffe--begin
    Vector pp0=p0.PerspectiveProject();
    Vector pp1=p1.PerspectiveProject();
    Vector pp2=p2.PerspectiveProject();
    Vector pp3=p3.PerspectiveProject();
    TColgp_Array1OfPnt AP(0,3);
    TColStd_Array1OfReal AW(0,3);
    AW.SetValue(0,p0.w);
    AW.SetValue(1,p1.w);
    AW.SetValue(2,p2.w);
    AW.SetValue(3,p3.w);
    AP.SetValue(0,gp_Pnt(pp0.x,pp0.y,pp0.z));
    AP.SetValue(1,gp_Pnt(pp1.x,pp1.y,pp1.z));
    AP.SetValue(2,gp_Pnt(pp2.x,pp2.y,pp2.z));
    AP.SetValue(3,gp_Pnt(pp3.x,pp3.y,pp3.z));
    ret.hCurve=new Geom_BezierCurve(AP, AW);
//**walter steffe--end
    ZERO(&ret);
    ret.deg = 3;
    ret.weight[0] = p0.w;
    ret.ctrl  [0] = p0.PerspectiveProject();
    ret.weight[1] = p1.w;
    ret.ctrl  [1] = p1.PerspectiveProject();
    ret.weight[2] = p2.w;
    ret.ctrl  [2] = p2.PerspectiveProject();
    ret.weight[3] = p3.w;
    ret.ctrl  [3] = p3.PerspectiveProject();
    return ret;
}
Пример #5
0
//-----------------------------------------------------------------------------
// Apply a perspective transformation to a rational Bezier curve, calculating
// the new weights as required.
//-----------------------------------------------------------------------------
SBezier SBezier::InPerspective(Vector u, Vector v, Vector n,
                               Vector origin, double cameraTan)
{
    Quaternion q = Quaternion::From(u, v);
    q = q.Inverse();
    // we want Q*(p - o) = Q*p - Q*o
    SBezier ret = this->TransformedBy(q.Rotate(origin).ScaledBy(-1), q, 1.0);
    int i;
    for(i = 0; i <= deg; i++) {
        Vector4 ct = Vector4::From(ret.weight[i], ret.ctrl[i]);
        // so the desired curve, before perspective, is
        //    (x/w, y/w, z/w)
        // and after perspective is
        //    ((x/w)/(1 - (z/w)*cameraTan, ...
        //  = (x/(w - z*cameraTan), ...
        // so we want to let w' = w - z*cameraTan
        ct.w = ct.w - ct.z*cameraTan;

        ret.ctrl[i] = ct.PerspectiveProject();
        ret.weight[i] = ct.w;
    }
    return ret;
}