something wrong with the getXJointNode ?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
cmoibenlepro
Posts: 237
Joined: Thu May 27, 2004 3:18 pm
Location: Canada

Post by cmoibenlepro »

heh, anybody here major in math in college??? HELP!!
I'm not sure if you'll find someone like this in this forum... :(

Did you try to post your question on GameDev or Flipcode?
There are some gurus there, so they might be able to help you to solve your mathematical problem...
generous_donator

Post by generous_donator »

Well, try this:

Change the method slerp of quaternion.h to this

Code: Select all

inline quaternion quaternion::Slerp(quaternion q1, quaternion q2, f32 time)
{
bool bShortestPath=true;
f32 fEpsilon=0.0001f;
f32 fCos = q1.getDotProduct(q2);
f32 fAngle = Math::ACos(fCos);

if ( Math::Abs(fAngle) < fEpsilon ) return q1;

f32 fSin = Math::Sin(fAngle);
f32 fInvSin = 1.0/fSin;
f32 f1 = Math::Sin((1.0-time)*fAngle)*fInvSin;
f32 f2 = Math::Sin(time*fAngle)*fInvSin;
// check invert rotation
if (fCos < 0.0f && bShortestPath)
{
  f1 = -f1;
  quaternion t(f1*q1 + f2*q2);
  t.normalize();
  return t;
}
else
{
  return f1*q1 + f2*q2;
}
}

// maybe you need the copy constructor too???
quaternion (const quaternion& q) { X=q.X; Y=q.Y; Z=q.Z; W=q.W; }


I use an extra Math class with these methods

Code: Select all

/////////////////////////////////
// Some Math stuff
/////////////////////////////////
class Math
{

static inline f32 ACos(float fValue)
{
		f32 val;
		if ( -1.0 < fValue )
		{
			if ( fValue < 1.0 )
				val = f32(acos(fValue));
			else
				val = 0.0f;
		}
		else
		{
			val = PI;
		}
		return val;
}

static inline f32 Abs (f32 fValue) { return f32(fabs(fValue)); }

static inline f32 Sin (f32 fValue) { return f32(sin(fValue)); }


If someone tries this please post here if it's working or not since I have not tried X animation scenenodes by now.

gd
justiceforall
Posts: 5
Joined: Tue Aug 17, 2004 1:07 am

Post by justiceforall »

generous_donator wrote:Well, try this:

If someone tries this please post here if it's working or not since I have not tried X animation scenenodes by now.

gd


But I can not compile it ,there is a lot of error,

\source\include\quaternion.h(419) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
\source\include\quaternion.h(420) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
\source\include\quaternion.h(426) : error C2677: binary '*' : no global operator defined which takes type 'class irr::core::quaternion' (or there is no acceptable conversion)
\source\include\quaternion.h(426) : error C2677: binary '*' : no global operator defined which takes type 'class irr::core::quaternion' (or there is no acceptable conversion)
.......
generous_donator

Post by generous_donator »

*g* don't just copy 'n paste.

read what the code does and then find the part's that need changes
nitroman

Post by nitroman »

does someone know if this patch works?
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

I do not know if this slerp routine is better than niko's as I have not tried it. It may be, as niko's comments in CXAnimationPlayer.cpp imply that there is a problem with how he interpolates rotations using quaternions.
However, it seems I was wrong when I thought that the weird returns from getMatrixOfJoint were from a quaternion problem. I noticed that getDrawableSkeleton gives points that will show the joints in the correct position. getMatrixOfJoint returns the CombinedAnimationMatrix of the joint. getDrawableSkeleton uses the AnimatedMatrix. I changed getMatrixOfJoint to return the AnimatedMatrix and it seems to work now (my getXJointNode function now works as well).
in CXAnimationPlayer.cpp

Code: Select all

//! Returns a pointer to a transformation matrix
core::matrix4* CXAnimationPlayer::getMatrixOfJoint(s32 jointNumber, s32 frame)
{
	if (jointNumber < 0 || jointNumber >= (s32)Joints.size())
		return 0;


	//return &Joints[jointNumber].CombinedAnimationMatrix;
   //not sure why above isn't working, but it doesn't seem to
   //this here below does
	return &Joints[jointNumber].AnimatedMatrix;
	
}
Note that the CombinedAnimationMatrix is the product of the AnimatedMatrix and the MatrixOffset of the joint. I do not know what the matrix offset does, but from a quick look at where it appeared in the code I think it may have something to do with skinning and vertex weigths. I'm only guessing on that though.

I wouldn't say I've got it all figured out, because I'm not sure exactly what's going on, but my fix seems to work. If anyone makes the change and finds that it doesn't fix the problem let me know.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Oz (Not logged in)

Post by Oz (Not logged in) »

Guest

Post by Guest »

Oops I might be confusing dates, sorry. :oops:
justiceforall
Posts: 5
Joined: Tue Aug 17, 2004 1:07 am

Post by justiceforall »

Electron wrote: I wouldn't say I've got it all figured out, because I'm not sure exactly what's going on, but my fix seems to work. If anyone makes the change and finds that it doesn't fix the problem let me know.

I change the code just like u say, but position is not correct. :(

here is the pic
Image
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

hmm. Your using vermeers dwarf model which is what I used in my tests that work fine. Could you please post your code?
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
justiceforall
Posts: 5
Joined: Tue Aug 17, 2004 1:07 am

Post by justiceforall »

Electron wrote:hmm. Your using vermeers dwarf model which is what I used in my tests that work fine. Could you please post your code?

here my code , maybe there are some bugs .

mesh = smgr->getMesh("../../media/dwarf.x");
scene::IAnimatedMeshSceneNode* anode1 = 0;
anode1 = smgr->addAnimatedMeshSceneNode(mesh);
anode1->setPosition(core::vector3df(-50,50,-140));
anode1->setAnimationSpeed(1500);

anode1->setMaterialFlag(irr::video::EMF_LIGHTING, false);


irr::scene::IAnimatedMesh* meshms3dgun = smgr->getMesh("../../media/10.x");
irr::scene::IAnimatedMeshSceneNode* node_ms3dgun2 = smgr->addAnimatedMeshSceneNode(meshms3dgun);
if(node_ms3dgun2)
{

node_ms3dgun2->setPosition(core::vector3df(-90,50,-140));
node_ms3dgun2->setMaterialFlag(irr::video::EMF_LIGHTING, true);
irr::scene::ISceneNode* hand = anode1->getXJointNode("Joint16");
hand->addChild(node_ms3dgun2);


}
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Code: Select all

node_ms3dgun2->setPosition(core::vector3df(-90,50,-140)); 
Couldn't this be the problem?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

i think that would indeed be the problem. Joint 16 is the hand joint with the dwarf model. On offset like you put will just make things come out weird
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Reiyn
Posts: 23
Joined: Sat Mar 05, 2005 7:51 pm
Location: Canada

Post by Reiyn »

Too cool, thank you very much for figuring out the fix, :D
I got .x bones animation and linking objects to bones working nicely now, woohoO!

<Happy>

Great job!! :D
Reiyn
Creating "Chimera", an Online RPG
DAoC - Guinevere - Druid rr11
WoW - Gorgonnash - Druid 55
Post Reply