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);
        }
    }
}
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);
	}
}