int loadObj(struct obj_t *obj,const char *objFile, char *vert, char *frag) { FILE *pFile; pFile = fopen( objFile , "rb" ); if (pFile==NULL) { printf("Cant find open model - %s\n",objFile); return false; } unsigned int magic; int NumVerts; fread (&magic,1, sizeof(unsigned int), pFile ); if (magic!=0x614f4247) { printf("Does not appear to be a version 'a' GBO file\n"); return false; } fread(&NumVerts,1,sizeof(unsigned int), pFile ); float* Verts = malloc(sizeof(float) * 3 * NumVerts); fread(Verts,1,sizeof(float) * 3 * NumVerts, pFile ); float* Norms = malloc(sizeof(float) * 3 * NumVerts); fread(Norms,1,sizeof(float) * 3 * NumVerts, pFile ); float* TexCoords = malloc(sizeof(float) * 2 * NumVerts); fread(TexCoords,1,sizeof(float) * 2 * NumVerts, pFile ); createObj(obj,NumVerts,Verts,TexCoords,Norms,vert,frag); free(TexCoords); free(Norms); free(Verts); return true; }
CallbackLinkedObj *CallbackQueue::schedule(lsi_callback_queue_pf cb, LsiSession *session, long lParam, void *pParam) { CallbackLinkedObj *pObj = createObj(cb, session, lParam, pParam); if (pObj) m_callbackObjList.append(pObj); return pObj; }
static PyObject* pyLoadObj(PyObject *self, PyObject *args) { char* filename; if(!PyArg_ParseTuple(args, "s", &filename)) return NULL; // Load obj & print info int id = createObj(); loadObj(filename, id); printf("Loaded: %i\n", id); return Py_BuildValue("i", id); }
int createConstraints(const Problem<double>& P, IloEnv& env, IloModel& model, IloNumVarArray& t, IloNumVarMatrix& x, IloNumVarMatrix& y, IloNumVarMatrix& b, IloNumVarMatrix& w,const std::vector<int>& config){ try { assert(config[1]+config[2]<=1); std::vector<std::vector<double>> bound(2*P.nbTask-1); std::vector<double> bd(2*P.nbTask,P.D); createObj(P,env,model,b);//objective min b_ie createConstraintStartBeforeEnd(P,env, model,x,y); createConstraintOrd(P,model,t);//contrainte te < te+1 createConstraintOneStart(P,env,model,x,y);//contrai sum zie>=1 createConstraintCapacity(P,env,model,t,b);//contrainte capacity createConstraintMinDur(P,model,t,x,y);//durée minimale createConstraintEnergy(P,env,model,t,b,w);//contrainte Wi createConstraintNulEnergy(P,env,model,x,y,w); createConstraintBmax(P,model,t,b);//contrainte bmax createConstraintNonConsump(P,model,env,x,y,b,config[3]);//bie=0 si zie=0 //additional constraints if (config[0]) { boundSepEvts(P,bound,config[0]); createConstraintSepEvt(P,model,t,bound); if (config[1]) createConstraintBmin(P,model,env,t,x,y,b,bound); //contrainte bmin } else if (config[1]){ boundSepEvts(P,bound,config[1]); createConstraintBmin(P,model,env,t,x,y,b,bound); //contrainte bmin } else createConstraintBmin(P,model,env,t,x,y,b,config[2]); //contrainte bmin if (config[5]) boundEvts(P,bd); createConstraintTimeW(P,model,t,x,y,bd);// te > ri et tf < di if (config[4]) { if (!config[5]) boundEvts(P,bd); createConstraintBoundEvt(P,model,t,bd); } if (config[6]) createConstraintKnapsack(P,env,model,x,y);//knapsack return 0; } catch (IloException& e){ std::cout << "iloexcpetion in createConstraint" << e <<std::endl; e.end(); return 1; } }
CallbackLinkedObj *CallbackQueue::scheduleSessionCb(lsi_callback_queue_pf cb, LsiSession *pSession, long lParam, void *pParam, CBQSessionHeader &header) { CallbackLinkedObj *pObj = createObj(cb, pSession, lParam, pParam); if (pObj) { if (header.get() == NULL) { header.set(pObj); m_callbackObjList.append(pObj); } else { m_callbackObjList.append(header.get(), pObj); logState("scheduleSessionCb()][Header EXIST", pObj); } } return pObj; }
GrDebugGL::GrDebugGL() : fPackRowLength(0) , fUnPackRowLength(0) , fCurTextureUnit(0) , fArrayBuffer(NULL) , fElementArrayBuffer(NULL) , fFrameBuffer(NULL) , fRenderBuffer(NULL) , fProgram(NULL) , fTexture(NULL) , fVertexArray(NULL) , fAbandoned(false) { for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>( createObj(GrDebugGL::kTextureUnit_ObjTypes)); fTextureUnits[i]->ref(); fTextureUnits[i]->setNumber(i); } }
/******************************************************************* City Modelling Program ********************************************************************/ ////////// #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> //#include <gl/glut.h> #include "Dependencies\freeglut\freeglut.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <utility> #include <vector> #include "VECTOR3D.h" #include "TerrainGrid.h" #include "Mesh.h" #include "RGBpixmap.h" #include "ComplexObj.h" void initOpenGL(); void display(void); void reshape(int w, int h); void mouse(int button, int state, int x, int y); void mouseMotionHandler(int xMouse, int yMouse); void keyboard(unsigned char key, int x, int y); void functionKeys(int key, int x, int y); void timer(int value); VECTOR3D ScreenToWorld(int x, int y); void updateCameraPos(); void limitCameraAngle(); bool hasCollision(const Mesh* a, Mesh* b[], Mesh* c[], Mesh* d[], float offset, int sizeb, int sizec, int sized); bool hasObjCollision(const Mesh* a, ComplexObj *cobj[], int sizee); void createBoundaryWalls(); void createInnerWalls(); void createDoors(); static int currentButton; static unsigned char currentKey; #define M_PI 3.14159265358979323846 const float FPS = 30.0; // City Interaction State Variable enum Action {TRANSLATE, ROTATE, RAISE, SCALE, EXTRUDE, SELECT, MULTIPLESELECT, DESELECT_ALL, NAVIGATE}; enum Action currentAction = TRANSLATE; GLfloat light_position0[] = {12.0, 6.0,-12.0,1.0}; GLfloat light_position1[] = {-12.0, 6.0,12.0,1.0}; GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_ambient[] = {0.2, 0.2, 0.2, 1.0}; // Person mesh - head + body Mesh *personBody; GLUquadricObj *personHead; // City terrain mesh TerrainGrid *terrainGrid = NULL; int gridSize = 16; // Wall Meshes Mesh *boundaryWalls[4]; // boundary walls that surround the world Mesh *innerWalls[20]; // inner walls of the rooms & world Mesh *doors[20]; // inner walls of the rooms & world float wallHeight = 1.0f; // wall height of all (boundary, inner) walls int numBoundaryWalls = 0, numInnerWalls = 0, numDoors = 0; RGBpixmap floorPix[1], boundaryWallPix[1], innerWallPix[1], doorPix[2]; // Room Objects ComplexObj *cobj[12]; //int nextobj = 0; //index to objects array to store next cube ComplexObj *navobj; //selected object in NAVIGATE mode bool objCollision = false; // state to toggle avatar and object collision float trsize = 0.2, scsize = 0.2, rosize = 5.0; //translation, scaling and rotation angle deltas // Textures GLuint textureId; // Camera Control VECTOR3D lookFrom; VECTOR3D lookAt; VECTOR3D up; float radius = 8; // Camera Distance float lookFromx = 0; // Camera X Position float lookFromy = 0; // Camera Y Position float lookFromz = radius; // Camera Z Position float angleTheta = 0; // Camera X angle float anglePhi = 80; // Camera Y angle float upx = 0; // Up Vector float upy = 1; float upz = 0; float lookAtx = 0; // Camera is looking at float lookAty = 0; float lookAtz = 0; float camerax = 0; // Camera X Position float cameray = 0; // Camera Y Position float cameraz = radius; // Camera Z Position static float zoomFactor = 1.0; float xbefore; // Previous X position of tank float zbefore; // Previous Y position of tank float collision_offset = 0.4; //GLint glutWindowWidth = 750; //GLint glutWindowHeight = 500; GLint glutWindowWidth = 1200; GLint glutWindowHeight = 800; GLint viewportWidth = glutWindowWidth; GLint viewportHeight = glutWindowHeight; // Wolrd Boundaries GLdouble worldLeftBase = -8.0; GLdouble worldRightBase = 8.0; GLdouble worldBottomBase= -8.0; GLdouble worldTopBase = 8.0; // World view boundaries GLdouble wvLeftBase = worldLeftBase, wvRightBase = worldRightBase, wvBottomBase = worldBottomBase, wvTopBase = worldTopBase; int main(int argc, char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //glutInitWindowSize(750, 500); glutInitWindowSize(glutWindowWidth, glutWindowHeight); glutInitWindowPosition(100, 100); glutCreateWindow("Room Navigator"); floorPix[0].readBMPFile("FloorWood01.bmp"); boundaryWallPix[0].readBMPFile("WallBrick02.bmp"); innerWallPix[0].readBMPFile("WallWood01.bmp"); doorPix[0].readBMPFile("Door01L.bmp"); doorPix[1].readBMPFile("Door01R.bmp"); initOpenGL(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(mouseMotionHandler); glutKeyboardFunc(keyboard); glutSpecialFunc(functionKeys); glutTimerFunc(1000.0 / FPS, timer, 0); glutMainLoop(); return 0; } int width, height; VECTOR3D scale; VECTOR3D trans; VECTOR3D angles; // Setup openGL */ void initOpenGL(){ glViewport(0, 0, (GLsizei) viewportWidth, (GLsizei) viewportHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0*zoomFactor,(float)viewportWidth/(float)viewportHeight,0.2,80.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set up and enable lighting glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position0); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glClearColor(0.6, 0.6, 0.6, 0.0); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); //Nice perspective. glHint(GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); updateCameraPos(); gluLookAt(lookFromx, lookFromy, lookFromz,lookAtx, lookAty, lookAtz, upx, upy, upz); //Texture glGenTextures(1, &textureId); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // store pixels by byte glBindTexture(GL_TEXTURE_2D, textureId); // select current texture (0) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set up Terrain Grid VECTOR3D origin = VECTOR3D(-16.0f, 0.0f, 16.0f); terrainGrid = new TerrainGrid(gridSize, 32.0); // gridsize = 16 terrainGrid->InitGrid(gridSize, origin, 32.0, 32.0); createBoundaryWalls(); // Create boundary walls createInnerWalls(); // create inner walls createDoors(); // create doors // Create a person (Head+Body) - initially oriented along z axis direction (-ve z dir (0,0,-1) & ccw => angles.y = 0) scale.x = 0.5; scale.y = 1.4; scale.z = 0.2; trans.x = -2.0; trans.y = 0; trans.z = 8.0; personBody = createMesh(scale, trans, 1.0, 1); personBody->angles.x = personBody->angles.y = personBody->angles.z = 0.0; personBody->selected = true; // Create room objects (4 kinds) for (int i = 0; i < 12; i++){ cobj[i] = createObj(); } createShield(cobj[0]); cobj[0]->translation.Set( 0.0, 2.0, 15.0); cobj[0]->angles.Set(0.0, 180.0, 0.0); createShield(cobj[1]); cobj[1]->translation.Set(-8.0, 2.0, -15.0); createShield(cobj[2]); cobj[2]->translation.Set( 8.0, 2.0, -15.0); createTable( cobj[3]); cobj[3]->translation.Set(14.0, 0.0, 2.0); createTable( cobj[4]); cobj[4]->translation.Set(14.0, 0.0,-2.0); createTable( cobj[5]); cobj[5]->translation.Set(-14.0,0.0,-2.0); createVase( cobj[6]); cobj[6]->translation.Set(14.0, 0.0, 4.0); createVase( cobj[7]); cobj[7]->translation.Set(-14.0, 0.0,-14.0); createVase( cobj[8]); cobj[8]->translation.Set(14.0, 0.0,-14.0); createPicFrame(cobj[9]); cobj[9]->translation.Set(8.0, 2.0, 15.0); cobj[9]->angles.Set(0.0, 180.0, 0.0); createPicFrame(cobj[10]); cobj[10]->translation.Set(-15.0, 2.0, -8.0); cobj[10]->angles.Set(0.0, 90.0, 0.0); createPicFrame(cobj[11]); cobj[11]->translation.Set(15.0, 2.0, -8.0); cobj[11]->angles.Set(0.0, -90.0, 0.0); }
Item* ItemFactory::createObj(int ID) { std::vector<std::string> arr = this->getInfoByID(ID); return createObj(arr); }
int execSetCommand(char (*argv)[ARGUMENTCNT]) { valObject *val = createObj(argv[2]); return setCommand(argv[1], val); }