private void BisectOrCreateRoom(Area area) { if (area.IsSmallerThan(THRESHOLD)) { Room room = CreateRoom(area); Debug.Log("created Room: " + room); rooms.Add(room); } else { bool bisectOnX = false; if (!area.IsSmallerOnXThan(THRESHOLD) && !area.IsSmallerOnYThan(THRESHOLD)) { int n = random.Next(100); if (n >= 50) { bisectOnX = true; } } else { if (area.IsSmallerOnXThan(THRESHOLD)) { bisectOnX = false; } else { bisectOnX = true; } } Area child1; Area child2; int minAreaSize = MIN_ROOM_SIZE + MIN_OFFSET * 2; if (bisectOnX) { //se è 30, deve essere tra 6 e 24 int bisectCoord = minAreaSize + random.Next(area.GetSizeX() - minAreaSize * 2); child1 = new Area(area, area.GetX(), area.GetY(), bisectCoord, area.GetSizeY(), tilesMap); child2 = new Area(area, area.GetX() + bisectCoord, area.GetY(), area.GetSizeX() - bisectCoord, area.GetSizeY(), tilesMap); } else { int bisectCoord = minAreaSize + random.Next(area.GetSizeY() - minAreaSize * 2); child1 = new Area(area, area.GetX(), area.GetY(), area.GetSizeX(), bisectCoord, tilesMap); child2 = new Area(area, area.GetX(), area.GetY() + bisectCoord, area.GetSizeX(), area.GetSizeY() - bisectCoord, tilesMap); } area.AddChild(child1); area.AddChild(child2); BisectOrCreateRoom(child1); BisectOrCreateRoom(child2); } }
public override void _Ready() { // That's how animations work ((AnimationPlayer)GetNode("AnimationPlayer")).PlaybackActive = true; ((AnimationPlayer)GetNode("AnimationPlayer")).Autoplay = "Attack"; ((AnimationPlayer)GetNode("AnimationPlayer")).Play("Attack"); aoe_scale *= ((MeshInstance)GetNode("HumanArmature/Knight")).Scale; // Create area for DMG query of other units area_of_effect = new Area(); aoe_dmg_collison = new CollisionShape(); BoxShape shape = new BoxShape(); shape.Extents = aoe_scale; aoe_dmg_collison.Shape = shape; area_of_effect.Translation += new Vector3(0, 0, aoe_scale.z * area_of_effect_offset); area_of_effect.Name = "DMG_Area"; area_of_effect.AddChild(aoe_dmg_collison); AddChild(area_of_effect); // Create area for collsion with other units hitbox_area = new Area(); hitbox_collision = new CollisionShape(); CylinderShape hitbox_shape = new CylinderShape(); hitbox_shape.Height = hitbox_scale.y; hitbox_shape.Radius = hitbox_scale.x; hitbox_collision.Shape = hitbox_shape; hitbox_area.Name = "Hitbox_Area"; hitbox_area.AddChild(hitbox_collision); AddChild(hitbox_area); }
/// Returns the Creature that is "under" the specified screen position, or null if there isn't one. /// In other words, projects a ray from the screen position and sees which creature it hits. public Creature GetCreatureAtScreenPos(Vector2 screenPos) { Vector3 worldPos = this.ScreenPosToWorldPos(screenPos); // create a small area at the world pos Area area = new Area(); CollisionShape collisionShape = new CollisionShape(); BoxShape boxShape = new BoxShape(); boxShape.Extents = new Vector3(0.1f, 0.1f, 0.1f); collisionShape.Shape = boxShape; area.AddChild(collisionShape); this.AddChild(area); area.Translation = worldPos; // see if any creature is in this area Creature result = null; foreach (var item in area.GetOverlappingBodies()) { if (item is Creature creature) { result = creature; } } // delete temp area this.RemoveChild(area); area.QueueFree(); return(result); }
public override void _Ready() { currentVelocity = initialVelocity; Universe.spaceBodies.Add(this); float r = radius / Universe.scaleFactor; MeshInstance meshInstance = new MeshInstance(); meshInstance.Mesh = new SphereMesh(); //just once! meshInstance.Scale = new Vector3(r, r, r); SpatialMaterial mat = new SpatialMaterial(); mat.AlbedoColor = color; meshInstance.Mesh.SurfaceSetMaterial(0, mat); AddChild(meshInstance); var area = new Area(); var colissionShape = new CollisionShape(); var SphereShape = new SphereShape(); SphereShape.Radius = r; colissionShape.Shape = SphereShape; area.AddChild(colissionShape); AddChild(area); area.Connect("input_event", this, nameof(_OnSelect)); }
private void GenerateCollisionArea(int m_x, int m_y, int m_z) { CollisionShape shape = new CollisionShape(); shape.Shape = new BoxShape(); shape.Translation = new Vector3(m_x * cell_size.x + cell_size.x / 2, m_y * cell_size.y + offset_y, m_z * cell_size.z + cell_size.z / 2); shape.Scale = new Vector3(cell_size.x / 2, 1, cell_size.z / 2); arealevel.AddChild(shape); }
void InitArea() { List <CollisionShape> shapes = GetCollisionShapes(); Area area = new Area(); CollisionShape areaShape = new CollisionShape(); area.AddChild(areaShape); object[] areaShapeOwners = area.GetShapeOwners(); for (int i = 0; i < areaShapeOwners.Length; i++) { int ownerInt = (int)areaShapeOwners[i]; for (int j = 0; j < shapes.Count; j++) { area.ShapeOwnerAddShape(ownerInt, shapes[i].Shape); } } area.Connect("body_entered", this, nameof(OnCollide)); AddChild(area); }
public Spatial makeAxisLines(int size) { axis_lines = new Spatial(); AddChild(axis_lines); axis_lines_exist = 1; Area axis_lines_area = new Area(); axis_lines.AddChild(axis_lines_area); Vector3 axis_scale = new Vector3(0, 0, 0); for (int i = 0; i < 3; i++) { MeshInstance single_axis = new MeshInstance(); single_axis.Mesh = new CubeMesh { }; axis_lines_area.AddChild(single_axis); axis_scale = new Vector3(0.1f, 0.1f, 0.1f); switch (i) { case 0: axis_scale.x = size + 1; break; case 1: axis_scale.y = size + 1; break; case 2: axis_scale.z = size + 1; break; } single_axis.Translate(-1 * axis_scale / (size + 1)); single_axis.Scale = axis_scale; } return(axis_lines); }
public PropPickup(int x, int y, Level level) : base(x, y, level) { if (level != null) { BoxShape box = new BoxShape(); box.Extents = new Vector3(Level.CellSize * 0.25f, Level.CellSize * 0.5f, Level.CellSize * 0.25f); _areaShape = new CollisionShape(); _areaShape.Shape = box; _area = new Area(); _area.CollisionLayer = (int)(Level.CollisionLayers.Pickups); _area.CollisionMask = (int)(Level.CollisionLayers.Characters); _area.AddChild(_areaShape); AddChild(_area); _area.Connect("body_entered", this, "OnBodyEntered"); } }
void InitArea() { if (area != null) { return; } List <CollisionShape> shapes = GetCollisionShapes(); this.area = new Area(); CollisionShape areaShape = new CollisionShape(); area.AddChild(areaShape); Godot.Array areaShapeOwners = area.GetShapeOwners(); for (int i = 0; i < areaShapeOwners.Count; i++) { int ownerInt = (int)areaShapeOwners[i]; for (int j = 0; j < shapes.Count; j++) { area.ShapeOwnerAddShape(ownerInt, shapes[i].Shape); } } area.Connect("body_entered", this, nameof(OnCollide)); AddChild(area); }
public async void UpdateShapes() { // await System.Threading.Thread.SpinWait(1000); await System.Threading.Tasks.Task.Delay(100); try { using (var frames = pipe.WaitForFrames()) using (var depth = frames.DepthFrame) using (var points = pc.Process(depth).As <Points>()) { // CopyVertices is extensible, any of these will do: float[] vertices; vertices = new float[points.Count * 3]; points.CopyVertices(vertices); Points = vertices; } // Remove all children from the detectbody foreach (Node child in detectBody.GetChildren()) { child.QueueFree(); } if (detectBody.GetShapeOwners().Count > 0) { GD.Print(detectBody.GetShapeOwners().Count); for (int l = 0; l < detectBody.GetShapeOwners().Count; l++) { detectBody.ShapeOwnerClearShapes((uint)l); } } } catch { } detectedPoints.Clear(); sortedPoints.Clear(); Vector3 currentGroundPoint = new Vector3(); // allPoints = new Vector3[101760]; for (int i = 0; i < meshDataTool.GetVertexCount(); i++) // 101760 { Vector3 vertex = meshDataTool.GetVertex(i); int indexOfX = i * 3; int indexOfY = i * 3 + 1; int indexOfZ = i * 3 + 2; float x = Points[indexOfX]; float y = Points[indexOfY]; float z = Points[indexOfZ]; bool shapeFoundForPoint = false; // GD.Print(x); if (z > distanceToGround || z == 0.0f || z < 0 || x < syncPointTL.x || y > syncPointTL.y || x > syncPointBR.x || y < syncPointBR.y) { z = 0; } else { z = (distanceToGround - z) * 2; if (vertex.y > 0) { currentGroundPoint = vertex; currentGroundPoint.y = 0; //------------------------------------------------- For each point test -------------------------------------------------- if (detectedPoints.Count == 0) { // make a vector on the ground for the detection shape to get a height List <Vector3> shapePoints = new List <Vector3> { currentGroundPoint, vertex }; detectedPoints.Add(shapePoints); // Add the vectors to a list with shapes } else { for (int j = 0; j < detectedPoints.Count; j++) // Run thrugh all the shapes { int lengthOfShape = detectedPoints[j].Count; // number of points in shape // find the shape with a last added start point... if (detectedPoints[j][lengthOfShape - 2].DistanceTo(currentGroundPoint) < 1) //4 distanceBetweenPoints { detectedPoints[j].Add(currentGroundPoint); detectedPoints[j].Add(vertex); shapeFoundForPoint = true; break; } } if (shapeFoundForPoint == false) { //... create a new shape and add the points List <Vector3> shapePoints = new List <Vector3> { currentGroundPoint, vertex }; detectedPoints.Add(shapePoints); } } shapeFoundForPoint = false; //------------------------------------------------------------------------------------------------------------------------ } } vertex.y = z; meshDataTool.SetVertex(i, vertex); // Draw shape } Vector3 prevPoint = new Vector3(10, 10, 10); Vector3 prevprevPoint = new Vector3(10, 10, 10); // ---------------------------- Add points to shapes -------------------------- for (int i = 0; i < detectedPoints.Count; i++) { // Point (000) removal detectedPoints[i].RemoveAll(item => item == pointZero); for (int j = 0; j < detectedPoints[i].Count; j++) { if (detectedPoints[i][j].z != prevprevPoint.z) { prevprevPoint = prevPoint; prevPoint = detectedPoints[i][j]; } else if (detectedPoints[i][j].z == prevprevPoint.z) { prevprevPoint = prevPoint; prevPoint = detectedPoints[i][j]; detectedPoints[i].Remove(prevprevPoint); } } int pointSets = 100000; var sortOut = detectedPoints[i].Where((x, n) => n % pointSets == 0 || n - 1 % pointSets == 0); Vector3[] convertedArr = sortOut.ToArray(); // -------------------------- Must be turned on ---------------------- convexPolygonShape = new ConvexPolygonShape(); convexPolygonShape.Points = convertedArr; var areaShape = new Area(); areaShape.AddToGroup("cameraDetections"); DetectionCollisionShape = new CollisionShape(); DetectionCollisionShape.Shape = convexPolygonShape; DetectionCollisionShape.Shape.Margin = 1; areaShape.AddChild(DetectionCollisionShape); detectBody.AddChild(areaShape); // ---------------------------------------------------------------- } detectedPoints.Clear(); sortedPoints.Clear(); // ---------------------------- Remove surface -------------------------- for (int j = 0; j < arrayPlane.GetSurfaceCount(); j++) { arrayPlane.SurfaceRemove(j); // Removes the drawing } meshDataTool.CommitToSurface(arrayPlane); // Resets the surface UpdateShapes(); // Rerun function }
public Spatial makeOutline(int size, Vector3 side_select) { outline = new Spatial(); AddChild(outline); outline_exists = 1; Area box = new Area(); outline.AddChild(box); Godot.Collections.Array edge_list = new Godot.Collections.Array(); Godot.Collections.Array pos_list = new Godot.Collections.Array(); float side_num = 0; Vector3 ss_normal = side_select.Normalized(); Vector3 ss_normal_x = x_axis; Vector3 ss_normal_y = y_axis; Vector3 ss_normal_z = z_axis; Vector3 ss_normal_1 = new Vector3(0, 0, 0); Vector3 ss_normal_2 = new Vector3(0, 0, 0); // need more comprehensive error checking if (side_select.x >= 1) { side_num = side_select.x; ss_normal_1 = ss_normal_y; ss_normal_2 = ss_normal_z; } else if (side_select.y >= 1) { side_num = side_select.y; ss_normal_1 = ss_normal_x; ss_normal_2 = ss_normal_z; } else if (side_select.z >= 1) { side_num = side_select.z; ss_normal_1 = ss_normal_x; ss_normal_2 = ss_normal_y; } else { GD.Print("ERROR, side select makeOutline"); return(outline); } Vector3 scale_add = new Vector3(0.1f, 0.1f, 0.1f); // 12 edges to a rectangular prism, so can make 8 of them // size-long, the other 4 are 1 unit long Vector3 scale_long = (ss_normal * size) + scale_add; Vector3 scale_short = ss_normal + scale_add; Vector3 rotation_long_1 = ss_normal_1 * 90f; Vector3 rotation_long_2 = ss_normal_2 * 90f; Vector3 rotation_short = ss_normal * 90f; Vector3 base_pos = ss_normal * (side_num - (size) + (((float)side_num - 1f) * 1f)); Vector3 base_pos_side_small = ss_normal; Vector3 base_pos_side_1 = ss_normal_1 * size; Vector3 base_pos_side_2 = ss_normal_2 * size; Vector3 position_short_1 = base_pos + base_pos_side_1 + base_pos_side_2; Vector3 position_short_2 = base_pos + base_pos_side_1 - base_pos_side_2; Vector3 position_short_3 = base_pos - base_pos_side_1 + base_pos_side_2; Vector3 position_short_4 = base_pos - base_pos_side_1 - base_pos_side_2; Vector3 position_long_1_1 = base_pos + base_pos_side_1 + ss_normal; Vector3 position_long_1_2 = base_pos + base_pos_side_1 - ss_normal; Vector3 position_long_1_3 = base_pos - base_pos_side_1 + ss_normal; Vector3 position_long_1_4 = base_pos - base_pos_side_1 - ss_normal; Vector3 position_long_2_1 = base_pos + base_pos_side_2 + ss_normal; Vector3 position_long_2_2 = base_pos + base_pos_side_2 - ss_normal; Vector3 position_long_2_3 = base_pos - base_pos_side_2 + ss_normal; Vector3 position_long_2_4 = base_pos - base_pos_side_2 - ss_normal; pos_list.Add(position_short_1); pos_list.Add(position_short_2); pos_list.Add(position_short_3); pos_list.Add(position_short_4); pos_list.Add(position_long_2_1); pos_list.Add(position_long_2_2); pos_list.Add(position_long_2_3); pos_list.Add(position_long_2_4); pos_list.Add(position_long_1_1); pos_list.Add(position_long_1_2); pos_list.Add(position_long_1_3); pos_list.Add(position_long_1_4); for (int i = 0; i < 12; i++) { MeshInstance edge = new MeshInstance(); edge.Mesh = new CubeMesh { }; box.AddChild(edge); edge.Translate((Vector3)pos_list[i]); if (i >= 0 && i < 4) { edge.Scale = scale_short; edge.RotationDegrees = rotation_short; } else if (i >= 4 && i < 8) { edge.Scale = scale_long; edge.RotationDegrees = rotation_long_2; } else if (i >= 8 && i < 12) { edge.Scale = scale_long; edge.RotationDegrees = rotation_long_1; } edge_list.Add(edge); } return(outline); }
public void AddRootInvItem(IInvItem item) { var observer = (DefaultInvPV)EasyInstancer.GenObserver((Node)item, item.ObserverPathInvPV); InventoryWorkspace.AddChild(observer); }