void AppWindow::initPrograms () { // Init my scene objects: _axis.init (); _floor.init( "../texture/_image.bmp", textures); _floor.build( 20.0f, -5.0f, 20.0f, textures); _side.init(); _side.build(25.0f, 20.0f, 20.0f, 25, textures); _sun.init(); _building.load("../models/The_City.obj"); //_building.scale(.7f); _city.init(); _city.build(_building); //initiate models _model.init(); _model2.init(); _model3.init(); _model4.init(); _model5.init(); _model6.init(); // set light: _light.set ( GsVec(0,0,10), GsColor(90,90,90,255), GsColor::white, GsColor::white ); _shadow.set(GsVec(0, 0, 10), GsColor(0, 0, 0, 255), GsColor::black, GsColor::black); // Load demo model: loadModel ( 1 ); }
void AppWindow::initPrograms () { // We are not directly initializing glsl programs here, instead, each scene object // initializes its own program(s). This makes sharing more difficult but is probably easier // to manage. // Init my scene objects: _axis.init (); _texturedCylinder.init (); _lines.init (); // set light: _light.set ( GsVec(0,0,10), GsColor(90,90,90,255), GsColor::white, GsColor::white ); // Load demo model: _texturedCylinder.build(rt, rb, 1.0f, numfaces); // Build normals object: _lines.build ( _texturedCylinder.NL, GsColor::yellow ); }
GsColor GsColor::interphue ( float t ) // static method { // First calculates RGB from HSV, saturation is set to 1.0 struct HSV { float h, s, v; }; struct COLOR { float r, g, b; }; COLOR c2, sat; HSV c1; c1.h = (1-t)*240.0f; // re-mapping t to hue space of interest c1.s = 1.0f; c1.v = 1.0f; while ( c1.h<0.0f ) c1.h += 360.0f; while ( c1.h>360.0f ) c1.h -= 360.0f; if ( c1.h<120.0f ) { sat.r = (120.0f-c1.h) / 60.0f; sat.g = c1.h / 60.0f; sat.b = 0.0f; } else if ( c1.h<240.0f ) { sat.r = 0.0f; sat.g = (240.0f-c1.h) / 60.0f; sat.b = (c1.h-120.0f) / 60.0f; } else { sat.r = (c1.h-240.0f) / 60.0f; sat.g = 0.0f; sat.b = (360.0f-c1.h) / 60.0f; } if ( sat.r>1 ) sat.r = 1; if ( sat.g>1 ) sat.g = 1; if ( sat.b>1 ) sat.b = 1; c2.r = ( 1 - c1.s + c1.s*sat.r ) * c1.v; c2.g = ( 1 - c1.s + c1.s*sat.g ) * c1.v; c2.b = ( 1 - c1.s + c1.s*sat.b ) * c1.v; return GsColor ( c2.r, c2.g, c2.b ); }
void SoModelWire::build(float len, float rt, float rb, int nfaces, bool shading) { //int i; P.clear(); N.clear(); // set size to zero, just in case //P.reserve(18); C.reserve(18); // reserve space to avoid re-allocations from the calls below //Drawing hand for (int i = 0; i < m.vsize; i++) { for (int j = 0; j < m.fsize; j++) { P.push_back(m.V[m.F[j].va]); P.push_back(m.V[m.F[j].vb]); P.push_back(m.V[m.F[j].vb]); P.push_back(m.V[m.F[j].vc]); P.push_back(m.V[m.F[j].vc]); P.push_back(m.V[m.F[j].va]); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); C.push_back(GsColor(m.F[0].r, m.F[0].g, m.F[0].b)); } } // send data to OpenGL buffers: glBindBuffer(GL_ARRAY_BUFFER, buf[0]); glBufferData(GL_ARRAY_BUFFER, P.size() * 3 * sizeof(float), &P[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buf[1]); glBufferData(GL_ARRAY_BUFFER, C.size() * 4 * sizeof(gsbyte), &C[0], GL_STATIC_DRAW); // save size so that we can free our buffers and later just draw the OpenGL arrays: _numpoints = P.size(); // free non-needed memory: P.resize(0); C.resize(0); }