void NMButton::eventhandle(NEvent* ev) //обработчик событий { NStaticText::eventhandle(ev); //предок if ( ev->done ) return; //одиночный или двойной клик NMouseEvent* mevent = (NMouseEvent*)ev; if (( ev->type == NEvent::evMOUSE ) && (mevent->cmdcode & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))) { if (isinside(mevent->row, mevent->col)) { ev->done = true; NEvent* tmp = pevent; pevent = NULL; putevent(tmp); //активируем событие связанное с этой кнопкой } } //клавиатура if ( ev->type == NEvent::evKB ) { if ( keys.end() != std::find(keys.begin(), keys.end(), ev->cmdcode) ) { kLogPrintf("NMButton::eventhandle() got '%c' key\n", ev->cmdcode); if (pevent) { ev->done = true; NEvent* tmp = pevent; pevent = NULL; putevent(tmp); //активируем событие связанное с этой кнопкой } } } }
void draw() { /*if (numpoints > 1) { glColor3f(0, 0, 0); glBegin(GL_POINTS); //glBegin(GL_LINE_STRIP); for (float Y = 0; Y < screenHeight; Y++) { for (float X = 0; X < screenWidth; X++) { //for (float Y = 0; Y < screenHeight; Y += 0.5f) { // for (float X = 0; X < screenWidth; X += 0.5f) { worldx = -((((screenWidth - (float) X) / screenWidth) * 2) - 1); worldy = ((((screenHeight - (float) Y) / screenHeight) * 2) - 1); if (fabs(worldx * normal.x + worldy * normal.y - c) <= 0.002f) { glVertex2f(worldx, worldy); } } } glEnd(); }*/ if (numpoints > 2) { //cout << "parabolarajz\n" << flush; //glPointSize(1); glBegin(GL_POINTS); //glBegin(GL_LINE_STRIP); for (float Y = 0; Y < screenHeight; Y++) { for (float X = 0; X < screenWidth; X++) { //for (float Y = 0; Y < screenHeight; Y += 0.5f) { // for (float X = 0; X < screenWidth; X += 0.5f) { worldx = -((((screenWidth - (float) X) / screenWidth) * 2) - 1); worldy = ((((screenHeight - (float) Y) / screenHeight) * 2) - 1); Vector v(worldx, worldy, 0); if (isinside(v)) { glColor3f(1, 1, 0); glVertex2f(worldx, worldy); //image[screenHeight-1-Y][X] = Color(1, 1, 0); } } } glEnd(); /* bool first = false; Vector f; glColor3f(1, 1, 0); glBegin(GL_TRIANGLE_FAN); glVertex2f(focus.x, focus.y); for (float X = -300; X < screenHeight + 300; X++) { for (float Y = -300; Y < screenWidth + 300; Y++) { worldx = -((((screenWidth - (float) X) / screenWidth) * 2) - 1); worldy = ((((screenHeight - (float) Y) / screenHeight) * 2) - 1); Vector v(worldx, worldy, 0); if (isinside(v)) { if (!first) { f = v; first = true; } glVertex2f(worldx, worldy); } } } glVertex2f(f.x, f.y); glEnd(); */ //glPointSize(4); /*glBegin(GL_POINTS); glColor3f(0, 1, 0); glVertex2f(tangentpoint.x, tangentpoint.y); glColor3f(0, 0, 0); glVertex2f(temp.x, temp.y); glColor3f(1, 1, 0); glVertex2f(temp2.x, temp2.y); glEnd();*/ } if (intersected) { glColor3f(0, 0.5f, 0); //glLineWidth(3); //glBegin(GL_LINES); //glVertex2f(intersectdirection.x, intersectdirection.y); //glVertex2f(tangentpoint.x, tangentpoint.y); //glVertex2f(intersectpoint.x, intersectpoint.y); /* glVertex2f(intersectpoint.x + intersectdirection.x, intersectpoint.y + intersectdirection.y); glVertex2f(intersectpoint.x, intersectpoint.y); glVertex2f(intersectpoint.x - intersectdirection.x, intersectpoint.y - intersectdirection.y); */ //glEnd(); glBegin(GL_LINES); glVertex2f(intersectpoint.x - intersectdirection.x, intersectpoint.y - intersectdirection.y); glVertex2f(intersectpoint.x + intersectdirection.x, intersectpoint.y + intersectdirection.y); glEnd(); } /* if (numpoints > 1) { glColor3f(1, 1, 1); glBegin(GL_LINES); glVertex2f(directixpoints[0].x, directixpoints[0].y); glVertex2f(directixpoints[1].x, directixpoints[1].y); glEnd(); } */ }
double DropCutter::FacetTest(const Cutter &cu, const double *e, const GTri &t) { // local copy of the surface normal //t.calculate_normal(); // don't trust the pre-calculated normal! calculate it separately here. // make sure to use calculate_normal whenever the triangle is made or modified double n[3] = {t.m_n[0], t.m_n[1], t.m_n[2]}; double cc[3]; if (fabs(n[2]) < 0.000000000001) { // vertical plane, can't touch cutter against that! return -10000000.0; } else if (n[2] < 0) { // flip the normal so it points up (? is this always required?) for(int i = 0; i<3; i++)n[i] = -1*n[i]; } // define plane containing facet double a = n[0]; double b = n[1]; double c = n[2]; double d = - n[0] * t.m_p[0] - n[1] * t.m_p[1] - n[2] * t.m_p[2]; // the z-direction normal is a special case (?required?) // in debug phase, see if this is a useful case! if ((fabs(a) < heeksCAD->GetTolerance()) && (fabs(b) < heeksCAD->GetTolerance())) { // System.Console.WriteLine("facet-test:z-dir normal case!"); cc[0] = e[0]; cc[1] = e[1]; cc[2] = t.m_p[2]; if (isinside(t, cc)) { // System.Console.WriteLine("facet-test:z-dir normal case!, returning {0}",e.z); // System.Console.ReadKey(); return cc[2]; } else return -10000000.0; } // System.Console.WriteLine("facet-test:general case!"); // facet test general case // uses trigonometry, so might be too slow? // flat endmill and ballnose should be simple to do without trig // toroidal case might require offset-ellipse idea? /* theta = asin(c); zf= -d/c - (a*xe+b*ye)/c+ (R-r)/tan(theta) + r/sin(theta) -r; e=[xe ye zf]; u=[0 0 1]; rc=e + ((R-r)*tan(theta)+r)*u - ((R-r)/cos(theta) + r)*n; t=isinside(p1,p2,p3,rc); */ double theta = asin(c); double zf = -d/c - (a*e[0]+b*e[1])/c + (cu.R-cu.r)/tan(theta) + cu.r/sin(theta) - cu.r; double ve[3] = {e[0],e[1],zf}; double u[3] = {0,0,1}; double rc[3] = {ve[0], ve[1], ve[2]}; for(int i = 0; i<3; i++)rc[i] = ve[i] + ((cu.R-cu.r)*tan(theta)+cu.r)*u[i] - ((cu.R-cu.r)/cos(theta)+cu.r)*n[i]; /* if (rc.z > 1000) System.Console.WriteLine("z>1000 !"); */ cc[0] = rc[0]; cc[1] = rc[1]; cc[2] = rc[2]; // check that CC lies in plane: // a*rc(1)+b*rc(2)+c*rc(3)+d double test = a * cc[0] + b * cc[1] + c * cc[2] + d; if (test > 0.000001) wxMessageBox(_T("FacetTest ERROR! CC point not in plane")); if (isinside(t, cc)) { if (fabs(zf) > 100000) { wxMessageBox(wxString::Format(_T("serious problem... at %lf,%lf"), e[0], e[1])); } return zf; } else return -10000000.0; }