当前位置: 首页>>代码示例>>C++>>正文


C++ Bone::GetRigidBody方法代码示例

本文整理汇总了C++中Bone::GetRigidBody方法的典型用法代码示例。如果您正苦于以下问题:C++ Bone::GetRigidBody方法的具体用法?C++ Bone::GetRigidBody怎么用?C++ Bone::GetRigidBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bone的用法示例。


在下文中一共展示了Bone::GetRigidBody方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BuildTail

bool Skeleton_Builder::BuildTail(float tail_width, float tail_height, float torso_height)
{
	Bone* UTail = new Bone();
	Bone* MTail = new Bone();
	Bone* LTail = new Bone();
	Bone* LLTail = new Bone();
	tail_height /= 4;
	
	Ogre::Quaternion neckrotation;
	neckrotation.FromAngleAxis(Ogre::Radian(Ogre::Degree(mTailIncline)), Ogre::Vector3::UNIT_X);
	btTransform t;
	btVector3 min, max;

	mHipNode->GetCollider()->getAabb(t, min, max);
	mBuilder->SetDimensions(tail_width, tail_height, mDepth / 2);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, -(torso_height /2), mDepth / 2), neckrotation, *mHipNode->GetNode());
	if (!mBuilder->BuildBone(*LLTail, Bone::BoneType::Tail))
		return false;
	mBuilder->SetDimensions(tail_width, tail_height, mDepth / 2);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, -tail_height , 0), neckrotation, *LLTail->GetNode());
	if (!mBuilder->BuildBone(*LTail, Bone::BoneType::Tail))
		return false;
	mBuilder->SetDimensions(tail_width, tail_height, mDepth / 2);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, -tail_height, 0), neckrotation, *LTail->GetNode());
	if (!mBuilder->BuildBone(*MTail, Bone::BoneType::Tail))
		return false;
	mBuilder->SetDimensions(tail_width, tail_height, mDepth / 2);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, -tail_height, 0), neckrotation, *MTail->GetNode());
	if (!mBuilder->BuildBone(*UTail, Bone::BoneType::Tail))
		return false;
	if (mHasMuscle)
	{
		mMuscleBuilder->CreateMuscle(mHipNode, LLTail, mMuscles);
		mMuscleBuilder->CreateMuscle(LLTail, LTail, mMuscles);
		mMuscleBuilder->CreateMuscle(LTail, MTail, mMuscles);
		mMuscleBuilder->CreateMuscle(MTail, UTail, mMuscles);
	}

	//add joints
	btTransform localA, localB;
	btVector3 JointPos;

	JointPos = Utils::OgreBTVector(mHipNode->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (torso_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, mHipNode, LLTail, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* shoulderNeckConst = new btConeTwistConstraint(*mHipNode->GetRigidBody(), *LLTail->GetRigidBody(), localA, localB);
	shoulderNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4),btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(LLTail->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (tail_height), 0));
	SetJointTransform(localA, localB, JointPos, LLTail, LTail, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* LNeckConst = new btConeTwistConstraint(*LLTail->GetRigidBody(), *LTail->GetRigidBody(), localA, localB);
	LNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(LTail->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (tail_height), 0));
	SetJointTransform(localA, localB, JointPos, LTail, MTail, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* MNeckConst = new btConeTwistConstraint(*LTail->GetRigidBody(), *MTail->GetRigidBody(), localA, localB);
	MNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(MTail->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (tail_height), 0));
	SetJointTransform(localA, localB, JointPos, MTail, UTail, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* HNeckConst = new btConeTwistConstraint(*MTail->GetRigidBody(), *UTail->GetRigidBody(), localA, localB);
	HNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	mConstraints.push_back(shoulderNeckConst);
	mConstraints.push_back(LNeckConst);
	mConstraints.push_back(MNeckConst);
	mConstraints.push_back(HNeckConst);

	return true;
}
开发者ID:nathn123,项目名称:FYP,代码行数:69,代码来源:Skeleton_Builder.cpp

示例2: BuildLeg

bool Skeleton_Builder::BuildLeg(float leg_width, float leg_height, float torso_width, float torso_height)
{
	auto halfgap = (torso_width / 2) - leg_width;
	auto legnodepos = halfgap + leg_width / 2;

	Bone* LUpperLeg = new Bone();
	Bone* LLowerLeg = new Bone();
	Bone* LFoot = new Bone();
	Bone* RUpperLeg = new Bone();
	Bone* RLowerLeg = new Bone();
	Bone* RFoot = new Bone();
	if (mLeg == LegType::Uninverted)
	{
		mBuilder->SetDimensions(leg_width, leg_height / 2, mDepth *0.75f);
		mBuilder->SetRelativePosition(Ogre::Vector3(legnodepos, -((torso_height / 2) + (leg_height / 4)), 0), Ogre::Quaternion::IDENTITY, *mHipNode->GetNode());
		if (!mBuilder->BuildBone(*LUpperLeg,Bone::BoneType::LUpperLeg))
			return false;
		mBuilder->SetDimensions(leg_width, leg_height / 2, mDepth *0.75f);
		mBuilder->SetRelativePosition(Ogre::Vector3(-legnodepos, -((torso_height / 2) + (leg_height / 4)), 0), Ogre::Quaternion::IDENTITY, *mHipNode->GetNode());
		if (!mBuilder->BuildBone(*RUpperLeg, Bone::BoneType::RUpperLeg))
			return false;
		mBuilder->SetDimensions(leg_width, leg_height / 2, mDepth *0.75f);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *LUpperLeg->GetNode());
		if (!mBuilder->BuildBone(*LLowerLeg, Bone::BoneType::LowerLeg))
			return false;
		mBuilder->SetDimensions(leg_width, leg_height / 2, mDepth *0.75f);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *RUpperLeg->GetNode());
		if (!mBuilder->BuildBone(*RLowerLeg, Bone::BoneType::LowerLeg))
			return false;

		// foot generation
		mBuilder->SetDimensions(leg_width*1.5f, leg_height / 4, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *LLowerLeg->GetNode());
		if (!mBuilder->BuildBone(*LFoot,Bone::BoneType::Foot))
			return false;
		mBuilder->SetDimensions(leg_width*1.5f, leg_height / 4, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *RLowerLeg->GetNode());
		if (!mBuilder->BuildBone(*RFoot, Bone::BoneType::Foot))
			return false;

	}
	else
	{
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(legnodepos, 0, 0), Ogre::Quaternion::IDENTITY, *mHipNode->GetNode());
		//if (!mBuilder->BuildBone(*LUpperLeg))
		//	return false;
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(0, leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *LUpperLeg->GetNode());
		//if (!mBuilder->BuildBone(*LLowerLeg))
		//	return false;
		// foot generation
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(legnodepos, 0, 0), Ogre::Quaternion::IDENTITY, Hip->GetNode());
		//if (!mBuilder->BuildBone(LUpperLeg))
		//	return false;
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(-legnodepos, 0, 0), Ogre::Quaternion::IDENTITY, *mHipNode->GetNode());
		//if (!mBuilder->BuildBone(*RUpperLeg))
		//	return false;
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(0, leg_height / 2, 0), Ogre::Quaternion::IDENTITY, *RUpperLeg->GetNode());
		//if (!mBuilder->BuildBone(*RLowerLeg))
		//	return false;
		// foot generation
		//mBuilder->SetDimensions(leg_width, leg_height / 2);
		//mBuilder->SetRelativePosition(Ogre::Vector3(legnodepos, 0, 0), Ogre::Quaternion::IDENTITY, Hip->GetNode());
		//if (!mBuilder->BuildBone(LUpperLeg))
		//	return false;
	}
	mBones.push_back(LUpperLeg);
	mBones.push_back(RUpperLeg);
	mBones.push_back(LLowerLeg);
	mBones.push_back(RLowerLeg);
	mBones.push_back(LFoot);
	mBones.push_back(RFoot);
	if (mHasMuscle)
	{
		mMuscleBuilder->CreateMuscle(mHipNode, LUpperLeg, mMuscles);
		mMuscleBuilder->CreateMuscle(LUpperLeg, LLowerLeg, mMuscles);
		mMuscleBuilder->CreateMuscle(LLowerLeg, LFoot, mMuscles);

		mMuscleBuilder->CreateMuscle(mHipNode, RUpperLeg, mMuscles);
		mMuscleBuilder->CreateMuscle(RUpperLeg, RLowerLeg, mMuscles);
		mMuscleBuilder->CreateMuscle(RLowerLeg, RFoot, mMuscles);
	}
	//add joints
	Ogre::Vector3 offset;
	btTransform localA, localB;
	btVector3 JointPos;

	JointPos = Utils::OgreBTVector(mHipNode->GetNode()->_getDerivedPosition() + Ogre::Vector3(legnodepos, -(torso_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, mHipNode, LUpperLeg, btVector3(0, btScalar(M_PI_2), 0));
	btConeTwistConstraint* LhipConst = new btConeTwistConstraint(*mHipNode->GetRigidBody(), *LUpperLeg->GetRigidBody(), localA, localB);
	LhipConst->setLimit(btScalar(M_PI_4), btScalar(M_PI_4), 0);

	JointPos = Utils::OgreBTVector(mHipNode->GetNode()->_getDerivedPosition() + Ogre::Vector3(-legnodepos, -(torso_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, mHipNode, RUpperLeg, btVector3(0, 0, btScalar(M_PI_4)));
	btConeTwistConstraint* RhipConst = new btConeTwistConstraint(*mHipNode->GetRigidBody(), *RUpperLeg->GetRigidBody(), localA, localB);
	RhipConst->setLimit(btScalar(M_PI_4), btScalar(M_PI_4), 0);
//.........这里部分代码省略.........
开发者ID:nathn123,项目名称:FYP,代码行数:101,代码来源:Skeleton_Builder.cpp

示例3: BuildNeck

bool Skeleton_Builder::BuildNeck(float neck_width, float neck_height, float torso_height)
{
	Bone* UNeck = new Bone();
	Bone* MNeck = new Bone();
	Bone* LNeck = new Bone();
	Bone* LLNeck = new Bone();
	neck_height /= 4;
	mBuilder->SetDimensions(neck_width, neck_height, mDepth * 0.5f);
	Ogre::Quaternion neckrotation;
	neckrotation.FromAngleAxis(Ogre::Radian(Ogre::Degree(mNeckIncline)), Ogre::Vector3::UNIT_X);

	mBuilder->SetRelativePosition(Ogre::Vector3(0, neck_height, 0), neckrotation, *mShouldernode->GetNode());
	if (!mBuilder->BuildBone(*LLNeck,Bone::BoneType::Neck))
		return false;
	mBuilder->SetDimensions(neck_width, neck_height, mDepth * 0.5f);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, neck_height, 0), neckrotation, *LLNeck->GetNode());
	if (!mBuilder->BuildBone(*LNeck, Bone::BoneType::Neck))
		return false;
	mBuilder->SetDimensions(neck_width, neck_height, mDepth * 0.5f);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, neck_height, 0), neckrotation, *LNeck->GetNode());
	if (!mBuilder->BuildBone(*MNeck, Bone::BoneType::Neck))
		return false;
	mBuilder->SetDimensions(neck_width, neck_height, mDepth * 0.5f);
	mBuilder->SetRelativePosition(Ogre::Vector3(0, neck_height, 0), neckrotation, *MNeck->GetNode());
	if (!mBuilder->BuildBone(*UNeck, Bone::BoneType::Neck))
		return false;
	if (mHasMuscle)
	{
		mMuscleBuilder->CreateMuscle(mShouldernode, LLNeck, mMuscles);
		mMuscleBuilder->CreateMuscle(LLNeck, LNeck, mMuscles);
		mMuscleBuilder->CreateMuscle(LNeck, MNeck, mMuscles);
		mMuscleBuilder->CreateMuscle(MNeck, UNeck, mMuscles);
	}
	
	//add joints
	btTransform localA, localB;
	btVector3 JointPos;

	JointPos = Utils::OgreBTVector(mShouldernode->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (torso_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, mShouldernode, LLNeck, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* shoulderNeckConst = new btConeTwistConstraint(*mShouldernode->GetRigidBody(), *LLNeck->GetRigidBody(), localA, localB);
	shoulderNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(LLNeck->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (neck_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, LLNeck, LNeck, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* LNeckConst = new btConeTwistConstraint(*LLNeck->GetRigidBody(), *LNeck->GetRigidBody(), localA, localB);
	LNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(mHipNode->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (neck_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, LNeck, MNeck, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* MNeckConst = new btConeTwistConstraint(*LNeck->GetRigidBody(), *MNeck->GetRigidBody(), localA, localB);
	MNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

	JointPos = Utils::OgreBTVector(mHipNode->GetNode()->_getDerivedPosition() + Ogre::Vector3(0, (neck_height / 2), 0));
	SetJointTransform(localA, localB, JointPos, MNeck, UNeck, btVector3(0, btScalar(-M_PI_2), 0));
	btConeTwistConstraint* HNeckConst = new btConeTwistConstraint(*MNeck->GetRigidBody(), *UNeck->GetRigidBody(), localA, localB);
	HNeckConst->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4),btScalar(M_PI_4 / 4));

	mConstraints.push_back(shoulderNeckConst);
	mConstraints.push_back(LNeckConst);
	mConstraints.push_back(MNeckConst);
	mConstraints.push_back(HNeckConst);

	return true;
}
开发者ID:nathn123,项目名称:FYP,代码行数:65,代码来源:Skeleton_Builder.cpp

示例4: BuildSkeleton


//.........这里部分代码省略.........
	auto onepercentW = mWidth / 100;
	// arms take 35% of width i.e 17.5% each side if needed
	torso_width = onepercentW * 65;
	Leg_width = onepercentW * 25; // ensures gaps between legs like realistic bipeds
	Arm_width = onepercentW * 17.5f;
	neck_width = onepercentW * 35;

	//build the torso here
	Bone* CentreTorso = new Bone();
	if (IsUpright())
	{
		
		Bone* TopTorso = new Bone();
		Bone* BotTorso = new Bone();
		//build 3 torso pieces
		torso_height /= 3;
		//build centre piece
		mBuilder->SetDimensions(torso_width, torso_height, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY,*mBase);
		if (!mBuilder->BuildBone(*CentreTorso,Bone::BoneType::Torso))
			return false;
		//build bot piece
		mBuilder->SetDimensions(torso_width, torso_height, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -(torso_height), 0), Ogre::Quaternion::IDENTITY, *CentreTorso->GetNode());
		if (!mBuilder->BuildBone(*BotTorso,Bone::BoneType::Hip))
			return false;
		//build top piece
		mBuilder->SetDimensions(torso_width, torso_height, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, (torso_height), 0), Ogre::Quaternion::IDENTITY, *CentreTorso->GetNode());
		if (!mBuilder->BuildBone(*TopTorso, Bone::BoneType::Shoulder))
			return false;
		mShouldernode = TopTorso;
		mHipNode = BotTorso;

		mBones.push_back(CentreTorso);
		mBones.push_back(TopTorso);
		mBones.push_back(BotTorso);
		//add muscles
		mMuscleBuilder->CreateMuscle(CentreTorso, TopTorso, mMuscles);
		mMuscleBuilder->CreateMuscle(CentreTorso, BotTorso, mMuscles);

		btTransform TransA;
		btTransform TransB;
		btVector3 JointPos; // world position of transform
		/*add constraints*/
		// JOINT POS IS THE POSITION ON THE EDGE OF THE BONE ATTACH I.E BONE POS + EDGE OF BONE IN DIRECTION TO NEXT
		JointPos = Utils::OgreBTVector(CentreTorso->GetNode()->_getDerivedPosition() + (torso_height / 2));

		SetJointTransform(TransA, TransB, JointPos, CentreTorso, TopTorso, btVector3(0, btScalar(-M_PI_2), 0));
		btConeTwistConstraint* TopSpine = new btConeTwistConstraint(*CentreTorso->GetRigidBody(), *TopTorso->GetRigidBody(), TransA, TransB);
		TopSpine->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

		JointPos = Utils::OgreBTVector(CentreTorso->GetNode()->_getDerivedPosition() - (torso_height / 2));

		SetJointTransform(TransA, TransB, JointPos, CentreTorso, BotTorso, btVector3(0, btScalar(-M_PI_2), 0));
		btConeTwistConstraint* BotSpine = new btConeTwistConstraint(*CentreTorso->GetRigidBody(), *BotTorso->GetRigidBody(), TransA, TransB);
		BotSpine->setLimit(btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4), btScalar(M_PI_4 / 4));

		mConstraints.push_back(TopSpine);
		mConstraints.push_back(BotSpine);
		
	}
	else
	{
		//Bone* CentreTorso = new Bone();

		//build centre piece
		mBuilder->SetDimensions(torso_width, torso_height, mDepth);
		mBuilder->SetRelativePosition(Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY, *mBase);
		if (!mBuilder->BuildBone(*CentreTorso,Bone::BoneType::HipShoulder))
			return false;
		mBones.push_back(CentreTorso);
		
		mShouldernode = CentreTorso;
		mHipNode = CentreTorso;
	}
	if (mFixed)
		CentreTorso->GetRigidBody()->setMassProps(0, btVector3(0, 0, 0));

	//if (!BuildArm(Arm_width, Leg_height, torso_width) || !BuildNeck(neck_width, neck_height, torso_height) || !BuildLeg(Leg_width, Leg_height, torso_width, torso_height))
	//	return false;
	if (!mHidearms)
		if (!BuildArm(Arm_width, torso_height, torso_width))
			return false;
	if (!mHideneck)
		if (!BuildNeck(neck_width, neck_height, torso_height))
			return false;
	if (!mHidelegs)
		if (!BuildLeg(Leg_width, Leg_height, torso_width, torso_height))
		return false;

	if (IsShortTail() || IsLongTail())
		if(!BuildTail(neck_width,tail_height, torso_height))
			return false;

		newSkel = Skeleton(mBones,mMuscles, mConstraints, mBase, mWorld);

		ClearData();
		return true;
}
开发者ID:nathn123,项目名称:FYP,代码行数:101,代码来源:Skeleton_Builder.cpp

示例5: BuildArm


//.........这里部分代码省略.........
	//	LshoulderConst->setLimit(M_PI_2, M_PI_2, 0);
	//	//SetJointTransform(localA, localB, Utils::OgreBTVector(mShouldernode->GetNode()->_getDerivedPosition() - offset), mShouldernode, RUpperArm);
	//	//btConeTwistConstraint* RshoulderConst = new btConeTwistConstraint(*mShouldernode->GetRigidBody(), *RUpperArm->GetRigidBody(), localA, localB);
	//	//RshoulderConst->setLimit(M_PI_2, M_PI_2, 0);

	//	offset = Ogre::Vector3(0, arm_height/4, 0);

	//	SetJointTransform(localA, localB, Utils::OgreBTVector(LUpperArm->GetNode()->_getDerivedPosition() - offset), LUpperArm, LLowerArm);
	//	btHingeConstraint* LArmConst = new btHingeConstraint(*LUpperArm->GetRigidBody(), *LLowerArm->GetRigidBody(), localA, localB);

	//	//SetJointTransform(localA, localB, Utils::OgreBTVector(RUpperArm->GetNode()->_getDerivedPosition() - offset), RUpperArm, RLowerArm);
	//	//btHingeConstraint* RArmConst = new btHingeConstraint(*RUpperArm->GetRigidBody(), *RLowerArm->GetRigidBody(), localA, localB);

	//	mConstraints.push_back(LshoulderConst);
	//	mConstraints.push_back(LArmConst);
	//	//mConstraints.push_back(RshoulderConst);
	//	//mConstraints.push_back(RArmConst);
	//	
	//}
	//else if (mArm == ArmType::LongArms)
	{
		//half height of legs
		Bone* LUpperArm = new Bone();
		Bone* RUpperArm = new Bone();
		Bone* LLowerArm = new Bone();
		Bone* RLowerArm = new Bone();

		//build shoulder piece
		//torso_width /= 2;
		mBuilder->SetDimensions(arm_Width, arm_height, mDepth * 0.5f);
		mBuilder->SetRelativePosition(Ogre::Vector3(((torso_width / 2) + arm_Width/2), 0, 0), Ogre::Quaternion::IDENTITY, *mShouldernode->GetNode());
		if (!mBuilder->BuildBone(*LUpperArm,Bone::BoneType::LUpperArm))
			return false;
		mBuilder->SetDimensions(arm_Width, arm_height, mDepth * 0.5f);
		mBuilder->SetRelativePosition(Ogre::Vector3(-((torso_width / 2) + arm_Width/2), 0, 0), Ogre::Quaternion::IDENTITY, *mShouldernode->GetNode());
		if (!mBuilder->BuildBone(*RUpperArm, Bone::BoneType::RUpperArm))
			return false;
		mBuilder->SetDimensions(arm_Width, arm_height, mDepth * 0.5f);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -(arm_height), 0), Ogre::Quaternion::IDENTITY, *LUpperArm->GetNode());
		if (!mBuilder->BuildBone(*LLowerArm, Bone::BoneType::LowerArm))
			return false;
		mBuilder->SetDimensions(arm_Width, arm_height, mDepth * 0.5f);
		mBuilder->SetRelativePosition(Ogre::Vector3(0, -(arm_height), 0), Ogre::Quaternion::IDENTITY, *RUpperArm->GetNode());
		if (!mBuilder->BuildBone(*RLowerArm, Bone::BoneType::LowerArm))
			return false;
		mBones.push_back(LUpperArm);
		mBones.push_back(RUpperArm);
		mBones.push_back(LLowerArm);
		mBones.push_back(RLowerArm);
		if (mHasMuscle)
		{
			mMuscleBuilder->CreateMuscle(mShouldernode, LUpperArm, mMuscles);
			mMuscleBuilder->CreateMuscle(LUpperArm, LLowerArm, mMuscles);
			mMuscleBuilder->CreateMuscle(mShouldernode, RUpperArm, mMuscles);
			mMuscleBuilder->CreateMuscle(RUpperArm, RLowerArm, mMuscles);
		}
		//add joints
		btTransform localA, localB;
		btVector3 JointPos;

		JointPos = Utils::OgreBTVector(mShouldernode->GetNode()->_getDerivedPosition() + (torso_width / 2 + arm_Width * 0.10f));
		SetJointTransform(localA, localB, JointPos, mShouldernode, LUpperArm, btVector3(0, 0, 0));
		// this needed a special case
		localA.getBasis().setEulerZYX(0,0,btScalar(M_PI));
		localB.getBasis().setEulerZYX(0, 0, btScalar(M_PI_2));
		btConeTwistConstraint* LshoulderConst = new btConeTwistConstraint(*mShouldernode->GetRigidBody(), *LUpperArm->GetRigidBody(), localA, localB);
		LshoulderConst->setLimit(btScalar(M_PI_2), btScalar(M_PI_2), 0);
		

		JointPos = Utils::OgreBTVector(mShouldernode->GetNode()->_getDerivedPosition() - (torso_width / 2 + arm_Width * 0.10f));
		SetJointTransform(localA, localB, JointPos, mShouldernode, RUpperArm, btVector3(0, 0, 0));
		localA.getBasis().setEulerZYX(0, 0, 0);
		localB.getBasis().setEulerZYX(0, 0, btScalar(M_PI_2));
		btConeTwistConstraint* RshoulderConst = new btConeTwistConstraint(*mShouldernode->GetRigidBody(), *RUpperArm->GetRigidBody(), localA, localB);
		RshoulderConst->setLimit(btScalar(M_PI_2), btScalar(M_PI_2), 0);
		

		JointPos = Utils::OgreBTVector(LUpperArm->GetNode()->_getDerivedPosition() - arm_height / 2);
		SetJointTransform(localA, localB, JointPos, LUpperArm, LLowerArm, btVector3(0, btScalar(M_PI_2), 0));
		btHingeConstraint* LArmConst = new btHingeConstraint(*LUpperArm->GetRigidBody(), *LLowerArm->GetRigidBody(), localA, localB);
		LArmConst->setLimit(0, btScalar(M_PI_2));

		JointPos = Utils::OgreBTVector(RUpperArm->GetNode()->_getDerivedPosition() - arm_height / 2);
		SetJointTransform(localA, localB, JointPos, RUpperArm, RLowerArm, btVector3(0, btScalar(M_PI_2), 0));
		btHingeConstraint* RArmConst = new btHingeConstraint(*RUpperArm->GetRigidBody(), *RLowerArm->GetRigidBody(), localA, localB);
		RArmConst->setLimit(0, btScalar(M_PI_2));

		mConstraints.push_back(LshoulderConst);
		mConstraints.push_back(RshoulderConst);
		mConstraints.push_back(LArmConst);
		mConstraints.push_back(RArmConst);

		//auto prestore = mMuscleBuilder->CreateMuscle(LUpperArm, LLowerArm);
		//for (auto m : prestore)
		//	mMuscles.push_back(m);
	}
	// means no arms to continue

	return true;
}
开发者ID:nathn123,项目名称:FYP,代码行数:101,代码来源:Skeleton_Builder.cpp


注:本文中的Bone::GetRigidBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。