Exemplo n.º 1
0
void ccHObject::drawNameIn3D(CC_DRAW_CONTEXT& context)
{
	if (!context.display)
		return;

	//we display it in the 2D layer in fact!
	ccBBox bBox = getOwnBB();
	if (!bBox.isValid())
		return;
	
	ccGLMatrix trans;
	getAbsoluteGLTransformation(trans);

	ccGLCameraParameters camera;
	context.display->getGLCameraParameters(camera);

	CCVector3 C = bBox.getCenter();
	CCVector3d Q2D;
	camera.project(C, Q2D);

	QFont font = context.display->getTextDisplayFont(); //takes rendering zoom into account!
	context.display->displayText(	getName(),
									static_cast<int>(Q2D.x),
									static_cast<int>(Q2D.y),
									ccGenericGLDisplay::ALIGN_HMIDDLE | ccGenericGLDisplay::ALIGN_VMIDDLE,
									0.75f,
									0,
									&font);
}
Exemplo n.º 2
0
ccBBox ccHObject::getDisplayBB_recursive(bool relative, const ccGenericGLDisplay* display/*=0*/)
{
	ccBBox box;

	if (!display || display == m_currentDisplay)
		box = getOwnBB(true);

	for (Container::iterator it = m_children.begin(); it != m_children.end(); ++it)
	{
		if ((*it)->isEnabled())
		{
			ccBBox childBox = (*it)->getDisplayBB_recursive(true, display);
			if ((*it)->isGLTransEnabled())
			{
				childBox = childBox * (*it)->getGLTransformation();
			}
			box += childBox;
		}
	}

	if (!relative && box.isValid())
	{
		//get absolute bounding-box?
		ccGLMatrix trans;
		getAbsoluteGLTransformation(trans);
		box = box * trans;
	}

	return box;
}
Exemplo n.º 3
0
//====================================================drawNameIn3D======================================//
void ccHObject::drawNameIn3D(CC_DRAW_CONTEXT& context)
{
	//绘制窗口
	if (!context._win)return;

	//we display it in the 2D layer in fact!
	ccBBox bBox = getOwnBB();
	if (bBox.isValid()){

		ccGLMatrix trans;
		getAbsoluteGLTransformation(trans); //得到由祖先到当前物体的变换矩阵

		const double* MM = context._win->getModelViewMatd(); //viewMat   //模型视图矩阵
		const double* MP = context._win->getProjectionMatd(); //projMat  //投影矩阵
		int VP[4];
		context._win->getViewportArray(VP); //视口参数

		GLdouble xp,yp,zp;
		CCVector3 C = bBox.getCenter(); //BB的中心为之
		trans.apply(C); //实际的位置和显示的位置不同,将变换矩阵作用到中心位置上
		gluProject(C.x,C.y,C.z,MM,MP,VP,&xp,&yp,&zp); //根据视图矩阵,投影矩阵和视口参数对BB中心点进行投影

		QFont font = context._win->getTextDisplayFont(); //takes rendering zoom into account! //获取字体

		//在2D屏幕上显示文本
		context._win->displayText(	getName(),
									static_cast<int>(xp),
									static_cast<int>(yp),
									ccGenericGLDisplay::ALIGN_HMIDDLE | ccGenericGLDisplay::ALIGN_VMIDDLE,
									0.75f,
									0,
									&font);
	}
}
Exemplo n.º 4
0
bool ccGenericPointCloud::isClicked(const CCVector2d& clickPos,
									int& nearestPointIndex,
									double& nearestSquareDist,
									const double* MM,
									const double* MP,
									const int* VP,
									double pickWidth/*=2.0*/,
									double pickHeight/*=2.0*/)
{
	ccGLMatrix trans;
	bool noGLTrans = !getAbsoluteGLTransformation(trans);

	//back project the clicked point in 3D
	CCVector3d clickPosd(clickPos.x, clickPos.y, 0);
	CCVector3d X(0,0,0);
	ccGL::Unproject<double, double>(clickPosd, MM, MP, VP, X);

	nearestPointIndex = -1;
	nearestSquareDist = -1.0;

#if defined(_OPENMP)
#pragma omp parallel for
#endif
	//brute force works quite well in fact?!
	for (unsigned i=0; i<size(); ++i)
	{
		const CCVector3* P = getPoint(i);
		CCVector3d Qs;
		if (noGLTrans)
		{
			ccGL::Project<PointCoordinateType, double>(*P,MM,MP,VP,Qs);
		}
		else
		{
			CCVector3 Q = *P;
			trans.apply(Q);
			ccGL::Project<PointCoordinateType, double>(Q,MM,MP,VP,Qs);
		}

		if (fabs(Qs.x-clickPos.x) <= pickWidth && fabs(Qs.y-clickPos.y) <= pickHeight)
		{
			double squareDist = CCVector3d(X.x-P->x, X.y-P->y, X.z-P->z).norm2d();
			if (nearestPointIndex < 0 || squareDist < nearestSquareDist)
			{
				nearestSquareDist = squareDist;
				nearestPointIndex = static_cast<int>(i);
			}
		}
	}

	return (nearestPointIndex >= 0);
}