- Main Page
- Classes
- Files

- Search for |

# CollisionSphere.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      CollisionSphere.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    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 // This next line is needed because H3DAPI.dll instantiates this template but this class does not see the header with
    00034 // the instantiation in it. So without the line, this class would instantiate an identical one and there would
    00035 // be a multiply defined symbol in the link stage.
    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