예제 #1
0
//////////////////////////////////////////////////////////////////////////
// Frame update jump state
//////////////////////////////////////////////////////////////////////////
void CControlJump::update_frame()
{
	// check if all jump stages are ended
	if (m_velocity_bounced && m_man->path_builder().is_path_end(0.f)) {
		stop();
		return;
	}

	// trace enemy for hit
	hit_test			();

	// set velocity from path if we are on it
	if (m_man->path_builder().is_moving_on_path()) {
		//---------------------------------------------------------------------------------------------------------------------------------
		// Set Velocity from path
		//---------------------------------------------------------------------------------------------------------------------------------
		SControlMovementData		*ctrl_move = (SControlMovementData*)m_man->data(this, ControlCom::eControlMovement); 
		VERIFY						(ctrl_move);

		ctrl_move->velocity_target	= m_object->move().get_velocity_from_path();
		ctrl_move->acc				= flt_max;
		//---------------------------------------------------------------------------------------------------------------------------------
	}
	
	// check if we landed
	if (is_on_the_ground()) grounding();
}
예제 #2
0
void CControlJump::on_event(ControlCom::EEventType type, ControlCom::IEventData *data)
{
	if (type == ControlCom::eventVelocityBounce) {
		SEventVelocityBounce *event_data = (SEventVelocityBounce *)data;
		if ((event_data->m_ratio < 0) && !m_velocity_bounced && (m_jump_time != 0)) {
 			if (is_on_the_ground()) {
				m_velocity_bounced	= true;
				grounding();
			} else stop();
		}
	} else if (type == ControlCom::eventAnimationEnd) {
		select_next_anim_state();
	} else if (type == ControlCom::eventAnimationStart) {
		
		// start new animation
		SControlAnimationData		*ctrl_data = (SControlAnimationData*)m_man->data(this, ControlCom::eControlAnimation); 
		VERIFY						(ctrl_data);
		
		if ((m_anim_state_current == eStateGlide) && (m_anim_state_prev == eStateGlide)) {
			//---------------------------------------------------------------------------------
			// start jump here
			//---------------------------------------------------------------------------------
			// получить врем¤ физ.прыжка
			float ph_time = m_object->character_physics_support()->movement()->JumpMinVelTime(m_target_position);
			// выполнить прыжок в соответствии с делителем времени
			float cur_factor	= ((m_data.force_factor > 0) ? m_data.force_factor : m_jump_factor);
			m_jump_time			= ph_time/cur_factor;
			m_object->character_physics_support()->movement()->Jump(m_target_position,m_jump_time);
			m_time_started		= time();
			m_time_next_allowed	= m_time_started + m_delay_after_jump;
			//---------------------------------------------------------------------------------
			
			// set angular speed in exclusive force mode
			SControlDirectionData					*ctrl_data_dir = (SControlDirectionData*)m_man->data(this, ControlCom::eControlDir); 
			VERIFY									(ctrl_data_dir);	

			ctrl_data_dir->heading.target_angle		= m_man->direction().angle_to_target(m_target_position);

			float cur_yaw,target_yaw;
			m_man->direction().get_heading			(cur_yaw, target_yaw);
			ctrl_data_dir->heading.target_speed		= angle_difference(cur_yaw,target_yaw)/ m_jump_time;
			ctrl_data_dir->linear_dependency		= false;
			//---------------------------------------------------------------------------------

			ctrl_data->set_speed	(m_man->animation().current_blend()->timeTotal/ m_man->animation().current_blend()->speed / m_jump_time);

		} else 
			ctrl_data->set_speed	(-1.f);

	}
}
예제 #3
0
void LvrQueryUpdater::doUpdateQueryValues(Atom* atom,vector<bool> isolatedTerms,vector<int> sampledTrueVals)
{
	//if(!isNormIdInQuery(atom->symbol->normParentId))
		//return;
	//ground the atom, if not grounded
	vector<LvrTerm*> iterms;
	vector<LvrTerm*> niterms;
	for(unsigned int i=0;i<atom->terms.size();i++)
	{
		if(!isolatedTerms[i])
		{
			niterms.push_back(atom->terms[i]);
		}
		else
		{
			iterms.push_back(atom->terms[i]);
		}
	}
	vector<vector<int> > permutedList;
	LvrPermutations::permuteTerms(niterms,permutedList);
	vector<vector<int> > permutedList1;
	LvrPermutations::permuteTerms(iterms,permutedList1);
	vector<int> grounding(atom->terms.size());
	for(unsigned int i=0;i<permutedList.size();i++)
	{
		int iter=0;
		for(unsigned int jj=0;jj<grounding.size();jj++)
		{
			if(!isolatedTerms[jj])
				grounding[jj] = permutedList[i].at(iter);
		}
		//set random groundings to true
		//set<int> indexes;
		vector<int> indexesToSetTrue;
		int countInd = 0;
		while(countInd!=sampledTrueVals[i])
		{
			int ind = LvRandomGenUtil::Instance()->getRandomPosition(permutedList1.size());
			if(find(indexesToSetTrue.begin(),indexesToSetTrue.end(),ind)==indexesToSetTrue.end())
			{
				//indexes.insert(ind);
				indexesToSetTrue.push_back(ind);
				countInd++;
			}
		}
		//for(set<int>::iterator it = indexes.begin();it!=indexes.end();it++)
		for(unsigned int kk=0;kk<permutedList1.size();kk++)
		{
			int iter = 0;
			for(unsigned int jj=0;jj<grounding.size();jj++)
			{
				if(isolatedTerms[jj])
					grounding[jj] = permutedList1[kk].at(iter);
			}
			vector<int> intRep(grounding.size()+1);
			//intRep[0]=atom->symbol->parentId;
			intRep[0]=atom->symbol->normParentId;
			for(unsigned int jj=0;jj<grounding.size();jj++)
				intRep[jj+1] = grounding[jj];
			bool value;
			bool found = lvrAtomHashUpdateFlags->getValue(intRep,value);
			if(!found)
				continue;
			if(!value)
			{
				//bool assignment=false;
				int assignment=0;
				if(find(indexesToSetTrue.begin(),indexesToSetTrue.end(),kk)!=indexesToSetTrue.end())
				{
					lvrAtomHashTemplate->incrementValue(intRep,1);
					//assignment=true;
					assignment = 1;
				}
				currentSampledValue->update(intRep,assignment);
				lvrAtomHashUpdateFlags->update(intRep,true);
			}
		}

		/*
		vector<int> intRep1(grounding.size()+1);
		//intRep[0]=atom->symbol->parentId;
		intRep1[0] = atom->symbol->normParentId;
		for(unsigned int jj=0;jj<grounding.size();jj++)
			intRep1[jj+1] = grounding[jj];
		lvrAtomHashUpdateFlags->update(intRep1,true);
		*/
	}
}