00001
00002 #include "CylinderShape.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/cylinder.h>
00010 #include <vrs/translation.h>
00011 #include <vrs/opengl/transparencytechniquegl.h>
00012
00013 namespace vrsode
00014 {
00015
00016 CylinderShape::CylinderShape(VRS::Vector p_direction,
00017 double p_height, double p_radius)
00018 {
00019 setCollisionShape(CS_Cylinder);
00020
00021 m_direction = p_direction;
00022 m_direction.normalize();
00023 m_height = p_height;
00024 m_radius = p_radius;
00025
00026 createDebugNode();
00027 createGeometry();
00028 }
00029
00030 CylinderShape::~CylinderShape()
00031 {
00032
00033 }
00034
00035 void
00036 CylinderShape::createGeometry()
00037 {
00038 setGeomId(dCreateCylinder(0, m_radius, m_height));
00039
00040 VRS::Vector initialDirection(0,0,1);
00041
00042 double angle = acos(m_direction.dotProduct(initialDirection));
00043 angle /= 3.14159265358979;
00044 angle *= 180.0;
00045
00046 VRS::Vector axis;
00047 if(angle)
00048 axis = m_direction.crossProduct(initialDirection);
00049 else
00050 axis = initialDirection;
00051
00052 offsetRotation()->setAngle(angle);
00053 offsetRotation()->setAxis(axis);
00054 offsetRotation()->setCenter(VRS::Vector(0,0,0));
00055 }
00056
00057 void
00058 CylinderShape::createDebugNode()
00059 {
00060 debugNode()->clear();
00061
00062 if(!debugNodeActive())
00063 return;
00064
00065 debugNode()->append(offsetRotation());
00066 debugNode()->append(new VRS::ColorAttribute(1.0, 0.3, 0.3, 0.3));
00067 debugNode()->append(new VRS::Translation(offsetCenter()));
00068 debugNode()->append(new VRS::ConstantDetail(8, 8));
00069 debugNode()->append(new VRS::Cylinder(VRS::Vector(0, 0, m_height * 0.5),
00070 VRS::Vector(0, 0, m_height * -0.5),
00071 m_radius, 360));
00072 }
00073
00074 }