arrays - Trying to make a world mesh that I can change at will c++ OpenGL -


so, have project trying build. goal have list of gl_quads hold level structure. want able add , remove cubes list , have opengl render it.

my problem arrays dont seem expandable. have allready written code allows me press space , create cube, need someway create make array of points creates cube longer @ will. if there way expand arrays needed ears.

here of code... might not need @ answer question. have sudo coded out irrelivant sections.

#include <gltools.h>     #include <glmatrixstack.h> #include <glframe.h> #include <glfrustum.h> #include <glbatch.h> #include <glgeometrytransform.h>  #include <math.h> #ifdef __apple__ #include <glut/glut.h> #else #define freeglut_static #include <gl/glut.h> #endif   // assortment of needed classes glshadermanager     shadermanager; glmatrixstack       modelviewmatrix; glmatrixstack       projectionmatrix; glframe             cameraframe; glframe             objectframe; glfrustum           viewfrustum;   glbatch             trianglebatch; glbatch             quadstrip;  glgeometrytransform transformpipeline; m3dmatrix44f        shadowmatrix;   glfloat vgreen[] = { 0.5f, 1.0f, 0.0f, 1.0f };    glfloat vpyramid[12][3] = { //coords};     //this function triggered when space pressed.  takes parameters passed create 8 points of cube makes quad_strip mesh void createplat(float centerx, float centery, float centerz, float width, float length, float depth) {      glfloat vp1[3] = { (centerx - (width/2)), (centery), (centerz + (length/2))}; //top left     glfloat vp2[3] = { (centerx + (width/2)), (centery), (centerz + (length/2))}; //top right     glfloat vp3[3] = { (centerx + (width/2)), (centery),(centerz - (length/2))}; //bottom right     glfloat vp4[3] = { (centerx - (width/2)), (centery), (centerz - (length/2))}; //bottom left     glfloat vp5[3] = { (centerx - (width/2)), (centery - depth), (centerz + (length/2))};     glfloat vp6[3] = { (centerx + (width/2)), (centery - depth), (centerz + (length/2))};     glfloat vp7[3] = { (centerx + (width/2)), (centery - depth),(centerz - (length/2))};     glfloat vp8[3] = { (centerx - (width/2)), (centery - depth), (centerz - (length/2))};        glfloat vplat[26][3] = {vp4[0], vp4[1], vp4[2],         //bla bla         vp2[0], vp2[1], vp2[2]};       quadstrip.begin(gl_quad_strip, 26);     quadstrip.copyvertexdata3f(vplat);     quadstrip.end();   }  glfloat size = 1.0;   void update () {      //controls      //rotate controls      if(space)         createplat(0.0, 0.0, 0.0, size, 1.0, 1.0);     if(w)         size += 1.0;     if(s)         size -= 1.0;      vpyramid[1][1] += 1.0; }   void setuprc()     {     trianglebatch.begin(gl_triangles, 12);     trianglebatch.copyvertexdata3f(vpyramid);     trianglebatch.end();      }   void drawwireframedbatch(glbatch* pbatch)     {            //take mesh , draw outlines     }  void renderscene(void)     {             update();         // clear window current clearing color         glclear(gl_color_buffer_bit | gl_depth_buffer_bit | gl_stencil_buffer_bit);          modelviewmatrix.pushmatrix();         m3dmatrix44f mcamera;         cameraframe.getcameramatrix(mcamera);         modelviewmatrix.multmatrix(mcamera);          m3dmatrix44f mobjectframe;         objectframe.getmatrix(mobjectframe);         modelviewmatrix.multmatrix(mobjectframe);          shadermanager.usestockshader(glt_shader_flat, transformpipeline.getmodelviewprojectionmatrix(), vblack);           drawwireframedbatch(&trianglebatch);         drawwireframedbatch(&quadstrip);          modelviewmatrix.popmatrix();         glutpostredisplay();          // flush drawing commands         glutswapbuffers();     }   int main(int argc, char* argv[])     {     gltsetworkingdirectory(argv[0]);      glutinit(&argc, argv);     glutinitdisplaymode(glut_double | glut_rgba | glut_depth | glut_stencil);     glutinitwindowsize(800, 600);     glutcreatewindow("gl_points");     glutreshapefunc(changesize);     glutdisplayfunc(renderscene);     //glutspecialfunc(specialkeys);      glenum err = glewinit();     if (glew_ok != err) {         fprintf(stderr, "glew error: %s\n", glewgeterrorstring(err));         return 1;         }       setuprc();      glutmainloop();     return 0;     } 

as can see desirable solution inside of createplat() function after creating lines, add lines array, rebuild buffer suit it. may notice using quad_strip.... using gl_quads.

side note planning sorta velocity based movement, familiar math of how deal orientation in 2d if trying add varying ammounts of horizontal , vertical velocity.... in 3d idk! able set things work perfectly, until player rotates when things complicated. sheir math3d lib thing this?

i think should use vbo instead of quadstrip , render basic shader program. can speed program bit , gives way more freedom.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -