NDEVR
API Documentation
RotationBounds.h
1#pragma once
2#include <NDEVR/Model.h>
3#include <NDEVR/ShapeConstructors.h>
4#include <NDEVR/Effect.h>
5#include <NDEVR/Geometry.h>
6#include <NDEVR/Material.h>
7#include <NDEVR/Scene.h>
8#include <NDEVR/Translator.h>
9#if NDEVR_GRIPS
10namespace NDEVR
11{
21 class RotationBounds : public Model
22 {
23 public:
34 RotationBounds(const Model& model)
35 : Model(model)
36 {
37 if (!is<NDPN::type>(TypeName()))
38 {
39 setChildApplicationConstructed();
40 m_vertical_rotation_grip = createChild();
41 m_horizontal_rotation_grip = createChild();
42 set<NDPN::type>(TypeName());
43 set<NDPO::tree_visible>(false);
44 set<NDPO::is_application_owned>(true);
45 set<NDPO::application_locked>(true);
46 set<NDPN::can_select_children>(true);
47 Effect effect = createChildEffect();
48 effect.setupAsBoundingBox(*this);
49 setupRotationGrips(m_vertical_rotation_grip, 0);
50 setupRotationGrips(m_horizontal_rotation_grip, 1);
51 }
52 else
53 {
54 m_vertical_rotation_grip = getChild(0);
55 m_horizontal_rotation_grip = getChild(1);
56 }
57 }
58
68 void attachTo(const Model& model)
69 {
70 Effect effect = getEffect();
71 if (effect.targetCount() < 2 || effect.getTarget(1) != model)
72 effect.setupAsBoundingBox(*this, model);
73 else
74 effect.activate();
75 }
76
91 void setupRotationGrips(Model& grip, uint01 index)
92 {
93 grip.set<NDPOC::name>(_t("Rotate"));
94 grip.set<NDPN::type>("rotation_grip");
95 grip.set<NDPN::can_select_children>(true);
96 Scene scene(grip.getScene());
97 Geometry circle = ShapeConstructors::StaticCircleOutline(scene);
98 Matrix<fltp08> matrix = Matrix<fltp08>::RotationMatrix(Angle<fltp08>(DEGREES, 90.0), IndexTangent(index));
99 grip.set<NDPO::transform>(matrix);
100 grip.setGeometryChild(circle);
101 grip.set<NDPO::bounds_ignored>(true);
102 BitFlag flag(0);
103 //flag(ParentMatrixFlags::e_scale_to_camera, true);
104 flag(ParentMatrixFlags::e_ignore_scale_distortion, true);
105 grip.setParentMatrixFlags(flag);
106 grip.update<NDPO::spacial_visible>(false);
107 grip.updateModifiedTime();
108
109 Material material = grip.createChildMaterial();
110 material.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
111 switch (index)
112 {
113 case X: material.setUVColor(UVType::e_KD, RGBColor(255, 0, 0)); break;
114 case Y: material.setUVColor(UVType::e_KD, RGBColor(0, 255, 0)); break;
115 case Z: material.setUVColor(UVType::e_KD, RGBColor(0, 0, 255)); break;
116 }
117
118 material.set<NDPM::shading_model>(Material::ShadingModel::e_flat);
119 material.set<NDPM::override_camera_material>(true);
120 material.set<NDPM::wireframe>(true);
121 material.set<NDPM::pixel_thickness>(10.0);
122 material.set<NDPO::tree_visible>(false);
123 material.updateModifiedTime();
124 grip.updateModifiedTime();
125 }
126
131 static constexpr StringView TypeName()
132 {
133 return "rotation_bounds_model";
134 }
135
142 static Ray<3, fltp08> IndexNormal(uint04 index)
143 {
144 switch (index)
145 {
146 case 0: return Ray<3, fltp08>(1.0, 0.0, 0.0);
147 case 1: return Ray<3, fltp08>(0.0, 1.0, 0.0);
148 default:
149 lib_assert(false, "Bad index normal");
150 return Ray<3, fltp08>(0, 0, 1);
151 }
152 }
153
164 static Ray<3, fltp08> IndexTangent(uint04 index)
165 {
166 switch (index)
167 {
168 case 0: return Ray<3, fltp08>(0.0, 1.0, 0.0);
169 case 1: return Ray<3, fltp08>(1.0, 0.0, 0.0);
170 default:
171 lib_assert(false, "Bad index normal");
172 return Ray<3, fltp08>(0, 0, 1);
173 }
174 }
175 protected:
176 Model m_vertical_rotation_grip;
177 Model m_horizontal_rotation_grip;
178 };
179}
180#endif
A core class that represents a node on model hierarchy.
Definition Model.h:292
The primary namespace for the NDEVR SDK.
@ BitFlag
Per-vertex bit flags (selected, hidden, etc.).