// 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 #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, ROT, NUMCONTROLS, }; // To make a BoxModel, we inherit off of ModelerView class BoxModel : public ModelerView { public: // Constructor for the model. In your model, // make sure you call the ModelerView constructor, // as done below. BoxModel(int x, int y, int w, int h, char *label) : ModelerView(x,y,w,h,label) {} virtual void draw(); // draw one branch of the tea tree void drawBranch(); }; // 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)) // draw branch function void BoxModel::drawBranch() { // draw one auto tea pourer glPushMatrix(); drawBox(1,1,1); glTranslated(0, 1.0, 0); glRotated(VAL(XPOS), 0, 0, 1); drawBox(1,1,1); glTranslated(0, 1.0, 0); glRotated(VAL(XPOS), 0, 0, 1); drawBox(1,1,1); glTranslated(0, 1.0, 0); glRotated(VAL(XPOS), 0, 0, 1); drawBox(1,1,1); glTranslated(0, 1.0, 0); glRotated(VAL(XPOS), 0, 0, 1); drawBox(1,1,1); glTranslated(0, 1.0, 0); glRotated(VAL(XPOS), 0, 0, 1); drawBox(1,1,1); // now the teapot glTranslated(.5, 1.0, 0.5); glutSolidTeapot(1); glPopMatrix(); } // 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(); // Set up our colors setAmbientColor(1,.1f,.1f); setDiffuseColor(.5f,1,.5f); glPushMatrix(); glScaled(0.5, 0.5, 0.5); glRotated(VAL(ROT), 0, 1, 0); // draw the first tea branch glPushMatrix(); glTranslated(2,0,0); drawBranch(); glPopMatrix(); // draw the second tea branch glPushMatrix(); glRotated(90, 0, 1, 0); glTranslated(2,0,0); drawBranch(); glPopMatrix(); // draw the third tea branch glPushMatrix(); glRotated(180, 0, 1, 0); glTranslated(2,0,0); drawBranch(); glPopMatrix(); // draw the final tea branch glPushMatrix(); glRotated(270, 0, 1, 0); glTranslated(2,0,0); drawBranch(); glPopMatrix(); glPopMatrix(); } int main() { // Initialize the controls // Constructor is ModelerControl(name, minimumvalue, maximumvalue, // stepsize, defaultvalue) // You will want to modify this to accommodate your model. ModelerControl controls[NUMCONTROLS]; controls[XPOS] = ModelerControl("Pour Tea", -90, 90, 1.0f, 0); controls[ROT] = ModelerControl("Rotate Tea Tree", -90, 90, 1.0f, 0); // Initialize the modeler application with your model and the // appropriate array of controls. ModelerApplication::Instance()->Init(&createBoxModel, controls, NUMCONTROLS); // make sure we give back the memory to older OSs that don't // clear your memory pool after shutdown. int Result = ModelerApplication::Instance()->Run(); delete ModelerApplication::Instance(); return Result; }