- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[sell=5]
[pcode=cpp,true]//////////////////////////////////////////////////////////////////////////
void ms2ps( AcDbViewport*pVp, AcGeMatrix3d &resultMat)
{
// first get all the data
AcGeVector3d viewDirection = pVp->viewDirection();
AcGePoint2d centre2d = pVp->viewCenter();
AcGePoint3d viewCenter = AcGePoint3d( centre2d.x, centre2d.y, 0);
AcGePoint3d viewTarget = pVp->viewTarget ();
double twistAngle = -pVp->twistAngle();
AcGePoint3d centerPoint = pVp->centerPoint();
double viewHeight = pVp->viewHeight();
double height = pVp->height();
double width = pVp->width();
double scaling = viewHeight / height;
double lensLength = pVp->lensLength();
// prepare the transformation
AcGeVector3d xAxis, yAxis, zAxis;
zAxis = viewDirection.normal();
xAxis = AcGeVector3d::kZAxis.crossProduct( viewDirection );
if( !xAxis.isZeroLength() ) {
xAxis.normalize();
yAxis = zAxis.crossProduct( xAxis );
} else if( zAxis.z < 0 ) {
xAxis = -AcGeVector3d::kXAxis;
yAxis = AcGeVector3d::kYAxis;
zAxis = -AcGeVector3d::kZAxis;
} else {
xAxis = AcGeVector3d::kXAxis;
yAxis = AcGeVector3d::kYAxis;
zAxis = AcGeVector3d::kZAxis;
}
AcGeMatrix3d dcs2wcs; // display coordinate system (DCS) to world coordinate system (WCS)
AcGeMatrix3d ps2Dcs; // paperspace to DCS
// First initialise with a transformation to centerPoint
ps2Dcs = AcGeMatrix3d::translation( AcGePoint3d::kOrigin - centerPoint);
// then scale for the view
ps2Dcs = ps2Dcs * AcGeMatrix3d::scaling( scaling, centerPoint);
// then adjust to the viewCenter
dcs2wcs = AcGeMatrix3d::translation( viewCenter - AcGePoint3d::kOrigin);
// Then transform for the view direction
AcGeMatrix3d matCoords;
matCoords.setCoordSystem( AcGePoint3d::kOrigin, xAxis, yAxis, zAxis);
dcs2wcs = matCoords * dcs2wcs;
// Then adjust for the viewTarget
dcs2wcs = AcGeMatrix3d::translation( viewTarget - AcGePoint3d::kOrigin) * dcs2wcs;
// Then the twist angle
dcs2wcs = AcGeMatrix3d::rotation(twistAngle, zAxis, viewTarget ) *dcs2wcs;
AcGeMatrix3d perspMat;
if( pVp->isPerspectiveOn())
{
// we do special perspective handling
double viewSize = viewHeight;
double aspectRatio = width / height;
double adjustFactor = 1.0 / 42.0;
double adjustedLensLength = viewSize * lensLength * sqrt ( 1.0 +
aspectRatio * aspectRatio ) * adjustFactor;
double eyeDistance = viewDirection.length();
double lensDistance = eyeDistance - adjustedLensLength;
double ed = eyeDistance;
double ll = adjustedLensLength;
double l = lensDistance;
perspMat.entry[2][2] = (ll - l ) / ll;
perspMat.entry[2][3] = l * ( ed - ll ) / ll;
perspMat.entry[3][2] = -1.0 / ll;
perspMat.entry[3][3] = ed / ll;
}
resultMat = ps2Dcs.inverse() * perspMat * dcs2wcs.inverse();
}
//////////////////////////////////////////////////////////////////////////
void ps2ms ( AcDbViewport*pVp, AcGeMatrix3d &resultMat )
{
// Keep life simple, just invert the other way
AcGeMatrix3d mat;
ms2ps( pVp, mat );
resultMat = mat.inverse();
return;
}
[/pcode]
[/sell] |
评分
-
查看全部评分
|