00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030
00031 static const char rcsid[] = "$Id: robotgl.cpp,v 1.10 2006/05/16 16:46:18 gourdeau Exp $";
00032
00033 #include "robotgl.h"
00034
00035
00036
00042 Robotgl_basic::Robotgl_basic(const short dof_): Basic_object(), dof(dof_)
00043 {
00044 try
00045 {
00046 linkgl = new Linkgl[dof];
00047 linkgl--;
00048 jointgl = new Jointgl[dof];
00049 jointgl--;
00050 axis = new Axis(0.15);
00051 }
00052 catch(bad_alloc)
00053 {
00054 cerr << "Robotgl_basic constructor : new ran out of memory" << endl;
00055 exit(1);
00056 }
00057 }
00058
00063 Robotgl_basic::Robotgl_basic(const Robotgl_basic & x): Basic_object(x)
00064 {
00065 axis = x.axis;
00066 pos = x.pos;
00067
00068 if ( dof != x.dof )
00069 {
00070 dof = x.dof;
00071 linkgl++;
00072 jointgl++;
00073 delete[] jointgl;
00074 delete[] linkgl;
00075
00076 try
00077 {
00078 linkgl = new Linkgl[dof];
00079 linkgl--;
00080 jointgl = new Jointgl[dof];
00081 jointgl--;
00082 }
00083 catch(bad_alloc)
00084 {
00085 cerr << "Robotgl_basic constructor : new ran out of memory" << endl;
00086 exit(1);
00087 }
00088 }
00089
00090 for(int i = 1; i <= dof; i++)
00091 {
00092 linkgl[i] = x.linkgl[i];
00093 jointgl[i] = x.jointgl[i];
00094 }
00095 }
00096
00097 Robotgl_basic::~Robotgl_basic()
00099 {
00100 linkgl++;
00101 jointgl++;
00102 delete[] jointgl;
00103 delete[] linkgl;
00104 delete axis;
00105 }
00106
00107 Robotgl_basic & Robotgl_basic::operator=(const Robotgl_basic & x)
00109 {
00110 Basic_object::operator=(x);
00111
00112 pos = x.pos;
00113 axis = x.axis;
00114
00115 linkgl++;
00116 jointgl++;
00117 delete[]linkgl;
00118 delete[] jointgl;
00119
00120 if(dof != x.dof)
00121 {
00122 dof = x.dof;
00123
00124
00125
00126
00127
00128
00129 try
00130 {
00131 linkgl = new Linkgl[dof];
00132 linkgl--;
00133 jointgl = new Jointgl[dof];
00134 jointgl--;
00135 }
00136 catch(bad_alloc)
00137 {
00138 cerr << "Robotgl_basic constructor : new ran out of memory" << endl;
00139 exit(1);
00140 }
00141 }
00142
00143 for(int i = 1; i <= dof; i++)
00144 {
00145 linkgl[i] = x.linkgl[i];
00146 jointgl[i] = x.jointgl[i];
00147 }
00148
00149 return (*this);
00150 }
00151
00152 void Robotgl_basic::set_dof(const short dof_)
00158 {
00159 if ( dof != dof_ )
00160 {
00161 dof = dof_;
00162 linkgl++;
00163 jointgl++;
00164 delete[] jointgl;
00165 delete[] linkgl;
00166 try
00167 {
00168 linkgl = new Linkgl[dof];
00169 linkgl--;
00170 jointgl = new Jointgl[dof];
00171 jointgl--;
00172 }
00173 catch(bad_alloc)
00174 {
00175 cerr << "Robotgl_basic constructor : new ran out of memory" << endl;
00176 exit(1);
00177 }
00178 }
00179 }
00180
00181 bool Robotgl_basic::Is_STL()
00186 {
00187 for(int i = 1; i <= dof; i++)
00188 {
00189 if(linkgl[i].STL || linkgl[i].STL)
00190 return true;
00191 }
00192 return false;
00193 }
00194
00195 void Robotgl_basic::create_list()
00197 {
00198 for(int i = 1; i <= dof; i++)
00199 {
00200 jointgl[i].create_list();
00201 linkgl[i].create_list();
00202 }
00203 }
00204
00205
00206
00207
00213 Robotgl::Robotgl(short ndof) : Robot(ndof), Robotgl_basic(ndof)
00214 {
00215 message_object = "Robotgl";
00216 }
00217
00224 Robotgl::Robotgl(const Matrix & initrob, const ColumnVector & position_) :
00225 Robot(initrob), Robotgl_basic()
00226 {
00227 std::vector<double> parameters;
00228 for(int i = 1; i <= initrob.Nrows(); i++)
00229 {
00230 parameters.push_back(initrob(i,1));
00231 parameters.push_back(initrob(i,2));
00232 parameters.push_back(initrob(i,5));
00233 parameters.push_back(initrob(i,4));
00234 parameters.push_back(initrob(i,3));
00235 parameters.push_back(0.05);
00236 }
00237
00238 position = position_;
00239 pos = ColumnVector(3); pos = 0;
00240
00241 message_object = "Robotgl";
00242 Robotgl_basic::set_dof(Robot::dof);
00243
00244 std::vector<double> para;
00245 for(int j = 1; j <= Robot_basic::dof; j++)
00246 {
00247 para.clear();
00248 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00249 para.push_back(parameters[i]);
00250
00251 jointgl[j] = Jointgl(para, position, true);
00252 linkgl[j] = Linkgl(para, position, jointgl[j].radius, true);
00253 }
00254 }
00255
00264 Robotgl::Robotgl(const Matrix & initrob, const Matrix & initrobm,
00265 const ColumnVector & position_) : Robot(initrob, initrobm),
00266 Robotgl_basic()
00267 {
00268 std::vector<double> parameters;;
00269 for(int i = 1; i <= initrob.Nrows(); i++)
00270 {
00271 parameters.push_back(initrob(i,1));
00272 parameters.push_back(initrob(i,2));
00273 parameters.push_back(initrob(i,5));
00274 parameters.push_back(initrob(i,4));
00275 parameters.push_back(initrob(i,3));
00276 parameters.push_back(0.05);
00277 }
00278
00279 position = position_;
00280 pos = ColumnVector(3); pos = 0;
00281
00282 Robotgl_basic::set_dof(Robot::dof);
00283
00284 std::vector<double> para;
00285 for(int j = 1; j <= Robot_basic::dof; j++)
00286 {
00287 para.clear();
00288 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00289 para.push_back(parameters[i]);
00290
00291 jointgl[j] = Jointgl(para, position, true);
00292 linkgl[j] = Linkgl(para, position, jointgl[j].radius, true);
00293 }
00294 }
00295
00304 Robotgl::Robotgl(const string & filename, const string & robotName,
00305 const ColumnVector & position_) : Robot(filename, robotName),
00306 Robotgl_basic()
00307 {
00308 Config robData(true);
00309 ifstream inconffile(filename.c_str(), std::ios::in);
00310 if (robData.read_conf(inconffile))
00311 {
00312 cerr << "Robotgl::Robotgl: unable to read input config file." << endl;
00313 }
00314
00315 bool Stl;
00316 string robotName_link_stl, stl_file;
00317 robData.select(robotName, "Stl", Stl);
00318
00319 std::vector<double> parameters;
00320 for(int i = 1; i <= Robot::dof; i++)
00321 {
00322 parameters.push_back(links[i].get_joint_type());
00323 parameters.push_back(links[i].get_theta());
00324 parameters.push_back(links[i].get_alpha());
00325 parameters.push_back(links[i].get_a());
00326 parameters.push_back(links[i].get_d());
00327 parameters.push_back(0.05);
00328 }
00329
00330 position = position_;
00331 pos = ColumnVector(3); pos = 0;
00332
00333 Robotgl_basic::set_dof(Robot::dof);
00334
00335 double trans_x, trans_y, trans_z, rot_x, rot_y, rot_z, scal_x, scal_y, scal_z;
00336 float red, green, blue;
00337 std::vector<double> para;
00338 for(int j = 1; j <= Robot_basic::dof; j++)
00339 {
00340 para.clear();
00341 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00342 para.push_back(parameters[i]);
00343
00344 if(Stl)
00345 {
00346 ostringstream ostr;
00347 ostr << robotName << "_LINK" << j << "_STL";
00348 robotName_link_stl = ostr.str();
00349 robData.select(robotName_link_stl, "joint_file", stl_file);
00350 robData.select(robotName_link_stl, "joint_translation_x", trans_x);
00351 robData.select(robotName_link_stl, "joint_translation_y", trans_y);
00352 robData.select(robotName_link_stl, "joint_translation_z", trans_z);
00353 robData.select(robotName_link_stl, "joint_rotation_x", rot_x);
00354 robData.select(robotName_link_stl, "joint_rotation_y", rot_y);
00355 robData.select(robotName_link_stl, "joint_rotation_z", rot_z);
00356 robData.select(robotName_link_stl, "joint_scaling_factor_x", scal_x);
00357 robData.select(robotName_link_stl, "joint_scaling_factor_y", scal_y);
00358 robData.select(robotName_link_stl, "joint_scaling_factor_z", scal_z);
00359 robData.select(robotName_link_stl, "joint_rgb_red", red);
00360 robData.select(robotName_link_stl, "joint_rgb_green", green);
00361 robData.select(robotName_link_stl, "joint_rgb_blue", blue);
00362
00363 jointgl[j] = Jointgl(para, position, true, trans_x, trans_y, trans_z, rot_x,
00364 rot_y, rot_z, scal_x, scal_y, scal_z, red,
00365 green, blue, stl_file);
00366
00367 robData.select(robotName_link_stl, "link_file", stl_file);
00368 robData.select(robotName_link_stl, "link_translation_x", trans_x);
00369 robData.select(robotName_link_stl, "link_translation_y", trans_y);
00370 robData.select(robotName_link_stl, "link_translation_z", trans_z);
00371 robData.select(robotName_link_stl, "link_rotation_x", rot_x);
00372 robData.select(robotName_link_stl, "link_rotation_y", rot_y);
00373 robData.select(robotName_link_stl, "link_rotation_z", rot_z);
00374 robData.select(robotName_link_stl, "link_scaling_factor_x", scal_x);
00375 robData.select(robotName_link_stl, "link_scaling_factor_y", scal_y);
00376 robData.select(robotName_link_stl, "link_scaling_factor_z", scal_z);
00377 robData.select(robotName_link_stl, "link_rgb_red", red);
00378 robData.select(robotName_link_stl, "link_rgb_green", green);
00379 robData.select(robotName_link_stl, "link_rgb_blue", blue);
00380
00381 linkgl[j] = Linkgl(para, position, jointgl[j].radius, true, trans_x, trans_y,
00382 trans_z, rot_x, rot_y, rot_z, scal_x, scal_y, scal_z,
00383 red, green, blue, stl_file);
00384 }
00385 else
00386 {
00387 jointgl[j] = Jointgl(para, position, true);
00388 linkgl[j] = Linkgl(para, position, jointgl[j].radius, true);
00389 }
00390 }
00391 }
00392
00397 Robotgl::Robotgl(const Robotgl & x) : Robot(x), Robotgl_basic(x)
00398 {
00399 }
00400
00401 Robotgl & Robotgl::operator=(const Robotgl & x)
00403 {
00404 Robot::operator=(x);
00405 Robotgl_basic::operator=(x);
00406
00407 return (*this);
00408 }
00409
00410 void Robotgl::draw()
00412 {
00413 pos = 0.0;
00414 glPushMatrix();
00415
00416 for(int i = 1; i <= Robot_basic::dof; i++)
00417 {
00418 GLfloat transformation [] =
00419 {links[i].R(1,1), links[i].R(2,1), links[i].R(3,1), 0,
00420 links[i].R(1,2), links[i].R(2,2), links[i].R(3,2), 0,
00421 links[i].R(1,3), links[i].R(2,3), links[i].R(3,3), 0,
00422 0, 0, 0, 1};
00423
00424 glTranslatef(pos(1), pos(2), pos(3));
00425 jointgl[i].draw();
00426
00427 glMultMatrixf(transformation);
00428
00429 linkgl[i].draw();
00430
00431 pos = links[i].get_p();
00432
00433
00434 pos = links[i].R.t()*pos;
00435 }
00436
00437 glTranslatef(pos(1), pos(2), pos(3));
00438 axis->draw();
00439
00440 glPopMatrix();
00441 }
00442
00443
00449 mRobotgl::mRobotgl(short ndof) : mRobot(ndof), Robotgl_basic(ndof)
00450 {
00451 message_object = "mRobotgl";
00452 }
00453
00460 mRobotgl::mRobotgl(const Matrix & initrob, const ColumnVector & position_) :
00461 mRobot(initrob), Robotgl_basic()
00462 {
00463 std::vector<double> parameters;
00464 for(int i = 1; i < initrob.Nrows(); i++)
00465 {
00466 parameters.push_back(initrob(i,1));
00467 parameters.push_back(initrob(i,2));
00468 parameters.push_back(initrob(i,5));
00469 parameters.push_back(initrob(i+1,4));
00470 parameters.push_back(initrob(i,3));
00471 parameters.push_back(0.05);
00472 }
00473
00474 pos = ColumnVector(3); pos = 0;
00475 position = position_;
00476 message_object = "mRobotgl";
00477
00478 Robotgl_basic::set_dof(mRobot::dof);
00479
00480 std::vector<double> para;
00481 for(int j = 1; j <= mRobot::dof; j++)
00482 {
00483 para.clear();
00484 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00485 para.push_back(parameters[i]);
00486
00487 jointgl[j] = Jointgl(para, position);
00488 linkgl[j] = Linkgl(para, position, jointgl[j].radius);
00489 }
00490 }
00491
00500 mRobotgl::mRobotgl(const Matrix & initrob, const Matrix & initrobm,
00501 const ColumnVector & position_) : mRobot(initrob, initrobm),
00502 Robotgl_basic()
00503 {
00504 std::vector<double> parameters;
00505 for(int i = 1; i < initrob.Nrows(); i++)
00506 {
00507 parameters.push_back(initrob(i,1));
00508 parameters.push_back(initrob(i,2));
00509 parameters.push_back(initrob(i,5));
00510 parameters.push_back(initrob(i+1,4));
00511 parameters.push_back(initrob(i,3));
00512 parameters.push_back(0.05);
00513 }
00514
00515 pos = ColumnVector(3); pos = 0;
00516 position = position_;
00517 message_object = "mRobotgl";
00518
00519 Robotgl_basic::set_dof(mRobot::dof);
00520
00521 std::vector<double> para;
00522 for(int j = 1; j <= mRobot::dof; j++)
00523 {
00524 para.clear();
00525 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00526 para.push_back(parameters[i]);
00527
00528 jointgl[j] = Jointgl(para, position);
00529 linkgl[j] = Linkgl(para, position, jointgl[j].radius);
00530 }
00531 }
00532
00541 mRobotgl::mRobotgl(const string & filename, const string & robotName,
00542 const ColumnVector & position_) : mRobot(filename, robotName),
00543 Robotgl_basic()
00544 {
00545
00546 Config robData(true);
00547 ifstream inconffile(filename.c_str(), std::ios::in);
00548 if (robData.read_conf(inconffile))
00549 {
00550 cerr << "mRobotgl::mRobotgl: unable to read input config file." << endl;
00551 }
00552
00553 bool Stl;
00554 string robotName_link_stl, stl_file;
00555
00556 robData.select(robotName, "Stl", Stl);
00557
00558 std::vector<double> parameters;
00559 for(int i = 1; i <= mRobot::dof; i++)
00560 {
00561 parameters.push_back(links[i].get_joint_type());
00562 parameters.push_back(links[i].get_theta());
00563 parameters.push_back(links[i].get_alpha());
00564 parameters.push_back(links[i+1].get_a());
00565 parameters.push_back(links[i].get_d());
00566 parameters.push_back(0.05);
00567 }
00568
00569 pos = ColumnVector(3); pos = 0;
00570 position = position_;
00571 message_object = "mRobotgl";
00572
00573 Robotgl_basic::set_dof(mRobot::dof);
00574
00575 double trans_x, trans_y, trans_z, rot_x, rot_y, rot_z, scal_x, scal_y, scal_z;
00576 float red, green, blue;
00577 std::vector<double> para;
00578 for(int j = 1; j <= mRobot::dof; j++)
00579 {
00580 para.clear();
00581 for(int i = (j-1)*NbParametresPerLink; i < j*NbParametresPerLink; i++)
00582 para.push_back(parameters[i]);
00583
00584 if(Stl)
00585 {
00586 ostringstream ostr;
00587 ostr << robotName << "_LINK" << j << "_STL";
00588 robotName_link_stl = ostr.str();
00589 robData.select(robotName_link_stl, "joint_file", stl_file);
00590 robData.select(robotName_link_stl, "joint_translation_x", trans_x);
00591 robData.select(robotName_link_stl, "joint_translation_y", trans_y);
00592 robData.select(robotName_link_stl, "joint_translation_z", trans_z);
00593 robData.select(robotName_link_stl, "joint_rotation_x", rot_x);
00594 robData.select(robotName_link_stl, "joint_rotation_y", rot_y);
00595 robData.select(robotName_link_stl, "joint_rotation_z", rot_z);
00596 robData.select(robotName_link_stl, "joint_scaling_factor_x", scal_x);
00597 robData.select(robotName_link_stl, "joint_scaling_factor_y", scal_y);
00598 robData.select(robotName_link_stl, "joint_scaling_factor_z", scal_z);
00599 robData.select(robotName_link_stl, "joint_rgb_red", red);
00600 robData.select(robotName_link_stl, "joint_rgb_green", green);
00601 robData.select(robotName_link_stl, "joint_rgb_blue", blue);
00602
00603 jointgl[j] = Jointgl(para, position, false, trans_x, trans_y, trans_z, rot_x,
00604 rot_y, rot_z, scal_x, scal_y, scal_z, red,
00605 green, blue, stl_file);
00606
00607 robData.select(robotName_link_stl, "link_file", stl_file);
00608 robData.select(robotName_link_stl, "link_translation_x", trans_x);
00609 robData.select(robotName_link_stl, "link_translation_y", trans_y);
00610 robData.select(robotName_link_stl, "link_translation_z", trans_z);
00611 robData.select(robotName_link_stl, "link_rotation_x", rot_x);
00612 robData.select(robotName_link_stl, "link_rotation_y", rot_y);
00613 robData.select(robotName_link_stl, "link_rotation_z", rot_z);
00614 robData.select(robotName_link_stl, "link_scaling_factor_x", scal_x);
00615 robData.select(robotName_link_stl, "link_scaling_factor_y", scal_y);
00616 robData.select(robotName_link_stl, "link_scaling_factor_z", scal_z);
00617 robData.select(robotName_link_stl, "link_rgb_red", red);
00618 robData.select(robotName_link_stl, "link_rgb_green", green);
00619 robData.select(robotName_link_stl, "link_rgb_blue", blue);
00620
00621 linkgl[j] = Linkgl(para, position, jointgl[j].radius, false, trans_x, trans_y,
00622 trans_z, rot_x, rot_y, rot_z, scal_x, scal_y, scal_z,
00623 red, green, blue, stl_file);
00624 }
00625 else
00626 {
00627 jointgl[j] = Jointgl(para, position);
00628 linkgl[j] = Linkgl(para, position, jointgl[j].radius);
00629 }
00630 }
00631 }
00632
00637 mRobotgl::mRobotgl(const mRobotgl & x): mRobot(x), Robotgl_basic(x)
00638 {
00639 }
00640
00641
00642 mRobotgl & mRobotgl::operator=(const mRobotgl & x)
00644 {
00645 mRobot::operator=(x);
00646 Robotgl_basic::operator=(x);
00647
00648 return (*this);
00649 }
00650
00651
00652 void mRobotgl::draw()
00654 {
00655 pos = 0;
00656
00657 glPushMatrix();
00658 int i;
00659 ColumnVector tmpColVec(3);
00660 for(i = 1; i <= Robotgl_basic::dof; i++)
00661 {
00662 GLfloat transformation [] =
00663 {links[i].R(1,1), links[i].R(2,1), links[i].R(3,1), 0,
00664 links[i].R(1,2), links[i].R(2,2), links[i].R(3,2), 0,
00665 links[i].R(1,3), links[i].R(2,3), links[i].R(3,3), 0,
00666 0, 0, 0, 1};
00667
00668 glTranslatef(pos(1), pos(2), pos(3));
00669 glMultMatrixf(transformation);
00670
00671 jointgl[i].draw();
00672 linkgl[i].draw();
00673
00674 tmpColVec = links[i].get_p();
00675 pos(1) = 0.0;
00676 pos(2) = tmpColVec(2);
00677 pos(3) = tmpColVec(3);
00678
00679 pos = links[i].R.t()*pos;
00680
00681 if( (i < mRobot::dof) || fix )
00682 tmpColVec = links[i+1].get_p();
00683 pos(1) = tmpColVec(1);
00684 }
00685
00686 glTranslatef(0.0,0.0,links[i-1].get_d());
00687 axis->draw();
00688
00689 glPopMatrix();
00690 }
00691
00696 Linkgl::Linkgl(bool DH_): Basic_object(), STL_obj(), DH(DH_)
00697 {
00698 STL = false;
00699 }
00700
00715 Linkgl::Linkgl(const std::vector<double> & parameters, const ColumnVector & pos,
00716 double jnt_radius, const bool DH_,
00717 const double stl_translation_x, const double stl_translation_y,
00718 const double stl_translation_z, const double stl_rotation_x,
00719 const double stl_rotation_y, const double stl_rotation_z,
00720 const double stl_scalling_x, const double stl_scalling_y,
00721 const double stl_scalling_z, const float rgb_red,
00722 const float rgb_green, const float rgb_blue, const string stl_file):
00723 Basic_object(), STL_obj(stl_file, stl_translation_x, stl_translation_y,
00724 stl_translation_z, stl_rotation_x, stl_rotation_y,
00725 stl_rotation_z, stl_scalling_x, stl_scalling_y,
00726 stl_scalling_z, rgb_red, rgb_green, rgb_blue)
00727 {
00728 DH = DH_;
00729 STL = stl_file != "" ? true : false;
00730
00731 if (parameters.size() >= NbParametresPerLink)
00732 {
00733 alpha = parameters[2];
00734 a = parameters[3];
00735 d = parameters[4];
00736 radius = parameters[5];
00737 message_object = "Linkgl";
00738 }
00739 else
00740 error("Linkgl constructor, parameters of wrong size");
00741 }
00742
00747 Linkgl::Linkgl(const Linkgl & x): Basic_object(x), STL_obj(x)
00748 {
00749 alpha = x.alpha;
00750 a = x.a;
00751 d = x.d;
00752 radius = x.radius;
00753 DH = x.DH;
00754 STL = x.STL;
00755 }
00756
00757 Linkgl::~Linkgl()
00759 {
00760 glDeleteLists(listName, 1);
00761 }
00762
00763 Linkgl & Linkgl::operator=(const Linkgl & x)
00765 {
00766 alpha = x.alpha;
00767 a = x.a;
00768 d = x.d;
00769 radius = x.radius;
00770 DH = x.DH;
00771 STL = x.STL;
00772 Basic_object::operator=(x);
00773 STL_obj::operator=(x);
00774
00775 return (*this);
00776 }
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 void Linkgl::create_list()
00801 {
00802
00803 if (STL)
00804 {
00805 listName = load_STL_TextFile();
00806 }
00807 else
00808 {
00809 Cylinder cylinder;
00810 listName = glGenLists(1);
00811
00812 if (listName)
00813 {
00814 glNewList(listName, GL_COMPILE);
00815
00816 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, rgb_blue_gray);
00817 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, rgb_blue_gray);
00818
00819 if(DH)
00820 {
00821 if(a)
00822 {
00823 glPushMatrix();
00824 glRotatef(90.0, 0.0, 1.0, 0.0);
00825 cylinder.draw(radius,a);
00826 glPopMatrix();
00827 }
00828 if(d)
00829 {
00830 glPushMatrix();
00831 glTranslatef(a, 0.0, 0);
00832 glRotatef(-rad2deg(alpha), 1.0, 0.0, 0.0);
00833 if (d < 0)
00834 glRotatef(180, 1.0, 0.0, 0.0);
00835 cylinder.draw(radius, fabs(d));
00836 glPopMatrix();
00837 }
00838 if(a && d)
00839 {
00840 glPushMatrix();
00841 glTranslatef(a, 0.0, 0);
00842 glRotatef(90.0, 0.0, 1.0, 0.0);
00843 cylinder.draw(radius, radius);
00844 glPopMatrix();
00845 }
00846 }
00847 else
00848 {
00849 if(a)
00850 {
00851 glPushMatrix();
00852 glRotatef(90.0, 0.0, 1.0, 0.0);
00853 cylinder.draw(radius, a);
00854 glPopMatrix();
00855 }
00856 if(d)
00857 {
00858 glPushMatrix();
00859 glTranslatef(a, 0.0, 0);
00860 if (d < 0)
00861 glRotatef(180, 1.0, 0.0, 0.0);
00862 cylinder.draw(radius, fabs(d));
00863 glPopMatrix();
00864 }
00865 if(a && d)
00866 {
00867 glPushMatrix();
00868 glTranslatef(a, 0.0, 0);
00869 glRotatef(90.0, 0.0, 1.0, 0.0);
00870 cylinder.draw(radius, radius);
00871 glPopMatrix();
00872 }
00873 }
00874 glEndList();
00875 }
00876 else
00877 error("Unable to create list for linkgl.");
00878 }
00879 }
00880
00885 Jointgl::Jointgl(bool DH_) : Basic_object(), STL_obj()
00886 {
00887 DH = DH_;
00888 STL = false;
00889 }
00890
00901 Jointgl::Jointgl(const std::vector<double> & parameters, const ColumnVector & pos,
00902 const bool DH_, const double stl_translation_x,
00903 const double stl_translation_y, const double stl_translation_z,
00904 const double stl_rotation_x, const double stl_rotation_y,
00905 const double stl_rotation_z, const double stl_scalling_x,
00906 const double stl_scalling_y, const double stl_scalling_z,
00907 const float rgb_red, const float rgb_green, const float rgb_blue,
00908 const string stl_file):
00909 Basic_object(), STL_obj(stl_file, stl_translation_x, stl_translation_y,
00910 stl_translation_z, stl_rotation_x, stl_rotation_y,
00911 stl_rotation_z, stl_scalling_x, stl_scalling_y,
00912 stl_scalling_z, rgb_red, rgb_green, rgb_blue)
00913 {
00914 DH = DH_;
00915 STL = (stl_file != "" ? true : false);
00916 prismatic = (short)parameters[0];
00917 radius = parameters[5]*1.4;
00918 hight = 2.5*radius;
00919 message_object = "Jointgl";
00920 }
00921
00926 Jointgl::Jointgl(const Jointgl & x): Basic_object(x), STL_obj(x)
00927 {
00928 prismatic = x.prismatic;
00929 radius = x.radius;
00930 hight = x.hight;
00931 DH = x.DH;
00932 STL = x.STL;
00933 }
00934
00935 Jointgl::~Jointgl()
00937 {
00938 glDeleteLists(listName, 1);
00939 }
00940
00941 Jointgl & Jointgl::operator=(const Jointgl & x)
00943 {
00944 prismatic = x.prismatic;
00945 radius = x.radius;
00946 hight = x.hight;
00947 DH = x.DH;
00948 STL = x.STL;
00949 Basic_object::operator=(x);
00950 STL_obj::operator=(x);
00951
00952 return (*this);
00953 }
00954
00955 void Jointgl::create_list()
00962 {
00963 if (STL)
00964 {
00965 listName = load_STL_TextFile();
00966 }
00967 else
00968 {
00969 Cylinder cylinder;
00970 listName = glGenLists(1);
00971
00972 if (listName)
00973 {
00974 glNewList(listName, GL_COMPILE);
00975
00976 glPushMatrix();
00977
00978 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, rgb_blue_gray);
00979 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, rgb_blue_gray);
00980
00981 if(DH)
00982 {
00983 glRotatef(180,1,0,0);
00984 glTranslatef(0, 0, -radius*1.5);
00985 cylinder.draw(radius, hight);
00986 }
00987 else
00988 {
00989 glTranslatef(0, 0, -radius*1.5);
00990 cylinder.draw(radius, hight);
00991 }
00992
00993 glPopMatrix();
00994
00995 glEndList();
00996 }
00997 else
00998 error("Unable to create list for joint.");
00999 }
01000 }