Skip to content

Commit af56603

Browse files
committed
Origin for rotation matrix node.
1 parent bc43060 commit af56603

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

Sources/Basic3DNodes/TransformationNodes.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "NE_SingleValues.hpp"
33
#include "NUIE_NodeCommonParameters.hpp"
44
#include "BI_BuiltInFeatures.hpp"
5+
#include "Geometry.hpp"
56
#include "GLMReadWrite.hpp"
67

78
NE::SerializationInfo TransformationMatrixNode::serializationInfo (NE::ObjectVersion (1));
@@ -175,37 +176,33 @@ RotationMatrixNode::RotationMatrixNode (const std::wstring& name, const NUIE::Po
175176
void RotationMatrixNode::Initialize ()
176177
{
177178
TransformationMatrixNode::Initialize ();
178-
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("angle"), L"Angle", NE::ValuePtr (new NE::FloatValue (0.0)), NE::OutputSlotConnectionMode::Single)));
179-
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("axisx"), L"Axis X", NE::ValuePtr (new NE::FloatValue (0.0)), NE::OutputSlotConnectionMode::Single)));
180-
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("axisy"), L"Axis Y", NE::ValuePtr (new NE::FloatValue (0.0)), NE::OutputSlotConnectionMode::Single)));
181-
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("axisz"), L"Axis Z", NE::ValuePtr (new NE::FloatValue (1.0)), NE::OutputSlotConnectionMode::Single)));
179+
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("angle"), L"Angle", NE::ValuePtr (new NE::FloatValue (0.0f)), NE::OutputSlotConnectionMode::Single)));
180+
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("origin"), L"Origin", NE::ValuePtr (new PointValue (glm::vec3 (0.0f, 0.0f, 0.0f))), NE::OutputSlotConnectionMode::Single)));
181+
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("axis"), L"Axis", NE::ValuePtr (new PointValue (glm::vec3 (0.0f, 0.0f, 1.0f))), NE::OutputSlotConnectionMode::Single)));
182182
RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("transformation"), L"Transformation")));
183183
}
184184

185185
NE::ValueConstPtr RotationMatrixNode::Calculate (NE::EvaluationEnv& env) const
186186
{
187187
NE::ValueConstPtr angleValue = EvaluateInputSlot (NE::SlotId ("angle"), env);
188-
NE::ValueConstPtr axisXValue = EvaluateInputSlot (NE::SlotId ("axisx"), env);
189-
NE::ValueConstPtr axisYValue = EvaluateInputSlot (NE::SlotId ("axisy"), env);
190-
NE::ValueConstPtr axisZValue = EvaluateInputSlot (NE::SlotId ("axisz"), env);
191-
192-
if (!NE::IsComplexType<NE::NumberValue> (angleValue) || !NE::IsComplexType<NE::NumberValue> (axisXValue) || !NE::IsComplexType<NE::NumberValue> (axisYValue) || !NE::IsComplexType<NE::NumberValue> (axisZValue)) {
188+
NE::ValueConstPtr originValue = EvaluateInputSlot (NE::SlotId ("origin"), env);
189+
NE::ValueConstPtr axisValue = EvaluateInputSlot (NE::SlotId ("axis"), env);
190+
if (!NE::IsComplexType<NE::NumberValue> (angleValue) || !NE::IsComplexType<CoordinateValue> (originValue) || !NE::IsComplexType<CoordinateValue> (axisValue)) {
193191
return nullptr;
194192
}
195193

196194
NE::ListValuePtr result (new NE::ListValue ());
197-
bool isValid = BI::CombineValues (this, {angleValue, axisXValue, axisYValue, axisZValue}, [&] (const NE::ValueCombination& combination) {
195+
bool isValid = BI::CombineValues (this, {angleValue, originValue, axisValue}, [&] (const NE::ValueCombination& combination) {
198196
float angle = NE::NumberValue::ToFloat (combination.GetValue (0));
199-
glm::vec3 axis (
200-
NE::NumberValue::ToFloat (combination.GetValue (1)),
201-
NE::NumberValue::ToFloat (combination.GetValue (2)),
202-
NE::NumberValue::ToFloat (combination.GetValue (3))
203-
);
204-
if (glm::length (axis) == 0.0f) {
197+
glm::vec3 origin = CoordinateValue::Get (combination.GetValue (1));
198+
glm::vec3 axis = CoordinateValue::Get (combination.GetValue (2));
199+
if (Geometry::IsEqual (glm::length (axis), 0.0f)) {
205200
return false;
206201
}
207-
axis = glm::normalize (axis);
208-
glm::mat4 transformation = glm::rotate (glm::mat4 (1.0f), glm::radians (angle), axis);
202+
glm::mat4 offset = glm::translate (glm::mat4 (1.0f), -origin);
203+
glm::mat4 rotation = glm::rotate (glm::mat4 (1.0f), glm::radians (angle), axis);
204+
glm::mat4 offsetBack = glm::translate (glm::mat4 (1.0f), origin);
205+
glm::mat4 transformation = offsetBack * rotation * offset;
209206
result->Push (NE::ValuePtr (new TransformationValue (transformation)));
210207
return true;
211208
});
@@ -220,9 +217,6 @@ void RotationMatrixNode::RegisterParameters (NUIE::NodeParameterList& parameterL
220217
{
221218
TransformationMatrixNode::RegisterParameters (parameterList);
222219
NUIE::RegisterSlotDefaultValueNodeParameter<RotationMatrixNode, NE::FloatValue> (parameterList, L"Angle", NUIE::ParameterType::Float, NE::SlotId ("angle"));
223-
NUIE::RegisterSlotDefaultValueNodeParameter<RotationMatrixNode, NE::FloatValue> (parameterList, L"Axis X", NUIE::ParameterType::Float, NE::SlotId ("axisx"));
224-
NUIE::RegisterSlotDefaultValueNodeParameter<RotationMatrixNode, NE::FloatValue> (parameterList, L"Axis Y", NUIE::ParameterType::Float, NE::SlotId ("axisy"));
225-
NUIE::RegisterSlotDefaultValueNodeParameter<RotationMatrixNode, NE::FloatValue> (parameterList, L"Axis Z", NUIE::ParameterType::Float, NE::SlotId ("axisz"));
226220
}
227221

228222
NE::Stream::Status RotationMatrixNode::Read (NE::InputStream& inputStream)

0 commit comments

Comments
 (0)