Exemple #1
0
int SbmPawn::init( SkSkeleton* new_skeleton_p ) {
	if( _skeleton ) {
		ct_tree_p->remove_skeleton( _skeleton->getName() );
		//_skeleton->unref();
		delete _skeleton;
	}
	_skeleton = new_skeleton_p;
	if( _skeleton ) {
		_skeleton->ref();
		if( init_skeleton()!=CMD_SUCCESS ) {
			return CMD_FAILURE; 
		}
		ct_tree_p->add_skeleton( _skeleton->getName(), _skeleton );
		SmartBody::SBScene* scene = SmartBody::SBScene::getScene();
		
		std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners();
		for (size_t i = 0; i < listeners.size(); i++)
		{
			listeners[i]->OnCharacterUpdate( getName() );
		}

	}

	// 	if (colObj_p)
	// 	{
	// 		initPhysicsObj();
	// 	}

	// Name the controllers
	string ct_name( getName() );
	ct_name += "'s world_offset writer";
	world_offset_writer_p->setName( ct_name.c_str() );

	return CMD_SUCCESS;
}
Exemple #2
0
void SbmPawn::setSkeleton(SkSkeleton* sk)
{
	if (!sk)
	{
		LOG("Cannot set a null skeleton on object %s", getName().c_str());
		return;
	}
	 

	if (_skeleton)
	{		
		ct_tree_p->remove_skeleton( _skeleton->getName() );
		//_skeleton->unref();
		delete _skeleton;
	}
	_skeleton = sk;
	_skeleton->ref();	
	ct_tree_p->add_skeleton( _skeleton->getName(), _skeleton );	

	//scene_p->init(_skeleton);
	//int err = mcu.add_scene(scene_p);	
		
	float height = _skeleton->getCurrentHeight();	
	setHeight(height);
	//_skeleton->ref();

	SmartBody::SBScene* scene = SmartBody::SBScene::getScene();
	std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners();
	for (size_t i = 0; i < listeners.size(); i++)
	{
		listeners[i]->OnCharacterUpdate( getName() );
	}
}
Exemple #3
0
int SbmPawn::setup() {
	// Verifiy the joint name is not already in use.
	if( _skeleton->search_joint( SbmPawn::WORLD_OFFSET_JOINT_NAME ) ) {
		std::stringstream strstr;
		strstr << "ERROR: SbmPawn::init_skeleton_offset: Skeleton already contains joint \"" << SbmPawn::WORLD_OFFSET_JOINT_NAME << "\".";
		LOG(strstr.str().c_str());
		return( CMD_FAILURE ); 
	}

	SkJoint* world_offset_joint = _skeleton->insert_new_root_joint( SkJoint::TypeQuat );
	world_offset_joint->name( SbmPawn::WORLD_OFFSET_JOINT_NAME );
	world_offset_joint->extName( SbmPawn::WORLD_OFFSET_JOINT_NAME );
	// Make sure the world_offset accepts new pos and quat values
	SkJointPos* world_offset_pos = world_offset_joint->pos();
	world_offset_pos->limits( SkVecLimits::X, false );
	world_offset_pos->limits( SkVecLimits::Y, false );
	world_offset_pos->limits( SkVecLimits::Z, false );
	world_offset_joint->quat()->activate();
	_skeleton->compress();
	_skeleton->make_active_channels();

	if( WORLD_OFFSET_CHANNELS_P.size()==0 ) {
		std::string world_offset_joint_name( WORLD_OFFSET_JOINT_NAME );
		WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::XPos );
		WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::YPos );
		WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::ZPos );
		WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::Quat );
	}
	world_offset_writer_p->init( this, WORLD_OFFSET_CHANNELS_P, true );

	wo_cache.x = 0;
	wo_cache.y = 0;
	wo_cache.z = 0;
	wo_cache.h = 0;
	wo_cache.p = 0;
	wo_cache.r = 0;

	SmartBody::SBScene* scene = SmartBody::SBScene::getScene();
	std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners();
	for (size_t i = 0; i < listeners.size(); i++)
	{
		listeners[i]->OnCharacterUpdate( getName() );
	}

	return( CMD_SUCCESS ); 
}