00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00025
00026 #ifndef CollisionSphere_H
00027 #define CollisionSphere_H
00028
00029
00030 #include "H3DNetworkingUtils/Config.h"
00031 #include "H3DNetworkingUtils/CollisionGeometry.h"
00032
00033
00034
00035
00036 template struct __declspec(dllimport) H3D::AutoUpdate <H3D::Field>;
00037
00038 namespace H3DNetworkingUtils {
00039
00047
00048 class H3D_NETWORKING_UTILS_DLL_SPEC CollisionSphere : public CollisionGeometry {
00049 public:
00050
00051 struct H3D_NETWORKING_UTILS_DLL_SPEC Radius : public H3D::SFFloat {
00052 virtual void setValue(const H3D::H3DFloat & val, int id = 0) {
00053 H3D::SFFloat::setValue(val, id);
00054 CollisionSphere * cs = static_cast<CollisionSphere*>(getOwner());
00055 cs->rad_sqrd = val * val;
00056 }
00057 virtual void update() {
00058 H3D::SFFloat::update();
00059 CollisionSphere * cs = static_cast<CollisionSphere*>(getOwner());
00060 cs->rad_sqrd = value * value;
00061 }
00062
00063 };
00064
00066 CollisionSphere( H3D::Inst< Radius > _radius = 0);
00067
00069 static H3D::H3DNodeDatabase database;
00070
00071
00076 auto_ptr< Radius > radius;
00077
00082 auto_ptr< H3D::SFBool > debug;
00083
00085 H3D::H3DFloat getGlobalRadius() {
00086 H3D::Vec3f scale = child_local_info->accForwardMatrix->getValue().getScalePart();
00087 H3D::H3DFloat sc = (scale.x + scale.y + scale.z) / 3.0f;
00088 return radius->getValue() * sc;
00089 }
00090
00092 virtual void initialize();
00093
00095 virtual CollisionGeometry * clone() {return new CollisionSphere;}
00096
00098 virtual void copy(CollisionGeometry * newP);
00099
00101 virtual bool contains(const H3D::Vec3f & pt) {
00102 return (pt - local_offset->translation->getValue()).lengthSqr() < rad_sqrd;
00103 }
00104
00105 private:
00106 H3D::H3DFloat rad_sqrd;
00107 H3D::H3DFloat scaled_rad_sqrd;
00108 H3D::Vec3f scaled_trans;
00109 };
00110
00111 }
00112
00113 #endif // COLLIDABLESPHERE_H