Jump to content

Need Help Parenting - Emergency


Shard
 Share

Recommended Posts

Sorry for posting this here, but no one has come up with a working reply in the C++ thread.

 

I have a character model whose head I need to parent the camera to.

 

So I position the camera correctly, do a FindChild on "Bip01 Head" and Parent it. But when I run the game, the camera is titled side ways. So I tried to do a get/set rotation on the camera before and after the Parenting command with no luck.

 

The reason I need to do this is because I want to turn the head in code and have the camera follow the head, so that when the player wants to look left, I turn the head left and the camera follows and turns left. Another major reason is that the head has some animations, like a head bob and reload, where the head moves and I want the camera to move with it.

 

Current Steps

1) Load Model

2) Find Child Head

3) Position Camera To Head

4) Parent Head to Camera

5) Rotate Head

 

 

Edit: I've found a way to make the screen turn back to the proper orientation but then I can't look around using the mouse anymore, and I've tried both TurnEntity and RotateEntity.

 

What is the proper way to do what I need to do?

post-26-12734503437527_thumb.jpg

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

When you parent one entity to another, if the global parameter is set to true, the global orientation of the child entity will be left intact, and the local orientation will be recalculated.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I sometimes get some strange effects parenting, scales of objects changing, uncommanded orientation. So if I need to parent anything I'll attach it to a pivot then Move the entity into position.

 

FWIW here's an example of how I add missiles to rails on an aircraft.

 

HellfireEntity[NextRail].SetParent(Self.PylonPivot, 0) ;
HellfireEntity[NextRail].Move(RailOffset[NextRail], 0) ;

 

Where RailOffset[] is an array of Vec3 defining offsets of missile mount locations on the rail. Not saying don't parent, just that sometimes it can yield unexpected results. It's also handy.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Well I don't know if this is of much help.

 

The simplified hierarchy is as follows:

Helicopter > Rail > Pivot > Missile

 

There's nothing unusual in how I parent these. I don't apply any scaling or transformation. Objects are created in code and all 3D objects are exported to the same scale.

 

The only different between these two images is what I parent the missile to. Correct when on a pivot, incorrect to the rail. The rail is a separate object that is parented to a natural child of the Helicopter model. *shrug* not a clue what's going on here but pivot works for me so I'm happy.

post-52-12735118434636_thumb.jpg

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

or do people just get confused with the global flags?

 

 

Mfg Imp

 

+1

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Ive been having this problem in LE 2.2 (http://forum.leadwerks.com/viewtopic.php?f=37&t=3044)

 

I guess the problem appears again. But it only appears if parent entity is scaled.

 

As I remember the problem was in GetEntetyQuat function. It returned wrong data if the object has a parent.

 

Here is the project that demonstrates the problem in detail:

 

 

Keys:

WASD - cam control

T,Y,U - turn child entity

G,H,J - turn parent entity

B,N,M - scale parent entity

Q - create helper

SPACE - reset all rotations

 

Also there is Rotations.cpp file. There is some math functions that Ive made by myself:

TurnEntityLocalQ and TurnEntityLocalM - first uses entity's quaternions for rotation calculations, second uses matrices.

Only second works as expected.

 

Im sure that problem is in GetQuat function.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

I adjusted the calculations to fix the parent rotation. When you have an asymmetric scaling of a parent, the child matrix can become sheared when rotated, and the engine calculations force nonsheared matrices to avoid degradation from floating point inaccuracy.

 

So it may not be possible to an asymmetrically scaled parent's child to turn correctly, but I will continue to try to improve the behavior.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Your code produces errors, as well as shearing behavior. When I turn the parent, then scale it, then turn it again, the parent and child matrices change suddenly.

post-1-12741484863869_thumb.jpg

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I don't want waste your time, but could you try this code in main loop:

if (Keyboard::IsDown(KEY_T))
		{
			//Axis2.SetRotation(Axis2.GetRotation().X+0.1, Axis2.GetRotation().Y, Axis2.GetRotation().Z);
			//Axis2.Turn(0.1,0,0);
			RotateEntityLocalM(Axis2,0.01,0,0);
		}
		if (Keyboard::IsDown(KEY_Y))
		{
			//Axis2.SetMatrix(matrixMult(Axis2.GetMatrix(),GetTurnMatrix(0,0.01,0)));
			//Axis2.Turn(0,0.1,0);
			RotateEntityLocalM(Axis2,0,0.01,0);
		}
		if (Keyboard::IsDown(KEY_U))
		{
			//Axis2.SetMatrix(matrixMult(Axis2.GetMatrix(),GetTurnMatrix(0,0,0.01)));
			//Axis2.Turn(0,0,0.1);
			RotateEntityLocalM(Axis2,0,0,0.01);
		}



		if (Keyboard::IsDown(KEY_G))
		{
			//Axis1.SetRotation(Axis1.GetRotation(GLOBAL).X+0.1, Axis1.GetRotation(GLOBAL).Y, Axis1.GetRotation(GLOBAL).Z,GLOBAL);
			//Axis1.Turn(0.1,0,0);
			RotateEntityLocalQ(Axis1,0.01,0,0);

		}
		if (Keyboard::IsDown(KEY_H))
		{
			//Axis1.SetRotation(Axis1.GetRotation(GLOBAL).X, Axis1.GetRotation(GLOBAL).Y+0.1, Axis1.GetRotation(GLOBAL).Z,GLOBAL);
			//Axis1.Turn(0,0.1,0);
			RotateEntityLocalM(Axis1,0,0.01,0);
		}
		if (Keyboard::IsDown(KEY_J))
		{
			//Axis1.SetRotation(Axis1.GetRotation(GLOBAL).X, Axis1.GetRotation(GLOBAL).Y, Axis1.GetRotation(GLOBAL).Z+0.1,GLOBAL);
			//Axis1.Turn(0,0,0.1);
			RotateEntityLocalM(Axis1,0,0,0.01);
		}


		if (Keyboard::IsDown(KEY_)
		{

			Axis1.SetScale(Axis1.GetScale().X-0.01,Axis1.GetScale().Y,Axis1.GetScale().Z);


		}
		if (Keyboard::IsDown(KEY_N))
		{
			Axis1.SetScale(Axis1.GetScale().X, Axis1.GetScale().Y-0.01,Axis1.GetScale().Z);
		}
		if (Keyboard::IsDown(KEY_M))
		{
			Axis1.SetScale(Axis1.GetScale().X, Axis1.GetScale().Y, Axis1.GetScale().Z-0.01);
		}

		MouseNavi(camera,0.8,0.1,0.8,0.1);


		// Update timing and world
		Engine::UpdateTime();
		World::Update( Engine::GetSpeed()) ;

		// Render
		gbuffer.Set();
		World::Render() ;
		Engine::GetBackBuffer().Set() ;
		World::RenderLights(gbuffer);


		Draw::Text(10,10,"%f %f %f %f",Axis1.GetMatrix().A0,Axis1.GetMatrix().A1,Axis1.GetMatrix().A2,Axis1.GetMatrix().A3);
		Draw::Text(10,20,"%f %f %f %f",Axis1.GetMatrix().B0,Axis1.GetMatrix().B1,Axis1.GetMatrix().B2,Axis1.GetMatrix().B3);
		Draw::Text(10,30,"%f %f %f %f",Axis1.GetMatrix().C0,Axis1.GetMatrix().C1,Axis1.GetMatrix().C2,Axis1.GetMatrix().C3);
		Draw::Text(10,40,"%f %f %f %f",Axis1.GetMatrix().D0,Axis1.GetMatrix().D1,Axis1.GetMatrix().D2,Axis1.GetMatrix().D3);

		// Send to screen
		Engine::Flip(0) ;

 

It works for me as expected.

 

[EDIT]

Last year I spent a week to solve this issue :) You can not control biped made with 3ds max with this bug.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

Alternating between turning and scaling the parent still produces sudden changes in the matrix. Try going back and forth between hitting the H and N keys.

 

You may be on to a good idea here, but it's still not working perfectly right.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yes, you are right. After rotating and scaling it a few minutes I saw strange behavior.

But itis not sudden changes. The child get smoothly distorted and back to normal shape while rotating (by the way I use LE 2.31)

 

Any way Im glad that you've paid attention to this problem and now you know that it exists :)

Hope this problem will be solved :)

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

  • 1 month later...

I just swapped out an animated character in my test level for another rigged with the same skeleton and animations and as soon as gun is parented to the hand it gets magnified about 20 times .. it's bigger than the buildings now lol.

 

The animated character works perfectly in game and is scaled correctly, but adding the same gun model that worked correctly with the previous animated model results in a massive scaling of the weapon. :blink: Looks like a similar issue to ones previously discussed in this tread. I'm using 2.31 currently.

 

Is this now fixed in 2.32r5?

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...