Nav(const Nav& nav)
	:	Pose(nav.pos(), nav.quat() ), 
		mMove0(nav.mMove0), mMove1(nav.mMove1),	// linear velocities (raw, smoothed)
		mSpin0(nav.mSpin0), mSpin1(nav.mSpin1),	// angular velocities (raw, smoothed)
		mTurn(nav.mTurn), mNudge(nav.mNudge),			//  
		mSmooth(nav.smooth()), mVelScale(nav.mVelScale)
	{	updateDirectionVectors(); }
	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 main(){

	double world_radius = 50;

	nav.smooth(0.8);
	lens.near(1).far(world_radius);

	// set up mesh:
	mesh.primitive(Graphics::TRIANGLES);
	double tri_size = 2;
	int count = 4000;
	for (int i=0; i<count; i++) {
		double x = rnd::uniformS(world_radius);
		double y = rnd::uniformS(world_radius);
		double z = rnd::uniformS(world_radius);
		for (int v=0; v<3; v++) {
			mesh.color(HSV(float(i)/count, v!=2, 1));
			mesh.vertex(x+rnd::uniformS(tri_size), y+rnd::uniformS(tri_size), z+rnd::uniformS(tri_size));
		}
	}

	// set up grid:
	grid.primitive(Graphics::LINES);
	double stepsize = 1./2;
	for (double x=-1; x<=1; x+= stepsize) {
	for (double y=-1; y<=1; y+= stepsize) {
		grid.vertex(x, y, 1);
		grid.vertex(x, y, -1);
	}}
	for (double x=-1; x<=1; x+= stepsize) {
	for (double z=-1; z<=1; z+= stepsize) {
		grid.vertex(x, 1, z);
		grid.vertex(x, -1, z);
	}}
	for (double y=-1; y<=1; y+= stepsize) {
	for (double z=-1; z<=1; z+= stepsize) {
		grid.vertex(1, y, z);
		grid.vertex(-1, y, z);
	}}
	grid.scale(world_radius);

	// set up cube:
	cube.color(1,1,1,1);
	cube.primitive(Graphics::TRIANGLES);
	addCube(cube);
	cube.generateNormals();

	win.create(Window::Dim(100, 0, 640, 480), "Cube Map FBO Example", 60);
	win.displayMode(win.displayMode() | Window::STEREO_BUF);
	win.add(new StandardWindowKeyControls);
	win.add(new NavInputControl(nav));

	MainLoop::start();

    return 0;
}
Esempio n. 4
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;
	}
Esempio n. 5
0
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;
}