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/viewpoint.cc

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001, 2002 Peter Amstutz
00003     Copyright (C) 2002 Reed Hedges
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00018 
00019 */
00020 
00021 #include <stdio.h>
00022 #include "viewpoint.hh"
00023 
00024 using namespace A3DL;
00025 
00026 Viewpoint::Viewpoint(MetaObject* superobject)
00027     : MetaObject(superobject), propac(0)
00028 {
00029 }
00030 
00031 Viewpoint::~Viewpoint()
00032 {
00033 }
00034 
00035 void Viewpoint::setPropertyAccessControl(PropertyAccessControl* pac) {
00036     propac = pac;
00037 }
00038 
00039 PropertyAccessControl* Viewpoint::getPropertyAccessControl() {
00040     return propac;
00041 }
00042 
00043 void Viewpoint::setPosition(double x, double y, double z) throw(NoSuchObjectError)
00044 {
00045     char c[256];
00046     sprintf(c, "%.15g %.15g %.15g", x, y, z);
00047     try {
00048         Property::setProperty(*this, "a3dl:position", string(c), "text/x-vector-float", propac);
00049     } catch(bad_cast e) {
00050         throw NoSuchObjectError(string("Error casting \"position\" object to type \"property\" (") + e.what() + ")");
00051     }
00052 }
00053 
00054 void Viewpoint::getPosition(double& x, double& y, double& z) throw(NoSuchObjectError)
00055 {
00056     try {
00057         rREF(Vobject&, v, findObject("a3dl:position"),
00058              string n;
00059              Property* p = meta_cast<Property*>(&v);
00060              if(!p) throw bad_cast();
00061              p->read(n);
00062              sscanf(n.c_str(), "%lg %lg %lg", &x, &y, &z);
00063             );
00064     } catch(bad_cast& e) {
00065         throw NoSuchObjectError(string("Error casting \"position\" object to type \"property\" (") + e.what() + ")");
00066     } catch(exception&  e) {
00067         LOG("viewpoint", 2, "Warning: Runtime error in A3DL::Viewpoint::getPosition()! " << e.what());
00068     }
00069 }
00070 
00071 void Viewpoint::setOrientation(double x, double y, double z, double r) throw(NoSuchObjectError)
00072 {
00073     char c[256];
00074     sprintf(c, "%.15g %.15g %.15g %.15g", x, y, z, r);
00075     try {
00076         Property::setProperty(*this, "a3dl:orientation", string(c), "text/x-vector-float", propac);
00077     } catch(bad_cast e) {
00078         throw NoSuchObjectError(string("Error casting \"orientation\" object to type \"property\" (") + e.what() + ")");
00079     }
00080 }
00081 
00082 void Viewpoint::getOrientation(double& x, double& y, double& z, double& r) throw(NoSuchObjectError)
00083 {
00084     try {
00085         rREF(Vobject&, v, findObject("a3dl:orientation"),
00086              string n;
00087              Property* p = meta_cast<Property*>(&v);
00088              if(!p) throw bad_cast();
00089              p->read(n);
00090              sscanf(n.c_str(), "%lg %lg %lg %lg", &x, &y, &z, &r);
00091             );
00092     } catch(bad_cast e) {
00093         throw NoSuchObjectError(string("Error casting \"orientation\" object to type \"property\" (") + e.what() + ")");
00094     } catch(exception&  e) {
00095         LOG("viewpoint", 2, "Warning: Runtime error in A3DL::Viewpoint::getOrientation()! " << e.what());
00096     }
00097 }
00098 
00099 void Viewpoint::setFOV(double angle) throw(NoSuchObjectError)
00100 {
00101     try {
00102         Property::setProperty(*this, "a3dl:viewpoint-fov", angle, propac);
00103     } catch(bad_cast& e) {
00104         throw NoSuchObjectError(string("Error casting \"viewpoint:fov\" object to type \"property\" (") + e.what() + ")");
00105     }
00106 }
00107 
00108 double Viewpoint::getFOV() throw(NoSuchObjectError)
00109 {
00110     double ret = 0;
00111     try {
00112         rREF(Vobject&, v, findObject("a3dl:viewpoint-fov"),
00113              string n;
00114              Property* p = meta_cast<Property*>(&v);
00115              p->read(n);
00116              sscanf(n.c_str(), "%lg", &ret);
00117             );
00118     } catch(bad_cast& e) {
00119         throw NoSuchObjectError(string("Error casting \"viewpoint:fov\" object to type \"property\" (") + e.what() + ")");
00120     }
00121     return ret;
00122 }
00123 
00124 
00125 void Viewpoint::setTitle(const string& text) throw(NoSuchObjectError)
00126 {
00127     try {
00128         Property::setProperty(*this, "a3dl:title", text, "text/plain", propac);
00129     } catch(bad_cast& e) {
00130         throw NoSuchObjectError(string("Error casting \"title\" object to type \"property\" (") + e.what() + ")");
00131     }
00132 }
00133 
00134 string Viewpoint::getTitle() throw(NoSuchObjectError)
00135 {
00136     string val;
00137     try {
00138         rREF(Vobject&, v, findObject("a3dl:title"),
00139             Property* p = meta_cast<Property*>(&v);
00140             if(!p) throw bad_cast();
00141             p->read(val);
00142         );
00143     } catch(exception& e) {
00144         throw NoSuchObjectError( string("Error getting \"title\" property: ") + e.what() );
00145     }
00146     return val;
00147 }
00148 
00149 
00150 
00151 void Viewpoint::initialize(PropertyAccessControl* access) throw(NoSuchObjectError) {
00152     if(access == NULL)
00153         this->setPropertyAccessControl(&NoPropertyAccessControl::static_);
00154     else
00155         this->setPropertyAccessControl(access);
00156     setPosition(0.0, 0.0, 0.0);
00157     setOrientation(0.0, 0.0, 1, 0);
00158 }
00159 
00160 MetaObject* Viewpoint::new_Viewpoint(MetaObject* superobject, const string& type)
00161 {
00162     return new Viewpoint(superobject);
00163 }
00164 
00165 const string Viewpoint::getType()
00166 {
00167     return "a3dl:viewpoint";
00168 }
00169 
00170 void Viewpoint::registerExtenders()
00171 {
00172     LocalSite::addLocalObjectExtension(typeid(Viewpoint).name(), &Viewpoint::new_Viewpoint);
00173     LocalSite::addLocalObjectExtension("a3dl:viewpoint", &Viewpoint::new_Viewpoint);
00174     RemoteSite::addRemoteObjectExtension(typeid(Viewpoint).name(), &Viewpoint::new_Viewpoint);
00175     RemoteSite::addRemoteObjectExtension("a3dl:viewpoint", &Viewpoint::new_Viewpoint);
00176 }

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