This commit is contained in:
81 files changed
+13770
No files matched your search
@@ -0,0 +1,255 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
/**
|
||||
* The camera component holds properties for the osg::Camera object
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT CameraComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ContextIdId;
|
||||
static const dtEntity::StringId LayerAttachPointId;
|
||||
|
||||
static const dtEntity::StringId CullingModeId;
|
||||
static const dtEntity::StringId CullMaskId;
|
||||
static const dtEntity::StringId NoAutoNearFarCullingId;
|
||||
static const dtEntity::StringId BoundingVolumeNearFarCullingId;
|
||||
static const dtEntity::StringId PrimitiveNearFarCullingId;
|
||||
static const dtEntity::StringId FieldOfViewId;
|
||||
static const dtEntity::StringId AspectRatioId;
|
||||
static const dtEntity::StringId NearClipId;
|
||||
static const dtEntity::StringId FarClipId;
|
||||
static const dtEntity::StringId LODScaleId;
|
||||
static const dtEntity::StringId ClearColorId;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId EyeDirectionId;
|
||||
static const dtEntity::StringId UpId;
|
||||
|
||||
static const dtEntity::StringId OrthoLeftId;
|
||||
static const dtEntity::StringId OrthoRightId;
|
||||
static const dtEntity::StringId OrthoTopId;
|
||||
static const dtEntity::StringId OrthoBottomId;
|
||||
static const dtEntity::StringId OrthoZNearId;
|
||||
static const dtEntity::StringId OrthoZFarId;
|
||||
|
||||
static const dtEntity::StringId ProjectionModeId;
|
||||
static const dtEntity::StringId ModePerspectiveId;
|
||||
static const dtEntity::StringId ModeOrthoId;
|
||||
|
||||
CameraComponent();
|
||||
|
||||
virtual ~CameraComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
osg::Camera* GetCamera() const;
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void FetchCamera();
|
||||
|
||||
void SetContextId(int id);
|
||||
int GetContextId() const { return mContextIdVal; }
|
||||
|
||||
void SetLayerAttachPoint(dtEntity::StringId id);
|
||||
dtEntity::StringId GetLayerAttachPoint() const;
|
||||
|
||||
void SetProjectionMode(dtEntity::StringId);
|
||||
dtEntity::StringId GetProjectionMode() const { return mProjectionModeVal; }
|
||||
|
||||
void SetCullingMode(dtEntity::StringId);
|
||||
dtEntity::StringId GetCullingMode() const { return mCullingModeVal; }
|
||||
|
||||
/** Set up vector of camera. Call UpdateViewMatrix to apply changes. */
|
||||
void SetUp(const osg::Vec3d&);
|
||||
osg::Vec3d GetUp() const;
|
||||
|
||||
/** Set eye position of camera. Call UpdateViewMatrix to apply changes. */
|
||||
void SetPosition(const osg::Vec3d&);
|
||||
osg::Vec3d GetPosition() const;
|
||||
|
||||
/** Set look direction of camera. Should be a normalized vector!
|
||||
* Call UpdateViewMatrix to apply changes.
|
||||
*/
|
||||
void SetEyeDirection(const osg::Vec3d&);
|
||||
osg::Vec3d GetEyeDirection() const;
|
||||
|
||||
/**
|
||||
* Re-calculate osg camera view matrix from up, pos and eye dir vectors
|
||||
*/
|
||||
void UpdateViewMatrix();
|
||||
|
||||
/**
|
||||
* Re-calculate osg camera projection matrix from mode, near, far etc
|
||||
*/
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
/**
|
||||
* Set the osg node mask controlling which nodes are
|
||||
* visible to the camera. Please see dtEntity/nodemasks.h
|
||||
*/
|
||||
void SetCullMask(unsigned int mask);
|
||||
unsigned int GetCullMask() const;
|
||||
|
||||
void SetClearColor(const osg::Vec4&);
|
||||
osg::Vec4 GetClearColor() const;
|
||||
|
||||
virtual osg::Vec3d GetTranslation() const { return GetPosition(); }
|
||||
virtual void SetTranslation(const osg::Vec3d& v) { SetPosition(v); }
|
||||
|
||||
virtual osg::Quat GetRotation() const
|
||||
{
|
||||
osg::Quat q;
|
||||
q.makeRotate(osg::Vec3d(0,1,0), mEyeDirection.Get());
|
||||
return q;
|
||||
}
|
||||
|
||||
virtual void SetRotation(const osg::Quat& q)
|
||||
{
|
||||
mEyeDirection.Set(q * osg::Vec3d(0, 1, 0));
|
||||
}
|
||||
|
||||
void SetFieldOfView(double v);
|
||||
double GetFieldOfView() const;
|
||||
|
||||
void SetAspectRatio(double v);
|
||||
double GetAspectRatio() const;
|
||||
|
||||
void SetNearClip(double v);
|
||||
double GetNearClip() const;
|
||||
|
||||
void SetFarClip(double v);
|
||||
double GetFarClip() const;
|
||||
|
||||
void SetLODScale(float v);
|
||||
float GetLODScale() const;
|
||||
|
||||
void SetOrthoLeft(double v);
|
||||
double GetOrthoLeft() const;
|
||||
|
||||
void SetOrthoRight(double v);
|
||||
double GetOrthoRight() const;
|
||||
|
||||
void SetOrthoTop(double v);
|
||||
double GetOrthoTop() const;
|
||||
|
||||
void SetOrthoBottom(double v);
|
||||
double GetOrthoBottom() const;
|
||||
|
||||
void SetOrthoZNear(double v);
|
||||
double GetOrthoZNear() const;
|
||||
|
||||
void SetOrthoZFar(double v);
|
||||
double GetOrthoZFar() const;
|
||||
|
||||
void TryAssignContext();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
dtEntity::DynamicIntProperty mContextId;
|
||||
int mContextIdVal;
|
||||
dtEntity::DynamicStringIdProperty mLayerAttachPoint;
|
||||
dtEntity::StringId mLayerAttachPointVal;
|
||||
|
||||
dtEntity::DynamicStringIdProperty mCullingMode;
|
||||
dtEntity::StringId mCullingModeVal;
|
||||
dtEntity::DynamicDoubleProperty mFieldOfView;
|
||||
double mFieldOfViewVal;
|
||||
dtEntity::DynamicDoubleProperty mAspectRatio;
|
||||
double mAspectRatioVal;
|
||||
dtEntity::DynamicDoubleProperty mNearClip;
|
||||
double mNearClipVal;
|
||||
dtEntity::DynamicDoubleProperty mFarClip;
|
||||
double mFarClipVal;
|
||||
dtEntity::DynamicVec4Property mClearColor;
|
||||
dtEntity::DynamicFloatProperty mLODScale;
|
||||
dtEntity::Vec3dProperty mPosition;
|
||||
dtEntity::Vec3dProperty mUp;
|
||||
dtEntity::Vec3dProperty mEyeDirection;
|
||||
dtEntity::DynamicUIntProperty mCullMask;
|
||||
dtEntity::DynamicStringIdProperty mProjectionMode;
|
||||
dtEntity::StringId mProjectionModeVal;
|
||||
|
||||
dtEntity::DynamicDoubleProperty mOrthoLeft;
|
||||
dtEntity::DynamicDoubleProperty mOrthoRight;
|
||||
dtEntity::DynamicDoubleProperty mOrthoBottom;
|
||||
dtEntity::DynamicDoubleProperty mOrthoTop;
|
||||
dtEntity::DynamicDoubleProperty mOrthoZNear;
|
||||
dtEntity::DynamicDoubleProperty mOrthoZFar;
|
||||
double mOrthoLeftVal;
|
||||
double mOrthoRightVal;
|
||||
double mOrthoBottomVal;
|
||||
double mOrthoTopVal;
|
||||
double mOrthoZNearVal;
|
||||
double mOrthoZFarVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT CameraSystem
|
||||
: public dtEntity::DefaultEntitySystem<CameraComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
CameraSystem(dtEntity::EntityManager& em);
|
||||
~CameraSystem();
|
||||
|
||||
dtEntity::EntityId GetCameraEntityByContextId(int id);
|
||||
|
||||
void OnWindowCreated(const dtEntity::Message& msg);
|
||||
|
||||
private:
|
||||
dtEntity::MessageFunctor mWindowCreatedFunctor;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class ComponentPluginManager;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
void DTENTITY_OSG_EXPORT RegisterStandardFactories(dtEntity::ComponentPluginManager& pluginManager);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// auto-generated by CMake, do not edit!
|
||||
|
||||
// was osgEphemeris found by cmake?
|
||||
#define OSGEPHEMERIS_FOUND 0
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
# ifdef DTENTITY_OSG_LIBRARY
|
||||
# define DTENTITY_OSG_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define DTENTITY_OSG_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define DTENTITY_OSG_EXPORT
|
||||
#endif
|
||||
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/cameracomponent.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/nodemasks.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <osgUtil/IntersectionVisitor>
|
||||
#include <osgUtil/LineSegmentIntersector>
|
||||
#include <osgSim/LineOfSight>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MapSystem;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class GroundClampingComponent : public dtEntity::Component
|
||||
{
|
||||
typedef dtEntity::Component BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ClampingModeId;
|
||||
static const dtEntity::StringId ClampingMode_DisabledId;
|
||||
static const dtEntity::StringId ClampingMode_KeepAboveTerrainId;
|
||||
static const dtEntity::StringId ClampingMode_SetHeightToTerrainHeightId;
|
||||
static const dtEntity::StringId ClampingMode_SetHeightAndRotationToTerrainId;
|
||||
static const dtEntity::StringId MinDistToCameraId;
|
||||
static const dtEntity::StringId MinMovementDeltaId;
|
||||
static const dtEntity::StringId VerticalOffsetId;
|
||||
|
||||
GroundClampingComponent();
|
||||
virtual ~GroundClampingComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& e);
|
||||
virtual void Finished();
|
||||
dtEntityOSG::TransformComponent* GetTransformComponent() const { return mTransformComponent; }
|
||||
|
||||
void SetClampingMode(dtEntity::StringId mode) { mClampingMode.Set(mode); }
|
||||
dtEntity::StringId GetClampingMode() const { return mClampingMode.Get(); }
|
||||
|
||||
float GetVerticalOffset() const { return mVerticalOffset.Get(); }
|
||||
void SetVerticalOffset(float v) { mVerticalOffset.Set(v); }
|
||||
|
||||
// for keeping track of intersections when using osgSim HeightAboveTerrain
|
||||
void SetIntersectIndex(unsigned int i) { mIntersectIndex = i; }
|
||||
unsigned int GetIntersectIndex() const { return mIntersectIndex; }
|
||||
|
||||
osgUtil::LineSegmentIntersector* GetIntersector() const { return mIntersector.get(); }
|
||||
void SetIntersector(osgUtil::LineSegmentIntersector* isect) { mIntersector = isect; }
|
||||
|
||||
void SetLastClampedPosition(const osg::Vec3d& p) { mLastClampedPosition = p; }
|
||||
osg::Vec3d GetLastClampedPosition() const { return mLastClampedPosition; }
|
||||
|
||||
void SetLastClampedAttitude(const osg::Quat& p) { mLastClampedAttitude = p; }
|
||||
osg::Quat GetLastClampedAttitude() const { return mLastClampedAttitude; }
|
||||
|
||||
void SetLastClampedNormal(const osg::Vec3& p) { mLastClampedNormal = p; }
|
||||
osg::Vec3 GetLastClampedNormal() const { return mLastClampedNormal; }
|
||||
|
||||
void SetMinDistToCamera(float p) { mMinDistToCamera.Set(p); }
|
||||
float GetMinDistToCamera() const { return mMinDistToCamera.Get(); }
|
||||
|
||||
void SetMinMovementDelta(float p) { mMinMovementDelta.Set(p); }
|
||||
float GetMinMovementDelta() const { return mMinMovementDelta.Get(); }
|
||||
|
||||
void SetDirty(bool v) { mDirty = v; }
|
||||
bool GetDirty() const { return mDirty; }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::StringIdProperty mClampingMode;
|
||||
dtEntity::FloatProperty mVerticalOffset;
|
||||
dtEntity::FloatProperty mMinDistToCamera;
|
||||
dtEntity::FloatProperty mMinMovementDelta;
|
||||
|
||||
dtEntityOSG::TransformComponent* mTransformComponent;
|
||||
unsigned int mIntersectIndex;
|
||||
dtEntity::Entity* mEntity;
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> mIntersector;
|
||||
osg::Vec3d mLastClampedPosition;
|
||||
osg::Vec3d mLastClampedNormal;
|
||||
|
||||
bool mDirty;
|
||||
osg::Quat mLastClampedAttitude;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class GroundClampingSystem
|
||||
: public dtEntity::DefaultEntitySystem<GroundClampingComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<GroundClampingComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId IntersectLayerId;
|
||||
static const dtEntity::StringId FetchLODsId;
|
||||
|
||||
GroundClampingSystem(dtEntity::EntityManager& em);
|
||||
~GroundClampingSystem();
|
||||
|
||||
void OnRemoveFromEntityManager(dtEntity::EntityManager& em);
|
||||
|
||||
void Tick(const dtEntity::Message& msg);
|
||||
void CameraAdded(const dtEntity::Message& msg);
|
||||
void CameraRemoved(const dtEntity::Message& msg);
|
||||
void MapLoaded(const dtEntity::Message& msg);
|
||||
|
||||
bool ClampToTerrain(osg::Vec3d& position, int voffset = 10000, unsigned int nodemask = dtEntity::NodeMasks::TERRAIN);
|
||||
|
||||
void SetIntersectLayer(dtEntity::StringId);
|
||||
dtEntity::StringId GetIntersectLayer() const;
|
||||
|
||||
|
||||
virtual bool StorePropertiesToScene() const { return true; }
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
private:
|
||||
|
||||
dtEntity::Property* ScriptGetTerrainHeight(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntityOSG::TransformComponent* GetTransformComp(dtEntity::EntityId eid, GroundClampingComponent* component);
|
||||
void DirtyAll();
|
||||
void HandleIntersection(GroundClampingComponent* component,
|
||||
const osgUtil::LineSegmentIntersector::Intersection& intersection, float dt, double simTime);
|
||||
|
||||
dtEntity::MessageFunctor mTickFunctor;
|
||||
dtEntity::MessageFunctor mCameraAddedFunctor;
|
||||
dtEntity::MessageFunctor mCameraRemovedFunctor;
|
||||
dtEntity::MessageFunctor mMapLoadedFunctor;
|
||||
osgUtil::IntersectionVisitor mIntersectionVisitor;
|
||||
osg::observer_ptr<osg::Node> mRootNode;
|
||||
osg::ref_ptr<osgUtil::IntersectorGroup> mIntersectorGroup;
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
dtEntity::DynamicStringIdProperty mIntersectLayer;
|
||||
dtEntity::StringId mIntersectLayerVal;
|
||||
dtEntity::BoolProperty mFetchLODs;
|
||||
|
||||
osgSim::LineOfSight mLos;
|
||||
dtEntityOSG::CameraComponent* mCamera;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
/**
|
||||
* Holds a single OSG group.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT GroupComponent : public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId ChildrenId;
|
||||
|
||||
/**
|
||||
* CTor, creates a new group component
|
||||
*/
|
||||
GroupComponent();
|
||||
|
||||
/**
|
||||
* CTor, uses passed group component
|
||||
*/
|
||||
GroupComponent(osg::Group* group);
|
||||
|
||||
virtual ~GroupComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
virtual osg::Group* GetGroup() const;
|
||||
|
||||
// return group to attach children to
|
||||
virtual osg::Group* GetAttachmentGroup() const { return GetGroup(); }
|
||||
|
||||
bool AddChildComponent(dtEntity::ComponentType c);
|
||||
bool RemoveChildComponent(dtEntity::ComponentType c);
|
||||
|
||||
/**
|
||||
* Expects an array of stringid properties containing component types
|
||||
* of children. These will be attached.
|
||||
*/
|
||||
void SetChildren(const dtEntity::PropertyArray& arr);
|
||||
dtEntity::PropertyArray GetChildren() const { return mChildrenVal.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
// to prevent redundant code in constructors
|
||||
void Init();
|
||||
|
||||
dtEntity::DynamicArrayProperty mChildren;
|
||||
dtEntity::ArrayProperty mChildrenVal;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT GroupSystem
|
||||
: public dtEntity::DefaultEntitySystem<GroupComponent>
|
||||
{
|
||||
public:
|
||||
GroupSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<GroupComponent>(em, NodeComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/logmanager.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
}
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
class ViewerBase;
|
||||
}
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Convenience setup function for dtEntity.
|
||||
* If you want to do fancy stuff in your setup then maybe you should not call this, instead write your own!
|
||||
*
|
||||
* Installs a log handler, calls SetupDataPaths(), calls InitDtEntity(), calls SetupViewer(), then calls DoScreenSetup()
|
||||
* @param argc number of command line args
|
||||
* @param standard c command line args
|
||||
* @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer
|
||||
* @param em a valid entity manager
|
||||
* @param addStatsHandler Should osg stats handler be installed (activated with key insert)
|
||||
* @param checkPaths Should SetupDataPaths complain about missing paths
|
||||
* @param addConsoleLog Should log messages be output to console
|
||||
* @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also
|
||||
* the main update callback that drives dtEntity is installed to this node. If this is NULL, a new osg::Group is created
|
||||
*/
|
||||
bool DTENTITY_OSG_EXPORT InitOSGViewer(int argc, char** argv,
|
||||
osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em,
|
||||
bool addStatsHandler = true, bool checkPaths = true, bool addConsoleLog = true, osg::Group* pSceneNode = 0);
|
||||
|
||||
|
||||
/**
|
||||
* Sets scene graph root node and adds callbacks
|
||||
* @param viewer An instance of either osgViewer::Viewer or osgViewer::CompositeViewer
|
||||
* @param pSceneNode An osg group that is used as scene graph root node. This is added as scene node to the main scene, also
|
||||
* the main update callback that drives dtEntity is installed to this node.
|
||||
*/
|
||||
void DTENTITY_OSG_EXPORT SetupSceneGraph(osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em, osg::Group* pSceneNode);
|
||||
|
||||
|
||||
/**
|
||||
* analyze command line and open OSG window with correct traits
|
||||
* @return true if success
|
||||
*/
|
||||
bool DTENTITY_OSG_EXPORT DoScreenSetup(int argc, char** argv, osgViewer::ViewerBase& viewer, dtEntity::EntityManager& em);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Group>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerAttachPointComponent
|
||||
: public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId NameId;
|
||||
|
||||
LayerAttachPointComponent();
|
||||
virtual ~LayerAttachPointComponent();
|
||||
virtual void Finished();
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
/**
|
||||
* Set osg group node that will hold layer component nodes
|
||||
* as children. When this is set, all layer components are
|
||||
* traversed and their nodes are attached to this group node
|
||||
* if the layer name fits
|
||||
*/
|
||||
virtual void SetNode(osg::Group* node);
|
||||
|
||||
|
||||
/**
|
||||
* Get name SID identifying this layer attach point
|
||||
*/
|
||||
dtEntity::StringId GetName() const { return mName.Get(); }
|
||||
|
||||
/**
|
||||
* Set name SID identifying this layer attach point.
|
||||
* When the name is changed all layer components are
|
||||
* traversed and their nodes are attached to this group node
|
||||
* if the layer name fits
|
||||
*/
|
||||
void SetName(dtEntity::StringId name);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
dtEntity::StringIdProperty mName;
|
||||
dtEntity::StringId mCurrentName;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerAttachPointSystem
|
||||
: public dtEntity::DefaultEntitySystem<LayerAttachPointComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
friend class LayerAttachPointComponent;
|
||||
|
||||
typedef dtEntity::DefaultEntitySystem<LayerAttachPointComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId DefaultLayerId;
|
||||
static const dtEntity::StringId RootId;
|
||||
|
||||
LayerAttachPointSystem(dtEntity::EntityManager& em);
|
||||
|
||||
virtual bool DeleteComponent(dtEntity::EntityId eid);
|
||||
|
||||
bool GetByName(dtEntity::StringId name, LayerAttachPointComponent*& recipient);
|
||||
|
||||
LayerAttachPointComponent* GetDefaultLayer();
|
||||
LayerAttachPointComponent* GetRootLayer();
|
||||
|
||||
osg::Group* GetSceneGraphRoot()
|
||||
{
|
||||
return mSceneGraphRoot.get();
|
||||
}
|
||||
|
||||
void CreateSceneGraphRootEntity(osg::Group* root);
|
||||
|
||||
dtEntity::Property* ScriptGetByName(const dtEntity::PropertyArgs& args);
|
||||
|
||||
private:
|
||||
|
||||
void RegisterByName(dtEntity::StringId, LayerAttachPointComponent*);
|
||||
typedef std::map<dtEntity::StringId, LayerAttachPointComponent*> LayerByNameMap;
|
||||
LayerByNameMap mLayerByNameMap;
|
||||
osg::ref_ptr<osg::Group> mSceneGraphRoot;
|
||||
dtEntity::EntityId mBaseEntityId;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class LayerAttachPointComponent;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct EntityData : public osg::Referenced
|
||||
{
|
||||
dtEntity::Entity* mEntity;
|
||||
EntityData(dtEntity::Entity* e)
|
||||
: mEntity(e)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Each visible entity has to have a layer component. The layer component
|
||||
* defines which node component of the entity is attached to which layer.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT LayerComponent
|
||||
: public dtEntity::Component
|
||||
{
|
||||
|
||||
friend class LayerSystem;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId LayerId;
|
||||
static const dtEntity::StringId AttachedComponentId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
|
||||
LayerComponent();
|
||||
virtual ~LayerComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attached component is the component that should be attached
|
||||
* to the layer. A component with this type has to be present on
|
||||
* the entity and it has to derive from NodeComponent.
|
||||
*/
|
||||
void SetAttachedComponent(dtEntity::ComponentType ctype);
|
||||
dtEntity::ComponentType GetAttachedComponent() const;
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity &entity);
|
||||
|
||||
void OnAddedToScene();
|
||||
void OnRemovedFromScene();
|
||||
|
||||
/**
|
||||
* Attach the entity to the layer with this name. Default value is DefaultLayerId
|
||||
*/
|
||||
dtEntity::StringId GetLayer() const;
|
||||
void SetLayer(dtEntity::StringId);
|
||||
|
||||
/**
|
||||
* Is the AttachedComponent currently attached to the layer node?
|
||||
*/
|
||||
bool IsVisible() const;
|
||||
|
||||
/**
|
||||
* Set to false to detach AttachedComponent from the layer node.
|
||||
* Re-attach by setting to true.
|
||||
*/
|
||||
void SetVisible(bool);
|
||||
|
||||
/**
|
||||
* Is the entity already added to scene? Can be used to query current initialization status
|
||||
*/
|
||||
bool IsAddedToScene() const { return mAddedToScene; }
|
||||
|
||||
/**
|
||||
* Get OSG node of attached component
|
||||
*/
|
||||
osg::Node* GetAttachedComponentNode() const;
|
||||
|
||||
/**
|
||||
* @return bool if geometry is attached to layer component
|
||||
*/
|
||||
bool GetBoundingBox(dtEntity::Vec3d& min, dtEntity::Vec3d& max);
|
||||
|
||||
/**
|
||||
* Add attached component node to layer as a child in the scene graph hierarchy
|
||||
*/
|
||||
bool Attach(LayerAttachPointComponent* current);
|
||||
|
||||
/**
|
||||
* Add attached component node to layer as a child in the scene graph hierarchy
|
||||
*/
|
||||
bool Detach(LayerAttachPointComponent* current);
|
||||
|
||||
private:
|
||||
|
||||
// is there an attach point, a component to attach and added to scene?
|
||||
bool CanAttach();
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
bool mVisibleVal;
|
||||
dtEntity::DynamicStringIdProperty mLayer;
|
||||
dtEntity::StringId mLayerVal;
|
||||
dtEntity::DynamicStringIdProperty mAttachedComponent;
|
||||
dtEntity::StringId mAttachedComponentVal;
|
||||
bool mAddedToScene;
|
||||
|
||||
};
|
||||
|
||||
LayerAttachPointComponent* GetAttachPoint(dtEntity::EntityManager& em, dtEntity::StringId name);
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LayerSystem
|
||||
: public dtEntity::DefaultEntitySystem<LayerComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId VisibilityBitsId;
|
||||
|
||||
LayerSystem(dtEntity::EntityManager& em);
|
||||
~LayerSystem();
|
||||
|
||||
void OnEnterWorld(const dtEntity::Message&);
|
||||
void OnLeaveWorld(const dtEntity::Message&);
|
||||
|
||||
void AddVisibleBoundingBox(dtEntity::EntityId id);
|
||||
void RemoveVisibleBoundingBox(dtEntity::EntityId id);
|
||||
void RemoveAllBoundingBoxes();
|
||||
|
||||
// set or clear these bits when visibility of component is toggled
|
||||
void SetVisibilityBits(unsigned int bits) { mVisibilityBits.Set(bits); }
|
||||
unsigned int GetVisibilityBits() const { return mVisibilityBits.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::Property* ScriptAddVisibleBoundingBox(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
AddVisibleBoundingBox(args[0]->UIntValue());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptRemoveVisibleBoundingBox(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
RemoveVisibleBoundingBox(args[0]->UIntValue());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptRemoveAllBoundingBoxes(const dtEntity::PropertyArgs& args)
|
||||
{
|
||||
RemoveAllBoundingBoxes();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dtEntity::Property* ScriptGetBoundingSphere(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntity::MessageFunctor mEnterWorldFunctor;
|
||||
dtEntity::MessageFunctor mLeaveWorldFunctor;
|
||||
|
||||
dtEntity::UIntProperty mVisibilityBits;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/entity.h>
|
||||
#include <dtEntity/entityid.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Light;
|
||||
class LightSource;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT LightComponent : public NodeComponent
|
||||
{
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId LightNumId;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId AmbientId;
|
||||
static const dtEntity::StringId DiffuseId;
|
||||
static const dtEntity::StringId SpecularId;
|
||||
static const dtEntity::StringId SpotCutoffId;
|
||||
static const dtEntity::StringId SpotExponentId;
|
||||
static const dtEntity::StringId DirectionId;
|
||||
static const dtEntity::StringId ConstantAttenuationId;
|
||||
static const dtEntity::StringId LinearAttenuationId;
|
||||
static const dtEntity::StringId QuadraticAttenuationId;
|
||||
|
||||
LightComponent();
|
||||
virtual ~LightComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
osg::Light* GetLight() { return mLight; }
|
||||
|
||||
private:
|
||||
|
||||
osg::Vec4 GetLightPosition() const;
|
||||
osg::Vec4 GetAmbient() const;
|
||||
osg::Vec4 GetDiffuse() const;
|
||||
osg::Vec4 GetSpecular() const;
|
||||
osg::Vec3 GetDirection() const;
|
||||
|
||||
osg::Light* mLight;
|
||||
dtEntity::DynamicIntProperty mLightNum;
|
||||
dtEntity::DynamicVec4Property mAmbient;
|
||||
dtEntity::DynamicVec4Property mDiffuse;
|
||||
dtEntity::DynamicVec4Property mSpecular;
|
||||
dtEntity::DynamicVec4Property mPosition;
|
||||
dtEntity::DynamicVec3Property mDirection;
|
||||
dtEntity::DynamicFloatProperty mConstantAttenuation;
|
||||
dtEntity::DynamicFloatProperty mLinearAttenuation;
|
||||
dtEntity::DynamicFloatProperty mQuadraticAttenuation;
|
||||
dtEntity::DynamicFloatProperty mSpotExponent;
|
||||
dtEntity:: DynamicFloatProperty mSpotCutOff;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT LightSystem
|
||||
: public dtEntity::DefaultEntitySystem<LightComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<LightComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
LightSystem(dtEntity::EntityManager& em);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <osgManipulator/Dragger>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class ManipulatorComponent
|
||||
: public dtEntityOSG::NodeComponent
|
||||
{
|
||||
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId LayerId;
|
||||
static const dtEntity::StringId DraggerTypeId;
|
||||
static const dtEntity::StringId OffsetFromStartId;
|
||||
static const dtEntity::StringId KeepSizeConstantId;
|
||||
static const dtEntity::StringId UseLocalCoordsId;
|
||||
static const dtEntity::StringId PivotAtBottomId;
|
||||
|
||||
static const dtEntity::StringId TabPlaneDraggerId;
|
||||
static const dtEntity::StringId TabPlaneTrackballDraggerId;
|
||||
static const dtEntity::StringId TabBoxTrackballDraggerId;
|
||||
static const dtEntity::StringId TrackballDraggerId;
|
||||
static const dtEntity::StringId Translate1DDraggerId;
|
||||
static const dtEntity::StringId Translate2DDraggerId;
|
||||
static const dtEntity::StringId TranslateAxisDraggerId;
|
||||
static const dtEntity::StringId TabBoxDraggerId;
|
||||
static const dtEntity::StringId TerrainTranslateDraggerId;
|
||||
static const dtEntity::StringId ScaleDraggerId;
|
||||
|
||||
|
||||
ManipulatorComponent();
|
||||
virtual ~ManipulatorComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& e);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& e);
|
||||
virtual void Finished();
|
||||
|
||||
osgManipulator::Dragger* GetDragger() const;
|
||||
|
||||
/**
|
||||
* Attach the dragger to the layer with this name. Default value is DefaultLayerId
|
||||
*/
|
||||
dtEntity::StringId GetLayer() const;
|
||||
void SetLayer(dtEntity::StringId);
|
||||
|
||||
dtEntity::StringId GetDraggerType() const { return mDraggerTypeVal; }
|
||||
void SetDraggerType(dtEntity::StringId);
|
||||
|
||||
void SetOffsetFromStart(const osg::Vec3d& v);
|
||||
osg::Vec3d GetOffsetFromStart() const { return mOffsetFromStartVal; }
|
||||
|
||||
void SetUseLocalCoords(bool v);
|
||||
bool GetUseLocalCoords() const { return mUseLocalCoordsVal; }
|
||||
|
||||
void SetKeepSizeConstant(bool v);
|
||||
bool GetKeepSizeConstant() const { return mKeepSizeConstantVal; }
|
||||
|
||||
void SetPivotAtBottom(bool v);
|
||||
bool GetPivotAtBottom() const { return mPivotAtBottomVal; }
|
||||
|
||||
private:
|
||||
|
||||
void RemoveFromParent();
|
||||
void AddToLayer();
|
||||
|
||||
osg::ref_ptr<osgManipulator::DraggerCallback> mDraggerCallback;
|
||||
dtEntity::DynamicStringIdProperty mLayerProperty;
|
||||
dtEntity::StringId mLayerVal;
|
||||
dtEntity::StringId mAttachPoint;
|
||||
dtEntity::DynamicStringIdProperty mDraggerType;
|
||||
dtEntity::StringId mDraggerTypeVal;
|
||||
dtEntity::DynamicVec3dProperty mOffsetFromStart;
|
||||
osg::Vec3 mOffsetFromStartVal;
|
||||
dtEntity::DynamicBoolProperty mKeepSizeConstant;
|
||||
bool mKeepSizeConstantVal;
|
||||
dtEntity::DynamicBoolProperty mUseLocalCoords;
|
||||
bool mUseLocalCoordsVal;
|
||||
dtEntity::DynamicBoolProperty mPivotAtBottom;
|
||||
bool mPivotAtBottomVal;
|
||||
osg::ref_ptr<osg::Group> mDraggerContainer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ManipulatorSystem
|
||||
: public dtEntity::DefaultEntitySystem<ManipulatorComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ManipulatorComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId UseLocalCoordsId;
|
||||
static const dtEntity::StringId UseGroundClampingId;
|
||||
|
||||
ManipulatorSystem(dtEntity::EntityManager& em);
|
||||
~ManipulatorSystem();
|
||||
|
||||
// don't store manipulators to map
|
||||
virtual bool StoreComponentsToMap() const { return false; }
|
||||
|
||||
// don't copy manipulators with entities, also don't store to spawners
|
||||
virtual bool AllowComponentCreationBySpawner() const { return false; }
|
||||
|
||||
void SetUseLocalCoords(bool v);
|
||||
bool GetUseLocalCoords() const { return mUseLocalCoordsVal; }
|
||||
|
||||
void SetUseGroundClamping(bool v) { mUseGroundClamping.Set(v); }
|
||||
bool GetUseGroundClamping() const { return mUseGroundClamping.Get(); }
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mUseLocalCoords;
|
||||
bool mUseLocalCoordsVal;
|
||||
dtEntity::BoolProperty mUseGroundClamping;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osgManipulator/Dragger>
|
||||
#include <osgManipulator/TabBoxDragger>
|
||||
#include <osgManipulator/TabBoxTrackballDragger>
|
||||
#include <osgManipulator/TabPlaneDragger>
|
||||
#include <osgManipulator/TabPlaneTrackballDragger>
|
||||
#include <osgManipulator/TrackballDragger>
|
||||
#include <osgManipulator/Translate1DDragger>
|
||||
#include <osgManipulator/Translate2DDragger>
|
||||
#include <osgManipulator/TranslateAxisDragger>
|
||||
#include <osgManipulator/Scale1DDragger>
|
||||
#include <osgManipulator/ScaleAxisDragger>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class TerrainTranslateDragger : public osgManipulator::CompositeDragger
|
||||
{
|
||||
typedef osgManipulator::CompositeDragger BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
TerrainTranslateDragger();
|
||||
virtual void setupDefaultGeometry();
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _xDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _yDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate1DDragger> _zDragger;
|
||||
osg::ref_ptr<osgManipulator::Translate2DDragger > _translate2DDragger;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ScaleAllDragger : public osgManipulator::Dragger
|
||||
{
|
||||
public:
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
|
||||
|
||||
protected:
|
||||
osg::Vec2 _startPoint;
|
||||
osg::Matrix _localToWorld;
|
||||
osg::Matrix _worldToLocal;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ScaleDragger : public osgManipulator::CompositeDragger
|
||||
{
|
||||
typedef osgManipulator::CompositeDragger BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
ScaleDragger();
|
||||
virtual void setupDefaultGeometry();
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
private:
|
||||
void setupGeometry(osgManipulator::Scale1DDragger*, const osg::Vec4& color);
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _xDragger;
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _yDragger;
|
||||
osg::ref_ptr<osgManipulator::Scale1DDragger> _zDragger;
|
||||
osg::ref_ptr<ScaleAllDragger> _scaleAllDragger;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class TrackballDragger : public osgManipulator::TrackballDragger
|
||||
{
|
||||
typedef osgManipulator::TrackballDragger BaseClass;
|
||||
public:
|
||||
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class MatrixTransform;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* holds a single matrix transform
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT MatrixTransformComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MatrixId;
|
||||
|
||||
MatrixTransformComponent();
|
||||
MatrixTransformComponent(osg::MatrixTransform* trans);
|
||||
|
||||
virtual ~MatrixTransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
const osg::MatrixTransform* GetMatrixTransform() const;
|
||||
osg::MatrixTransform* GetMatrixTransform();
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const;
|
||||
virtual void SetMatrix(const dtEntity::Matrix& m);
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getTrans();
|
||||
}
|
||||
|
||||
virtual void SetTranslation(const dtEntity::Vec3d& t)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m.setTrans(t);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getRotate();
|
||||
}
|
||||
|
||||
virtual void SetRotation(const dtEntity::Quat& q)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m.setRotate(q);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
virtual dtEntity::Vec3d GetScale() const
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
return m.getScale();
|
||||
}
|
||||
|
||||
virtual void SetScale(const dtEntity::Vec3d& v)
|
||||
{
|
||||
dtEntity::Matrix m = GetMatrix();
|
||||
m = m.scale(v);
|
||||
SetMatrix(m);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicMatrixProperty mMatrix;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT MatrixTransformSystem
|
||||
: public dtEntity::DefaultEntitySystem<MatrixTransformComponent>
|
||||
{
|
||||
public:
|
||||
MatrixTransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<MatrixTransformComponent>(em, TransformComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Node>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT NodeStore
|
||||
{
|
||||
public:
|
||||
|
||||
NodeStore();
|
||||
NodeStore(osg::Node* node);
|
||||
virtual ~NodeStore();
|
||||
|
||||
/**
|
||||
* returns encapsulated node
|
||||
*/
|
||||
virtual osg::Node* GetNode() const;
|
||||
|
||||
/**
|
||||
* Sets encapsulated node. Also, if the currently held node
|
||||
* is attached as a child to another component then it is
|
||||
* removed from that parent and the passed node is added as a child
|
||||
*/
|
||||
virtual void SetNode(osg::Node* node);
|
||||
|
||||
/**
|
||||
* type of compponent that this node component is attached to.
|
||||
* Is 0 if not attached to a parent
|
||||
*/
|
||||
dtEntity::ComponentType GetParentComponent() const { return mParentComponent; }
|
||||
void SetParentComponent(dtEntity::ComponentType c) { mParentComponent = c; }
|
||||
|
||||
void ClearFromParent();
|
||||
|
||||
void SetNodeMask(unsigned int nodemask, bool recursive = false);
|
||||
unsigned int GetNodeMask() const;
|
||||
|
||||
void SetNodeEntity(dtEntity::Entity*);
|
||||
dtEntity::Entity* GetNodeEntity();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Node> mNode;
|
||||
dtEntity::ComponentType mParentComponent;
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Holds a single OSG node. Subclass this if you want to wrap an object
|
||||
* derived from osg::Node. NodeComponent instances can be attached to
|
||||
* the scene by the Layer system.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT NodeComponent
|
||||
: public dtEntity::Component
|
||||
, public NodeStore
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
NodeComponent();
|
||||
NodeComponent(osg::Node* node);
|
||||
virtual ~NodeComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity& entity);
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT NodeSystem
|
||||
: public dtEntity::DefaultEntitySystem<NodeComponent>
|
||||
{
|
||||
public:
|
||||
NodeSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<NodeComponent>(em)
|
||||
{
|
||||
|
||||
}
|
||||
};}
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
class NodeMaskVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
NodeMaskVisitor(unsigned int mask) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
|
||||
{
|
||||
mMask = mask;
|
||||
}
|
||||
|
||||
virtual void apply(osg::Group& node)
|
||||
{
|
||||
node.setNodeMask(mMask);
|
||||
this->traverse(node);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
unsigned int mMask;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT OSGAnimationComponent : public dtEntity::Component
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
OSGAnimationComponent();
|
||||
virtual ~OSGAnimationComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
osgAnimation::BasicAnimationManager* GetAnimationManager() const
|
||||
{
|
||||
return mAnimationManager;
|
||||
}
|
||||
|
||||
void SetupMesh(osg::Node*);
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const;
|
||||
|
||||
bool AddAttachment(const std::string& boneName, osg::Node* node, const osg::Matrix& m);
|
||||
bool RemoveAtachment(const std::string& boneName, osg::Node* node);
|
||||
void RemoveAtachments(const std::string& boneName);
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager;
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT OSGAnimationSystem
|
||||
: public dtEntity::DefaultEntitySystem<OSGAnimationComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId VertexShaderId;
|
||||
static const dtEntity::StringId FragmentShaderId;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
OSGAnimationSystem(dtEntity::EntityManager& em);
|
||||
~OSGAnimationSystem();
|
||||
|
||||
void OnMeshChanged(const dtEntity::Message&);
|
||||
|
||||
void SetVertexShader(const std::string& v) { mVertexShader.Set(v); }
|
||||
std::string GetVertexShader() const { return mVertexShader.Get(); }
|
||||
|
||||
void SetFragmentShader(const std::string& v) { mFragmentShader.Set(v); }
|
||||
std::string GetFragmentShader() const { return mFragmentShader.Get(); }
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
bool GetAnimationList(dtEntity::EntityId id, const osgAnimation::AnimationList*& list,
|
||||
osgAnimation::BasicAnimationManager*& manager);
|
||||
dtEntity::Property* ScriptPlayAnimation(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptStopAnimation(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimations(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimationLength(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetAnimationPlayMode(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetAnimationPlayMode(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptAddAttachment(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptRemoveAttachments(const dtEntity::PropertyArgs& args);
|
||||
|
||||
dtEntity::MessageFunctor mMeshChangedFunctor;
|
||||
dtEntity::StringProperty mVertexShader;
|
||||
dtEntity::StringProperty mFragmentShader;
|
||||
bool mEnabledVal;
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/debugdrawinterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/entitymanager.h>
|
||||
#include <dtEntityOSG/layerattachpointcomponent.h>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Group>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Geode;
|
||||
class Geometry;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Can be used to add simple debug geometry to the scene. Each debug graphics primitive is added
|
||||
* together with a lifetime / duration.
|
||||
* If you want to do per-frame drawing, simply set a duration of 0 and
|
||||
* execute the draw each frame.
|
||||
* Warning: To use, first do SetEnabled(true), it is off by default!
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT OSGDebugDrawInterface
|
||||
: public dtEntity::DebugDrawInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param layer Add debug draw manager to layer of this name
|
||||
*/
|
||||
OSGDebugDrawInterface(dtEntity::EntityManager& em,
|
||||
dtEntity::StringId layer = dtEntity::StringId());
|
||||
~OSGDebugDrawInterface();
|
||||
|
||||
/**
|
||||
* message functors, don't call directly
|
||||
*/
|
||||
void Tick(const dtEntity::Message& msg);
|
||||
void OnEnable(const dtEntity::Message& m);
|
||||
|
||||
/**
|
||||
* Draw a single point
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddPoint(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color,
|
||||
int size = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw multiple points
|
||||
* @param positions A vector of point positions
|
||||
* @param color Draw with this color
|
||||
* @param size Size of points in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddPoints(const std::vector<dtEntity::Vec3f>& positions, const dtEntity::Vec4f& color,
|
||||
int size = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a single line
|
||||
* @param start Line starts here
|
||||
* @param end Line ends here
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddLine(const dtEntity::Vec3f& start, const dtEntity::Vec3f& end,
|
||||
const dtEntity::Vec4f& color, int linewidth = 1, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a number of lines
|
||||
* @param lines A vector containing two entries for each line. So to draw two lines you have to have four entries.
|
||||
* @param color Draw with this color
|
||||
* @param linewidth Width of line in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddLines(const std::vector<dtEntity::Vec3f>& lines, const dtEntity::Vec4f& color,
|
||||
int linewidth = 1, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a 3d cross
|
||||
* @param position Draw point here
|
||||
* @param color Draw with this color
|
||||
* @param size length of each arm
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddCross(const dtEntity::Vec3f& position, const dtEntity::Vec4f& color, float size,
|
||||
float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a sphere
|
||||
* @param position Draw sphere here
|
||||
* @param radius radius of sphere
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddSphere(const dtEntity::Vec3f& position, float radius, const dtEntity::Vec4f& color,
|
||||
float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a single triangle
|
||||
* @param vert0 First vertex of triangle
|
||||
* @param vert1 Second vertex of triangle
|
||||
* @param vert2 Third vertex of triangle
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddTriangle(const dtEntity::Vec3f& vert0, const dtEntity::Vec3f& vert1,
|
||||
const dtEntity::Vec3f& vert2, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw multiple triangles
|
||||
* @param verts A vector containing triangle verts. The vector should contain three entries for each triangle.
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw in pixels
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddTriangles(const std::vector<dtEntity::Vec3f>& verts, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a mesh
|
||||
* @param geometry The OSG geometry that should be drawn
|
||||
* @param position Draw geometry here
|
||||
* @param lineColor Draw wireframe with this color. If alpha value is 0 then wireframe will not be drawn
|
||||
* @param lineWidth Draw wireframe with this line with. If value is 0 then wireframe will not be drawn
|
||||
* @param faceColor Draw polygons with this color. Blending is enabled, so feel free to set an alpha value.
|
||||
* Alpha value 0 means no polygons are drawn
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddMesh(osg::Geometry* geometry, const dtEntity::Vec3f& position,
|
||||
const dtEntity::Vec4f& lineColor, int lineWidth,
|
||||
const dtEntity::Vec4f& faceColor, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a circle
|
||||
* @param position Center of circle is here
|
||||
* @param planeNormal A normal vector pointing away from the face of the disk
|
||||
* @param radius Radius of disk
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddCircle(const dtEntity::Vec3f& position, const dtEntity::Vec3f& planeNormal,
|
||||
float radius, const dtEntity::Vec4f& color, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw a text string
|
||||
* @param position Draw text here
|
||||
* @param str The text to draw
|
||||
* @param color Draw with this color
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddString(const dtEntity::Vec3f& position, const std::string& str,
|
||||
const dtEntity::Vec4f& color, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Draw an axis aligned bounding box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddAABB(const dtEntity::Vec3f& minCoords, const dtEntity::Vec3f& maxCoords,
|
||||
const dtEntity::Vec4f& color, int lineWidth, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add an oriented bounding box
|
||||
* @param matrix transformation matrix to apply to box
|
||||
* @param minCoords start box from here
|
||||
* @param maxCoords end box here
|
||||
* @param color Draw with this color
|
||||
* @param lineWidth with of line to draw
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddOBB(const dtEntity::Matrix& matrix, const dtEntity::Vec3f& minCoords,
|
||||
const dtEntity::Vec3f& maxCoords, const dtEntity::Vec4f& color,
|
||||
int lineWidth, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add a cross showing coordinate orientation
|
||||
* @param matrix transformation cross by this matrix
|
||||
* @param color Draw with this color
|
||||
* @param size length of cross arms
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddAxes(const dtEntity::Matrix& matrix, const dtEntity::Vec4f& color,
|
||||
float size, float duration = 0, bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* Add an OSG drawable
|
||||
* @param drawable Add this drawable
|
||||
* @param duration Show for how many seconds. Value 0 means draw once
|
||||
* @param depthTestEnabled if false, always draw on top
|
||||
*/
|
||||
void AddDrawable(osg::Drawable* drawable, float duration = 0,
|
||||
bool depthTestEnabled = true);
|
||||
|
||||
/**
|
||||
* DebugDrawInterface is disabled by default, enable it!
|
||||
*/
|
||||
void SetEnabled(bool enabled);
|
||||
bool IsEnabled() const;
|
||||
|
||||
/**
|
||||
* Immediately remove all debug geometry
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/**
|
||||
If context id is set then a redraw of that context is requested from OSG.
|
||||
Only relevant when render on demand is used.
|
||||
*/
|
||||
void SetContextId(unsigned int v)
|
||||
{
|
||||
mContextId = v;
|
||||
mContextIdSet = true;
|
||||
}
|
||||
unsigned int GetContextId() const { return mContextId; }
|
||||
|
||||
private:
|
||||
bool mEnabled;
|
||||
|
||||
// osg group with stateset depth test enabled
|
||||
osg::ref_ptr<osg::Group> mGroupDepthTest;
|
||||
|
||||
// osg group with stateset depth test disabled
|
||||
osg::ref_ptr<osg::Group> mGroupNoDepthTest;
|
||||
|
||||
double mCurrentTime;
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
dtEntity::MessageFunctor mEnableFunctor;
|
||||
dtEntity::MessageFunctor mTickFunctor;
|
||||
dtEntity::StringId mLayerName;
|
||||
int mContextId;
|
||||
bool mContextIdSet;
|
||||
void RequestRedraw();
|
||||
};
|
||||
|
||||
inline OSGDebugDrawInterface* GetOSGDebugDrawInterface()
|
||||
{
|
||||
return static_cast<OSGDebugDrawInterface*>(dtEntity::GetDebugDrawInterface());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/inputinterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <sstream>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MessagePump;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// for use with GuiEventAdapter user event
|
||||
class MouseEnterLeaveEvent : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
bool mFocused;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT OSGInputInterface
|
||||
: public dtEntity::InputInterface
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// can't make OSGInputInterface derive from osgGA::GUIEventHandler because
|
||||
// we don't want to inherit osg::Referenced stuff
|
||||
class EventHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
OSGInputInterface* mIface;
|
||||
public:
|
||||
EventHandler(OSGInputInterface* i)
|
||||
: mIface(i)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* o, osg::NodeVisitor* nv)
|
||||
{
|
||||
return mIface->handle(ea, aa, o, nv);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
osgGA::GUIEventHandler* GetEventHandler() { return mEventHandler; }
|
||||
|
||||
typedef std::map<std::string, osgGA::GUIEventAdapter::KeySymbol> KeyNames;
|
||||
typedef std::map<int, std::string> KeyNamesReverse;
|
||||
|
||||
OSGInputInterface(dtEntity::MessagePump&);
|
||||
virtual ~OSGInputInterface();
|
||||
|
||||
//virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*);
|
||||
|
||||
virtual void AddInputCallback(dtEntity::InputCallbackInterface*);
|
||||
virtual bool RemoveInputCallback(dtEntity::InputCallbackInterface*);
|
||||
|
||||
/**
|
||||
* Stores if current system is multitouch-capable
|
||||
*/
|
||||
virtual bool GetMultiTouchEnabled() const { return mMultiTouchEnabled; }
|
||||
virtual void SetMultiTouchEnabled(bool v) { mMultiTouchEnabled = v; }
|
||||
|
||||
virtual bool GetLockCursor() const { return mLockCursor; }
|
||||
virtual void SetLockCursor(bool v) { mLockCursor = v; }
|
||||
|
||||
/**
|
||||
* Multitouch interface: return number of touch points
|
||||
*/
|
||||
virtual size_t GetNumTouches() const { return mNumTouches; }
|
||||
|
||||
/**
|
||||
* Multitouch interface: return touch points
|
||||
*/
|
||||
virtual std::vector<dtEntity::TouchPoint> GetTouches() const { return mTouches; }
|
||||
|
||||
/**
|
||||
* Return true if key is pressed, else false
|
||||
*/
|
||||
bool GetKey(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if key was released this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyUp(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if key was pressed down this frame, else false
|
||||
*/
|
||||
virtual bool GetKeyDown(const std::string& name, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Returns true if any keyboard key is currently pressed
|
||||
*/
|
||||
virtual bool AnyKeyDown() const;
|
||||
|
||||
/**
|
||||
* Return string entered this frame
|
||||
*/
|
||||
virtual std::string GetInputString() const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button is currently pressed.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButton(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was pressed this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonDown(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return true if given mouse button was released this frame.
|
||||
* 0 for left button, 1 for right, 2 for center
|
||||
*/
|
||||
virtual bool GetMouseButtonUp(int button, unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return axis value from -1 to 1
|
||||
* @TODO: Axes are currently hard coded
|
||||
*/
|
||||
virtual double GetAxis(dtEntity::StringId axisname) const;
|
||||
|
||||
/**
|
||||
* Return current mouse wheel state. -1 = down, 1 = up, 0 = no motion
|
||||
*/
|
||||
virtual int GetMouseWheelState(unsigned int contextId = 0) const;
|
||||
|
||||
/**
|
||||
* Return a list containing names of all registered keys
|
||||
*/
|
||||
void GetKeyNames(std::map<std::string, unsigned int>&) const;
|
||||
|
||||
/**
|
||||
* Get OSG key symbol from key name
|
||||
*/
|
||||
osgGA::GUIEventAdapter::KeySymbol GetKeySymbol(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Clear stuff at end of frame
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* React to OSG input events
|
||||
*/
|
||||
bool handleInternal(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventHandler> mEventHandler;
|
||||
|
||||
void HandleMultiTouch(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleKeyUp(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleKeyDown(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseUp(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseDown(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseMove(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseWheel(const osgGA::GUIEventAdapter& ea);
|
||||
void HandleMouseEnterLeave(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
dtEntity::MessagePump* mMessagePump;
|
||||
bool mMultiTouchEnabled;
|
||||
bool mLockCursor;
|
||||
size_t mNumTouches;
|
||||
std::vector<dtEntity::TouchPoint> mTouches;
|
||||
|
||||
typedef std::vector<dtEntity::InputCallbackInterface*> Callbacks;
|
||||
Callbacks mCallbacks;
|
||||
|
||||
// pair of context id, key
|
||||
typedef std::set<std::pair<unsigned int, int> > ContextKeyMap;
|
||||
ContextKeyMap mKeyPressedSet;
|
||||
ContextKeyMap mKeyUpSet;
|
||||
ContextKeyMap mKeyDownSet;
|
||||
|
||||
KeyNames mKeyNames;
|
||||
KeyNamesReverse mKeyNamesReverse;
|
||||
|
||||
typedef std::set<std::pair<unsigned int, int> > ContextButtonMap;
|
||||
ContextButtonMap mMouseButtonPressed;
|
||||
ContextButtonMap mMouseButtonUp;
|
||||
ContextButtonMap mMouseButtonDown;
|
||||
|
||||
float mMouseX;
|
||||
float mMouseY;
|
||||
|
||||
int mMouseXRaw;
|
||||
int mMouseYRaw;
|
||||
int mMouseDeltaXRaw;
|
||||
int mMouseDeltaYRaw;
|
||||
float mMouseDeltaX;
|
||||
float mMouseDeltaY;
|
||||
|
||||
unsigned int mFrameNumber;
|
||||
int mMouseScroll;
|
||||
unsigned int mMouseScrollContext;
|
||||
std::ostringstream mInputString;
|
||||
|
||||
bool mNeedReset; // internal flag to check when to reset
|
||||
};
|
||||
|
||||
inline OSGInputInterface* GetOSGInputInterface()
|
||||
{
|
||||
return static_cast<OSGInputInterface*>(dtEntity::GetInputInterface());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/systeminterface.h>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <osgViewer/ViewerBase>
|
||||
#include <vector>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class MessagePump;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT OSGSystemInterface : public dtEntity::SystemInterface
|
||||
{
|
||||
public:
|
||||
|
||||
OSGSystemInterface(dtEntity::MessagePump&, int argc, const char** argv);
|
||||
~OSGSystemInterface();
|
||||
|
||||
void InstallUpdateCallback(osg::Node* node);
|
||||
|
||||
void SetViewer(osgViewer::ViewerBase* v) { mViewer = v; }
|
||||
osgViewer::ViewerBase* GetViewer() const { return mViewer.get(); }
|
||||
|
||||
osgViewer::View* GetPrimaryView() const;
|
||||
osgViewer::GraphicsWindow* GetPrimaryWindow() const;
|
||||
osg::Camera* GetPrimaryCamera() const;
|
||||
|
||||
virtual void EmitTickMessagesAndQueuedMessages();
|
||||
|
||||
virtual void EmitPostUpdateMessage();
|
||||
|
||||
virtual float GetDeltaSimTime() const;
|
||||
virtual float GetDeltaRealTime() const;
|
||||
virtual dtEntity::Timer_t GetRealClockTime();
|
||||
virtual double GetSimulationTime() const;
|
||||
void SetSimulationTime(double);
|
||||
|
||||
virtual float GetTimeScale() const;
|
||||
virtual void SetTimeScale(float v);
|
||||
|
||||
virtual dtEntity::Timer_t GetSimulationClockTime() const;
|
||||
virtual void SetSimulationClockTime(dtEntity::Timer_t t);
|
||||
|
||||
void SetTimeValues(double simulationTime, float deltaSimTime,float deltaTime, dtEntity::Timer_t clockTime);
|
||||
|
||||
/**
|
||||
* Get absolute path from a relative file path.
|
||||
* Returns empty string if file is not found
|
||||
*/
|
||||
virtual std::string FindDataFile(const std::string& filename);
|
||||
|
||||
/**
|
||||
* return true if a file exists
|
||||
*/
|
||||
virtual bool FileExists(const std::string& filename);
|
||||
|
||||
virtual int GetArgC() { return mArgC; }
|
||||
virtual const char** GetArgV() { return mArgV; }
|
||||
|
||||
private:
|
||||
osg::observer_ptr<osgViewer::ViewerBase> mViewer;
|
||||
dtEntity::MessagePump* mMessagePump;
|
||||
class Impl;
|
||||
Impl* mImpl;
|
||||
|
||||
int mArgC;
|
||||
const char** mArgV;
|
||||
|
||||
};
|
||||
|
||||
inline OSGSystemInterface* GetOSGSystemInterface()
|
||||
{
|
||||
return static_cast<OSGSystemInterface*>(dtEntity::GetSystemInterface());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/core.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/messagepump.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/windowinterface.h>
|
||||
#include <osg/GraphicsContext>
|
||||
|
||||
namespace dtEntity
|
||||
{
|
||||
class EntityManager;
|
||||
}
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
class GraphicsWindow;
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT OSGWindowInterface : public dtEntity::WindowInterface
|
||||
{
|
||||
public:
|
||||
|
||||
struct WindowPos
|
||||
{
|
||||
int mX;
|
||||
int mY;
|
||||
int mW;
|
||||
int mH;
|
||||
bool mWindowDeco;
|
||||
};
|
||||
|
||||
OSGWindowInterface(dtEntity::EntityManager& em);
|
||||
~OSGWindowInterface();
|
||||
|
||||
osgViewer::GraphicsWindow* GetWindowByContextId(unsigned int contextId) const;
|
||||
osgViewer::View* GetViewByContextId(unsigned int contextId) const;
|
||||
|
||||
/**
|
||||
* Opens a new window if used viewer is a composite viewer.
|
||||
* @param name Name of osg nodes for window, view and camera to set
|
||||
* @param traits OSG GraphicsWindow traits to use
|
||||
* @contextId receives context id of newly created context
|
||||
* @return true if success, else false
|
||||
*/
|
||||
virtual bool OpenWindow(const std::string& name, unsigned int& contextId);
|
||||
|
||||
virtual void CloseWindow(unsigned int contextid);
|
||||
|
||||
/**
|
||||
* Get pick ray at given screen position
|
||||
*/
|
||||
dtEntity::Vec3f GetPickRay(unsigned int contextid, float x, float y, bool usePixels = false) const;
|
||||
|
||||
virtual bool GetWindowGeometry(unsigned int contextid, int& x, int& y, int& width, int& height) const;
|
||||
virtual bool SetWindowGeometry(unsigned int contextid, int x, int y, int width, int height);
|
||||
|
||||
virtual void SetFullscreen(unsigned int contextid, bool fullscreen);
|
||||
virtual bool GetFullscreen(unsigned int contextid) const;
|
||||
|
||||
virtual dtEntity::EntityId PickEntity(double x,
|
||||
double y,
|
||||
unsigned int nodemask,
|
||||
unsigned int contextid,
|
||||
bool usePixels = true) const;
|
||||
|
||||
void SetTraits(osg::GraphicsContext::Traits* traits) { mTraits = traits; }
|
||||
osg::GraphicsContext::Traits* GetTraits() const { return mTraits; }
|
||||
|
||||
virtual void SetShowCursor(unsigned int contextid, bool);
|
||||
|
||||
virtual dtEntity::Vec3d ConvertWorldToScreenCoords(unsigned int contextid, const dtEntity::Vec3d& coord);
|
||||
|
||||
/**
|
||||
* Should the window with given context id be continuously redrawn
|
||||
* or only by request? Default is on
|
||||
*/
|
||||
virtual void SetContinuousRedraw(unsigned int contextid, bool);
|
||||
|
||||
/**
|
||||
* If Continuous Redraw is off, request a redraw in next render traversal
|
||||
*/
|
||||
virtual void RequestRedraw(unsigned int contextid);
|
||||
|
||||
/**
|
||||
* Get intersections between start and end and add them to isects vector
|
||||
* @param start Start of intersection line
|
||||
* @param end End of intersection lnie
|
||||
* @param isects Vector return value for isect results
|
||||
* @param nodemask Bit mask, used for selecting nodes for intersection
|
||||
* @param layer Name of layer attach point component from which intersecition test will
|
||||
* be executed downwards (default: layer "default")
|
||||
* @return true if an intersection was found
|
||||
*/
|
||||
virtual bool GetIntersections(const dtEntity::Vec3d& start, const dtEntity::Vec3d& end,
|
||||
std::vector<dtEntity::WindowInterface::Intersection>& isects,
|
||||
unsigned int nodemask = dtEntity::NodeMasks::PICKABLE | dtEntity::NodeMasks::TERRAIN,
|
||||
dtEntity::StringId layer = dtEntity::StringId()
|
||||
) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
bool OpenWindowInternal(const std::string& name, unsigned int& contextId);
|
||||
|
||||
dtEntity::EntityManager* mEntityManager;
|
||||
|
||||
typedef std::map<unsigned int, WindowPos> WindowPosMap;
|
||||
WindowPosMap mWindowPositions;
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> mTraits;
|
||||
|
||||
};
|
||||
|
||||
inline OSGWindowInterface* GetOSGWindowInterface()
|
||||
{
|
||||
return static_cast<OSGWindowInterface*>(dtEntity::GetWindowInterface());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <osgManipulator/Dragger>
|
||||
#include <osgParticle/ParticleSystem>
|
||||
#include <osgParticle/ModularEmitter>
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/ParticleSystemUpdater>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class ParticleComponent
|
||||
: public dtEntityOSG::NodeComponent
|
||||
{
|
||||
|
||||
public:
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId AlphaRangeId;
|
||||
static const dtEntity::StringId ColorRangeMinId;
|
||||
static const dtEntity::StringId ColorRangeMaxId;
|
||||
static const dtEntity::StringId CounterId;
|
||||
static const dtEntity::StringId DebugOnId;
|
||||
static const dtEntity::StringId EmissiveParticlesId;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId LifeTimeId;
|
||||
static const dtEntity::StringId LightingId;
|
||||
static const dtEntity::StringId MassId;
|
||||
static const dtEntity::StringId PlacerId;
|
||||
static const dtEntity::StringId SizeRangeId;
|
||||
static const dtEntity::StringId TextureFileId;
|
||||
static const dtEntity::StringId TextureUnitId;
|
||||
|
||||
static const dtEntity::StringId __SELECTED__Id;
|
||||
static const dtEntity::StringId BoxId;
|
||||
static const dtEntity::StringId CompositeId;
|
||||
static const dtEntity::StringId MultiSegmentId;
|
||||
static const dtEntity::StringId PointId;
|
||||
static const dtEntity::StringId SectorId;
|
||||
static const dtEntity::StringId SegmentId;
|
||||
|
||||
static const dtEntity::StringId XRangeId;
|
||||
static const dtEntity::StringId YRangeId;
|
||||
static const dtEntity::StringId ZRangeId;
|
||||
static const dtEntity::StringId CenterId;
|
||||
|
||||
static const dtEntity::StringId RandomRateCounterId;
|
||||
static const dtEntity::StringId ConstantRateCounterId;
|
||||
|
||||
static const dtEntity::StringId RateRangeId;
|
||||
static const dtEntity::StringId MinimumNumberOfParticlesToCreateId;
|
||||
static const dtEntity::StringId NumberOfParticlesPerSecondToCreateId;
|
||||
|
||||
static const dtEntity::StringId ShooterThetaRangeId;
|
||||
static const dtEntity::StringId ShooterPhiRangeId;
|
||||
static const dtEntity::StringId ShooterInitialSpeedRangeId;
|
||||
static const dtEntity::StringId ShooterInitialRotationalSpeedMinId;
|
||||
static const dtEntity::StringId ShooterInitialRotationalSpeedMaxId;
|
||||
|
||||
static const dtEntity::StringId ShapeId;
|
||||
static const dtEntity::StringId ShapePointId;
|
||||
static const dtEntity::StringId ShapeQuadId;
|
||||
static const dtEntity::StringId ShapeQuadTriangeStripId;
|
||||
static const dtEntity::StringId ShapeHexagonId;
|
||||
static const dtEntity::StringId ShapeLineId;
|
||||
|
||||
static const dtEntity::StringId OperatorsId;
|
||||
|
||||
static const dtEntity::StringId BounceOperatorId;
|
||||
static const dtEntity::StringId ForceOperatorId;
|
||||
|
||||
static const dtEntity::StringId FrictionId;
|
||||
static const dtEntity::StringId ResilienceId;
|
||||
static const dtEntity::StringId CutoffId;
|
||||
static const dtEntity::StringId DomainsId;
|
||||
static const dtEntity::StringId PlaneDomainId;
|
||||
static const dtEntity::StringId SphereDomainId;
|
||||
static const dtEntity::StringId ForceId;
|
||||
static const dtEntity::StringId NormalId;
|
||||
static const dtEntity::StringId DistId;
|
||||
static const dtEntity::StringId RadiusId;
|
||||
|
||||
|
||||
|
||||
ParticleComponent();
|
||||
virtual ~ParticleComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity &entity);
|
||||
virtual void OnRemovedFromEntity(dtEntity::Entity &entity);
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetTextureFile(const std::string& v) { mTextureFile.Set(v); }
|
||||
std::string GetTextureFile() const { return mTextureFile.Get(); }
|
||||
|
||||
void SetEmissiveParticles(bool v) { mEmissiveParticles.Set(v); }
|
||||
bool GetEmissiveParticles() const { return mEmissiveParticles.Get(); }
|
||||
|
||||
void SetDebugOn(bool v);
|
||||
bool GetDebugOn() const { return mDebugOnVal; }
|
||||
|
||||
void SetLighting(bool v) { mLighting.Set(v); }
|
||||
bool GetLighting() const { return mLighting.Get(); }
|
||||
|
||||
void SetTextureUnit(int v) { mTextureUnit.Set(v); }
|
||||
int GetTextureUnit() const { return mTextureUnit.Get(); }
|
||||
|
||||
void SetLifeTime(double v) { mLifeTime.Set(v); }
|
||||
double GetLifeTime() const { return mLifeTime.Get(); }
|
||||
|
||||
void SetMass(float v) { mMass.Set(v); }
|
||||
float GetMass() const { return mMass.Get(); }
|
||||
|
||||
void SetSizeRange(const osg::Vec2& v) { mSizeRange.Set(v); }
|
||||
osg::Vec2 GetSizeRange() const { return mSizeRange.Get(); }
|
||||
|
||||
|
||||
void SetCounter(const dtEntity::PropertyGroup&);
|
||||
dtEntity::PropertyGroup GetCounter() const;
|
||||
|
||||
void SetPlacer(const dtEntity::PropertyGroup&);
|
||||
dtEntity::PropertyGroup GetPlacer() const;
|
||||
|
||||
void SetShooterThetaRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterThetaRange() const;
|
||||
|
||||
void SetShooterPhiRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterPhiRange() const;
|
||||
|
||||
void SetShooterInitialSpeedRange(const osg::Vec2& v);
|
||||
osg::Vec2 GetShooterInitialSpeedRange() const;
|
||||
|
||||
void SetShooterInitialRotationalSpeedMin(const osg::Vec3& v);
|
||||
osg::Vec3 GetShooterInitialRotationalSpeedMin() const;
|
||||
|
||||
void SetShooterInitialRotationalSpeedMax(const osg::Vec3& v);
|
||||
osg::Vec3 GetShooterInitialRotationalSpeedMax() const;
|
||||
|
||||
void SetOperators(const dtEntity::PropertyArray& v);
|
||||
dtEntity::PropertyArray GetOperators() const;
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osg::Geode> mGeode;
|
||||
osg::ref_ptr<osgParticle::ParticleSystem> mParticleSystem;
|
||||
osg::ref_ptr<osgParticle::ModularEmitter> mModularEmitter;
|
||||
osg::ref_ptr<osgParticle::ModularProgram> mProgram;
|
||||
|
||||
dtEntity::DynamicBoolProperty mDebugOn;
|
||||
bool mDebugOnVal;
|
||||
dtEntity::StringProperty mTextureFile;
|
||||
dtEntity::BoolProperty mEmissiveParticles;
|
||||
dtEntity::BoolProperty mEnabled;
|
||||
dtEntity::BoolProperty mLighting;
|
||||
dtEntity::IntProperty mTextureUnit;
|
||||
|
||||
dtEntity::DoubleProperty mLifeTime;
|
||||
dtEntity::FloatProperty mMass;
|
||||
dtEntity::Vec2Property mSizeRange;
|
||||
dtEntity::Vec2Property mAlphaRange;
|
||||
dtEntity::Vec4Property mColorRangeMin;
|
||||
dtEntity::Vec4Property mColorRangeMax;
|
||||
|
||||
dtEntity::DynamicGroupProperty mPlacer;
|
||||
dtEntity::GroupProperty mPlacerVal;
|
||||
dtEntity::DynamicGroupProperty mCounter;
|
||||
dtEntity::GroupProperty mCounterVal;
|
||||
|
||||
dtEntity::DynamicVec2Property mShooterThetaRange;
|
||||
dtEntity::DynamicVec2Property mShooterPhiRange;
|
||||
dtEntity::DynamicVec2Property mShooterInitialSpeedRange;
|
||||
dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMin;
|
||||
dtEntity::DynamicVec3Property mShooterInitialRotationalSpeedMax;
|
||||
|
||||
dtEntity::StringIdProperty mShape;
|
||||
|
||||
dtEntity::DynamicArrayProperty mOperators;
|
||||
dtEntity::ArrayProperty mOperatorsVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ParticleSystem
|
||||
: public dtEntity::DefaultEntitySystem<ParticleComponent>
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ParticleComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
ParticleSystem(dtEntity::EntityManager& em);
|
||||
~ParticleSystem();
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/message.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class PathComponent : public dtEntityOSG::NodeComponent
|
||||
{
|
||||
typedef dtEntityOSG::NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId VertsId;
|
||||
static const dtEntity::StringId PathVisibleId;
|
||||
static const dtEntity::StringId VertsVisibleId;
|
||||
|
||||
typedef dtEntity::PropertyArray::size_type size_type;
|
||||
|
||||
PathComponent();
|
||||
virtual ~PathComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetPathsVisible(bool v) { mPathsVisible.Set(v); }
|
||||
bool GetPathsVisible() const { return mPathsVisible.Get(); }
|
||||
|
||||
void SetVertsVisible(bool v) { mVertsVisible.Set(v); }
|
||||
bool GetVertsVisible() const { return mVertsVisible.Get(); }
|
||||
|
||||
osg::Vec3 GetVertex(size_type index) const;
|
||||
void SetVertex(size_type index, const osg::Vec3& v);
|
||||
size_type GetNumVertices() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::ArrayProperty mVerts;
|
||||
dtEntity::BoolProperty mPathsVisible;
|
||||
dtEntity::BoolProperty mVertsVisible;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PathSystem
|
||||
: public dtEntity::DefaultEntitySystem<PathComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<PathComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
PathSystem(dtEntity::EntityManager& em);
|
||||
~PathSystem();
|
||||
|
||||
dtEntity::Property* ScriptPickVertex(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptGetVertexWorldPosition(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetVertexWorldPosition(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptDuplicateVertex(const dtEntity::PropertyArgs& args);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/ShapeDrawable>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Adds a pickable shape to the transform of the entity
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT PickShapeComponent
|
||||
: public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MinBoundsId;
|
||||
static const dtEntity::StringId MaxBoundsId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
|
||||
PickShapeComponent();
|
||||
virtual ~PickShapeComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
void SetMinBounds(const osg::Vec3& v);
|
||||
osg::Vec3 GetMinBounds() const { return mMinBoundsVal; }
|
||||
|
||||
void SetMaxBounds(const osg::Vec3& v);
|
||||
osg::Vec3 GetMaxBounds() const { return mMaxBoundsVal; }
|
||||
|
||||
void SetVisible(bool v);
|
||||
bool GetVisible() const;
|
||||
|
||||
private:
|
||||
|
||||
void UpdatePickShape();
|
||||
|
||||
// path to loaded script file
|
||||
dtEntity::StringProperty mMeshPathProperty;
|
||||
dtEntity::DynamicVec3Property mMinBounds;
|
||||
dtEntity::DynamicVec3Property mMaxBounds;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
osg::ref_ptr<osg::Box> mBox;
|
||||
osg::Vec3 mMinBoundsVal;
|
||||
osg::Vec3 mMaxBoundsVal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT PickShapeSystem
|
||||
: public dtEntity::DefaultEntitySystem<PickShapeComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
PickShapeSystem(dtEntity::EntityManager& em);
|
||||
~PickShapeSystem();
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/transformcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class PositionAttitudeTransform;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* holds a single PositionAttitude transform
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT PositionAttitudeTransformComponent
|
||||
: public TransformComponent
|
||||
{
|
||||
typedef TransformComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId PositionId;
|
||||
static const dtEntity::StringId AttitudeId;
|
||||
static const dtEntity::StringId ScaleId;
|
||||
|
||||
PositionAttitudeTransformComponent();
|
||||
|
||||
virtual ~PositionAttitudeTransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
const osg::PositionAttitudeTransform* GetPositionAttitudeTransform() const;
|
||||
osg::PositionAttitudeTransform* GetPositionAttitudeTransform();
|
||||
|
||||
dtEntity::Vec3d GetPosition() const;
|
||||
void SetPosition(const dtEntity::Vec3d& p);
|
||||
|
||||
dtEntity::Quat GetAttitude() const;
|
||||
void SetAttitude(const dtEntity::Quat& r);
|
||||
|
||||
dtEntity::Vec3d GetScale() const;
|
||||
void SetScale(const dtEntity::Vec3d& q);
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const { return GetPosition(); }
|
||||
virtual void SetTranslation(const dtEntity::Vec3d& t) { SetPosition(t); }
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const { return GetAttitude(); }
|
||||
virtual void SetRotation(const dtEntity::Quat& q) { SetAttitude(q); }
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const;
|
||||
virtual void SetMatrix(const dtEntity::Matrix& mat);
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicVec3dProperty mPosition;
|
||||
dtEntity::DynamicVec3dProperty mScale;
|
||||
dtEntity::DynamicQuatProperty mAttitude;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT PositionAttitudeTransformSystem
|
||||
: public dtEntity::DefaultEntitySystem<PositionAttitudeTransformComponent>
|
||||
{
|
||||
public:
|
||||
PositionAttitudeTransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::DefaultEntitySystem<PositionAttitudeTransformComponent>(em, TransformComponent::TYPE)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Program;
|
||||
}
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class DTENTITY_OSG_EXPORT ShaderComponent : public dtEntity::Component
|
||||
{
|
||||
|
||||
typedef dtEntity::Component BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MaterialNamePrefixId;
|
||||
static const dtEntity::StringId TopLevelMaterialNameId;
|
||||
|
||||
ShaderComponent();
|
||||
virtual ~ShaderComponent();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
std::string GetMaterialNamePrefix() const { return mMaterialNamePrefix.Get(); }
|
||||
void SetMaterialNamePrefix(const std::string& s) { mMaterialNamePrefix.Set(s); }
|
||||
|
||||
std::string GetTopLevelMaterialName() const { return mTopLevelMaterialName.Get(); }
|
||||
void SetTopLevelMaterialName(const std::string& s) { mTopLevelMaterialName.Set(s); }
|
||||
|
||||
private:
|
||||
dtEntity::StringProperty mMaterialNamePrefix;
|
||||
dtEntity::StringProperty mTopLevelMaterialName;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT ShaderSystem
|
||||
: public dtEntity::DefaultEntitySystem<ShaderComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
typedef dtEntity::DefaultEntitySystem<ShaderComponent> BaseClass;
|
||||
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
ShaderSystem(dtEntity::EntityManager& em);
|
||||
~ShaderSystem();
|
||||
|
||||
void AddProgram(const std::string& name, osg::Program* prg);
|
||||
osg::Program* GetProgram(const std::string& name) const;
|
||||
|
||||
virtual bool CreateComponent(dtEntity::EntityId eid, dtEntity::Component*& component);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Program> > ProgramMap;
|
||||
ProgramMap mPrograms;
|
||||
dtEntity::MessageFunctor mChangedMeshFunctor;
|
||||
|
||||
void OnChangedMesh(const dtEntity::Message& msg);
|
||||
void ApplyShader(dtEntity::EntityId);
|
||||
dtEntity::Property* ScriptAddProgram(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptAddUniform(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptRemoveUniform(const dtEntity::PropertyArgs& args);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osgShadow/ShadowTechnique>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Holds a single OSG node.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT ShadowComponent : public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
static const dtEntity::StringId EnabledId;
|
||||
static const dtEntity::StringId ShadowTechniqueId;
|
||||
static const dtEntity::StringId MinLightMarginId;
|
||||
static const dtEntity::StringId MaxFarPlaneId;
|
||||
static const dtEntity::StringId TexSizeId;
|
||||
static const dtEntity::StringId BaseTexUnitId;
|
||||
static const dtEntity::StringId ShadowTexUnitId;
|
||||
static const dtEntity::StringId ShadowTexCoordIndexId;
|
||||
static const dtEntity::StringId BaseTexCoordIndexId;
|
||||
static const dtEntity::StringId MapCountId;
|
||||
static const dtEntity::StringId MapResId;
|
||||
static const dtEntity::StringId DebugColorOnId;
|
||||
static const dtEntity::StringId MinNearSplitId;
|
||||
static const dtEntity::StringId MaxFarDistId;
|
||||
static const dtEntity::StringId MoveVCamFactorId;
|
||||
static const dtEntity::StringId PolyOffsetFactorId;
|
||||
static const dtEntity::StringId PolyOffsetUnitId;
|
||||
static const dtEntity::StringId LISPId;
|
||||
static const dtEntity::StringId PSSMId;
|
||||
static const dtEntity::StringId __SELECTED__Id;
|
||||
|
||||
static const dtEntity::StringId ShadowTypeId;
|
||||
|
||||
ShadowComponent();
|
||||
virtual ~ShadowComponent();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void SetShadowTechnique(const std::string name);
|
||||
|
||||
void SetEnabled(bool v) { mEnabled.Set(v); }
|
||||
bool GetEnabled() const { return mEnabled.Get(); }
|
||||
private:
|
||||
|
||||
dtEntity::Entity* mEntity;
|
||||
dtEntity::BoolProperty mEnabled;
|
||||
osg::ref_ptr<osgShadow::ShadowTechnique> mTechnique;
|
||||
|
||||
dtEntity::GroupProperty mShadowType;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT ShadowSystem
|
||||
: public dtEntity::DefaultEntitySystem<ShadowComponent>
|
||||
{
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId EnabledId;
|
||||
|
||||
ShadowSystem(dtEntity::EntityManager& em);
|
||||
virtual ~ShadowSystem();
|
||||
|
||||
void SetEnabled(bool);
|
||||
bool GetEnabled() const { return mEnabledVal; }
|
||||
|
||||
private:
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
#include <osg/Geode>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
/**
|
||||
* Holds a single OSG node.
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT SkyBoxComponent : public GroupComponent
|
||||
{
|
||||
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId TextureUpId;
|
||||
static const dtEntity::StringId TextureDownId;
|
||||
static const dtEntity::StringId TextureNorthId;
|
||||
static const dtEntity::StringId TextureSouthId;
|
||||
static const dtEntity::StringId TextureEastId;
|
||||
static const dtEntity::StringId TextureWestId;
|
||||
|
||||
SkyBoxComponent();
|
||||
virtual ~SkyBoxComponent();
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual osg::Group* GetAttachmentGroup() const { return mDrawables; }
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Geode> mSkyboxGeode;
|
||||
dtEntity::StringProperty mTextureUp;
|
||||
dtEntity::StringProperty mTextureDown;
|
||||
dtEntity::StringProperty mTextureNorth;
|
||||
dtEntity::StringProperty mTextureSouth;
|
||||
dtEntity::StringProperty mTextureEast;
|
||||
dtEntity::StringProperty mTextureWest;
|
||||
osg::ref_ptr<osg::Group> mDrawables;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT SkyBoxSystem
|
||||
: public dtEntity::DefaultEntitySystem<SkyBoxComponent>
|
||||
{
|
||||
public:
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
SkyBoxSystem(dtEntity::EntityManager& em);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Loads a static mesh from a path
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT StaticMeshComponent
|
||||
: public NodeComponent
|
||||
{
|
||||
public:
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId MeshId;
|
||||
static const dtEntity::StringId CacheHintId;
|
||||
static const dtEntity::StringId OptimizeId;
|
||||
static const dtEntity::StringId IsTerrainId;
|
||||
|
||||
static const dtEntity::StringId CacheNoneId;
|
||||
static const dtEntity::StringId CacheAllId;
|
||||
static const dtEntity::StringId CacheNodesId;
|
||||
static const dtEntity::StringId CacheHardwareMeshesId;
|
||||
|
||||
StaticMeshComponent();
|
||||
virtual ~StaticMeshComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
// set existing geometry as static mesh
|
||||
void SetStaticMesh(osg::Node* node);
|
||||
|
||||
/**
|
||||
* return path of currently loaded mesh
|
||||
*/
|
||||
std::string GetMesh() const;
|
||||
|
||||
/**
|
||||
* Load mesh from path
|
||||
*/
|
||||
virtual void SetMesh(const std::string& path, dtEntity::StringId cacheHint = CacheAllId);
|
||||
|
||||
void SetCacheHint(dtEntity::StringId v) { mCacheHint.Set(v); }
|
||||
dtEntity::StringId GetCacheHint() const { return mCacheHint.Get(); }
|
||||
|
||||
bool GetOptimize() const { return mOptimize.Get(); }
|
||||
void SetOptimize(bool v) { mOptimize.Set(v); }
|
||||
|
||||
bool GetIsTerrain() const { return mIsTerrainVal; }
|
||||
void SetIsTerrain(bool v);
|
||||
|
||||
protected:
|
||||
|
||||
// path to loaded script file
|
||||
dtEntity::StringProperty mMeshPathProperty;
|
||||
dtEntity::StringIdProperty mCacheHint;
|
||||
dtEntity::BoolProperty mOptimize;
|
||||
dtEntity::DynamicBoolProperty mIsTerrain;
|
||||
bool mIsTerrainVal;
|
||||
std::string mLoadedMesh;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// storage only
|
||||
class DTENTITY_OSG_EXPORT StaticMeshSystem
|
||||
: public dtEntity::DefaultEntitySystem<StaticMeshComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
StaticMeshSystem(dtEntity::EntityManager& em);
|
||||
~StaticMeshSystem();
|
||||
|
||||
void OnResourceChanged(const dtEntity::Message& msg);
|
||||
|
||||
private:
|
||||
dtEntity::MessageFunctor mResourceChangedFunctor;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <dtEntity/scriptaccessor.h>
|
||||
#include <osgText/Text>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
class Entity;
|
||||
class TextLabelSystem;
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextLabelComponent : public NodeComponent
|
||||
{
|
||||
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector<osg::ref_ptr<osgText::Text> >::size_type size_type;
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId TextsId;
|
||||
static const dtEntity::StringId AlwaysOnTopId;
|
||||
static const dtEntity::StringId TextId;
|
||||
static const dtEntity::StringId ColorId;
|
||||
static const dtEntity::StringId BackdropColorId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
static const dtEntity::StringId HighlightedId;
|
||||
static const dtEntity::StringId OffsetId;
|
||||
static const dtEntity::StringId CharacterHeightId;
|
||||
static const dtEntity::StringId FontId;
|
||||
static const dtEntity::StringId AlignmentId;
|
||||
|
||||
TextLabelComponent();
|
||||
virtual ~TextLabelComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
|
||||
size_type GetNumTexts() const { return mTextEntries.size(); }
|
||||
void Create(size_type textid);
|
||||
void Destroy(size_type textid);
|
||||
|
||||
void ClearAll();
|
||||
|
||||
void SetText(size_type textid, const std::string&);
|
||||
std::string GetText(size_type textid) const;
|
||||
|
||||
void SetHighlighted(size_type textid, bool);
|
||||
bool GetHighlighted(size_type textid) const;
|
||||
|
||||
void SetFlashing(size_type textid, bool);
|
||||
bool GetFlashing(size_type textid) const;
|
||||
|
||||
void SetColor(size_type textid, const osg::Vec4&);
|
||||
osg::Vec4 GetColor(size_type textid) const;
|
||||
|
||||
void SetBackdropColor(size_type textid, const osg::Vec4&);
|
||||
osg::Vec4 GetBackdropColor(size_type textid) const;
|
||||
|
||||
void SetVisible(size_type textid, bool);
|
||||
bool GetVisible(size_type textid) const;
|
||||
|
||||
void SetFont(size_type textid, const std::string&);
|
||||
std::string GetFont(size_type textid) const;
|
||||
|
||||
void SetOffset(size_type textid, const osg::Vec3&);
|
||||
osg::Vec3 GetOffset(size_type textid) const;
|
||||
|
||||
void SetCharacterHeight(size_type textid, float);
|
||||
float GetCharacterHeight(size_type textid) const;
|
||||
|
||||
void SetAlignment(size_type textid, const std::string& str);
|
||||
std::string GetAlignment(size_type textid) const;
|
||||
|
||||
bool GetAlwaysOnTop() const { return mAlwaysOnTopVal; }
|
||||
void SetAlwaysOnTop(bool v);
|
||||
|
||||
private:
|
||||
|
||||
void SetTexts(const dtEntity::PropertyArray& texts);
|
||||
dtEntity::PropertyArray GetTexts() const;
|
||||
dtEntity::DynamicArrayProperty mTexts;
|
||||
dtEntity::ArrayProperty mTextsVal;
|
||||
dtEntity::DynamicBoolProperty mAlwaysOnTop;
|
||||
bool mAlwaysOnTopVal;
|
||||
typedef std::vector<osg::ref_ptr<osgText::Text> > TextEntries;
|
||||
TextEntries mTextEntries;
|
||||
TextLabelSystem* mTextLabelSystem;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextLabelSystem
|
||||
: public dtEntity::DefaultEntitySystem<TextLabelComponent>
|
||||
, public dtEntity::ScriptAccessor
|
||||
{
|
||||
static const dtEntity::StringId EnabledId;
|
||||
typedef dtEntity::DefaultEntitySystem<TextLabelComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TextLabelSystem(dtEntity::EntityManager& em);
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
dtEntity::Property* ScriptCreate(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptDestroy(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetText(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetOffset(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetAlignment(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetColor(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetBackdropColor(const dtEntity::PropertyArgs& args);
|
||||
dtEntity::Property* ScriptSetHighlighted(const dtEntity::PropertyArgs& args);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
|
||||
*/
|
||||
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntityOSG/nodecomponent.h>
|
||||
#include <dtEntity/dynamicproperty.h>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Program>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
class TextureLabelSystem;
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextureLabelComponent : public NodeComponent
|
||||
{
|
||||
|
||||
friend class TextureLabelSystem;
|
||||
typedef NodeComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
static const dtEntity::StringId OffsetId;
|
||||
static const dtEntity::StringId PathId;
|
||||
static const dtEntity::StringId ColorId;
|
||||
static const dtEntity::StringId MaxSizeId;
|
||||
static const dtEntity::StringId MinSizeId;
|
||||
static const dtEntity::StringId DistanceAttenuationId;
|
||||
static const dtEntity::StringId VisibleId;
|
||||
static const dtEntity::StringId AlwaysOnTopId;
|
||||
static const dtEntity::StringId AddConnectingLineId;
|
||||
|
||||
TextureLabelComponent();
|
||||
virtual ~TextureLabelComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const { return TYPE; }
|
||||
|
||||
virtual bool IsInstanceOf(dtEntity::ComponentType id) const
|
||||
{
|
||||
return (id == TYPE);
|
||||
}
|
||||
|
||||
virtual void Finished();
|
||||
|
||||
virtual void OnAddedToEntity(dtEntity::Entity& entity);
|
||||
std::string GetPath() const { return mPath.Get(); }
|
||||
|
||||
// call OnFinished...() to apply
|
||||
void SetPath(const std::string& path) { mPath.Set(path); }
|
||||
|
||||
osg::Geode* GetGeode() const;
|
||||
|
||||
osg::Vec3 GetOffset() const { return mOffsetVal; }
|
||||
void SetOffset(const osg::Vec3& o);
|
||||
|
||||
void SetMaxSize(unsigned int v) { mMaxSize.Set(v); }
|
||||
unsigned int GetMaxSize() const { return mMaxSize.Get(); }
|
||||
|
||||
void SetMinSize(unsigned int v) { mMinSize.Set(v); }
|
||||
unsigned int GetMinSize() const { return mMinSize.Get(); }
|
||||
|
||||
void SetDistanceAttenuation(const osg::Vec3& v) { mDistanceAttenuation.Set(v); }
|
||||
osg::Vec3 GetDistanceAttenuation() const { return mDistanceAttenuation.Get(); }
|
||||
|
||||
osg::Vec4 GetColor() const { return mColorVal; }
|
||||
void SetColor(const osg::Vec4& v);
|
||||
|
||||
void SetVisible(bool v);
|
||||
bool GetVisible() const;
|
||||
|
||||
bool GetAlwaysOnTop() const { return mAlwaysOnTop.Get(); }
|
||||
void SetAlwaysOnTop(bool v) { mAlwaysOnTop.Set(v); }
|
||||
|
||||
osg::Uniform* GetColorUniform() const { return mColorUniform; }
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osg::Vec4Array> mColorArray;
|
||||
osg::ref_ptr<osg::Geometry> mDotGeometry;
|
||||
dtEntity::DynamicVec3Property mOffset;
|
||||
osg::Vec3 mOffsetVal;
|
||||
dtEntity::DynamicVec4Property mColor;
|
||||
osg::Vec4 mColorVal;
|
||||
dtEntity::StringProperty mPath;
|
||||
dtEntity::UIntProperty mMinSize;
|
||||
dtEntity::UIntProperty mMaxSize;
|
||||
dtEntity::Vec3Property mDistanceAttenuation;
|
||||
dtEntity::DynamicBoolProperty mVisible;
|
||||
dtEntity::BoolProperty mAlwaysOnTop;
|
||||
TextureLabelSystem* mLabelSystem;
|
||||
osg::ref_ptr<osg::Uniform> mColorUniform;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DTENTITY_OSG_EXPORT TextureLabelSystem
|
||||
: public dtEntity::DefaultEntitySystem<TextureLabelComponent>
|
||||
{
|
||||
static const dtEntity::StringId EnabledId;
|
||||
typedef dtEntity::DefaultEntitySystem<TextureLabelComponent> BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TextureLabelSystem(dtEntity::EntityManager& em);
|
||||
~TextureLabelSystem();
|
||||
|
||||
osg::StateSet* GetSymbolStateset(const std::string& symbolpath, TextureLabelComponent& component);
|
||||
|
||||
void SetupLabel(TextureLabelComponent& component);
|
||||
|
||||
void SetEnabled(bool v);
|
||||
bool GetEnabled() const;
|
||||
|
||||
private:
|
||||
|
||||
dtEntity::DynamicBoolProperty mEnabled;
|
||||
bool mEnabledVal;
|
||||
osg::ref_ptr<osg::Program> mProgram;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
/* -*-c++-*-
|
||||
* dtEntity Game and Simulation Engine
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Martin Scheffler
|
||||
*/
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <dtEntityOSG/export.h>
|
||||
#include <dtEntity/defaultentitysystem.h>
|
||||
#include <dtEntity/component.h>
|
||||
#include <dtEntityOSG/groupcomponent.h>
|
||||
#include <dtEntity/property.h>
|
||||
#include <dtEntity/stringid.h>
|
||||
|
||||
namespace dtEntityOSG
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* abstract base class for transform components
|
||||
*/
|
||||
class DTENTITY_OSG_EXPORT TransformComponent
|
||||
: public GroupComponent
|
||||
{
|
||||
typedef GroupComponent BaseClass;
|
||||
|
||||
public:
|
||||
|
||||
static const dtEntity::ComponentType TYPE;
|
||||
|
||||
TransformComponent(osg::Transform* trans);
|
||||
|
||||
virtual ~TransformComponent();
|
||||
|
||||
virtual dtEntity::ComponentType GetType() const {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
virtual dtEntity::Vec3d GetTranslation() const = 0;
|
||||
virtual void SetTranslation(const dtEntity::Vec3d&) = 0;
|
||||
|
||||
virtual dtEntity::Vec3d GetScale() const { return dtEntity::Vec3d(1,1,1); }
|
||||
virtual void SetScale(const dtEntity::Vec3d&) {}
|
||||
|
||||
virtual dtEntity::Quat GetRotation() const = 0;
|
||||
virtual void SetRotation(const dtEntity::Quat&) = 0;
|
||||
|
||||
virtual dtEntity::Matrix GetMatrix() const
|
||||
{
|
||||
dtEntity::Matrix matrix;
|
||||
matrix.setTrans(GetTranslation());
|
||||
matrix.setRotate(GetRotation());
|
||||
return matrix;
|
||||
}
|
||||
|
||||
virtual void SetMatrix(const dtEntity::Matrix& mat)
|
||||
{
|
||||
SetTranslation(mat.getTrans());
|
||||
SetRotation(mat.getRotate());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class DTENTITY_OSG_EXPORT TransformSystem
|
||||
: public dtEntity::EntitySystem
|
||||
{
|
||||
public:
|
||||
TransformSystem(dtEntity::EntityManager& em)
|
||||
: dtEntity::EntitySystem(em)
|
||||
{
|
||||
}
|
||||
|
||||
dtEntity::ComponentType GetComponentType() const { return TransformComponent::TYPE; }
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user