| 1003 | } |
| 1004 | |
| 1005 | void VPathEditor::addNode( const Gui3DMouseEvent &pEvent ) |
| 1006 | { |
| 1007 | VPath *path = mSelection.Path; |
| 1008 | if ( !path ) |
| 1009 | { |
| 1010 | // Woops! |
| 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | // Min Index. |
| 1015 | S32 nodeIndex = -1; |
| 1016 | MatrixF nodeTransform( true ); |
| 1017 | if ( !getPointOnPath( path, pEvent, nodeIndex, nodeTransform ) ) |
| 1018 | { |
| 1019 | // Can't Add. |
| 1020 | return; |
| 1021 | } |
| 1022 | |
| 1023 | // Invert Transform. |
| 1024 | MatrixF pathTransform = mSelection.Path->getTransform(); |
| 1025 | pathTransform.setPosition( Point3F::Zero ); |
| 1026 | pathTransform.inverse(); |
| 1027 | |
| 1028 | Point3F nodePosition = ( nodeTransform.getPosition() - mSelection.Path->getPosition() ); |
| 1029 | pathTransform.mulP( nodePosition ); |
| 1030 | |
| 1031 | // Node Rotation. |
| 1032 | nodeTransform.mul( pathTransform ); |
| 1033 | QuatF nodeRotation( nodeTransform ); |
| 1034 | |
| 1035 | // Node Weights. |
| 1036 | F32 nodeWeight = 10.f; |
| 1037 | |
| 1038 | // Add New Node. |
| 1039 | VPathNode *node = path->addNode( nodePosition, nodeRotation, nodeWeight, ++nodeIndex ); |
| 1040 | |
| 1041 | // Valid Node? |
| 1042 | if ( !node ) |
| 1043 | { |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | // Update Size. |
| 1048 | path->updateContainer(); |
| 1049 | |
| 1050 | // Calculate Path. |
| 1051 | path->calculatePath(); |
| 1052 | |
| 1053 | UndoManager *historyManager = NULL; |
| 1054 | if ( !Sim::findObject( "EUndoManager", historyManager ) ) |
| 1055 | { |
| 1056 | Con::errorf( "VPathEditor::addNode() - EUndoManager not found!" ); |
| 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | // Create Undo Action. |
| 1061 | VPathEditorAddNodeAction *editAction = new VPathEditorAddNodeAction(); |
| 1062 |
no test coverage detected