void CMine::EditGeoFwd () { double x,y,z; double radius; vms_vector center,opp_center; int i; /* calculate center of current side */ center.x = center.y = center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [side_vert [Current ()->side][i]]; center.x += Vertices (vertnum)->x; center.y += Vertices (vertnum)->y; center.z += Vertices (vertnum)->z; } center.x /= 4; center.y /= 4; center.z /= 4; // calculate center of opposite of current side opp_center.x = opp_center.y = opp_center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [opp_side_vert [Current ()->side][i]]; opp_center.x += Vertices (vertnum)->x; opp_center.y += Vertices (vertnum)->y; opp_center.z += Vertices (vertnum)->z; } opp_center.x /= 4; opp_center.y /= 4; opp_center.z /= 4; // normalize vector x = center.x - opp_center.x; y = center.y - opp_center.y; z = center.z - opp_center.z; // normalize direction radius = sqrt(x*x + y*y + z*z); if (radius > (F1_0/10)) { x /= radius; y /= radius; z /= radius; } else { vms_vector direction; CalcOrthoVector(direction,Current ()->segment,Current ()->side); x = (double)direction.x/(double)F1_0; y = (double)direction.y/(double)F1_0; z = (double)direction.z/(double)F1_0; } // move on x, y, and z theApp.SetModified (TRUE); theApp.LockUndo (); MoveOn('X', (INT32) (x*move_rate)); MoveOn('Y', (INT32) (y*move_rate)); MoveOn('Z', (INT32) (z*move_rate)); theApp.UnlockUndo (); }
/* * set EyeMove (current speed) for FLYING mode */ void SetMove(float newmove) { if (newmove > MINMOVE) { EyeMove = newmove; MoveOn(1); } else { EyeMove = 0; MoveOn(0); } }
void agvHandleButton(int button, int state, int x, int y) { if (state == GLUT_DOWN && downb == -1) { lastx = downx = x; lasty = downy = y; downb = button; switch (button) { case GLUT_LEFT_BUTTON: lastEl = downEl = EyeEl; lastAz = downAz = EyeAz; AzSpin = ElSpin = dAz = dEl = 0; AdjustingAzEl = 1; MoveOn(1); break; case GLUT_MIDDLE_BUTTON: downDist = EyeDist; downEx = Ex; downEy = Ey; downEz = Ez; downEyeMove = EyeMove; EyeMove = 0; } } else if (state == GLUT_UP && button == downb) { downb = -1; switch (button) { case GLUT_LEFT_BUTTON: if (MoveMode != FLYING) { AzSpin = -dAz; if (AzSpin < MIN_AZSPIN && AzSpin > -MIN_AZSPIN) AzSpin = 0; ElSpin = -dEl; if (ElSpin < MIN_ELSPIN && ElSpin > -MIN_ELSPIN) ElSpin = 0; } AdjustingAzEl = 0; MoveOn(1); break; case GLUT_MIDDLE_BUTTON: EyeMove = downEyeMove; } } }
/* * when moving to flying we stay in the same spot, moving to polar we * reset since we have to be looking at the origin (though a pivot from * current position to look at origin might be cooler) */ void agvSwitchMoveMode(int move) { switch (move) { case FLYING: if (MoveMode == FLYING) return; Ex = -EyeDist*sin(TORAD(EyeAz))*cos(TORAD(EyeEl)); Ey = EyeDist*sin(TORAD(EyeEl)); Ez = EyeDist*(cos(TORAD(EyeAz))*cos(TORAD(EyeEl))); EyeAz = EyeAz; EyeEl = -EyeEl; EyeMove = INIT_MOVE; break; case POLAR: EyeDist = INIT_DIST; EyeAz = INIT_POLAR_AZ; EyeEl = INIT_POLAR_EL; AzSpin = INIT_AZ_SPIN; ElSpin = INIT_EL_SPIN; break; } MoveMode = move; MoveOn(1); glutPostRedisplay(); }
void CMine::EditGeoBack() { vms_vector center,opp_center; double x,y,z,radius; int i; /* calculate center of current side */ center.x = center.y = center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [side_vert [Current ()->side][i]]; center.x += Vertices (vertnum)->x; center.y += Vertices (vertnum)->y; center.z += Vertices (vertnum)->z; } center.x /= 4; center.y /= 4; center.z /= 4; // calculate center of oppisite current side opp_center.x = opp_center.y = opp_center.z = 0; for (i = 0; i < 4; i++) { int vertnum = Segments (Current ()->segment)->verts [opp_side_vert [Current ()->side][i]]; opp_center.x += Vertices (vertnum)->x; opp_center.y += Vertices (vertnum)->y; opp_center.z += Vertices (vertnum)->z; } opp_center.x /= 4; opp_center.y /= 4; opp_center.z /= 4; // normalize vector x = center.x - opp_center.x; y = center.y - opp_center.y; z = center.z - opp_center.z; // make sure distance is positive to prevent // cube from turning inside out #if 1 // defines line orthogonal to a side at a point UINT8 orthog_line [6][4] = { {8,6,1,3}, {0,5,7,2}, {3,1,6,8}, {2,7,5,0}, {4,9,10,11}, {11,10,9,4} }; CDSegment *seg; INT16 point0,point1; vms_vector *vector0,*vector1; bool ok_to_move; ok_to_move = TRUE; seg = Segments () + Current ()->segment; switch (m_selectMode) { case POINT_MODE: point0 = line_vert [orthog_line [Current ()->side][Current ()->point]][0]; point1 = line_vert [orthog_line [Current ()->side][Current ()->point]][1]; vector0 = Vertices (seg->verts [point0]); vector1 = Vertices (seg->verts [point1]); if (CalcLength(vector0,vector1) - move_rate < F1_0 / 4) { ok_to_move = FALSE; } break; case LINE_MODE: for (i=0;i<2;i++) { point0 = line_vert [orthog_line [Current ()->side][(Current ()->line+i)%4]][0]; point1 = line_vert [orthog_line [Current ()->side][(Current ()->line+i)%4]][1]; vector0 = Vertices (seg->verts [point0]); vector1 = Vertices (seg->verts [point1]); if (CalcLength(vector0,vector1) - move_rate < F1_0 / 4) { ok_to_move = FALSE; } } break; case SIDE_MODE: for (i = 0; i < 4; i++) { point0 = line_vert [orthog_line [Current ()->side][i]][0]; point1 = line_vert [orthog_line [Current ()->side][i]][1]; vector0 = Vertices (seg->verts [point0]); vector1 = Vertices (seg->verts [point1]); if (CalcLength(vector0,vector1) - move_rate < F1_0 / 4) { ok_to_move = FALSE; } } break; } if (ok_to_move == FALSE) { ErrorMsg("Too small to move in that direction"); return; } #endif radius = sqrt(x*x + y*y + z*z); if ((radius-move_rate) < F1_0 / 4) { if (m_selectMode == POINT_MODE || m_selectMode == LINE_MODE || m_selectMode == SIDE_MODE) { ErrorMsg("Cannot make cube any smaller\n" "Cube must be greater or equal to 1.0 units wide."); } } else { // normalize direction if (radius > (F1_0/10)) { x /= radius; y /= radius; z /= radius; } else { vms_vector direction; CalcOrthoVector(direction,Current ()->segment,Current ()->side); x = (double)direction.x/(double)F1_0; y = (double)direction.y/(double)F1_0; z = (double)direction.z/(double)F1_0; } // move on x, y, and z theApp.SetModified (TRUE); theApp.LockUndo (); MoveOn('X',(INT32) (-x*move_rate)); MoveOn('Y',(INT32) (-y*move_rate)); MoveOn('Z',(INT32) (-z*move_rate)); theApp.UnlockUndo (); } theApp.SetModified (TRUE); }
/* * set new redisplay window. If <= 0 it means we are not to install * an idle function and will rely on whoever does install one to * put statement like "if (agvMoving) agvMove();" at end of it */ void agvSetAllowIdle(int allowidle) { if ((AllowIdle = allowidle)) MoveOn(1); }