[GEM-cvs] Gem/src/Vertex vertex_add.cpp,1.1,1.1 vertex_add.h,1.1,1.1 vertex_combine.cpp,1.1,1.1 vert
Brought to you by:
zmoelnig
Update of /cvsroot/pd-gem/Gem/src/Vertex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21520 Added Files: vertex_add.cpp vertex_add.h vertex_combine.cpp vertex_combine.h vertex_draw.cpp vertex_draw.h vertex_grid.cpp vertex_grid.h vertex_info.cpp vertex_info.h vertex_model.cpp vertex_model.h vertex_mul.cpp vertex_mul.h vertex_offset.cpp vertex_offset.h vertex_quad.cpp vertex_quad.h vertex_scale.cpp vertex_scale.h vertex_set.cpp vertex_set.h Log Message: moved all the vertex_-objects from src/Geos to src/Vertex; added vertex_mul, vertex_add vertex_offset,... now work on all arrays --- NEW FILE: vertex_offset.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_offset.h" #include "Base/GemState.h" CPPEXTERN_NEW_WITH_GIMME(vertex_offset) ///////////////////////////////////////////////////////// // // vertex_offset // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_offset :: vertex_offset(int argc, t_atom*argv) : vertex_scale(argc, argv), m_x(0.f), m_y(0.f), m_z(0.f), m_w(0.f) {} ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_offset :: ~vertex_offset() { } void vertex_offset :: paramMess(int argc, t_atom*argv){ m_w=0.f; switch (argc){ case 4: m_w = atom_getfloat(argv+3); case 3: m_z = atom_getfloat(argv+2); m_y = atom_getfloat(argv+1); m_x = atom_getfloat(argv); break; default: error("vertex_offset: offset must be 3 or 4 values!"); break; } } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_offset :: vertexProcess(int size, GLfloat*array){ int count; if (m_offset < 0) m_offset = 0; if (m_offset > size) m_offset = size; count = m_count; if (count < 1) count = 1; if ((count + m_offset-1) > size) count = size - m_offset;// -1; //needs some altivec if (m_offset){ int src = (m_offset-1) * 4; for (int i=0; i< count; i++){ array[src] += m_x; array[src+1] += m_y; array[src+2] += m_z; array[src+3] += m_w; src+=4; } }else{ int src=0; for (int i=0; i< size; i++){ array[src] += m_x; array[src+1] += m_y; array[src+2] += m_z; array[src+3] += m_w; src+=4; } } } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_offset :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_offset::paramMessCallback, gensym("offset"), A_GIMME, A_NULL); class_addmethod(classPtr, (t_method)&vertex_offset::paramMessCallback, gensym("param"), A_GIMME, A_NULL); } --- NEW FILE: vertex_combine.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_combine Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_vertex_combine_H_ #define INCLUDE_vertex_combine_H_ #include "Base/GemVertex.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_combine Creates a vertex_combine KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_combine : public GemBase { CPPEXTERN_HEADER(vertex_combine, GemBase) public: ////////// // Constructor vertex_combine(); protected: ////////// // Destructor virtual ~vertex_combine(); float *m_rightVertexArray; float *m_rightColorArray; float m_blend; int m_vertCountR; t_inlet *m_inlet; GemCache *m_cacheRight; ////////// // Do the rendering virtual void render(GemState *state); virtual void postrender(GemState *state); virtual void rightRender(GemState *state); //private: static void gem_rightMessCallback(void *x, t_symbol *s, int argc, t_atom *argv); static void blendCallback(void *data, t_floatarg x); }; #endif // for header file --- NEW FILE: vertex_model.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_model Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) Günther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_vertex_model_H_ #define INCLUDE_vertex_model_H_ #include "Base/GemVertex.h" #include "Geos/model_loader.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_model Creates a vertex_model KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_model : public GemBase { CPPEXTERN_HEADER(vertex_model, GemBase) public: ////////// // Constructor vertex_model(); protected: ////////// // Destructor virtual ~vertex_model(); //int m_blend; float *m_ColorArray; float *m_VertexArray; float *m_tempCA; float *m_tempVA; float *m_TexCoordArray; float *m_tempTA; float *m_NormalArray; float *m_tempNA; GLMmodel *m_model; int m_vertcount; int m_haveModel; int m_oldVSize,m_oldCSize; float maxX, maxY, oldmaxX, oldmaxY; ////////// // Should we rescale the model when loaded // Default is yes int m_rescaleModel; ////////// // Do the rendering virtual void render(GemState *state); virtual void openMess(t_symbol *filename); private: static void openMessCallback(void *data, t_symbol *filename); }; #endif // for header file --- NEW FILE: vertex_info.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) G¸nther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_info.h" #include "Base/GemState.h" #include "string.h" CPPEXTERN_NEW(vertex_info) ///////////////////////////////////////////////////////// // // vertex_info // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_info :: vertex_info() : m_previousSize(0), m_vertNum(0), m_vertCount(0) { m_Vsize = outlet_new(this->x_obj, 0); //m_Csize = outlet_new(this->x_obj, 0); //m_VOut = outlet_new(this->x_obj, 0); } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_info :: ~vertex_info() { if(m_Vsize)outlet_free(m_Vsize); } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_info :: render(GemState *state) { int i,size,src,count; GLfloat *VertexArray; VertexArray =state->VertexArray; if (state->VertexArray == NULL || state->VertexArraySize <= 0){ post("vertex_info: no vertex array!"); return; } if (state->VertexArray == NULL ){ post("vertex_info: no color array!"); return; } size = state->VertexArraySize; outlet_float(m_Vsize, (t_float)size); } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_info :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_info::vertexMessCallback, gensym("vertex"), A_FLOAT, A_FLOAT, A_NULL); } void vertex_info :: vertexMessCallback(void *data, t_floatarg num, t_floatarg counter) { GetMyClass(data)->m_vertNum=((int)num); GetMyClass(data)->m_vertCount=((int)counter); } --- NEW FILE: vertex_scale.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_scale.h" #include "Base/GemState.h" CPPEXTERN_NEW_WITH_GIMME(vertex_scale) ///////////////////////////////////////////////////////// // // vertex_scale // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_scale :: vertex_scale(int argc, t_atom*argv) : GemBase(), m_x(1.f), m_y(1.f), m_z(1.f), m_w(1.f), m_offset(0), m_count(0), m_vertex(false), m_color(false), m_normal(false), m_texture(false) { m_vertIn=inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("vertex")); m_parmIn=inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("param")); modeMess(argc, argv); if(!argc)m_vertex=true; } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_scale :: ~vertex_scale() { inlet_free(m_vertIn); inlet_free(m_parmIn); } void vertex_scale :: modeMess(int argc, t_atom*argv){ m_vertex =false; m_color =false; m_normal =false; m_texture=false; for(int i=0; i<argc; i++){ char c=*atom_getsymbol(argv+i)->s_name; switch(c){ case 'v': case 'V': m_vertex =true; break; case 'c': case 'C': m_color =true; break; case 'n': case 'N': m_normal =true; break; case 't': case 'T': m_texture=true; break; default: error("vertex_operator: invalid operand '%s'! skipping", atom_getsymbol(argv+i)->s_name); break; } } } void vertex_scale :: vertexMess(int offset, int count){ m_offset = offset; m_count = count; } void vertex_scale :: paramMess(int argc, t_atom*argv){ m_w=1.f; switch (argc){ case 4: m_w = atom_getfloat(argv+3); case 3: m_z = atom_getfloat(argv+2); m_y = atom_getfloat(argv+1); m_x = atom_getfloat(argv); break; default: error("vertex_scale: scale must be 3 or 4 values!"); break; } } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_scale :: vertexProcess(int size, GLfloat*array){ int count; if (m_offset < 0) m_offset = 0; if (m_offset > size) m_offset = size; count = m_count; if (count < 1) count = 1; if ((count + m_offset-1) > size) count = size - m_offset;// -1; //needs some altivec if (m_offset){ int src = (m_offset-1) * 4; for (int i=0; i< count; i++){ array[src] *= m_x; array[src+1] *= m_y; array[src+2] *= m_z; array[src+3] *= m_w; src+=4; } }else{ int src=0; for (int i=0; i< size; i++){ array[src] *= m_x; array[src+1] *= m_y; array[src+2] *= m_z; array[src+3] *= m_w; src+=4; } } } void vertex_scale :: render(GemState *state) { if(state->VertexArraySize<=0) return; if(m_vertex && state->VertexArray != NULL){ vertexProcess(state->VertexArraySize, state->VertexArray); } if(m_color && state->ColorArray != NULL){ vertexProcess(state->VertexArraySize, state->ColorArray); } if(m_normal && state->NormalArray != NULL){ vertexProcess(state->VertexArraySize, state->NormalArray); } if(m_texture && state->TexCoordArray != NULL){ vertexProcess(state->VertexArraySize, state->TexCoordArray); } } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_scale :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_scale::modeMessCallback, gensym("mode"), A_GIMME, A_NULL); class_addmethod(classPtr, (t_method)&vertex_scale::vertexMessCallback, gensym("vertex"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&vertex_scale::paramMessCallback, gensym("param"), A_GIMME, A_NULL); class_addmethod(classPtr, (t_method)&vertex_scale::paramMessCallback, gensym("scale"), A_GIMME, A_NULL); } void vertex_scale :: paramMessCallback(void *data, t_symbol*, int argc, t_atom*argv) { GetMyClass(data)->paramMess(argc, argv); } void vertex_scale :: vertexMessCallback(void *data, t_floatarg num, t_floatarg counter) { GetMyClass(data)->vertexMess((int)num, (int)counter); } void vertex_scale :: modeMessCallback(void *data, t_symbol*, int argc, t_atom*argv) { GetMyClass(data)->modeMess(argc, argv); } --- NEW FILE: vertex_set.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_set.h" #include "Base/GemState.h" CPPEXTERN_NEW_WITH_GIMME(vertex_set) ///////////////////////////////////////////////////////// // // vertex_set // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_set :: vertex_set(int argc, t_atom*argv) : vertex_scale(argc, argv), m_x(1.f), m_y(1.f), m_z(1.f), m_w(1.f) {} ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_set :: ~vertex_set() { } void vertex_set :: paramMess(int argc, t_atom*argv){ m_w=1.f; switch (argc){ case 4: m_w = atom_getfloat(argv+3); case 3: m_z = atom_getfloat(argv+2); m_y = atom_getfloat(argv+1); m_x = atom_getfloat(argv); break; default: error("vertex_set: set must be 3 or 4 values!"); break; } } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_set :: vertexProcess(int size, GLfloat*array){ int count; if (m_offset < 0) m_offset = 0; if (m_offset > size) m_offset = size; count = m_count; if (count < 1) count = 1; if ((count + m_offset-1) > size) count = size - m_offset;// -1; //needs some altivec if (m_offset){ int src = (m_offset-1) * 4; for (int i=0; i< count; i++){ array[src] = m_x; array[src+1] = m_y; array[src+2] = m_z; array[src+3] = m_w; src+=4; } }else{ int src=0; for (int i=0; i< size; i++){ array[src] = m_x; array[src+1] = m_y; array[src+2] = m_z; array[src+3] = m_w; src+=4; } } } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_set :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_set::paramMessCallback, gensym("set"), A_GIMME, A_NULL); class_addmethod(classPtr, (t_method)&vertex_set::paramMessCallback, gensym("param"), A_GIMME, A_NULL); } --- NEW FILE: vertex_draw.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) G¸nther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_draw.h" #include "Base/GemState.h" CPPEXTERN_NEW_WITH_ONE_ARG(vertex_draw, t_floatarg, A_DEFFLOAT) ///////////////////////////////////////////////////////// // // vertex_draw // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_draw :: vertex_draw(t_floatarg size) { // m_drawType = GL_QUADS; m_drawType = GL_TRIANGLES; m_defaultDraw = 1; m_vao=1; m_color=1; m_index = 0; vertices = new float [4]; m_oldsize = 0; m_init = 1; m_texcoord = 0; } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_draw :: ~vertex_draw() { } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_draw :: render(GemState *state) { int size,stride; // int index,vindex; GLuint vao; GLuint fences[2]; if (state->VertexArray == NULL || state->VertexArraySize <= 0){ // post("vertex_draw: no vertex array!"); return; } if (state->ColorArray == NULL || state->HaveColorArray == 0){ // post("vertex_draw: no Color array!"); // m_color = 0; } if (state->TexCoordArray == NULL || state->HaveTexCoordArray == 0){ post("vertex_draw: no Texture Coordinate array!"); m_texcoord = 0; } if (state->drawType && m_defaultDraw){ m_drawType = state->drawType; } size = state->VertexArraySize; stride = state->VertexArrayStride; glShadeModel( GL_SMOOTH ); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); #ifdef __APPLE__ # error please replace __APPLE__ by something more specific; JMZ glGenVertexArraysAPPLE(2, fences); #endif vao = fences[0]; //works but is slow // post("vertex draw: VAO %d",vao); /* if (glIsVertexArrayAPPLE(vao)) glBindVertexArrayAPPLE(vao); post("vertex draw: using VAO"); } else{ post("vertex draw: not using VAO"); }*/ // glGenVertexArraysAPPLE(2, fences); vao = fences[0]; #ifdef __APPLE__ # error please replace __APPLE__ by something more specific; JMZ if (m_vao){ if (!glIsVertexArrayAPPLE(1)) post("vertex draw: not using VAO"); glBindVertexArrayAPPLE(1); } #endif glDisableClientState(GL_INDEX_ARRAY); if(m_color && (state->ColorArray != NULL || state->HaveColorArray == 0) ){ glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4,GL_FLOAT,0,state->ColorArray); }else{ glDisableClientState(GL_COLOR_ARRAY); } //if(m_texcoord){ glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,0,state->TexCoordArray); // }else{ // glDisableClientState(GL_TEXTURE_COORD_ARRAY); // } if(state->HaveNormalArray || state->NormalArray!=NULL){ glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT,0,state->NormalArray); } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(4,GL_FLOAT,0,(GLfloat *)state->VertexArray); #ifdef GL_VERTEX_ARRAY_RANGE_APPLE glVertexArrayParameteriAPPLE(GL_VERTEX_ARRAY_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE); glVertexArrayRangeAPPLE( size, (GLvoid *)state->VertexArray); glEnableClientState( GL_VERTEX_ARRAY_RANGE_APPLE ); glFlushVertexArrayRangeAPPLE( size, (GLvoid *)state->VertexArray); #endif glDrawArrays(m_drawType,0,size); glDisableClientState(GL_VERTEX_ARRAY); #ifdef GL_VERTEX_ARRAY_RANGE_APPLE glDisableClientState(GL_VERTEX_ARRAY_RANGE_APPLE); glVertexArrayRangeAPPLE(0,0); #endif if(m_color)glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); // if(m_texcoord)glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_BLEND); // glDeleteVertexArraysAPPLE(2, fences); } ///////////////////////////////////////////////////////// // typeMess // ///////////////////////////////////////////////////////// void vertex_draw :: typeMess(t_symbol *type) { char c=*type->s_name; switch (c){ case 'L': case 'l': // line m_drawType = GL_LINE_LOOP; break; case 'F': case 'f': // fill m_drawType = GL_POLYGON; break; case 'Q': case 'q': // fill m_drawType = GL_QUADS; break; case 'P': case 'p': // point m_drawType = GL_POINTS; break; case 'T': case 't': // triangles m_drawType = GL_TRIANGLES; break; case 'S': case 's': // tri-strip m_drawType = GL_TRIANGLE_STRIP; break; default: error ("GEM: square draw style"); return; } setModified(); } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_draw :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_draw::blendMessCallback, gensym("default"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&vertex_draw::colorMessCallback, gensym("color"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&vertex_draw::texcoordMessCallback, gensym("texcoord"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&vertex_draw::typeMessCallback, gensym("draw"), A_SYMBOL, A_NULL); } void vertex_draw :: blendMessCallback(void *data, t_floatarg size) { GetMyClass(data)->m_defaultDraw=((int)size); } void vertex_draw :: colorMessCallback(void *data, t_floatarg size) { GetMyClass(data)->m_color=((int)size); } void vertex_draw :: texcoordMessCallback(void *data, t_floatarg t) { GetMyClass(data)->m_texcoord=((int)t); } void vertex_draw :: typeMessCallback(void *data, t_symbol *type) { GetMyClass(data)->typeMess(type); } --- NEW FILE: vertex_combine.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) G¸nther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_combine.h" #include "Base/GemState.h" #include "string.h" #include "math.h" CPPEXTERN_NEW(vertex_combine) ///////////////////////////////////////////////////////// // // vertex_combine // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_combine :: vertex_combine() { m_blend = 0.f; //hopefully this gets us a right inlet that accepts another gem state m_inlet = inlet_new(this->x_obj, &this->x_obj->ob_pd,gensym("gem_state"), gensym("gem_right")); } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_combine :: ~vertex_combine() { } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_combine :: render(GemState *state) { int i,size,srcL,srcS,count,sizeR,end,ratio,remainder; GLfloat *VertexArray; GLfloat *Temp; float blendL, blendR, ratiof,countf; VertexArray =state->VertexArray; if (state->VertexArray == NULL || state->VertexArraySize <= 0){ post("vertex_combine: no vertex array!"); return; } if (state->ColorArray == NULL ){ post("vertex_combine: no color array!"); return; } size = state->VertexArraySize; sizeR = m_vertCountR; //dumb and dirty x-fade blendR = m_blend; blendL = fabs(1.f - m_blend); if (size > sizeR){ //left is larger ratiof = (float)size/sizeR; ratio = size / sizeR; remainder = size % sizeR; // post("float ratio %f:1 int ratio %d:1 remainder %d",ratiof,ratio,remainder); i = 0; srcL = 0; srcS = 0; countf = 0.0; while (i < sizeR) { count = 0; while (count < ratio){ VertexArray[srcL] = (VertexArray[srcL] * blendL) + (m_rightVertexArray[srcS] * blendR); VertexArray[srcL+1] = (VertexArray[srcL+1] * blendL) + (m_rightVertexArray[srcS+1] * blendR); VertexArray[srcL+2] = (VertexArray[srcL+2] * blendL) + (m_rightVertexArray[srcS+2] * blendR); VertexArray[srcL+3] = (VertexArray[srcL+3] * blendL )+ (m_rightVertexArray[srcS+3] * blendR); srcL+=4; count++; } i++; srcS+=4; } state->VertexArraySize = size; }else{ ratiof = (float)sizeR/size; ratio = sizeR / size; remainder = sizeR % size; post("float ratio %f:1 int ratio %d:1 remainder %d",ratiof,ratio,remainder); } /* -- this almost works - good for fast and dirty integer ratios if (size > sizeR){ //left is larger ratiof = (float)size/sizeR; ratio = size / sizeR; remainder = size % sizeR; // post("float ratio %f:1 int ratio %d:1 remainder %d",ratiof,ratio,remainder); i = 0; srcL = 0; srcS = 0; while (i < sizeR) { count = 0; while (count < ratio){ VertexArray[srcL] = (VertexArray[srcL] * blendL) + (m_rightVertexArray[srcS] * blendR); VertexArray[srcL+1] = (VertexArray[srcL+1] * blendL) + (m_rightVertexArray[srcS+1] * blendR); VertexArray[srcL+2] = (VertexArray[srcL+2] * blendL) + (m_rightVertexArray[srcS+2] * blendR); VertexArray[srcL+3] = (VertexArray[srcL+3] * blendL )+ (m_rightVertexArray[srcS+3] * blendR); srcL+=4; count++; } i++; srcS+=4; } state->VertexArraySize = size; }else{ ratiof = (float)sizeR/size; ratio = sizeR / size; remainder = sizeR % size; post("float ratio %f:1 int ratio %d:1 remainder %d",ratiof,ratio,remainder); } */ } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_combine :: postrender(GemState *state) { //m_vertNum = 0; } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_combine :: rightRender(GemState *state) { if (state->VertexArray == NULL || state->VertexArraySize <= 0){ post("vertex_combine: no right vertex array!"); return; } if (state->ColorArray == NULL ){ post("vertex_combine: no right color array!"); } m_vertCountR = state->VertexArraySize; m_rightVertexArray = state->VertexArray; m_rightColorArray = state->ColorArray; //post("vertex_combine: state->VertexArraySize %d", state->VertexArraySize); //post("vertex_combine: rightRender"); } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_combine :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_combine::gem_rightMessCallback, gensym("gem_right"), A_GIMME, A_NULL); class_addmethod(classPtr, (t_method)&vertex_combine::blendCallback, gensym("blend"), A_FLOAT, A_NULL); } void vertex_combine :: gem_rightMessCallback(void *data, t_symbol *s, int argc, t_atom *argv) { if (argc==1 && argv->a_type==A_FLOAT){ } else if (argc==2 && argv->a_type==A_POINTER && (argv+1)->a_type==A_POINTER){ GetMyClass(data)->m_cacheRight = (GemCache*)argv->a_w.w_gpointer; GetMyClass(data)->rightRender((GemState *)(argv+1)->a_w.w_gpointer); } else error("GEM: wrong righthand arguments...."); } void vertex_combine :: blendCallback(void *data, t_floatarg x) { GetMyClass(data)->m_blend = (float)x; } --- NEW FILE: vertex_scale.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_scale Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_VERTEX_SCALE_H_ #define INCLUDE_VERTEX_SCALE_H_ #include "Base/GemVertex.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_scale Creates a vertex_scale KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_scale : public GemBase { CPPEXTERN_HEADER(vertex_scale, GemBase) public: ////////// // Constructor vertex_scale(int, t_atom*); protected: ////////// // Destructor virtual ~vertex_scale(); virtual void paramMess(int,t_atom*); float m_x,m_y,m_z,m_w; virtual void vertexMess(int offset, int count); int m_offset,m_count; virtual void modeMess(int,t_atom*); bool m_vertex, m_color, m_normal, m_texture; t_inlet*m_parmIn, *m_vertIn; ////////// // Do the rendering virtual void vertexProcess(int,GLfloat *); virtual void render(GemState *state); static void paramMessCallback(void *data, t_symbol*, int, t_atom*); private: static void modeMessCallback(void *data, t_symbol*, int, t_atom*); static void vertexMessCallback(void *data, t_floatarg num, t_floatarg counter); }; #endif // for header file --- NEW FILE: vertex_quad.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) G¸nther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_quad.h" #include "Base/GemState.h" #include "string.h" CPPEXTERN_NEW(vertex_quad) ///////////////////////////////////////////////////////// // // vertex_quad // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_quad :: vertex_quad() { m_blend=0; m_VertexArray = new float [16]; m_ColorArray = new float [16]; m_TexCoordArray = new float [8]; } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_quad :: ~vertex_quad() { } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_quad :: render(GemState *state) { static GLfloat quad[16]= {-1.,-1.,0.,1., 1.,-1.,0.,1., 1.,1.,0.,1., -1.,1.,0.,1.}; static GLfloat color[16]= {1.,1.,1.,1., 1.,1.,1.,1., 1.,1.,1.,1., 1.,1.,1.,1.}; GLfloat texcoord[8] = { 0.0,1.0, 1.0,1.0, 1.0,0.0, 0.0,0.0 }; /* coords[3].s = 0.f; // switched the order of coords on __APPLE__ coords[3].t = 0.f; // otherwise we'd be upside down! coords[2].s = xRatio; coords[2].t = 0.f; coords[1].s = xRatio; coords[1].t = yRatio; coords[0].s = 0.f; coords[0].t = yRatio;*/ if (state->numTexCoords){ texcoord[0] = state->texCoordX(0); texcoord[1] = state->texCoordY(0); texcoord[2] = state->texCoordX(1); texcoord[3] = state->texCoordY(1); texcoord[4] = state->texCoordX(2); texcoord[5] = state->texCoordY(2); texcoord[6] = state->texCoordX(3); texcoord[7] = state->texCoordY(3); } memcpy(m_VertexArray, quad, sizeof(quad)); memcpy(m_ColorArray, color, sizeof(color)); memcpy(m_TexCoordArray, texcoord, sizeof(texcoord)); //state->VertexArray = 0; //state->ColorArray = 0; //m_VertexArray = quad; //m_ColorArray = color; state->VertexArray = m_VertexArray; state->ColorArray = m_ColorArray; state->TexCoordArray = m_TexCoordArray; //let vertex draaw know which arrays to draw state->HaveColorArray = 1; state->HaveTexCoordArray = 1; //state->VertexArray = quad; // state->ColorArray = color; state->VertexArrayStride = 4; state->VertexArraySize = 4; // delete [] color; // delete [] quad; } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_quad :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_quad::blendMessCallback, gensym("blend"), A_FLOAT, A_NULL); } void vertex_quad :: blendMessCallback(void *data, t_floatarg size) { GetMyClass(data)->m_blend=((int)size); } --- NEW FILE: vertex_info.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_info Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_vertex_info_H_ #define INCLUDE_vertex_info_H_ #include "Base/GemVertex.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_info Creates a vertex_info KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_info : public GemBase { CPPEXTERN_HEADER(vertex_info, GemBase) public: ////////// // Constructor vertex_info(); protected: ////////// // Destructor virtual ~vertex_info(); int m_previousSize; int m_vertNum,m_vertCount; t_outlet *m_Vsize; ////////// // Do the rendering virtual void render(GemState *state); private: static void vertexMessCallback(void *data, t_floatarg num, t_floatarg counter); }; #endif // for header file --- NEW FILE: vertex_model.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_model.h" #include "Base/GemState.h" #include "string.h" #ifdef __APPLE__ #include <AGL/agl.h> extern bool HaveValidContext (void); #endif #define T(x) (m_model->triangles[(x)]) CPPEXTERN_NEW(vertex_model) ///////////////////////////////////////////////////////// // // vertex_model // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_model :: vertex_model() { m_VertexArray = new float [16]; m_ColorArray = new float [16]; m_TexCoordArray = new float [16]; m_NormalArray = new float [16]; m_tempTA = new float [16]; m_tempVA = new float [16]; m_tempCA = new float [16]; m_tempNA = new float [16]; m_vertcount = 4; m_rescaleModel = 1; m_haveModel = 0; m_oldVSize = m_oldCSize = 0; maxX = 1; maxY = 1; oldmaxX = 1; oldmaxY = 1; } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_model :: ~vertex_model() { } ///////////////////////////////////////////////////////// // openMess // ///////////////////////////////////////////////////////// void vertex_model :: openMess(t_symbol *filename) { GLMgroup* group; GLMtriangle* triangle; float* tritext; //texture coords for a triangle float* trivert; //vertices of one point in a triangle float* trinorm; int src2,src3, src4,numvertices; unsigned int i; m_haveModel = 0; #ifdef __APPLE__ if (!HaveValidContext ()) { post("GEM: geo: model - need window to load model"); return; } #endif //cleanModel(); char buf[MAXPDSTRING]; canvas_makefilename(getCanvas(), filename->s_name, buf, MAXPDSTRING); // read the object in m_model = glmReadOBJ(buf); if (!m_model) return; // set the size to -1 to 1 if (m_rescaleModel) glmUnitize(m_model); group = m_model->groups; glmFacetNormals (m_model); glmVertexNormals(m_model, 90); glmLinearTexture(m_model); post("vertex_model: model->numtriangles %d",m_model->numtriangles); post("vertex_model: model->numgroups %d",m_model->numgroups); post("vertex_model: model->numvertices %d",m_model->numvertices); post("vertex_model: model->numnormals %d",m_model->numnormals); post("vertex_model: model->numtexcoords %d",m_model->numtexcoords); numvertices = (int)(m_model->numtriangles * m_model->numgroups * 3); m_vertcount = numvertices; // would it be a bad idea to make all arrays equally sized ? // (fill up the missing elements with zeros delete [] m_VertexArray; m_VertexArray = new float[numvertices * 4]; // x, y, z, w delete [] m_ColorArray; m_ColorArray = new float[numvertices * 4]; // r, g, b, a delete [] m_TexCoordArray; m_TexCoordArray = new float[numvertices * 2];// u, v delete [] m_NormalArray; m_NormalArray = new float[numvertices * 3]; // x, y, z delete [] m_tempVA; m_tempVA = new float[numvertices * 4]; delete [] m_tempCA; m_tempCA = new float[numvertices * 4]; delete [] m_tempTA; m_tempTA = new float[numvertices * 2]; delete [] m_tempNA; m_tempNA = new float[numvertices * 3]; src2 = 0; src3 = 0; src4 = 0; while(group){ for (i = 0; i < group->numtriangles; i++) { triangle = &T(group->triangles[i]); trivert = &m_model->vertices[3 * triangle->vindices[0]]; m_VertexArray[src4] = trivert[0]; m_VertexArray[src4+1] = trivert[1]; m_VertexArray[src4+2] = trivert[2]; m_VertexArray[src4+3] = 1; m_ColorArray[src4] = 1; m_ColorArray[src4+1] = 1; m_ColorArray[src4+2] = 1; m_ColorArray[src4+3] = 1; tritext = &m_model->texcoords[2 * triangle->tindices[0]]; m_TexCoordArray[src2] = tritext[0]; m_TexCoordArray[src2+1] = tritext[1]; trinorm = &m_model->normals[3 * triangle->nindices[0]]; m_NormalArray[src3] = trinorm[0]; m_NormalArray[src3+1] = trinorm[1]; m_NormalArray[src3+2] = trinorm[2]; src3 += 3; src2 += 2; src4 += 4; trivert = &m_model->vertices[3 * triangle->vindices[1]]; m_VertexArray[src4] = trivert[0]; m_VertexArray[src4+1] = trivert[1]; m_VertexArray[src4+2] = trivert[2]; m_VertexArray[src4+3] = 1; m_ColorArray[src4] = 1; m_ColorArray[src4+1] = 1; m_ColorArray[src4+2] = 1; m_ColorArray[src4+3] = 1; tritext = &m_model->texcoords[2 * triangle->tindices[1]]; m_TexCoordArray[src2] = tritext[0]; m_TexCoordArray[src2+1] = tritext[1]; trinorm = &m_model->normals[3 * triangle->nindices[1]]; m_NormalArray[src3] = trinorm[0]; m_NormalArray[src3+1] = trinorm[1]; m_NormalArray[src3+2] = trinorm[2]; src3 += 3; src2 += 2; src4 += 4; trivert = &m_model->vertices[3 * triangle->vindices[2]]; m_VertexArray[src4] = trivert[0]; m_VertexArray[src4+1] = trivert[1]; m_VertexArray[src4+2] = trivert[2]; m_VertexArray[src4+3] = 1; m_ColorArray[src4] = 1; m_ColorArray[src4+1] = 1; m_ColorArray[src4+2] = 1; m_ColorArray[src4+3] = 1; tritext = &m_model->texcoords[2 * triangle->tindices[2]]; m_TexCoordArray[src2] = tritext[0]; m_TexCoordArray[src2+1] = tritext[1]; trinorm = &m_model->normals[3 * triangle->nindices[2]]; m_NormalArray[src3] = trinorm[0]; m_NormalArray[src3+1] = trinorm[1]; m_NormalArray[src3+2] = trinorm[2]; src3 += 3; src2 += 2; src4 += 4; } group = group->next; } src4 = src4/4; src2 = src2/4; post("vertex_model: i %d",i); post("vertex_model: src2 %d",src2); post("vertex_model: src4 %d",src4); m_haveModel = 1; this->setModified(); } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_model :: render(GemState *state) { int size,i,src,length; if (!m_haveModel) return; //this will get the appropriate maximum texcoord size for use with the model src = 0; size = m_vertcount * 4 * 4; // post("vertex_model: m_vertcount %d",m_vertcount); memcpy(m_tempVA, m_VertexArray, size); memcpy(m_tempCA, m_ColorArray, size); size = m_vertcount * 4 * 3; memcpy(m_tempNA, m_NormalArray, size); /* if (state->numTexCoords) { if (maxX != state->texCoordX(1) || maxY != state->texCoordY(1)){ post("vertex_model: changing texcoords"); post("vertex_model: state->texCoordX(1) %f",state->texCoordX(1)); post("vertex_model: state->texCoordY(1) %f",state->texCoordY(1)); maxX = state->texCoordX(1); maxY = state->texCoordY(1); post("vertex_model: maxX %f",maxX); post("vertex_model: maxY %f",maxY); //resize the texcoords //length = sizeof(m_TexCoordArray)/2; length = m_vertcount; post("vertex_model: length %d",length); post("vertex_model: m_tempTA[0] start %f",m_TexCoordArray[0]); post("vertex_model: m_tempTA[1] start %f",m_TexCoordArray[1]); post("vertex_model: m_tempTA[2] start %f",m_TexCoordArray[2]); post("vertex_model: m_tempTA[length] start %f",m_TexCoordArray[length]); for(i=0; i < length; i++){ m_TexCoordArray[src] = m_TexCoordArray[src] * maxX; m_TexCoordArray[src+1] = m_TexCoordArray[src+1] * maxY; src+=2; } post("vertex_model: src %d",src); post("vertex_model: m_tempTA[0] end %f",m_TexCoordArray[0]); post("vertex_model: m_tempTA[1] end %f",m_TexCoordArray[1]); post("vertex_model: m_tempTA[src] end %f",m_TexCoordArray[src]); } } */ size = m_vertcount * 4 * 2; // memcpy(m_tempTA, m_TexCoordArray, size); if (state->numTexCoords) { if (maxX != state->texCoordX(1) || maxY != state->texCoordY(1)){ // post("vertex_model: changing texcoords"); // post("vertex_model: state->texCoordX(1) %f",state->texCoordX(1)); // post("vertex_model: state->texCoordY(1) %f",state->texCoordY(1)); maxX = state->texCoordX(1); maxY = state->texCoordY(1); // post("vertex_model: maxX %f",maxX); // post("vertex_model: maxY %f",maxY); //resize the texcoords //length = sizeof(m_TexCoordArray)/2; length = m_vertcount; // post("vertex_model: length %d",length); // post("vertex_model: m_tempTA[0] start %f",m_tempTA[0]); // post("vertex_model: m_tempTA[1] start %f",m_tempTA[1]); // post("vertex_model: m_tempTA[2] start %f",m_tempTA[2]); // post("vertex_model: m_tempTA[length] start %f",m_tempTA[length]); //can this be unrolled?? for(i=0; i < length; i++){ m_tempTA[src] = m_TexCoordArray[src] * maxX; m_tempTA[src+1] = m_TexCoordArray[src+1] * maxY; src+=2; } // post("vertex_model: src %d",src); // post("vertex_model: m_tempTA[0] end %f",m_tempTA[0]); // post("vertex_model: m_tempTA[1] end %f",m_tempTA[1]); // post("vertex_model: m_tempTA[src] end %f",m_tempTA[src]); // } } }else{ memcpy(m_tempTA, m_TexCoordArray, size); } state->VertexArray = m_tempVA; state->ColorArray = m_tempCA; state->TexCoordArray = m_tempTA; state->NormalArray = m_tempNA; state->HaveColorArray = 1; state->HaveTexCoordArray = 1; state->HaveNormalArray = 1; state->VertexArrayStride = 4; state->VertexArraySize = m_vertcount; } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_model :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_model::openMessCallback, gensym("open"), A_SYMBOL, A_NULL); } void vertex_model :: openMessCallback(void *data, t_symbol *filename) { GetMyClass(data)->openMess(filename); } --- NEW FILE: vertex_grid.cpp --- //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmo...@ie... // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) G¸nther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #include "vertex_grid.h" #include "Base/GemState.h" #include "string.h" CPPEXTERN_NEW_WITH_TWO_ARGS(vertex_grid, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT) ///////////////////////////////////////////////////////// // // vertex_grid // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// vertex_grid :: vertex_grid(t_floatarg f1, t_floatarg f2) { m_x = 4; m_y = 4; if(f1>=1.0)m_x=(int)f1; if(f2>=1.0)m_y=(int)f1; maxX = 0; maxY = 0; m_spacex = 1; m_spacey = 1; m_oldx = 0; m_oldy = 0; m_VertexArray = new float [16]; m_ColorArray = new float [16]; m_TexCoordArray = new float [8]; } ///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// vertex_grid :: ~vertex_grid() { } ///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void vertex_grid :: render(GemState *state) { int h,w,src,x,y,t; // m_x = 4; // m_y = 4; // m_spacex = 0.5f; // m_spacey = 0.5f; if(m_x < 1)m_x = 1; if(m_y < 1)m_y = 1; //texcoords s,t 0..state->texCoordX,texCoordY //ratios on OSX are on texcoord[1].s,t // if (maxX != state->texCoordX(1) || maxY != state->texCoordY(1)){ //get the maximum x,y texcoord values maxX = state->texCoordX(1); //bottom right of image maxY = state->texCoordY(1); //make a ratio between the max and number of vertices on each axis for interpolation ratioX = maxX / m_x; ratioY = maxY / m_y; post("vertex_grid: maxX %f",maxX); post("vertex_grid: maxY %f",maxY); post("vertex_grid: ratioX %f",ratioX); post("vertex_grid: ratioY %f",ratioY); } ratioX = maxX / m_x; ratioY = maxY / m_y; if (m_x != m_oldx || m_y != m_oldy){ post("vertex_grid : resizing arrays"); m_x += 1; //to give the correct number of columns; delete [] m_VertexArray; delete [] m_ColorArray; delete [] m_TexCoordArray; m_VertexArray = new float [m_x * m_y * 4 * 2]; m_ColorArray = new float [m_x * m_y * 4 * 2]; m_TexCoordArray = new float [m_x * m_y * 2 * 2]; m_oldx = m_x; m_oldy = m_y; post("vertex_grid : resizing arrays done"); } //this has to do two rows at once for TRIANGLE_STRIPS to draw correctly src=0; y = 0; t = 0; //this could be put in a separate function and only done when the size changes //use memcpy() for render passes that don't change the size for (h=0;h<m_y;h++){ // y = y *h; for(w=0;w<m_x;w++){ m_VertexArray[src]= (w * m_spacex); m_VertexArray[src+1]= (h * m_spacey); m_VertexArray[src+2]= 0.f; m_VertexArray[src+3]= 1.f; m_VertexArray[src+4]= (w * m_spacex); m_VertexArray[src+5]= (h * m_spacey + m_spacey); m_VertexArray[src+6]= 0.f; m_VertexArray[src+7]= 1.f; m_ColorArray[src]= 1.f; m_ColorArray[src+1]= 1.f; m_ColorArray[src+2]= 1.f; m_ColorArray[src+3]= 1.f; m_ColorArray[src+4]= 1.f; m_ColorArray[src+5]= 1.f; m_ColorArray[src+6]= 1.f; m_ColorArray[src+7]= 1.f; src+=8; m_TexCoordArray[t] = (w * ratioX); m_TexCoordArray[t+1] = (maxY - (h * ratioY)); m_TexCoordArray[t+2] = (w * ratioX); m_TexCoordArray[t+3] = ((maxY - (h * ratioY)) - ratioY); // post("vertex_grid: %f %f",m_TexCoordArray[t],m_TexCoordArray[t+1]); // post("vertex_grid: %f %f",m_TexCoordArray[t+2],m_TexCoordArray[t+3]); t+=4; } } //post(""); //post("vertex_grid: m_TexCoordArray[t] %f",m_TexCoordArray[t]); state->VertexArray = m_VertexArray; state->ColorArray = m_ColorArray; state->TexCoordArray = m_TexCoordArray; state->HaveColorArray = 1; state->HaveTexCoordArray = 1; state->VertexArrayStride = 4; state->VertexArraySize = src / 4; state->drawType = GL_TRIANGLE_STRIP; } ///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void vertex_grid :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&vertex_grid::sizeMessCallback, gensym("size"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&vertex_grid::spacingMessCallback, gensym("spacing"), A_FLOAT, A_FLOAT, A_NULL); } void vertex_grid :: sizeMessCallback(void *data, t_floatarg x, t_floatarg y) { GetMyClass(data)->m_x=((int)x); GetMyClass(data)->m_y=((int)y); } void vertex_grid :: spacingMessCallback(void *data, t_floatarg x, t_floatarg y) { GetMyClass(data)->m_spacex=((float)x); GetMyClass(data)->m_spacey=((float)y); } --- NEW FILE: vertex_draw.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_draw Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_vertex_draw_H_ #define INCLUDE_vertex_draw_H_ #include "Base/GemVertex.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_draw Creates a vertex_draw KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_draw : public GemBase { CPPEXTERN_HEADER(vertex_draw, GemBase) public: ////////// // Constructor vertex_draw(t_floatarg size); protected: ////////// // Destructor virtual ~vertex_draw(); int m_vao, m_color, m_texcoord; int *m_index; float *vertices; int m_oldsize; int m_init; int m_defaultDraw; ////////// // Do the rendering virtual void render(GemState *state); virtual void typeMess(t_symbol*s); GLint m_drawType; private: static void blendMessCallback(void *data, t_floatarg size); static void colorMessCallback(void *data, t_floatarg size); static void texcoordMessCallback(void *data, t_floatarg t); static void typeMessCallback(void *data, t_symbol*s); }; #endif // for header file --- NEW FILE: vertex_set.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_set Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_VERTEX_SET_H_ #define INCLUDE_VERTEX_SET_H_ #include "vertex_scale.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_set Creates a vertex_set KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_set : public vertex_scale { CPPEXTERN_HEADER(vertex_set, vertex_scale) public: ////////// // Constructor vertex_set(int, t_atom*); protected: ////////// // Destructor virtual ~vertex_set(); virtual void paramMess(int,t_atom*); float m_x,m_y,m_z,m_w; ////////// // Do the rendering virtual void vertexProcess(int,GLfloat *); }; #endif // for header file --- NEW FILE: vertex_quad.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_quad Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_vertex_quad_H_ #define INCLUDE_vertex_quad_H_ #include "Base/GemVertex.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_quad Creates a vertex_quad KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_quad : public GemBase { CPPEXTERN_HEADER(vertex_quad, GemBase) public: ////////// // Constructor vertex_quad(); protected: ////////// // Destructor virtual ~vertex_quad(); int m_blend; float *m_ColorArray; float *m_VertexArray; float *m_NormalArray; float *m_TexCoordArray; ////////// // Do the rendering virtual void render(GemState *state); static void blendMessCallback(void *data, t_floatarg size); }; #endif // for header file --- NEW FILE: vertex_offset.h --- /*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia A vertex_scale Copyright (c) 1997-2000 Mark Danks. ma...@da... Copyright (c) G¸nther Geiger. ge...@ep... Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f¸r::umlâ°ute. IEM. zmo...@ie... For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -----------------------------------------------------------------*/ #ifndef INCLUDE_VERTEX_OFFSET_H_ #define INCLUDE_VERTEX_OFFSET_H_ #include "vertex_scale.h" /*----------------------------------------------------------------- ------------------------------------------------------------------- CLASS vertex_offset Creates a vertex_offset KEYWORDS geo DESCRIPTION -----------------------------------------------------------------*/ class GEM_EXTERN vertex_offset : public vertex_scale { CPPEXTERN_HEADER(vertex_offset, vertex_scale) public: ////////// // Constructor vertex_offset(int, t_atom*); protected: ////////// // Destructor virtual ~vertex_offset(); virtual void paramMess(int,t_atom*); float m_x,m_y,m_z,m_w; ////////// // Do the renderi... [truncated message content] |