Show
Ignore:
Timestamp:
10/29/08 11:12:02 (6 years ago)
Author:
robert
Message:

From James Moliere, fixed display of axis

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgrobot/osgrobot.cpp

    r9031 r9071  
    225225    osg::Geode* joint = new osg::Geode(); 
    226226    xTransform->addChild(joint); 
    227  
    228     //The cylinder's barycenter is the point of rotation. 
    229     //For this project, the x and y axis of rotation needs to be at the start of the cylinder and the 
    230     //axis of rotation about the z axis needs to be at the center of the cylinder. 
    231     //  this is where height/2 is used -- to offset x and y axis barycenter. 
    232     // note: we did not use -height/2 
    233227    joint->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f,0.0f,height/2),radius,height),hints)); 
    234228 
     
    297291    osg::Matrix xRot = osg::Matrix::rotate(-osg::PI_2, 1.0, 0.0, 0.0); 
    298292    xTransform->setMatrix(xRot); 
    299     if (showAxis) 
    300     { 
    301         createAxis(xTransform); 
    302     } 
     293 
    303294 
    304295    osg::MatrixTransform* zCheat = new osg::MatrixTransform(); 
     
    306297    zCheat->setMatrix(zTransCheat); 
    307298    xTransform->addChild(zCheat); 
    308  
     299     
    309300    osg::ShapeDrawable *shape = new osg::ShapeDrawable(new osg::Capsule(osg::Vec3(0.0f,0.0f,height/2),radius,height),hints); 
    310301    joint->addDrawable(shape); 
     
    316307    osg::Matrix zTrans = osg::Matrix::translate(0,0,0); 
    317308    zTransform->setMatrix(zTrans*zRot); 
    318     return zTransform; 
    319 } 
    320  
     309    if (showAxis) 
     310    { 
     311        createAxis(zTransform); 
     312    } 
     313    return zTransform; 
     314} 
    321315osg::MatrixTransform* buildJoint4(osg::MatrixTransform* previousJoint) 
    322316{ 
     
    326320    tube4->addDrawable(new osg::ShapeDrawable(new osg::Capsule(osg::Vec3(0.0f,0.0f,height/2),radius,height),hints)); 
    327321    osg::MatrixTransform* xTransform = new osg::MatrixTransform(); 
    328     if (showAxis) 
    329     { 
    330         createAxis(xTransform); 
    331     } 
     322    //if (showAxis) 
     323    //{ 
     324        //createAxis(xTransform); 
     325    //} 
    332326    previousJoint->addChild(xTransform); 
    333327    xTransform->addChild(tube4); 
     
    344338} 
    345339 
     340 
    346341osg::MatrixTransform* buildTube5(osg::MatrixTransform* previousJoint) 
    347342{ 
     343    if (showAxis) 
     344    { 
     345        createAxis(previousJoint); 
     346    } 
    348347    double height = 7.5; 
    349348    double radius = 2.86479; 
     
    427426void createAxis(osg::Transform* previousJoint) 
    428427{ 
    429     double height = 10.0; 
     428    double height = 12.0; 
    430429    double radius = .5; 
    431430 
     
    453452    previousJoint->addChild(mt); 
    454453 
    455     osg::Matrix xMatrix = osg::Matrix::rotate(-osg::PI_2, 0.0, 1.0, 0.0); 
     454    osg::Matrix xMatrix = osg::Matrix::rotate(-M_PI_2, 0.0, 1.0, 0.0); 
    456455    mt->setMatrix(xMatrix); 
    457456 
     
    466465    osg::MatrixTransform *yMt = new osg::MatrixTransform(); 
    467466    previousJoint->addChild(yMt); 
    468     osg::Matrix yMatrix = osg::Matrix::rotate(osg::PI_2, 1.0, 0.0, 0.0); 
     467    osg::Matrix yMatrix = osg::Matrix::rotate(M_PI_2, 1.0, 0.0, 0.0); 
    469468    yMt->setMatrix(yMatrix); 
    470469 
     
    479478{ 
    480479    hints->setDetailRatio(0.5f); 
    481     showAxis = false; 
     480    showAxis = true; 
    482481    jointAngle1=0.0; 
    483482    jointAngle2=0.0; 
     
    487486    jointAngle6=0.0; 
    488487    EndEffector=1.0; 
    489  
    490488    osgViewer::Viewer viewer; 
    491489    viewer.addEventHandler(new KeyboardEventHandler());