Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/3D/a3dl/portal.cc

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 <tetron@interreality.org>
00022 */
00023 
00024 #include <vos/metaobjects/property/fileproperty.hh>
00025 #include "material.hh"
00026 #include "portal.hh"
00027 
00028 using namespace A3DL;
00029 
00030 Portal::Portal(MetaObject* superobject)
00031     : MetaObject(superobject)
00032 {
00033 }
00034 
00035 Portal::~Portal()
00036 {
00037 }
00038 
00039 MetaObject* Portal::new_Portal(MetaObject* superobject, const string& type)
00040 {
00041     return new Portal(superobject);
00042 }
00043 
00044 const string Portal::getType()
00045 {
00046     return "a3dl:portal";
00047 }
00048 
00049 void Portal::registerExtenders()
00050 {
00051     LocalSite::addLocalObjectExtension(typeid(Portal).name(), &Portal::new_Portal);
00052     LocalSite::addLocalObjectExtension("a3dl:portal", &Portal::new_Portal);
00053     RemoteSite::addRemoteObjectExtension(typeid(Portal).name(), &Portal::new_Portal);
00054     RemoteSite::addRemoteObjectExtension("a3dl:portal", &Portal::new_Portal);
00055 }
00056 
00057 
00058 void Portal::setTargetSector(Sector* sector)
00059 {
00060     try {
00061         vRef<ParentChildRelation> pcr = findChild("a3dl:targetsector");
00062         setChild(pcr->position, "a3dl:targetsector", sector);
00063     } catch(NoSuchObjectError) {
00064         insertChild(-1, "a3dl:targetsector", sector);
00065     }
00066 }
00067 
00068 Sector* Portal::getTargetSector()
00069 {
00070     return meta_cast<Sector*>(&findObject("a3dl:targetsector"));
00071 }
00072 
00073 
00074 void Portal::setWarpingTransform(float m11, float m12, float m13,
00075                          float m21, float m22, float m23,
00076                          float m31, float m32, float m33,
00077                          float tx,  float ty,  float tz)
00078 {
00079     char s[256];
00080     snprintf(s, sizeof(s), "%f %f %f %f %f %f %f %f %f",
00081              m11, m12, m13, m21, m22, m23, m31, m32, m33);
00082     Property::setProperty(*this, "a3dl:warpMatrix", string(s), "text/x-vector-float", accesscontrol);
00083 
00084     snprintf(s, sizeof(s), "%f %f %f", tx, ty, tz);
00085     Property::setProperty(*this, "a3dl:warpTranslate", string(s), "text/x-vector-float", accesscontrol);
00086 }
00087 
00088 
00089 void Portal::getWarpingTransform(float& m11, float& m12, float& m13,
00090                          float& m21, float& m22, float& m23,
00091                          float& m31, float& m32, float& m33,
00092                          float& tx,  float& ty,  float& tz)
00093 {
00094     m11 = m22 = m33 = 1;
00095     m12 = m13 = m21 = m23 = m31 = m32 = 0;
00096     tx = ty = tz = 0;
00097 
00098     try {
00099         vRef<Vobject> v = findObject("a3dl:warpMatrix");
00100         if(Property* p = meta_cast<Property*>(&v)) {
00101             string s = p->read();
00102             sscanf(s.c_str(), "%f %f %f %f %f %f %f %f %f",
00103                    &m11, &m12, &m13, &m21, &m22, &m23, &m31, &m32, &m33);
00104         }
00105     } catch(NoSuchObjectError) {
00106     }
00107     try {
00108         vRef<Vobject> v = findObject("a3dl:warpTranslate");
00109         if(Property* p = meta_cast<Property*>(&v)) {
00110             string s = p->read();
00111             sscanf(s.c_str(), "%f %f %f", &tx, &ty, &tz);
00112         }
00113     } catch(NoSuchObjectError) {
00114     }
00115 }
00116 
00117 
00118 /** Get material vobject. */
00119 Material* Portal::getMaterial(bool createIfNone)
00120 {
00121     try {
00122         return meta_cast<Material*>(&findObject("a3dl:material"));
00123     } catch(NoSuchObjectError) {
00124         if(createIfNone) {
00125             vRef<LocalSite> site = Site::getDefaultPeer();
00126             vRef<Material> mat = meta_cast<Material*>(site->createMetaObject("a3dl:material",
00127                                                                                          typeid(Material).name(), 0));
00128             mat->setPropertyAccessControl(accesscontrol);
00129             insertChild(-1, "a3dl:material", &mat);
00130             mat->acquire();
00131             return &mat;
00132         } else throw;
00133     }
00134 }
00135 
00136 
00137 /** Set material vobject. */
00138 void Portal::setMaterialObj(Material* material)
00139 {
00140     try {
00141         vRef<ParentChildRelation> pcr = findChild("a3dl:material");
00142         setChild(pcr->position, "a3dl:material", material);
00143     } catch(NoSuchObjectError) {
00144         insertChild(-1, "a3dl:material", material);
00145     }
00146 }
00147 

Generated on Tue Aug 12 03:55:36 2003 for Interreality Project - VOS by doxygen 1.3.2