Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: HLH15/24783
void FsLazyWindowApplication::CacheBoundingBox(void)
{
	auto nVtx=vtx.size()/3;
	// Cache bounding box
	if(0<nVtx)
	{
		float minx,miny,minz,maxx,maxy,maxz;
		minx=vtx[0];
		miny=vtx[1];
		minz=vtx[2];
		maxx=vtx[0];
		maxy=vtx[1];
		maxz=vtx[2];
		for(decltype(nVtx) i=0; i<nVtx; ++i)
		{
			YsMakeSmaller(minx,vtx[i*3]);
			YsMakeSmaller(miny,vtx[i*3+1]);
			YsMakeSmaller(minz,vtx[i*3+2]);
			YsMakeGreater(maxx,vtx[i*3]);
			YsMakeGreater(maxy,vtx[i*3+1]);
			YsMakeGreater(maxz,vtx[i*3+2]);
		}
		min.Set(minx,miny,minz);
		max.Set(maxx,maxy,maxz);
	}
	else
	{
		min=YsVec3::Origin();
		max=YsVec3::Origin();
	}
}
Ejemplo n.º 2
0
void YsClassSample::Motion(int x,int y)
{
	double dx,dy;
	YsVec3 vec;

	dx=double(x-lastX);
	dy=double(lastY-y);
	switch(mouseMode)
	{
	case 0:
		eyeAtt.NoseUp(dy/300.0);
		eyeAtt.YawLeft(-dx/300.0);
		break;
	case 1:
		vec.Set(-dx/30.0,-dy/30.0,0.0);
		vec=eyeAtt.GetMatrix()*vec;
		eyeLookAt=eyeLookAt+vec;
		break;
	case 2:
		RotatePolygon(p,dy/300.0,-dx/300.0);
		break;
	case 3:
		RotatePolygon(q,dy/300.0,-dx/300.0);
		break;
	case 4:
		RotatePolygon(r,dy/300.0,-dx/300.0);
		break;
	}
	lastX=x;
	lastY=y;
}
Ejemplo n.º 3
0
void YsClassSample::DrawNearestPointInsideOrOutside(void)
{
	YsPlane pln;
	YsVec3 nearestPoint;
	YSSIDE sd;
	BIPOINT cursor;

	pln.MakeBestFitPlane(4,p);
	pln.GetNearestPoint(nearestPoint,pointOfInterest);

	sd=YsCheckInsidePolygon3(nearestPoint,4,p);
	BiSetPoint(&cursor,nearestPoint.x(),nearestPoint.y(),nearestPoint.z());
	switch(sd)
	{
	case YSINSIDE:
		BiInsMarker(&cursor,&BiGreen,BIMK_CROSS);
		break;
	case YSOUTSIDE:
		BiInsMarker(&cursor,&BiBlue,BIMK_CROSS);
		break;
	case YSBOUNDARY:
		BiInsMarker(&cursor,&BiYellow,BIMK_CROSS);
		break;
	case YSUNKNOWNSIDE:
		BiInsMarker(&cursor,&BiRed,BIMK_CROSS);
		break;
	}
}
Ejemplo n.º 4
0
void Display(void)
{
	double matBuf[4*4];
	YsVec3 eyePos;
	YsMatrix4x4 eyeTfm;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	eyePos.Set(0.0,0.0,eyeDistance);
	eyePos=eyeAtt.GetMatrix()*eyePos;

	eyeTfm.Initialize();
	eyeTfm.Translate(eyePos);
	eyeTfm.Rotate(eyeAtt);
	eyeTfm.Invert();
	eyeTfm.Translate(-eyeLookAt);

	eyeTfm.GetArray(matBuf);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMultMatrixd(matBuf);
	DrawSeparatablePair(nVtx,vtx);

	glFlush();
	glutSwapBuffers();
}
Ejemplo n.º 5
0
void Display(void)
{
	double matBuf[4*4];
	YsVec3 eyePos;
	YsMatrix4x4 eyeTfm;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	eyePos.Set(0.0,0.0,eyeDistance);
	eyePos=eyeAtt.GetMatrix()*eyePos;

	eyeTfm.Initialize();
	eyeTfm.Translate(eyePos);
	eyeTfm.Rotate(eyeAtt);
	eyeTfm.Invert();
	eyeTfm.Translate(-eyeLookAt);

	eyeTfm.GetArray(matBuf);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMultMatrixd(matBuf);
	DrawShell(sh1,blu,drawInPolygon);
	DrawShell(sh2,grn,drawInPolygon);
	DrawAxis(5.0);
	glFlush();
	glutSwapBuffers();
}
Ejemplo n.º 6
0
static YSRESULT YsClipInfiniteLine3_FindFirstIntersection
    (YsVec3 &itsc,const YsVec3 &org,const YsVec3 &vec,const YsVec3 range[2])
{
	int i,j,k;

	for(i=0; i<3; i++)
	{
		for(j=0; j<2; j++)
		{
			if(YsClip3DLine(itsc,org,vec,range[j].GetValue()[i],i)==YSOK)
			{
				for(k=0; k<3; k++)
				{
					if(i!=k &&
					   (itsc.GetValue()[k]<range[0].GetValue()[k]-YsTolerance ||
					    range[1].GetValue()[k]+YsTolerance<itsc.GetValue()[k]))
					{
						goto NEXTPLANE;
					}
				}
				return YSOK;
			}
		NEXTPLANE:
			;
		}
	}
	return YSERR;
}
Ejemplo n.º 7
0
void Motion(int x,int y)
{
	if(button==GLUT_DOWN)
	{
		double dx,dy;
		YsVec3 vec;

		dx=double(x-lastX);
		dy=double(lastY-y);
		switch(mouseMode)
		{
		case 0:
			eyeAtt.NoseUp(dy/300.0);
			eyeAtt.YawLeft(-dx/300.0);
			break;
		case 1:
			vec.Set(-dx/30.0,-dy/30.0,0.0);
			vec=eyeAtt.GetMatrix()*vec;
			eyeLookAt=eyeLookAt+vec;
			break;
		}
		glutPostRedisplay();
	}
	lastX=x;
	lastY=y;
}
Ejemplo n.º 8
0
void Cylinder::collide(Particle &particle)const
{
    YsVec3 r=particle.getPosition();
    YsVec3 v=particle.getVelocity();
    YsVec3 n;
    //particle penetrates neither bottom nor radius
    if (bottom_fun(r)<0 && side_fun(r)<0) {
        return;
    }
    if (bottom_fun(r)>0) {
        n=YsYVec();
        if (n*v<0) {
            v=v-2*(v*n)*n; //bounce velocity
            particle.setVelocity(v);
        }
    }
    if (side_fun(r)>0) {
        n=origin-r;
        n.SetY(0.0);
        n.Normalize();
        if (n*v<0) {
            v=v-2*(v*n)*n; //bounce velocity
            particle.setVelocity(v);
        }
    }
}
Ejemplo n.º 9
0
YSBOOL YsBoundingBoxMaker3::IsInsideXY(const YsVec3 &pos) const
{
	if(min.x()-YsTolerance<=pos.x() && pos.x()<=max.x()+YsTolerance &&
	   min.y()-YsTolerance<=pos.y() && pos.y()<=max.y()+YsTolerance)
	{
		return YSTRUE;
	}
	return YSFALSE;
}
Ejemplo n.º 10
0
YSRESULT YsZClip(YsVec3 &clipPos,const YsVec3 &p1,const YsVec3 &p2,const double &clipz)
{
	const double denom=(p2.z()-p1.z());
	if(YsTolerance<=fabs(denom))
	{
		const YsVec3 v=p2-p1;
		const double t=(clipz-p1.z())/denom;
		clipPos.Set(p1[0]+t*v[0],p1[1]+t*v[1],clipz);
		return YSOK;
	}
	return YSERR;
}
Ejemplo n.º 11
0
YSRESULT YsClipLineWithNearZ(
	YsVec3 &newP1,YsVec3 &newP2,const YsVec3 &p1,const YsVec3 &p2,const double &nearz,YSBOOL positivez)
{
	class TestIsFrontSide
	{
	public:
		inline YSBOOL IsFrontSide(const double tstz,const double nearz,YSBOOL positivez)
		{
			if(YSTRUE==positivez && nearz<=tstz)
			{
				return YSTRUE;
			}
			else if(YSTRUE!=positivez && tstz<=nearz)
			{
				return YSTRUE;
			}
			return YSFALSE;
		}
	};

	TestIsFrontSide tester;

	if(YSTRUE==tester.IsFrontSide(p1.z(),nearz,positivez) &&
	   YSTRUE==tester.IsFrontSide(p2.z(),nearz,positivez))
	{
		newP1=p1;
		newP2=p2;
		return YSOK;
	}
	else if(YSTRUE==tester.IsFrontSide(p1.z(),nearz,positivez) ||
	        YSTRUE==tester.IsFrontSide(p2.z(),nearz,positivez))
	{
		YsVec3 clipPos;
		if(YSOK==YsZClip(clipPos,p1,p2,nearz))
		{
			if(YSTRUE==tester.IsFrontSide(p2.z(),nearz,positivez))
			{
				newP1=clipPos;
				newP2=p2;
				return YSOK;
			}
			else
			{
				newP1=p1;
				newP2=clipPos;
				return YSOK;
			}
		}
	}
	return YSERR;
}
Ejemplo n.º 12
0
void YsTransform3DCoordToScreenCoord(YsVec3 &scrn,const YsVec3 &from,const int viewport[4],const YsMatrix4x4 &projViewModelTfm)
{
	double pos4d[4]={from.x(),from.y(),from.z(),1.0};
	projViewModelTfm.Mul(pos4d,pos4d);

	pos4d[0]/=pos4d[3];
	pos4d[1]/=pos4d[3];
	pos4d[2]/=pos4d[3];

	pos4d[0]=(double)viewport[0]+(double)viewport[2]*(pos4d[0]+1.0)/2.0;
	pos4d[1]=(double)viewport[1]+(double)viewport[3]*(pos4d[1]+1.0)/2.0;

	scrn.Set(pos4d[0],pos4d[1],pos4d[2]);
}
YSRESULT YsShell::SaveMs3(int &nIgnored,const char fn[]) const
{
	FILE *fp;
	YsShellVertexHandle vtHd;
	YsShellPolygonHandle plHd;

	Encache();
	nIgnored=0;

	fp=fopen(fn,"w");
	if(fp!=NULL)
	{
		vtHd=NULL;
		while((vtHd=FindNextVertex(vtHd))!=NULL)
		{
			YsVec3 pos;
			GetVertexPosition(pos,vtHd);
			fprintf(fp,"V %lf %lf %lf\n",pos.x(),pos.y(),pos.z());
		}

		plHd=NULL;
		while((plHd=FindNextPolygon(plHd))!=NULL)
		{
			int n;
			const YsShellVertexHandle *plVtHd;
			n=GetNumVertexOfPolygon(plHd);
			plVtHd=GetVertexListOfPolygon(plHd);

			if(n==3)
			{
				fprintf(fp,"D %d %d %d\n",   // D of Delta
				    GetVertexIdFromHandle(plVtHd[0]),
				    GetVertexIdFromHandle(plVtHd[1]),
				    GetVertexIdFromHandle(plVtHd[2]));
			}
			else if(n==4)
			{
				fprintf(fp,"Q %d %d %d %d\n",
				    GetVertexIdFromHandle(plVtHd[0]),
				    GetVertexIdFromHandle(plVtHd[1]),
				    GetVertexIdFromHandle(plVtHd[2]),
				    GetVertexIdFromHandle(plVtHd[3]));
			}
		}

		fclose(fp);
		return YSOK;
	}
	return YSERR;
}
Ejemplo n.º 14
0
void YsTransformScreenCoordTo3DCoord(YsVec3 &threeD,const YsVec3 &scrn,const int viewport[4],const YsMatrix4x4 &projViewModelTfm)
{
	double pos4d[4]=
	{
		(scrn.x()-(double)viewport[0])*2.0/(double)viewport[2]-1.0,
		(scrn.y()-(double)viewport[1])*2.0/(double)viewport[3]-1.0,
		scrn.z(),
		1.0
	};

	projViewModelTfm.MulInverse(pos4d,pos4d);

	pos4d[0]/=pos4d[3];
	pos4d[1]/=pos4d[3];
	pos4d[2]/=pos4d[3];
	threeD.Set(pos4d[0],pos4d[1],pos4d[2]);
}
Ejemplo n.º 15
0
const YsVec3 YsTraceLineSegment::GetCurrentTangent(void) const
{
	YsVec3 t;
	if(curPos.seg<lSeg.GetN()-1)
	{
		t=lSeg[curPos.seg+1]-lSeg[curPos.seg];
		t.Normalize();
		return t;
	}
	else if(2<=lSeg.GetN())
	{
		t=lSeg[lSeg.GetN()-1]-lSeg[lSeg.GetN()-2];
		t.Normalize();
		return t;
	}
	return YsOrigin();
}
Ejemplo n.º 16
0
void YsClassSample::Display(void)
{
	BIPOSATT biEyePos;
	BIPOINT cursor;

	eyePos.Set(0.0,0.0,-eyeDistance);
	eyePos=eyeAtt.GetMatrix()*eyePos;
	eyePos=eyeLookAt+eyePos;

	BiSetPoint(&biEyePos.p,eyePos.x(),eyePos.y(),eyePos.z());
	BiSetAngleDeg(&biEyePos.a,
	              YsRadToDeg(eyeAtt.h()),
	              YsRadToDeg(eyeAtt.p()),
	              YsRadToDeg(eyeAtt.b()));

	BiClearScreen();
	BiStartBuffer(&biEyePos);

	BiSetPoint(&cursor,
	           pointOfInterest.x(),
	           pointOfInterest.y(),
	           pointOfInterest.z());
	BiInsMarker(&cursor,&BiWhite,BIMK_CROSS);
	DrawSlashedPolygon();
	DrawPolygon(4,q,blu,YSFALSE);
	DrawPolygon(4,r,blu,YSFALSE);
	DrawAxis(5.0);

	BiFlushBuffer();
	BiSwapBuffers();
}
Ejemplo n.º 17
0
void YsCollisionOfPolygon::SetPolygon2(YSSIZE_T nv2,const YsVec3 v2[],const YsVec3 &nom2)
{
	if(nv2>0)
	{
		np2=nv2;
		p2=v2;

		YsBoundingBoxMaker3 bbx;
		bbx.Make(nv2,v2);
		bbx.Get(p2min,p2max);

		YsVec3 nom;
		nom=nom2;
		if(nom.IsNormalized()!=YSTRUE)
		{
			nom.Normalize();
		}
		pln2.Set(v2[0],nom);
	}
}
Ejemplo n.º 18
0
static YSRESULT YsClipInfiniteLine3_FindSecondIntersection
    (YsVec3 &itsc,const YsVec3 &first,const YsVec3 &vec,const YsVec3 range[2])
{
	int i,j,k;
	double dist,d;
	YSRESULT found;
	YsVec3 candidate;

	found=YSERR;
	dist=-1.0;
	candidate.Set(0.0,0.0,0.0);
	for(i=0; i<3; i++)
	{
		for(j=0; j<2; j++)
		{
			if(YsClip3DLine(candidate,first,vec,range[j].GetValue()[i],i)==YSOK)
			{
				for(k=0; k<3; k++)
				{
					if(i!=k &&
					   (candidate.GetValue()[k]<range[0].GetValue()[k]-YsTolerance ||
					    range[1].GetValue()[k]+YsTolerance<candidate.GetValue()[k]))
					{
						goto NEXTPLANE;
					}
				}
				found=YSOK;
				d=(first-candidate).GetSquareLength();
				if(d>dist)
				{
					itsc=candidate;
					dist=d;
				}
			}
		NEXTPLANE:
			;
		}
	}
	return found;
}
Ejemplo n.º 19
0
void ParticleGroup::MakeCloud(int nParticle,const YsVec3 &min,const YsVec3 &max)
{
	particle.resize(nParticle);
	for(auto &p : particle)
	{
		double s=(double)rand()/(double)RAND_MAX;
		double t=(double)rand()/(double)RAND_MAX;
		double u=(double)rand()/(double)RAND_MAX;

		double x=min.x()*(1.0-s)+max.x()*s;
		double y=min.y()*(1.0-t)+max.y()*t;
		double z=min.z()*(1.0-u)+max.z()*u;

		p.pos.Set(x,y,z);

		p.t=0.0;
		p.tRemain=1.0;

		// Assume 4x4 texture atlas
		s=0.25*(double)(rand()%4);
		t=0.75;
		p.texCoordRange[0]=(float)s;
		p.texCoordRange[1]=(float)t;
		p.texCoordRange[2]=(float)s+0.25;
		p.texCoordRange[3]=(float)t+0.25;
	}
}
Ejemplo n.º 20
0
void YsClassSample::MainLoop(void)
{
	int lb,mb,rb;
	long mx,my;

	eyeDistance=10.0;
	eyeLookAt.Set(0.0,0.0,0.0);
	eyeAtt.Set(0.0,0.0,0.0);

	pointOfInterest.Set(0.0,0.0,-1.0);
	PrepareSquare(p);
	PrepareSquare(q);
	RotatePolygon(q,YsDegToRad(90.0),0.0);
	PrepareSquare(r);
	RotatePolygon(r,0.0,YsDegToRad(90.0));

	BiMouse(&lb,&mb,&rb,&mx,&my);

	mouseMode=0;
	while((key=BiInkey())!=BIKEY_ESC)
	{
		BIPROJ prj;

		BiUpdateDevice();
		BiGetStdProjection(&prj);
		BiSetProjection(&prj);

		Key(key);
		Display();

		lastX=mx;
		lastY=my;
		BiMouse(&lb,&mb,&rb,&mx,&my);
		if(lb==BI_ON && (mx!=lastX || my!=lastY))
		{
			Motion(mx,my);
		}
	}

}
Ejemplo n.º 21
0
void YsCollisionOfPolygon::SetPolygon1(YSSIZE_T nv1,const YsVec3 v1[],const YsVec3 &nom1)
{
	if(nv1>0)
	{
		np1=nv1;
		p1=v1;

		YsBoundingBoxMaker3 bbx;
		bbx.Make(nv1,v1);
		bbx.Get(p1min,p1max);

		YsVec3 nom;
		nom=nom1;
		if(nom.IsNormalized()!=YSTRUE)
		{
			nom.Normalize();
		}
		pln1.Set(v1[0],nom);

		p1Prj.Set(0,NULL);
	}
}
Ejemplo n.º 22
0
int main(int argc, char** argv)
{
	InitYsClass();

	axisOfOrbit.Set(1.0,1.0,1.0);
	axisOfOrbit.Normalize();

	orbiter=axisOfOrbit.GetArbitraryParpendicularVector();
	orbiter.Normalize();

	rot.Set(axisOfOrbit,0.0);


	printf("Keys\n");
	printf("A....Viewing Rotation Mode\n");
	printf("B....Viewing Translation (Scroll) Mode\n");
	printf("Z....Zoom\n");
	printf("M....Mooz\n");
	printf("----------\n");

	eyeAtt.Set(YsPi/2.0,0.0,0.0);
	eyeDistance=10.0;

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow(argv[0]);
	InitOpenGL();
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(Keyboard);
	glutMouseFunc(Mouse);
	glutMotionFunc(Motion);
	glutIdleFunc(Idle);
	glutMainLoop();
	return 0;
}
Ejemplo n.º 23
0
void Display(void)
{
	double matBuf[4*4];
	YsVec3 eyePos;
	YsMatrix4x4 eyeTfm;
	YsVec3 p;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	eyePos.Set(0.0,0.0,eyeDistance);
	eyePos=eyeAtt.GetMatrix()*eyePos;

	eyeTfm.Initialize();
	eyeTfm.Translate(eyePos);
	eyeTfm.Rotate(eyeAtt);
	eyeTfm.Invert();
	eyeTfm.Translate(-eyeLookAt);

	eyeTfm.GetArray(matBuf);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMultMatrixd(matBuf);
	DrawAxis(5.0);

	glDisable(GL_LIGHTING);
	glColor3d(1.0,1.0,1.0);
	glBegin(GL_LINES);
	glVertex3d(0.0,0.0,0.0);
	glVertex3d(axisOfOrbit.x()*5.0,axisOfOrbit.y()*5.0,axisOfOrbit.z()*5.0);
	glEnd();

	rot.RotatePositive(p,orbiter);
	glPushMatrix();
	glTranslatef(p.x()*5.0,p.y()*5.0,p.z()*5.0);
	DrawCursor();
	glPopMatrix();

	glFlush();
	glutSwapBuffers();
}
Ejemplo n.º 24
0
void Ys3DDrawingEnvironment::TransformScreenCoordTo3DLine(YsVec3 &org,YsVec3 &vec,double sx,double sy) const
{
	if(YSTRUE==screenOriginIsTopLeft)
	{
		sy=(double)windowHeight-sy;
	}

	const YsMatrix4x4 &viewMat=GetViewMatrix();
	const YsMatrix4x4 &projMat=GetProjectionMatrix();
	const YsMatrix4x4 projViewMat=projMat*viewMat;

	const YsVec3 p1(sx,sy,-1.0),p2(sx,sy,1.0);
	YsTransformScreenCoordTo3DCoord(org,p1,viewport,projViewMat);
	YsTransformScreenCoordTo3DCoord(vec,p2,viewport,projViewMat);

	vec-=org;
	vec.Normalize();
}
Ejemplo n.º 25
0
void YsBoundingBoxMaker3::Add(const YsVec3 &vec)
{
	if(first!=YSTRUE)
	{
		min.Set
		   (YsSmaller(min.x(),vec.x()),
		    YsSmaller(min.y(),vec.y()),
		    YsSmaller(min.z(),vec.z()));
		max.Set
		   (YsGreater(max.x(),vec.x()),
		    YsGreater(max.y(),vec.y()),
		    YsGreater(max.z(),vec.z()));
	}
	else
	{
		Begin(vec);
	}
}
void FsGui3DInterface::DrawRectMarker(const YsVec3 &o,const double lng) const
{
	YsVec3 scrnO;
	YsTransform3DCoordToScreenCoord(scrnO,o,viewport,projViewModelTfm);

	YsVec3 quad[4]=
	{
		YsVec3(scrnO.x()-markerSize,scrnO.y()-markerSize,scrnO.z()),
		YsVec3(scrnO.x()+markerSize,scrnO.y()-markerSize,scrnO.z()),
		YsVec3(scrnO.x()+markerSize,scrnO.y()+markerSize,scrnO.z()),
		YsVec3(scrnO.x()-markerSize,scrnO.y()+markerSize,scrnO.z())
	};
	YsTransformScreenCoordTo3DCoord(quad[0],quad[0],viewport,projViewModelTfm);
	YsTransformScreenCoordTo3DCoord(quad[1],quad[1],viewport,projViewModelTfm);
	YsTransformScreenCoordTo3DCoord(quad[2],quad[2],viewport,projViewModelTfm);
	YsTransformScreenCoordTo3DCoord(quad[3],quad[3],viewport,projViewModelTfm);

	glBegin(GL_LINE_LOOP);
	glVertex3dv(quad[0]);
	glVertex3dv(quad[1]);
	glVertex3dv(quad[2]);
	glVertex3dv(quad[3]);
	glEnd();
}
Ejemplo n.º 27
0
static YSRESULT YsClip3DLine
    (YsVec3 &clip,const YsVec3 &org,const YsVec3 &vec,const double &clipPoint,int component)
{
	int c1,c2;
	double buf[3],slope[3];

	if(component==0)
	{
		c1=1;
		c2=2;
	}
	else if(component==1)
	{
		c1=0;
		c2=2;
	}
	else
	{
		c1=0;
		c2=1;
	}

	if(YsAbs(vec.GetValue()[component])>=YsTolerance)
	{
		slope[c1]=vec.GetValue()[c1]/vec.GetValue()[component];
		slope[c2]=vec.GetValue()[c2]/vec.GetValue()[component];

		buf[component]=clipPoint;
		buf[c1]=org.GetValue()[c1]+slope[c1]*(clipPoint-org.GetValue()[component]);
		buf[c2]=org.GetValue()[c2]+slope[c2]*(clipPoint-org.GetValue()[component]);

		clip.Set(buf[0],buf[1],buf[2]);

		return YSOK;
	}
	else
	{
		return YSERR;
	}
}
Ejemplo n.º 28
0
YSRESULT YsClipLineSeg3
   (YsVec3 &newP1,YsVec3 &newP2,const YsVec3 &p1,const YsVec3 &p2,const YsVec3 &range1,const YsVec3 &range2)
{
	int j,nInComp;
	YsVec3 min,max;
	YsBoundingBoxMaker3 bbx;
	bbx.Begin(range1);
	bbx.Add(range2);
	bbx.Get(min,max);

	nInComp=0;
	for(j=0; j<3; j++)
	{
		if(min.GetValue()[j]<=p1.GetValue()[j] && p1.GetValue()[j]<=max.GetValue()[j] &&
		   min.GetValue()[j]<=p2.GetValue()[j] && p2.GetValue()[j]<=max.GetValue()[j])
		{
			nInComp++;
		}

		if(p1.GetValue()[j]<min.GetValue()[j] &&
		   p2.GetValue()[j]<min.GetValue()[j])
		{
			return YSERR;
		}
		if(p1.GetValue()[j]>max.GetValue()[j] &&
		   p2.GetValue()[j]>max.GetValue()[j])
		{
			return YSERR;
		}
	}

	if(nInComp==3)
	{
		newP1=p1;
		newP2=p2;
		return YSOK;
	}

	YsVec3 c1,c2;
	if(YsClipInfiniteLine3(c1,c2,p1,p2-p1,min,max)==YSOK)
	{
		if(YsCheckInBetween3(c1,p1,p2)==YSTRUE &&
		   YsCheckInBetween3(c2,p1,p2)==YSTRUE)
		{
			newP1=c1;
			newP2=c2;
			return YSOK;
		}
		else if(YsCheckInBetween3(c1,p1,p2)==YSTRUE)
		{
			// p1-c1 or c1-p2
			if(YsCheckInBetween3(p1,c1,c2)==YSTRUE)
			{
				newP1=p1;
				newP2=c1;
			}
			else
			{
				newP1=c1;
				newP2=p2;
			}
			return YSOK;
		}
		else if(YsCheckInBetween3(c2,p1,p2)==YSTRUE)
		{
			// p1-c2 or c2-p2
			if(YsCheckInBetween3(p1,c1,c2)==YSTRUE)
			{
				newP1=p1;
				newP2=c2;
			}
			else
			{
				newP1=c2;
				newP2=p2;
			}
			return YSOK;
		}
		else
		{
			return YSERR;
		}
	}
	else
	{
		return YSERR;
	}
}
Ejemplo n.º 29
0
static YSRESULT YsClipPolygon3_ByOnePlane
   (int &newNp,YsVec3 newp[],int bufLen,
    int np,const YsVec3 p[],const YsVec3 &threshold,int component,YSBOOL removeGreater)
{
	const double *v1,*v2,*thr;
	double v[3];
	YSBOOL in;

	thr=threshold.GetValue();

	if(bufLen>0)
	{
		newNp=0;
		v1=p[0].GetValue();
		if(removeGreater==YSTRUE)
		{
			if(v1[component]<=thr[component])
			{
				in=YSTRUE;
				newp[newNp]=p[0];
				newNp++;
			}
			else
			{
				in=YSFALSE;
			}
		}
		else
		{
			if(v1[component]>=thr[component])
			{
				in=YSTRUE;
				newp[newNp]=p[0];
				newNp++;
			}
			else
			{
				in=YSFALSE;
			}
		}

		int i;
		YSBOOL prevIn;
		for(i=0; i<np; i++)
		{
			v1=p[i].GetValue();
			v2=p[(i+1)%np].GetValue();

			prevIn=in;
			if(removeGreater==YSTRUE)
			{
				if(v2[component]<=thr[component])
				{
					in=YSTRUE;
				}
				else
				{
					in=YSFALSE;
				}
			}
			else
			{
				if(v2[component]>=thr[component])
				{
					in=YSTRUE;
				}
				else
				{
					in=YSFALSE;
				}
			}

			if(prevIn!=in && YsEqual(v1[component],v2[component])!=YSTRUE)
			{
				if(newNp<bufLen)
				{
					int e;
					for(e=0; e<3; e++)
					{
						if(e==component)
						{
							v[e]=thr[component];
						}
						else
						{
							double x1,y1,x2,y2,x,y;
							x1=v1[component];
							y1=v1[e];
							x2=v2[component];
							y2=v2[e];
							x=thr[component];
							y=(y2-y1)/(x2-x1)*(x-x1)+y1;
							v[e]=y;
						}
					}
					newp[newNp].Set(v[0],v[1],v[2]);
					newNp++;
				}
				else
				{
					return YSERR;
				}
			}

			if(in==YSTRUE)
			{
				if(newNp<bufLen)
				{
					newp[newNp].Set(v2[0],v2[1],v2[2]);
					newNp++;
				}
				else
				{
					return YSERR;
				}
			}
		}
		return YSOK;
	}
	return YSERR;
}
void FsGui3DInterface::Draw(void) const
{
	needRedraw=YSFALSE;

	if(type==IFTYPE_BOX)
	{
		YsVec3 cen,o;

		glColor3d(0.0,1.0,0.0);

		glEnable(GL_LINE_STIPPLE);
		glLineStipple(1,0xf0f0);

		glBegin(GL_LINES);

		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z());
		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z());

		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z());
		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z());

		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z());
		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z());


		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z());
		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z());

		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z());
		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z());

		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z());
		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z());

		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z());
		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z());

		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z());
		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z());


		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[0].z());
		glVertex3d(box_pos[0].x(),box_pos[0].y(),box_pos[1].z());

		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[0].z());
		glVertex3d(box_pos[1].x(),box_pos[0].y(),box_pos[1].z());

		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[0].z());
		glVertex3d(box_pos[1].x(),box_pos[1].y(),box_pos[1].z());

		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[0].z());
		glVertex3d(box_pos[0].x(),box_pos[1].y(),box_pos[1].z());


		glEnd();

		glDisable(GL_LINE_STIPPLE);

		cen=(box_pos[0]+box_pos[1])/2.0;

		glPointSize(float(markerSize));
		glLineWidth(float(linePickingTolerance));

		o.Set(box_pos[0].x(),cen.y(),cen.z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3( 1.0,0.0,0.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(-1.0,0.0,0.0),pickerLength);

		o.Set(box_pos[1].x(),cen.y(),cen.z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3( 1.0,0.0,0.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(-1.0,0.0,0.0),pickerLength);

		o.Set(cen.x(),box_pos[0].y(),cen.z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3(0.0, 1.0,0.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(0.0,-1.0,0.0),pickerLength);

		o.Set(cen.x(),box_pos[1].y(),cen.z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3(0.0, 1.0,0.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(0.0,-1.0,0.0),pickerLength);

		o.Set(cen.x(),cen.y(),box_pos[0].z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3(0.0,0.0, 1.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(0.0,0.0,-1.0),pickerLength);

		o.Set(cen.x(),cen.y(),box_pos[1].z());
		glBegin(GL_POINTS);
		glVertex3dv(o.GetValue());
		glEnd();
		DrawLineByPixelLength(o,YsVec3(0.0,0.0, 1.0),pickerLength);
		DrawLineByPixelLength(o,YsVec3(0.0,0.0,-1.0),pickerLength);


		glPointSize(1);
		glLineWidth(1);

		if(dragging==YSTRUE)
		{
			switch(box_dragging)
			{
			case BOX_XMIN:
				glBegin(GL_LINES);
				glVertex3d(box_pos[0].x()-infiniteLongLine,cen.y(),cen.z());
				glVertex3d(box_pos[0].x()+infiniteLongLine,cen.y(),cen.z());
				glEnd();
				break;
			case BOX_XMAX:
				glBegin(GL_LINES);
				glVertex3d(box_pos[1].x()-infiniteLongLine,cen.y(),cen.z());
				glVertex3d(box_pos[1].x()+infiniteLongLine,cen.y(),cen.z());
				glEnd();
				break;
			case BOX_YMIN:
				glBegin(GL_LINES);
				glVertex3d(cen.x(),box_pos[0].y()-infiniteLongLine,cen.z());
				glVertex3d(cen.x(),box_pos[0].y()+infiniteLongLine,cen.z());
				glEnd();
				break;
			case BOX_YMAX:
				glBegin(GL_LINES);
				glVertex3d(cen.x(),box_pos[1].y()-infiniteLongLine,cen.z());
				glVertex3d(cen.x(),box_pos[1].y()+infiniteLongLine,cen.z());
				glEnd();
				break;
			case BOX_ZMIN:
				glBegin(GL_LINES);
				glVertex3d(cen.x(),cen.y(),box_pos[0].z()-infiniteLongLine);
				glVertex3d(cen.x(),cen.y(),box_pos[0].z()+infiniteLongLine);
				glEnd();
				break;
			case BOX_ZMAX:
				glBegin(GL_LINES);
				glVertex3d(cen.x(),cen.y(),box_pos[1].z()-infiniteLongLine);
				glVertex3d(cen.x(),cen.y(),box_pos[1].z()+infiniteLongLine);
				glEnd();
				break;
			}
		}
	}
	else if(type==IFTYPE_POINT)
	{
		glColor3d(0.0,1.0,0.0);

		glBegin(GL_LINE_STRIP);
		switch(point_dlg1->GetBasePlane())
		{
		case 0:
			glVertex3d(point_pos.x(),point_pos.y(),point_pos.z());
			glVertex3d(point_pos.x(),point_pos.y(),0.0);
			glVertex3d(point_pos.x(),0.0          ,0.0);
			glVertex3d(0.0          ,0.0          ,0.0);
			glVertex3d(0.0          ,point_pos.y(),0.0);
			glVertex3d(point_pos.x(),point_pos.y(),0.0);
			break;
		case 1:
			glVertex3d(point_pos.x(),point_pos.y(),point_pos.z());
			glVertex3d(point_pos.x(),0.0          ,point_pos.z());
			glVertex3d(0.0          ,0.0          ,point_pos.z());
			glVertex3d(0.0          ,0.0          ,0.0);
			glVertex3d(point_pos.x(),0.0          ,0.0);
			glVertex3d(point_pos.x(),0.0          ,point_pos.z());
			break;
		case 2:
			glVertex3d(point_pos.x(),point_pos.y(),point_pos.z());
			glVertex3d(0.0          ,point_pos.y(),point_pos.z());
			glVertex3d(0.0          ,0.0          ,point_pos.z());
			glVertex3d(0.0          ,0.0          ,0.0);
			glVertex3d(0.0          ,point_pos.y(),0.0);
			glVertex3d(0.0          ,point_pos.y(),point_pos.z());
			break;
		}

		glEnd();


		auto nom=point_dlg1->GetNormalDirection();

		if(POINT_Y==point_dragging)
		{
			glPushAttrib(GL_ENABLE_BIT);
			glLineWidth(1);
			glEnable(GL_LINE_STIPPLE);
			glLineStipple(1,0x0003);
			glBegin(GL_LINES);
			glVertex3dv((point_pos-nom*infiniteLongLine).GetValue());
			glVertex3dv((point_pos+nom*infiniteLongLine).GetValue());
			glEnd();
			glPopAttrib();
		}

		glLineWidth(float(linePickingTolerance));
		DrawLineByPixelLength(point_pos, nom,pickerLength);
		DrawLineByPixelLength(point_pos,-nom,pickerLength);
		glLineWidth(float(1));

		DrawRectMarker(point_pos,markerSize);
	}
	else if(type==IFTYPE_DRAGPOINT)
	{
		glColor3d(0.0,1.0,0.0);

		glPointSize(float(markerSize));
		glBegin(GL_POINTS);
		glVertex3dv(point_pos.GetValue());
		glEnd();
		glPointSize(1);


		YsVec3 dragDir[3];
		if(YSTRUE==point_dlg2->UseCustomOrientation())
		{
			dragDir[0]=point_dragDir[0];
			dragDir[1]=point_dragDir[1];
			dragDir[2]=point_dragDir[2];
		}
		else
		{
			dragDir[0]=YsXVec();
			dragDir[1]=YsYVec();
			dragDir[2]=YsZVec();
		}

		const DRAGTARGET pointDragTarget[3]=
		{
			POINT_X,
			POINT_Y,
			POINT_Z
		};


		int i;
		for(i=0; i<3; i++)
		{
			if(point_dragDirSwitch[i]==YSTRUE)
			{
				glLineWidth(float(linePickingTolerance));
				DrawLineByPixelLength(point_pos, dragDir[i],pickerLength);
				DrawLineByPixelLength(point_pos,-dragDir[i],pickerLength);
			}
			if(dragging==YSTRUE && point_dragging==pointDragTarget[i])
			{
				glPushAttrib(GL_ENABLE_BIT);
				glLineWidth(1);
				glEnable(GL_LINE_STIPPLE);
				glLineStipple(1,0x0003);
				glBegin(GL_LINES);
				glVertex3dv((point_pos-dragDir[i]*infiniteLongLine).GetValue());
				glVertex3dv((point_pos+dragDir[i]*infiniteLongLine).GetValue());
				glEnd();
				glPopAttrib();
			}
		}

		glLineWidth(1);
	}
	else if(type==IFTYPE_SLIDER)
	{
	}
	else if(type==IFTYPE_ROTATION)
	{
		if(dragging==YSTRUE)
		{
			glColor3d(1.0,0.0,5.0);
		}
		else
		{
			glColor3d(0.0,1.0,0.0);
		}


		glLineWidth(3);
		glBegin(GL_LINES);
		glVertex3dv((rot_center+rot_axis*infiniteLongLine).GetValue());
		glVertex3dv((rot_center-rot_axis*infiniteLongLine).GetValue());
		glEnd();
		glLineWidth(1);


		YsVec3 iVec=rot_iVec;
		YsVec3 jVec=rot_jVec;
		YsVec3 kVec=rot_kVec;

		YsMatrix4x4 mat,axisMat;
		YsAtt3 att;
		att.SetForwardVector(rot_axis);
		att.GetMatrix4x4(axisMat);
		mat.Initialize();
		mat.Rotate(rot_axis.x(),rot_axis.y(),rot_axis.z(),rot_angle);
		mat=mat*axisMat;
		mat.Scale(1.0,1.0,rot_mirror);
		mat.Scale(rot_ref_size,rot_ref_size,rot_ref_size);
		axisMat.Invert();
		mat=mat*axisMat;

		iVec=mat*iVec;
		jVec=mat*jVec;
		kVec=mat*kVec;

		glBegin(GL_LINES);
		for(int i=0; i<360; i+=30)
		{
			YsVec3 p[2];
			double a;
			a=YsPi*2.0*double(i)/360.0;
			p[0]=rot_center+iVec*cos(a)+jVec*1.0+kVec*sin(a);
			p[1]=rot_center+iVec*cos(a)-jVec*1.0+kVec*sin(a);

			glVertex3dv(p[0].GetValue());
			glVertex3dv(p[1].GetValue());
		}
		glEnd();

		glBegin(GL_LINE_LOOP);
		for(int i=0; i<360; i+=10)
		{
			double a;
			YsVec3 p;
			a=YsPi*2.0*double(i)/360.0;
			p=rot_center+iVec*cos(a)+jVec*1.0+kVec*sin(a);
			glVertex3dv(p.GetValue());
		}
		glEnd();

		glBegin(GL_LINE_LOOP);
		for(int i=0; i<360; i+=10)
		{
			double a;
			YsVec3 p;
			a=YsPi*2.0*double(i)/360.0;
			p=rot_center+iVec*cos(a)-jVec*1.0+kVec*sin(a);
			glVertex3dv(p.GetValue());
		}
		glEnd();


		// Side drag marker

		const YsVec3 sideX=rot_drag_dir*rot_ref_size*1.1;
		const YsVec3 sideY=(rot_drag_dir^rot_axis)*rot_ref_size*1.1;

		glLineWidth(3);

		glBegin(GL_LINE_LOOP);
		for(int i=0; i<360; i+=10)
		{
			const double a=YsPi*2.0*double(i)/360.0;
			YsVec3 p;
			p=rot_center+sideX*cos(a)+sideY*sin(a);
			glVertex3dv(p);
		}
		glEnd();


		if(ROTATION_HANDLE==rot_dragging)
		{
			glBegin(GL_LINES);
			glVertex3dv(rot_center);

			const YsVec3 radial=rot_ref_size*1.1*(rot_iVec*cos(rot_drag_angle)-rot_kVec*sin(rot_drag_angle));
			glVertex3dv(rot_center+radial);

			glEnd();
		}

		glLineWidth(1);
	}
}