My plugin works but not correct. After that i try'd the original TSX and it does the sample failure. That brings me to the point:
Who can help to bring this in a right working plugin? This here is the function which is called when left clicking the TSX Button (original C++):
Code: Select all
// this function will be called when the tSX button is left-clicked
int tsxOnLeftClick()
{
// Put at beginning of exported functions if using MFC
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
// this is a very simple plugin, we're not going to launch a dialog
// first get the active view settings
CtsxVector3f ViewLocation;
tsxAViewGetPosition(&ViewLocation);
CtsxVector3f ViewDirection;
tsxAViewGetDirection(&ViewDirection);
float ViewBankAngle = tsxAViewGetBankAngle();
float ViewZoom = tsxAViewGetZoom();
// now create a camera
tsxCameraCreateInScene();
//tsxSceneAddObject((tsxGNODE*)tsxCreateCube(1,1,1,2), e_tsxTRUE);
// and select it
tsxGNODE *pCamera = (tsxGNODE*)tsxGetCurrentSelection();
PlaceCamera(pCamera, ViewLocation, ViewDirection, ViewBankAngle);
// and zoom it
CtsxVector3f CamSize;
CamSize.x = 0.5f;
CamSize.y = 1.0f;
CamSize.z = ViewZoom;
tsxGNodeSetSize(pCamera, &CamSize);
// finally, make the active view look through our new camera object
//tsxAViewSetCameraMode(pCamera);
// and refresh the view
tsxAViewRefresh();
return tsxPLUG_DONE;
}
Code: Select all
// based on code from the Renderman Companion
void PlaceCamera(tsxGNODE *pCamera, CtsxVector3f position, CtsxVector3f direction, float bank)
{
CtsxVector3f axis = { 0.f,1.f,0.f };
CtsxVector3f center = { 0.f,0.f,0.f };
tsxGNodeRotate(pCamera, ¢er, &axis, -bank, e_tsxWorldFrame);
double xzlen, yzlen, xrot, yrot;
if ( (direction.x == 0) && (direction.y == 0) && (direction.z == 0) )
return;
xzlen = sqrt(direction.x * direction.x + direction.z * direction.z);
if (xzlen == 0)
if (direction.y < 0)
yrot = 180;
else
yrot = (direction.y < 0) ? 180 : 0;
else
yrot = 180*acos(direction.z / xzlen) / M_PI;
yzlen = sqrt(direction.y * direction.y + xzlen * xzlen);
xrot = 180 * acos(xzlen/yzlen) / M_PI;
if (direction.y > 0)
{
axis.x = 1.0f;
axis.y = 0.0f;
axis.z = 0.0f;
tsxGNodeRotate(pCamera, ¢er, &axis, (float)xrot, e_tsxWorldFrame);
}
else
{
axis.x = 1.0f;
axis.y = 0.0f;
axis.z = 0.0f;
tsxGNodeRotate(pCamera, ¢er, &axis, (float)(-xrot), e_tsxWorldFrame);
}
if (direction.x > 0)
{
axis.x = 0.0f;
axis.y = 0.0f;
axis.z = 1.0f;
tsxGNodeRotate(pCamera, ¢er, &axis, (float)(-yrot), e_tsxWorldFrame);
}
else
{
axis.x = 0.0f;
axis.y = 0.0f;
axis.z = 1.0f;
tsxGNodeRotate(pCamera, ¢er, &axis, (float)yrot, e_tsxWorldFrame);
}
tsxGNodeSetLocation(pCamera, &position);
}