Exemple #1
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);
        }
    }
}
Exemple #2
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();
}
Exemple #3
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;
}
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();
}
Exemple #5
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);
	}
}
Exemple #6
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);
	}
}
Exemple #7
0
void DrawShell(YsShell &shell,YsColor &col,YSBOOL inPolygon)
{
	int i,j,k;
	int nVtx,nPlg;
	YsVec3 vtx[256];

	if(inPolygon==YSTRUE)
	{
		glEnable(GL_LIGHTING);
	}
	else
	{
		glDisable(GL_LIGHTING);
	}

	nPlg=shell.GetNumPolygon();
	for(i=0; i<nPlg; i++)
	{
		nVtx=shell.GetNumVertexOfPolygon(i);
		if(nVtx>0)
		{
			double r,g,b;
			YsVec3 nom;

			shell.GetVertexListOfPolygon(vtx,256,i);
			nom=(vtx[1]-vtx[0])^(vtx[2]-vtx[1]);
			nom.Normalize();

			col.GetDoubleRGB(r,g,b);

			glColor3d(r,g,b);

			if(inPolygon==YSFALSE || YsCheckConvex3(nVtx,vtx)==YSTRUE)
			{
				switch(inPolygon)
				{
				case YSFALSE:
					glBegin(GL_LINE_LOOP);
					break;
				case YSTRUE:
					glBegin(GL_POLYGON);
					break;
				}
				glNormal3d(nom.x(),nom.y(),nom.z());
				for(j=0; j<nVtx; j++)
				{
					glVertex3d(vtx[j].x(),vtx[j].y(),vtx[j].z());
				}
				glEnd();
			}
			else
			{
				YsSword swd;
				swd.SetInitialPolygon(nVtx,vtx);
				swd.Convexnize();
				for(j=0; j<swd.GetNumPolygon(); j++)
				{
					nVtx=swd.GetNumVertexOfPolygon(j);
					swd.GetVertexListOfPolygon(vtx,256,j);
					glBegin(GL_POLYGON);
					for(k=0; k<nVtx; k++)
					{
						glVertex3dv(vtx[k].GetValue());
					}
					glEnd();
				}
			}
		}
	}
}