当前位置: 首页>>代码示例>>C++>>正文


C++ Body2DSW::get_linear_velocity方法代码示例

本文整理汇总了C++中Body2DSW::get_linear_velocity方法的典型用法代码示例。如果您正苦于以下问题:C++ Body2DSW::get_linear_velocity方法的具体用法?C++ Body2DSW::get_linear_velocity怎么用?C++ Body2DSW::get_linear_velocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Body2DSW的用法示例。


在下文中一共展示了Body2DSW::get_linear_velocity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) {

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

	Vector2 v = body->get_linear_velocity();
	Vector2 axis = p_axis_velocity.normalized();
	v -= axis * axis.dot(v);
	v += p_axis_velocity;
	body->set_linear_velocity(v);
	body->wakeup();
};
开发者ID:MattUV,项目名称:godot,代码行数:12,代码来源:physics_2d_server_sw.cpp

示例2: MAX


//.........这里部分代码省略.........

				Shape2DSW *body_shape = p_body->get_shape(j);

				if (body_shape->get_type() != Physics2DServer::SHAPE_RAY)
					continue;

				Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j);

				for (int i = 0; i < amount; i++) {

					const CollisionObject2DSW *col_obj = intersection_query_results[i];
					int shape_idx = intersection_query_subindex_results[i];

					cbk.amount = 0;
					cbk.ptr = sr;
					cbk.invalid_by_dir = 0;

					if (CollisionObject2DSW::TYPE_BODY == col_obj->get_type()) {
						const Body2DSW *b = static_cast<const Body2DSW *>(col_obj);
						if (p_infinite_inertia && Physics2DServer::BODY_MODE_STATIC != b->get_mode() && Physics2DServer::BODY_MODE_KINEMATIC != b->get_mode()) {
							continue;
						}
					}

					if (col_obj->is_shape_set_as_one_way_collision(shape_idx)) {

						cbk.valid_dir = body_shape_xform.get_axis(1).normalized();
						cbk.valid_depth = p_margin; //only valid depth is the collision margin
						cbk.invalid_by_dir = 0;

					} else {
						cbk.valid_dir = Vector2();
						cbk.valid_depth = 0;
						cbk.invalid_by_dir = 0;
					}

					Shape2DSW *against_shape = col_obj->get_shape(shape_idx);
					if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), cbkres, cbkptr, NULL, p_margin)) {
						if (cbk.amount > 0) {
							collided = true;
						}

						if (ray_index < p_result_max) {
							Physics2DServer::SeparationResult &result = r_results[ray_index];

							for (int k = 0; k < cbk.amount; k++) {
								Vector2 a = sr[k * 2 + 0];
								Vector2 b = sr[k * 2 + 1];

								recover_motion += (b - a) * 0.4;

								float depth = a.distance_to(b);
								if (depth > result.collision_depth) {

									result.collision_depth = depth;
									result.collision_point = b;
									result.collision_normal = (b - a).normalized();
									result.collision_local_shape = shape_idx;
									result.collider = col_obj->get_self();
									result.collider_id = col_obj->get_instance_id();
									result.collider_metadata = col_obj->get_shape_metadata(shape_idx);
									if (col_obj->get_type() == CollisionObject2DSW::TYPE_BODY) {
										Body2DSW *body = (Body2DSW *)col_obj;

										Vector2 rel_vec = b - body->get_transform().get_origin();
										result.collider_velocity = Vector2(-body->get_angular_velocity() * rel_vec.y, body->get_angular_velocity() * rel_vec.x) + body->get_linear_velocity();
									}
								}
							}
						}
					}
				}

				ray_index++;
			}

			rays_found = MAX(ray_index, rays_found);

			if (!collided || recover_motion == Vector2()) {
				break;
			}

			body_transform.elements[2] += recover_motion;
			body_aabb.position += recover_motion;

			recover_attempts--;
		} while (recover_attempts);
	}

	//optimize results (remove non colliding)
	for (int i = 0; i < rays_found; i++) {
		if (r_results[i].collision_depth == 0) {
			rays_found--;
			SWAP(r_results[i], r_results[rays_found]);
		}
	}

	r_recover_motion = body_transform.elements[2] - p_transform.elements[2];
	return rays_found;
}
开发者ID:RandomShaper,项目名称:godot,代码行数:101,代码来源:space_2d_sw.cpp


注:本文中的Body2DSW::get_linear_velocity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。