Skip to content

Commit

Permalink
Fixed TileMapLayer scaled problems and solved scaled QMeshNode render…
Browse files Browse the repository at this point in the history
… problems.
  • Loading branch information
erayzesen committed Jan 17, 2025
1 parent eee1973 commit 69aced6
Show file tree
Hide file tree
Showing 42 changed files with 18 additions and 4 deletions.
Binary file modified .sconsign.dblite
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions project/addons/quarkphysics/helper_nodes/qtilemap_collider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ func parse_tile_map() :
bodyNode.collidable_layers=collider_layer["body_collidable_layers_bit"]
bodyNodes.add_child(bodyNode)


for polygon in collider_layer["polygons"] :
var decomp_polygons=Geometry2D.decompose_polygon_in_convex(polygon)
for decomp_poly in decomp_polygons :
for i in range(decomp_poly.size()) :
decomp_poly[i]=decomp_poly[i]*tile_map.global_scale
for decomp_poly in decomp_polygons :
create_and_add_mesh_with_cell_data(bodyNode,decomp_poly)

Expand Down
2 changes: 1 addition & 1 deletion project/examples/7_classic_platformer/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ data_uv_maps = Array[PackedInt32Array]([PackedInt32Array(0, 1, 3), PackedInt32Ar
[node name="Water" type="QSoftBodyNode" parent="."]
rigidity = 0.01
use_custom_gravity = true
position = Vector2(754, 785)
position = Vector2(656, 496)

[node name="QMeshAdvancedNode" type="QMeshAdvancedNode" parent="Water"]
disable_polygon_for_collisions = true
Expand Down
Binary file added src/QuarkPhysics/extensions/qplatformerbody.os
Binary file not shown.
Binary file added src/QuarkPhysics/extensions/qspatialhashing.os
Binary file not shown.
Binary file added src/QuarkPhysics/json/json.os
Binary file not shown.
Binary file added src/QuarkPhysics/qaabb.os
Binary file not shown.
Binary file added src/QuarkPhysics/qareabody.os
Binary file not shown.
Binary file added src/QuarkPhysics/qbody.os
Binary file not shown.
Binary file added src/QuarkPhysics/qbroadphase.os
Binary file not shown.
Binary file added src/QuarkPhysics/qcollision.os
Binary file not shown.
Binary file added src/QuarkPhysics/qgizmos.os
Binary file not shown.
Binary file added src/QuarkPhysics/qjoint.os
Binary file not shown.
Binary file added src/QuarkPhysics/qmanifold.os
Binary file not shown.
Binary file added src/QuarkPhysics/qmesh.os
Binary file not shown.
Binary file added src/QuarkPhysics/qobjectpool.os
Binary file not shown.
Binary file added src/QuarkPhysics/qparticle.os
Binary file not shown.
Binary file added src/QuarkPhysics/qraycast.os
Binary file not shown.
Binary file added src/QuarkPhysics/qrigidbody.os
Binary file not shown.
Binary file added src/QuarkPhysics/qsoftbody.os
Binary file not shown.
Binary file added src/QuarkPhysics/qspring.os
Binary file not shown.
Binary file added src/QuarkPhysics/quarkphysics.os
Binary file not shown.
Binary file added src/QuarkPhysics/qvector.os
Binary file not shown.
Binary file added src/QuarkPhysics/qworld.os
Binary file not shown.
Binary file added src/qareabody_node.os
Binary file not shown.
Binary file added src/qbody_node.os
Binary file not shown.
Binary file added src/qjoint_object.os
Binary file not shown.
Binary file added src/qmesh_advanced_node.os
Binary file not shown.
Binary file added src/qmesh_circle_node.os
Binary file not shown.
16 changes: 13 additions & 3 deletions src/qmesh_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void QMeshNode::debug_render_in_runtime()
QDebugColors colors;

bool isOwnerBodyRigid=false;

Vector2 node_scale_inverse_factor=Vector2(1/get_global_scale().x,1/get_global_scale().y);
//Drawing springs
if(ownerBodyNode!=nullptr){
if(ownerBodyNode->bodyObject->GetBodyType()!=QBody::BodyTypes::RIGID){
Expand All @@ -340,6 +340,8 @@ void QMeshNode::debug_render_in_runtime()
QVector qpb=spring->GetParticleB()->GetGlobalPosition();
Vector2 pA=( Vector2(qpa.x,qpa.y)-get_global_position() ).rotated(-get_global_rotation() );
Vector2 pB=( Vector2(qpb.x,qpb.y)-get_global_position() ).rotated(-get_global_rotation() );
pA*=node_scale_inverse_factor;
pB*=node_scale_inverse_factor;
rs->canvas_item_add_line(debugRenderInstance,pA,pB,springColor);

}
Expand All @@ -363,6 +365,8 @@ void QMeshNode::debug_render_in_runtime()
QVector qpn=meshObject->GetParticleFromPolygon((n+1)%meshObject->GetPolygonParticleCount())->GetGlobalPosition();
Vector2 p=(Vector2(qp.x,qp.y)-get_global_position() ).rotated(-get_global_rotation() ) ;
Vector2 pn=( Vector2(qpn.x,qpn.y)-get_global_position() ).rotated(-get_global_rotation() );
p*=node_scale_inverse_factor;
pn*=node_scale_inverse_factor;
rs->canvas_item_add_line(debugRenderInstance,p,pn,colliderColor);
}
}
Expand All @@ -371,6 +375,7 @@ void QMeshNode::debug_render_in_runtime()
QParticle *particle=meshObject->GetParticleAt(i);
Vector2 pos=Vector2( particle->GetGlobalPosition().x, particle->GetGlobalPosition().y )-get_global_position();
pos=pos.rotated(-get_global_rotation() );
pos*=node_scale_inverse_factor;
float radius=particle->GetRadius();
Color particleColor=colors.COLLIDER_PARTICLE;
if (particle->GetIsLazy()==true){
Expand Down Expand Up @@ -414,6 +419,8 @@ void QMeshNode::vector_render_in_runtime()
if(enableVectorRendering==false)
return;

Vector2 node_scale_inverse_factor=Vector2(1/get_global_scale().x,1/get_global_scale().y);

PackedColorArray fillColors;
fillColors.push_back(fillColor);
PackedColorArray strokeColors;
Expand All @@ -426,7 +433,8 @@ void QMeshNode::vector_render_in_runtime()
for(int n=0;n<polygonSize;n++){
QVector qpg=meshObject->GetParticleFromPolygon(n)->GetGlobalPosition();
QVector qpl=meshObject->GetParticleFromPolygon(n)->GetPosition();
Vector2 pg=(Vector2(qpg.x,qpg.y)-get_global_position() ).rotated(-get_global_rotation() );
Vector2 pg=(Vector2(qpg.x,qpg.y)-get_global_position() ).rotated(-get_global_rotation() );
pg*=node_scale_inverse_factor;
Vector2 pl=Vector2(qpl.x,qpl.y);
polygonPoints.push_back(pg );
polygonLocalPoints.push_back(pl );
Expand Down Expand Up @@ -657,7 +665,9 @@ QMesh::MeshData QMeshNode::convert_mesh_node_data_to_mesh_data()

QMesh::MeshData qData;
for(size_t i=0;i<dataParticlePositions.size();++i){
qData.particlePositions.push_back( QVector( dataParticlePositions[i].x, dataParticlePositions[i].y) );
Vector2 pos=dataParticlePositions[i];
pos*=get_global_scale();
qData.particlePositions.push_back( QVector( pos.x, pos.y) );
}

for(size_t i=0;i<dataParticlePositions.size();++i){
Expand Down
Binary file added src/qmesh_node.os
Binary file not shown.
Binary file added src/qmesh_polygon_node.os
Binary file not shown.
Binary file added src/qmesh_rect_node.os
Binary file not shown.
Binary file added src/qparticle_object.os
Binary file not shown.
Binary file added src/qplatformerbody_node.os
Binary file not shown.
Binary file added src/qraycast_object.os
Binary file not shown.
Binary file added src/qrigidbody_node.os
Binary file not shown.
Binary file added src/qsoftbody_node.os
Binary file not shown.
Binary file added src/qspring_object.os
Binary file not shown.
Binary file added src/qworld_node.os
Binary file not shown.
Binary file added src/register_types.os
Binary file not shown.

0 comments on commit 69aced6

Please sign in to comment.