[Solved][1.11] Moving and rotating nodes

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

[Solved][1.11] Moving and rotating nodes

Post by saintnick » Thu Dec 20, 2018 4:10 am

When I press a button my program changes camera style from free look to third person of the selected unit. This works fine when changing cameras back and forth at 0,0,0. My problem comes when I move the unit. When I enter third person camera of a unit not at 0,0,0 the results no longer make sense. The further away from 0,0,0 the node is the larger a circle it pitches around, instead of pitching the unit. Note that I can move a unit and pitch it correctly, it isn't until I switch cameras back and forth that this happens to a unit that has moved.

How can I retain my rotational results when I switch to a unit that isn't at 0,0,0?

A = Main Node
B = Entity Node
C = Camera Node

A
|\
B C

Detach code:

Code: Select all

	mMainRollNode->removeChild(camNode);
	mScnMgr->getRootSceneNode()->addChild(camNode);
	camPitchNode->setAutoTracking(false);
Attach code:

Code: Select all

					Vector3 oldPosition = mMainNode->getPosition();
					Quaternion oldOrient = mMainNode->getOrientation();

					mScnMgr->getRootSceneNode()->removeAndDestroyChild("MainNode");
					mMainNode= mScnMgr->getRootSceneNode()->createChildSceneNode("MainNode");
					mMainPitchNode= mMainNode->createChildSceneNode();
					mMainRollNode= mMainPitchNode->createChildSceneNode();

					mMainNode->setPosition(oldPosition);
					mMainNode->setOrientation(oldOrient);
	
					mScnMgr->getRootSceneNode()->removeChild(mNode);
					mMainRollNode->addChild(mNode);

					mNode->setPosition(Vector3(oldPosition.x, oldPosition.y, oldPosition.z));

					Vector3 newCamPosition = Vector3(
						mMainNode->getPosition().x,
						mMainNode->getPosition().y,
						mMainNode->getPosition().z + 500);

					mScnMgr->getRootSceneNode()->removeChild(camNode);
					mMainRollNode->addChild(camNode);

					camPitchNode->setAutoTracking(true, mNode);
					camNode->setPosition(newCamPosition);
					camNode->setFixedYawAxis(false);
Edit
Following changes got the intended results.

Code: Select all

					mNode->_setDerivedPosition(Vector3(oldPosition.x, oldPosition.y, oldPosition.z));

					Vector3 newCamPosition = Vector3(
						mNode->getPosition().x,
						mNode->getPosition().y,
						mNode->getPosition().z + 500);
0 x

Post Reply