Beispiel #1
0
int test_extrapolation(void)
{
	tl_message ("start");
	JHMM        *hmm1 = NULL, *hmm2 = NULL, *hmm3 = NULL, *extra_hmm = NULL;
	JHMM        *hmm_vec[3];
	double      weight[3];
	Behavior    *beh = NULL;
	hmm1      = new JHMM;
	hmm2      = new JHMM;
	hmm3      = new JHMM;
	extra_hmm = new JHMM;
	hmm1->Load("./.tmp/squat/squat.hmm");
	hmm2->Load("./.tmp/punch/punch.hmm");
	hmm3->Load("./.tmp/kick/kick.hmm");
	hmm1->Show();
	hmm2->Show();
	hmm3->Show();
	hmm_vec[0] = hmm1;   weight[0] = -1.0;
	hmm_vec[1] = hmm2;   weight[1] = -13;
	hmm_vec[2] = hmm3;   weight[2] =  1.3;

	tl_message ("Now generate a extrapolation HMM");
	extra_hmm->InterpolationAny (hmm_vec, weight, 3);
	extra_hmm->Show();
	beh = extra_hmm->GenerateBehavior(100, 30);
	beh->FileOut("interpolation_any.beh");

	delete beh;
	delete hmm1;
	delete hmm2;
	delete hmm3;
	delete extra_hmm;
	return TRUE;
}
Beispiel #2
0
int test_for_iros08_method2(void)
{
	tl_message ("start");
	JHMM        *hmm1 = NULL, *hmm2 = NULL, *inter_hmm = NULL, *extra_hmm = NULL;
	Behavior    *beh = NULL;
	hmm1      = new JHMM;
	hmm2      = new JHMM;
	inter_hmm = new JHMM;
	extra_hmm = new JHMM;
	hmm1->Load("./.tmp/squat/squat.hmm");
	hmm2->Load("./.tmp/punch/punch.hmm");
	hmm1->Show();
	hmm2->Show();

	tl_message ("Hellinger Distance between squat and punch = %g", hmm1->HellingerDistance(*hmm2));

	tl_message ("Now generate a interpolation HMM");
	inter_hmm->Interpolation (*hmm1, *hmm2, 0.5, 0.5);
	inter_hmm->Show();
	beh = inter_hmm->GenerateBehavior(100, 30);
	beh->FileOut("interpolation_any2.beh");

	tl_message ("Now generate a extrapolation HMM");
	extra_hmm->Interpolation (*hmm1, *hmm2, -1.0, 2.0);
	extra_hmm->Show();
	beh = extra_hmm->GenerateBehavior(100, 30);
	beh->FileOut("extrapolation_any2.beh");

	delete beh;
	delete hmm1;
	delete hmm2;
	delete inter_hmm;
	delete extra_hmm;
	return TRUE;
}
Beispiel #3
0
/*
 * For given cur_v in BHnew create unique childs, add them to BHnew 
 * and connect them all to cur_v
 * Then call this func for each childs vertices
 * Unique childs mean what for given cur_v and any Step exists 
 * only one (or zero) child vertex marked with this Step symbol 
 */
void create_childs_for_min(const Behavior& BHorig, Behavior& BHnew,
	BGVertex cur_v, const vector<BGVertex>& childs)
{
	if (childs.empty()) // no recursion, do nothing
		return ;
	else // main logic, do all work here 
	{
		// iterate all child vertices, obtain set of unique Steps
		// with corresponding vertices
		vector<StepChildVertices> storage;
		for (vector<BGVertex>::const_iterator it=
			childs.begin();it!=childs.end();it++)
			add2SChVV(storage,BHorig,*it);
		// now for each "child Step" create vertex, add it to BHnew
		// and connect it to cur_v 
		for (vector<StepChildVertices>::const_iterator sit=
			storage.begin();sit!=storage.end();sit++)
		{
			BGVertex new_v = BHnew.add_step(sit->sp);
			BHnew.add_edge(cur_v,new_v);
			
			vector<BGVertex> new_childs;
			new_childs = obtain_childs(BHorig,sit->vvec);
			
			// finally, recursion 
			create_childs_for_min(BHorig,BHnew,new_v,new_childs);
		}
		return ;
	}
}
Beispiel #4
0
RESULT 
BehaviorManager::PushBehaviorOnToGameObject( IN HBehavior hBehavior, IN HGameObject hGameObject, IN StateMachineQueue queue )
{
    RESULT rval           = S_OK;
    string gameObjectName = "";
    
    Behavior* pBehavior = GetObjectPointer( hBehavior );
    if (pBehavior)
    {
        GOMan.GetName( hGameObject, &gameObjectName );
        
        RETAILMSG(ZONE_STATEMACHINE | ZONE_VERBOSE, "BehaviorManager::PushBehaviorOnToGameObject( \"%s\", \"%s\", queue: %d )", 
            pBehavior->GetName().c_str(),
            gameObjectName.c_str(),
            queue);

        CHR(pBehavior->BindToGameObject( hGameObject, queue ));
    }
    else 
    {
        rval = E_FAIL;
    }

Exit:
    if (FAILED(rval))
    {
        RETAILMSG(ZONE_ERROR, "ERROR: BehaviorManager::PushBehaviorOnToGameObject( \"%s\", \"%s\" ): Behavior or GO not found", 
            pBehavior ? pBehavior->GetName().c_str() : "NULL",
            gameObjectName.c_str());
    }
    
    return rval;
}
//
// Behavior followBehavior(target, dist)
// Last modified: 07Nov2009
//
// Directs the robot to follow the parameterized target
// maintaining the parameterized distance,
// returning the appropriate robot behavior.
//
// Returns:     the appropriate robot behavior
// Parameters:
//      target  in/out  the target to follow
//      dist    in      the distance to maintain from the target
//
Behavior Robot::followBehavior(const Vector &target, const GLfloat dist)
{
    GLfloat  r   = target.magnitude();
    if (r <= threshold()) return moveStopBehavior();
    Behavior beh = orientToBehavior(target, 0.0f);
    if ((beh.isDone()) && (r > dist)) return moveForwardBehavior(r - dist);
    return beh;
}   // followBehavior(const Vector &, const GLfloat)
void SequenceBehavior::childSucceeded() {
	if (currentPos == children.size() - 1)
		endWithSuccess();
	else {
		currentPos++;
		Behavior* currentChild = children.get(currentPos);
		if (currentChild == NULL || !currentChild->checkConditions())
			endWithFailure();
	}
}
Beispiel #7
0
	FBOXAPI void Actor::start()
	{
		for (std::list<Behavior*>::iterator i = this->behaviors.begin(); i != this->behaviors.end(); i++)
		{
			Behavior* behavior = *i;
			if (behavior != 0)
			{
				behavior->start();
			}
		}
	}
Beispiel #8
0
gd::Behavior * Object::AddNewBehavior(gd::Project & project, const gd::String & type, const gd::String & name)
{
    Behavior * behavior = project.GetCurrentPlatform().CreateBehavior(type);

    if ( behavior != NULL ) {
        behavior->SetName(name);
        behaviors[behavior->GetName()] = behavior;
    }

    return behavior;
}
Beispiel #9
0
Oop* __fastcall Interpreter::primitiveMakePoint(CompiledMethod&, unsigned argCount)
{
	Oop* sp = m_registers.m_stackPointer;
	Oop oopReceiver = *(sp-argCount);
	if (!ObjectMemory::isBehavior(oopReceiver))
		return primitiveFailure(0);
	BehaviorOTE* oteClass = reinterpret_cast<BehaviorOTE*>(oopReceiver);
	Behavior* behavior = oteClass->m_location;

	if (behavior->isBytes())
		return primitiveFailure(1);

	size_t minSize = behavior->fixedFields();
	size_t i;
	if (behavior->isIndexable())
	{
		i = max(minSize, argCount);
	}
	else
	{
		if (argCount > minSize)
		{
			// Not indexable, and too many fields
			return primitiveFailure(2);
		}
		i = minSize;
	}

	// Note that instantiateClassWithPointers counts up the class,
	PointersOTE* oteObj = ObjectMemory::newUninitializedPointerObject(oteClass, i);
	VariantObject* obj = oteObj->m_location;

	// nil out any extra fields
	const Oop nil = reinterpret_cast<Oop>(Pointers.Nil);
	while (i > argCount)
	{
		obj->m_fields[--i] = nil;
	}

	while (i != 0)
	{
		i--;
		Oop oopArg = *sp--;
		ObjectMemory::countUp(oopArg);
		obj->m_fields[i] = oopArg;
	}

	// Save down SP in case ZCT is reconciled on adding result, allowing unref'd args to be reclaimed
	m_registers.m_stackPointer = sp;
	*sp = reinterpret_cast<Oop>(oteObj);
	ObjectMemory::AddToZct((OTE*)oteObj);
	return sp;
}
int main (int argc, char **argv)
{
    string scoutname = "";
    int behavior_num;
    string behavior_name = "";

    // Running with no arguments only supports one scout. Check in case
    // the user meant to specify a scout in the arguments.
    if (argc < 2)
    {
        cout << "You have started this behavior in hardware mode." << endl
             << "To start in software mode, use: " << argv[0]
             << " <behavior#> <scoutname> " << endl;
    }
    else
    {
        // Use the provided scoutname for simulator messages
        //scoutname = argv[1];
        behavior_num = atoi(argv[1]);
        if (argc == 3) {
            scoutname = argv[2];
        }

        ros::init(argc, argv, scoutname + "Behavior",
            ros::init_options::NoSigintHandler);

        // Initialize the signal handler after initializing rosnode.
        // Otherwise it will be overwritten and you will be sad.
        signal(SIGINT, sigint_handler);

        // one Sensor instance per-class
        Sensors* sensors = new Sensors(scoutname);
        BehaviorList* list = new BehaviorList();
        vector<behavior_func> behavior_list = list->behavior_list;
        if (behavior_num < (int)behavior_list.size())
        {
            Behavior* b = behavior_list[behavior_num](scoutname, sensors);
            b->run();
            delete b;
        }
        else
        {
            cout << "There is no behavior number" << behavior_num
              << ". There are only " << (int)behavior_list.size() << "behaviors."
              << endl;
        }

        delete list;
        delete sensors;
    }

    return 0;
}
Beispiel #11
0
	FBOXAPI void Actor::update()
	{
		this->transform->recalculate();
		for (std::list<Behavior*>::iterator i = this->behaviors.begin(); i != this->behaviors.end(); i++)
		{
			Behavior* behavior = *i;
			if (behavior != 0)
			{
				behavior->update();
			}
		}
	}
Beispiel #12
0
Behavior* GoToBase::selectNext()
{
	Behavior *baseBehavior = Behavior::selectNext();
	if(baseBehavior)
		return baseBehavior;
	Behavior* nextBehavior = this->_nextGoalBehavior;
	while(nextBehavior && nextBehavior->stopCond())
	{
		nextBehavior = nextBehavior->selectNext();
	}
	return nextBehavior;
}
Beispiel #13
0
bool Object::RenameBehavior(const gd::String & name, const gd::String & newName)
{
    if ( behaviors.find(name) == behaviors.end()
      || behaviors.find(newName) != behaviors.end() ) return false;

    Behavior * aut = behaviors.find(name)->second;
    behaviors.erase(name);
    behaviors[newName] = aut;
    aut->SetName(newName);

    return true;
}
Beispiel #14
0
Behavior make_full_with_clo (const Behavior& BHfull, 
	const vector<LOrder>& lorder_vec)
{
	Behavior BH;
	BGVertex root;
	Trace trace;
	
	if (handle_path(BHfull,BHfull.get_root(),lorder_vec,BH,trace,root))
		BH.set_root(root);
	
	return BH;
}
Beispiel #15
0
Behavior* Behavior::getNextBehavior()
{
	for (vector<Behavior*>::const_iterator iter = _nextBehaviors.begin(); iter != _nextBehaviors.end(); iter++)
	{
		Behavior* currentBehavior = *iter;
		if (currentBehavior->startCondition())
		{
			return currentBehavior;
		}
	}

	return NULL;
}
Beispiel #16
0
Behavior make_minimized (const Behavior& BHorig)
{
	Behavior BH;
	BGVertex root;
	root = BH.add_step(NULL);
	BH.set_root(root);
	
	vector<BGVertex> parents;
	parents.push_back(BHorig.get_root());
	
	create_childs_for_min(BHorig,BH,root,obtain_childs(BHorig,parents));
	
	return BH;
}
Beispiel #17
0
// recursive depth-first handling all paths in Behavior graph
// BHorig - original behavior graph
// cur_v - current vertex in original graph
// lo_vec - vector of lorders
// BHnew - new behavior graph containign only paths with correct
// lorders from lo_vec
// trace - prefix of trace, trace corresponds the path
// from "root" of BHorig to current vertex cur_v, including cur_v
// return - true if vertex cur_v was added to BHnew, i.e. 
// iff path has correct lorder
bool handle_path(const Behavior& BHorig, const BGVertex& cur_v,
	const vector<LOrder>& lo_vec, 
	Behavior& BHnew, const Trace& trace, BGVertex& new_v)
{
	//cout<<"prefix trace: ";debugPrint(trace);cout<<"\n";
	// get out_edges of cur_v
	BGOutEdgeIt out_i, out_end;
	BGEdge e;
	tie(out_i,out_end) = BHorig.get_out_edges(cur_v);
	if (out_i==out_end) // if there are no out edges - no recursion 
	{
		//cout<<"no recursion for: ";debugPrint(trace);cout<<"\n";
		// now we have full trace
		// check if its lorder correct 
		// and if so, add vertex for Step corresponding cur_v
		if (lorder_in_set(lorder(trace),lo_vec)) {
			new_v = BHnew.add_step( BHorig.get_step(cur_v) );
			return true;
		} else return false;
			//BHnew.add_path(trace.begin(),trace.end(),
			//	BHnew.get_root(),fin);
	} else // recursively handle all child vertices
	{
		// flag to check if some path was added for any child vertex
		bool was_added = false;
		vector<BGVertex> new_vvec;
		
		for (;out_i!=out_end;out_i++)
		{
			e = *out_i;
			// get next child vertex
			BGVertex child_v = BHorig.get_target(e);
			// add new Step for given vertex to new trace
			Trace t = trace;
			t.push_back(BHorig.get_step(child_v));
			//cout<<"form new trace: ";debugPrint(t);cout<<"\n";
			// recursive call for this func with new params
			// if for given edge child_v vertex new_v was added
			// then store this new_v in vector and set the flag
			BGVertex new_v;
			if (handle_path(BHorig,child_v,lo_vec,BHnew,t,new_v)) {
				was_added = true;
				new_vvec.push_back(new_v);
			}
		}
		// if at least one path was added, then 
		if (was_added) {
			// create vertex for current Step
			BGVertex this_v;
			this_v = BHnew.add_step(BHorig.get_step(cur_v));
			// connect it to all recursively added child vertices
			for (vector<BGVertex>::const_iterator vvec_it = 
				new_vvec.begin();vvec_it!=new_vvec.end();vvec_it++)
				BHnew.add_edge(this_v,*vvec_it);
			// set this vertex as a new_v for our parent
			new_v = this_v;
		}
		return was_added;
	}
}
void BehaviorBase::execSyncV(      FieldContainer    &oFrom,
                                        ConstFieldMaskArg  whichField,
                                        AspectOffsetStore &oOffsets,
                                        ConstFieldMaskArg  syncMode,
                                  const UInt32             uiSyncInfo)
{
    Behavior *pThis = static_cast<Behavior *>(this);

    pThis->execSync(static_cast<Behavior *>(&oFrom),
                    whichField,
                    oOffsets,
                    syncMode,
                    uiSyncInfo);
}
Beispiel #19
0
// |point| is in screen coords (pixel) with the origin at the top left corner.
bool Node::handleTouch(const BehaviorType& type, const Vector2& point) {
    LOGD("[Node handleTouch] triggered. Scene node = %s.\n", mName.c_str());
    Behavior* behavior = getBehavior(type);
    if (behavior) {
        LOGD("[Node handleTouch] Behavior = %lu acts.\n", behavior->getID());
        behavior->act();

        // Get the coords of the point in a coords with the origin at bottom left.
//        Vector2 newPoint = point;
//        int screenH = mSceneMgr->getRenderer()->getScreenHeight();
//        newPoint.y = screenH - newPoint.y;
        return true;
    }
    return false;
}
Beispiel #20
0
// note - we might not really get to the time in one shot
// so let it take up to 10 tries
void GrObject::simulateUntil(unsigned long t)
{
	for(vector<Behavior*>::iterator i = behaviors.begin(); i != behaviors.end(); ++i) {
	  Behavior *b = *i;
	  int ct=0;
	  while ((b->lastV < t) && (ct<10)) {
		b->simulateUntil(t);
		ct++;
	  }
	  /* if (ct>1) 
		  printf("needed %d simulation substeps\n",ct); */
	  // this is a common bug - you'll get caught here if you don't update lastV
	  if (ct>8)
		  printf("Warning! stuck behavior!\n");
  }
}
void CompositeBehavior::start() {
	currentPos = 0;

	for (int i = 0; i < children.size(); i++) {
		Behavior* currentChild = children.get(i);

		if (currentChild == NULL) {
			agent->error("NULL child in CompositeBehavior");
			continue;
		}

		currentChild->setStatus(AiMap::SUSPEND);
	}

	Behavior::start();
}
Beispiel #22
0
map<string, BGVertex> create_layer(Behavior& BH, 
	vector<trcit_pair_t>& tit_vec) 
{
	map<string, BGVertex> layer;
	
	for (vector<trcit_pair_t>::iterator it = tit_vec.begin();
		it!=tit_vec.end();it++)
	{
		// get next label (via trace iterator)
		Trace::const_iterator cur = 
			get_next_label(it->first,it->second);
		// set iterator in vector to this label
		it->first = cur;
		
		// check if label was found
		if (cur != it->second) 
		{	
			string label_name = (*cur)->get_name();

			// check if "label vertex" with given name already exists
			// in layer or not, if not - add it to layer
			if (layer.find(label_name) == layer.end())
			{
				BGVertex lv = BH.add_step(*cur);
				layer.insert(pair<string,BGVertex>
					(label_name,lv));
			}
		}
	}
	return layer;
}
Beispiel #23
0
Behavior make_full_bh(const TraceSet& traces)
{
	Behavior BH;
	
	BGVertex root,fin;
	root = BH.add_step(NULL);
	BH.set_root(root);
	//fin = BH.add_step(NULL);
	
	// take pairs of iterators for each trace
	// each pair contain iterator for current position in trace
	// and the trace.end()
	vector< trcit_pair_t > tit_vec;
	// store such the pairs in vector
	for (TraceSet::const_iterator it=
		traces.begin();it!=traces.end();it++)
		tit_vec.push_back(trcit_pair_t(it->begin(),it->end()));
	// create 2 layers of label-vertices: prev and current
	// each layer contain information about label name
	// and associated vertex
	map<string, BGVertex> prev_layer, cur_layer;
	// now create first layer of "label vertices" and connect
	// them to "root" vertex 
	prev_layer = create_layer(BH,tit_vec);
	for (map<string,BGVertex>::iterator lit = 
		prev_layer.begin();lit!=prev_layer.end();lit++)
		BH.add_edge(root,lit->second);

	// create "full" graph
	do {
		// 0. shift iterators to next position to deal only with
		// "remaining" traces
		shift_iterators(tit_vec);
		// 1. create the next layer of "label vertices"
		cur_layer = create_layer(BH,tit_vec);
		
		// 2. connect each pair of "label vertices" 
		// in previous and current layers with appropriate paths
		// Paths are obtained from subt(traces,label1,label2)
		link_layers(BH,traces,prev_layer,cur_layer);
		
		prev_layer = cur_layer;
	}
	while (!tit_vec.empty()); 
	
	return BH;
}
Beispiel #24
0
Task* BehaviorTask::update()
{
    PROFILE_SCOPE(BehaviorTask_update);

    Behavior *node = static_cast<Behavior*>(mNodeRep);

    // first check preconditions are valid
    bool precondition = true;
    if( (node->getPreconditionMode() == ONCE && mStatus == INVALID) || (node->getPreconditionMode() == TICK) )
        precondition = node->precondition( mOwner );

    if(precondition)
    {
        // run onEnter if this is the first time the node is ticked
        if(mStatus == INVALID)
            node->onEnter(mOwner);

        // execute the main behavior and get its return value
        mStatus = node->behavior(mOwner);
    }
    else
    {
        mStatus = FAILURE;
    }

    mIsComplete = mStatus != RUNNING && mStatus != SUSPENDED;

    if(mIsComplete)
        node->onExit(mOwner);

    return NULL; // leaves don't have children
}
Beispiel #25
0
RESULT
BehaviorManager::Init( IN const string& settingsFilename )
{
    RETAILMSG(ZONE_INFO, "BehaviorManager::Init( %s )", settingsFilename.c_str());

    RESULT rval = S_OK;
    char   path[MAX_PATH];
    
    //
    // Create a Settings object and load the file.
    //
    Settings mySettings;
    if ( FAILED(mySettings.Read( settingsFilename )) )
    {
        RETAILMSG(ZONE_ERROR, "ERROR: BehaviorManager::Init( %s ): failed to load settings file", settingsFilename.c_str() );
        return E_UNEXPECTED;
    }
    

    //
    // Create each Behavior.
    //
    UINT32 numBehaviors = mySettings.GetInt("/Behaviors.NumBehaviors");

    for (int i = 0; i < numBehaviors; ++i)
    {
        sprintf(path, "/Behaviors/Behavior%d", i);
        //DEBUGMSG(ZONE_INFO, "Loading [%s]", path);

        Behavior *pBehavior = NULL;
        CreateBehavior( &mySettings, path, &pBehavior );
        if (!pBehavior)
        {
            RETAILMSG(ZONE_ERROR, "ERROR: BehaviorManager::Init( %s ): failed to create Behavior", path);
            // Continue loading other Behaviors rather than aborting.
            continue;
        }
        
        //DEBUGMSG(ZONE_Behavior, "Created Behavior [%s]", pBehavior->GetName().c_str());
        CHR(Add(pBehavior->GetName(), pBehavior));
    }
    
Exit:
    return rval;
}
Beispiel #26
0
//-----------------------------------------------------------------------------------------------
void AISprite::CreateTree()
{
	tree = new BehaviorTree();

	for (int i = 0; i < m_behaviors.size(); i++)
	{
		Behavior* aiBehavior = new Behavior(m_behaviors[i]->name);
		{
			PrioritySelector* selector = new PrioritySelector();
			{
				for (int j = 0; j < m_behaviors[i]->sequence_info.size(); j++)
				{
					Sequence* sequence = new Sequence();
					{
						Node* sequence_node = new TaskNode();
						{
							sequence_node->SetSequenceLevel(1);
							Decorator* sequence_decorator = new Decorator();
							{
								LuaTask* action = new LuaTask();
								LuaDelegate* condition = new LuaDelegate(this);
								action->SetLuaState(Scripting::LuaState());
								condition->SetLuaState(Scripting::LuaState());
								string path = Scripting::GetGameDirectory()->m_scripts_path;
								path.append("\\");
								path.append(m_script_name);
								action->AddLuaAction(this, m_behaviors[i]->sequence_info[j]->name, path, m_behaviors[i]->sequence_info[j]->action_func_name);
								condition->AddFunction(path, m_behaviors[i]->sequence_info[j]->condition_func_name);
								sequence_decorator->SetUseLua(true);
								sequence_decorator->AddDecoratedComponent(action);
								sequence_decorator->AddCondition(condition);
							}
							sequence_node->AddDecorator( sequence_decorator );
						}
						sequence->AddChildTask( sequence_node );
					}
					selector->AddSequence( sequence );
				}
			}
			aiBehavior->AddSelector( selector );
		}
		tree->InsertBehavior( aiBehavior );
	}
}
Beispiel #27
0
void Object::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
    //Name and type are already loaded.
    objectVariables.UnserializeFrom(element.GetChild("variables", 0, "Variables"));

    //Compatibility with GD <= 3.3
    if (element.HasChild("Automatism"))
    {
        for (std::size_t i = 0; i < element.GetChildrenCount("Automatism"); ++i)
        {
            SerializerElement & behaviorElement = element.GetChild("Automatism", i);

            gd::String autoType = behaviorElement.GetStringAttribute("type", "", "Type")
                .FindAndReplace("Automatism", "Behavior");
            gd::String autoName = behaviorElement.GetStringAttribute("name", "", "Name");

            Behavior* behavior = project.CreateBehavior(autoType);
            if ( behavior != NULL )
            {
                behavior->SetName(autoName);
                behavior->UnserializeFrom(behaviorElement);
                behaviors[behavior->GetName()] = behavior;
            }
            else
                std::cout << "WARNING: Unknown behavior " << autoType << std::endl;
        }
    }
    //End of compatibility code
    else
    {
        SerializerElement & behaviorsElement = element.GetChild("behaviors", 0, "automatisms");
        behaviorsElement.ConsiderAsArrayOf("behavior", "automatism");
        for (std::size_t i = 0; i < behaviorsElement.GetChildrenCount(); ++i)
        {
            SerializerElement & behaviorElement = behaviorsElement.GetChild(i);

            gd::String autoType = behaviorElement.GetStringAttribute("type")
                .FindAndReplace("Automatism", "Behavior"); //Compatibility with GD <= 4
            gd::String autoName = behaviorElement.GetStringAttribute("name");

            Behavior* behavior = project.CreateBehavior(autoType);
            if ( behavior != NULL )
            {
                behavior->SetName(autoName);
                behavior->UnserializeFrom(behaviorElement);
                behaviors[behavior->GetName()] = behavior;
            }
            else
                std::cout << "WARNING: Unknown behavior " << autoType << std::endl;
        }
    }

    DoUnserializeFrom(project, element);
}
 void onFrame(){
   
   model = glm::mat4(1.0);
   
   vec3 totals = rotateBehavior.tick(now()).totals();
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   
   //draw cube 1 into an offscreen texture
   fbo.bind(); {
     glViewport(0, 0, fbo.width, fbo.height);
     glClearColor(0.1,0.1,0.1,1.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     draw(model, cubeMeshBuffer1, texture, textureProgram);
     
   } fbo.unbind();
   
   
   //draw cube 2 with the offscreen texture using phong shading
   glViewport(0, 0, width, height);
   glClearColor(0.0,0.0,0.0,1.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   model = glm::mat4(1.0);
   
   model = glm::translate(model, vec3(1.0,0.0,0.0));
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   draw(model, cubeMeshBuffer2, fbo.texture, phongProgram);
   
   
   
   //draw cube 3 - a colored cube
   
   model = mat4(1.0);
   model = glm::translate(model, vec3(-1.0,0.0,0.0));
   
   model = glm::rotate(model, -totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, -totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, -totals.z, vec3(0.0f,0.0f,1.0f));
   
   programColor.bind(); {
     glUniformMatrix4fv(programColor.uniform("model"), 1, 0, ptr(model));
     glUniformMatrix4fv(programColor.uniform("view"), 1, 0, ptr(view));
     glUniformMatrix4fv(programColor.uniform("proj"), 1, 0, ptr(proj));
     
     cubeMeshBuffer3.draw();
     
   } programColor.unbind();
   
 }
void LightDialog::slotRemove() {
  EM_CERR("LightDialog::slotRemove");
  Light * light = p_Behavior->getLight();
  if (light != NULL) {
    Group * gl = light->getParent();
    assert (gl != NULL);
    Group * parent = gl->getParent();
    assert(parent != NULL);
    Behavior * beh = parent->getBehavior();
    assert(beh != NULL);
    beh->setLight(NULL);
    parent->removeGroup(gl);
  } else {
    EM_CERR("LightDialog::slotRemove no light");
  }
  p_Doc->setModified(true);
  p_Doc->rebuildAll("group");
  this->done(0);
}
Beispiel #30
0
/////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////
// obtain child vertices for given vertex set
vector<BGVertex> obtain_childs(const Behavior& BH, 
	const vector<BGVertex> vvec)
{
	vector<BGVertex> childs;
	
	BGOutEdgeIt out_i, out_end;
	BGEdge e;
	for (vector<BGVertex>::const_iterator vit =
		vvec.begin();vit!=vvec.end();vit++) {
	
		tie(out_i,out_end) = BH.get_out_edges(*vit);
		for (;out_i!=out_end;out_i++)
		{
			e = *out_i;
			BGVertex child_v = BH.get_target(e);
			childs.push_back(child_v);
		}
	}
	return childs;
}