/* Copyright 1999, Be Incorporated. All Rights Reserved. This file may be used under the terms of the Be Sample Code License. */ #include "GLObject.h" #include #include #include #include "glob.h" struct material { float ambient[3], diffuse[3], specular[3]; }; float *colors[] = {NULL, white, yellow, blue, red, green}; material materials[] = { // Null { {0.1745, 0.03175, 0.03175}, {0.61424, 0.10136, 0.10136}, {0.727811, 0.626959, 0.626959} }, // White { {0.1745, 0.1745, 0.1745}, {0.61424, 0.61424, 0.61424}, {0.727811, 0.727811, 0.727811} }, // Yellow { {0.1745, 0.1745, 0.03175}, {0.61424, 0.61424, 0.10136}, {0.727811, 0.727811, 0.626959} }, // Blue { {0.03175, 0.03175, 0.1745}, {0.10136, 0.10136, 0.61424}, {0.626959, 0.626959, 0.727811} }, // Red { {0.1745, 0.03175, 0.03175}, {0.61424, 0.10136, 0.10136}, {0.727811, 0.626959, 0.626959} }, // Green { {0.03175, 0.1745, 0.03175}, {0.10136, 0.61424, 0.10136}, {0.626959, 0.727811, 0.626959} }, }; #define USE_QUAD_STRIPS 1 extern long setEvent(sem_id event); GLObject::GLObject(ObjectView *ov) : rotX(0), rotY(0), lastRotX(0), lastRotY(0), spinX(2), spinY(2), x(0), y(0), z(-2.0), color(4), solidity(0), changed(false), objView(ov) { }; GLObject::~GLObject() { }; void GLObject::MenuInvoked(BPoint point) { BPopUpMenu *m = new BPopUpMenu("Object",false,false); BMenuItem *i; int c = 1; m->AddItem(i = new BMenuItem("White",NULL)); if (color == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Yellow",NULL)); if (color == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Blue",NULL)); if (color == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Red",NULL)); if (color == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Green",NULL)); if (color == c++) i->SetMarked(true); m->AddSeparatorItem(); c = 0; m->AddItem(i = new BMenuItem("Solid",NULL)); if (solidity == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Translucent",NULL)); if (solidity == c++) i->SetMarked(true); m->AddItem(i = new BMenuItem("Transparent",NULL)); if (solidity == c++) i->SetMarked(true); i = m->Go(point); int32 index = m->IndexOf(i); delete m; if (index < 5) { color = index+1; } else if (index > 5) { solidity = index-6; }; changed = true; setEvent(objView->drawEvent); }; bool GLObject::SpinIt() { rotX += spinX; rotY += spinY; bool c = changed; c = c || ((rotX != lastRotX) || (rotY != lastRotY)); lastRotX = rotX; lastRotY = rotY; return c; }; void GLObject::Draw(bool forID, float IDcolor[]) { glPushMatrix(); glTranslatef(x, y, z); glRotatef(rotY, 0.0,1.0,0.0); glRotatef(rotX, 1.0,0.0,0.0); if (forID) { glColor3fv(IDcolor); }; DoDrawing(forID); glPopMatrix(); changed = false; }; TriangleObject::TriangleObject(ObjectView *ov, char *filename) : GLObject(ov), points(100,100), triangles(100,100), qs(50,50) { float maxp=0; int numPt,numTri; FILE *f = fopen(filename,"r"); fscanf(f,"%d",&numPt); // printf("Points: %d\n",numPt); for (int i=0;i maxp) maxp = fabs(p.x); if (fabs(p.y) > maxp) maxp = fabs(p.y); if (fabs(p.z) > maxp) maxp = fabs(p.z); points.add(p); }; for (int i=0;i