Exemplo n.º 1
0
bool Chunk::Destroy(int x, int y, int z) {
	if (GetActive(x, y, z)) {
		m_blocks[x][y][z].SetActive(false);
		RebuildMesh();
		return true;
	}
	return false;
}
Exemplo n.º 2
0
	void Chunk::EndEdit()
	{
		if (_editing != 0)
		{
			_editing--;
			if (_editing == 0)
			{
				RebuildMesh();
			}
		}
	}
Exemplo n.º 3
0
	void DynamicsWorld::Update()
	{
		dynamicsWorld->stepSimulation(Time::Delta, 10);

		for (auto fb : BodyMap)
		{
			auto rb = fb.second->Entity->GetComponent<RigidBody>();
			if (rb != nullptr)
			{
				btRigidBody* body = rb->GetBody();

				if (body && body->getMotionState())
				{
					btTransform trans;
					body->getMotionState()->getWorldTransform(trans);

					auto p = trans.getOrigin();
					auto r = trans.getRotation();

					Transform t;
					t.Position = glm::vec3(p.getX(), p.getY(), p.getZ());
					t.Rotation = glm::quat(r.getW(), r.getX(), r.getY(), r.getZ());

					rb->Entity->Transform.Position = glm::vec3(t.ToMatrix() * glm::vec4(rb->GetOffset(), 1.0f));
					if (rb->Entity->GetComponent<Character>() == nullptr)
						rb->Entity->Transform.Rotation = t.Rotation;
				}
			}

			auto sb = fb.second->Entity->GetComponent<SoftBody>();
			if (sb != nullptr)
			{
				sb->RebuildMesh();
			}
		}

		softBodyWorldInfo.m_sparsesdf.GarbageCollect();
	}
Exemplo n.º 4
0
vector<Point2f> Recognition::findBoundingAndRebuild(Mat img, Mat Template, int& horizontalSize){
	vector<Point2f> mesh;
	Squares s(projectedSquareSize);
	vector<vector<Point> > squares;
	s.find_squares(img, squares);
	if(squares.size()> 0){
		vector<Point2f> refinedSquares= s.refineAndOrderSquares(squares, img );
		s.FilterOnRectified(refinedSquares, img);
		imshow("findBoundingAndRebuild",img);
		int biggestXSquareIndex, biggestYSquareIndex, smallestXSquareIndex, smallestYSquareIndex;
		Point2f biggestX(0,0);
		Point2f biggestY(0,0);
		Point2f smallestX(numeric_limits<float>::infinity(),numeric_limits<float>::infinity());
		Point2f smallestY(numeric_limits<float>::infinity(),numeric_limits<float>::infinity());

		for(unsigned int i=0; i< refinedSquares.size(); i++){
			if(refinedSquares[i].x> biggestX.x){
				biggestXSquareIndex= ((int)(i/4))*4;
				biggestX= refinedSquares[i];
			}
			if(refinedSquares[i].x< smallestX.x){
				smallestXSquareIndex= ((int)(i/4))*4;
				smallestX= refinedSquares[i];
			}
			if(refinedSquares[i].y> biggestY.y){
				biggestYSquareIndex= ((int)(i/4))*4;
				biggestY= refinedSquares[i];
			}
			if(refinedSquares[i].y< smallestY.y){
				smallestYSquareIndex= ((int)(i/4))*4;
				smallestY= refinedSquares[i];
			}
		}
		/*circle(img, biggestX, 1, Scalar(255,255,255), 5);
		circle(img, biggestY, 1, Scalar(255,255,255), 5);
		circle(img, smallestX, 1, Scalar(255,255,255), 5);
		circle(img, smallestY, 1, Scalar(255,255,255), 5);*/

		//template Matching
		int result_cols =  img.cols - Template.cols + 1;
		int result_rows = img.rows - Template.rows + 1;
		Mat result;

		result.create( result_cols, result_rows, CV_32FC1 );

		/// Do the Matching and Normalize
		matchTemplate( img, Template, result, CV_TM_CCOEFF_NORMED );
		normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );

		/// Localizing the best match with minMaxLoc
		double minVal; double maxVal; Point minLoc; Point maxLoc;
		Point templateUpperLeft, templateUpperRight, templateLowerLeft, templateLowerRight;

		minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );

		templateUpperLeft = maxLoc;			//matchLoc holds the upper left corner
		templateUpperRight= Point( templateUpperLeft.x + Template.cols , templateUpperLeft.y );
		templateLowerLeft= Point( templateUpperLeft.x , templateUpperLeft.y + Template.rows);
		templateLowerRight= Point( templateUpperLeft.x + Template.cols , templateUpperLeft.y + Template.rows);

		if((templateUpperLeft.x - smallestX.x) < 10 || (templateUpperLeft.y - smallestY.y) < 10 || (templateLowerRight.x - biggestX.x) < 10 || (templateLowerRight.y - biggestY.y) < 10)
			cout << "Square recovery and template match!!" << endl;
		else
			cout << "Square recovery and template matching do not match, rebuilding mesh with template match only!!" << endl;

		Mat templatePoint = img.clone();
		circle(templatePoint, templateUpperLeft, 1, Scalar(255,0,255), 4);
		circle(templatePoint, templateLowerRight, 1, Scalar(255,0,255), 4);
		imshow("templatePoint",templatePoint);

		mesh=  RebuildMesh(templateLowerRight, templateLowerRight, templateUpperLeft, templateUpperLeft, horizontalSize, img, refinedSquares);

	}

	return mesh;
}