那你这个就是要做编辑器啊,类似3dmax之类。知识点不一样
有些是有大小参数的如 void auxSolidSphere (GLdouble radius)// 实形球 (半径)
//SHAPES.C #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <GL/gl.h> #include <GL/glu.h> #include "3d.h" #define SPHEREWIRE 0 #define CUBEWIRE 1 #define BOXWIRE 2 #define TORUSWIRE 3 #define CYLINDERWIRE 4 #define ICOSAWIRE 5 #define OCTAWIRE 6 #define TETRAWIRE 7 #define DODECAWIRE 8 #define CONEWIRE 9 #define SPHERESOLID 10 #define CUBESOLID 11 #define BOXSOLID 12 #define TORUSSOLID 13 #define CYLINDERSOLID 14 #define ICOSASOLID 15 #define OCTASOLID 16 #define TETRASOLID 17 #define DODECASOLID 18 #define CONESOLID 19 #define PI ((GLdouble)3.1415926535897) GLuint findList (int index, GLdouble *paramArray, int size); int compareParams (GLdouble *oneArray, GLdouble *twoArray,int size); GLuint makeModelPtr (int index, GLdouble *sizeArray, int count); void drawbox(GLdouble, GLdouble, GLdouble,GLdouble, GLdouble, GLdouble, GLenum); void doughnut(GLdouble, GLdouble, GLint, GLint, GLenum); void icosahedron(GLdouble *,GLdouble, GLenum); void octahedron(GLdouble *, GLdouble, GLenum); void tetrahedron(GLdouble *, GLdouble, GLenum); void subdivide(int,GLdouble *,GLdouble *,GLdouble *,GLdouble *,GLdouble,GLenum,int); void drawtriangle(int, int, int,GLdouble *,GLdouble,GLenum,int); void recorditem(GLdouble *, GLdouble *, GLdouble *, GLdouble *, GLdouble, GLenum, int); void initdodec(void); void dodecahedron(GLdouble *, GLdouble, GLenum); void pentagon(int, int, int, int, int, GLenum); /* structure for each geometric object */ typedef struct model { GLuint list; /* display list to render object */ struct model *ptr; /* pointer to next object */ int numParam; /* # of parameters */ GLdouble *params; /* array with parameters */ } MODEL, *MODELPTR; /* array of linked lists--used to keep track of display lists * for each different type of geometric object. */ static MODELPTR lists[25] = {0}; // void auxWireSphere (GLdouble radius) { GLUquadricObj *quadObj; GLdouble *sizeArray; GLuint displayList; sizeArray = (GLdouble *)malloc(sizeof (GLdouble) * 1); *sizeArray = radius; displayList = findList (SPHEREWIRE, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr (SPHEREWIRE, sizeArray, 1),GL_COMPILE_AND_EXECUTE); quadObj = gluNewQuadric (); gluQuadricDrawStyle (quadObj, GLU_LINE); gluSphere (quadObj, radius, 16, 16); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidSphere (GLdouble radius) { GLUquadricObj *quadObj; GLdouble *sizeArray; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 1); *sizeArray = radius; displayList = findList (SPHERESOLID, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr (SPHERESOLID, sizeArray, 1),GL_COMPILE_AND_EXECUTE); quadObj = gluNewQuadric (); gluQuadricDrawStyle (quadObj, GLU_FILL); gluQuadricNormals (quadObj, GLU_SMOOTH); gluSphere (quadObj, radius, 16, 16); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid cube. If no display list with * the current model size exists, create a new display list. */ void auxWireCube (GLdouble size) { GLdouble *sizeArray; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 1); *sizeArray = size; displayList = findList (CUBEWIRE, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr (CUBEWIRE, sizeArray, 1), GL_COMPILE_AND_EXECUTE);// ListMode drawbox(-size/(GLdouble)2.,size/(GLdouble)2., -size/(GLdouble)2., size/(GLdouble)2., -size/(GLdouble)2.,size/(GLdouble)2.,GL_LINE_LOOP); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidCube (GLdouble size) { GLdouble *sizeArray; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 1); *sizeArray = size; displayList = findList (CUBESOLID, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr (CUBESOLID, sizeArray, 1), GL_COMPILE_AND_EXECUTE); drawbox(-size/(GLdouble)2.,size/(GLdouble)2.,-size/(GLdouble)2.,size/(GLdouble)2.,-size/(GLdouble)2.,size/(GLdouble)2.,GL_QUADS); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid cube. If no display list with * the current model size exists, create a new display list. */ void auxWireBox (GLdouble width, GLdouble height, GLdouble depth) { GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 3); tmp = sizeArray; *tmp++ = width; *tmp++ = height; *tmp++ = depth; displayList = findList (BOXWIRE, sizeArray, 3); if (displayList == 0) { glNewList(makeModelPtr (BOXWIRE, sizeArray, 3),GL_COMPILE_AND_EXECUTE); drawbox(-width/(GLdouble)2., width/(GLdouble)2., -height/(GLdouble)2., height/(GLdouble)2.,-depth/(GLdouble)2., depth/(GLdouble)2., GL_LINE_LOOP); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidBox (GLdouble width, GLdouble height, GLdouble depth) { GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 3); tmp = sizeArray; *tmp++ = width; *tmp++ = height; *tmp++ = depth; displayList = findList (BOXSOLID, sizeArray, 3); if (displayList == 0) { glNewList(makeModelPtr (BOXSOLID, sizeArray, 3), GL_COMPILE_AND_EXECUTE); drawbox(-width/(GLdouble)2., width/(GLdouble)2., -height/(GLdouble)2.,height/(GLdouble)2., -depth/(GLdouble)2., depth/(GLdouble)2., GL_QUADS); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid tori. If no display list with * the current model size exists, create a new display list. */ void auxWireTorus (GLdouble innerRadius, GLdouble outerRadius) { GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 2); tmp = sizeArray; *tmp++ = innerRadius; *tmp++ = outerRadius; displayList = findList (TORUSWIRE, sizeArray, 2); if (displayList == 0) { glNewList(makeModelPtr (TORUSWIRE, sizeArray, 2), GL_COMPILE_AND_EXECUTE); doughnut(innerRadius, outerRadius, 5, 10, GL_LINE_LOOP); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidTorus (GLdouble innerRadius, GLdouble outerRadius) { GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 2); tmp = sizeArray; *tmp++ = innerRadius; *tmp++ = outerRadius; displayList = findList (TORUSSOLID, sizeArray, 2); if (displayList == 0) { glNewList(makeModelPtr (TORUSSOLID, sizeArray, 2), GL_COMPILE_AND_EXECUTE); doughnut(innerRadius, outerRadius, 8, 15, GL_QUADS); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid cylinders. If no display list with * the current model size exists, create a new display list. */ void auxWireCylinder (GLdouble radius, GLdouble height) { GLUquadricObj *quadObj; GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 2); tmp = sizeArray; *tmp++ = radius; *tmp++ = height; displayList = findList (CYLINDERWIRE, sizeArray, 2); if (displayList == 0) { glNewList(makeModelPtr (CYLINDERWIRE, sizeArray, 2),GL_COMPILE_AND_EXECUTE); glPushMatrix (); glRotatef ((GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0); // glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.0);//y ^ quadObj = gluNewQuadric (); gluQuadricDrawStyle (quadObj,GLU_LINE); gluCylinder (quadObj, radius, radius, height, 12, 2); glPopMatrix (); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidCylinder (GLdouble radius, GLdouble height) { GLUquadricObj *quadObj; GLdouble *sizeArray, *tmp; GLuint displayList; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 2); tmp = sizeArray; *tmp++ = radius; *tmp++ = height; displayList = findList (CYLINDERWIRE, sizeArray, 2); if (displayList == 0) { glNewList(makeModelPtr (CYLINDERWIRE, sizeArray, 2),GL_COMPILE_AND_EXECUTE); glPushMatrix (); glRotatef((GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0); glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.0); quadObj = gluNewQuadric (); gluQuadricDrawStyle (quadObj, GLU_FILL); gluQuadricNormals (quadObj, GLU_SMOOTH); gluCylinder (quadObj, radius, radius, height, 12, 2); glPopMatrix (); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid icosahedra. If no display list with * the current model size exists, create a new display list. */ void auxWireIcosahedron (GLdouble radius) { GLdouble *sizeArray; GLuint displayList; GLdouble center[3] = {(GLdouble)0.0, (GLdouble)0.0, (GLdouble)0.0}; sizeArray = (GLdouble *) malloc (sizeof (GLdouble) * 1); *sizeArray = radius; displayList = findList (ICOSAWIRE, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr(ICOSAWIRE, sizeArray, 1),GL_COMPILE_AND_EXECUTE); icosahedron (center, radius, GL_LINE_LOOP); glEndList(); } else { glCallList(displayList); free (sizeArray); } } // void auxSolidIcosahedron (GLdouble radius) { GLdouble *sizeArray; GLuint displayList; GLdouble center[3] = {(GLdouble)0.0, (GLdouble)0.0, (GLdouble)0.0}; sizeArray = (GLdouble *)malloc (sizeof (GLdouble) * 1); *sizeArray = radius; displayList = findList (ICOSASOLID, sizeArray, 1); if (displayList == 0) { glNewList(makeModelPtr (ICOSASOLID, sizeArray, 1),GL_COMPILE_AND_EXECUTE); icosahedron (center, radius,GL_TRIANGLES); glEndList(); } else { glCallList(displayList); free (sizeArray); } } /* Render wire frame or solid octahedra. If no display list with * the current model size exists, create a new display list. */
https://github.com/ArsMasiuk/qvge
没搞过。不过,应该和2D差不多。记录鼠标按键按下的位置。跟踪鼠标移动并刷新一些效果,在鼠标释放时创建对象。
19,468
社区成员
50,698
社区内容
加载中
试试用AI创作助手写篇文章吧