Jump to content


- - - - -

D3DXVec3TransformCoordArray


9 replies to this topic

#1 wolf

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 11 October 2005 - 02:33 AM

Hi,
I am currently in the process of porting a DirectX application to a platform independent engine.
My biggest time-eater are the D3DX Math functions. Does anybody have a math library that follows the D3DX math library in source?
Currently I am stuck with

D3DXVec3TransformCoordArray()

Any help would be appreciated,
- Wolf

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 11 October 2005 - 03:34 AM

It just takes two arrays of vectors, and transforms each one in the input by a given matrix and stores it in the output.

The only caveats are that the input and output strides may be specified (so when incrementing your pointers, you will need to typecast to unsigned char*, add the stride, and then typecast back to D3DXVECTOR3*); and the function is supposed to project back to w = 1, so divide each vector by its w component after transforming.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 wolf

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 11 October 2005 - 06:52 PM

Find below my current version that should do it.

//
// Transforms a 3D vector by a given matrix, projecting the result back into w = 1.
//
//  similar to D3DXVec3TransformCoord()
//
Vector3 * Vec3TransformCoord(
							 Vector3 * pOut,
							 const Vector3 * pV,
							 const Matrix44 * pM)
{
	float   rhw, x, y, z;

	x = pV->x; y = pV->y; z = pV->z;

	rhw = (x * pM->a.w + y * pM->b.w + z * pM->c.w + pM->d.w);
	if (fabsf(rhw) < EPS5) return NULL;

	rhw = 1.0f / rhw;

	pOut->x = rhw * (x * pM->a.x + y * pM->b.x + z * pM->c.x + pM->d.x);
	pOut->y = rhw * (x * pM->a.y + y * pM->b.y + z * pM->c.y + pM->d.y);
	pOut->z = rhw * (x * pM->a.z + y * pM->b.z + z * pM->c.z + pM->d.z);

	return pOut;
}


//
// Transforms an array (x, y, z, 1) by a given matrix, and projects the result back into w = 1.
//
//  similar to D3DXVec3TransformCoordArrays()
//
Vector3 * Vec3TransformCoordArray(
							 Vector3 * pOut,
							 u32 OutStride,		
							 const Vector3 * pV,
							 u32 VStride,		
							 const Matrix44 * pM,
							 u32 n)
{
	Vector3 * pOutput;
	Vector3 * pVector;
	pOutput = pOut;
	pVector = pV;

	for(u32 i = 0; i < n; i++)
	{
		Vec3TransformCoord(pOutput, pVector, pM);
		pVector+=VStride;
		pOutput+=OutStride;
	}

	return pOut;
}


#4 wolf

    New Member

  • Members
  • PipPip
  • 11 posts

Posted 13 October 2005 - 02:54 AM

uhmm ... actually I meant

Vector3 * Vec3TransformCoordArray(

								  Vector3 * pOut,

								  u32 OutStride,		// [in] Stride between vectors in the output data stream.

								  const Vector3 * pV,

								  u32 VStride,		// [in] Stride between vectors in the input data stream.

								  const Matrix44 * pM,

								  u32 n)

{

	u8 * pOutput;

	const u8 * pVector;

	pOutput = (u8*)pOut;

	pVector = (u8*)pV;


	for(u32 i = 0; i < n; i++)

	{

		Vec3TransformCoord(pOut, pV, pM);

		pVector+=VStride;

		pOutput+=OutStride;

		pOut = (Vector3*)pOutput;

		pV = (Vector3*)pVector;

	}


	return pOut;

}

:-) Wolf

#5 goyal_nitu22

    New Member

  • Members
  • Pip
  • 3 posts

Posted 03 September 2007 - 09:13 AM

Hi Wolf,
I want to know what r these EPS5, u8,u32....
Plz reply as soon as possible.

#6 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 03 September 2007 - 12:33 PM

goyal_nitu22 said:

I want to know what r these EPS5, u8,u32....
EPS5 is an 'epsilon' value; an extremely small value to compare to if you want to know whether a floating-point value should be treated as zero. In this case it's used to avoid division by zero. I'm not sure if Vec3TransformCoord should return NULL in this situation though. u8 is clearly an 8-bit unsigned integer (unsigned char) and u32 an unsigned 32-bit integer (unsigned int).

Quote

Plz reply as soon as possible.
Like in two years? (check the dates)

Seriously now, it is sometimes considered a bit rude to ask for an urgent reply. There are lots of professionals here who visit the forum in their free time and have no obligation to share their knowledge. So show a little patience. Else if there's a particular reason why it's urgent and we should care more about it than our own busy agenda's, please give us an incentive.

#7 goyal_nitu22

    New Member

  • Members
  • Pip
  • 3 posts

Posted 18 September 2007 - 06:52 AM

Thanks a lot Nick it helped me a lot.

#8 goyal_nitu22

    New Member

  • Members
  • Pip
  • 3 posts

Posted 26 September 2007 - 11:05 AM

Hi Nic
Can this code be available in assembly language?If yes plz post it.I have to reduce the time taken by it.It takes somewhat less time than DirectX fn(D3DXVec3TransformCoordArray) but the difference in their time is negligible.
So i want assembly code.I have written it in assembly code but this assembly code takes more time than the c++ code.Plz help me.

#9 njdewit

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 September 2007 - 04:05 PM

Try and optimize it using SIMD and take a look at the cache-friendliness of what you're doing. But perhaps it's wise to stick to C++, given the circumstances. And what's the reason you're performing so many transformations (otherwise the speed of this particular function would not be an issue)? Nothing to do about that?

That aside, you're being rather rude. You can ask for assistance but nobody's here to do your job.

#10 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 26 September 2007 - 06:22 PM

I know of optimized code that can process each vector in ~17 cycles, but I am not gonna post post it because it is freely available on the internet. A simple search is all it takes.

Also, as you have proven yourself, translating a function to assembly does not necessarily make it faster, because you have consider memory alignment access, instruction pairing, cache access and so on. Is this function even a bottleneck? Couldn't you do some optimization at a higher level?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users