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