openscenegraph
ConvertVec
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_CONVERTVEC
15#define OSGUTIL_CONVERTVEC 1
16
17namespace osgUtil {
18
19template <typename InType, typename OutType,
20 unsigned int InSize = InType::num_components,
21 unsigned int OutSize = OutType::num_components>
22struct ConvertVec
23{
24 static void convert(InType & in, OutType & out)
25 {}
26};
27
28
29
30template <typename InType, typename OutType>
31struct ConvertVec<InType, OutType, 2, 2>
32{
33 static void convert(InType & in, OutType & out)
34 {
35 out.set(static_cast<typename OutType::value_type>(in.x()),
36 static_cast<typename OutType::value_type>(in.y()));
37 }
38};
39
40template <typename InType, typename OutType>
41struct ConvertVec<InType, OutType, 2, 3>
42{
43 static void convert(InType & in, OutType & out)
44 {
45 out.set(static_cast<typename OutType::value_type>(in.x()),
46 static_cast<typename OutType::value_type>(in.y()),
47 static_cast<typename OutType::value_type>(0.0));
48 }
49};
50
51template <typename InType, typename OutType>
52struct ConvertVec<InType, OutType, 2, 4>
53{
54 static void convert(InType & in, OutType & out)
55 {
56 out.set(static_cast<typename OutType::value_type>(in.x()),
57 static_cast<typename OutType::value_type>(in.y()),
58 static_cast<typename OutType::value_type>(0.0),
59 static_cast<typename OutType::value_type>(1.0));
60 }
61};
62
63
64
65
66
67template <typename InType, typename OutType>
68struct ConvertVec<InType, OutType, 3, 2>
69{
70 static void convert(InType & in, OutType & out)
71 {
72 out.set(static_cast<typename OutType::value_type>(in.x()),
73 static_cast<typename OutType::value_type>(in.y()));
74 }
75};
76
77template <typename InType, typename OutType>
78struct ConvertVec<InType, OutType, 3, 3>
79{
80 static void convert(InType & in, OutType & out)
81 {
82 out.set(static_cast<typename OutType::value_type>(in.x()),
83 static_cast<typename OutType::value_type>(in.y()),
84 static_cast<typename OutType::value_type>(in.z()));
85 }
86};
87
88template <typename InType, typename OutType>
89struct ConvertVec<InType, OutType, 3, 4>
90{
91 static void convert(InType & in, OutType & out)
92 {
93 out.set(static_cast<typename OutType::value_type>(in.x()),
94 static_cast<typename OutType::value_type>(in.y()),
95 static_cast<typename OutType::value_type>(in.z()),
96 static_cast<typename OutType::value_type>(1.0));
97 }
98};
99
100
101
102
103
104template <typename InType, typename OutType>
105struct ConvertVec<InType, OutType, 4, 2>
106{
107 static void convert(InType & in, OutType & out)
108 {
109 out.set(static_cast<typename OutType::value_type>(in.x()/in.w()),
110 static_cast<typename OutType::value_type>(in.y()/in.w()));
111 }
112};
113
114template <typename InType, typename OutType>
115struct ConvertVec<InType, OutType, 4, 3>
116{
117 static void convert(InType & in, OutType & out)
118 {
119 out.set(static_cast<typename OutType::value_type>(in.x()/in.w()),
120 static_cast<typename OutType::value_type>(in.y()/in.w()),
121 static_cast<typename OutType::value_type>(in.z()/in.w()));
122 }
123};
124
125template <typename InType, typename OutType>
126struct ConvertVec<InType, OutType, 4, 4>
127{
128 static void convert(InType & in, OutType & out)
129 {
130 out.set(static_cast<typename OutType::value_type>(in.x()),
131 static_cast<typename OutType::value_type>(in.y()),
132 static_cast<typename OutType::value_type>(in.z()),
133 static_cast<typename OutType::value_type>(in.w()));
134 }
135};
136
137} // end of osg namespace
138
139#endif // ** OSG_CONVERTVEC ** //