Git Product home page Git Product logo

opensiv3dbulletphysics's Introduction

OpenSiv3DBulletPhysics

OpenSiv3Dで物理エンジンBulletを使うためのC++ライブラリ

記事

Siv3D Advent Calendar 2022 7日目

対応形状

Box Sphere Cone Cylinder

サンプル

#include <Siv3D.hpp> // OpenSiv3D v0.6.6
#include "SivBullet.hpp"

void Main() {
	// 3D シーンを描く、マルチサンプリング対応レンダーテクスチャ
	const MSRenderTexture rt{ Scene::Size(), TextureFormat::R8G8B8A8_Unorm_SRGB, HasDepth::Yes };
	// 背景色 (removeSRGBCurve() で sRGB カーブを除去)
	Color bgColor = Palette::Skyblue.removeSRGBCurve();

	// デバッグカメラ
	DebugCamera3D camera{ rt.size(), 60_deg, Vec3{0, 30, -100}, Vec3{0, 0, 0} };

	// シミュレーション空間の定義 (重力 Vec3{ 0, -9.8, 0 })
	DynamicsWorld world{ Vec3{ 0, -9.8, 0 } };

	//
	// 質量 0.0 で { 0, 0, 0 } に { 100, 0.1, 100 } の大きさの箱
	auto ground = world.createBox(Vec3{ 0, 0, 0 }, Vec3{ 100, 0.1, 100 }, 0.0);

	// 箱の配列
	Array<BulletBody> boxes;

	// システムループ
	while (System::Update()) {
		// 空間の更新
		world.update(Scene::DeltaTime());

		// Enterキーで箱を追加
		if (KeyEnter.down()) {
			boxes << world.createBox(Vec3{ Random(-50, 50), 50, Random(-50, 50)}, Vec3{1, 1, 1}, 1.0);
		}

		// カメラの更新
		camera.update();

		// カメラを3D空間に設定
		Graphics3D::SetCameraTransform(camera);

		// [3D 描画]
		{
			const ScopedRenderTarget3D target{ rt.clear(bgColor) };

			// 床の描画
			ground.draw();
			// 箱の描画
			for (const auto& box : boxes) {
				box.draw();
			}
		}

		// [3D を 2D に描画]
		{
			Graphics3D::Flush();
			rt.resolve();
			Shader::LinearToScreen(rt);
		}
	}
}

opensiv3dbulletphysics's People

Contributors

tas9n avatar

Stargazers

Takuma HASHIMOTO avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.