示例#1
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		int period = int(time * 0.125);
		if(prev_period < period)
		{
			if(period % 2)
				gl.PolygonMode(PolygonMode::Line);
			else gl.PolygonMode(PolygonMode::Fill);
			prev_period = period;
		}

		auto camera = CamMatrixf::Orbiting(
			Vec3f(0.0f, 2.0f, 0.0f),
			17.0f - CosineWave(time / 31.0f) * 10.0f,
			FullCircles(time / 43.0f),
			Degrees(45 - SineWave(time / 29.0f) * 35)
		);
		camera_matrix.Set(camera);
		camera_position.Set(camera.Position());

		anim_time.Set(time);

		plane_instr.Draw(plane_indices);
	}
示例#2
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5,
				Degrees(time * 35),
				Degrees(SineWave(time / 20.0) * 60)
			)
		);
		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationY(FullCircles(time * 0.25)) *
			ModelMatrixf::RotationX(FullCircles(0.25))
		);

		gl.PolygonMode(PolygonMode::Line);
		gl.CullFace(Face::Front);
		torus_instr.Draw(torus_indices);
		//
		gl.PolygonMode(PolygonMode::Fill);
		gl.CullFace(Face::Back);
		torus_instr.Draw(torus_indices);
	}
示例#3
0
	void Render(double time)
	{
		const GLfloat clear_color[4] = {0.8f, 0.8f, 0.7f, 0.0f};
		gl.ClearColorBuffer(0, clear_color);
		gl.ClearDepthBuffer(1.0f);
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5,
				Degrees(time * 15),
				Degrees(SineWave(time / 6.3) * 45)
			)
		);
		model_matrix.Set(
			ModelMatrixf::Translation(-1.0, 0.0, 0.0) *
			ModelMatrixf::RotationZ(Degrees(time * 180))
		);
		cube_instr.Draw(cube_indices);
		model_matrix.Set(
			ModelMatrixf::Translation(+1.0, 0.0, 0.0) *
			ModelMatrixf::RotationY(Degrees(time * 90))
		);
		cube_instr.Draw(cube_indices);
	}
示例#4
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		auto lightAzimuth = FullCircles(time * -0.5);
		light_pos.Set(
			Vec3f(
				Cos(lightAzimuth),
				1.0f,
				Sin(lightAzimuth)
			) * 2.0f
		);
		//
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0f,
				Degrees(-45),
				Degrees(SineWave(time / 30.0) * 70)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationY(FullCircles(time * 0.05))
		);

		cube.Bind();
		gl.CullFace(Face::Back);
		cube_instr.Draw(cube_indices);
	}
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.5 - SineWave(time / 16.0) * 2.0,
				FullCircles(time / 12.0),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time / 10.0)
			)
		);

		shape.Bind();
		shape_instr.Draw(shape_indices);
	}
示例#6
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.0 - SineWave(time / 6.0) * 2.0,
				FullCircles(time * 0.4),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationZ(FullCircles(time * 0.1))
		);

		cube.Bind();
		gl.CullFace(Face::Front);
		cube_instr.Draw(cube_indices);
		gl.CullFace(Face::Back);
		cube_instr.Draw(cube_indices);
	}
	void Reshape(GLuint width, GLuint height)
	{
		gl.Viewport(width, height);
		viewport_dimensions.Set(Vec2f(width, height));
		projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(60),
				double(width)/height,
				1, 40
			)
		);
	}
示例#8
0
	void Render(double time)
	{
		// update the particle positions, ages and directions
		GLuint i = 0;
		float time_diff = (time - prev_time);
		float age_mult = 0.2f;
		while(i != positions.size())
		{
			float drag = 0.1f * (time_diff);
			if((ages[i] += time_diff * age_mult) < 1.0f)
			{
				directions[i] *= (1.0f - drag);
				positions[i] += directions[i]*time_diff;
			}
			else
			{
				ages[i] = 0.0f;
				directions[i] = NewDirection();
				positions[i] = Vec3f();
			}
			++i;
		}
		// if there are not enough particles yet
		if(i != particle_count)
		{
			float spawn_interval = 1.0f/(age_mult*particle_count);
			if(prev_spawn + spawn_interval < time)
			{
				directions.push_back(NewDirection());
				positions.push_back(Vec3f());
				ages.push_back(0.0f);
				prev_spawn = time;
			}
		}
		prev_time = time;

		assert(positions.size() == directions.size());
		assert(positions.size() == ages.size());

		// upload the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, positions);
		// upload the particle ages
		age_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, ages);

		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				18.0f,
				FullCircles(time * 0.5),
				Degrees(45)
			)
		);

		gl.DrawArrays(PrimitiveType::Points, 0, positions.size());
	}
	void Reshape(GLuint width, GLuint height)
	{
		GLfloat w_2f = width / 2.0f;
		GLfloat h_2f = height/ 2.0f;
		GLfloat viewports[4*4] = {
			0.0f, 0.0f, w_2f, h_2f,
			w_2f, 0.0f, w_2f, h_2f,
			0.0f, h_2f, w_2f, h_2f,
			w_2f, h_2f, w_2f, h_2f
		};
		gl.ViewportArray(0, 4, viewports);

		projection = CamMatrixf::PerspectiveX(
			Degrees(65),
			double(width)/height,
			1, 30
		);

		camera_matrix_0.Set(
			projection *
			Mat4f(
				 Vec4f(0, 0,-1, 0),
				 Vec4f(0, 1, 0, 0),
				 Vec4f(1, 0, 0,-3),
				 Vec4f(0, 0, 0, 1)
			)
		);
		camera_matrix_1.Set(
			projection *
			Mat4f(
				 Vec4f(1, 0, 0, 0),
				 Vec4f(0, 0,-1, 0),
				 Vec4f(0, 1, 0,-3),
				 Vec4f(0, 0, 0, 1)
			)
		);
		camera_matrix_2.Set(
			projection *
			Mat4f(
				 Vec4f(1, 0, 0, 0),
				 Vec4f(0, 1, 0, 0),
				 Vec4f(0, 0, 1,-3),
				 Vec4f(0, 0, 0, 1)
			)
		);
	}
示例#10
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			4.5,
			Degrees(time * 35),
			Degrees(SineWave(time / 30.0) * 60)
		);

		auto model =
			ModelMatrixf::RotationY(FullCircles(time * 0.25)) *
			ModelMatrixf::RotationX(FullCircles(0.25));

		Vec4f lightPos(4.0f, 4.0f, -8.0f, 1.0f);

		prog.Use();
		camera_matrix.Set(camera);
		model_matrix.Set(model);
		light_pos_cam.Set(camera * lightPos);

		front_color.Set(Vec3f(0.3f, 0.2f, 0.0f));
		back_color.Set(Vec3f(0.2f, 0.1f, 0.0f));
		gl.PolygonMode(PolygonMode::Line);
		torus_instr.Draw(torus_indices);

		front_color.Set(Vec3f(0.9f, 0.8f, 0.1f));
		back_color.Set(Vec3f(1.0f, 0.9f, 0.8f));
		gl.PolygonMode(PolygonMode::Fill);
		torus_instr.Draw(torus_indices);
	}
示例#11
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(0.0f, 0.5f, 0.0f),
				6.5,
				Degrees(time * 35),
				Degrees(55 - SineWave(time / 20.0) * 30)
			)
		);
		light_pos.Set(light_path.Position(time / 10.0));

		plane.Bind();
		plane_instr.Draw(plane_indices);
	}
示例#12
0
	void Render(ExampleClock& clock)
	{
		positions.clear();
		ages.clear();

		// update the emitters and get the particle data
		for(auto i=emitters.begin(), e=emitters.end(); i!=e; ++i)
		{
			i->Update(clock);
			i->Upload(positions, ages);
		}
		assert(positions.size() == ages.size());

		// make a camera matrix
		auto cameraMatrix = CamMatrixf::Orbiting(
			Vec3f(),
			38.0 - SineWave(clock.Now().Seconds() / 6.0) * 17.0,
			FullCircles(clock.Now().Seconds() * 0.1),
			Degrees(SineWave(clock.Now().Seconds() / 20.0) * 60)
		);

		std::vector<float> depths(positions.size());
		std::vector<GLuint> indices(positions.size());
		// calculate the depths of the particles
		for(GLuint i=0, n=positions.size(); i!=n; ++i)
		{
			depths[i] = (cameraMatrix * Vec4f(positions[i], 1.0)).z();
			indices[i] = i;
		}

		// sort the indices by the depths
		std::sort(
			indices.begin(),
			indices.end(),
			[&depths](GLuint i, GLuint j)
			{
				return depths[i] < depths[j];
			}
		);

		// upload the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, positions, BufferUsage::DynamicDraw);
		// upload the particle ages
		age_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, ages, BufferUsage::DynamicDraw);

		gl.Clear().ColorBuffer().DepthBuffer();
		camera_matrix.Set(cameraMatrix);
		// use the indices to draw the particles
		gl.DrawElements(
			PrimitiveType::Points,
			indices.size(),
			indices.data()
		);
	}
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		edge_width.Set(4.0+SineWave(time / 7.0)*3.0);

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				5.5 - SineWave(time / 27)*2.0,
				Degrees(time * 33),
				Degrees(SineWave(time / 21.0) * 31)
			)
		);

		model_matrix.Set(ModelMatrixf::RotationZ(Degrees(time * 37)));

		shape_instr.Draw(shape_indices);
	}
示例#14
0
	void Reshape(GLuint width, GLuint height)
	{
		gl.Viewport(width, height);
		auto projection = CamMatrixf::PerspectiveX(
			Degrees(60),
			double(width)/height,
			1, 20
		);
		prog.Use();
		projection_matrix.Set(projection);
	}
示例#15
0
	void Reshape(GLuint width, GLuint height)
	{
		gl.Viewport(width, height);
		projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(70),
				double(width)/height,
				1, 20
			)
		);
	}
示例#16
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5,
				Degrees(time * 35),
				Degrees(SineWave(time / 60.0) * 80)
			)
		);
		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time * 0.25))
		);

		torus_instr.Draw(torus_indices);
	}
示例#17
0
	void Reshape(GLuint width, GLuint height)
	{
		gl.Viewport(width, height);
		prog.Use();
		projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(60),
				GLfloat(width)/height,
				0.1, 30
			)
		);
	}
示例#18
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		camera_matrix.Set(
			CamMatrixf::LookingAt(
				Vec3f(2.5, 3.5, 2.5),
				Vec3f()
			)
		);

		model_matrix.Set(
			ModelMatrixf::Translation(
				0.0f,
				sqrt(1.0f+SineWave(time / 2.0)),
				0.0f
			) *
			ModelMatrixf::RotationY(Degrees(time * 180))
		);

		sphere_instr.Draw(sphere_indices);
	}
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		CamMatrixf camera = CamMatrixf::Orbiting(
			Vec3f(),
			4.5 - SineWave(time / 16.0) * 1.5,
			FullCircles(time / 12.0),
			Degrees(SineWave(time / 30.0) * 90)
		);
		// set the matrix for camera orbiting the origin
		camera_matrix_3.Set(projection * camera);
		camera_position_3.Set(camera.Position());

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time / 10.0))
		);

		shape.Bind();
		shape_instr.Draw(shape_indices);
	}
示例#20
0
	void Render(double time)
	{
		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			3.0,
			FullCircles(time / 13.0),
			Degrees(-SineWave(time / 19.0) * 85)
		);
		camera_matrix.Set(camera);

		gl.Clear().ColorBuffer().DepthBuffer();
		gl.DrawElements(PrimitiveType::TriangleStrip, 6*5, DataType::UnsignedInt);
	}
示例#21
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5 + SineWave(time / 6.0)*0.5,
				FullCircles(time * 0.2),
				Degrees(SineWave(time / 20.0) * 80)
			)
		);
		gl.DrawArrays(PrimitiveType::Points, 0, 1);
	}
示例#22
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			2.9,
			FullCircles(time / 17.0),
			Degrees(45 + SineWave(time / 20.0) * 40)
		);

		camera_matrix.Set(camera);
		camera_position.Set(camera.Position());

		auto langle = FullCircles(time / 31.0);
		light_position.Set(
			Cos(langle)*20.0f,
			(1.2+Sin(langle))*15.0f,
			Sin(langle)*20.0f
		);

		shape.Draw();
	}
 void Render(double time)
 {
     gl.Clear().ColorBuffer().DepthBuffer();
     //
     // set the matrix for camera orbiting the origin
     camera_matrix.Set(
         CamMatrixf::Orbiting(
             Vec3f(),
             3.5,
             Degrees(time * 15),
             Degrees(SineWave(time / 6.3) * 45)
         )
     );
     model_matrix.Set(
         ModelMatrixf::Translation(-1.0, 0.0, 0.0) *
         ModelMatrixf::RotationZ(Degrees(time * 180))
     );
     cube_instr.Draw(cube_indices);
     model_matrix.Set(
         ModelMatrixf::Translation(+1.0, 0.0, 0.0) *
         ModelMatrixf::RotationY(Degrees(time * 90))
     );
     cube_instr.Draw(cube_indices);
 }
示例#24
0
    void Render(double time)
    {
        gl.Clear().ColorBuffer().DepthBuffer();

        camera_matrix.Set(
            CamMatrixf::Orbiting(
                Vec3f(),
                30.0 - SineWave(time / 17.0)*25.0,
                Degrees(time * 47),
                Degrees(SineWave(time / 31.0) * 90)
            )
        );

        gl.DrawArrays(PrimitiveType::Patches, 0, 16);
    }
示例#25
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5,
				Degrees(time * 135),
				Degrees(SineWave(time / 20.0) * 90)
			)
		);

		sphere_instr.Draw(sphere_indices);
	}
示例#26
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				18.5,
				Degrees(time * 135),
				Degrees(SineWave(time / 20.0) * 30)
			)
		);

		// draw 36 instances of the cube
		// the vertex shader will take care of their placement
		cube_instr.Draw(cube_indices, 36);
	}
示例#27
0
    void Render(double time)
    {
        gl.Clear().ColorBuffer().DepthBuffer();
        //
        // set the matrix for camera orbiting the origin
        camera_matrix.Set(
            CamMatrixf::LookingAt(
                cam_path.Position(time / 9.0),
                tgt_path.Position(time / 7.0)
            )
        );

        // draw the points
        gl.DrawArrays(PrimitiveType::Points, 0, node_count * 3);
        // draw the edges
        gl.DrawElements(
            PrimitiveType::Lines,
            edge_count,
            DataType::UnsignedInt
        );
    }
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			9.0,
			FullCircles(time * 0.1),
			Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)* 0.5 * 75)
		);
		ModelMatrixf identity;
		ModelMatrixf model =
			ModelMatrixf::Translation(0.0f, 2.5f, 0.0) *
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time * 0.2)
			);

		gl.CullFace(Face::Back);
		gl.ColorMask(true, true, true, true);
		gl.DepthMask(true);
		gl.Disable(Capability::StencilTest);

		object_prog.Use();
		object_camera_matrix.Set(camera);
		object_light_mult.Set(0.2f);

		object_model_matrix.Set(identity);
		plane.Bind();
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		object_model_matrix.Set(model);
		torus.Bind();
		torus_instr.Draw(torus_indices);

		gl.ColorMask(false, false, false, false);
		gl.DepthMask(false);
		gl.Enable(Capability::StencilTest);
		gl.StencilFunc(CompareFunction::Always, 0);
		gl.StencilOpSeparate(
			Face::Front,
			StencilOp::Keep,
			StencilOp::Keep,
			StencilOp::Incr
		);
		gl.StencilOpSeparate(
			Face::Back,
			StencilOp::Keep,
			StencilOp::Keep,
			StencilOp::Decr
		);

		shadow_prog.Use();
		shadow_camera_matrix.Set(camera);
		shadow_model_matrix.Set(model);

		gl.CullFace(Face::Back);
		torus_instr.Draw(torus_indices);
		gl.CullFace(Face::Front);
		torus_instr.Draw(torus_indices);
		gl.CullFace(Face::Back);

		gl.ColorMask(true, true, true, true);
		gl.DepthMask(true);
		gl.Clear().DepthBuffer();
		gl.StencilFunc(CompareFunction::Equal, 0);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep);

		object_prog.Use();
		object_light_mult.Set(2.5);

		object_model_matrix.Set(identity);
		object_color.Set(0.8f, 0.7f, 0.4f);
		plane.Bind();
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		object_model_matrix.Set(model);
		object_color.Set(0.9f, 0.8f, 0.1f);
		torus.Bind();
		torus_instr.Draw(torus_indices);
	}
示例#29
0
	void Render(double time)
	{
		// render into the texture
		fbo.Bind(Framebuffer::Target::Draw);
		gl.Viewport(tex_side, tex_side);
		gl.ClearDepth(1.0f);
		gl.ClearColor(0.4f, 0.9f, 0.4f, 1.0f);
		gl.Clear().ColorBuffer().DepthBuffer();
		torus_prog.Use();

		torus_projection_matrix.Set(
			CamMatrixf::PerspectiveX(Degrees(60), 1.0, 1, 30)
		);

		torus_camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.5,
				Degrees(time * 25),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		torus_model_matrix.Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time * 0.5)
			)
		);

		torus.Bind();
		gl.FrontFace(make_torus.FaceWinding());
		torus_instr.Draw(torus_indices);

		// render the textured cube
		Framebuffer::BindDefault(Framebuffer::Target::Draw);
		gl.Viewport(width, height);
		gl.ClearDepth(1.0f);
		gl.ClearColor(0.8f, 0.8f, 0.8f, 0.0f);
		gl.Clear().ColorBuffer().DepthBuffer();
		cube_prog.Use();

		cube_projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(70),
				double(width)/height,
				1, 30
			)
		);

		cube_camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0,
				Degrees(time * 35),
				Degrees(SineWave(time / 20.0) * 60)
			)
		);

		cube_model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time * 0.25))
		);

		cube.Bind();
		gl.FrontFace(make_cube.FaceWinding());
		cube_instr.Draw(cube_indices);
	}