vrsode/src/SphereShape.cpp

Go to the documentation of this file.
00001 
00002 #include "SphereShape.h"
00003 #include "PhysicsManager.h"
00004 
00005 #include <vrs/colorattribute.h>
00006 #include <vrs/constantdetail.h>
00007 #include <vrs/facestyle.h>
00008 #include <vrs/rotation.h>
00009 #include <vrs/sphere.h>
00010 #include <vrs/translation.h>
00011 
00012 namespace vrsode
00013 {
00014 
00015 SphereShape::SphereShape(VRS::Bounds p_bounds) : Shape()
00016 {
00017     setCollisionShape(CS_Sphere);
00018     setOffsetCenter(p_bounds.center());
00019 
00020     m_bounds = p_bounds;
00021 
00022     createDebugNode();
00023     createGeometry();
00024 }
00025 
00026 SphereShape::~SphereShape()
00027 {
00028 
00029 }
00030 
00031 void
00032 SphereShape::createGeometry()
00033 {
00034     // RU_SYNCHRONIZE(PhysicsManager::get());
00035     setGeomId(dCreateSphere(0, radius()));
00036 }
00037 
00038 void
00039 SphereShape::createDebugNode()
00040 {
00041     debugNode()->clear();
00042     
00043     if(!debugNodeActive())
00044         return;
00045     
00046     debugNode()->append(new VRS::ColorAttribute(1.0, 0.3, 0.3, 0.3));
00047     debugNode()->append(new VRS::Translation(offsetCenter()));
00048     debugNode()->append(new VRS::ConstantDetail(8, 8));
00049     debugNode()->append(new VRS::Sphere(radius() + 0.1));
00050 }
00051 
00052 void
00053 SphereShape::setRadius(double p_radius)
00054 {
00055     // RU_SYNCHRONIZE(PhysicsManager::get());
00056     m_bounds = VRS::Bounds(VRS::Vector(-p_radius, -p_radius, -p_radius),
00057                            VRS::Vector(p_radius, p_radius, p_radius));
00058     createDebugNode();
00059     dGeomSphereSetRadius(geomId(), p_radius);
00060 }
00061 
00062 double
00063 SphereShape::radius()
00064 {
00065     double sX  = m_bounds.getURB()[0] - m_bounds.getLLF()[0];
00066     double sY  = m_bounds.getURB()[1] - m_bounds.getLLF()[1];
00067     double sZ  = m_bounds.getURB()[2] - m_bounds.getLLF()[2];
00068     return fmax(sX, fmax(sY, sZ)) / 2.0;
00069 }
00070 
00071 void
00072 SphereShape::setBounds(VRS::Bounds p_bounds)
00073 {
00074     // RU_SYNCHRONIZE(PhysicsManager::get());
00075     m_bounds = p_bounds;
00076     createDebugNode();
00077     dGeomSphereSetRadius(geomId(), radius());
00078 }
00079 
00080 VRS::Bounds
00081 SphereShape::bounds()
00082 {
00083     return m_bounds;
00084 }
00085 
00086 }

Generated on Fri May 11 21:01:58 2007 for Random Racer by  doxygen 1.5.1