/home/tetron/hack/vos/libs/vos/metaobjects/a3dl/object3d.hh
Go to the documentation of this file.00001 /* 00002 This file is part of the Virtual Object System of 00003 the Interreality project (http://interreality.org). 00004 00005 Copyright (C) 2001, 2002 Peter Amstutz 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Peter Amstutz <http://www.interreality.org> 00022 */ 00023 #ifndef _OBJECT3D_HH_ 00024 #define _OBJECT3D_HH_ 00025 00026 #include "a3dldefs.hh" 00027 #include <vos/vos/vos.hh> 00028 #include "material.hh" 00029 00030 #ifndef A3DL_EXPORTS 00031 IMPORT_METAOBJECT_FACTORIES(A3DL_Object3D) 00032 #endif 00033 00034 namespace A3DL 00035 { 00036 class MaterialIterator; 00037 00038 /** @class Object3D object3d.hh vos/metaobjects/a3dl/object3d.hh 00039 * @ingroup libmetaobject_a3dl 00040 * Base class for all 3D objects. Provides properties for position, 00041 * orientation and scaling (size) of the object, as well as material. 00042 */ 00043 class A3DL_API Object3D : public VOS::MetaObject 00044 { 00045 public: 00046 Object3D(VOS::VobjectBase* superobject); 00047 virtual ~Object3D(); 00048 00049 /** Initialize this object to have no property access control, position 00050 * (0,0,0), orientation (0,1,0,0) and scaling(1,1,1). 00051 */ 00052 virtual void initialize(); 00053 00054 /** Set position of this 3D object. 00055 @param x X translation, relative to origin of parent object 00056 @param y Y translation, relative to origin of parent object 00057 @param z Z translation, relative to origin of parent object 00058 @throws NoSuchObjectError if "position" subobject does not exist, or is not a property. 00059 */ 00060 virtual void setPosition(double x, double y, double z); 00061 00062 00063 /** Set the orientation of this 3D object in axis-angle 00064 rotation. The first three parameters are a unit vector in 00065 world space which define an axis, the fourth parameter is 00066 a clockwise rotation about that axis. For example, [0 1 0 20] would 00067 specify a rotation of 20 degrees around a vector pointing 00068 straight up. 00069 @note You can convert a quaternion into angle-axis 00070 rotation with the following math: 00071 @code 00072 phi = 2.0 * acos(quat.r); 00073 x = quat.x / sin(phi/2.0); 00074 y = quat.y / sin(phi/2.0); 00075 z = quat.z / sin(phi/2.0); 00076 @endcode 00077 @param x X vector component 00078 @param y Y vector component 00079 @param z Z vector component 00080 @param phi the rotation about the vector axis, in degrees 00081 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00082 */ 00083 virtual void setOrientation(double x, double y, double z, double phi); 00084 00085 /** Convenience function to set the orientation of this 3D object using a quaternion, 00086 which is then converted to A3DL's axis-angle notation. 00087 @param x X vector component 00088 @param y Y vector component 00089 @param z Z vector component 00090 @param phi the rotation about the vector axis, in degrees 00091 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00092 */ 00093 virtual void setOrientationWithQuaternion(double x, double y, double z, double phi); 00094 00095 /** Set scaling factors of this 3D object. 00096 @param x X scaling 00097 @param y Y scaling 00098 @param z Z scaling 00099 @throws NoSuchObjectError if "scaling" subobject does not exist, or is not a property. 00100 */ 00101 virtual void setScaling(double x, double y, double z); 00102 00103 /** Get position of this 3D object. 00104 @param x X translation, relative to origin of parent object 00105 @param y Y translation, relative to origin of parent object 00106 @param z Z translation, relative to origin of parent object 00107 @throws NoSuchObjectError if "position" subobject does not exist, or is not a property. 00108 */ 00109 virtual void getPosition(double& x, double& y, double& z); 00110 00111 /** Get the orientation of this 3D object in axis-angle 00112 rotation. See setOrientation() for details. 00113 00114 @note This can be easily converted into a quaternion with 00115 the following math: 00116 @code 00117 quat.r = cos(phi/2.0); 00118 quat.x = x * sin(phi/2.0); 00119 quat.y = y * sin(phi/2.0); 00120 quat.z = z * sin(phi/2.0); 00121 @endcode 00122 @param x X vector component 00123 @param y Y vector component 00124 @param z Z vector component 00125 @param phi the rotation about the vector axis, in degrees 00126 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00127 */ 00128 virtual void getOrientation(double& x, double& y, double& z, double& phi); 00129 00130 /** Convenience function to get the orientation of this 3D 00131 object as a quaternion, converting from A3DL's axis-angle 00132 representation. 00133 @param x X vector component 00134 @param y Y vector component 00135 @param z Z vector component 00136 @param phi the rotation about the vector axis, in degrees 00137 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00138 */ 00139 virtual void getOrientationAsQuaternion(double& x, double& y, double& z, double& phi); 00140 00141 /** Get scaling factors of this 3D object. 00142 @param x X scaling 00143 @param y Y scaling 00144 @param z Z scaling 00145 @throws NoSuchObjectError if "scaling" subobject does not exist, or is not a property. 00146 */ 00147 virtual void getScaling(double& x, double& y, double& z); 00148 00149 00150 /** Get material vobject. */ 00151 virtual VUtil::vRef<Material> getMaterial(bool createIfNone = true); 00152 00153 /** Set a material vobject */ 00154 virtual void setMaterial(Material* obj); 00155 00156 /** Get all attached material objects */ 00157 virtual MaterialIterator getMaterials(); 00158 00159 /** Set the hard transform (HT) position of this 3D object. 00160 This transform is applied against the object before the 00161 normal position transform is applied and is not affected 00162 by hierarchical transforms. 00163 @param x X translation, relative to origin of parent object 00164 @param y Y translation, relative to origin of parent object 00165 @param z Z translation, relative to origin of parent object 00166 @throws NoSuchObjectError if "position" subobject does not exist, or is not a property. 00167 */ 00168 virtual void setPositionHT(double x, double y, double z); 00169 00170 00171 /** Set the hard transform (HT) orientation of this 3D object 00172 in axis-angle rotation. This transform is applied against 00173 the object before the normal orientation transform is applied 00174 and is not affected by hierarchical transforms. The first 00175 three parameters are a unit vector in world space which 00176 define an axis, the fourth parameter is a clockwise 00177 rotation about that axis. For example, [0 1 0 20] would 00178 specify a rotation of 20 degrees around a vector pointing 00179 straight up. 00180 @note You can convert a quaternion into angle-axis 00181 rotation with the following math: 00182 @code 00183 phi = 2.0 * acos(quat.r); 00184 x = quat.x / sin(phi/2.0); 00185 y = quat.y / sin(phi/2.0); 00186 z = quat.z / sin(phi/2.0); 00187 @endcode 00188 @param x X vector component 00189 @param y Y vector component 00190 @param z Z vector component 00191 @param phi the rotation about the vector axis, in degrees 00192 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00193 */ 00194 virtual void setOrientationHT(double x, double y, double z, double phi); 00195 00196 /** Convenience function to set the hard transform (HT) 00197 orientation of this 3D object using a quaternion, which is 00198 then converted to A3DL's axis-angle notation. This 00199 transform is applied against the object before the normal 00200 orientation transform is applied and is not affected by 00201 hierarchical transforms. 00202 00203 @param x X vector component 00204 @param y Y vector component 00205 @param z Z vector component 00206 @param phi the rotation about the vector axis, in degrees 00207 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00208 */ 00209 virtual void setOrientationWithQuaternionHT(double x, double y, double z, double phi); 00210 00211 00212 /** Set the hard transform (HT) scaling this 3D object. This 00213 transform is applied against the object before the normal 00214 scaling transform is applied and is not affected by 00215 hierarchical transforms. 00216 @param x X scaling 00217 @param y Y scaling 00218 @param z Z scaling 00219 @throws NoSuchObjectError if "scaling" subobject does not exist, or is not a property. 00220 */ 00221 virtual void setScalingHT(double x, double y, double z); 00222 00223 /** Get the hard transform (HT) position of this 3D object. 00224 This transform is applied against the object before the 00225 normal position transform is applied and is not affected by 00226 hierarchical transforms. 00227 00228 @param x X translation, relative to origin of parent object 00229 @param y Y translation, relative to origin of parent object 00230 @param z Z translation, relative to origin of parent object 00231 @throws NoSuchObjectError if "position" subobject does not exist, or is not a property. 00232 */ 00233 virtual void getPositionHT(double& x, double& y, double& z); 00234 00235 /** Get the hard transform (HT) orientation of this 3D object in axis-angle 00236 rotation. See setOrientation() for details. This 00237 transform is applied against the object before the normal 00238 orientation transform is applied and is not affected by 00239 hierarchical transforms. 00240 00241 @note This can be easily converted into a quaternion with 00242 the following math: 00243 @code 00244 quat.r = cos(phi/2.0); 00245 quat.x = x * sin(phi/2.0); 00246 quat.y = y * sin(phi/2.0); 00247 quat.z = z * sin(phi/2.0); 00248 @endcode 00249 @param x X vector component 00250 @param y Y vector component 00251 @param z Z vector component 00252 @param phi the rotation about the vector axis, in degrees 00253 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00254 */ 00255 virtual void getOrientationHT(double& x, double& y, double& z, double& phi); 00256 00257 /** Convenience function to get the hard transform (HT) 00258 orientation of this 3D object as a quaternion, converting 00259 from A3DL's axis-angle representation. This 00260 transform is applied against the object before the normal 00261 orientation transform is applied and is not affected by 00262 hierarchical transforms. 00263 00264 @param x X vector component 00265 @param y Y vector component 00266 @param z Z vector component 00267 @param phi the rotation about the vector axis, in degrees 00268 @throws NoSuchObjectError if "orientation" subobject does not exist, or is not a property. 00269 */ 00270 virtual void getOrientationAsQuaternionHT(double& x, double& y, double& z, double& phi); 00271 00272 00273 /** Get the hard transform (HT) scaling of this 3D object. 00274 This transform is applied against the object before the 00275 normal scaling transform is applied and is not 00276 affected by hierarchical transforms. 00277 @param x X scaling 00278 @param y Y scaling 00279 @param z Z scaling 00280 @throws NoSuchObjectError if "scaling" subobject does not exist, or is not a property. 00281 */ 00282 virtual void getScalingHT(double& x, double& y, double& z); 00283 00284 00285 virtual const std::string getVOSType(); 00286 static VOS::MetaObject* new_Object3D(VOS::VobjectBase* superobject, const std::string& type); 00287 00288 void setOrInsertChild(const std::string& name, VOS::Vobject* obj); 00289 00290 /** @return If true, applyForce/applyTorque will be fed into a 00291 physics engine and the object will have dynamic response. 00292 If false applyForce/applyTorque apply the change directly 00293 as a delta to the position/orientation property. 00294 */ 00295 virtual bool supportsPhysics(); 00296 00297 /** Apply an instantaneous linear force vector to this object 00298 @param x component of vector 00299 @param y component of vector 00300 @param z component of vector 00301 */ 00302 virtual void applyForce(double x, double y, double z); 00303 00304 /** Apply an instantaneous angular torque to this object. 00305 The direction of the vector specifies the axis, the length 00306 of the vector specifies the magnitude, and the direction of rotation 00307 is determined by the "right hand" rule. 00308 @param x component of vector 00309 @param y component of vector 00310 @param z component of vector 00311 */ 00312 virtual void applyTorque(double x, double y, double z); 00313 00314 /** Fetch the current linear velocity vector for this object 00315 @param x component of vector 00316 @param y component of vector 00317 @param z component of vector 00318 */ 00319 virtual void getLinearVelocity(double& x, double& y, double& z); 00320 00321 /** Fetch the current angular velocity of this object. 00322 The direction of the vector specifies the axis, the length 00323 of the vector specifies the magnitude, and the direction of rotation 00324 is determined by the "right hand" rule. 00325 @param x component of vector 00326 @param y component of vector 00327 @param z component of vector 00328 */ 00329 virtual void getAngularVelocity(double& x, double& y, double& z); 00330 00331 /** Utility functions for getting/setting properties */ 00332 //@{ 00333 static void setThreeFloatProperty(Vobject& vob, const std::string& name, double x, double y, double z); 00334 static void getThreeFloatProperty(Vobject& vob, const std::string& name, double* x, double* y, double* z); 00335 //@} 00336 00337 /** Get position property object. */ 00338 virtual VUtil::vRef<VOS::Property> getPositionObj(); 00339 00340 /** Set position property object */ 00341 virtual void setPositionObj(VOS::Property* obj); 00342 virtual VUtil::vRef<VOS::Property> getOrientationObj(); 00343 virtual void setOrientationObj(VOS::Property* obj); 00344 virtual VUtil::vRef<VOS::Property> getScalingObj(); 00345 virtual void setScalingObj(VOS::Property* obj); 00346 00347 virtual void moveTo(double x, double y, double z, double timestep); 00348 }; 00349 } 00350 00351 #endif