VR-Vantage API Documentation
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  /*
78  * Drawable creation functions.
79  */
80  static osg::Geometry* create_sphere_solid(float radius,
81  int slices,
82  int layers,
83  const diguyVec4f & color);
84 
85  static osg::Geometry* create_sphere_wireframe(float radius,
86  int slices,
87  int layers,
88  const diguyVec4f & color,
89  float line_width,
90  bool lit);
91 
92  static osg::Geometry* create_cone_solid(float radius,
93  float height,
94  int slices,
95  int layers,
96  const diguyVec3f & position_offset,
97  const diguyVec3f & orientation,
98  const diguyVec4f & color);
99 
100  static osg::Geometry* create_cone_wireframe(float radius,
101  float height,
102  int slices,
103  int layers,
104  const diguyVec3f & position_offset,
105  const diguyVec3f & orientation,
106  const diguyVec4f & color,
107  float line_width,
108  bool lit);
109 
110  static osg::Geometry* create_cylinder_solid(float radius,
111  float height,
112  int slices,
113  int layers,
114  const diguyVec3f & position_offset,
115  const diguyVec3f & orientation,
116  const diguyVec4f & color);
117 
118  static osg::Geometry* create_cylinder_wireframe(float radius,
119  float height,
120  int slices,
121  int layers,
122  const diguyVec3f & position_offset,
123  const diguyVec3f & orientation,
124  const diguyVec4f & color,
125  float line_width,
126  bool lit);
127 
128  static osg::Geometry* create_box_solid(const diguyVec3f & min,
129  const diguyVec3f & max,
130  const diguyVec3f & position_offset,
131  const diguyVec3f & orientation,
132  const diguyVec4f & color);
133 
134  static osg::Geometry* create_box_wireframe(const diguyVec3f & min,
135  const diguyVec3f & max,
136  const diguyVec3f & position_offset,
137  const diguyVec3f & orientation,
138  const diguyVec4f & color,
139  float line_width,
140  bool lit);
141 
142  static void set_name_from_uid(osg::Object* object, long uid);
143 
144  /*
145  * Material functions.
146  */
147  static osg::StateSet* create_material_state_set(const diguyVec4f & color, bool lit);
148  static osg::StateSet* create_material_state_set(diguyAuthorVisualMaterial* visual_material);
149 
150  /*
151  * Vector conversion functions.
152  */
153  static osg::Vec3 diguyVec3_to_osgVec3(const diguyVec3f & diguy_vec3);
154  static osg::Vec4 diguyVec4_to_osgVec4(const diguyVec4f & diguy_vec4);
155  static osg::Quat diguy_euler_zxy_radians_to_osgQuat(const diguyVec3f & diguy_euler);
156  static osg::Quat diguy_euler_zxy_degrees_to_osgQuat(const diguyVec3f & diguy_euler);
157 
158  static diguyVec3f osgVec3_to_diguyVec3(const osg::Vec3& osg_vec3);
159  static diguyVec4f osgVec4_to_diguyVec4(const osg::Vec4& osg_vec4);
160 
161  /*
162  * ...
163  */
164  static bool check_visual_update_flag(int update_flags, diguyAuthorVisualUpdateFlag flag)
165  {
166  if ((update_flags & (int) flag) != 0)
167  return true;
168  return false;
169  }
170 
171  static bool check_visual_update_flag2(int update_flags,
172  diguyAuthorVisualUpdateFlag flag1,
173  diguyAuthorVisualUpdateFlag flag2)
174  {
175  if (((update_flags & (int) flag1) != 0) ||
176  ((update_flags & (int) flag2) != 0))
177  return true;
178  return false;
179  }
180 
181  static bool check_visual_update_flag3(int update_flags,
182  diguyAuthorVisualUpdateFlag flag1,
183  diguyAuthorVisualUpdateFlag flag2,
184  diguyAuthorVisualUpdateFlag flag3)
185  {
186  if (((update_flags & (int) flag1) != 0) ||
187  ((update_flags & (int) flag2) != 0) ||
188  ((update_flags & (int) flag3) != 0))
189  return true;
190  return false;
191  }
192 
193  static void raise_visual_update_flag(int& update_flags,
194  diguyAuthorVisualUpdateFlag flag)
195  {
196  update_flags |= (int) flag;
197  }
198 };
199 


Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)