.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

why using viewport.twistangle affects viewport.viewcenter

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mohamedalmaz6
216 Views, 3 Replies

why using viewport.twistangle affects viewport.viewcenter

i am trying to rotate ucs to algine with rotated rectangle in modelspace but when using viewport.twistangle it affects viewport.viewcenter although it algin with center of view if i didnot use viewport.twist angle ot the angle is zero (horizontal rectangle as example)

 

 

 

    Autodesk.AutoCAD.DatabaseServices.ObjectId vpid = layout1.GetViewports()[1];

    Viewport vp = ts.GetObject(vpid, OpenMode.ForWrite) as Viewport;

    var WCS2DCS =
Matrix3d.WorldToPlane(vp.ViewDirection) *
Matrix3d.Displacement(vp.ViewTarget.GetAsVector().Negate()) *
Matrix3d.Rotation(vp.TwistAngle, vp.ViewDirection, vp.ViewTarget);


    var centertrans = centerpoint.TransformBy(WCS2DCS);

    double vpRatio = vp.Width / vp.Height;
    double extWidth = width;
    double extHeight = height;
    double extRatio = extWidth / extHeight;
    double scale = extRatio < vpRatio ? vp.Height / extHeight : vp.Width / extWidth;
    vp.TwistAngle = Math.PI * 2 - angle;
    vp.ViewCenter = new Point2d(centertrans.X, centertrans.Y);
    vp.ViewDirection = Vector3d.ZAxis;
    vp.CustomScale=scale;

 

 

 

@_gile 

 

3 REPLIES 3
Message 2 of 4
_gile
in reply to: mohamedalmaz6

Hi,

What about setting the Viewport.TwistAngle before computing the WCS2DCS matrix?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4
mohamedalmaz6
in reply to: _gile

yes your idea has worked

thanks gile

but why it affects it 

how just computing the transformation matirx overwrite anything

  

Message 4 of 4
_gile
in reply to: mohamedalmaz6


@mohamedalmaz6 wrote:

yes your idea has worked

thanks gile

but why it affects it 

how just computing the transformation matirx overwrite anything


If you attentively read the transformation matrix code, you can see it is built from the the viewport ViewDirection, ViewTarget and TwistAngle values. That's why you have to set these properties before building the transformation matrix and use it to transform the 'centerpoint'.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta