TS 6.6 SDK sample plugin is wrong - who can help

Smart people ~ Great Scripts
Post Reply
User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

TS 6.6 SDK sample plugin is wrong - who can help

Post by DesignDevil »

I try'd to translate the "viewcam" sample plugin into my FreeBasic code.

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;
}
This is the function which places the cam - i think here is a failure inside.

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, &center, &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, &center, &axis, (float)xrot, e_tsxWorldFrame);
	}
	else
	{
		axis.x = 1.0f;
		axis.y = 0.0f;
		axis.z = 0.0f;
		tsxGNodeRotate(pCamera, &center, &axis, (float)(-xrot), e_tsxWorldFrame);
	}

	if (direction.x > 0)
	{
		axis.x = 0.0f;
		axis.y = 0.0f;
		axis.z = 1.0f;
		tsxGNodeRotate(pCamera, &center, &axis, (float)(-yrot), e_tsxWorldFrame);
	}
	else
	{
		axis.x = 0.0f;
		axis.y = 0.0f;
		axis.z = 1.0f;
		tsxGNodeRotate(pCamera, &center, &axis, (float)yrot, e_tsxWorldFrame);
	}

	tsxGNodeSetLocation(pCamera, &position);
}
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6
User avatar
Johny
Petty Officer First Class
Posts: 53
Joined: 21 May 2009, 17:14

Re: TS 6.6 SDK sample plugin is wrong - who can help

Post by Johny »

do you already got the solution of this problem?

if not, maybe information on this link usefull. ;)

http://www.euclideanspace.com/maths/geo ... /index.htm" onclick="window.open(this.href);return false;
User avatar
DesignDevil
Master Chief Petty Officer
Posts: 500
Joined: 22 May 2009, 08:52
Type the number ten into the box: 0
Location: Neuruppin, Germany, Earth.
Contact:

Re: TS 6.6 SDK sample plugin is wrong - who can help

Post by DesignDevil »

Not yet. Thanks for this Link - looks very informative - i do a bit research ;)
I still use TrueSpace 6.6
Link: My Youtube Channel
Link: www.DesignDevil.de - Plugins, Tutorials and more about TrueSpace 6.6
User avatar
Johny
Petty Officer First Class
Posts: 53
Joined: 21 May 2009, 17:14

Re: TS 6.6 SDK sample plugin is wrong - who can help

Post by Johny »

remmember, when an object create on tS, its default xyz rotation are (0;0;0),

but when a new camera is create, it's default rotation are( -90 ; -90 ; 0) ;)
Image
Post Reply