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

projectionMatrix of Current Viewport

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
620 Views, 2 Replies

projectionMatrix of Current Viewport

I have written the following code to get the projectionMatrix of the current viewport.

AcDbObjectId curVportId = acedActiveViewportId();

AcDbObjectPointer curVport (curVportId,AcDb::kForRead);

AcGsView *currentGSV = curVport->gsView();

AcGeMatrix3d currProjMat3D = currentGSV->projectionMatrix();

But the problem is that curVport->gsView() is assigning NULL to AcGsView *currentGSV .

Thus I can't move ahead. Can any body help me out .
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

If you must have an AcGsView to work with then use acgsGetGsView passing in "true" for the bCreateIfNone parameter.

However, the necessary information for calculating the projection matrix is available without using an AcGsView if you dig around in the ARX help files. What you need is the device's width and height (in the device coordinate system), the camera to target distance (in world coordinates), and whether or not the projection is orthographic or perspective.

Once you have that info, the projection matrix calculation is as follows...

AcGeMatrix3d
getProjectionMatrix
(
double dcsWidth,
double dcsHeight,
double wcsCameraToTargetDistance,
bool isPerspective
)
{
AcGeMatrix3d xform;
xform(0, 0) = 2.0 / dcsWidth;
xform(1, 1) = 2.0 / dcsHeight;
if (isPerspective)
{
xform(2, 2) = xform(3, 2) = 1.0 / wcsCameraToTargetDistance;
}
else // if projection is orthographic.
{
xform(2, 2) = 0.1 / wcsCameraToTargetDistance;
}
return xform;
}


That should give you the same projection matrix as AcGsView::projectionMatrix().



Regards,
Andy F.
Message 3 of 3
Anonymous
in reply to: Anonymous

Thank You Very much Sir. Your code is really helpfull.

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

Post to forums  

Autodesk Design & Make Report

”Boost