Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

box.cc

Go to the documentation of this file.
00001 #include "box.hh"
00002 #include "register.hh"
00003 #include "abstractworld.hh"
00004 
00005 namespace anoid {
00006     namespace plugin {
00007 
00008         using namespace simple;
00009         using namespace config;
00010 
00011         DtShapeRef boxshape;
00012         int boxdisplay; // For some reason I cannot load classes with static members
00013 
00014         bool boxinited = false;
00015 
00016         void Box::redraw() {
00017             getWorld()->getContext()->drawFigure(boxdisplay);
00018             Shape::redraw();
00019         }
00020 
00021         void Box::init(Configuration &c) {
00022             if (!boxinited) {
00023                 boxinited = true;
00024                 boxdisplay = getWorld()->getContext()->beginFigure();
00025 
00026                 boxshape = dtBox(1.0,1.0,1.0);
00027 
00028                 // Front Face
00029                 getWorld()->getContext()->drawQuad(Vector(-0.5, -0.5, 0.5),
00030                         Vector(0.5, -0.5, 0.5),
00031                         Vector(0.5, 0.5, 0.5),
00032                         Vector(-0.5, 0.5, 0.5),
00033                         Vector(0.0, 0.0, 1.0));
00034 
00035                 // Back Face
00036                 getWorld()->getContext()->drawQuad(Vector(-0.5, -0.5, -0.5),
00037                         Vector(-0.5, 0.5, -0.5),
00038                         Vector( 0.5, 0.5, -0.5),
00039                         Vector( 0.5, -0.5, -0.5),
00040                         Vector( 0.0, 0.0, -1.0));
00041 
00042                 // Top Face
00043                 getWorld()->getContext()->drawQuad(Vector(-0.5, 0.5, -0.5),
00044                         Vector(-0.5, 0.5, 0.5),
00045                         Vector( 0.5, 0.5, 0.5),
00046                         Vector( 0.5, 0.5, -0.5),
00047                         Vector( 0.0, 1.0, 0.0));
00048 
00049 
00050                 // Bottom Face
00051                 getWorld()->getContext()->drawQuad(Vector(-0.5, -0.5, -0.5),
00052                         Vector( 0.5, -0.5, -0.5),
00053                         Vector( 0.5, -0.5, 0.5),
00054                         Vector(-0.5, -0.5, 0.5),
00055                         Vector( 0.0, -1.0, 0.0));
00056                 // Right Face
00057                 getWorld()->getContext()->drawQuad(Vector( 0.5, -0.5, -0.5),
00058                         Vector( 0.5, 0.5, -0.5),
00059                         Vector( 0.5, 0.5, 0.5),
00060                         Vector( 0.5, -0.5, 0.5),
00061                         Vector(1.0, 0.0, 0.0));
00062 
00063                 // Left Face
00064                 getWorld()->getContext()->drawQuad(Vector(-0.5, -0.5, -0.5),
00065                         Vector(-0.5, -0.5, 0.5),
00066                         Vector(-0.5, 0.5, 0.5),
00067                         Vector(-0.5, 0.5, -0.5),
00068                         Vector(-1.0, 0.0, 0.0));
00069 
00070                 getWorld()->getContext()->endFigure();
00071             }
00072             dtCreateObject(parent, boxshape);
00073             Shape::init(c);
00074         }
00075 
00076         void Box::getInverseInertiaTensor(double *output, double a, double b, double c) {
00077             Shape::getInverseInertiaTensor(output, a, b, c);
00078 
00079             output[0] = 12.0 / (b*b + c*c);
00080             output[5] = 12.0 / (a*a + c*c);
00081             output[10] = 12.0 / (a*a + b*b);
00082         }
00083 
00084         Register(Box)
00085 
00086     };
00087 };

Anoid NG © Michael Westergaard, Martin Stig Stissing, Ronni Michael Laursen, and Kristian Bisgaard Lassen