Debian Codegraph @

lib/database/src/so/upgraders/SoV1TextureCoordinatePlane.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91,92 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoV1TextureCoordinatePlane
47 |
48 | Author(s) : Gavin Bell
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include "SoV1TextureCoordinatePlane.h"
55 #include <Inventor/nodes/SoTextureCoordinatePlane.h>
56 #include <Inventor/nodes/SoTexture2Transform.h>
57
58 SO_NODE_SOURCE(SoV1TextureCoordinatePlane);
59
60 // Static vars:
61 SbVec3f SoV1TextureCoordinatePlane::sDir;
62 SbVec3f SoV1TextureCoordinatePlane::tDir;
63
64 ////////////////////////////////////////////////////////////////////////
65 //
66 // Description:
67 // Default constructor
68 //
69 // Use: public
70
71 SoV1TextureCoordinatePlane::SoV1TextureCoordinatePlane()
72 //
73 ////////////////////////////////////////////////////////////////////////
74 {
75 SO_NODE_CONSTRUCTOR(SoV1TextureCoordinatePlane);
76
77 SO_NODE_ADD_FIELD(coord, (ALL));
78 SO_NODE_ADD_FIELD(normal,(SbVec3f(1, 0, 0)));
79 SO_NODE_ADD_FIELD(distanceFromOrigin, (0));
80 SO_NODE_ADD_FIELD(repeatInterval, (1));
81
82 // Set up static info for enumerated type field
83 SO_NODE_DEFINE_ENUM_VALUE(Coordinate, S);
84 SO_NODE_DEFINE_ENUM_VALUE(Coordinate, T);
85 SO_NODE_DEFINE_ENUM_VALUE(Coordinate, ALL);
86
87 // Set up info in enumerated type field
88 SO_NODE_SET_SF_ENUM_TYPE(coord, Coordinate);
89
90 // This upgrader returns a group, but it is an upgrade of a non-group
91 isGroup = FALSE;
92 }
93
94 ////////////////////////////////////////////////////////////////////////
95 //
96 // Description:
97 // Destructor.
98 //
99 // Use: private
100
101 SoV1TextureCoordinatePlane::~SoV1TextureCoordinatePlane()
102 //
103 ////////////////////////////////////////////////////////////////////////
104 {
105 }
106
107 ////////////////////////////////////////////////////////////////////////
108 //
109 // Description:
110 // Create a version 2.0 SoTextureCoordinatePlane.
111 //
112 // Use: private
113
114 SoNode *
115 SoV1TextureCoordinatePlane::createNewNode()
116 //
117 ////////////////////////////////////////////////////////////////////////
118 {
119 SoTextureCoordinatePlane *tex = SO_UPGRADER_CREATE_NEW(SoTextureCoordinatePlane);
120 tex->ref();
121
122 // Convert from old enums to new fields:
123
124 // The math is really pretty easy:
125 SbVec3f norm = normal.getValue();
126 norm.normalize();
127 SbVec3f direction = norm / repeatInterval.getValue();
128
129 // If translation is non-zero, we'll need to add a
130 // Texture2Transform node...
131 float translation = distanceFromOrigin.getValue() /
132 repeatInterval.getValue();
133
134 // Figure out which coordinate(s) to set. We set static variables
135 // because it is no longer possible to inherit the s/t coordinates
136 // separately across two nodes, so we'll remember the values
137 // across nodes...
138
139 if (coord.getValue() == ALL || coord.getValue() == S) {
140 sDir = direction;
141 }
142 if (coord.getValue() == ALL || coord.getValue() == T) {
143 tDir = direction;
144 }
145
146 tex->directionS = sDir;
147 tex->directionT = tDir;
148
149 if (translation == 0.0) {
150 tex->unrefNoDelete();
151 return tex;
152 }
153
154 // OK, have to make a group....
155 SoGroup *result = SO_UPGRADER_CREATE_NEW(SoGroup);
156 result->ref();
157 result->addChild(tex);
158 tex->unref();
159
160 SoTexture2Transform *xf = SO_UPGRADER_CREATE_NEW(SoTexture2Transform);
161 if (coord.getValue() == ALL || coord.getValue() == S) {
162 xf->translation.setValue(translation, 0);
163 }
164 if (coord.getValue() == ALL || coord.getValue() == T) {
165 xf->translation = xf->translation.getValue() +
166 SbVec2f(0, translation);
167 }
168 result->addChild(xf);
169 result->unrefNoDelete();
170
171 return result;
172 }
173