not implemented guQuat funcs and others.

Post Reply
ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

not implemented guQuat funcs and others.

Post by ozzyyzzo » Tue Jun 09, 2009 2:39 pm

i've noticed that :

MTXQuat (not implemented, even N's one is buggy)
QUATSlerp (not implemented)
QUATMtx (not implemented)
QUATMultiply (buggy C version and ps not implemented)

MTXInvXpose (not implemented)

now i'm a happy devkitpro user and i have ported my stuff
would you be interested by the C versions that works?

i guess you would prefer the assembly optimised but i can't help for that sorry..

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: not implemented guQuat funcs and others.

Post by WinterMute » Wed Jun 10, 2009 12:54 am

We're more than happy to consider patches to libogc, ideally these should be supplied as a diff against latest svn.

https://sourceforge.net/tracker/?group_ ... tid=668553
Help keep devkitPro toolchains free, Donate today

Personal Blog

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: not implemented guQuat funcs and others.

Post by shagkur » Mon Jun 15, 2009 4:03 pm

Hi,

first of all: Thanks for the patch. I've taken a look thru and there're a few questions i've.

What's the desired result for Normalize? I see you calculate the dot-product/scale from the source quaternion but then just multiply the "unit" quaternion with the scale value. Isn't the "unit" quaternion meant to be the destination quaternion? Or does it already contain meaningful values? For my understanding of normalization of vectors/quaternions you calculate the dot-product/scale from the vector/quaternion and multiply this vector/quaternion with the scaler and hence get the normalized variant of it.

For the QuatMtx & MtxQuat i'd like to ask you if the variants below would do the trick too (i've to admit that i'm not very well at quaternion calculations, but those would make my life easier to build the PS assembly versions of it).

QuatMtx:

Code: Select all

			m(0,0) = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
			m(0,1) = 2.0f*X*Y - 2.0f*Z*W;
			m(0,2) = 2.0f*X*Z + 2.0f*Y*W;
			m(0,3) = 0.0f;

			m(1,0) = 2.0f*X*Y + 2.0f*Z*W;
			m(1,1) = 1.0f - 2.0f*X*X - 2.0f*Z*Z;
			m(1,2) = 2.0f*Z*Y - 2.0f*X*W;
			m(1,3) = 0.0f;

			m(2,0) = 2.0f*X*Z - 2.0f*Y*W;
			m(2,1) = 2.0f*Z*Y + 2.0f*X*W;
			m(2,2) = 1.0f - 2.0f*X*X - 2.0f*Y*Y;
			m(2,3) = 0.0f;

			m(3,0) = 0.0f;
			m(3,1) = 0.0f;
			m(3,2) = 0.0f;
			m(3,3) = 1.0f;
MtxQuat:

Code: Select all

			const f32 diag = mat(0,0) + mat(1,1) + mat(2,2) + 1;

			if(diag>0.0f) {
				const f32 scale = sqrtf32(diag)*2.0f;

				X = (mat(1,2) - mat(2,1))/scale;
				Y = (mat(2,0) - mat(0,2))/scale;
				Z = (mat(0,1) - mat(1,0))/scale;
				W = 0.25f*scale;
			} else {
				if(mat(0,0)>mat(1,1) && mat(0,0)>mat(2,2)) {
					const f32 scale = sqrtf32(1.0f + mat(0,0) + mat(1,1) + mat(2,2))*2.0f;

					X = 0.25f*scale;
					Y = (mat(1,0) + mat(0,1))/scale;
					Z = (mat(0,2) + mat(2,0))/scale;
					W = (mat(1,2) - mat(2,1))/scale;
				} else if(mat(1,1)>mat(2,2)) {
					const f32 scale = sqrtf32(1.0f + mat(0,0) + mat(1,1) + mat(2,2))*2.0f;

					X = (mat(1,0) + mat(0,1))/scale;
					Y = 0.25f*scale;
					Z = (mat(2,1) + mat(1,2))/scale;
					W = (mat(2,0) - mat(0,2))/scale;
				} else {
					const f32 scale = sqrtf32(1.0f + mat(0,0) + mat(1,1) + mat(2,2))*2.0f;

					X = (mat(2,0) + mat(0,2))/scale;
					Y = (mat(2,1) + mat(1,2))/scale;
					Z = 0.25f*scale;
					W = (mat(0,1) - mat(1,0))/scale;
				}
			}
			return normalize();
Code is taken from IrrLichts implementation. Probably needs to be right ordered for the access of the matrix elements.

regards
shagkur

PS: when this all is done in C i'll write down the assembly versions of it.

ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

Re: not implemented guQuat funcs and others.

Post by ozzyyzzo » Mon Jun 15, 2009 8:41 pm

Hello,

//Damn me here is the correction :)
void c_guQuatNormalize ( Quaternion* src, Quaternion* unit )
{
f32 dot,scale;

dot = (src->x * src->x) + (src->y * src->y) + (src->z * src->z) + (src->w * src->w);
if (dot == 0.f)
return;

scale = 1.f / sqrtf(dot);

//Of course there was a very bad affectation here ^^
unit->x = src->x * scale;
unit->y = src->y * scale;
unit->z = src->z * scale;
unit->w = src->w * scale;
}

I'll test your Quat->Mtx->Quat asap :)

ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

Re: not implemented guQuat funcs and others.

Post by ozzyyzzo » Mon Jun 15, 2009 9:52 pm

Hello,

Ok both versions are giving similar results.
here are right ordered Mtx versions:

for quatMtx:
const f32 diag = guMtxRowCol(m,0,0) + guMtxRowCol(m,1,1) + guMtxRowCol(m,2,2) + 1;

if(diag>0.0f) {
const f32 scale = sqrtf(diag)*2.0f;

quat->x = (guMtxRowCol(m,2,1) - guMtxRowCol(m,1,2))/scale;
quat->y = (guMtxRowCol(m,0,2) - guMtxRowCol(m,2,0))/scale;
quat->z = (guMtxRowCol(m,1,0) - guMtxRowCol(m,0,1))/scale;
quat->w = 0.25f*scale;
} else {
if(guMtxRowCol(m,0,0)>guMtxRowCol(m,1,1) && guMtxRowCol(m,0,0)>guMtxRowCol(m,2,2)) {
const f32 scale = sqrtf(1.0f + guMtxRowCol(m,0,0) + guMtxRowCol(m,1,1) + guMtxRowCol(m,2,2))*2.0f;

quat->x = 0.25f*scale;
quat->y = (guMtxRowCol(m,0,1) + guMtxRowCol(m,1,0))/scale;
quat->z = (guMtxRowCol(m,2,0) + guMtxRowCol(m,0,2))/scale;
quat->w = (guMtxRowCol(m,2,1) - guMtxRowCol(m,1,2))/scale;
} else if(guMtxRowCol(m,1,1)>guMtxRowCol(m,2,2)) {
const f32 scale = sqrtf(1.0f + guMtxRowCol(m,0,0) + guMtxRowCol(m,1,1) + guMtxRowCol(m,2,2))*2.0f;

quat->x = (guMtxRowCol(m,0,1) + guMtxRowCol(m,1,0))/scale;
quat->y = 0.25f*scale;
quat->z = (guMtxRowCol(m,1,2) + guMtxRowCol(m,2,1))/scale;
quat->w = (guMtxRowCol(m,0,2) - guMtxRowCol(m,2,0))/scale;
} else {
const f32 scale = sqrtf(1.0f + guMtxRowCol(m,0,0) + guMtxRowCol(m,1,1) + guMtxRowCol(m,2,2))*2.0f;

quat->x = (guMtxRowCol(m,0,2) + guMtxRowCol(m,2,0))/scale;
quat->y = (guMtxRowCol(m,1,2) + guMtxRowCol(m,2,1))/scale;
quat->z = 0.25f*scale;
quat->w = (guMtxRowCol(m,1,0) - guMtxRowCol(m,0,1))/scale;
}
}
guQuatNormalize ( (Quaternion*) quat, (Quaternion*) quat);


for guMtxQuat: (warning undefined translation part here)

guMtxRowCol(m0,0,0) = 1.0f - 2.0f*q0->y*q0->y - 2.0f*q0->z*q0->z;
guMtxRowCol(m0,1,0) = 2.0f*q0->x*q0->y - 2.0f*q0->z*q0->w;
guMtxRowCol(m0,2,0) = 2.0f*q0->x*q0->z + 2.0f*q0->y*q0->w;

guMtxRowCol(m0,0,1) = 2.0f*q0->x*q0->y + 2.0f*q0->z*q0->w;
guMtxRowCol(m0,1,1) = 1.0f - 2.0f*q0->x*q0->x - 2.0f*q0->z*q0->z;
guMtxRowCol(m0,2,1) = 2.0f*q0->z*q0->y - 2.0f*q0->x*q0->w;

guMtxRowCol(m0,0,2) = 2.0f*q0->x*q0->z - 2.0f*q0->y*q0->w;
guMtxRowCol(m0,1,2) = 2.0f*q0->z*q0->y + 2.0f*q0->x*q0->w;
guMtxRowCol(m0,2,2) = 1.0f - 2.0f*q0->x*q0->x - 2.0f*q0->y*q0->y;


now good luck with the assembly version! ^^

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: not implemented guQuat funcs and others.

Post by shagkur » Tue Jun 16, 2009 4:39 pm

Hi,

thanks alot for having a look at it. :)
I've added so far all the C version of those quaternion functions.
Additionally i also added PS version for QuatMultiply,QuatNormalize & QuatInverse.
So still missing is QuatMtx & MtxQuat as this will take a bit of time to do so. ;)

I'd be glad if you could test the PS version i just added. Just call the like them now without any prefix, i.e. guQuatNormalize.

regards
shagkur

ozzyyzzo
Posts: 19
Joined: Wed Jun 03, 2009 7:23 pm
Location: greece

Re: not implemented guQuat funcs and others.

Post by ozzyyzzo » Tue Jun 23, 2009 8:38 pm

Hello,

Tested guxxx implementations using 23/06/09 SVN version.
It seems all fine from my side ^^

Would be nice to get guQuatSlerp implemented aswell.
The MtxInvXPose optimised assembly version would also be neat for lighting (normals, envmap and so on)

Let us know when full optimised versions will be available eh? :)

cheers!

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: not implemented guQuat funcs and others.

Post by shagkur » Wed Jun 24, 2009 2:23 pm

Hi,

i'm working on them... ;)
Will come back as soon as i got them.

regards
shagkur

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests