(got it) D3DXVec3TransformCoord & D3DXMatrixRotationAxis

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Stellar
Posts: 48
Joined: Mon Dec 12, 2005 9:13 am

(got it) D3DXVec3TransformCoord & D3DXMatrixRotationAxis

Post by Stellar »

I didnt know if there were higher level functions already written for this, but if not, i did it from scratch :)

D3DXMATRIX * D3DXMatrixRotationAxis(
D3DXMATRIX * pOut,
CONST D3DXVECTOR3 * pV,
FLOAT Angle
);

D3DXVECTOR3 * D3DXVec3TransformCoord(
D3DXVECTOR3 * pOut,
CONST D3DXVECTOR3 * pV,
CONST D3DXMATRIX * pM
);

____________________________________________

UPDATE: this is what i got for transform

Code: Select all

ScePspFVector3 Vector3TransformCoord(
	ScePspFVector3 vector,
	ScePspFMatrix4 matrix
)
{
	ScePspFVector3 temp;

	temp.x = matrix.x.x * vector.x + matrix.x.y * vector.y + matrix.x.z * vector.z;
	temp.y = matrix.y.x * vector.x + matrix.y.y * vector.y + matrix.y.z * vector.z;
	temp.z = matrix.z.x * vector.x + matrix.z.y * vector.y + matrix.z.z * vector.z;

	return temp;
}
and heres the code for rotate, but i havent tried the functions yet.

Code: Select all

ScePspFMatrix4 XlMatrixRotationAxis(
	ScePspFVector3 vector,
	float angle 
)
{
	ScePspFMatrix4 temp;

	float sin_a = sin( angle );
	float cos_a = cos( angle );

	float x_y = vector.x * vector.y;
	float x_z = vector.x * vector.z;
	float y_z = vector.y * vector.z;

	temp.x.x = 1 + ( 1 - cos_a ) * ( vector.x * vector.x - 1 );
	temp.x.y = -vector.z * sin_a + ( 1 - cos_a ) * x_y; 	
	temp.x.z =  vector.y * sin_a + ( 1 - cos_a ) * x_z;
	temp.x.w = 0;
	
	temp.y.x =  vector.z * sin_a + ( 1 - cos_a ) * x_y;
	temp.y.y = 1 + ( 1 - cos_a ) * ( vector.y * vector.y - 1 );
	temp.y.z = -vector.x * sin_a + ( 1 - cos_a ) * y_z;
	temp.y.z = 0;

	temp.z.x = -vector.y * sin_a + ( 1 - cos_a ) * x_z;
	temp.z.y =  vector.x * sin_a + ( 1 - cos_a ) * y_z;
	temp.z.z = 1 + ( 1 - cos_a ) * ( vector.z * vector.z -1 );
	temp.z.w = 0;
	
	temp.w.x = 0;			
	temp.w.y = 0;
	temp.w.z = 0;
	temp.w.w = 1;

	return temp;
}

thanks,
-stellar
Image
Post Reply