VR-Vantage
Loading...
Searching...
No Matches
diguyOsgUtil.h
Go to the documentation of this file.
1/****************************************************************************
2* Copyright (c) 2020 VT MAK
3* All rights reserved.
4* ***************************************************************************/
5
9
10
11#pragma once
12
13#include <osg/Geometry>
14#include <osg/Object>
15#include <osg/StateSet>
16
17#include <diguy_constants.h>
18#include <diguy_vector_classes.h>
19#include <diguyAuthorVisualMaterial.h>
20
21class diguyAuthorInterface;
22
23
24/****************************************************************************/
27{
28
29public:
30
31 /*
32 * Mask flags.
33 */
34 enum
35 {
39 };
40
41 /*
42 * Convenience functions for unref-ing a node. The functions below
43 * remove the child from all parents, and then set the ref_ptr to NULL.
44 * In many cases this will bring the ref count to 0 and delete the
45 * child.
46 */
47 static void detachAndNull(osg::ref_ptr<osg::MatrixTransform>& child);
48 static void detachAndNull(osg::ref_ptr<osg::Group>& child);
49 static void detachAndNull(osg::ref_ptr<osg::Geode>& child);
50 static void detachAndNull(osg::Geode* geode, osg::ref_ptr<osg::Geometry>& drawable);
51
52 static void dumpStateSet( osg::StateSet * stateSet, const char * indent );
53
54 /*
55 * Drawable creation functions.
56 */
57 static osg::Geometry* create_sphere_solid(float radius,
58 int slices,
59 int layers,
60 const diguyVec4f & color);
61
62 static osg::Geometry* create_sphere_wireframe(float radius,
63 int slices,
64 int layers,
65 const diguyVec4f & color,
66 float line_width,
67 bool lit);
68
69 static osg::Geometry* create_cone_solid(float radius,
70 float height,
71 int slices,
72 int layers,
73 const diguyVec3f & position_offset,
74 const diguyVec3f & orientation,
75 const diguyVec4f & color);
76
77 static osg::Geometry* create_cone_wireframe(float radius,
78 float height,
79 int slices,
80 int layers,
81 const diguyVec3f & position_offset,
82 const diguyVec3f & orientation,
83 const diguyVec4f & color,
84 float line_width,
85 bool lit);
86
87 static osg::Geometry* create_cylinder_solid(float radius,
88 float height,
89 int slices,
90 int layers,
91 const diguyVec3f & position_offset,
92 const diguyVec3f & orientation,
93 const diguyVec4f & color);
94
95 static osg::Geometry* create_cylinder_wireframe(float radius,
96 float height,
97 int slices,
98 int layers,
99 const diguyVec3f & position_offset,
100 const diguyVec3f & orientation,
101 const diguyVec4f & color,
102 float line_width,
103 bool lit);
104
105 static osg::Geometry* create_box_solid(const diguyVec3f & min,
106 const diguyVec3f & max,
107 const diguyVec3f & position_offset,
108 const diguyVec3f & orientation,
109 const diguyVec4f & color);
110
111 static osg::Geometry* create_box_wireframe(const diguyVec3f & min,
112 const diguyVec3f & max,
113 const diguyVec3f & position_offset,
114 const diguyVec3f & orientation,
115 const diguyVec4f & color,
116 float line_width,
117 bool lit);
118
119 static osg::Geometry * create_line_primitive( const osg::Vec4 & color );
120 static osg::Geometry * create_coord_sys_primitive();
121
122 static void set_name_from_uid(osg::Object* object, long uid);
123
124 /*
125 * Material functions.
126 */
127 static osg::StateSet* create_material_state_set(const diguyVec4f & color, bool lit);
128 static osg::StateSet* create_material_state_set(diguyAuthorVisualMaterial* visual_material);
129
130 /*
131 * Vector conversion functions.
132 */
133 static osg::Vec3 diguyVec3_to_osgVec3(const diguyVec3f & diguy_vec3);
134 static osg::Vec4 diguyVec4_to_osgVec4(const diguyVec4f & diguy_vec4);
135 static osg::Quat diguy_euler_zxy_radians_to_osgQuat(const diguyVec3f & diguy_euler);
136 static osg::Quat diguy_euler_zxy_degrees_to_osgQuat(const diguyVec3f & diguy_euler);
137 static osg::Matrixd yrp_to_matrix(double yaw, double roll, double pitch);
138
139 static diguyVec3f osgVec3_to_diguyVec3(const osg::Vec3& osg_vec3);
140 static diguyVec4f osgVec4_to_diguyVec4(const osg::Vec4& osg_vec4);
141
142
143 /*
144 * ...
145 */
146 static bool check_visual_update_flag(int update_flags, diguyAuthorVisualUpdateFlag flag)
147 {
148 if ((update_flags & (int) flag) != 0)
149 return true;
150 return false;
151 }
152
153 static bool check_visual_update_flag2(int update_flags,
154 diguyAuthorVisualUpdateFlag flag1,
155 diguyAuthorVisualUpdateFlag flag2)
156 {
157 if (((update_flags & (int) flag1) != 0) ||
158 ((update_flags & (int) flag2) != 0))
159 return true;
160 return false;
161 }
162
163 static bool check_visual_update_flag3(int update_flags,
164 diguyAuthorVisualUpdateFlag flag1,
165 diguyAuthorVisualUpdateFlag flag2,
166 diguyAuthorVisualUpdateFlag flag3)
167 {
168 if (((update_flags & (int) flag1) != 0) ||
169 ((update_flags & (int) flag2) != 0) ||
170 ((update_flags & (int) flag3) != 0))
171 return true;
172 return false;
173 }
174
175 static void raise_visual_update_flag(int& update_flags,
176 diguyAuthorVisualUpdateFlag flag)
177 {
178 update_flags |= (int) flag;
179 }
180};
181
Contains some helper functions for diguy and osg .
Definition diguyOsgUtil.h:27
static osg::Geometry * create_line_primitive(const osg::Vec4 &color)
static osg::Geometry * create_cylinder_wireframe(float radius, float height, int slices, int layers, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color, float line_width, bool lit)
static void detachAndNull(osg::ref_ptr< osg::Geode > &child)
static osg::StateSet * create_material_state_set(const diguyVec4f &color, bool lit)
static osg::Geometry * create_box_solid(const diguyVec3f &min, const diguyVec3f &max, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color)
static diguyVec3f osgVec3_to_diguyVec3(const osg::Vec3 &osg_vec3)
static void detachAndNull(osg::ref_ptr< osg::MatrixTransform > &child)
static osg::StateSet * create_material_state_set(diguyAuthorVisualMaterial *visual_material)
static osg::Geometry * create_sphere_solid(float radius, int slices, int layers, const diguyVec4f &color)
static osg::Geometry * create_cone_wireframe(float radius, float height, int slices, int layers, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color, float line_width, bool lit)
static osg::Quat diguy_euler_zxy_degrees_to_osgQuat(const diguyVec3f &diguy_euler)
static osg::Quat diguy_euler_zxy_radians_to_osgQuat(const diguyVec3f &diguy_euler)
@ MASK_CHARACTER
Definition diguyOsgUtil.h:37
@ MASK_GRAPHICS_VISUALS
Definition diguyOsgUtil.h:38
@ MASK_TERRAIN
Definition diguyOsgUtil.h:36
static void detachAndNull(osg::Geode *geode, osg::ref_ptr< osg::Geometry > &drawable)
static osg::Vec3 diguyVec3_to_osgVec3(const diguyVec3f &diguy_vec3)
static void set_name_from_uid(osg::Object *object, long uid)
static osg::Matrixd yrp_to_matrix(double yaw, double roll, double pitch)
static osg::Geometry * create_cylinder_solid(float radius, float height, int slices, int layers, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color)
static osg::Geometry * create_box_wireframe(const diguyVec3f &min, const diguyVec3f &max, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color, float line_width, bool lit)
static osg::Vec4 diguyVec4_to_osgVec4(const diguyVec4f &diguy_vec4)
static osg::Geometry * create_sphere_wireframe(float radius, int slices, int layers, const diguyVec4f &color, float line_width, bool lit)
static diguyVec4f osgVec4_to_diguyVec4(const osg::Vec4 &osg_vec4)
static void detachAndNull(osg::ref_ptr< osg::Group > &child)
static osg::Geometry * create_coord_sys_primitive()
static osg::Geometry * create_cone_solid(float radius, float height, int slices, int layers, const diguyVec3f &position_offset, const diguyVec3f &orientation, const diguyVec4f &color)
static bool check_visual_update_flag2(int update_flags, diguyAuthorVisualUpdateFlag flag1, diguyAuthorVisualUpdateFlag flag2)
Definition diguyOsgUtil.h:153
static void raise_visual_update_flag(int &update_flags, diguyAuthorVisualUpdateFlag flag)
Definition diguyOsgUtil.h:175
static void dumpStateSet(osg::StateSet *stateSet, const char *indent)
static bool check_visual_update_flag3(int update_flags, diguyAuthorVisualUpdateFlag flag1, diguyAuthorVisualUpdateFlag flag2, diguyAuthorVisualUpdateFlag flag3)
Definition diguyOsgUtil.h:163
static bool check_visual_update_flag(int update_flags, diguyAuthorVisualUpdateFlag flag)
Definition diguyOsgUtil.h:146