Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D()); if (tile_map[p_id].shapes_data.size() > p_shape_id) return tile_map[p_id].shapes_data[p_shape_id].shape_transform; return Transform2D(); }
Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const { if (p_parent == this) return Transform2D(); Node2D *parent_2d = Object::cast_to<Node2D>(get_parent()); ERR_FAIL_COND_V(!parent_2d, Transform2D()); if (p_parent == parent_2d) return get_transform(); else return parent_2d->get_relative_transform_to_parent(p_parent) * get_transform(); }
void RenderVector(int frameNumber) { CanvasT *canvas = R_("Canvas"); PointT *toDraw = R_("TriangleToDraw"); MatrixStack2D *ms = R_("ms2d"); float s = sin(frameNumber * 3.14159265f / 22.5f); float c = cos(frameNumber * 3.14159265f / 45.0f); StackReset(ms); PushTranslation2D(ms, -1.5f, -1.5f); PushScaling2D(ms, 20.0f + 10.0f * s, 20.0f + 10.0f * s); PushRotation2D(ms, (float)(frameNumber * -3)); PushTranslation2D(ms, (float)(WIDTH/2) + c * (WIDTH/4), (float)(HEIGHT/2)); Transform2D(R_("CrossToDraw"), R_("Cross"), 12, GetMatrix2D(ms, 0)); if (effect == 0) { CanvasFill(canvas, 0); DrawPolyLine(canvas, R_("CrossToDraw"), 12, TRUE); } StackReset(ms); PushTranslation2D(ms, 5.0f, 10.0f); PushScaling2D(ms, 2.5f, 2.5f); PushRotation2D(ms, (float)(frameNumber*5*c)); PushTranslation2D(ms, WIDTH/2 + c * 50, HEIGHT/2 + s * 20); Transform2D(R_("TriangleToDraw"), R_("Triangle"), 3, GetMatrix2D(ms, 0)); frameNumber &= 255; if (frameNumber < 128) canvas->fg_col = frameNumber * 2; else canvas->fg_col = (255 - frameNumber) * 2; if (effect == 1) { DrawTriangle(canvas, toDraw[0].x, toDraw[0].y, toDraw[1].x, toDraw[1].y, toDraw[2].x, toDraw[2].y); } if (effect == 2) { DrawEllipse(canvas, toDraw[1].x, toDraw[1].y, 30 + c * 15, 30 + s * 15); } }
static void Render(int frameNumber) { PointT *toDraw = triangleToDraw; float s = sin(frameNumber * 3.14159265f / 22.5f); float c = cos(frameNumber * 3.14159265f / 45.0f); StackReset(ms); PushTranslation2D(ms, -1.5f, -1.5f); PushScaling2D(ms, 20.0f + 10.0f * s, 20.0f + 10.0f * s); PushRotation2D(ms, (float)(frameNumber * -3)); PushTranslation2D(ms, (float)(WIDTH/2) + c * (WIDTH/4), (float)(HEIGHT/2)); Transform2D(crossToDraw, cross, 12, GetMatrix2D(ms, 0)); if (effect == 0) { PixBufClear(canvas); DrawPolyLine(canvas, crossToDraw, 12, TRUE); } StackReset(ms); PushTranslation2D(ms, 5.0f, 10.0f); PushScaling2D(ms, 2.5f, 2.5f); PushRotation2D(ms, (float)(frameNumber*5*c)); PushTranslation2D(ms, WIDTH/2 + c * 50, HEIGHT/2 + s * 20); Transform2D(triangleToDraw, triangle, 3, GetMatrix2D(ms, 0)); frameNumber &= 255; if (frameNumber < 128) canvas->fgColor = frameNumber * 2; else canvas->fgColor = (255 - frameNumber) * 2; if (effect == 1) { TriPoint p1 = { toDraw[0].x, toDraw[0].y }; TriPoint p2 = { toDraw[1].x, toDraw[1].y }; TriPoint p3 = { toDraw[2].x, toDraw[2].y }; DrawTriangle(canvas, &p1, &p2, &p3); } if (effect == 2) { DrawEllipse(canvas, toDraw[1].x, toDraw[1].y, 30 + c * 15, 30 + s * 15); } c2p1x1_8_c5_bm(canvas->data, GetCurrentBitMap(), WIDTH, HEIGHT, 0, 0); }
void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin) { const Vector2 *x_axis = (const Vector2 *)p_x_axis; const Vector2 *y_axis = (const Vector2 *)p_y_axis; const Vector2 *origin = (const Vector2 *)p_origin; Transform2D *dest = (Transform2D *)r_dest; *dest = Transform2D(x_axis->x, x_axis->y, y_axis->x, y_axis->y, origin->x, origin->y); }
Entity::Ptr DefinePlayer(const Entity::Ptr& super) { auto& texture = super->AddProperty("texture", super->GetGame().GetResourceManager().GetResource<Texture>("orb")); auto& transform = super->AddProperty("transform", Transform2D()); auto& rectangle = super->AddProperty("rectangle", Rectangle()); transform.Scale = glm::vec2(texture.GetWidth() , texture.GetHeight()); // Sync transform and rectangle super->AddComponent([&](float delta, Entity& parent) { rectangle.Rect.x = transform.Position.x; rectangle.Rect.y = transform.Position.y; rectangle.Rect.w = transform.Scale.x; rectangle.Rect.h = transform.Scale.y; }); // Sprite renderer super->AddComponent([&](float delta, Entity& parent) { SpriteRenderer::Draw(texture, transform.Position, transform.Rotation, transform.Scale, 0); }); // Update position from input super->AddComponent([&](float delta, Entity& parent) { int x, y; SDL_GetMouseState(&x, &y); transform.Position = glm::vec2(x, y); }); return super; }
void RenderCircle(Shader *sh, Primitive prim, int segments, float radius) { assert(segments >= 3); auto &vbo = circlevbos[segments]; if (!vbo) { auto vbuf = new float3[segments]; float step = PI * 2 / segments; for (int i = 0; i < segments; i++) { // + 1 to reduce "aliasing" from exact 0 / 90 degrees points vbuf[i] = float3(sinf(i * step + 1), cosf(i * step + 1), 0); } vbo = GenBO(GL_ARRAY_BUFFER, sizeof(float3), segments, vbuf); delete[] vbuf; } Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]() { sh->Set(); RenderArray(prim, segments, segments, "P", sizeof(float3), vbo); }); }
void Body2DSW::integrate_velocities(real_t p_step) { if (mode == Physics2DServer::BODY_MODE_STATIC) return; if (fi_callback) get_space()->body_add_to_state_query_list(&direct_state_query_list); if (mode == Physics2DServer::BODY_MODE_KINEMATIC) { _set_transform(new_transform, false); _set_inv_transform(new_transform.affine_inverse()); if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0) set_active(false); //stopped moving, deactivate return; } real_t total_angular_velocity = angular_velocity + biased_angular_velocity; Vector2 total_linear_velocity = linear_velocity + biased_linear_velocity; real_t angle = get_transform().get_rotation() + total_angular_velocity * p_step; Vector2 pos = get_transform().get_origin() + total_linear_velocity * p_step; _set_transform(Transform2D(angle, pos), continuous_cd_mode == Physics2DServer::CCD_MODE_DISABLED); _set_inv_transform(get_transform().inverse()); if (continuous_cd_mode != Physics2DServer::CCD_MODE_DISABLED) new_transform = get_transform(); //_update_inertia_tensor(); }
Transform2D& Transform2DComponentManager::getTransform(Entity entity) { if(entity_transform_map.find(entity) == entity_transform_map.end()) { entity_transform_map[entity] = Transform2D(); } return entity_transform_map[entity]; }
Transform2D Physics2DServerSW::area_get_transform(RID p_area) const { Area2DSW *area = area_owner.get(p_area); ERR_FAIL_COND_V(!area, Transform2D()); return area->get_transform(); };
Transform2D Physics2DServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) const { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, Transform2D()); return body->get_shape_transform(p_shape_idx); }
Transform2D CanvasItem::get_canvas_transform() const { ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); if (canvas_layer) return canvas_layer->get_transform(); else if (Object::cast_to<CanvasItem>(get_parent())) return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform(); else return get_viewport()->get_canvas_transform(); }
Transform2D CanvasItem::get_viewport_transform() const { ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); if (canvas_layer) { if (get_viewport()) { return get_viewport()->get_final_transform() * canvas_layer->get_transform(); } else { return canvas_layer->get_transform(); } } else { return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform(); } }
Transform2D Transform2D::operator * (const Transform2D& other) const { float x = scale_.x_ * other.position_.x_; float y = scale_.y_ * other.position_.y_; float s = Sin(angle_); float c = Cos(angle_); Vector2 position; position.x_ = (x * c) - (y * s); position.y_ = (x * s) + (y * c); position = position_ + position; float angle = angle_ + other.angle_; Vector2 scale = scale_ * other.scale_; return Transform2D(position, angle, scale); }
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { ERR_FAIL_COND(!tile_map.has(p_id)); Vector<ShapeData> shapes_data; Transform2D default_transform = tile_get_shape_transform(p_id, 0); bool default_one_way = tile_get_shape_one_way(p_id, 0); for (int i = 0; i < p_shapes.size(); i++) { ShapeData s = ShapeData(); if (p_shapes[i].get_type() == Variant::OBJECT) { Ref<Shape2D> shape = p_shapes[i]; if (shape.is_null()) continue; s.shape = shape; s.shape_transform = default_transform; s.one_way_collision = default_one_way; } else if (p_shapes[i].get_type() == Variant::DICTIONARY) { Dictionary d = p_shapes[i]; if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT) s.shape = d["shape"]; else continue; if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) s.shape_transform = d["shape_transform"]; else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]); else s.shape_transform = default_transform; if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) s.one_way_collision = d["one_way"]; else s.one_way_collision = default_one_way; } else { ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes"); ERR_CONTINUE(true); } shapes_data.push_back(s); } tile_map[p_id].shapes_data = shapes_data; }
void RenderOpenCircle(Shader *sh, int segments, float radius, float thickness) { assert(segments >= 3); auto vbo_type = make_pair(segments, thickness); auto &vibo = opencirclevbos[vbo_type]; auto nverts = segments * 2; auto nindices = segments * 6; if (!vibo.first) { auto vbuf = new float3[nverts]; auto ibuf = new int[nindices]; float step = PI * 2 / segments; float inner = 1 - thickness; for (int i = 0; i < segments; i++) { // + 1 to reduce "aliasing" from exact 0 / 90 degrees points float x = sinf(i * step + 1); float y = cosf(i * step + 1); vbuf[i * 2 + 0] = float3(x, y, 0); vbuf[i * 2 + 1] = float3(x * inner, y * inner, 0); ibuf[i * 6 + 0] = i * 2 + 0; ibuf[i * 6 + 1] = ((i + 1) * 2 + 0) % nverts; ibuf[i * 6 + 2] = i * 2 + 1; ibuf[i * 6 + 3] = i * 2 + 1; ibuf[i * 6 + 4] = ((i + 1) * 2 + 1) % nverts; ibuf[i * 6 + 5] = ((i + 1) * 2 + 0) % nverts; } vibo.first = GenBO(GL_ARRAY_BUFFER, sizeof(float3), nverts, vbuf); vibo.second = GenBO(GL_ELEMENT_ARRAY_BUFFER, sizeof(int), nindices, ibuf); delete[] vbuf; delete[] ibuf; } Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]() { sh->Set(); RenderArray(PRIM_TRIS, nindices, nverts, "P", sizeof(float3), vibo.first, vibo.second); }); }
void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, const Vector2 &p_to, AnimationNodeStateMachineTransition::SwitchMode p_mode, bool p_enabled, bool p_selected, bool p_travel, bool p_auto_advance) { Color linecolor = get_color("font_color", "Label"); Color icon_color(1, 1, 1); Color accent = get_color("accent_color", "Editor"); if (!p_enabled) { linecolor.a *= 0.2; icon_color.a *= 0.2; accent.a *= 0.6; } Ref<Texture> icons[6] = { get_icon("TransitionImmediateBig", "EditorIcons"), get_icon("TransitionSyncBig", "EditorIcons"), get_icon("TransitionEndBig", "EditorIcons"), get_icon("TransitionImmediateAutoBig", "EditorIcons"), get_icon("TransitionSyncAutoBig", "EditorIcons"), get_icon("TransitionEndAutoBig", "EditorIcons") }; if (p_selected) { state_machine_draw->draw_line(p_from, p_to, accent, 6, true); } if (p_travel) { linecolor = accent; linecolor.set_hsv(1.0, linecolor.get_s(), linecolor.get_v()); } state_machine_draw->draw_line(p_from, p_to, linecolor, 2, true); Ref<Texture> icon = icons[p_mode + (p_auto_advance ? 3 : 0)]; Transform2D xf; xf.elements[0] = (p_to - p_from).normalized(); xf.elements[1] = xf.elements[0].tangent(); xf.elements[2] = (p_from + p_to) * 0.5 - xf.elements[1] * icon->get_height() * 0.5 - xf.elements[0] * icon->get_height() * 0.5; state_machine_draw->draw_set_transform_matrix(xf); state_machine_draw->draw_texture(icon, Vector2(), icon_color); state_machine_draw->draw_set_transform_matrix(Transform2D()); }
void _add_concave(const Vector<Vector2> &p_points, const Transform2D &p_xform = Transform2D()) { Physics2DServer *ps = Physics2DServer::get_singleton(); VisualServer *vs = VisualServer::get_singleton(); RID concave = ps->concave_polygon_shape_create(); ps->shape_set_data(concave, p_points); RID body = ps->body_create(); ps->body_set_mode(body, Physics2DServer::BODY_MODE_STATIC); ps->body_set_space(body, space); ps->body_add_shape(body, concave); ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform); RID sprite = vs->canvas_item_create(); vs->canvas_item_set_parent(sprite, canvas); vs->canvas_item_set_transform(sprite, p_xform); for (int i = 0; i < p_points.size(); i += 2) { vs->canvas_item_add_line(sprite, p_points[i], p_points[i + 1], Color(0, 0, 0), 2); } }
void CurveEditor::update_view_transform() { Vector2 control_size = get_size(); const real_t margin = 24; float min_y = 0; float max_y = 1; if (_curve_ref.is_valid()) { min_y = _curve_ref->get_min_value(); max_y = _curve_ref->get_max_value(); } Rect2 world_rect = Rect2(Curve::MIN_X, min_y, Curve::MAX_X, max_y - min_y); Vector2 wm = Vector2(margin, margin) / control_size; wm.y *= (max_y - min_y); world_rect.position -= wm; world_rect.size += 2.0 * wm; _world_to_view = Transform2D(); _world_to_view.translate(-world_rect.position - Vector2(0, world_rect.size.y)); _world_to_view.scale(Vector2(control_size.x, -control_size.y) / world_rect.size); }
void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) { const Vector2 *pos = (const Vector2 *)p_pos; Transform2D *dest = (Transform2D *)r_dest; *dest = Transform2D(p_rot, *pos); }
void Physics2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("shape_create", "type"), &Physics2DServer::shape_create); ClassDB::bind_method(D_METHOD("shape_set_data", "shape", "data"), &Physics2DServer::shape_set_data); ClassDB::bind_method(D_METHOD("shape_get_type", "shape"), &Physics2DServer::shape_get_type); ClassDB::bind_method(D_METHOD("shape_get_data", "shape"), &Physics2DServer::shape_get_data); ClassDB::bind_method(D_METHOD("space_create"), &Physics2DServer::space_create); ClassDB::bind_method(D_METHOD("space_set_active", "space", "active"), &Physics2DServer::space_set_active); ClassDB::bind_method(D_METHOD("space_is_active", "space"), &Physics2DServer::space_is_active); ClassDB::bind_method(D_METHOD("space_set_param", "space", "param", "value"), &Physics2DServer::space_set_param); ClassDB::bind_method(D_METHOD("space_get_param", "space", "param"), &Physics2DServer::space_get_param); ClassDB::bind_method(D_METHOD("space_get_direct_state", "space"), &Physics2DServer::space_get_direct_state); ClassDB::bind_method(D_METHOD("area_create"), &Physics2DServer::area_create); ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &Physics2DServer::area_set_space); ClassDB::bind_method(D_METHOD("area_get_space", "area"), &Physics2DServer::area_get_space); ClassDB::bind_method(D_METHOD("area_set_space_override_mode", "area", "mode"), &Physics2DServer::area_set_space_override_mode); ClassDB::bind_method(D_METHOD("area_get_space_override_mode", "area"), &Physics2DServer::area_get_space_override_mode); ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform"), &Physics2DServer::area_add_shape, DEFVAL(Transform2D())); ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &Physics2DServer::area_set_shape); ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &Physics2DServer::area_set_shape_transform); ClassDB::bind_method(D_METHOD("area_set_shape_disabled", "area", "shape_idx", "disable"), &Physics2DServer::area_set_shape_disabled); ClassDB::bind_method(D_METHOD("area_get_shape_count", "area"), &Physics2DServer::area_get_shape_count); ClassDB::bind_method(D_METHOD("area_get_shape", "area", "shape_idx"), &Physics2DServer::area_get_shape); ClassDB::bind_method(D_METHOD("area_get_shape_transform", "area", "shape_idx"), &Physics2DServer::area_get_shape_transform); ClassDB::bind_method(D_METHOD("area_remove_shape", "area", "shape_idx"), &Physics2DServer::area_remove_shape); ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &Physics2DServer::area_clear_shapes); ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &Physics2DServer::area_set_collision_layer); ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &Physics2DServer::area_set_collision_mask); ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &Physics2DServer::area_set_param); ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &Physics2DServer::area_set_transform); ClassDB::bind_method(D_METHOD("area_get_param", "area", "param"), &Physics2DServer::area_get_param); ClassDB::bind_method(D_METHOD("area_get_transform", "area"), &Physics2DServer::area_get_transform); ClassDB::bind_method(D_METHOD("area_attach_object_instance_id", "area", "id"), &Physics2DServer::area_attach_object_instance_id); ClassDB::bind_method(D_METHOD("area_get_object_instance_id", "area"), &Physics2DServer::area_get_object_instance_id); ClassDB::bind_method(D_METHOD("area_set_monitor_callback", "area", "receiver", "method"), &Physics2DServer::area_set_monitor_callback); ClassDB::bind_method(D_METHOD("body_create", "mode", "init_sleeping"), &Physics2DServer::body_create, DEFVAL(BODY_MODE_RIGID), DEFVAL(false)); ClassDB::bind_method(D_METHOD("body_set_space", "body", "space"), &Physics2DServer::body_set_space); ClassDB::bind_method(D_METHOD("body_get_space", "body"), &Physics2DServer::body_get_space); ClassDB::bind_method(D_METHOD("body_set_mode", "body", "mode"), &Physics2DServer::body_set_mode); ClassDB::bind_method(D_METHOD("body_get_mode", "body"), &Physics2DServer::body_get_mode); ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform"), &Physics2DServer::body_add_shape, DEFVAL(Transform2D())); ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &Physics2DServer::body_set_shape); ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &Physics2DServer::body_set_shape_transform); ClassDB::bind_method(D_METHOD("body_set_shape_metadata", "body", "shape_idx", "metadata"), &Physics2DServer::body_set_shape_metadata); ClassDB::bind_method(D_METHOD("body_get_shape_count", "body"), &Physics2DServer::body_get_shape_count); ClassDB::bind_method(D_METHOD("body_get_shape", "body", "shape_idx"), &Physics2DServer::body_get_shape); ClassDB::bind_method(D_METHOD("body_get_shape_transform", "body", "shape_idx"), &Physics2DServer::body_get_shape_transform); ClassDB::bind_method(D_METHOD("body_get_shape_metadata", "body", "shape_idx"), &Physics2DServer::body_get_shape_metadata); ClassDB::bind_method(D_METHOD("body_remove_shape", "body", "shape_idx"), &Physics2DServer::body_remove_shape); ClassDB::bind_method(D_METHOD("body_clear_shapes", "body"), &Physics2DServer::body_clear_shapes); ClassDB::bind_method(D_METHOD("body_set_shape_disabled", "body", "shape_idx", "disable"), &Physics2DServer::body_set_shape_disabled); ClassDB::bind_method(D_METHOD("body_set_shape_as_one_way_collision", "body", "shape_idx", "enable"), &Physics2DServer::body_set_shape_as_one_way_collision); ClassDB::bind_method(D_METHOD("body_attach_object_instance_id", "body", "id"), &Physics2DServer::body_attach_object_instance_id); ClassDB::bind_method(D_METHOD("body_get_object_instance_id", "body"), &Physics2DServer::body_get_object_instance_id); ClassDB::bind_method(D_METHOD("body_set_continuous_collision_detection_mode", "body", "mode"), &Physics2DServer::body_set_continuous_collision_detection_mode); ClassDB::bind_method(D_METHOD("body_get_continuous_collision_detection_mode", "body"), &Physics2DServer::body_get_continuous_collision_detection_mode); ClassDB::bind_method(D_METHOD("body_set_collision_layer", "body", "layer"), &Physics2DServer::body_set_collision_layer); ClassDB::bind_method(D_METHOD("body_get_collision_layer", "body"), &Physics2DServer::body_get_collision_layer); ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &Physics2DServer::body_set_collision_mask); ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &Physics2DServer::body_get_collision_mask); ClassDB::bind_method(D_METHOD("body_set_param", "body", "param", "value"), &Physics2DServer::body_set_param); ClassDB::bind_method(D_METHOD("body_get_param", "body", "param"), &Physics2DServer::body_get_param); ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &Physics2DServer::body_set_state); ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &Physics2DServer::body_get_state); ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &Physics2DServer::body_apply_impulse); ClassDB::bind_method(D_METHOD("body_add_force", "body", "offset", "force"), &Physics2DServer::body_add_force); ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &Physics2DServer::body_set_axis_velocity); ClassDB::bind_method(D_METHOD("body_add_collision_exception", "body", "excepted_body"), &Physics2DServer::body_add_collision_exception); ClassDB::bind_method(D_METHOD("body_remove_collision_exception", "body", "excepted_body"), &Physics2DServer::body_remove_collision_exception); //virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions)=0; ClassDB::bind_method(D_METHOD("body_set_max_contacts_reported", "body", "amount"), &Physics2DServer::body_set_max_contacts_reported); ClassDB::bind_method(D_METHOD("body_get_max_contacts_reported", "body"), &Physics2DServer::body_get_max_contacts_reported); ClassDB::bind_method(D_METHOD("body_set_omit_force_integration", "body", "enable"), &Physics2DServer::body_set_omit_force_integration); ClassDB::bind_method(D_METHOD("body_is_omitting_force_integration", "body"), &Physics2DServer::body_is_omitting_force_integration); ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "receiver", "method", "userdata"), &Physics2DServer::body_set_force_integration_callback, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "margin", "result"), &Physics2DServer::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant())); /* JOINT API */ ClassDB::bind_method(D_METHOD("joint_set_param", "joint", "param", "value"), &Physics2DServer::joint_set_param); ClassDB::bind_method(D_METHOD("joint_get_param", "joint", "param"), &Physics2DServer::joint_get_param); ClassDB::bind_method(D_METHOD("pin_joint_create", "anchor", "body_a", "body_b"), &Physics2DServer::pin_joint_create, DEFVAL(RID())); ClassDB::bind_method(D_METHOD("groove_joint_create", "groove1_a", "groove2_a", "anchor_b", "body_a", "body_b"), &Physics2DServer::groove_joint_create, DEFVAL(RID()), DEFVAL(RID())); ClassDB::bind_method(D_METHOD("damped_spring_joint_create", "anchor_a", "anchor_b", "body_a", "body_b"), &Physics2DServer::damped_spring_joint_create, DEFVAL(RID())); ClassDB::bind_method(D_METHOD("damped_string_joint_set_param", "joint", "param", "value"), &Physics2DServer::damped_string_joint_set_param); ClassDB::bind_method(D_METHOD("damped_string_joint_get_param", "joint", "param"), &Physics2DServer::damped_string_joint_get_param); ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &Physics2DServer::joint_get_type); ClassDB::bind_method(D_METHOD("free_rid", "rid"), &Physics2DServer::free); ClassDB::bind_method(D_METHOD("set_active", "active"), &Physics2DServer::set_active); ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &Physics2DServer::get_process_info); //ClassDB::bind_method(D_METHOD("init"),&Physics2DServer::init); //ClassDB::bind_method(D_METHOD("step"),&Physics2DServer::step); //ClassDB::bind_method(D_METHOD("sync"),&Physics2DServer::sync); //ClassDB::bind_method(D_METHOD("flush_queries"),&Physics2DServer::flush_queries); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP); BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS); BIND_ENUM_CONSTANT(SHAPE_LINE); BIND_ENUM_CONSTANT(SHAPE_SEGMENT); BIND_ENUM_CONSTANT(SHAPE_CIRCLE); BIND_ENUM_CONSTANT(SHAPE_RECTANGLE); BIND_ENUM_CONSTANT(SHAPE_CAPSULE); BIND_ENUM_CONSTANT(SHAPE_CONVEX_POLYGON); BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON); BIND_ENUM_CONSTANT(SHAPE_CUSTOM); BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY); BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR); BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT); BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE); BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_ATTENUATION); BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP); BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY); BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_DISABLED); BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE); BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_COMBINE_REPLACE); BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE); BIND_ENUM_CONSTANT(AREA_SPACE_OVERRIDE_REPLACE_COMBINE); BIND_ENUM_CONSTANT(BODY_MODE_STATIC); BIND_ENUM_CONSTANT(BODY_MODE_KINEMATIC); BIND_ENUM_CONSTANT(BODY_MODE_RIGID); BIND_ENUM_CONSTANT(BODY_MODE_CHARACTER); BIND_ENUM_CONSTANT(BODY_PARAM_BOUNCE); BIND_ENUM_CONSTANT(BODY_PARAM_FRICTION); BIND_ENUM_CONSTANT(BODY_PARAM_MASS); BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA); BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE); BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_MAX); BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM); BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_SLEEPING); BIND_ENUM_CONSTANT(BODY_STATE_CAN_SLEEP); BIND_ENUM_CONSTANT(JOINT_PIN); BIND_ENUM_CONSTANT(JOINT_GROOVE); BIND_ENUM_CONSTANT(JOINT_DAMPED_SPRING); BIND_ENUM_CONSTANT(DAMPED_STRING_REST_LENGTH); BIND_ENUM_CONSTANT(DAMPED_STRING_STIFFNESS); BIND_ENUM_CONSTANT(DAMPED_STRING_DAMPING); BIND_ENUM_CONSTANT(CCD_MODE_DISABLED); BIND_ENUM_CONSTANT(CCD_MODE_CAST_RAY); BIND_ENUM_CONSTANT(CCD_MODE_CAST_SHAPE); //BIND_ENUM_CONSTANT( TYPE_BODY ); //BIND_ENUM_CONSTANT( TYPE_AREA ); BIND_ENUM_CONSTANT(AREA_BODY_ADDED); BIND_ENUM_CONSTANT(AREA_BODY_REMOVED); BIND_ENUM_CONSTANT(INFO_ACTIVE_OBJECTS); BIND_ENUM_CONSTANT(INFO_COLLISION_PAIRS); BIND_ENUM_CONSTANT(INFO_ISLAND_COUNT); }
void RenderQuad(Shader *sh, Primitive prim, bool centered, const float4x4 &trans) { Transform2D(trans, [&]() { RenderUnitSquare(sh, prim, centered); }); }
Transform2D CollisionObject2D::get_shape_transform(int p_shape_idx) const { ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), Transform2D()); return shapes[p_shape_idx].xform; }
void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect) { VSG::canvas_render->canvas_begin(); int l = p_canvas->child_items.size(); Canvas::ChildItem *ci = p_canvas->child_items.ptr(); bool has_mirror = false; for (int i = 0; i < l; i++) { if (ci[i].mirror.x || ci[i].mirror.y) { has_mirror = true; break; } } if (!has_mirror) { static const int z_range = VS::CANVAS_ITEM_Z_MAX - VS::CANVAS_ITEM_Z_MIN + 1; RasterizerCanvas::Item *z_list[z_range]; RasterizerCanvas::Item *z_last_list[z_range]; for (int i = 0; i < z_range; i++) { z_list[i] = NULL; z_last_list[i] = NULL; } for (int i = 0; i < l; i++) { _render_canvas_item(ci[i].item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, NULL, NULL); } for (int i = 0; i < z_range; i++) { if (!z_list[i]) continue; if (p_masked_lights) { _light_mask_canvas_items(VS::CANVAS_ITEM_Z_MIN + i, z_list[i], p_masked_lights); } VSG::canvas_render->canvas_render_items(z_list[i], VS::CANVAS_ITEM_Z_MIN + i, p_canvas->modulate, p_lights); } } else { for (int i = 0; i < l; i++) { Canvas::ChildItem &ci = p_canvas->child_items[i]; _render_canvas_item_tree(ci.item, p_transform, p_clip_rect, p_canvas->modulate, p_lights); //mirroring (useful for scrolling backgrounds) if (ci.mirror.x != 0) { Transform2D xform2 = p_transform * Transform2D(0, Vector2(ci.mirror.x, 0)); _render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } if (ci.mirror.y != 0) { Transform2D xform2 = p_transform * Transform2D(0, Vector2(0, ci.mirror.y)); _render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } if (ci.mirror.y != 0 && ci.mirror.x != 0) { Transform2D xform2 = p_transform * Transform2D(0, ci.mirror); _render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights); } } } }
void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { Item *current_clip = NULL; RasterizerStorageGLES2::Shader *shader_cache = NULL; bool rebind_shader = true; state.current_tex = RID(); state.current_tex_ptr = NULL; state.current_normal = RID(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); int last_blend_mode = -1; RID canvas_last_material = RID(); while (p_item_list) { Item *ci = p_item_list; if (current_clip != ci->final_clip_owner) { current_clip = ci->final_clip_owner; if (current_clip) { glEnable(GL_SCISSOR_TEST); int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y); if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) y = current_clip->final_clip_rect.position.y; glScissor(current_clip->final_clip_rect.position.x, y, current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } else { glDisable(GL_SCISSOR_TEST); } } // TODO: copy back buffer if (ci->copy_back_buffer) { if (ci->copy_back_buffer->full) { _copy_texscreen(Rect2()); } else { _copy_texscreen(ci->copy_back_buffer->rect); } } Item *material_owner = ci->material_owner ? ci->material_owner : ci; RID material = material_owner->material; RasterizerStorageGLES2::Material *material_ptr = storage->material_owner.getornull(material); if (material != canvas_last_material || rebind_shader) { RasterizerStorageGLES2::Shader *shader_ptr = NULL; if (material_ptr) { shader_ptr = material_ptr->shader; if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) { shader_ptr = NULL; // not a canvas item shader, don't use. } } if (shader_ptr) { if (shader_ptr->canvas_item.uses_screen_texture) { _copy_texscreen(Rect2()); } if (shader_ptr != shader_cache) { if (shader_ptr->canvas_item.uses_time) { VisualServerRaster::redraw_request(); } state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id); state.canvas_shader.bind(); } int tc = material_ptr->textures.size(); Pair<StringName, RID> *textures = material_ptr->textures.ptrw(); ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptrw(); for (int i = 0; i < tc; i++) { glActiveTexture(GL_TEXTURE0 + i); RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second); if (!t) { switch (texture_hints[i]) { case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO: case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); } break; case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: { glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex); } break; default: { glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); } break; } continue; } t = t->get_ptr(); if (t->redraw_if_visible) { VisualServerRaster::redraw_request(); } glBindTexture(t->target, t->tex_id); } } else { state.canvas_shader.set_custom_shader(0); state.canvas_shader.bind(); } state.canvas_shader.use_material((void *)material_ptr); shader_cache = shader_ptr; canvas_last_material = material; rebind_shader = false; } int blend_mode = shader_cache ? shader_cache->canvas_item.blend_mode : RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX; bool unshaded = (shader_cache && blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX); bool reclip = false; if (last_blend_mode != blend_mode) { switch (blend_mode) { case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX: { glBlendEquation(GL_FUNC_ADD); if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } break; case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_ADD: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_SUB: { glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MUL: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_DST_COLOR, GL_ZERO); } break; case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } break; } } state.uniforms.final_modulate = unshaded ? ci->final_modulate : Color(ci->final_modulate.r * p_modulate.r, ci->final_modulate.g * p_modulate.g, ci->final_modulate.b * p_modulate.b, ci->final_modulate.a * p_modulate.a); state.uniforms.modelview_matrix = ci->final_transform; state.uniforms.extra_matrix = Transform2D(); _set_uniforms(); _canvas_item_render_commands(p_item_list, NULL, reclip, material_ptr); rebind_shader = true; // hacked in for now. if (reclip) { glEnable(GL_SCISSOR_TEST); int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y); if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) y = current_clip->final_clip_rect.position.y; glScissor(current_clip->final_clip_rect.position.x, y, current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } p_item_list = p_item_list->next; } if (current_clip) { glDisable(GL_SCISSOR_TEST); } }
void RasterizerCanvasGLES2::canvas_begin() { state.canvas_shader.bind(); if (storage->frame.current_rt) { glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); glColorMask(1, 1, 1, 1); } if (storage->frame.clear_request) { glColorMask(true, true, true, true); glClearColor(storage->frame.clear_request_color.r, storage->frame.clear_request_color.g, storage->frame.clear_request_color.b, storage->frame.clear_request_color.a); glClear(GL_COLOR_BUFFER_BIT); storage->frame.clear_request = false; } /* if (storage->frame.current_rt) { glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); glColorMask(1, 1, 1, 1); } */ reset_canvas(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); glDisableVertexAttribArray(VS::ARRAY_COLOR); // set up default uniforms Transform canvas_transform; if (storage->frame.current_rt) { float csy = 1.0; if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) { csy = -1.0; } canvas_transform.translate(-(storage->frame.current_rt->width / 2.0f), -(storage->frame.current_rt->height / 2.0f), 0.0f); canvas_transform.scale(Vector3(2.0f / storage->frame.current_rt->width, csy * -2.0f / storage->frame.current_rt->height, 1.0f)); } else { Vector2 ssize = OS::get_singleton()->get_window_size(); canvas_transform.translate(-(ssize.width / 2.0f), -(ssize.height / 2.0f), 0.0f); canvas_transform.scale(Vector3(2.0f / ssize.width, -2.0f / ssize.height, 1.0f)); } state.uniforms.projection_matrix = canvas_transform; state.uniforms.final_modulate = Color(1, 1, 1, 1); state.uniforms.modelview_matrix = Transform2D(); state.uniforms.extra_matrix = Transform2D(); _set_uniforms(); _bind_quad_buffer(); }
Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), Transform2D()); return shapes[p_owner].xform; }
void TextureRegionEditor::_region_draw() { Ref<Texture> base_tex = NULL; if (node_sprite) base_tex = node_sprite->get_texture(); else if (node_patch9) base_tex = node_patch9->get_texture(); else if (obj_styleBox.is_valid()) base_tex = obj_styleBox->get_texture(); else if (atlas_tex.is_valid()) base_tex = atlas_tex->get_atlas(); if (base_tex.is_null()) return; Transform2D mtx; mtx.elements[2] = -draw_ofs; mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), mtx); edit_draw->draw_texture(base_tex, Point2()); VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), Transform2D()); if (snap_mode == SNAP_GRID) { Size2 s = edit_draw->get_size(); int last_cell; if (snap_step.x != 0) { if (snap_separation.x == 0) for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x)); if (i == 0) last_cell = cell; if (last_cell != cell) edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3)); last_cell = cell; } else for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / (snap_step.x + snap_separation.x))); if (i == 0) last_cell = cell; if (last_cell != cell) edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), Color(0.3, 0.7, 1, 0.3)); last_cell = cell; } } if (snap_step.y != 0) { if (snap_separation.y == 0) for (int i = 0; i < s.height; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y)); if (i == 0) last_cell = cell; if (last_cell != cell) edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3)); last_cell = cell; } else for (int i = 0; i < s.height; i++) { int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / (snap_step.y + snap_separation.y))); if (i == 0) last_cell = cell; if (last_cell != cell) edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), Color(0.3, 0.7, 1, 0.3)); last_cell = cell; } } } else if (snap_mode == SNAP_AUTOSLICE) { for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { Rect2 r = E->get(); Vector2 endpoints[4] = { mtx.basis_xform(r.position), mtx.basis_xform(r.position + Vector2(r.size.x, 0)), mtx.basis_xform(r.position + r.size), mtx.basis_xform(r.position + Vector2(0, r.size.y)) }; for (int i = 0; i < 4; i++) { int next = (i + 1) % 4; edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, Color(0.3, 0.7, 1, 1), 2); } } } Ref<Texture> select_handle = get_icon("EditorHandle", "EditorIcons"); Rect2 scroll_rect(Point2(), mtx.basis_xform(base_tex->get_size())); scroll_rect.expand_to(mtx.basis_xform(edit_draw->get_size())); Vector2 endpoints[4] = { mtx.basis_xform(rect.position), mtx.basis_xform(rect.position + Vector2(rect.size.x, 0)), mtx.basis_xform(rect.position + rect.size), mtx.basis_xform(rect.position + Vector2(0, rect.size.y)) }; Color color(0.9, 0.5, 0.5); for (int i = 0; i < 4; i++) { int prev = (i + 3) % 4; int next = (i + 1) % 4; Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized(); ofs *= 1.4144 * (select_handle->get_size().width / 2); edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, color, 2); if (snap_mode != SNAP_AUTOSLICE) edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs); ofs = (endpoints[next] - endpoints[i]) / 2; ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); if (snap_mode != SNAP_AUTOSLICE) edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs); scroll_rect.expand_to(endpoints[i]); } scroll_rect = scroll_rect.grow(200); updating_scroll = true; hscroll->set_min(scroll_rect.position.x); hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x); hscroll->set_page(edit_draw->get_size().x); hscroll->set_value(draw_ofs.x); hscroll->set_step(0.001); vscroll->set_min(scroll_rect.position.y); vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y); vscroll->set_page(edit_draw->get_size().y); vscroll->set_value(draw_ofs.y); vscroll->set_step(0.001); updating_scroll = false; float margins[4]; if (node_patch9 || obj_styleBox.is_valid()) { if (node_patch9) { margins[0] = node_patch9->get_patch_margin(MARGIN_TOP); margins[1] = node_patch9->get_patch_margin(MARGIN_BOTTOM); margins[2] = node_patch9->get_patch_margin(MARGIN_LEFT); margins[3] = node_patch9->get_patch_margin(MARGIN_RIGHT); } else if (obj_styleBox.is_valid()) { margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP); margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM); margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT); margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } Vector2 pos[4] = { mtx.basis_xform(Vector2(0, margins[0])) + Vector2(0, endpoints[0].y - draw_ofs.y), -mtx.basis_xform(Vector2(0, margins[1])) + Vector2(0, endpoints[2].y - draw_ofs.y), mtx.basis_xform(Vector2(margins[2], 0)) + Vector2(endpoints[0].x - draw_ofs.x, 0), -mtx.basis_xform(Vector2(margins[3], 0)) + Vector2(endpoints[2].x - draw_ofs.x, 0) }; draw_margin_line(edit_draw, pos[0], pos[0] + Vector2(edit_draw->get_size().x, 0)); draw_margin_line(edit_draw, pos[1], pos[1] + Vector2(edit_draw->get_size().x, 0)); draw_margin_line(edit_draw, pos[2], pos[2] + Vector2(0, edit_draw->get_size().y)); draw_margin_line(edit_draw, pos[3], pos[3] + Vector2(0, edit_draw->get_size().y)); } }
void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest) { Transform2D *dest = (Transform2D *)r_dest; *dest = Transform2D(); }
void CollisionObject2D::_bind_methods() { ClassDB::bind_method(D_METHOD("add_shape", "shape:Shape2D", "transform"), &CollisionObject2D::add_shape, DEFVAL(Transform2D())); ClassDB::bind_method(D_METHOD("get_shape_count"), &CollisionObject2D::get_shape_count); ClassDB::bind_method(D_METHOD("set_shape", "shape_idx", "shape:Shape"), &CollisionObject2D::set_shape); ClassDB::bind_method(D_METHOD("set_shape_transform", "shape_idx", "transform"), &CollisionObject2D::set_shape_transform); ClassDB::bind_method(D_METHOD("set_shape_as_trigger", "shape_idx", "enable"), &CollisionObject2D::set_shape_as_trigger); ClassDB::bind_method(D_METHOD("get_shape:Shape2D", "shape_idx"), &CollisionObject2D::get_shape); ClassDB::bind_method(D_METHOD("get_shape_transform", "shape_idx"), &CollisionObject2D::get_shape_transform); ClassDB::bind_method(D_METHOD("is_shape_set_as_trigger", "shape_idx"), &CollisionObject2D::is_shape_set_as_trigger); ClassDB::bind_method(D_METHOD("remove_shape", "shape_idx"), &CollisionObject2D::remove_shape); ClassDB::bind_method(D_METHOD("clear_shapes"), &CollisionObject2D::clear_shapes); ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid); ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable); ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable); BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx"))); ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx"))); ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); ADD_GROUP("Pickable", "input_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pickable"), "set_pickable", "is_pickable"); ADD_GROUP("", ""); }