VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyOsgUtil.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************
28  **
29  *t diguyOsgUtil
30  **
31  *b Summary:
32  **
33  ** The diguyOsgUtil class provides some useful functions
34  ** for implementing DI-Guy Author objects.
35  */
36 
37 #pragma once
38 
39 #include <osg/Geometry>
40 #include <osg/Object>
41 #include <osg/StateSet>
42 
43 #include <diguy_constants.h>
44 #include <diguy_vector_classes.h>
45 #include <diguyAuthorVisualMaterial.h>
46 
47 class diguyAuthorInterface;
48 
49 
50 /****************************************************************************/
52 {
53 
54 public:
55 
56  /*
57  * Mask flags.
58  */
59  enum
60  {
61  MASK_TERRAIN = 0x1,
64  };
65 
66  /*
67  * Convenience functions for unref-ing a node. The functions below
68  * remove the child from all parents, and then set the ref_ptr to NULL.
69  * In many cases this will bring the ref count to 0 and delete the
70  * child.
71  */
72  static void detachAndNull(osg::ref_ptr<osg::MatrixTransform>& child);
73  static void detachAndNull(osg::ref_ptr<osg::Group>& child);
74  static void detachAndNull(osg::ref_ptr<osg::Geode>& child);
75  static void detachAndNull(osg::Geode* geode, osg::ref_ptr<osg::Geometry>& drawable);
76 
77  static void dumpStateSet( osg::StateSet * stateSet, const char * indent );
78 
79  /*
80  * Drawable creation functions.
81  */
82  static osg::Geometry* create_sphere_solid(float radius,
83  int slices,
84  int layers,
85  const diguyVec4f & color);
86 
87  static osg::Geometry* create_sphere_wireframe(float radius,
88  int slices,
89  int layers,
90  const diguyVec4f & color,
91  float line_width,
92  bool lit);
93 
94  static osg::Geometry* create_cone_solid(float radius,
95  float height,
96  int slices,
97  int layers,
98  const diguyVec3f & position_offset,
99  const diguyVec3f & orientation,
100  const diguyVec4f & color);
101 
102  static osg::Geometry* create_cone_wireframe(float radius,
103  float height,
104  int slices,
105  int layers,
106  const diguyVec3f & position_offset,
107  const diguyVec3f & orientation,
108  const diguyVec4f & color,
109  float line_width,
110  bool lit);
111 
112  static osg::Geometry* create_cylinder_solid(float radius,
113  float height,
114  int slices,
115  int layers,
116  const diguyVec3f & position_offset,
117  const diguyVec3f & orientation,
118  const diguyVec4f & color);
119 
120  static osg::Geometry* create_cylinder_wireframe(float radius,
121  float height,
122  int slices,
123  int layers,
124  const diguyVec3f & position_offset,
125  const diguyVec3f & orientation,
126  const diguyVec4f & color,
127  float line_width,
128  bool lit);
129 
130  static osg::Geometry* create_box_solid(const diguyVec3f & min,
131  const diguyVec3f & max,
132  const diguyVec3f & position_offset,
133  const diguyVec3f & orientation,
134  const diguyVec4f & color);
135 
136  static osg::Geometry* create_box_wireframe(const diguyVec3f & min,
137  const diguyVec3f & max,
138  const diguyVec3f & position_offset,
139  const diguyVec3f & orientation,
140  const diguyVec4f & color,
141  float line_width,
142  bool lit);
143 
144  static osg::Geometry * create_line_primitive( const osg::Vec4 & color );
145  static osg::Geometry * create_coord_sys_primitive();
146 
147  static void set_name_from_uid(osg::Object* object, long uid);
148 
149  /*
150  * Material functions.
151  */
152  static osg::StateSet* create_material_state_set(const diguyVec4f & color, bool lit);
153  static osg::StateSet* create_material_state_set(diguyAuthorVisualMaterial* visual_material);
154 
155  /*
156  * Vector conversion functions.
157  */
158  static osg::Vec3 diguyVec3_to_osgVec3(const diguyVec3f & diguy_vec3);
159  static osg::Vec4 diguyVec4_to_osgVec4(const diguyVec4f & diguy_vec4);
160  static osg::Quat diguy_euler_zxy_radians_to_osgQuat(const diguyVec3f & diguy_euler);
161  static osg::Quat diguy_euler_zxy_degrees_to_osgQuat(const diguyVec3f & diguy_euler);
162  static osg::Matrixd yrp_to_matrix(double yaw, double roll, double pitch);
163 
164  static diguyVec3f osgVec3_to_diguyVec3(const osg::Vec3& osg_vec3);
165  static diguyVec4f osgVec4_to_diguyVec4(const osg::Vec4& osg_vec4);
166 
167 
168  /*
169  * ...
170  */
171  static bool check_visual_update_flag(int update_flags, diguyAuthorVisualUpdateFlag flag)
172  {
173  if ((update_flags & (int) flag) != 0)
174  return true;
175  return false;
176  }
177 
178  static bool check_visual_update_flag2(int update_flags,
179  diguyAuthorVisualUpdateFlag flag1,
180  diguyAuthorVisualUpdateFlag flag2)
181  {
182  if (((update_flags & (int) flag1) != 0) ||
183  ((update_flags & (int) flag2) != 0))
184  return true;
185  return false;
186  }
187 
188  static bool check_visual_update_flag3(int update_flags,
189  diguyAuthorVisualUpdateFlag flag1,
190  diguyAuthorVisualUpdateFlag flag2,
191  diguyAuthorVisualUpdateFlag flag3)
192  {
193  if (((update_flags & (int) flag1) != 0) ||
194  ((update_flags & (int) flag2) != 0) ||
195  ((update_flags & (int) flag3) != 0))
196  return true;
197  return false;
198  }
199 
200  static void raise_visual_update_flag(int& update_flags,
201  diguyAuthorVisualUpdateFlag flag)
202  {
203  update_flags |= (int) flag;
204  }
205 };
206 

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)