bool onFrame(){ nav.step(); // capture the scene: cubeFBO.capture(gl, lens, nav, *this); // now use the captured texture: gl.viewport(0, 0, width(), height()); gl.clearColor(0.2, 0.2, 0.2, 0); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // first, draw it as a cylindrical map in the background: // ortho for 2D, ranging from 0..1 in each axis: gl.projection(Matrix4d::ortho(0, 1, 1, 0, -1, 1)); gl.modelView(Matrix4d::identity()); gl.depthTesting(false); gl.lighting(false); gl.blending(false); cubeFBO.drawMap(gl); // second, use it to texture a rotating object: gl.projection(Matrix4d::perspective(70, width()/(double)height(), lens.near(), lens.far())); gl.modelView(Matrix4d::lookAt(Vec3d(0, 0, 4), Vec3d(0, 0, 2), Vec3d(0, 1, 0))); // rotate over time: gl.rotate(MainLoop::now()*30., 0.707, 0.707, 0.); gl.lighting(false); gl.blending(false); gl.depthTesting(true); // use cubemap texture cubeFBO.bind(); // generate texture coordinates from the object: GLenum map = GL_OBJECT_LINEAR; //GLenum map = GL_REFLECTION_MAP; //GLenum map = GL_NORMAL_MAP; //GLenum map = GL_EYE_LINEAR; //GLenum map = GL_SPHERE_MAP; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, map); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, map); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, map); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); gl.draw(cube); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); cubeFBO.unbind(); return true; }
int utSpatial(){ { Pose a; } { Nav a; a.smooth(0); a.home(); a.move(1,0,0); a.step(); assert(a.vec() == Vec3d(1.0,0,0)); a.step(); assert(a.vec() == Vec3d(2.0,0,0)); a.step(0.5); assert(a.vec() == Vec3d(2.5,0,0)); } return 0; }
bool onFrame(){ nav.smooth(0.8); nav.step(1.); stereo.draw(gl, lens, nav, Viewport(width(), height()), *this); if(evolve){ if((phase += 0.0002) > 2*M_PI) phase -= 2*M_PI; for(int k=0; k<N; ++k){ double z = double(k)/N * 4*M_PI; for(int j=0; j<N; ++j){ double y = double(j)/N * 4*M_PI; for(int i=0; i<N; ++i){ double x = double(i)/N * 4*M_PI; volData[k*N*N + j*N + i] = cos(x * cos(phase*7)) + cos(y * cos(phase*8)) + cos(z * cos(phase*9)); }}} } return true; }