2
// C++ Implementation: OrientationAdapter
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
27
#include "OrientationAdapter.h"
28
#include <wfmath/quaternion.h>
29
#include <wfmath/atlasconv.h>
39
OrientationAdapter::OrientationAdapter(const ::Atlas::Message::Element& element, CEGUI::Window* xWindow, CEGUI::Window* yWindow, CEGUI::Window* zWindow, CEGUI::Window* scalarWindow)
40
: AdapterBase(element), mXWindow(xWindow), mYWindow(yWindow), mZWindow(zWindow), mScalarWindow(scalarWindow)
43
addGuiEventConnection(mXWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this)));
46
addGuiEventConnection(mYWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this)));
49
addGuiEventConnection(mZWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this)));
52
addGuiEventConnection(mScalarWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this)));
56
updateGui(mOriginalElement);
60
OrientationAdapter::~OrientationAdapter()
64
void OrientationAdapter::updateGui(const ::Atlas::Message::Element& element)
66
AdapterSelfUpdateContext context(*this);
67
WFMath::Quaternion orientation(element);
68
// axisBox.fromAtlas(element.asList());
70
mXWindow->setText(toString(orientation.vector().x()));
73
mYWindow->setText(toString(orientation.vector().y()));
76
mZWindow->setText(toString(orientation.vector().z()));
79
mScalarWindow->setText(toString(orientation.scalar()));
84
bool OrientationAdapter::window_TextChanged(const CEGUI::EventArgs& e)
87
EventValueChanged.emit();
92
void OrientationAdapter::fillElementFromGui()
94
float x(0), y(0), z(0), scalar(0);
96
x = atof(mXWindow->getText().c_str());
99
y = atof(mYWindow->getText().c_str());
102
z = atof(mZWindow->getText().c_str());
105
scalar = atof(mScalarWindow->getText().c_str());
107
WFMath::Quaternion orientation(scalar, x, y, z);
108
mEditedElement = orientation.toAtlas();
111
bool OrientationAdapter::_hasChanges()
113
WFMath::Quaternion originalOrientation(mOriginalElement);
114
WFMath::Quaternion newOrientation(getValue());
115
return originalOrientation != newOrientation;