~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/adapters/atlas/OrientationAdapter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: OrientationAdapter
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
 
8
//
 
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.
 
13
// 
 
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.
 
18
// 
 
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.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "OrientationAdapter.h"
 
28
#include <wfmath/quaternion.h>
 
29
#include <wfmath/atlasconv.h>
 
30
 
 
31
namespace EmberOgre {
 
32
 
 
33
namespace Gui {
 
34
 
 
35
namespace Adapters {
 
36
 
 
37
namespace Atlas {
 
38
 
 
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)
 
41
{
 
42
        if (mXWindow) {
 
43
                addGuiEventConnection(mXWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this))); 
 
44
        }
 
45
        if (mYWindow) {
 
46
                addGuiEventConnection(mYWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this))); 
 
47
        }
 
48
        if (mZWindow) {
 
49
                addGuiEventConnection(mZWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this))); 
 
50
        }
 
51
        if (mScalarWindow) {
 
52
                addGuiEventConnection(mScalarWindow->subscribeEvent(CEGUI::Window::EventTextChanged, CEGUI::Event::Subscriber(&OrientationAdapter::window_TextChanged, this))); 
 
53
        }
 
54
 
 
55
        
 
56
        updateGui(mOriginalElement);
 
57
}
 
58
 
 
59
 
 
60
OrientationAdapter::~OrientationAdapter()
 
61
{
 
62
}
 
63
 
 
64
void OrientationAdapter::updateGui(const ::Atlas::Message::Element& element)
 
65
{
 
66
        AdapterSelfUpdateContext context(*this);
 
67
        WFMath::Quaternion orientation(element);
 
68
//      axisBox.fromAtlas(element.asList());
 
69
        if (mXWindow) {
 
70
                mXWindow->setText(toString(orientation.vector().x())); 
 
71
        }
 
72
        if (mYWindow) {
 
73
                mYWindow->setText(toString(orientation.vector().y())); 
 
74
        }
 
75
        if (mZWindow) {
 
76
                mZWindow->setText(toString(orientation.vector().z())); 
 
77
        }
 
78
        if (mScalarWindow) {
 
79
                mScalarWindow->setText(toString(orientation.scalar())); 
 
80
        }
 
81
 
 
82
}
 
83
 
 
84
bool OrientationAdapter::window_TextChanged(const CEGUI::EventArgs& e)
 
85
{
 
86
        if (!mSelfUpdate) {
 
87
                EventValueChanged.emit();
 
88
        }
 
89
        return true;
 
90
}
 
91
 
 
92
void OrientationAdapter::fillElementFromGui()
 
93
{
 
94
        float x(0), y(0), z(0), scalar(0);
 
95
        if (mXWindow) {
 
96
                x = atof(mXWindow->getText().c_str()); 
 
97
        }
 
98
        if (mYWindow) {
 
99
                y = atof(mYWindow->getText().c_str()); 
 
100
        }
 
101
        if (mZWindow) {
 
102
                z = atof(mZWindow->getText().c_str()); 
 
103
        }
 
104
        if (mScalarWindow) {
 
105
                scalar = atof(mScalarWindow->getText().c_str()); 
 
106
        }
 
107
        WFMath::Quaternion orientation(scalar, x, y, z);
 
108
        mEditedElement = orientation.toAtlas();
 
109
}
 
110
 
 
111
bool OrientationAdapter::_hasChanges()
 
112
{
 
113
        WFMath::Quaternion originalOrientation(mOriginalElement);
 
114
        WFMath::Quaternion newOrientation(getValue());
 
115
        return originalOrientation != newOrientation;
 
116
}
 
117
 
 
118
}
 
119
 
 
120
}
 
121
 
 
122
}
 
123
 
 
124
}