-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
62 lines (52 loc) · 1.29 KB
/
Main.cpp
File metadata and controls
62 lines (52 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# include <Siv3D.hpp>
void Main()
{
// 2D物理演算のシミュレーション空間(重力は下向きに 980)
P2World world{ 980.0 };
// 描画用のリスト
Array<P2Body> bodies;
// 線(床)の作成用
Optional<Vec2> startPos;
while (System::Update())
{
// 物理演算の更新
world.update();
// 左クリック:ボール(動体)を生成
if (MouseL.down())
{
bodies << world.createCircle(P2Dynamic, Cursor::Pos(), 20, P2Material{ .restitution = 0.5 });
}
// 右クリック:ドラッグで床(静止体)を生成
if (MouseR.down())
{
startPos = Cursor::Pos();
}
if (MouseR.up() && startPos)
{
const Vec2 endPos = Cursor::Pos();
if (startPos->distanceFrom(endPos) > 5)
{
bodies << world.createLine(P2Static, Vec2{ 0, 0 }, Line{ *startPos, endPos }, P2Material{ .friction = 0.5 });
}
startPos.reset();
}
// 描画処理
for (const auto& body : bodies)
{
body.draw(Palette::Skyblue);
}
// ドラッグ中のプレビュー線
if (startPos)
{
Line{ *startPos, Cursor::Pos() }.draw(4, Palette::Orange);
}
// 説明文
Print << U"左クリック: ボール作成";
Print << U"右クリックドラッグ: 床を作成";
Print << U"Cキー: クリア";
if (KeyC.down())
{
bodies.clear();
}
}
}