Example #1
0
bool CollisionObject2D::_set(const StringName& p_name, const Variant& p_value) {
	String name=p_name;

	if (name=="shape_count") {

		shapes.resize(p_value);
		_update_shapes();
		_change_notify();

	} else if (name.begins_with("shapes/")) {

		int idx=name.get_slice("/",1).to_int();
		String what=name.get_slice("/",2);
		if (what=="shape")
			set_shape(idx,RefPtr(p_value));
		else if (what=="transform")
			set_shape_transform(idx,p_value);
		else if (what=="trigger")
			set_shape_as_trigger(idx,p_value);
	} else
		return false;

	return true;


}
void PhysicsServerSW::step(real_t p_step) {

#ifndef _3D_DISABLED

	if (!active)
		return;

	_update_shapes();

	doing_sync = false;

	last_step = p_step;
	PhysicsDirectBodyStateSW::singleton->step = p_step;

	island_count = 0;
	active_objects = 0;
	collision_pairs = 0;
	for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) {

		stepper->step((SpaceSW *)E->get(), p_step, iterations);
		island_count += E->get()->get_island_count();
		active_objects += E->get()->get_active_objects();
		collision_pairs += E->get()->get_collision_pairs();
	}
#endif
}
Example #3
0
void CollisionObject2DSW::_set_space(Space2DSW *p_space) {

    if (space) {

        space->remove_object(this);

        for(int i=0; i<shapes.size(); i++) {

            Shape &s=shapes[i];
            if (s.bpid) {
                space->get_broadphase()->remove(s.bpid);
                s.bpid=0;
            }
        }

    }

    space=p_space;

    if (space) {

        space->add_object(this);
        _update_shapes();
    }

}
Example #4
0
void CollisionObject2D::set_shape_transform(int p_shape_idx, const Matrix32& p_transform) {

	ERR_FAIL_INDEX(p_shape_idx,shapes.size());
	shapes[p_shape_idx].xform=p_transform;

	_update_shapes();
}
Example #5
0
void CollisionObject2D::remove_shape(int p_shape_idx) {

	ERR_FAIL_INDEX(p_shape_idx, shapes.size());
	shapes.remove(p_shape_idx);

	_update_shapes();
}
Example #6
0
void CollisionObject::add_shape(const Ref<Shape> &p_shape, const Transform &p_transform) {

	ShapeData sdata;
	sdata.shape = p_shape;
	sdata.xform = p_transform;
	shapes.push_back(sdata);
	_update_shapes();
}
Example #7
0
void CollisionObject2DSW::set_shape_transform(int p_index,const Matrix32& p_transform) {

    ERR_FAIL_INDEX(p_index,shapes.size());

    shapes[p_index].xform=p_transform;
    shapes[p_index].xform_inv=p_transform.affine_inverse();
    _update_shapes();
    _shapes_changed();
}
void PhysicsServerSW::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
	BodySW *body = body_owner.get(p_body);
	ERR_FAIL_COND(!body);

	_update_shapes();

	body->apply_central_impulse(p_impulse);
	body->wakeup();
}
Example #9
0
void CollisionObject2DSW::set_shape(int p_index, Shape2DSW *p_shape) {

	ERR_FAIL_INDEX(p_index, shapes.size());
	shapes[p_index].shape->remove_owner(this);
	shapes[p_index].shape = p_shape;

	p_shape->add_owner(this);
	_update_shapes();
	_shapes_changed();
}
Example #10
0
void CollisionObject2D::add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p_transform) {

	ShapeData sdata;
	sdata.shape=p_shape;
	sdata.xform=p_transform;
	sdata.trigger=false;
	shapes.push_back(sdata);
	_update_shapes();

}
Example #11
0
bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, MotionResult *r_result) {

	BodySW *body = body_owner.get(p_body);
	ERR_FAIL_COND_V(!body, false);
	ERR_FAIL_COND_V(!body->get_space(), false);
	ERR_FAIL_COND_V(body->get_space()->is_locked(), false);

	_update_shapes();

	return body->get_space()->test_body_motion(body, p_from, p_motion, body->get_kinematic_margin(), r_result);
}
Example #12
0
void CollisionObject2D::_update_shapes_from_children() {

	shapes.clear();
	for (int i = 0; i < get_child_count(); i++) {

		Node *n = get_child(i);
		n->call("_add_to_collision_object", this);
	}

	_update_shapes();
}
Example #13
0
int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) {

	BodySW *body = body_owner.get(p_body);
	ERR_FAIL_COND_V(!body, false);
	ERR_FAIL_COND_V(!body->get_space(), false);
	ERR_FAIL_COND_V(body->get_space()->is_locked(), false);

	_update_shapes();

	return body->get_space()->test_body_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin);
}
Example #14
0
void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Matrix32 &p_transform) {

	Shape s;
	s.shape = p_shape;
	s.xform = p_transform;
	s.xform_inv = s.xform.affine_inverse();
	s.bpid = 0; //needs update
	s.trigger = false;
	shapes.push_back(s);
	p_shape->add_owner(this);
	_update_shapes();
	_shapes_changed();
}
Example #15
0
void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {

	BodySW *body = body_owner.get(p_body);
	ERR_FAIL_COND(!body);

	_update_shapes();

	Vector3 v = body->get_linear_velocity();
	Vector3 axis = p_axis_velocity.normalized();
	v -= axis * axis.dot(v);
	v += p_axis_velocity;
	body->set_linear_velocity(v);
	body->wakeup();
};
Example #16
0
void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_transform) {

	Shape s;
	s.shape = p_shape;
	s.xform = p_transform;
	s.xform_inv = s.xform.affine_inverse();
	s.bpid = 0; //needs update
	s.disabled = false;
	s.one_way_collision = false;
	shapes.push_back(s);
	p_shape->add_owner(this);
	_update_shapes();
	_shapes_changed();
}
Example #17
0
void PhysicsServerSW::free(RID p_rid) {

	_update_shapes(); //just in case

	if (shape_owner.owns(p_rid)) {

		ShapeSW *shape = shape_owner.get(p_rid);

		while (shape->get_owners().size()) {
			ShapeOwnerSW *so = shape->get_owners().front()->key();
			so->remove_shape(shape);
		}

		shape_owner.free(p_rid);
		memdelete(shape);
	} else if (body_owner.owns(p_rid)) {

		BodySW *body = body_owner.get(p_rid);

		/*
		if (body->get_state_query())
			_clear_query(body->get_state_query());

		if (body->get_direct_state_query())
			_clear_query(body->get_direct_state_query());
		*/

		body->set_space(NULL);

		while (body->get_shape_count()) {

			body->remove_shape(0);
		}

		body_owner.free(p_rid);
		memdelete(body);

	} else if (area_owner.owns(p_rid)) {

		AreaSW *area = area_owner.get(p_rid);

		/*
		if (area->get_monitor_query())
			_clear_query(area->get_monitor_query());
		*/

		area->set_space(NULL);

		while (area->get_shape_count()) {

			area->remove_shape(0);
		}

		area_owner.free(p_rid);
		memdelete(area);
	} else if (space_owner.owns(p_rid)) {

		SpaceSW *space = space_owner.get(p_rid);

		while (space->get_objects().size()) {
			CollisionObjectSW *co = (CollisionObjectSW *)space->get_objects().front()->get();
			co->set_space(NULL);
		}

		active_spaces.erase(space);
		free(space->get_default_area()->get_self());
		free(space->get_static_global_body());

		space_owner.free(p_rid);
		memdelete(space);
	} else if (joint_owner.owns(p_rid)) {

		JointSW *joint = joint_owner.get(p_rid);

		for (int i = 0; i < joint->get_body_count(); i++) {

			joint->get_body_ptr()[i]->remove_constraint(joint);
		}
		joint_owner.free(p_rid);
		memdelete(joint);

	} else {

		ERR_EXPLAIN("Invalid ID");
		ERR_FAIL();
	}
};
Example #18
0
void CollisionObject2D::clear_shapes() {

	shapes.clear();

	_update_shapes();
}
Example #19
0
void CollisionObject2DSW::_shape_changed() {

    _update_shapes();
    _shapes_changed();
}
Example #20
0
void CollisionObject2D::set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape) {

	ERR_FAIL_INDEX(p_shape_idx,shapes.size());
	shapes[p_shape_idx].shape=p_shape;
	_update_shapes();
}