Exemplo n.º 1
0
void hull3d() {
	for (int i = 2; i <= n; ++i) {
		if (dblcmp((pt[i] - pt[1]).length()) > 0) swap(pt[i], pt[2]);
	}
	for (int i = 3; i <= n; ++i) {
		if (dblcmp(fabs(area(pt[1], pt[2], pt[i]))) > 0) swap(pt[i], pt[3]);
	}
	for (int i = 4; i <= n; ++i) {
		if (dblcmp(fabs(volume(pt[1], pt[2], pt[3], pt[i]))) > 0) swap(pt[i], pt[4]);
	}
	zm(fc), fcnt = 0, zm(bf);
	for (int i = 1; i <= 4; ++i) {
		face_t f;
		f.a = i + 1, f.b = i + 2, f.c = i + 3;
		if (f.a > 4) f.a -= 4;
		if (f.b > 4) f.b -= 4;
		if (f.c > 4) f.c -= 4;
		if (dblcmp(volume(pt[i], pt[f.a], pt[f.b], pt[f.c])) > 0) swap(f.a, f.b);
		f.vis = true;
		bf[f.a][f.b] = bf[f.b][f.c] = bf[f.c][f.a] = ++fcnt;
		fc[fcnt] = f;
	}
	random_shuffle(pt + 5, pt + 1 + n);
	for (int i = 5; i <= n; ++i) {
		for (int j = 1; j <= fcnt; ++j) {
			if (!fc[j].vis) continue;
			if (dblcmp(volume(pt[i], pt[fc[j].a], pt[fc[j].b], pt[fc[j].c])) >= 0) {
				dfs(i, j);
				break;
			}
		}
	}
	for (int i = 1; i <= fcnt; ++i) if (!fc[i].vis) swap(fc[i--], fc[fcnt--]);
}
Exemplo n.º 2
0
void BezierWidget::computeMatrices()
{
    QMatrix4x4 xm(cp[0].x(), cp[1].x(), cp[2].x(), cp[3].x(),
                  cp[4].x(), cp[5].x(), cp[6].x(), cp[7].x(),
                  cp[8].x(), cp[9].x(), cp[10].x(), cp[11].x(),
                  cp[12].x(), cp[13].x(), cp[14].x(), cp[15].x());
    QMatrix4x4 ym(cp[0].y(), cp[1].y(), cp[2].y(), cp[3].y(),
                  cp[4].y(), cp[5].y(), cp[6].y(), cp[7].y(),
                  cp[8].y(), cp[9].y(), cp[10].y(), cp[11].y(),
                  cp[12].y(), cp[13].y(), cp[14].y(), cp[15].y());
    QMatrix4x4 zm(cp[0].z(), cp[1].z(), cp[2].z(), cp[3].z(),
                  cp[4].z(), cp[5].z(), cp[6].z(), cp[7].z(),
                  cp[8].z(), cp[9].z(), cp[10].z(), cp[11].z(),
                  cp[12].z(), cp[13].z(), cp[14].z(), cp[15].z());

    matrixX = matrixM * xm * matrixM;
    matrixY = matrixM * ym * matrixM;
    matrixZ = matrixM * zm * matrixM;
}
Exemplo n.º 3
0
void MG_poseReader::draw( M3dView & view, const MDagPath & path, 
							 M3dView::DisplayStyle dispStyle,
							 M3dView::DisplayStatus status )
{ 
   
	
	MPlug sizeP (thisMObject(),size);
	double sizeV;
	sizeP.getValue(sizeV);

	MPlug poseMatrixP (thisMObject(),poseMatrix);
	MObject poseMatrixData;
	poseMatrixP.getValue(poseMatrixData);
	MFnMatrixData matrixFn(poseMatrixData);
	MMatrix poseMatrixV =matrixFn.matrix();

	MPlug readerMatrixP (thisMObject(),readerMatrix);
	MObject readerMatrixData;
	readerMatrixP.getValue(readerMatrixData);

	matrixFn.setObject(readerMatrixData);
	MMatrix readerMatrixV =matrixFn.matrix();

	MMatrix poseMatrixFix =poseMatrixV*readerMatrixV.inverse();

	MPlug aimAxisP  (thisMObject(),aimAxis);
	int aimAxisV;
	aimAxisP.getValue(aimAxisV);
	MVector aimBall;

	  
	MPlug readerOnOffP(thisMObject(),readerOnOff);
	MPlug axisOnOffP(thisMObject(),axisOnOff);
	MPlug poseOnOffP(thisMObject(),poseOnOff);

	double readerOnOffV;
	double axisOnOffV;
	double poseOnOffV;

	readerOnOffP.getValue(readerOnOffV);
	axisOnOffP.getValue(axisOnOffV);
	poseOnOffP.getValue(poseOnOffV);

	MPlug xPositiveP  (thisMObject(),xPositive);
	MPlug xNegativeP  (thisMObject(),xNegative);

	double xPositiveV;
	double xNegativeV;

	xPositiveP.getValue(xPositiveV);
	xNegativeP.getValue(xNegativeV);

	double xColor = xPositiveV;
	if (xPositiveV==0)
	{
		xColor=xNegativeV;

	}
	


	MPlug yPositiveP  (thisMObject(),yPositive);
	MPlug yNegativeP  (thisMObject(),yNegative);

	double yPositiveV;
	double yNegativeV;

	yPositiveP.getValue(yPositiveV);
	yNegativeP.getValue(yNegativeV);

	double yColor = yPositiveV;
	if (yPositiveV==0)
	{
		yColor=yNegativeV;

	}

	MPlug zPositiveP  (thisMObject(),zPositive);
	MPlug zNegativeP  (thisMObject(),zNegative);

	double zPositiveV;
	double zNegativeV;

	zPositiveP.getValue(zPositiveV);
	zNegativeP.getValue(zNegativeV);

	double zColor = zPositiveV;
	if (zPositiveV==0)
	{
		zColor=zNegativeV;

	}



		if (aimAxisV==0)
		{
			
			aimBall.x=poseMatrixFix[0][0];
			aimBall.y=poseMatrixFix[0][1];
			aimBall.z=poseMatrixFix[0][2];
		}
		else if (aimAxisV==1)
		{
			
			aimBall.x=poseMatrixFix[1][0];
			aimBall.y=poseMatrixFix[1][1];
			aimBall.z=poseMatrixFix[1][2];

		}else
		{
			
			aimBall.x=poseMatrixFix[2][0];
			aimBall.y=poseMatrixFix[2][1];
			aimBall.z=poseMatrixFix[2][2];
		}
	
      
	//*****************************************************************
	// Initialize opengl and draw
	//*****************************************************************
	view.beginGL();
	glPushAttrib( GL_ALL_ATTRIB_BITS );
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glLineWidth(2);
	if(status == M3dView::kLead)
		glColor4f(0.0,1.0,0.0,0.3f);
	else
		glColor4f(1.0,1.0,0.0,0.3f);





	MVector baseV(0,0,0);
	MVector xp(1*sizeV,0,0);
	MVector xm(-1*sizeV,0,0);
	MVector yp(0,1*sizeV,0);
	MVector ym(0,-1*sizeV,0);
	MVector zp(0,0,1*sizeV);
	MVector zm(0,0,-1*sizeV);



	double * red;
	red = new double[4];
	red[0]=1;
	red[1]=0;
	red[2]=0;
	red[3]=1;

	double * green;
	green = new double[4];
	green[0]=0;
	green[1]=1;
	green[2]=0;
	green[3]=1;

	double * blue;
	blue = new double[4];
	blue[0]=0;
	blue[1]=0;
	blue[2]=1;
	blue[3]=1;

	double * yellow;
	yellow = new double[4];
	yellow[0]=1;
	yellow[1]=1;
	yellow[2]=0.2;
	yellow[3]=0.3;



	if (readerOnOffV==1)
	{
	drawSphere(sizeV,20,20,baseV,yellow);
	}
	
	
	if  (axisOnOffV==1)
	{
	drawSphere(sizeV/7,15,15,xp,red);
	drawSphere(sizeV/7,15,15,xm,red); 
	drawSphere(sizeV/7,15,15,yp,green);
	drawSphere(sizeV/7,15,15,ym,green);
	drawSphere(sizeV/7,15,15,zp,blue);
	drawSphere(sizeV/7,15,15,zm,blue);
	}
	if (poseOnOffV==1)
	{
	  

	
	double* color = blendColor(xColor,yColor,zColor,1);

	drawSphere(sizeV/7,15,15,aimBall*sizeV,color);
	}

	glDisable(GL_BLEND);
	glPopAttrib();



}