// The sample box model. You should build a file // very similar to this for when you make your model. #include "modelerview.h" #include "modelerapp.h" #include "modelerdraw.h" #include // This is a list of the controls for the RobotArm // We'll use these constants to access the values // of the controls from the user interface. enum BoxModelControls { XPOS, YPOS, ZPOS, HEIGHT, NUMCONTROLS }; // To make a BoxModel, we inherit off of ModelerView class BoxModel : public ModelerView { public: BoxModel(int x, int y, int w, int h, char *label) : ModelerView(x,y,w,h,label) {} virtual void draw(); }; // We need to make a creator function, mostly because of // nasty API stuff that we'd rather stay away from. ModelerView* createBoxModel(int x, int y, int w, int h, char *label) { return new BoxModel(x,y,w,h,label); } // We'll be getting the instance of the application a lot; // might as well have it as a macro. #define VAL(x) (ModelerApplication::Instance()->GetControlValue(x)) // We are going to override (is that the right word?) the draw() // method of ModelerView to draw out RobotArm void BoxModel::draw() { // This call takes care of a lot of the nasty projection // matrix stuff. Unless you want to fudge directly with the // projection matrix, don't bother with this ... ModelerView::draw(); // draw the floor setAmbientColor(.1f,.1f,.1f); setDiffuseColor(.5f,.5,0); glPushMatrix(); glTranslated(-2.5,0,-2.5); drawBox(5,0.01f,5); glPopMatrix(); // draw the box setAmbientColor(.1f,.1f,.1f); setDiffuseColor(0,1,.5f); glPushMatrix(); glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS)); glTranslated(-.5,0,-.5); glScaled(1, VAL(HEIGHT), 1); drawBox(1,1,1); glPopMatrix(); } int main() { // Initialize the controls // Constructor is ModelerControl(name, minimumvalue, maximumvalue, // stepsize, defaultvalue) ModelerControl controls[NUMCONTROLS]; controls[XPOS] = ModelerControl("X Position", -5, 5, 0.1f, 0); controls[YPOS] = ModelerControl("Y Position", 0, 5, 0.1f, 0); controls[ZPOS] = ModelerControl("Z Position", -5, 5, 0.1f, 0); controls[HEIGHT] = ModelerControl("Height", 1, 5, 0.1f, 1); ModelerApplication::Instance()->Init(&createBoxModel, controls, NUMCONTROLS); return ModelerApplication::Instance()->Run(); }