Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Circle Collision Issues of QRigidBody #32

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Godot
/**/.godot
/**/export_presets.cfg


# CMake
Expand Down Expand Up @@ -60,4 +61,4 @@
/**/.Spotlight-V100
/**/.TemporaryItems
/**/.Trashes
/**/.VolumeIcon.icns
/**/.VolumeIcon.icns
Binary file modified .sconsign.dblite
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions project/examples/1_welcome/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ script = ExtResource("1_nagly")

[node name="QWorldNode" type="QWorldNode" parent="."]
gravity = Vector2(0, 0.1)
debug_renderer = false
enable_debug_mouse_interactions = true

[node name="background" type="ColorRect" parent="."]
Expand Down
44 changes: 26 additions & 18 deletions project/examples/8_pbd_bodies/main.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[gd_scene load_steps=4 format=3 uid="uid://b07dx1g015v5r"]

[ext_resource type="Texture2D" uid="uid://ojuguaw1u74o" path="res://examples/8_pbd_bodies/sprites/godot_pixel_kenney.png" id="1_m1fsg"]
[ext_resource type="Texture2D" uid="uid://dd5t0hki4gur8" path="res://examples/8_pbd_bodies/sprites/godot_pixel_17x16.png" id="1_i8jge"]

[sub_resource type="Gradient" id="Gradient_5kq2g"]
interpolation_mode = 2
offsets = PackedFloat32Array(0, 0.835648)
offsets = PackedFloat32Array(0.208333, 0.835648)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)

[sub_resource type="GradientTexture2D" id="GradientTexture2D_f3c86"]
gradient = SubResource("Gradient_5kq2g")
width = 256
height = 256
fill = 1
fill = 2
fill_from = Vector2(0.5, 0.5)
fill_to = Vector2(1, 1)

Expand Down Expand Up @@ -85,25 +85,33 @@ data_polygon = PackedInt32Array(0, 1, 2, 3)
data_uv_maps = Array[PackedInt32Array]([PackedInt32Array(0, 1, 3), PackedInt32Array(1, 2, 3)])

[node name="QTexturedPBDBodyNode" type="QTexturedPBDBodyNode" parent="."]
texture = ExtResource("1_m1fsg")
texture_scale = 4.0
texture = ExtResource("1_i8jge")
texture_scale = 10.0
sfd_texture = SubResource("GradientTexture2D_f3c86")
sfd_shader_alpha_threshold = 0.6
break_distance = 15.0
pixel_step_size = 2.0
pixel_step_size = 1.0
rigidity = 0.1
self_collision = true
shape_matching_rate = 0.1
position = Vector2(320, 304)
position = Vector2(368, 256)

[node name="QTexturedPBDBodyNode2" type="QTexturedPBDBodyNode" parent="."]
texture = ExtResource("1_m1fsg")
texture_scale = 4.0
sfd_texture = SubResource("GradientTexture2D_f3c86")
sfd_shader_alpha_threshold = 0.6
break_distance = 15.0
pixel_step_size = 2.0
rigidity = 0.1
self_collision = true
shape_matching_rate = 0.1
position = Vector2(336, -32)
[node name="QRigidBodyNode" type="QRigidBodyNode" parent="."]
position = Vector2(592, 208)

[node name="QMeshCircleNode" type="QMeshCircleNode" parent="QRigidBodyNode"]
enable_vector_rendering = true
enable_stroke = true
data_particle_positions = PackedVector2Array(0, 0)
data_particle_radius = PackedFloat32Array(32)
data_particle_is_internal = PackedByteArray(0)

[node name="QRigidBodyNode2" type="QRigidBodyNode" parent="."]
position = Vector2(656, 272)

[node name="QMeshCircleNode" type="QMeshCircleNode" parent="QRigidBodyNode2"]
enable_vector_rendering = true
enable_stroke = true
data_particle_positions = PackedVector2Array(0, 0)
data_particle_radius = PackedFloat32Array(32)
data_particle_is_internal = PackedByteArray(0)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://ojuguaw1u74o"
path="res://.godot/imported/godot_pixel_kenney.png-5063dfda5bb9e63ab2298615b90515b8.ctex"
uid="uid://dd5t0hki4gur8"
path="res://.godot/imported/godot_pixel_17x16.png-1bc62bc0bab32cbd55e97670e03f3c9e.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://examples/8_pbd_bodies/sprites/godot_pixel_kenney.png"
dest_files=["res://.godot/imported/godot_pixel_kenney.png-5063dfda5bb9e63ab2298615b90515b8.ctex"]
source_file="res://examples/8_pbd_bodies/sprites/godot_pixel_17x16.png"
dest_files=["res://.godot/imported/godot_pixel_17x16.png-1bc62bc0bab32cbd55e97670e03f3c9e.ctex"]

[params]

Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions project/examples/examples_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func _ready() -> void:
option_button.add_item("5-So Soft World",4)
option_button.add_item("6-Box Stack",5)
option_button.add_item("7-Classic Platformer",5)
option_button.add_item("8-PBD Dynamics",5)
option_button.set_global_position(Vector2(32,32) )
add_child(option_button)
option_button.selected=-1
Expand All @@ -38,6 +39,8 @@ func on_example_selected(value:int) :
get_tree().change_scene_to_file("res://examples/6_box_stack/main.tscn")
6:
get_tree().change_scene_to_file("res://examples/7_classic_platformer/main.tscn")
7:
get_tree().change_scene_to_file("res://examples/8_pbd_bodies/main.tscn")



Expand Down
41 changes: 41 additions & 0 deletions project/export_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[preset.0]

name="Web"
platform="Web"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2

[preset.0.options]

custom_template/debug=""
custom_template/release=""
variant/extensions_support=true
variant/thread_support=false
vram_texture_compression/for_desktop=true
vram_texture_compression/for_mobile=false
html/export_icon=true
html/custom_html_shell=""
html/head_include=""
html/canvas_resize_policy=2
html/focus_canvas_on_start=true
html/experimental_virtual_keyboard=false
progressive_web_app/enabled=false
progressive_web_app/ensure_cross_origin_isolation_headers=true
progressive_web_app/offline_page=""
progressive_web_app/display=1
progressive_web_app/orientation=0
progressive_web_app/icon_144x144=""
progressive_web_app/icon_180x180=""
progressive_web_app/icon_512x512=""
progressive_web_app/background_color=Color(0, 0, 0, 1)
4 changes: 4 additions & 0 deletions src/QuarkPhysics/qcollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,15 @@ void QCollision::CircleAndCircle(vector<QParticle*> &particlesA,vector<QParticle
sizeGreaterThenOne=true;
}



//A. Start the loop for all points of orderedParticlesA

for(size_t i=0;i<sizeA;++i ){
QParticle *pA=orderedParticlesA[i];

cout<<"particleA AABB minX:"<<pA->GetAABB().GetMin()<<" minY:"<<pA->GetAABB().GetMax()<<endl;


if(sizeGreaterThenOne){
if(pA->GetAABB().isCollidingWith(boundingBoxB)==false ){
Expand Down
2 changes: 1 addition & 1 deletion src/QuarkPhysics/qworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ vector<QCollision::Contact*> QWorld::GetCollisions(QBody *bodyA, QBody *bodyB){
if(bodyA->GetBodyType()==QBody::BodyTypes::RIGID && bodyB->GetBodyType()==QBody::BodyTypes::RIGID){
velocitySensitive=true;
}
QCollision::CircleAndCircle(meshA->particles,meshB->particles,bboxB,contactList,velocitySensitive);
QCollision::CircleAndCircle(meshA->particles,meshB->particles,bboxB,contactList,0.0f,velocitySensitive);

}else if(QMesh::CheckCollisionBehaviors(meshA,meshB,QMesh::POLYLINE, QMesh::POLYGONS )){
QMesh *polylineMesh=meshA->collisionBehavior==QMesh::POLYLINE ? meshA:meshB;
Expand Down
23 changes: 19 additions & 4 deletions src/qmesh_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,24 @@ QMeshNode *QMeshNode::remove_particle_at(int index) {
while(i<springObjects.size()){
Ref<QSpringObject> sp=springObjects[i];
if(sp->get_particle_a()==particle_object || sp->get_particle_b()==particle_object){
springObjects.erase(springObjects.begin()+i);
remove_spring_at(i);
}else{
i++;
++i;
}

}

//Remove linked angle constraints
i=0;
while(i<angleConstraintObjects.size()){
Ref<QAngleConstraintObject> ac=angleConstraintObjects[i];
if(ac->get_particle_a()==particle_object || ac->get_particle_b()==particle_object || ac->get_particle_c()==particle_object){
remove_angle_constraint_at(i);
}else{
++i;
}
}

//Remove linked polygons


Expand All @@ -1316,14 +1329,16 @@ QMeshNode *QMeshNode::remove_particle_at(int index) {
int n=0;
while(n<pol.size() ){
if(pol[n]==particle_object){
pol.erase(pol.begin()+n );
remove_particle_from_polygon_at(n);
matched=true;
}else{
++n;
}
}
if(matched==true && pol.size()<3){
polygon.clear();
while(get_polygon_particle_count()>0 ){
remove_particle_from_polygon_at(0);
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/qtexturedpbdbody_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,17 @@ QTexturedPBDBodyNode *QTexturedPBDBodyNode::create_mesh_with_texture()
size_t i=0;
while (i<meshNode->get_particle_count() ){
if(particleColors[i].a==0.0f){
cout<<i<<endl;
meshNode->remove_particle_at(i);
particleColors.remove_at(i);

}else{
++i;
}
}

cout<<"Particle Remove operation finished! "<<endl;


add_child(meshNode);

Expand Down