I can't use single class from AutoCAD API, only from Teigha.netClassic.
You can find AbstractViewportData class in Teigha.DatabaseServices namespace.
var basePoints = new Point3dCollection
{
new Point3d(
-abstractViewportData.FieldWidth / 2,
-abstractViewportData.FieldHeight / 2,
0),
new Point3d(
abstractViewportData.FieldWidth / 2,
-abstractViewportData.FieldHeight / 2,
0),
new Point3d(
abstractViewportData.FieldWidth / 2,
abstractViewportData.FieldHeight / 2,
0),
new Point3d(
-abstractViewportData.FieldWidth / 2,
abstractViewportData.FieldHeight / 2,
0)
};
var baseOfParallelepiped = new Polyline3d(Poly3dType.SimplePoly, basePoints, true);
AttachEntityToModelSpace(baseOfParallelepiped);
var projectionPlane =
new Plane(viewport.ViewTarget, viewport.ViewDirection);
var projectionCS = projectionPlane.GetCoordinateSystem();
var transMatrix = Matrix3d.AlignCoordinateSystem(
Point3d.Origin,
Vector3d.XAxis,
Vector3d.YAxis,
Vector3d.ZAxis,
projectionCS.Origin,
projectionCS.Xaxis,
projectionCS.Yaxis,
projectionCS.Zaxis);
baseOfParallelepiped.TransformBy(transMatrix);
AttachEntityToModelSpace(baseOfParallelepiped);
The code from above generates the black rectangle, which is situated in the correct plane actually, but its center is not where it should be. It should be in the place of the red one, which is drawn by myself to show what's wrong. The problem is somewhere in transformations, maybe I have to add some translation but I don't see yet what exactly it should be.