API Documentation
Loading...
Searching...
No Matches
RotationBounds.h
Go to the documentation of this file.
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/Translator.h>
8#if NDEVR_GRIPS
9namespace NDEVR
10{
11 /**--------------------------------------------------------------------------------------------------
12 \brief A Model which provides rotational grips to a model.
13 *-----------------------------------------------------------------------------------------------**/
14 class RotationBounds : public Model
15 {
16 public:
17 RotationBounds(const Model& model)
18 : Model(model)
19 {
20 if (!isOfType(TypeName()))
21 {
22 setModelProperty(Model::e_application_constructed, true);
23 m_vertical_rotation_grip = createChild();
24 m_horizontal_rotation_grip = createChild();
25 setModelProperty(Model::e_type, TypeName());
26 setProperty(DesignObject::e_tree_visible, false);
27 setProperty(DesignObject::e_is_application_owned, true);
28 setProperty(DesignObject::e_is_application_locked, true);
29 setModelProperty(Model::e_can_select_children, true);
30 Effect effect = createChildEffect();
31 effect.setupAsBoundingBox(*this);
32 setupRotationGrips(m_vertical_rotation_grip, 0);
33 setupRotationGrips(m_horizontal_rotation_grip, 1);
34 }
35 else
36 {
37 m_vertical_rotation_grip = getChild(0);
38 m_horizontal_rotation_grip = getChild(1);
39 }
40 }
41 void attachTo(const Model& model)
42 {
43 Effect effect = getEffect();
44 if (effect.numberOfTargets() < 2 || effect.getTarget(1) != model)
45 effect.setupAsBoundingBox(*this, model);
46 else
47 effect.activate();
48 }
49
50 void setupRotationGrips(Model& grip, uint01 index)
51 {
52 grip.setProperty(DesignObject::e_name, _t("Rotate"));
53 grip.setModelProperty(Model::e_type, "rotation_grip");
54 grip.setModelProperty(Model::e_can_select_children, true);
55 Scene scene = grip.getScene();
56 Geometry circle = ShapeConstructors::StaticCircleOutline(scene);
57 Matrix<fltp08> matrix = Matrix<fltp08>::RotationMatrix(Angle<fltp08>(DEGREES, 90.0), IndexTangent(index));
58 grip.setTransform(matrix);
59 grip.setGeometryChild(circle);
60 grip.setProperty(Model::e_bounds_ignored, true);
61 BitFlag flag(0);
62 //flag(ParentMatrixFlags::e_scale_to_camera, true);
63 flag(ParentMatrixFlags::e_ignore_scale_distortion, true);
64 grip.setParentMatrixFlags(flag);
65 grip.updateVisible(false);
66 grip.updateModifiedTime();
67
68 Material material = grip.createChildMaterial();
69 material.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
70 switch (index)
71 {
72 case X: material.setUVColor(UVType::e_KD, RGBColor(255, 0,0));
73 case Y: material.setUVColor(UVType::e_KD, RGBColor(0, 255, 0));
74 case Z: material.setUVColor(UVType::e_KD, RGBColor(0, 0, 255));
75 }
76
77 material.setShadingModel(Material::ShadingModel::e_flat);
78 material.setMaterialProperty(Material::e_override_camera_material, true);
79 material.setMaterialProperty(Material::e_wireframe, true);
80 material.setMaterialProperty(Material::e_pixel_thickness, 10.0);
81 material.setProperty(Material::e_tree_visible, false);
82 material.updateModifiedTime();
83 grip.updateModifiedTime();
84 }
85 static constexpr const char* TypeName()
86 {
87 return "rotation_bounds_model";
88 }
89 static Ray<3, fltp08> IndexNormal(uint04 index)
90 {
91 switch (index)
92 {
93 case 0: return Ray<3, fltp08>(1.0, 0.0, 0.0);
94 case 1: return Ray<3, fltp08>(0.0, 1.0, 0.0);
95 default:
96 lib_assert(false, "Bad index normal");
97 return Ray<3, fltp08>(0, 0, 1);
98 }
99 }
100 static Ray<3, fltp08> IndexTangent(uint04 index)
101 {
102 switch (index)
103 {
104 case 0: return Ray<3, fltp08>(0.0, 1.0, 0.0);
105 case 1: return Ray<3, fltp08>(1.0, 0.0, 0.0);
106 default:
107 lib_assert(false, "Bad index normal");
108 return Ray<3, fltp08>(0, 0, 1);
109 }
110 }
111 protected:
112 Model m_vertical_rotation_grip;
113 Model m_horizontal_rotation_grip;
114 };
115}
116#endif
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:68
#define _t(english_string)
Definition Translator.h:90
Definition ACIColor.h:37
@ Y
Definition BaseValues.hpp:165
@ X
Definition BaseValues.hpp:163
@ Z
Definition BaseValues.hpp:167