| 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 | | SoRotation |
| 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/actions/SoCallbackAction.h> |
| 55 | #include <Inventor/actions/SoGLRenderAction.h> |
| 56 | #include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 57 | #include <Inventor/actions/SoGetMatrixAction.h> |
| 58 | #include <Inventor/actions/SoPickAction.h> |
| 59 | #include <Inventor/elements/SoModelMatrixElement.h> |
| 60 | #include <Inventor/nodes/SoRotation.h> |
| 61 | |
| 62 | SO_NODE_SOURCE(SoRotation); |
| 63 | |
| 64 | //////////////////////////////////////////////////////////////////////// |
| 65 | // |
| 66 | // Description: |
| 67 | // Constructor |
| 68 | // |
| 69 | // Use: public |
| 70 | |
| 71 | SoRotation::SoRotation() |
| 72 | // |
| 73 | //////////////////////////////////////////////////////////////////////// |
| 74 | { |
| 75 | SO_NODE_CONSTRUCTOR(SoRotation); |
| 76 | SO_NODE_ADD_FIELD(rotation, (0.0, 0.0, 0.0, 1.0)); |
| 77 | isBuiltIn = TRUE; |
| 78 | } |
| 79 | |
| 80 | //////////////////////////////////////////////////////////////////////// |
| 81 | // |
| 82 | // Description: |
| 83 | // Destructor |
| 84 | // |
| 85 | // Use: private |
| 86 | |
| 87 | SoRotation::~SoRotation() |
| 88 | // |
| 89 | //////////////////////////////////////////////////////////////////////// |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | //////////////////////////////////////////////////////////////////////// |
| 94 | // |
| 95 | // Description: |
| 96 | // Implements most actions. |
| 97 | // |
| 98 | // Use: extender |
| 99 | |
| 100 | void |
| 101 | SoRotation::doAction(SoAction *action) |
| 102 | // |
| 103 | //////////////////////////////////////////////////////////////////////// |
| 104 | { |
| 105 | if (! rotation.isIgnored() && ! rotation.isDefault()) |
| 106 | SoModelMatrixElement::rotateBy(action->getState(), this, |
| 107 | rotation.getValue()); |
| 108 | } |
| 109 | |
| 110 | //////////////////////////////////////////////////////////////////////// |
| 111 | // |
| 112 | // Description: |
| 113 | // Handles callback action |
| 114 | // |
| 115 | // Use: extender |
| 116 | |
| 117 | void |
| 118 | SoRotation::callback(SoCallbackAction *action) |
| 119 | // |
| 120 | //////////////////////////////////////////////////////////////////////// |
| 121 | { |
| 122 | SoRotation::doAction(action); |
| 123 | } |
| 124 | |
| 125 | //////////////////////////////////////////////////////////////////////// |
| 126 | // |
| 127 | // Description: |
| 128 | // Handles GL render action |
| 129 | // |
| 130 | // Use: extender |
| 131 | |
| 132 | void |
| 133 | SoRotation::GLRender(SoGLRenderAction *action) |
| 134 | // |
| 135 | //////////////////////////////////////////////////////////////////////// |
| 136 | { |
| 137 | SoRotation::doAction(action); |
| 138 | } |
| 139 | |
| 140 | //////////////////////////////////////////////////////////////////////// |
| 141 | // |
| 142 | // Description: |
| 143 | // Handles get bounding box action |
| 144 | // |
| 145 | // Use: extender |
| 146 | |
| 147 | void |
| 148 | SoRotation::getBoundingBox(SoGetBoundingBoxAction *action) |
| 149 | // |
| 150 | //////////////////////////////////////////////////////////////////////// |
| 151 | { |
| 152 | SoRotation::doAction(action); |
| 153 | } |
| 154 | |
| 155 | //////////////////////////////////////////////////////////////////////// |
| 156 | // |
| 157 | // Description: |
| 158 | // Returns transformation matrix. |
| 159 | // |
| 160 | // Use: extender |
| 161 | |
| 162 | void |
| 163 | SoRotation::getMatrix(SoGetMatrixAction *action) |
| 164 | // |
| 165 | //////////////////////////////////////////////////////////////////////// |
| 166 | { |
| 167 | if (! rotation.isIgnored() && ! rotation.isDefault()) { |
| 168 | SbRotation rot = rotation.getValue(); |
| 169 | SbMatrix &ctm = action->getMatrix(); |
| 170 | SbMatrix &inv = action->getInverse(); |
| 171 | SbMatrix m; |
| 172 | |
| 173 | rot.getValue(m); |
| 174 | ctm.multLeft(m); |
| 175 | rot.invert(); |
| 176 | rot.getValue(m); |
| 177 | inv.multRight(m); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | //////////////////////////////////////////////////////////////////////// |
| 182 | // |
| 183 | // Description: |
| 184 | // Handles pick action. |
| 185 | // |
| 186 | // Use: extender |
| 187 | |
| 188 | void |
| 189 | SoRotation::pick(SoPickAction *action) |
| 190 | // |
| 191 | //////////////////////////////////////////////////////////////////////// |
| 192 | { |
| 193 | SoRotation::doAction(action); |
| 194 | } |