Grip-Reloaded
Grip version visualizaiton interface for DART (DynamicAnimationandRoboticsToolkits)
|
00001 /* 00002 * Copyright (c) 2014, Georgia Tech Research Corporation 00003 * All rights reserved. 00004 * 00005 * Author: Pete Vieira <pete.vieira@gatech.edu> 00006 * Date: Feb 2014 00007 * 00008 * Humanoid Robotics Lab Georgia Institute of Technology 00009 * Director: Mike Stilman http://www.golems.org 00010 * 00011 * 00012 * This file is provided under the following "BSD-style" License: 00013 * Redistribution and use in source and binary forms, with or 00014 * without modification, are permitted provided that the following 00015 * conditions are met: 00016 * 00017 * * Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * 00020 * * Redistributions in binary form must reproduce the above 00021 * copyright notice, this list of conditions and the following 00022 * disclaimer in the documentation and/or other materials provided 00023 * with the distribution. 00024 * 00025 * * Neither the name of the Humanoid Robotics Lab nor the names of 00026 * its contributors may be used to endorse or promote products 00027 * derived from this software without specific prior written 00028 * permission 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00031 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00032 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00033 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00034 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00035 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00036 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00037 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00038 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00039 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00040 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00041 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00042 * POSSIBILITY OF SUCH DAMAGE. 00043 */ 00044 00050 #ifndef AXES_H 00051 #define AXES_H 00052 00053 // OpenSceneGraph includes 00054 #include <osg/Geode> 00055 #include <osg/PositionAttitudeTransform> 00056 #include <osgViewer/Viewer> 00057 #include <osg/LineWidth> 00058 #include <osg/Matrix> 00059 #include <osg/MatrixTransform> 00060 00065 namespace osgGolems { 00066 00071 class Axes : public osg::Geometry 00072 { 00073 public: 00074 00079 inline Axes(float scale = 0.1) 00080 { 00081 _verts = new osg::Vec3Array(4); 00082 _colors = new osg::Vec4Array; 00083 _lineWidth = new osg::LineWidth; 00084 00085 this->_createAxes(); 00086 this->setScale(scale); 00087 this->setLineWidth(1.0f); 00088 } 00089 00095 inline void setScale(float newScale) 00096 { 00097 (*_verts)[0].set(0,0,0); // origin 00098 (*_verts)[1].set(newScale,0,0); // x-axis endpoint 00099 (*_verts)[2].set(0,newScale,0); // y-axis endpoint 00100 (*_verts)[3].set(0,0,newScale); // z-axis endpoint 00101 00102 // Move vertices to VertexBuffer 00103 this->setVertexArray(_verts); 00104 } 00105 00113 inline void setColors(const osg::Vec4& xAxis, const osg::Vec4& yAxis, const osg::Vec4& zAxis) 00114 { 00115 (*_colors)[0] = xAxis; 00116 (*_colors)[1] = yAxis; 00117 (*_colors)[2] = zAxis; 00118 this->setColorArray(_colors); 00119 } 00120 00126 inline void setLineWidth(float newLineWidth) 00127 { 00128 _lineWidth->setWidth(newLineWidth); 00129 this->getOrCreateStateSet()->setAttribute(_lineWidth); 00130 } 00131 00132 protected: 00133 00139 inline void _createAxes() 00140 { 00141 osg::DrawElementsUShort* x_elem = 00142 new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, 0); 00143 x_elem->push_back(0); x_elem->push_back(1); 00144 this->addPrimitiveSet(x_elem); 00145 _colors->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); 00146 00147 osg::DrawElementsUShort* y_elem = 00148 new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, 0); 00149 y_elem->push_back(0); y_elem->push_back(2); 00150 this->addPrimitiveSet(y_elem); 00151 _colors->push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f)); 00152 00153 osg::DrawElementsUShort* z_elem = 00154 new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, 0); 00155 z_elem->push_back(0); z_elem->push_back(3); 00156 this->addPrimitiveSet(z_elem); 00157 _colors->push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); 00158 00159 this->setColorArray(_colors); 00160 this->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); 00161 } 00162 00164 osg::Vec3Array* _verts; 00165 00167 osg::Vec4Array* _colors; 00168 00170 osg::LineWidth* _lineWidth; 00171 00172 }; // end class Axes 00173 00174 } // end namespace osgGolems 00175 00176 #endif // AXES_H