Skip to content

Commit

Permalink
Added custom gravity feature
Browse files Browse the repository at this point in the history
  • Loading branch information
erayzesen committed Jan 13, 2025
1 parent e99b2e7 commit e630741
Show file tree
Hide file tree
Showing 45 changed files with 99 additions and 2 deletions.
Binary file modified .sconsign.dblite
Binary file not shown.
Binary file not shown.
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.
22 changes: 22 additions & 0 deletions src/QuarkPhysics/qbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ bool QBody::GetIntegratedVelocitiesEnabled() {
return enableIntegratedVelocities;
}

bool QBody::GetCustomGravityEnabled()
{
return enableCustomGravity;
}

QVector QBody::GetCustomGravity()
{
return customGravity;
}

QBody *QBody::SetVelocityLimit(float value)
{
velocityLimit=value;
Expand Down Expand Up @@ -125,6 +135,18 @@ QBody *QBody::SetIntegratedVelocitiesEnabled(bool value) {
return this;
}

QBody *QBody::SetCustomGravityEnabled(bool value)
{
enableCustomGravity=value;
return this;
}

QBody *QBody::SetCustomGravity(QVector value)
{
customGravity=value;
return this;
}

QBody *QBody::AddMesh(QMesh *mesh) {
_meshes.push_back(mesh);
mesh->ownerBody=this;
Expand Down
28 changes: 28 additions & 0 deletions src/QuarkPhysics/qbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class QBody{
bool enabled=true;
float velocityLimit=0.0f;
bool enableIntegratedVelocities=true;
bool enableCustomGravity=false;
QVector customGravity=QVector::Zero();

//Material Properties;

Expand Down Expand Up @@ -357,6 +359,16 @@ class QBody{
*/
bool GetIntegratedVelocitiesEnabled();

/**
* Returns whether a specific custom gravity value, defined using the SetCustomGravity() method, will be applied to the body instead of the gravity defined for the physics world.
*/
bool GetCustomGravityEnabled();

/*
Returns the gravity vector specifically defined for the body.
*/
QVector GetCustomGravity();



//General Set Methods
Expand Down Expand Up @@ -568,9 +580,25 @@ class QBody{

/**
* Sets whether the application of gravity and various velocity integrators necessary for the body's movement in the physics world is enabled. It is set to true by default. Typically, it is disabled for specific body objects that require manual control.
* @param value A value to set
* @return A pointer to the body itself.
*/
QBody *SetIntegratedVelocitiesEnabled(bool value);

/**
* Sets whether a specific custom gravity value, defined using the SetCustomGravity() method, will be applied to the body instead of the gravity defined for the physics world.
* @param value A value to set
* @return A pointer to the body itself.
*/
QBody *SetCustomGravityEnabled(bool value);

/**
* Sets whether a specific custom gravity value, defined using the SetCustomGravity() method, will be applied to the body instead of the gravity defined for the physics world.
* @param value A value to set
* @return A pointer to the body itself.
*/
QBody *SetCustomGravity(QVector value);


//Mesh Methods
/** Adds a mesh to the body.
Expand Down
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.
8 changes: 7 additions & 1 deletion src/QuarkPhysics/qrigidbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ void QRigidBody::Update()
//Verlet Integration
if(isKinematic==false && enableIntegratedVelocities==true){
position+=vel-(vel*airFriction);
position+=(world->GetGravity()*mass*ts);

if(enableCustomGravity){
position+=(customGravity*mass*ts);
}else{
position+=(world->GetGravity()*mass*ts);
}

rotation+=rotVel-(rotVel*airFriction);
}
//Position Forces
Expand Down
Binary file added src/QuarkPhysics/qrigidbody.os
Binary file not shown.
6 changes: 5 additions & 1 deletion src/QuarkPhysics/qsoftbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ void QSoftBody::Update()
if(enableIntegratedVelocities==true ){
particle->ApplyForce(vel-(vel*airFriction) );
if(!(particle->GetIsInternal()==true && enablePassivationOfInternalSprings==true) ){
particle->ApplyForce(mass*world->GetGravity()*ts);
if (enableCustomGravity){
particle->ApplyForce(mass*customGravity*ts);
}else{
particle->ApplyForce(mass*world->GetGravity()*ts);
}
}
}
particle->ApplyForce(particle->GetForce());
Expand Down
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.
29 changes: 29 additions & 0 deletions src/qbody_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void QBodyNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_enabled"),&QBodyNode::get_enabled );
ClassDB::bind_method(D_METHOD("get_velocity_limit"),&QBodyNode::get_velocity_limit );
ClassDB::bind_method(D_METHOD("get_integrated_velocities_enabled"),&QBodyNode::get_integrated_velocities_enabled );
ClassDB::bind_method(D_METHOD("get_custom_gravity_enabled"),&QBodyNode::get_custom_gravity_enabled );
ClassDB::bind_method(D_METHOD("get_custom_gravity"),&QBodyNode::get_custom_gravity );

//Set
ClassDB::bind_method(D_METHOD("set_body_position","value","with_previous_position"),&QBodyNode::set_body_position );
Expand All @@ -117,6 +119,8 @@ void QBodyNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled","value"),&QBodyNode::set_enabled );
ClassDB::bind_method(D_METHOD("set_velocity_limit","value"),&QBodyNode::set_velocity_limit );
ClassDB::bind_method(D_METHOD("set_integrated_velocities_enabled","value"),&QBodyNode::set_integrated_velocities_enabled );
ClassDB::bind_method(D_METHOD("set_custom_gravity_enabled","value"),&QBodyNode::set_custom_gravity_enabled );
ClassDB::bind_method(D_METHOD("set_custom_gravity","value"),&QBodyNode::set_custom_gravity );
ClassDB::bind_method(D_METHOD("wake_up"),&QBodyNode::wake_up );

ClassDB::bind_method(D_METHOD("add_mesh_node","mesh_node"),&QBodyNode::add_mesh_node );
Expand All @@ -131,6 +135,8 @@ void QBodyNode::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static"),"set_mode","get_mode" );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "can_sleep"),"set_can_sleep","get_can_sleep" );
ADD_PROPERTY( PropertyInfo(Variant::FLOAT, "velocity_limit"),"set_velocity_limit","get_velocity_limit" );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "use_custom_gravity"),"set_custom_gravity_enabled","get_custom_gravity_enabled" );
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2, "custom_gravity"),"set_custom_gravity","get_custom_gravity" );

ADD_GROUP("Physics Properties","");
ADD_PROPERTY( PropertyInfo(Variant::FLOAT, "mass"),"set_mass","get_mass" );
Expand Down Expand Up @@ -283,6 +289,17 @@ bool QBodyNode::get_integrated_velocities_enabled() {
return bodyObject->GetIntegratedVelocitiesEnabled();
}

bool QBodyNode::get_custom_gravity_enabled()
{
return bodyObject->GetCustomGravityEnabled();
}

Vector2 QBodyNode::get_custom_gravity()
{
QVector customGravity=bodyObject->GetCustomGravity();
return Vector2(customGravity.x,customGravity.y);
}

//SET METHODS

QBodyNode *QBodyNode::set_body_position(Vector2 value, bool with_previous_position) {
Expand Down Expand Up @@ -410,6 +427,18 @@ QBodyNode *QBodyNode::set_integrated_velocities_enabled(bool value) {
return this;
}

QBodyNode *QBodyNode::set_custom_gravity_enabled(bool value)
{
bodyObject->SetCustomGravityEnabled(value);
return this;
}

QBodyNode *QBodyNode::set_custom_gravity(Vector2 value)
{
bodyObject->SetCustomGravity(QVector(value.x,value.y) );
return this;
}

QBodyNode *QBodyNode::wake_up() {
bodyObject->WakeUp();
return this;
Expand Down
8 changes: 8 additions & 0 deletions src/qbody_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class QBodyNode: public Node2D{

bool get_integrated_velocities_enabled();

bool get_custom_gravity_enabled();

Vector2 get_custom_gravity();

//Set Methods

QBodyNode *set_body_position(Vector2 value,bool with_previous_position=true);
Expand Down Expand Up @@ -186,6 +190,10 @@ class QBodyNode: public Node2D{

QBodyNode *set_integrated_velocities_enabled(bool value);

QBodyNode *set_custom_gravity_enabled(bool value);

QBodyNode *set_custom_gravity(Vector2 value);

//Sleeping

QBodyNode *wake_up();
Expand Down
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.
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 e630741

Please sign in to comment.