Debian Codegraph @

lib/database/src/so/nodes/SoPerspectiveCamera.c++

raw symbols SCIP
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 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 | SoPerspectiveCamera
47 |
48 | Author(s) : Paul S. Strauss
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 <Inventor/nodes/SoPerspectiveCamera.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoPerspectiveCamera.h`/
55 #include <cmath>
56
57 #define MINIMUM_NEAR_PLANEcxx . . $ `lib/database/src/so/nodes/SoPerspectiveCamera.c++:57:9`! 0.01 /* minimum near clipping distance */
58 /* (from center) */
59
60 SO_NODE_SOURCEcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:241:9`!(SoPerspectiveCamera);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Constructor
66 //
67 // Use: public
68
69 SoPerspectiveCameracxx . . $ SoPerspectiveCamera#::SoPerspectiveCameracxx . . $ SoPerspectiveCamera#SoPerspectiveCamera(49f6e7a06ebc5aa8).()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(SoPerspectiveCamera);
74 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(heightAngle, (M_PI_4cxx . . $ `<external>/11263917310783833665/math.h:1123:10`!)); // 45 degrees
75 isBuiltIncxx . . $ SoFieldContainer#isBuiltIn. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
76 }
77
78 ////////////////////////////////////////////////////////////////////////
79 //
80 // Description:
81 // Destructor (necessary since inline destructor is too complex)
82 //
83 // Use: private
84
85 SoPerspectiveCameracxx . . $ SoPerspectiveCamera#::~cxx . . $ SoPerspectiveCamera#`~SoPerspectiveCamera`(49f6e7a06ebc5aa8).SoPerspectiveCameracxx . . $ SoPerspectiveCamera#()
86 //
87 ////////////////////////////////////////////////////////////////////////
88 {
89 }
90
91 ////////////////////////////////////////////////////////////////////////
92 //
93 // Description:
94 // Scales the height of the camera, in this case the 'heightAngle' field
95 //
96 // Use: public
97
98 void
99 SoPerspectiveCameracxx . . $ SoPerspectiveCamera#::scaleHeightcxx . . $ SoPerspectiveCamera#scaleHeight(9364e6e7bff7660).(float scaleFactor)
100 //
101 ////////////////////////////////////////////////////////////////////////
102 {
103 if (scaleFactor == 0.0)
104 return;
105
106 heightAnglecxx . . $ SoPerspectiveCamera#heightAngle..setValuecxx . . $ SoSFFloat#setValue(9364e6e7bff7660).(scaleFactor * heightAnglecxx . . $ SoPerspectiveCamera#heightAngle..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).());
107 }
108
109 ////////////////////////////////////////////////////////////////////////
110 //
111 // Description:
112 // Fills in a view volume structure, based on the camera. If the
113 // useAspectRatio field is not 0.0 (the default), the camera uses
114 // that ratio instead of the one it has.
115 //
116 // Use: public
117
118 SbViewVolumecxx . . $ SbViewVolume#
119 SoPerspectiveCameracxx . . $ SoPerspectiveCamera#::getViewVolumecxx . . $ SoPerspectiveCamera#getViewVolume(595ca63569ff31e3).( float useAspectRatio) const
120 //
121 ////////////////////////////////////////////////////////////////////////
122 {
123 SbViewVolumecxx . . $ SbViewVolume# viewcxx . . $ SbViewVolume#SbViewVolume(49f6e7a06ebc5aa8).;
124
125 float camAspect = (useAspectRatio != 0.0 ? useAspectRatio :
126 aspectRatiocxx . . $ SoCamera#aspectRatio..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).());
127
128 // Set up the perspective camera.
129 view.perspectivecxx . . $ SbViewVolume#perspective(7e9a355db6148521).(heightAnglecxx . . $ SoPerspectiveCamera#heightAngle..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).(), camAspect,
130 nearDistancecxx . . $ SoCamera#nearDistance..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).(), farDistancecxx . . $ SoCamera#farDistance..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).());
131
132 // Note that these move the camera rather than moving objects
133 // relative to the camera.
134 view.rotateCameracxx . . $ SbViewVolume#rotateCamera(8b1048b3fc01a89c).(orientationcxx . . $ SoCamera#orientation..getValuecxx . . $ SoSFRotation#getValue(cd68af149be99fa7).());
135 view.translateCameracxx . . $ SbViewVolume#translateCamera(65a601b9d70571d6).(positioncxx . . $ SoCamera#position..getValuecxx . . $ SoSFVec3f#getValue(b5c384c15c94bb12).());
136 return view;
137 }
138
139 ////////////////////////////////////////////////////////////////////////
140 //
141 // Description:
142 // Finds a bounding sphere around the passed bounding box, then
143 // positions the camera without changing its height angle so that
144 // the entire sphere is visible. The aspect ratio to use for the
145 // camera is passed in.
146 //
147 // Use: protected
148
149 void
150 SoPerspectiveCameracxx . . $ SoPerspectiveCamera#::viewBoundingBoxcxx . . $ SoPerspectiveCamera#viewBoundingBox(1f223877e37fb080).(const SbBox3fcxx . . $ SbBox3f# &box,
151 float aspect, float slack)
152 //
153 ////////////////////////////////////////////////////////////////////////
154 {
155 SbSpherecxx . . $ SbSphere# bSpherecxx . . $ SbSphere#SbSphere(49f6e7a06ebc5aa8).;
156 float distToCenter;
157 SbMatrixcxx . . $ SbMatrix# rotationcxx . . $ SbMatrix#SbMatrix(49f6e7a06ebc5aa8).;
158 SbVec3fcxx . . $ SbVec3f# poscxx . . $ SbVec3f#SbVec3f(49f6e7a06ebc5aa8).;
159
160 // if the bounding box is not empty, create the bounding sphere
161 if (! box.isEmptycxx . . $ SbBox3f#isEmpty(455f465bc33b4cdf).())
162 bSphere.circumscribecxx . . $ SbSphere#circumscribe(40deaff30b131494).(box);
163 else {
164 pos.setValuecxx . . $ SbVec3f#setValue(4e87f9d875f2d08d).(0., 0., 0.);
165 bSphere.setValuecxx . . $ SbSphere#setValue(91fd4afec15735a5).(pos, 1.0);
166 }
167
168 // Find the angle necessary to fit the object completely in the
169 // window. We don't need any slack, because the bounding sphere
170 // is already bigger than the bounding box.
171 // h = height (radius of sphere)
172 // d = distance to eye
173 // tan(alpha) gives us h/d
174 float hOverD = tan(heightAnglecxx . . $ SoPerspectiveCamera#heightAngle..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).() / 2.0);
175 if (aspect < 1.0)
176 hOverD *= aspect;
177
178 distToCenter = bSphere.getRadiuscxx . . $ SbSphere#getRadius(5036dfe8d4170af2).() / hOverD; // h / (h/d) gives us d
179
180 rotation =cxx . . $ SbMatrix#`operator=`(63101dd9e6974539). orientationcxx . . $ SoCamera#orientation..getValuecxx . . $ SoSFRotation#getValue(cd68af149be99fa7).();
181 rotation.multVecMatrixcxx . . $ SbMatrix#multVecMatrix(f4e74898890c8c54).(SbVec3fcxx . . $ SbVec3f#SbVec3f(bd1040fe176e0786).(0.0, 0.0, distToCenter), pos);
182
183 positioncxx . . $ SoCamera#position. =cxx . . $ SoSFVec3f#`operator=`(861f7885f8980b32). pos +cxx . . $ operator+(af63bf8d0639b76b). bSphere.getCentercxx . . $ SbSphere#getCenter(b5c384c15c94bb12).();
184 nearDistancecxx . . $ SoCamera#nearDistance. =cxx . . $ SoSFFloat#`operator=`(fbcf3211dfe1bfd1). distToCenter - slack * bSphere.getRadiuscxx . . $ SbSphere#getRadius(5036dfe8d4170af2).();
185 if (nearDistancecxx . . $ SoCamera#nearDistance..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).() < 0.0 ||
186 nearDistancecxx . . $ SoCamera#nearDistance..getValuecxx . . $ SoSFFloat#getValue(5036dfe8d4170af2).() < (MINIMUM_NEAR_PLANEcxx . . $ `lib/database/src/so/nodes/SoPerspectiveCamera.c++:57:9`! * distToCenter))
187 nearDistancecxx . . $ SoCamera#nearDistance. =cxx . . $ SoSFFloat#`operator=`(fbcf3211dfe1bfd1). MINIMUM_NEAR_PLANEcxx . . $ `lib/database/src/so/nodes/SoPerspectiveCamera.c++:57:9`! * distToCenter;
188 farDistancecxx . . $ SoCamera#farDistance. =cxx . . $ SoSFFloat#`operator=`(fbcf3211dfe1bfd1). distToCenter + slack * bSphere.getRadiuscxx . . $ SbSphere#getRadius(5036dfe8d4170af2).();
189 focalDistancecxx . . $ SoCamera#focalDistance. =cxx . . $ SoSFFloat#`operator=`(fbcf3211dfe1bfd1). distToCenter;
190 }