From 70dd0144edbe4ea70ac3ff8d75e60e5ea572d154 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 27 Feb 2024 00:45:59 +0800 Subject: [PATCH 1/4] add issue link. --- docs/gsoc/ideas.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/gsoc/ideas.md b/docs/gsoc/ideas.md index c05cd1b0..d03095b8 100644 --- a/docs/gsoc/ideas.md +++ b/docs/gsoc/ideas.md @@ -21,6 +21,8 @@ Our goal is to introduce a pybind11 compatible solution to pocketpy as an altern for functions and classes. You can use C\+\+17 features to implement it, instead of C++11 used in pybind11. +See https://github.com/pocketpy/pocketpy/issues/216 for more details. + ### Add `numpy` module + Difficulty Level: 4/5 (Intermediate) From 2a1a71a0e958a99b7dfb76b41e4e2aebc1c60be6 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 27 Feb 2024 00:54:28 +0800 Subject: [PATCH 2/4] Update ideas.md --- docs/gsoc/ideas.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/gsoc/ideas.md b/docs/gsoc/ideas.md index d03095b8..391e6a99 100644 --- a/docs/gsoc/ideas.md +++ b/docs/gsoc/ideas.md @@ -36,4 +36,5 @@ It would be nice to have a `numpy` module in pocketpy. `numpy` is a huge project. Our goal is to implement a most commonly used subset of `numpy` in pocketpy. You can mix C++ and Python code to simplify the overall workloads. + See https://github.com/pocketpy/pocketpy/issues/202 for more details. From 394ee13c8de0e5d14b7d7a9787a379efc6635be5 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 27 Feb 2024 01:04:11 +0800 Subject: [PATCH 3/4] Update guide.md --- docs/gsoc/guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/gsoc/guide.md b/docs/gsoc/guide.md index 2ff0f353..e3d51e49 100644 --- a/docs/gsoc/guide.md +++ b/docs/gsoc/guide.md @@ -14,7 +14,7 @@ First, you need to install these tools: 1. Python(>= 3.8), I am sure you already have it. 2. A C++ compiler, such as GCC, Clang or MSVC. If you are on Linux, `gcc` and `g++` are already installed. If you are on Windows, you can install Visual Studio with C++ development tools. -3. CMake(>= 3.15), a cross-platform build tool. You can use `pip install cmake` to install it. +3. CMake(>= 3.10), a cross-platform build tool. You can use `pip install cmake` to install it. Then, clone pocketpy sources from github and try to build: ```bash @@ -37,7 +37,7 @@ Type "exit()" to exit. ### Application guide -Your application should include the following: +**Your need to send an email to `blueloveth@foxmail.com` with the following information:** 1. A brief introduction about yourself, including the most related open sourced project you have worked on before. It is highly recommended to attach your Github profile link. 2. A technical proposal for the project you are interested in working on, including: @@ -54,5 +54,5 @@ See [Coding Style Guide](../coding_style_guide.md). ### Contact us If you have any questions, you can join our [Discord](https://discord.gg/WWaq72GzXv) -or send an email to blueloveth@foxmail.com. +or contact me via email. We are glad to help you with your application. From d8fb555258f9f3ab6def964a84a4a2780367321b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 27 Feb 2024 01:19:39 +0800 Subject: [PATCH 4/4] Delete box2d.md --- docs/modules/box2d.md | 208 ------------------------------------------ 1 file changed, 208 deletions(-) delete mode 100644 docs/modules/box2d.md diff --git a/docs/modules/box2d.md b/docs/modules/box2d.md deleted file mode 100644 index 22f83e77..00000000 --- a/docs/modules/box2d.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -icon: package-dependencies -label: box2d ---- - -!!! -This module was moved to `carrotlib`, i.e. not a builtin module anymore. -!!! - -[Box2D](https://box2d.org/) by Erin Catto, the world's best 2D physics engine. -All platforms are supported, including desktop, mobile and web. - -## Overview - -The `box2d` module in pkpy provides a high-level, also simplified, interface to Box2D engine, which is suitable for most use cases. -There are two classes in `box2d` module: `World` and `Body`. - -`World` is the world of Box2D, it is the container of all `Body`s. -In most cases, you only need one `World` instance. -`World` class provides methods to create, destroy and query `Body`s -and also methods to step the simulation. - -A `Body` instance is a physical entity in the world. -A `Body` can only have one shape at a time. -For example, a circle, a rectangle, a polygon, etc. -You are allowed to change the shape of a `Body` at runtime. -`Body`s can be static, dynamic or kinematic. -A static `Body` is not affected by forces or collisions. -A dynamic `Body` is fully simulated. -A kinematic `Body` moves according to its velocity. -`Body` class provides methods to set its properties, such as position, velocity, etc. -It also provides methods to apply forces and impulses to it. - -!!! -A `box2d.Body` in pkpy is an unified wrapper of Box2D's `b2Body`, -`b2Shape` and `b2Fixture`. -It hides the details of Box2D's API and provides a high-level interface. -!!! - -## APIs - -https://github.com/pocketpy/pocketpy/blob/main/include/typings/box2d.pyi - -## Example - -### Simple simulation - -```python -import box2d -from linalg import vec2 - -# create a world -world = box2d.World() - -# create a body with a box shape -body = box2d.Body(world) -body.set_box_shape(1, 1) - -# give it a velocity -body.velocity = vec2(1, 0) - -# step the simulation -for i in range(30): - world.step(1/30, 8, 3) - print(i, body.position) -``` - -``` -0 vec2(0.033, 0.000) -1 vec2(0.067, 0.000) -2 vec2(0.100, 0.000) -3 vec2(0.133, 0.000) -4 vec2(0.167, 0.000) -5 vec2(0.200, 0.000) -6 vec2(0.233, 0.000) -7 vec2(0.267, 0.000) -8 vec2(0.300, 0.000) -9 vec2(0.333, 0.000) -10 vec2(0.367, 0.000) -11 vec2(0.400, 0.000) -12 vec2(0.433, 0.000) -13 vec2(0.467, 0.000) -14 vec2(0.500, 0.000) -15 vec2(0.533, 0.000) -16 vec2(0.567, 0.000) -17 vec2(0.600, 0.000) -18 vec2(0.633, 0.000) -19 vec2(0.667, 0.000) -20 vec2(0.700, 0.000) -21 vec2(0.733, 0.000) -22 vec2(0.767, 0.000) -23 vec2(0.800, 0.000) -24 vec2(0.833, 0.000) -25 vec2(0.867, 0.000) -26 vec2(0.900, 0.000) -27 vec2(0.933, 0.000) -28 vec2(0.967, 0.000) -29 vec2(1.000, 0.000) -``` - -### Two bodies with collision - -```python -import box2d -from linalg import vec2 - -world = box2d.World() - -""" - 12/s -B -----> A --|-|-|-|-|-|-|-|-|- -0 1 2 3 4 5 6 7 8 9 -""" - -# body_a is a static body with a box shape at (9, 0) -body_a = box2d.Body(world) -body_a.type = 0 # static type -body_a.set_box_shape(0.5, 0.5) -body_a.position = vec2(9, 0) - -class Node: - def on_box2d_contact_begin(self, other): - print('body_a collides with body_b!!') - - def on_box2d_pre_step(self): - pass - - def on_box2d_post_step(self): - pass - -# body_b is a dynamic body with a circle shape at (0, 0) -body_b = box2d.Body(world, Node()) -body_b.set_circle_shape(0.5) -body_b.position = vec2(0, 0) - -# give body_b a velocity and it will collide with body_a at some point -body_b.velocity = vec2(12, 0) - -for i in range(30): - world.step(1/30, 8, 3) - print(i, body_b.position) -``` - -``` -0 vec2(0.400, 0.000) -1 vec2(0.800, 0.000) -2 vec2(1.200, 0.000) -3 vec2(1.600, 0.000) -4 vec2(2.000, 0.000) -5 vec2(2.400, 0.000) -6 vec2(2.800, 0.000) -7 vec2(3.200, 0.000) -8 vec2(3.600, 0.000) -9 vec2(4.000, 0.000) -10 vec2(4.400, 0.000) -11 vec2(4.800, 0.000) -12 vec2(5.200, 0.000) -13 vec2(5.600, 0.000) -14 vec2(6.000, 0.000) -15 vec2(6.400, 0.000) -16 vec2(6.800, 0.000) -17 vec2(7.200, 0.000) -18 vec2(7.600, 0.000) -19 vec2(8.000, 0.000) -body_a collides with body_b!! -20 vec2(7.999, 0.000) -21 vec2(7.998, 0.000) -22 vec2(7.998, 0.000) -23 vec2(7.997, 0.000) -24 vec2(7.997, 0.000) -25 vec2(7.996, 0.000) -26 vec2(7.996, 0.000) -27 vec2(7.996, 0.000) -28 vec2(7.996, 0.000) -29 vec2(7.996, 0.000) -``` - -## Caveats - -You should set the shape of the body first before accessing fixture properties. -```python -class Body: - ... - - # fixture settings - density: float - friction: float - restitution: float - restitution_threshold: float - is_sensor: bool -``` - -```python -import box2d -world = box2d.World() -body = box2d.Body(world) - -body.is_sensor = True # this will raise an error -``` - -The correct usage is: -```python -body = box2d.Body(world) -body.set_box_shape(1, 1) # set shape first - -body.is_sensor = True # OK -``` \ No newline at end of file