Mango request: added an input node to use track's position in compositor
[blender-staging.git] / source / blender / compositor / nodes / COM_TrackPositionNode.cpp
1 /*
2  * Copyright 2012, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor:
19  *              Jeroen Bakker
20  *              Monique Dewanchand
21  *              Sergey Sharybin
22  */
23
24 #include "COM_TrackPositionNode.h"
25 #include "COM_ExecutionSystem.h"
26 #include "COM_TrackPositionOperation.h"
27
28 extern "C" {
29         #include "DNA_movieclip_types.h"
30 }
31
32 TrackPositionNode::TrackPositionNode(bNode *editorNode) : Node(editorNode)
33 {
34         /* pass */
35 }
36
37 void TrackPositionNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
38 {
39         OutputSocket *outputX = this->getOutputSocket(0);
40         OutputSocket *outputY = this->getOutputSocket(1);
41
42         bNode *editorNode = this->getbNode();
43         MovieClip *clip = (MovieClip *) editorNode->id;
44
45         NodeTrackPosData *trackpos_data = (NodeTrackPosData *) editorNode->storage;
46
47         TrackPositionOperation *operationX = new TrackPositionOperation();
48         TrackPositionOperation *operationY = new TrackPositionOperation();
49
50         operationX->setMovieClip(clip);
51         operationX->setTrackingObject(trackpos_data->tracking_object);
52         operationX->setTrackName(trackpos_data->track_name);
53         operationX->setFramenumber(context->getFramenumber());
54         operationX->setAxis(0);
55         operationX->setRelative(editorNode->custom1);
56
57         operationY->setMovieClip(clip);
58         operationY->setTrackingObject(trackpos_data->tracking_object);
59         operationY->setTrackName(trackpos_data->track_name);
60         operationY->setFramenumber(context->getFramenumber());
61         operationY->setAxis(1);
62         operationY->setRelative(editorNode->custom1);
63
64         outputX->relinkConnections(operationX->getOutputSocket());
65         outputY->relinkConnections(operationY->getOutputSocket());
66
67         graph->addOperation(operationX);
68 }