interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/csplugin/vosobject3d.hh

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002    $Id: vosobject3d.h,v 1.26 2006/03/12 02:59:40 tetron Exp $
00003 
00004     This file is part of Crystal Space Virtual Object System Abstract
00005     3D Layer plugin (csvosa3dl).
00006 
00007     Copyright (C) 2004 Peter Amstutz
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with this program; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 #ifndef _CSVOSOBJECT3D_H_
00024 #define _CSVOSOBJECT3D_H_
00025 
00026 #include <vos/metaobjects/a3dl/object3d.hh>
00027 #include <vos/vos/listener.hh>
00028 
00029 #include "csvosa3dl.hh"
00030 #include "vossector.hh"
00031 #include "vosmaterial.hh"
00032 
00033 class csMetaObject3D;
00034 
00035 class csVosObject3D : public csObject,
00036                       public iVosObject3D,
00037                       public iVosApi,
00038                       public iDynamicsMoveCallback
00039 {
00040 private:
00041   csRef<iMeshWrapper> meshwrapper;
00042   csRef<iRigidBody> collider;
00043   VUtil::vRef<csMetaObject3D> object3d;
00044 
00045 public:
00046   SCF_DECLARE_IBASE;
00047 
00048   csVosObject3D(csMetaObject3D* obj3d, VUtil::RefCounted* rc);
00049   virtual ~csVosObject3D();
00050 
00051   virtual csRef<iMeshWrapper> GetMeshWrapper();
00052 
00053   void SetMeshWrapper(iMeshWrapper* mw);
00054 
00055   virtual csRef<iRigidBody> GetCollider();
00056 
00057   void SetCollider (iRigidBody *col);
00058 
00059   virtual VUtil::vRef<VOS::Vobject> GetVobject();
00060 
00061   virtual void Execute (iMeshWrapper* mesh, csOrthoTransform& t);
00062   virtual void Execute (iLight* light, csOrthoTransform& t) { }
00063   virtual void Execute (iCamera* camera, csOrthoTransform& t) { }
00064   virtual void Execute (csOrthoTransform& t);
00065 };
00066 
00067 class csMetaObject3D : public virtual A3DL::Object3D,
00068                        public VOS::PropertyListener,
00069                        public VOS::ChildChangeListener
00070 {
00071 protected:
00072   bool alreadyLoaded;
00073   csRef<csVosObject3D> csvobj3d;
00074   csRef<csVosA3DL> vosa3dl;
00075   csRef<csVosSector> sector;
00076   VUtil::vRef<csMetaMaterial> metamaterial;
00077   bool htvalid;
00078   csColliderActor collider_actor;
00079   bool setupCA;
00080   bool wasZero;
00081 
00082 public:
00083   csMetaObject3D(VOS::VobjectBase* superobject);
00084   virtual ~csMetaObject3D();
00085 
00086   static VOS::MetaObject* new_csMetaObject3D(VOS::VobjectBase* superobject,
00087                                              const std::string& type);
00088 
00089   // Accessor for vosa3dl
00090   csVosA3DL *getVosA3DL () { return vosa3dl; }
00091 
00092   // Set up the object
00093   virtual void Setup(csVosA3DL* vosa3dl, csVosSector* sect);
00094   VUtil::Task* GetSetupTask(csVosA3DL* vosa3dl, csVosSector* sect);
00095 
00096   void updateMaterial ();
00097 
00098   csRef<csVosObject3D> GetCSinterface();
00099   VUtil::vRef<csMetaMaterial> getMetaMaterial() { return metamaterial; }
00100 
00101   // Child change listener for events
00102   virtual void notifyChildInserted (VOS::VobjectEvent &event);
00103   virtual void notifyChildRemoved (VOS::VobjectEvent &event);
00104   virtual void notifyChildReplaced (VOS::VobjectEvent &event);
00105 
00106   // Property listener and callbacks for object property events
00107   virtual void notifyPropertyChange(const VOS::PropertyEvent &event);
00108 
00109   // Reads the position property and sets the CS object
00110   virtual void syncPosition (bool setCollider);
00111 
00112   // Reads the orientation property and sets the CS object
00113   virtual void syncOrientation (bool setCollider);
00114 
00115   virtual void changeMaterial (iMaterialWrapper* mat);
00116 
00117   // This is commented out because CS does not support dynamically changing
00118   // scaling of objects
00119   //virtual void changeScaling (const csMatrix3 &scaling)
00120 
00121   virtual bool supportsPhysics();
00122   virtual void applyForce(double x, double y, double z);
00123   virtual void applyTorque(double x, double y, double z);
00124   virtual void getLinearVelocity(double& x, double& y, double& z);
00125   virtual void getAngularVelocity(double& x, double& y, double& z);
00126 
00127   virtual void moveTo(double x, double y, double z, double timestep);
00128 
00129   void doMoveTo(const csVector3& vec, float timestep);
00130   void setupCollider();
00131   void setupCollider(bool coldet, double gravity);
00132 };
00133 
00134 #endif