How to get cureent view port camera position and projection matrices?

How to get cureent view port camera position and projection matrices?

Anonymous
Not applicable
2,567 Views
6 Replies
Message 1 of 7

How to get cureent view port camera position and projection matrices?

Anonymous
Not applicable

Hello, How to get current view port camera position and projection? How to capture event, when view port camera is changed? For example user use command zoom or move and camera parameters is changed. How to get this event?  Thank you in advance.

0 Likes
Accepted solutions (1)
2,568 Views
6 Replies
Replies (6)
Message 2 of 7

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

#1 the current(active) view transform is getviewtm() or viewport.gettm()

 

#2 general callbacks - #viewportchanged

Message 3 of 7

Anonymous
Not applicable

Thank you, it helps me 

0 Likes
Message 4 of 7

Anonymous
Not applicable

I use following algorithm to get current view camera.

 

	//get current view port
        ViewExp *viewPort = &GetCOREInterface()->GetActiveViewExp();

	GraphicsWindow *gw = viewPort->getGW();

        //register redraw call
	GetCOREInterface()->RegisterRedrawViewsCallback(&pccb);
	
	float mat[4][4];//The transformation matrix times the projection matrix.
	Matrix3 invTM;//This is the inverse of the affine part of the camera transformation matrix
	int persp;//Nonzero indicates this is a perspective view; 0 is orthogonal.
	float hither;//Near clip value.
	float yon;//Far clip value. 


	gw->getCameraMatrix(mat, &invTM, &persp, &hither, &yon);

 

I try render scene with camera projection matrix ("mat"), but Y and Z coordinates are reversedt. what might be happened:Image 2.jpg

0 Likes
Message 5 of 7

Anonymous
Not applicable

If I use cm->SetCoordSystem(IGameConversionManager::IGAME_MAX); all is ok

0 Likes
Message 6 of 7

omidt_gh
Enthusiast
Enthusiast

How possibly that's going to help, what you asked and write is in C++ SDK and the answer you accept is written in MaxScript !!!! ????

0 Likes
Message 7 of 7

omidt_gh
Enthusiast
Enthusiast

This is the correct answer in C++ SDK

First, you need to get the view and camera view from it and then use the data you need to.

 

float FOV = 0;
float focaldistance = 0;
Interval ivalid = FOREVER;
Matrix3 aTM, coordSysTM; // affine and invert affine
Matrix3 invTM; //This is the inverse of the affine part of the camera transformation matrix

Point3 viewDir;
float mat[4][4]; //The transformation matrix times the projection matrix.
int persp; //Nonzero indicates this is a perspective view; 0 is orthogonal.
float hither; //Near clip value.
float yon; //Far clip value. 

//get current viewport
ViewExp *viewPort = &GetCOREInterface()->GetActiveViewExp();

GraphicsWindow *gw = viewPort->getGW();
FOV = viewPort->GetFOV() * 180 / PI;
focaldistance = viewPort->GetFocalDist();

// The affine TM transforms from world coords to view coords
// so we need the inverse of this matrix
viewPort->GetAffineTM(aTM);
coordSysTM = Inverse(aTM); // if you need the parameters to be inverted
// The Z axis of this matrix is the view direction.
viewDir = coordSysTM.GetRow(2);

gw->getCameraMatrix(mat, &invTM, &persp, &hither, &yon);

 

 

0 Likes