예제 #1
0
파일: Main.cpp 프로젝트: calonx/Code
//==============================================================================
int main () {
    VertexSimple vertices[BOX_VERTEX_COUNT];
    ushort indices[BOX_INDEX_COUNT];
    
    GenerateBox(vertices, arrsize(vertices), indices, arrsize(indices));
    
    const float scale = 0.5f;
    for (uint i = 0; i < arrsize(vertices); ++i) {
        vertices[i].x *= scale;
        vertices[i].y *= scale;
        vertices[i].z *= scale;
    }
    
    const Rect4i windowRect(0, 0, 800, 600);
    IGraphics * graphics = Gphx::GraphicsCreate(L"GraphicsTest", windowRect);
    
    IModel * model = graphics->CreateModel(vertices, arrsize(vertices), indices, arrsize(indices));
    
    while (graphics->Advance()) {
        graphics->RenderBegin();
        model->Render();
        graphics->RenderEnd();
    }
    
    delete model;
    delete graphics;
    
    _CrtDumpMemoryLeaks();
    
    return 0;
}
예제 #2
0
CPlayerSource::CPlayerSource(const CString& name, ILocalEntity * parent) :
IBasePlayer (name, parent)
{
    int modelId = Game::modelManager->getResourceId("../../models/player.mdl");
    IModel * mdl = new IModel(Game::modelManager->getModelData(modelId));
    setModel(mdl);

    // Suppression du buffer graphique
    CBuffer * buffer = mdl->getBuffer();
    delete buffer;
    mdl->setBuffer(nullptr);
}
예제 #3
0
//-----------------------------------------------------------------------------
void ObjDetailPGView::OnObjPropBeforeRemove(const IModel& vec, const std::vector<SptrIModel>& remVec)
{
	auto obj_prop_array = mObj->GetObjPropArray();

	auto propCategory = GetProperty("user_obj_prop");
	if (obj_prop_array->GetChildQty() == remVec.size())
	{
		propCategory->DeleteChildren();
	}
	else
	{
		size_t pos = 0;
		for (const auto& remItem : remVec)
		{
			if (vec.GetItemPosition(remItem, pos))
			{
				DeleteProperty(pos);
			}

		}
	}
	if (!propCategory->GetChildCount())
		propCategory->Hide(true);
	else
		propCategory->Hide(false);

}
예제 #4
0
		IModel *AsyncRenderer::CreateModel(spades::VoxelModel *bmp) {
			SPADES_MARK_FUNCTION();
			
			class CreateModelDispatch: public ConcurrentDispatch {
				IRenderer *base;
				VoxelModel *bmp;
				IModel *result;
				std::string error;
			public:
				CreateModelDispatch(IRenderer *base, VoxelModel *bmp):
				base(base), bmp(bmp), result(NULL){}
				virtual void Run(){
					try{
						result = base->CreateModel(bmp);
					}catch(const std::exception& ex){
						error = ex.what();
					}
				}
				IModel *GetResult() {
					if(!error.empty()){
						SPRaise("Error while CreateImageDispatch:\n%s", error.c_str());
					}else{
						return result;
					}
				}
			};
			
			FlushCommands();
			CreateModelDispatch dispatch(base, bmp);
			dispatch.StartOn(queue);
			dispatch.Join();
			IModel *img = dispatch.GetResult();
			return img;
		}
예제 #5
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnRowBeforeRemove(const IModel& vec, const std::vector<SptrIModel>& remVec)
{
	wxBusyCursor			busyCursor;
	wxWindowUpdateLocker	wndLockUpdater(this);
	
	if (vec.size() != remVec.size() )
	{
		size_t pos;
		wxArrayInt	itemsArray;
		for (const auto& remItem : remVec)
		{
			if (vec.GetItemPosition(remItem, pos))
				itemsArray.push_back(pos);
		}
		mDataViewModel->RowsDeleted(itemsArray);
	}
	else
		mDataViewModel->Reset(0);
}//OnRemove
예제 #6
0
		void AsyncRenderer::AddLongSprite(IImage *img, Vector3 p1, Vector3 p2,
									  float radius){
			SPADES_MARK_FUNCTION();
			rcmds::AddLongSprite *cmd = generator->AllocCommand<rcmds::AddLongSprite>();
			cmd->img = img;
			img->AddRef();
			cmd->p1 = p1;
			cmd->p2 = p2;
			cmd->radius = radius;
		}
예제 #7
0
		void AsyncRenderer::AddSprite(IImage *img, Vector3 center,
									  float radius, float rotation){
			SPADES_MARK_FUNCTION();
			rcmds::AddSprite *cmd = generator->AllocCommand<rcmds::AddSprite>();
			cmd->img = img;
			img->AddRef();
			cmd->center = center;
			cmd->radius = radius;
			cmd->rotation = rotation;
		}
예제 #8
0
파일: scenewidget.cpp 프로젝트: lgarest/42
/*
========================
setActiveModel
========================
*/
void CSceneWidget::setActiveModel( int index )
{
	IModel* mdl = NULL;
	QString ptName( "" );
	int pt = GL_POINTS;

	// validate index
	if( index >= 0 && index < m_numModels )
	{
		mdl = m_models[ index ];
		pt  = mdl->getPrimitiveType();
		ptName = mdl->getPrimitiveTypeName();
	}

	// set new state
	m_scene->getShader()->setGeometryInputType( pt );
	m_labPrimitiveType->setText( ptName );
	m_scene->setCurrentModel( mdl );
}
예제 #9
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnRowAfterChange(const IModel& newVec, const std::vector<unsigned int>& itemVec)
{
	wxBusyCursor			busyCursor;
	wxWindowUpdateLocker	wndLockUpdater(this);

	auto changedQty = itemVec.size();
	bool changeAll = newVec.GetChildQty() == itemVec.size();

	if (!changeAll && changedQty < 100)
	{
		for (const unsigned int& item : itemVec)
			mDataViewModel->RowChanged(item);
	}
	else
	{
		mDataViewModel->Reset(changedQty);
		this->Refresh();
	}
	OnChangeVecState(newVec.GetState());
}//OnChange
예제 #10
0
		IModel *AsyncRenderer::RegisterModel(const char *filename) {
			SPADES_MARK_FUNCTION();
			
			class RegisterModelDispatch: public ConcurrentDispatch {
				IRenderer *base;
				const char *fn;
				IModel *result;
				std::string error;
			public:
				RegisterModelDispatch(IRenderer *base, const char *fn):
				base(base), fn(fn), result(NULL){}
				virtual void Run(){
					try{
						result = base->RegisterModel(fn);
					}catch(const std::exception& ex){
						error = ex.what();
					}
				}
				IModel *GetResult() {
					if(!error.empty()){
						SPRaise("Error while RegisterImageDispatch:\n%s", error.c_str());
					}else{
						return result;
					}
				}
			};
			
			std::map<std::string, IModel *>::iterator it = models.find(filename);
			if(it == models.end()) {
				FlushCommands();
				RegisterModelDispatch dispatch(base, filename);
				dispatch.StartOn(queue);
				dispatch.Join();
				IModel *img = dispatch.GetResult();
				models[filename] = img;
				img->AddRef();
				return img;
			}
			return it->second;
		}
예제 #11
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnRowAfterInsert(const IModel& vec, const std::vector<SptrIModel>& newItems
	, const SptrIModel& itemBefore)
{
	wxBusyCursor			busyCursor;
	wxWindowUpdateLocker	wndLockUpdater(this);

	if (itemBefore)
	{
		size_t pos;
		if (vec.GetItemPosition(itemBefore, pos))
		{
			for (const auto& curr : newItems)
				mDataViewModel->RowInserted(pos++);
		}
	}
	else
	{
		for (const auto& curr : newItems)
			mDataViewModel->RowAppended();
	}
	OnChangeVecState(vec.GetState());
}//OnAppend
예제 #12
0
void Evaluation::eval (IModel &model, ISamples &samples, ssi_size_t stream_index) {

	// init confussion matrix
	_trainer = 0;
	destroy_conf_mat ();
	init_conf_mat (samples);
	ssi_size_t n_classes = samples.getClassSize ();
	ssi_real_t *probs = new ssi_real_t[n_classes];

	_n_total = samples.getSize ();
	_result_vec = new ssi_size_t[2*_n_total];
	_result_vec_ptr = _result_vec;

	samples.reset ();
	const ssi_sample_t *sample = 0;	
	while (sample = samples.next ()) {

		ssi_size_t real_index = sample->class_id;
		*_result_vec_ptr++ = real_index;
		if (model.forward (*sample->streams[stream_index], n_classes, probs)) {

			ssi_size_t max_ind = 0;
			ssi_real_t max_val = probs[0];
			for (ssi_size_t i = 1; i < n_classes; i++) {
				if (probs[i] > max_val) {
					max_val = probs[i];
					max_ind = i;
				}
			}

			*_result_vec_ptr++ = max_ind;
			_conf_mat_ptr[real_index][max_ind]++;
			_n_classified++;

		} else if (!_allow_unclassified) {
			ssi_size_t max_ind = _default_class_id;
			*_result_vec_ptr++ = max_ind;
			_conf_mat_ptr[real_index][max_ind]++;
			_n_classified++;
		} else {
			*_result_vec_ptr++ = SSI_ISAMPLES_GARBAGE_CLASS_ID;
			_n_unclassified++;
		}		
	}

	delete[] probs;
}
예제 #13
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnFieldBeforeRemove(const IModel& vec, const std::vector<SptrIModel>& remVec)
{
	if (!mModel)
		return;
	wxWindowUpdateLocker	wndLockUpdater(this);
	for (const auto& field : remVec)
	{
		size_t model_idx = 0;
		if (vec.GetItemPosition(field, model_idx))
		{
			auto col_idx = GetModelColumnIndex(model_idx);
			auto col = GetColumn(col_idx);
			if (col)
				this->DeleteColumn(col);
		}
	}
}
예제 #14
0
ConstSection CFormatHandler::GetSectionByIndex(const IModel &model,size_t index) const
{
	return model.GetSectionByIndex(index);
}
예제 #15
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnFieldAfterInsert(const IModel& vec, const std::vector<SptrIModel>& newItems
	, const SptrIModel& itemBefore)
{
	if (!mModel)
		return;
	wxWindowUpdateLocker	wndLockUpdater(this);
	const auto& fvec = mModel->mFieldVec;
	for (const auto& new_item : newItems)
	{
		size_t model_idx = -1;
		if (vec.GetItemPosition(new_item, model_idx))
		{
			const auto& field = fvec->at(model_idx)->GetData();
			if (field.mGuiShow)
			{
				wxString name = field.mTitle;
				auto width = GetColumnWidthBy(field.mType);

				//auto col = AppendTextColumn(name, model_idx, wxDATAVIEW_CELL_INERT, width,
				//	wxALIGN_NOT, /*wxDATAVIEW_COL_SORTABLE | */wxDATAVIEW_COL_RESIZABLE);

				class wxDataViewMLTextRenderer : public wxDataViewTextRenderer
				{
				public:
					wxDataViewMLTextRenderer(const wxString &  varianttype = wxT("string"), //GetDefaultType(),
						wxDataViewCellMode  mode = wxDATAVIEW_CELL_INERT,
						int  align = wxDVR_DEFAULT_ALIGNMENT )
						:wxDataViewTextRenderer(varianttype, mode, align)
					{}
					void RenderText(const wxString& text,
						int xoffset,
						wxRect rect,
						wxDC *dc,
						int state) override
					{
						wxCoord widthText, heightText, heightLine;
						dc->GetMultiLineTextExtent(text, &widthText, &heightText, &heightLine); 

						if (heightLine && heightText > heightLine)
						{
							int qty = heightText / heightLine -1;
							int rh = GetView()->GetCharHeight() * 2 + 2;
							int max_offset = (rh - heightLine) / 2;
							int calc_offset = qty* (heightLine / 2);
							int curr_offset = (calc_offset > max_offset) ? max_offset : calc_offset;
							rect.y = rect.y - curr_offset;
							rect.height = heightText;
							rect.width = widthText;
						}
						wxDataViewTextRenderer::RenderText(text, xoffset, rect, dc, state);
						/*
						wxRect rectText = rect;
						rectText.x += xoffset;
						rectText.width -= xoffset;

						// check if we want to ellipsize the text if it doesn't fit
						wxString ellipsizedText;
						if (GetEllipsizeMode() != wxELLIPSIZE_NONE)
						{
							ellipsizedText = wxControl::Ellipsize
								(
								text,
								*dc,
								GetEllipsizeMode(),
								rectText.width,
								wxELLIPSIZE_FLAGS_NONE
								);
						}

						// get the alignment to use
						dc->DrawLabel(ellipsizedText.empty() ? text : ellipsizedText,
							rectText, GetEffectiveAlignment());
						*/
					}
					
				};

				auto renderer = new wxDataViewMLTextRenderer();
				if(FieldType::ftText == field.mType)
					renderer->EnableEllipsize(wxELLIPSIZE_START);

				wxDataViewColumn * col = new wxDataViewColumn(name
					, renderer
					, model_idx
					, width
					, wxALIGN_NOT
					, wxDATAVIEW_COL_RESIZABLE);
				this->AppendColumn(col);

				auto col_idx = GetColumnIndex(col);

				if (ftText == field.mType)
					EnableAutosizeColumn(col_idx);

				SetGuiColumnSort(field, col);
			}//if (field.mGuiShow)

		}
	}
}
예제 #16
0
	bool ModelInstance::setModel(const char* modelName,ModelNode *pNode)
	{
		IModelManager *pModelManager = getRenderEngine()->getModelManager();
		IModel *pModel = pModelManager->loadModel(modelName);
		if(!pModel)return false;

		m_pModel = pModel;
		m_pNode = pNode;

		//设置buffer		
		m_pIB = m_pModel->getIndexBuffer();
		m_pVBTexcoord = m_pModel->getTexcoordBuffer();
		m_pVBBlendWeight = m_pModel->getBlendWeightBuffer();
		m_pBlendShaderProgram = m_pModel->getBlendShaderProgram();//需要再构造SubModelInstance前设置
		m_needDrawShadow = m_pModel->needDrawShadow();

		//创建子mesh
		uint numSubModels = m_pModel->getNumSubModels();
		for(uint i = 0;i < numSubModels;i++)
		{
			ISubModel *pSubModel = m_pModel->getSubModel(i);
			SubModelInstance *pSubModelInstance = new SubModelInstance(this,pSubModel, i);
			m_subModels.push_back(pSubModelInstance);
			m_vBlendIndices.push_back( m_pModel->getBlendIndicesBuffer(i));//保存骨骼混合的索引buffer
		}

		//创建骨骼树
		if( !m_skeleton.create(m_pModel->getCoreSkeletion() ) )
		{
			return false;
		}
		//uint numBones = m_pModel->numBones();
		//for(uint i = 0;i < numBones;i++)
		//{
		//	BoneData *pData = m_pModel->getBone(i);
		//	Bone *pBone = m_skeleton.createBone(m_pNode);
		//	loadBone(pBone,pData);
		//}
		////骨骼树形结构构建
		//for(size_t i = 0;i < numBones;i++)
		//{
		//	BoneData *pBone = m_pModel->getBone(i);
		//	if(pBone->parentId != -1)
		//	{
		//		for(size_t j = 0;j < numBones;j++)
		//		{
		//			BoneData *pParent = m_pModel->getBone(j);
		//			if(pBone->parentId == pParent->objectId)
		//			{
		//				m_skeleton.getBone(i)->setParent(m_skeleton.getBone(j));
		//				break;
		//			}
		//		}
		//	}
		//	m_skeleton.getBone(i)->setPrecomputeMatrix(pBone->precomputeMtx);
		//}

		//ParticleSystem
		size_t size = m_pModel->numParticleSystem();
		for(size_t j = 0;j < size;j++)
		{
			ParticleSystem *pParticleSystem = new ParticleSystem;
			pParticleSystem->m_pData = m_pModel->getParticleSystemData(j);
			pParticleSystem->m_pBone = m_skeleton.getBone(pParticleSystem->m_pData->boneObjectId);
			pParticleSystem->m_pNode = m_pNode;
			m_vParticleSystem.push_back(pParticleSystem);
		}

		//RibbonSystem
		size = m_pModel->numRibbonSystem();
		for(size_t j = 0;j < size;j++)
		{
			RibbonSystem *pRibbonSystem = new RibbonSystem;
			pRibbonSystem->m_pData = m_pModel->getRibbonSystemData(j);
			pRibbonSystem->m_pBone = m_skeleton.getBone(pRibbonSystem->m_pData->boneObjectId);
			pRibbonSystem->m_pNode = m_pNode;
			m_vRibbonSystem.push_back(pRibbonSystem);
		}

		//MmParticleSystem
		size = m_pModel->numMmParticleSystem();
		for(size_t j = 0;j < size;j++)
		{
			MmParticleSystem *pMmPs = new MmParticleSystem;
			pMmPs->m_pData = m_pModel->getMmParticleSystem(j);
			pMmPs->m_pNode = m_pNode;
			pMmPs->m_pBone = m_skeleton.getBone(pMmPs->m_pData->bone);
			m_vMmParticleSystem.push_back(pMmPs);
		}

		if(m_pModel->getAnimationCount())
			setCurrentAnimation(pModel->getAnimation(0)->getName());

		return true;
	}
예제 #17
0
파일: VTable.cpp 프로젝트: alex3696/wh3
//-----------------------------------------------------------------------------
void VTable::OnRowAfterRemove(const IModel& vec, const std::vector<SptrIModel>& remVec)
{
	OnChangeVecState(vec.GetState());
}
예제 #18
0
bool FeatureFusion::forward (ssi_size_t n_models,
	IModel **models,
	ssi_size_t n_streams,
	ssi_stream_t *streams[],
	ssi_size_t n_probs,
	ssi_real_t *probs) {

	if (!isTrained ()) {
		ssi_wrn ("not trained");
		return false;
	}

	if (n_streams != _n_streams) {
		ssi_wrn ("#streams (%u) differs from #streams (%u)", n_streams, _n_streams);
		return false;
	}

	if (_n_models != n_models) {
		ssi_wrn ("#models (%u) differs from #models (%u)", n_models, _n_models);
		return false;
	}

	if (_n_classes != n_probs) {
		ssi_wrn ("#probs (%u) differs from #classes (%u)", n_probs ,_n_classes);
		return false;
	}

	//No Missing Data:
	if(!_handle_md){

		IModel *model = 0;
		ssi_stream_t *stream = 0;

		model = models[0];

		ssi_stream_t *fusion_stream = new ssi_stream_t;

		ssi_size_t fusion_stream_dim = 0;
		for(ssi_size_t nstrm = 0; nstrm < _n_streams; nstrm++){
			fusion_stream_dim += streams[nstrm]->dim;
		}

		//create aligned streams
		ssi_stream_init (*fusion_stream, 1, fusion_stream_dim, streams[0]->byte, streams[0]->type, streams[0]->sr);
		
		ssi_byte_t *ptr = fusion_stream->ptr;
		for(ssi_size_t i = 0; i < _n_streams; i++){
			memcpy(ptr, streams[i]->ptr, ( streams[i]->byte * streams[i]->dim ) );
			ptr += ( streams[i]->byte * streams[i]->dim );
		}

		//clear probs
		for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
			probs[num_probs] = 0.0f;
		}

		model->forward (*fusion_stream, n_probs, probs);

		ssi_stream_destroy(*fusion_stream);
		delete fusion_stream;
		fusion_stream = 0;

		///// is there a draw ? ///
		ssi_size_t max_ind = 0;
		ssi_size_t max_ind_draw = 0;
		ssi_real_t max_val = probs[0];
		bool draw = false;

		for (ssi_size_t i = 1; i < n_probs; i++) {
			if (probs[i] >= max_val) {
				if(probs[i] == max_val){
					draw = true;
					max_ind_draw = i;
				}
				max_val = probs[i];
				max_ind = i;
			}
		}
		
		if(draw && (max_ind == max_ind_draw)){
			return false;
		}else{
			return true;
		}

	}//No Missing Data


	//Missing Data:
	bool found_data = false;

	IModel *model = 0;
	ssi_stream_t *stream = 0;

	//calculate actual models
	ssi_size_t miss_counter = 0;
	ssi_size_t *available = new ssi_size_t[n_models];
	available[0] = 1;
	for (ssi_size_t n_model = 1; n_model < _n_models; n_model++) {
		stream = streams[n_model - 1];
		if (stream->num > 0) {
			found_data = true;
			available[n_model] = 1;
		}
		else{
			miss_counter++;
			available[n_model] = 0;
			if(available[0] == 1){
				available[0] = 0;
				miss_counter++;
			}
		}
	}
	ssi_size_t counter = 0;
	ssi_size_t *models_actual = new ssi_size_t[(n_models - miss_counter)];
	for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
		if(available[n_model] == 1){
			models_actual[counter] = n_model;
			counter++;
		}
	}

	if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
		ssi_print("\n\n-----------------------------\navailable models:\n");
		for(ssi_size_t i = 0; i < (n_models - miss_counter); i++){
			ssi_print("%d ", models_actual[i]);
		}ssi_print("\n");
	}

	if(found_data){

		if(available[0] == 1){
			//feature fusion possible
			if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
				ssi_print("\nfeature fusion possible\n");
			}

			model = models[0];
			stream = 0;
			ssi_stream_t *fusion_stream = new ssi_stream_t;

			ssi_size_t fusion_stream_dim = 0;
			for(ssi_size_t nstrm = 0; nstrm < _n_streams; nstrm++){
				fusion_stream_dim += streams[nstrm]->dim;
			}

			//create aligned streams
			ssi_stream_init (*fusion_stream, 1, fusion_stream_dim, streams[0]->byte, streams[0]->type, streams[0]->sr);
			
			ssi_byte_t *ptr = fusion_stream->ptr;
			for(ssi_size_t i = 0; i < _n_streams; i++){
				memcpy(ptr, streams[i]->ptr, ( streams[i]->byte * streams[i]->dim ) );
				ptr += ( streams[i]->byte * streams[i]->dim );
			}

			//clear probs
			for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
				probs[num_probs] = 0.0f;
			}

			model->forward (*fusion_stream, n_probs, probs);

			ssi_stream_destroy(*fusion_stream);
			delete fusion_stream;
			fusion_stream = 0;

			if(available){
				delete [] available;
				available = 0;
			}
			if(models_actual){
				delete [] models_actual;
				models_actual = 0;
			}

			return true;

		}else{
			//feature fusion not possible, choose filler ...
			if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
				ssi_print("\nfeature fusion not possible: filler needed\n");
				ssi_print("\nfiller:\n");
				for (ssi_size_t n_model = 0; n_model < _n_streams; n_model++) {
					ssi_print("%d ", _filler[n_model]);
				}ssi_print("\n");
			}

			bool model_available = false;
			ssi_size_t model_id = 0;
			for(ssi_size_t h = 0; h < _n_streams; h++){
				model_id = _filler[h];
				for(ssi_size_t i = 0; i < (n_models - miss_counter); i++){
					if(model_id == models_actual[i]){
						model_available = true;
						break;
					}
				}
				if(model_available == true){
					model = models[model_id];
					if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
						ssi_print("\nSelected Model: %d", model_id);
					}
					break;
				}
			}

			model->forward(*streams[model_id - 1], n_probs, probs);

		}

	}

	if(available){
		delete [] available;
		available = 0;
	}
	if(models_actual){
		delete [] models_actual;
		models_actual = 0;
	}
	

	/// is there a draw ? ///
	ssi_size_t max_ind = 0;
	ssi_size_t max_ind_draw = 0;
	ssi_real_t max_val = probs[0];
	bool draw = false;

	for (ssi_size_t i = 1; i < n_probs; i++) {
		if (probs[i] >= max_val) {
			if(probs[i] == max_val){
				draw = true;
				max_ind_draw = i;
			}
			max_val = probs[i];
			max_ind = i;
		}
	}
	
	if(draw && (max_ind == max_ind_draw)){
		return false;
	}else{
		return found_data;
	}
}
예제 #19
0
Sprite* NodeFactory::CreatePODSprite(const FileIdRef& modelName)
{
	IModel* model = ModelFactory::Instance().Create(modelName);
	RETURN_NULL_IF_NULL(model);
	return (Sprite*)model->CreateCloneInstance();
}
예제 #20
0
ConstSection CFormatHandler::GetSection(const IModel &model,String name) const
{
	return model.GetSection(name);
}
예제 #21
0
void UpdateAgentsFromCrowdData(GSceneManager* crowdEngine, map<UID, IModel*>& agentModels, map<string, float> meshScales, map<string, IMesh*> meshList, map<UID, IModel*>& DestinationVectors, map<UID, IModel*>& MovementVectors)
{
	//TODO: Find correct value for thisScale 

	gen::CMatrix3x3 tempAgentMat;
	float tempModelMat[16];

	for (auto agent : agentModels)
	{
		if (crowdEngine->GetAgentMatrix(agent.first, tempAgentMat))
		{
			float thisScale = meshScales[FindStringFromMesh(agent.second->GetMesh(), meshList)];

			agent.second->GetMatrix(tempModelMat);
			tempModelMat[0] = tempAgentMat.e00 * thisScale;
			
			tempModelMat[2] = tempAgentMat.e01 * thisScale;

			



			tempModelMat[8] = tempAgentMat.e10 * thisScale;
			
			tempModelMat[10] = tempAgentMat.e11 * thisScale;

			tempModelMat[12] = tempAgentMat.e20;
			tempModelMat[14] = tempAgentMat.e21;
			agent.second->SetMatrix(tempModelMat);
		}
	}

#ifdef DirectionVisualiserEnabled
	gen::CVector2 tempDestination;
	for (auto destinationVector : DestinationVectors)
	{
		if (crowdEngine->GetAgentDestination(destinationVector.first, tempDestination))
		{
			IModel* thisAgentModel = agentModels.at(destinationVector.first);

			//Set the vector model to the id model's position
			destinationVector.second->SetPosition(thisAgentModel->GetX(),
				thisAgentModel->GetY() + 10.0f,		//+10 to have to vector model rest atop the id model
				thisAgentModel->GetZ());

			destinationVector.second->LookAt(tempDestination.x, 10.0f, tempDestination.y);
			
			CVector2 vectorToEnd = tempDestination - CVector2(thisAgentModel->GetX(), thisAgentModel->GetZ());
			destinationVector.second->ScaleZ(vectorToEnd.Length());
		}
	}

	for (auto movementVector : MovementVectors)
	{
		//Will only fetch the results of global collision avoidance
		if (crowdEngine->GetAgentDesiredVector(movementVector.first, tempDestination))
		{
			IModel* thisAgentModel = agentModels.at(movementVector.first);

			//Set the vector model to the id model's position
			movementVector.second->SetPosition(thisAgentModel->GetX(),
				thisAgentModel->GetY() + 11.0f,		//+11 to have to vector model rest atop the id model
				thisAgentModel->GetZ());

			movementVector.second->LookAt(tempDestination.x + thisAgentModel->GetX(), 10.0f, tempDestination.y + thisAgentModel->GetZ());

			movementVector.second->ScaleZ(tempDestination.Length());
		}
	}
#endif
}
예제 #22
0
void UpdateAgentFromCrowdData(UID agentID, GSceneManager* crowdEngine, map<UID, IModel*>& agentModels, map<string, float> meshScales, map<string, IMesh*> meshList, map<UID, IModel*>& DestinationVectors, map<UID, IModel*>& MovementVectors)
{
	gen::CMatrix3x3 tempAgentMat;

	if (crowdEngine->GetAgentMatrix(agentID, tempAgentMat))
	{
		try		//Find the id 'holding' and set the holding skin
		{
			float tempModelMat[16];
			IModel* thisAgentModel;
			thisAgentModel = agentModels.at(agentID);

			float thisScale = meshScales[FindStringFromMesh(thisAgentModel->GetMesh(), meshList)];  

			thisAgentModel->GetMatrix(tempModelMat);
			tempModelMat[0] = tempAgentMat.e00 * thisScale;

			tempModelMat[2] = tempAgentMat.e01 * thisScale;





			tempModelMat[8] = tempAgentMat.e10 * thisScale;

			tempModelMat[10] = tempAgentMat.e11 * thisScale;

			tempModelMat[12] = tempAgentMat.e20;
			tempModelMat[14] = tempAgentMat.e21;
			thisAgentModel->SetMatrix(tempModelMat);
		}
		catch (std::out_of_range err)
		{
			cout << err.what();
		}
	}

#ifdef DirectionVisualiserEnabled
	
	gen::CVector2 tempDestination;
	if (crowdEngine->GetAgentDestination(agentID, tempDestination))
	{
		IModel* thisVectorModel;
		IModel* thisAgentModel;
		thisAgentModel = agentModels.at(agentID);
		thisVectorModel = DestinationVectors.at(agentID);
		
		//Set the vector model to the id model's position
		thisVectorModel->SetPosition(thisAgentModel->GetX(),
		thisAgentModel->GetY() + 10.0f,
		thisAgentModel->GetZ());
		
		thisVectorModel->LookAt(tempDestination.x, 10.0f, tempDestination.y);

		CVector2 vectorToEnd = tempDestination - CVector2(thisAgentModel->GetX(), thisAgentModel->GetZ());
		thisVectorModel->ScaleZ(vectorToEnd.Length());
	}

	if (crowdEngine->GetAgentDesiredVector(agentID, tempDestination))
	{
		IModel* thisVectorModel;
		IModel* thisAgentModel;
		thisAgentModel = agentModels.at(agentID);
		thisVectorModel = MovementVectors.at(agentID);

		//Set the vector model to the id model's position
		thisVectorModel->SetPosition(thisAgentModel->GetX(),
			thisAgentModel->GetY() + 10.0f,
			thisAgentModel->GetZ());

		thisVectorModel->LookAt(tempDestination.x + thisAgentModel->GetX(), 10.0f, tempDestination.y + thisAgentModel->GetZ());

		thisVectorModel->ScaleZ(tempDestination.Length());
	}
#endif
}
예제 #23
0
int EngineMain(string worldFile)
{
	int returnValue = Quit_Completely;

	//--------------------------
	// CrowdDynamics Setup
	//--------------------------
	GSceneManager* crowdEngine = GSceneManager::GetInstance(worldFile);
	worldBlueprint = crowdEngine->GetWorldBlueprint();

	// Create a 3D engine (using TLX engine here) and open a window for it
	I3DEngine* gameEngine = New3DEngine(kTLX);
	gameEngine->StartWindowed();

	// Add default folder for meshes and other media
	gameEngine->AddMediaFolder(".\\Media");

	IFont* mousePosFont = gameEngine->LoadFont("Font1.bmp");

	IMesh* floorTileMesh = gameEngine->LoadMesh("FloorTile.x");
	IMesh* vectorMesh = gameEngine->LoadMesh("Vector.x");
	IMesh* influenceTileMesh = gameEngine->LoadMesh("InfluenceTile.x");
	IMesh* SkyboxMesh = gameEngine->LoadMesh("Skybox.x");

	////////////////////////
	// Obstacles
	////////////////////////
	std::map<string, float> obstacleMeshList = crowdEngine->GetObstacleMeshes();
	std::map<string, IMesh*> obstacleTLMeshes;

	for (auto mesh : obstacleMeshList)	//Load the TL Meshes
	{
		obstacleTLMeshes.emplace(make_pair(mesh.first, gameEngine->LoadMesh(mesh.first)));
	}

	vector<UID> obstacleUIDs = crowdEngine->GetObstacleUIDs();	//Get a list of all the obstacles in the scene
	map<UID, IModel*> obstacleModels;

	for (auto id : obstacleUIDs)	//Construct a TL model for each obstacle
	{
		string thisMeshName;
		if (crowdEngine->GetObstacleMesh(id, thisMeshName))
		{
			obstacleModels.emplace(id, obstacleTLMeshes[thisMeshName]->CreateModel());
		}
	}

	////////////////////////
	// Agents
	////////////////////////
	
	std::map<string, float> agentMeshScales = crowdEngine->GetAgentMeshes();
	std::map<string, IMesh*> agentTLMeshes;

	for (auto mesh : agentMeshScales)
	{
		agentTLMeshes.emplace(make_pair(mesh.first, gameEngine->LoadMesh(mesh.first)));
	}

	map<UID, IModel*> Agents;
	map<UID, IModel*> DestinationVectors;
	map<UID, IModel*> MovementVectors;

	vector<UID> AgentIDs = crowdEngine->GetAgentUIDs();

	for (auto id : AgentIDs)
	{
		//Use the Y Column as the height (0 column), CrowdDynamics uses X and Y as this will use X and Z
		//Where the model spawns is irrelevant as it's matrix is built from the CrowdDynamics matrix
		string thisMeshName;
		if (crowdEngine->GetAgentMeshFile(id, thisMeshName))
		{
			Agents.emplace(make_pair(id, agentTLMeshes[thisMeshName]->CreateModel()));
			Agents[id]->ScaleY(agentMeshScales[thisMeshName]);

#ifdef DirectionVisualiserEnabled
			DestinationVectors.insert(make_pair(id, vectorMesh->CreateModel()));
			MovementVectors.insert(make_pair(id, vectorMesh->CreateModel()));
#endif
		}
	}

#ifdef DirectionVisualiserEnabled
	for (auto item : MovementVectors)
	{
		item.second->SetSkin("vectortex2.jpg");
	}
#endif



	IModel** FloorTiles;
	IModel* SkyBox = SkyboxMesh->CreateModel();
	SkyBox->ScaleX((worldBlueprint.WorldSize.x + 2000.0f) / 2000.0f);			//worldBlueprint.WorldSize.x / 200.0f);
	SkyBox->ScaleZ((worldBlueprint.WorldSize.y + 2000.0f) / 2000.0f);		//worldBlueprint.WorldSize.y / 200.0f);
	SkyBox->SetPosition(worldBlueprint.WorldSize.x / 2.0f, -1000.0f, worldBlueprint.WorldSize.y / 2.0f);

	FloorTiles = new IModel*[worldBlueprint.subdivisions.x * worldBlueprint.subdivisions.y];
	for (int i = 0; i < worldBlueprint.subdivisions.x; i++)
	{
		for (int j = 0; j < worldBlueprint.subdivisions.y; j++)
		{
			FloorTiles[i * worldBlueprint.subdivisions.x + j] = floorTileMesh->CreateModel(i * (worldBlueprint.WorldSize.x / worldBlueprint.subdivisions.x), 0.0f, j * (worldBlueprint.WorldSize.y / worldBlueprint.subdivisions.y));
			FloorTiles[i * worldBlueprint.subdivisions.x + j]->ScaleX(worldBlueprint.WorldSize.x / worldBlueprint.subdivisions.x);
			FloorTiles[i * worldBlueprint.subdivisions.x + j]->ScaleZ(worldBlueprint.WorldSize.y / worldBlueprint.subdivisions.y);
			FloorTiles[i * worldBlueprint.subdivisions.x + j]->Scale(1.0f);
		}
	}

#ifdef InfluenceVisualiserEnabled
	IModel** InfluenceTiles;

	InfluenceTiles = new IModel*[worldBlueprint.influenceSubdivisions.x * worldBlueprint.influenceSubdivisions.y];
	for (int i = 0; i < worldBlueprint.influenceSubdivisions.x; i++)
	{
		for (int j = 0; j < worldBlueprint.influenceSubdivisions.y; j++)
		{
			InfluenceTiles[i * worldBlueprint.influenceSubdivisions.x + j] = influenceTileMesh->CreateModel(static_cast<float>(i) / worldBlueprint.influenceSquaresPerUnit, 0.5f, (static_cast<float>(j) + 1) / worldBlueprint.influenceSquaresPerUnit);
			InfluenceTiles[i * worldBlueprint.influenceSubdivisions.x + j]->RotateX(180.0f);
			InfluenceTiles[i * worldBlueprint.influenceSubdivisions.x + j]->ScaleX((1.0f / worldBlueprint.influenceSquaresPerUnit) * 0.75f);
			InfluenceTiles[i * worldBlueprint.influenceSubdivisions.x + j]->ScaleZ((1.0f / worldBlueprint.influenceSquaresPerUnit) * 0.75f);
		}
	}
#endif

	ICamera* cameras[Camera_Size];
	ECameraState currentCameraState = Camera_TopDown;
	cameras[Camera_FirstPerson]= gameEngine->CreateCamera(kFPS, worldBlueprint.WorldSize.x / 2.0f, (worldBlueprint.WorldSize.x + worldBlueprint.WorldSize.y) / 2, worldBlueprint.WorldSize.y / 2.0f);
	cameras[Camera_FirstPerson]->SetMovementSpeed(100.0f);
	cameras[Camera_FirstPerson]->SetRotationSpeed(25.0f);
	cameras[Camera_FirstPerson]->RotateX(90.0f);
	cameras[Camera_TopDown] = gameEngine->CreateCamera(kManual, worldBlueprint.WorldSize.x / 2.0f, 220.0f, worldBlueprint.WorldSize.y / 2.0f);
	cameras[Camera_TopDown]->RotateX(90.0f);

	float frameRate;
	stringstream frameStream;

	gen::CMatrix3x3 tempAgentMat;
	string tempString;

	//Assign the simulation matrices to the model matrices - first time
	UpdateAgentsFromCrowdData(crowdEngine, Agents, agentMeshScales,agentTLMeshes, DestinationVectors, MovementVectors);
	UpdateObstaclesFromCrowdData(crowdEngine, obstacleModels);


	UID holding = -1;
	crowdEngine->SetPaused(true);
	// The main game loop, repeat until engine is stopped
	while (gameEngine->IsRunning())
	{
		if (gameEngine->KeyHit(Key_Escape))
		{
			returnValue = Quit_Completely;
			gameEngine->Stop();
		}
		if (gameEngine->KeyHit(Key_Delete))
		{
			returnValue = Quit_LoadNewMap;
			gameEngine->Stop();
		}

		frameTime = gameEngine->Timer();
		// Draw the scene
		gameEngine->DrawScene(cameras[currentCameraState]);
		//Check if the active camera is to change
		CameraSwitcher(gameEngine, cameras, currentCameraState);

		DrawPointingPosition(gameEngine, cameras[currentCameraState], mousePosFont, frameStream);

		frameRate = 1 / frameTime;
		frameStream << setprecision(4) << (frameRate);
		gameEngine->SetWindowCaption(frameStream.str());
		frameStream.str("");



		CameraControls(gameEngine, cameras[currentCameraState]);

		/**** Update your scene each frame here ****/
		crowdEngine->Update(frameTime);	//Update the CrowdDynamics simulation

										//Update the influence representation from the crowd engine
#ifdef InfluenceVisualiserEnabled
		UpdateInfluenceFromCrowdData(crowdEngine, InfluenceTiles);
#endif

		//Assign the simulation matrices to the model matrices
		UpdateAgentsFromCrowdData(crowdEngine, Agents, agentMeshScales, agentTLMeshes, DestinationVectors, MovementVectors);
		UpdateObstaclesFromCrowdData(crowdEngine, obstacleModels);


		if (gameEngine->KeyHit(pauseKey))
		{
			crowdEngine->SetPaused(!crowdEngine->GetIsPaused());	//Toggle paused
		}
		if (gameEngine->KeyHeld(Key_T) && crowdEngine->GetIsPaused())
		{
			crowdEngine->PerformOneTimeStep();	//Update the CrowdDynamics simulation

												//Assign the simulation matrices to the model matrices
			UpdateAgentsFromCrowdData(crowdEngine, Agents, agentMeshScales, agentTLMeshes, DestinationVectors, MovementVectors);
			UpdateObstaclesFromCrowdData(crowdEngine, obstacleModels);

		}
		if (gameEngine->KeyHit(Key_N))
		{
			CVector3 tempPos = WorldPosFromPixel(gameEngine, cameras[currentCameraState]);
			CVector2 mousePosition = CVector2(tempPos.x, tempPos.z);
#ifdef _DEBUG
			crowdEngine->GetSquareString(mousePosition, tempString);
			cout << tempString;
#endif
		}
		if (gameEngine->KeyHeld(Mouse_LButton))
		{
			if (holding == -1)	//If not holding anything, pick the nearest item up
			{
				UID tempHold;
				if (FindNearestAgent(Agents, crowdEngine, tempHold, gameEngine, cameras[currentCameraState]))
				{
					holding = tempHold;
					string agentString;
#ifdef _DEBUG
					if (crowdEngine->GetAgentString(holding, agentString))
					{
						cout << "Picked up: " << endl;
						cout << agentString << endl;
					}
#endif
					try		//Find the id 'holding' and set the holding skin
					{
						Agents.at(holding)->SetSkin("tiles3.jpg");

					}
					catch (std::out_of_range err)
					{
						cout << err.what();
					}
				}
			}
			if (holding != -1)
			{
				CVector3 tempPos = WorldPosFromPixel(gameEngine, cameras[currentCameraState]);
				crowdEngine->SetAgentPosition(holding, CVector2(tempPos.x, tempPos.z));

				UpdateAgentFromCrowdData(holding, crowdEngine, Agents, agentMeshScales, agentTLMeshes, DestinationVectors, MovementVectors);

			}
		}
		else //Release the held item if there is a held item
		{
			if (holding != -1)
			{
#ifdef _DEBUG
				string agentString;
				if (crowdEngine->GetAgentString(holding, agentString))
				{
					cout << "Dropped: " << endl;
					cout << agentString << endl;
				}
#endif
				try
				{
					if (crowdEngine->GetAgentWatched(holding))
					{
						Agents.at(holding)->SetSkin("tiles2.jpg");
					}
					else
					{
						Agents.at(holding)->SetSkin("tiles1.jpg");
					}
				}
				catch (std::out_of_range err)
				{
					cout << err.what();
				}

				holding = -1;
			}
		}
		if (gameEngine->KeyHit(Mouse_RButton))
		{
			UID foundNearest;
			if (FindNearestAgent(Agents, crowdEngine, foundNearest, gameEngine, cameras[currentCameraState]))
			{
				bool isWatched = crowdEngine->GetAgentWatched(foundNearest);
				if (crowdEngine->SetAgentWatched(foundNearest, !crowdEngine->GetAgentWatched(foundNearest)))
				{
					cout << "Agent: " << foundNearest << " Is ";
					if (isWatched)	//Was being watched before change, is now not being watched
					{
						try
						{
							Agents.at(foundNearest)->SetSkin("tiles1.jpg");
						}
						catch (std::out_of_range err)
						{
							cout << endl << err.what() << endl;
						}
						cout << "Not ";
					}
					else
					{
						try
						{
							Agents.at(foundNearest)->SetSkin("tiles2.jpg");
						}
						catch (std::out_of_range err)
						{
							cout << endl << err.what() << endl;
						}
					}
					cout << "Being Watched" << endl;
				}
			}
		}
		if (gameEngine->KeyHit(Key_Space))
		{
			CVector3 tempPos = WorldPosFromPixel(gameEngine, cameras[currentCameraState]);
			string thisBlueprint = "AgentBlueprint1.xml";
			UID newID = crowdEngine->AddAgent(thisBlueprint, true, CVector2(tempPos.x, tempPos.z));
			if (agentMeshScales.count(thisBlueprint) == 0)	//This blueprint does not already exist on the TL side
			{
				float scale;
				if (crowdEngine->GetAgentMeshScale(thisBlueprint, scale))
				{
					agentTLMeshes.emplace(thisBlueprint, gameEngine->LoadMesh(thisBlueprint));
					agentMeshScales[thisBlueprint] = scale;
				}
			}
			Agents.insert(make_pair(newID, agentTLMeshes[thisBlueprint]->CreateModel(tempPos.x, 0.0f, tempPos.z)));
#ifdef DirectionVisualiserEnabled
			DestinationVectors.insert(make_pair(newID, vectorMesh->CreateModel(tempPos.x, 10.0f, tempPos.z)));
			MovementVectors.insert(make_pair(newID, vectorMesh->CreateModel(tempPos.x, 11.0f, tempPos.z)));
			MovementVectors.at(newID)->SetSkin("vectortex2.jpg");
#endif

		}
	}

	// Delete the 3D engine now we are finished with it
	gameEngine->Delete();
	delete[] FloorTiles;
#ifdef InfluenceVisualiserEnabled
	delete[] InfluenceTiles;
#endif
	delete crowdEngine;

	return returnValue;
}
예제 #24
0
size_t CFormatHandler::GetSectionCount(const IModel &model) const {
	return model.GetSectionCount();
}
예제 #25
0
bool MajorityVoting::forward (ssi_size_t n_models,
	IModel **models,
	ssi_size_t n_streams,
	ssi_stream_t *streams[],
	ssi_size_t n_probs,
	ssi_real_t *probs) {

	if (n_streams != _n_streams) {
		ssi_wrn ("#streams (%u) differs from #streams (%u)", n_streams, _n_streams);
		return false;
	}

	if (_n_streams != n_models) {
		ssi_wrn ("#models (%u) differs from #streams (%u)", n_models, _n_streams);
		return false;
	}

	if (_n_classes != n_probs) {
		ssi_wrn ("#probs (%u) differs from #classes (%u)", n_probs ,_n_classes);
		return false;
	}

	bool found_data = false;

	IModel *model = 0;
	ssi_stream_t *stream = 0;

	//calculate actual models
	ssi_size_t miss_counter = 0;
	ssi_size_t *available = new ssi_size_t[n_models];
	for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
		stream = streams[n_model];
		if (stream->num > 0) {
			found_data = true;
			available[n_model] = 1;
		}
		else{
			miss_counter++;
			available[n_model] = 0;
		}
	}
	ssi_size_t counter = 0;
	ssi_size_t *models_actual = new ssi_size_t[(n_models - miss_counter)];
	for (ssi_size_t n_model = 0; n_model < n_models; n_model++) {
		if(available[n_model] == 1){
			models_actual[counter] = n_model;
			counter++;
		}
	}

	if(found_data){

		ssi_size_t *votes = new ssi_size_t[(n_models - miss_counter)];

		for (ssi_size_t n_model = 0; n_model < (n_models - miss_counter); n_model++) {
			model = models[models_actual[n_model]];
			stream = streams[models_actual[n_model]];
			model->forward (*stream, n_probs, probs);

			ssi_size_t max_ind = 0;
			ssi_real_t max_val = probs[0];
			
			for (ssi_size_t i = 1; i < n_probs; i++) {
				if (probs[i] > max_val) {
					max_val = probs[i];
					max_ind = i;
				}
			}
			votes[n_model] = max_ind;

			if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
				for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
					ssi_print("%f ", probs[num_probs]);
				}ssi_print("- vote: %d\n", max_ind);
			}

		}
		if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
			ssi_print("\n");
		}

		//clear probs
		for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
			probs[num_probs] = 0;
		}

		//fill probs with votes
		for(ssi_size_t n_model = 0; n_model < (n_models - miss_counter); n_model++){
			probs[votes[n_model]]++;
		}
		
		if (ssi_log_level >= SSI_LOG_LEVEL_DEBUG) {
			for (ssi_size_t num_probs = 0; num_probs < n_probs; num_probs++){
				ssi_print("%f ", probs[num_probs]);
			}ssi_print("\n\n");
		}


		if(votes){
			delete[] votes;
			votes = 0;
		}
		if(available){
			delete [] available;
			available = 0;
		}
		if(models_actual){
			delete [] models_actual;
			models_actual = 0;
		}
	}
		
	/// is there a draw ? ///
	ssi_size_t max_ind = 0;
	ssi_size_t max_ind_draw = 0;
	ssi_real_t max_val = probs[0];
	bool draw = false;

	for (ssi_size_t i = 1; i < n_probs; i++) {
		if (probs[i] >= max_val) {
			if(probs[i] == max_val){
				draw = true;
				max_ind_draw = i;
			}
			max_val = probs[i];
			max_ind = i;
		}
	}
	
	if(draw && (max_ind == max_ind_draw)){
		return false;
	}else{
		return found_data;
	}
	
}
예제 #26
0
				virtual void Execute(IRenderer *r){
					r->RenderModel(model, param);
					model->Release(); model = NULL;
				}