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

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			field.Radius()*(1.4 + SineWave(time / 6.0) * 0.2),
			FullCircles(time * 0.1),
			Degrees(SineWave(time / 30.0) * 90)
		);

		auto light = CamMatrixf::Orbiting(
			Vec3f(),
			field.Radius()*1.6,
			FullCircles(0.33-time * 0.07),
			Degrees(SineWave(time / 31.0) * 80)
		);

		prog.camera_matrix.Set(camera);
		prog.light_position.Set(light.Position());

		GLfloat fade_coef = 1.1*(1.0-CosineWave01(time / 90.0));
		prog.fade_coef.Set(fade_coef);

		field.Draw();
	}
コード例 #2
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);
	}
コード例 #3
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

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

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

		shape.Draw();

		thread_ready.Signal();
		parent_ready.Wait();
	}
コード例 #4
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(time * 0.33));

        camera_matrix.Set(camera);
        model_matrix.Set(model);
        transf_time.Set(time);

        face_pp.Bind();
        gl.PolygonMode(PolygonMode::Fill);
        torus_instr.Draw(torus_indices);

        frame_pp.Bind();
        gl.PolygonMode(PolygonMode::Line);
        torus_instr.Draw(torus_indices);
    }
コード例 #5
0
ファイル: 016_noise_torus.cpp プロジェクト: detunized/oglplus
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.5,
				Degrees(time * 35),
				Degrees(SineWave(time / 20.0) * 60)
			)
		);
		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationX(FullCircles(time * 0.25))
		);

		torus.Bind();
		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);
	}
コード例 #6
0
ファイル: 030_pin_display.cpp プロジェクト: Extrunder/oglplus
	double Draw(double time)
	{
		assert(!shapes.empty());
		assert(ishape != shapes.end());
		shapes::ShapeWrapper& shape = *ishape;


		const double interval = 11.0;
		double segment = time - shape_time;
		double fade = segment*(interval-segment);
		fade -= 1.0;
		if(fade < 0.0) fade = 0.0;
		fade = std::sqrt(fade/interval);
		if(fade > 1.0) fade = 1.0;

		if(segment > interval)
		{
			if(++ishape == shapes.end())
			{
				ishape = shapes.begin();
			}
			shape_time = time;
		}

		gl.Clear().DepthBuffer();

		float dist = (1.0+SineWave(time / 13.0))*2.5;

		projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(45),
				1.0,
				1.0+dist,
				shape.BoundingSphere().Radius()*2.0+1.0+dist
			)
		);

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				shape.BoundingSphere().Radius()+1.5+dist,
				FullCircles(time / 27.0),
				Degrees(SineWave(time / 23.0) * 89)
			)
		);
		model_matrix.Set(
			ModelMatrixf::RotationA(
				Vec3f(1,1,1),
				FullCircles(time /-37.0)
			)
		);

		prog.Use();
		shape.Use();
		shape.Draw();

		return fade;
	}
コード例 #7
0
	void Render(double time)
	{
		namespace se = oglplus::smart_enums;
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		Mat4f camera = CamMatrixf::Orbiting(
			Vec3f(),
			6.5,
			Degrees(time * 135),
			Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
		);
		ModelMatrixf model = ModelMatrixf::Translation(0.0f, 1.5f, 0.0);
		ModelMatrixf identity;
		//
		SetProgramUniform(prog_norm, "CameraMatrix", camera);
		SetProgramUniform(prog_refl, "CameraMatrix", camera);
		// draw the plane into the stencil buffer
		prog_norm.Use();

		gl.Disable(se::Blend());
		gl.Disable(se::DepthTest());
		gl.Enable(se::StencilTest());
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(se::Always(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Replace());

		Uniform<Mat4f> model_matrix_norm(prog_norm, "ModelMatrix");
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);

		gl.ColorMask(true, true, true, true);
		gl.Enable(se::DepthTest());
		gl.StencilFunc(se::Equal(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Keep());

		// draw the torus using the reflection program
		prog_refl.Use();
		Uniform<Mat4f>(prog_refl, "ModelMatrix").Set(model);
		torus.Bind();
		torus_instr.Draw(torus_indices);

		gl.Disable(se::StencilTest());

		prog_norm.Use();
		// draw the torus using the normal object program
		model_matrix_norm.Set(model);
		torus_instr.Draw(torus_indices);

		// blend-in the plane
		gl.Enable(se::Blend());
		gl.BlendEquation(se::Max());
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);
	}
コード例 #8
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				5.0,
				Degrees(time * 11),
				Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
			)
		);
		ModelMatrixf identity;
		// make the model transformation matrix
		ModelMatrixf model =
			ModelMatrixf::Translation(0.0f, 1.5f, 0.0) *
			ModelMatrixf::RotationZ(Degrees(time * 43))*
			ModelMatrixf::RotationY(Degrees(time * 63))*
			ModelMatrixf::RotationX(Degrees(time * 79));
		// make the reflection matrix
		auto reflection = ModelMatrixf::Reflection(false, true, false);
		//
		gl.Disable(Capability::Blend);
		gl.Disable(Capability::DepthTest);
		gl.Enable(Capability::StencilTest);
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(CompareFunction::Always, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Replace);

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

		gl.ColorMask(true, true, true, true);
		gl.Enable(Capability::DepthTest);
		gl.StencilFunc(CompareFunction::Equal, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep);

		// draw the cube using the reflection program
		model_matrix.Set(reflection * model);
		gl.Bind(cube);
		cube_instr.Draw(cube_indices);

		gl.Disable(Capability::StencilTest);

		// draw the cube using the normal object program
		model_matrix.Set(model);
		cube_instr.Draw(cube_indices);

		// blend-in the plane
		gl.Enable(Capability::Blend);
		gl.BlendEquation(BlendEquation::Max);
		gl.Bind(plane);
		model_matrix.Set(identity);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}
コード例 #9
0
/**
 * @brief Derives Euler angles for the specified directional vector.
 */
void VectorAngles(const vec3_t vector, vec3_t angles) {

	const vec_t forward = sqrt(vector[0] * vector[0] + vector[1] * vector[1]);

	vec_t pitch = ClampAngle(-Degrees(atan2(vector[2], forward)));
	vec_t yaw = ClampAngle(Degrees(atan2(vector[1], vector[0])));

	VectorSet(angles, pitch, yaw, 0.0);
}
コード例 #10
0
	void Render(double time)
	{
		auto camera =
			CamMatrixf::Roll(Degrees(SineWave(time / 11.0)*7+SineWave(time/13.0)*5))*
			CamMatrixf::Orbiting(
				Vec3f(),
				40.0f,
				Degrees(SineWave(time / 11.0)*10+CosineWave(time/19.0)*10-90),
				Degrees(SineWave(time / 17.0)*10+SineWave(time/13.0)*10)
			);

		auto mm_identity = ModelMatrixf();
		auto mm_rotation = ModelMatrixf::RotationZ(FullCircles(time / 7.0));

		Uniform<Mat4f>* model_matrix = nullptr;

		GLuint drawing_fan = fan_index;
		auto drawing_driver =
			[
				&model_matrix,
				&mm_identity,
				&mm_rotation,
				&drawing_fan
			](GLuint phase) -> bool
			{
				if(phase == drawing_fan)
					model_matrix->Set(mm_rotation);
				else model_matrix->Set(mm_identity);
				return true;
			};

		// render the light mask
		light_fbo.Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		mask_vao.Bind();
		mask_prog.Use();
		mask_prog.camera_matrix.Set(camera);
		model_matrix = &mask_prog.model_matrix;

		meshes.Draw(drawing_driver);

		// render the final image
		DefaultFramebuffer().Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		draw_vao.Bind();
		draw_prog.Use();
		Vec4f lsp = projection * camera * Vec4f(light_position, 1.0);
		draw_prog.light_screen_pos = lsp.xyz()/lsp.w();
		draw_prog.camera_matrix.Set(camera);
		model_matrix = &draw_prog.model_matrix;

		meshes.Draw(drawing_driver);
	}
コード例 #11
0
void printGeo(PredicThirteen::geodetic_t *geo){
    Serial.print("lat: ");
    Serial.println(Degrees(geo->lat));
    Serial.print("lon: ");
    Serial.println(Degrees(geo->lon));
    Serial.print("alt: ");
    Serial.println(geo->alt);
    Serial.print("theta: ");
    Serial.println(geo->theta);
}
コード例 #12
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// camera matrix
		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			4.5f,
			Degrees(time * 50),
			Degrees(SineWave(time / 15.0) * 70)
		);
		// model matrix
		auto model =
			ModelMatrixf::Translation(
				0.0f,
				sqrt(1.0f+SineWave(time / 2.0)),
				0.0f
			) *
			ModelMatrixf::RotationX(FullCircles(time));
		//
		// use transform feedback to get transformed hole vertices
		prog_tfb.Use();
		Uniform<Mat4f>(prog_tfb, "CameraMatrix").Set(camera);
		Uniform<Mat4f>(prog_tfb, "ModelMatrix").Set(model);
		holes.Bind();
		{
			TransformFeedback::Activator activates_tfb(
				TransformFeedbackPrimitiveType::Points
			);
			gl.DrawArrays(PrimitiveType::Points, 0, hole_count);
		}
		prog.Use();
		//
		Uniform<Mat4f>(prog, "CameraMatrix").Set(camera);
		Uniform<Mat4f>(prog, "ModelMatrix").Set(model);

		// map the transform feedback buffer
		BufferTypedMap<GLfloat> transf_hole_verts_map(
			Buffer::Target::TransformFeedback,
			BufferMapAccess::Read
		);
		// use the values stored in the buffer as the input
		// for the fragment shader, that will use them to
		// calculate the bump map
		Uniform<GLfloat>(prog, "TransfHole").SetVectors<3>(
			transf_hole_verts_map.Count(),
			transf_hole_verts_map.Data()
		);
		// bind the VAO for the spere and render it
		sphere.Bind();
		sphere_instr.Draw(sphere_indices);
	}
コード例 #13
0
ファイル: 019_bpatch_tess.cpp プロジェクト: xubingyue/oglplus
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

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

		gl.DrawArrays(PrimitiveType::Patches, 0, 16);
	}
コード例 #14
0
ファイル: 023_waves.cpp プロジェクト: detunized/oglplus
	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);
	}
コード例 #15
0
	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);
	}
コード例 #16
0
    void Reshape(GLuint vp_width, GLuint vp_height) {
        width = vp_width;
        height = vp_height;

        float aspect = float(width) / height;

        auto projection = CamMatrixf::PerspectiveX(Degrees(60), aspect, 1, 20);

        plane_projection_matrix.Set(projection);
        shape_projection_matrix.Set(projection);

        gl.Bound(Texture::Target::Rectangle, depth_tex)
          .Image2D(
            0,
            PixelDataInternalFormat::DepthComponent,
            width / tex_size_div,
            height / tex_size_div,
            0,
            PixelDataFormat::DepthComponent,
            PixelDataType::Float,
            nullptr);
        gl.Bound(Texture::Target::Rectangle, reflect_tex)
          .Image2D(
            0,
            PixelDataInternalFormat::RGB,
            width / tex_size_div,
            height / tex_size_div,
            0,
            PixelDataFormat::RGB,
            PixelDataType::UnsignedByte,
            nullptr);
    }
コード例 #17
0
ファイル: 019_honeycomb_cube.cpp プロジェクト: xdray/oglplus
	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);
	}
コード例 #18
0
ファイル: 028_ripples.cpp プロジェクト: JanChou/oglplus
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		liquid_prog.time = time;


		auto camera = CamMatrixf::Orbiting(
			Vec3f(0, 0, 0),
			4.5 - SineWave(time / 14.0),
			FullCircles(time / 26.0),
			Degrees(55 + SineWave(time / 14.0) * 30)
		);
		Vec3f camera_position = camera.Position();

		liquid_prog.camera_position = camera_position;
		liquid_prog.camera_matrix = perspective*camera;

		for(int z=-grid_repeat; z!=grid_repeat; ++z)
		for(int x=-grid_repeat; x!=grid_repeat; ++x)
		{
			liquid_prog.grid_offset.Set(x, -0.5, z);
			grid.Draw();
		}

	}
コード例 #19
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);
	}
コード例 #20
0
	void Render(double time)
	{
		const Vec3f light_position(16.0, 10.0, 9.0);
		const Vec3f torus_center(0.0, 1.5, 0.0);

		const Mat4f torus_matrix =
			ModelMatrixf::Translation(torus_center) *
			ModelMatrixf::RotationZ(FullCircles(time / 16.0));

		const Mat4f light_proj_matrix =
			CamMatrixf::PerspectiveX(Degrees(10), 1.0, 1, 80) *
			CamMatrixf::LookingAt(light_position, torus_center);

		transf_prog.light_position.Set(light_position);

		RenderFrameShadowMap(
			light_position,
			torus_matrix,
			light_proj_matrix
		);
		RenderGlassShadowMap(
			light_position,
			torus_center,
			torus_matrix,
			light_proj_matrix
		);
		RenderImage(
			time,
			torus_center,
			torus_matrix,
			light_proj_matrix
		);
	}
コード例 #21
0
ファイル: test03.cpp プロジェクト: detunized/oglplus
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		Uniform<Mat4f>(prog, "cameraMatrix").Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0 + std::sin(time)*1.5,
				FullCircles(time * 0.5),
				Degrees(std::sin(time * 0.5) * 70)
			)
		);

		Uniform<Mat4f>(prog, "modelMatrix").Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time * 0.4)
			)
		);
		Uniform<Vec3f>(prog, "lightPos").Set(Vec3f(1.0f, 2.0f, 3.0f*std::sin(time * 2.9)));

		vao.Bind();
		// This is not very effective
		shape.Instructions().Draw(shape.Indices());
	}
コード例 #22
0
ファイル: 023_sky.cpp プロジェクト: matus-chochlik/oglplus
    void Render(double time) {
        const double day_duration = 67.0;
        auto sun =
          Vec3f(0.000, 1.000, 0.000) * 1e10 * SineWave(time / day_duration) +
          Vec3f(0.000, 0.000, -1.000) * 1e10 * CosineWave(time / day_duration);

        auto camera = CamMatrixf::Orbiting(
          Vec3f(),
          5.0,
          FullCircles(-0.10 - time / 27.0),
          Degrees(-20 - SineWave(time / 17.0) * 30));

        auto model = ModelMatrixf::RotationA(
          Vec3f(1.0, 1.0, 1.0), FullCircles(time / 13.0));

        gl.Clear().ColorBuffer().DepthBuffer();

        sky_box.Use();
        sky_box_prog.Use();
        sky_box_camera_matrix.Set(camera);
        sky_box_sun_position.Set(sun);
        sky_box.Draw();

        shape.Use();
        shape_prog.Use();
        shape_model_matrix.Set(model);
        shape_camera_matrix.Set(camera);
        shape_camera_position.Set(camera.Position());
        shape_sun_position.Set(sun);
        shape.Draw();
    }
コード例 #23
0
	void Reshape(GLuint vp_width, GLuint vp_height)
	{
		width = vp_width;
		height = vp_height;
		gl.Viewport(width, height);

		Texture::Image2D(
			Texture::Target::Rectangle,
			0,
			PixelDataInternalFormat::DepthComponent,
			width,
			height,
			0,
			PixelDataFormat::DepthComponent,
			PixelDataType::Float,
			nullptr
		);

		auto projection =
			CamMatrixf::PerspectiveX(
				Degrees(60),
				double(width)/height,
				1, 10000
			);
		draw_prog.Use();
		draw_prog.projection_matrix.Set(projection);
		depth_prog.Use();
		depth_prog.projection_matrix.Set(projection);
	}
コード例 #24
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		Uniform<Mat4f>(prog, "CameraMatrix").Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				2.7,
				Degrees(time * 135),
				Degrees(SineWave(time / 20.0) * 90)
			)
		);

		cube_instr.Draw(cube_indices);
	}
コード例 #25
0
    void Render(ExampleClock& clock) {
        if(long(clock.Now().Seconds()) % 4 == 0) {
            status += clock.Interval().Seconds();
        } else if(status != double(long(status))) {
            if(status - double(long(status)) < 0.5)
                status = double(long(status));
            else
                status = 1.0 + double(long(status));
        }

        gl.Clear().ColorBuffer().DepthBuffer();

        point_prog.status = GLfloat(0.5 - 0.5 * CosineWave(status * 0.5));

        CamMatrixf camera = CamMatrixf::Orbiting(
          Vec3f(),
          5.5f,
          FullCircles(clock.Now().Seconds() / 19.0),
          Degrees(45 + SineWave(clock.Now().Seconds() / 15.0) * 40));
        point_prog.camera_matrix.Set(camera);

        point_prog.model_matrix.Set(
          ModelMatrixf::RotationX(RightAngles(status)));
        shape.Draw();
    }
コード例 #26
0
ファイル: 023_sky.cpp プロジェクト: matus-chochlik/oglplus
 void Reshape(GLuint width, GLuint height) {
     gl.Viewport(width, height);
     auto projection =
       CamMatrixf::PerspectiveX(Degrees(70), float(width) / height, 1, 200);
     sky_box_projection_matrix.Set(projection);
     shape_projection_matrix.Set(projection);
 }
コード例 #27
0
	void Reshape(GLuint vp_width, GLuint vp_height)
	{
		width = vp_width;
		height = vp_height;
		refl_tex_side = width > height ? height : width;

		reflect_tex.Image2D(
			0,
			PixelDataInternalFormat::RGB,
			refl_tex_side, refl_tex_side,
			0,
			PixelDataFormat::RGB,
			PixelDataType::UnsignedByte,
			nullptr
		);
		rbo.Storage(
			PixelDataInternalFormat::DepthComponent,
			refl_tex_side, refl_tex_side
		);

		float aspect = float(width)/height;
		ProgramUniform<GLfloat>(plane_prog, "Aspect").Set(aspect);

		auto projection = CamMatrixf::PerspectiveX(
			Degrees(60), aspect, 1, 60
		);
		ProgramUniform<Mat4f>(plane_prog, "ProjectionMatrix").Set(projection);
		ProgramUniform<Mat4f>(shape_prog, "ProjectionMatrix").Set(projection);
	}
コード例 #28
0
	void Render(double time)
	{
		static const Mat4f reflection(
			Vec4f( 1.0, 0.0, 0.0, 0.0),
			Vec4f( 0.0,-1.0, 0.0, 0.0),
			Vec4f( 0.0, 0.0, 1.0, 0.0),
			Vec4f( 0.0, 0.0, 0.0, 1.0)
		);

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			GLfloat(7.0 + SineWave(time / 12.0)*2.5),
			FullCircles(time / 10.0),
			Degrees(45.0 - SineWave(time / 7.0)*35.0)
		);

		shape_prog.Use();
		shape.Bind();

		gl.Enable(Capability::CullFace);
		gl.FrontFace(make_shape.FaceWinding());

		// render into the off-screen framebuffer
		fbo.Bind(Framebuffer::Target::Draw);
		gl.Viewport(
			(width - refl_tex_side) / 2,
			(height - refl_tex_side) / 2,
			refl_tex_side, refl_tex_side
		);
		gl.Clear().ColorBuffer().DepthBuffer();

		shape_camera_matrix.Set(
			camera *
			ModelMatrixf::Translation(0.0f, -1.0f, 0.0f) *
			reflection
		);

		gl.CullFace(Face::Front);
		shape_instr.Draw(shape_indices);

		gl.Bind(Framebuffer::Target::Draw, DefaultFramebuffer());
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		shape_camera_matrix.Set(camera);

		gl.CullFace(Face::Back);
		shape_instr.Draw(shape_indices);

		gl.Disable(Capability::CullFace);

		// Render the plane
		plane_prog.Use();
		plane.Bind();

		plane_camera_matrix.Set(camera);
		plane_camera_position.Set(camera.Position());

		plane_instr.Draw(plane_indices);
	}
コード例 #29
0
ファイル: geodesic.c プロジェクト: AsherBond/MondocosmOS
double G_geodesic_lat_from_lon(double lon)
{
    adjust_lon(&lon);
    lon = Radians(lon);

    return Degrees(atan(st->A * sin(lon) - st->B * cos(lon)));
}
コード例 #30
0
ファイル: 018_particle_system.cpp プロジェクト: xdray/oglplus
	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());
	}