private void GetFloorCollision() { Rect floorRect = new Rect(); for (int row = 0; row < mapData.Height; ++row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (row + 1 < mapData.Height) { Tile aboveTile = mapData[row + 1, col]; if (IsNormalCollision(aboveTile)) { continue; } } else { return; } floorRect.x = col; floorRect.y = row; while (IsInBounds(row + 1, col + 1)) { currentTile = mapData[row, col + 1]; if (row + 1 < mapData.Height) { Tile aboveTile = mapData[row + 1, col]; if (IsNormalCollision(aboveTile)) { --col; break; } } if (IsNormalCollision(currentTile)) { ++col; } else { break; } } float floorWidth = col - floorRect.x + 1; floorRect.width = floorWidth; floorRect.height = 1; RectangleMesh floorMesh = new RectangleMesh(floorRect); floorMesh.BuildHorizontalMesh(); meshes.Add(floorMesh.Mesh); } } } }
private void GetLeftCollision() { Rect leftRect = new Rect(); for (int col = 0; col < mapData.Width; ++col) { for (int row = 0; row < mapData.Height; ++row) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (col - 1 >= 0) { Tile leftTile = mapData[row, col - 1]; if (IsNormalCollision(leftTile)) { continue; } } else { continue; } leftRect.x = col; leftRect.y = row; while (row + 1 < mapData.Height) { currentTile = mapData[row + 1, col]; if (col - 1 >= 0) { Tile leftTile = mapData[row, col - 1]; if (IsNormalCollision(leftTile)) { --row; break; } } if (IsNormalCollision(currentTile)) { ++row; } else { break; } } leftRect.width = 0; leftRect.height = row - leftRect.y + 1; RectangleMesh leftMesh = new RectangleMesh(leftRect); leftMesh.BuildVerticalMesh(); meshes.Add(leftMesh.Mesh); } } } }
private MeshBase GetChoosenMesh(MeshCreator meshCreator) { switch (meshCreator.meshType) { case MeshCreator.MeshType.Triangle: return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1, meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Rectangle: return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Circle: return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius, meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Quadrangle: Vector2[] verts = new Vector2[4] { meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2, meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4 }; return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Ellipse: return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius, meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.PointedCircle: return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius, meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Cake: return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides, meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Convex: return(ConvexMesh.AddConvexMesh(meshCreator.transform.position, MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints), Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Star: return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB, meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Gear: return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius, meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Line: return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth, meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody)); } return(null); }
private RectangleMesh AddBox() { Vector3 pos = new Vector3(0, -4, -0.1f); RectangleMesh rectangleMesh = RectangleMesh.AddRectangle(pos, new Vector2(0.5f, 2.5f), null, false); rectangleMesh.SetColor(Color.blue); return(rectangleMesh); }
public RectangleMesh CreateImage(Rect rect, Texture2D texture, string styleName) { var image = new RectangleMesh(); var style = GetStyle(styleName); image.Init(style, rect); image.Texture = texture; return(image); }
void Start() { mesh_gen = new RectangleMesh(mesh_size_x, mesh_size_y, mesh_detail, rough_height); mesh_gen.set_rough_map(rough_top, rough_right, rough_bottom, rough_left); mesh_gen.make_mesh(); GetComponent <MeshFilter>().mesh = mesh_gen.get_mesh(); mesh_gen.extract_perimeter_vertices(); GetComponent <PolygonCollider2D>().points = mesh_gen.get_perimeter(); GetComponent <MeshRenderer>().sortingLayerName = "Default"; }
private void AddRectangle(Vector3 pos) { float x = Random.Range(0.3f, 2f); float y = Random.Range(0.3f, 2f); RectangleMesh rectangle = RectangleMesh.AddRectangle(pos, new Vector2(x, y), material); rectangle.SetTexture(squareTexture); rectangle.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(); }
private void AddBox(Vector3 pos) { GameObject box = new GameObject(); RectangleMesh rectangleMesh = box.AddComponent <RectangleMesh>(); rectangleMesh.Build(new Vector2(1.2f, 1.2f)); rectangleMesh.SetTexture(squareTexture); rectangleMesh.SetPhysicsMaterialProperties(1, 0); box.AddComponent <Rigidbody2D>(); rectangleMesh.C_MR.material.color = new Color(0.8f, 0.8f, 0.3f); }
private void GetDiagonalCollision() { Rect diagonalRect = new Rect(); for (int row = 0; row < mapData.Height; ++row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsDiagonalCollision(currentTile)) { if (IsLowerCollision(currentTile)) { diagonalRect.x = col; diagonalRect.y = row; diagonalRect.width = 1f; diagonalRect.height = 0.5f; } else // upper collision { diagonalRect.x = col; diagonalRect.y = row + 0.5f; diagonalRect.width = 1f; diagonalRect.height = 0.5f; } if (IsLeftCollision(currentTile)) { diagonalRect.x += 1; diagonalRect.width = -diagonalRect.width; } else { } RectangleMesh diagRectMesh = new RectangleMesh(diagonalRect); diagRectMesh.BuildDiagonalMesh(); if (IsTopCollision(currentTile) || IsLeftCollision(currentTile)) { diagRectMesh.InvertMesh(); } meshes.Add(diagRectMesh.Mesh); } } } }
public void filledRect(Span <uint> destSpan, int baseVertex) => RectangleMesh.filledIndices(destSpan, baseVertex);
void uploadVertices(IDeviceContext ic, Span <sDrawCall> drawCallsSpan) { ReadOnlySpan <int> baseVertices = buffersLayout.baseVertices; using (var mapped = resources.getVertexBuffer().map <sVertexWithId>(ic, buffersLayout.vertexBufferSize)) { Span <sVertexWithId> span = mapped.span; for (int i = 0; i < drawCallsSpan.Length; i++) { int bv = baseVertices[i]; if (bv < 0) { continue; // Empty draw call, i.e. completely clipped out } Span <sVertexWithId> dest = span.Slice(bv); ref var dc = ref drawCallsSpan[i]; uint id = VertexID.vertex(i); int sn = dc.order.sn; if (sn >= 0) { drawMeshes.meshes[sn].mesh.mesh.copyVertices(dest, id); continue; } sn = -sn - 1; if (dc.drawCall.mesh == eMesh.SpriteRectangle) { Rect rc = drawMeshes.spriteCommands[sn].rect; SpriteMesh.writeVertices(dest, ref rc, id); continue; } if (dc.drawCall.isText) { var text = drawMeshes.textCommands[sn]; sMeshDataSize mds; if (text.consoleWidth.HasValue) { mds = text.font.renderConsole(dest, id, text.text, text.rectangle.topLeft, text.textRendering, text.consoleWidth.Value); } else { mds = text.font.renderBlock(dest, id, text.text, ref text.rectangle, text.textRendering); } Debug.Assert(mds.vertices <= text.meshDataSize.vertices && mds.triangles <= text.meshDataSize.triangles); // Store the actual count of triangles written. // uploadIndices function needs it later, to fill unused portion of the index buffer with UINT_MAX (32 bit IB) or 0xFFFF (16 bit IB) discarding the data. // Technically that's wasted GPU bandwidth, however: // (a) Not much of it, as normal text only contains a few of these soft hyphens and ligatures. // (b) Saves substantial amount of resources allowing to generate the complete mesh with a single pass over the glyphs. // With exact-sized buffers, we would have to build the complete text mesh in managed memory, then copy to GPU. // Current implementation only buffers 1 word for left aligned blocks, or 1 line for middle or right aligned blocks, or nothing at all for single-line text. The vertices go straight to mapped GPU verftex buffer. text.actualTriangles = mds.triangles; drawMeshes.textCommands[sn] = text; // dbgPrintGlyphVertices( dest ); continue; } sDrawRectCommand cmd = drawMeshes.rectCommands[sn]; if (cmd.strokeWidth.HasValue) { RectangleMesh.strokedVertices(dest, id, ref cmd.rect, cmd.strokeWidth.Value); } else { RectangleMesh.filledVertices(dest, id, ref cmd.rect); } } }
override protected void OnLoad(System.EventArgs e) { lastMouseState = OpenTK.Input.Mouse.GetState(); Texture angrySquirrelTexture, angryTurtleTexture, angryDilloTexture; Texture[] worldTextures; Mesh squirrelMesh, turtleMesh, dilloMesh; RectangleMesh[] worldMeshes; float aspectRatio = ClientSize.Width / (float)(ClientSize.Height); projectionMatrix.set(Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspectRatio, 1, 1000)); cameraOnFrame = delegate(Matrix4f mvMatrix) { float radius = 40, y = 20, timeRatio = 0.5f; Vector3 pos = new Vector3( (float)Math.Sin(time.Value * timeRatio) * radius, y, (float)Math.Cos(time.Value * timeRatio) * radius); mvMatrix.set(Matrix4.LookAt(pos, new Vector3(0, y * 0.5f * (1.5f + (float)Math.Sin(time.Value * timeRatio)), 0), new Vector3(0, 1, 0))); }; cameraOnFrame(modelviewMatrix); cameraOnFrame = null; // enable/disable ambientColor.set(0.4f, 0.4f, 0.4f); lightColor.set(1.0f, 1.0f, 1.0f); lightDirUnit.set(0.5f, 1.0f, 0.5f); //lightDirUnit.set( 0.1f, 5.0f, 0.1f ); lightDirUnit.normalize(); //texture = new Texture( "E:\\drop\\logo-dark.jpg" ); angrySquirrelTexture = new Texture("gfx/angry-squirrel.png"); angryTurtleTexture = new Texture("gfx/angry-turtle.png"); angryDilloTexture = new Texture("gfx/angry-armadillo.png"); worldTextures = new Texture[] { new Texture("gfx/drzewka-1.png"), new Texture("gfx/drzewka-3.png"), new Texture("gfx/sky.png"), new Texture("gfx/grass.png"), new Texture("gfx/drzewka-2.png"), new Texture("gfx/drzewka-4.png") }; CreateShaders(); squirrelMesh = new SphereMesh(BALL_RADIUS, 20, 20, true); squirrelMesh.Texture = angrySquirrelTexture; /* * squirrelMesh.UpdateAction = delegate( Mesh model ) { * Matrix4f transform = model.Transform; * transform.setScaleAndRotation( Matrix4.CreateRotationZ( time.Value ) ); * //transform.setTranslationY( BALL_RADIUS + JUMP_HEIGHT * 0.5f * (1 + (float) Math.Sin( time.Value )) ); // hover * //transform.setTranslationY( BALL_RADIUS + JUMP_HEIGHT * (float) Math.Abs( Math.Sin( time.Value ) ) ); // hover * }; * squirrelMesh.UpdateAction( squirrelMesh ); */ //sm.writeOBJ(); meshes.Add(squirrelMesh); turtleMesh = new SphereMesh(BALL_RADIUS * 5, 10, 10, true); turtleMesh.Texture = angryTurtleTexture; /* * turtleMesh.UpdateAction = delegate( Mesh model ) { * Matrix4f transform = model.Transform; * transform.setScaleAndRotation( Matrix4.CreateRotationX( -time.Value ) ); * }; * turtleMesh.UpdateAction( turtleMesh ); */ meshes.Add(turtleMesh); dilloMesh = new SphereMesh(BALL_RADIUS * 2, 20, 20, true); dilloMesh.Texture = angryDilloTexture; /* * dilloMesh.UpdateAction = delegate( Mesh model ) { * Matrix4f transform = model.Transform; * transform.setScaleAndRotation( Matrix4.CreateRotationX( -time.Value ) ); * }; * dilloMesh.UpdateAction( dilloMesh ); */ meshes.Add(dilloMesh); float boxX = 100, boxY = 50, boxZ = 100, shiftX = 0.5f * boxX, shiftY = 0.5f * boxY, shiftZ = 0.5f * boxZ; worldMeshes = new RectangleMesh[] { new RectangleMesh(Vector3f.OZ, boxX, boxY), new RectangleMesh(Vector3f.OZ, boxX, -boxY), new RectangleMesh(Vector3f.OY, boxX, boxZ), new RectangleMesh(Vector3f.OY, -boxX, boxZ), new RectangleMesh(Vector3f.OZ, -boxX, boxY), new RectangleMesh(Vector3f.OZ, boxX, boxY) }; for (int i = worldMeshes.Length - 1; i >= 0; i--) { Mesh m = worldMeshes[i]; m.Texture = worldTextures[i]; meshes.Add(m); } Matrix4f trans; trans = worldMeshes[0].Transform; trans.setZero(); trans.Data[2] = 1; trans.Data[5] = 1; trans.Data[8] = 1; trans.Data[15] = 1; trans.setTranslation(shiftX, shiftY, 0); trans = worldMeshes[1].Transform; trans.setZero(); trans.Data[2] = -1; trans.Data[5] = -1; trans.Data[8] = -1; trans.Data[15] = 1; worldMeshes[1].Transform.setTranslation(-shiftX, shiftY, 0); worldMeshes[2].Transform.setTranslation(0, boxY, 0); worldMeshes[3].Transform.setTranslation(0, 0, 0); worldMeshes[4].Transform.setTranslation(0, shiftY, shiftZ); worldMeshes[5].Transform.setTranslation(0, shiftY, -shiftZ); foreach (Mesh m in meshes) { m.init(); } //bodyManager.Gravity.setZero(); /*SphereBody*/ squirrelBody = new SphereBody(1, BALL_RADIUS); squirrelBody.Transform.setTranslation(40, 40, 40); squirrelBody.RotationSpeed = 1f; /*SphereBody*/ turtleBody = new SphereBody(25, BALL_RADIUS * 5); turtleBody.Transform.setTranslation(0, 20, 0); //turtleBody.Velocity.Y = 5; turtleBody.RotationSpeed = 1f; /*SphereBody*/ dilloBody = new SphereBody(25, BALL_RADIUS * 2); //dilloBody.Transform.setTranslation( -20, 100, -30 ); dilloBody.Transform.setTranslation(0, 30, 0); //dilloBody.Velocity.Y = -5; dilloBody.RotationSpeed = 1f; Vector3f fixPoint = new Vector3f(0, 42, 9); /* * // spring - vertical harmonic oscillator * dilloBody.Forces.Add( delegate( Body obj ) { * Vector3f disp = obj.Transform.getDisplacement( fixPoint ); * float k = 20.0f; * disp.scale( k ); * obj.applyForce( disp ); * } ); */ // springy pendulum - 3D harmonic oscillator dilloBody.Forces.Add(delegate(Body obj) { Vector3f disp = obj.Transform.getDisplacement(fixPoint); float k = 10.0f, l = 15.0f; disp.scale(k * (disp.length() - l)); obj.applyForce(disp); }); planeBodies = new PlaneBody[] { new PlaneBody(new Plane3f(new Vector3f(0, 1, 0), 0)), new PlaneBody(new Plane3f(new Vector3f(0, -1, 0), boxY)), new PlaneBody(new Plane3f(new Vector3f(1, 0, 0), shiftX)), new PlaneBody(new Plane3f(new Vector3f(-1, 0, 0), shiftX)), new PlaneBody(new Plane3f(new Vector3f(0, 0, 1), shiftZ)), new PlaneBody(new Plane3f(new Vector3f(0, 0, -1), shiftZ)) }; foreach (PlaneBody pb in planeBodies) { pb.Friction = 0.1f; bodyManager.addBody(pb); } bodyManager.addBody(squirrelBody, squirrelMesh); bodyManager.addBody(turtleBody, turtleMesh); bodyManager.addBody(dilloBody, dilloMesh); VSync = VSyncMode.On; }
public void strokedRect(Span <ushort> destSpan, int baseVertex) => RectangleMesh.strokedIndices(destSpan, baseVertex);
private void GetLeftCollision () { Rect leftRect = new Rect(); for (int col = 0; col < mapData.Width; ++col) { for (int row = 0; row < mapData.Height; ++row) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (col - 1 >= 0 ) { Tile leftTile = mapData[row, col - 1]; if (IsNormalCollision(leftTile)) { continue; } } else { continue; } leftRect.x = col; leftRect.y = row; while (row + 1 < mapData.Height) { currentTile = mapData[row + 1, col]; if (col - 1 >= 0 ) { Tile leftTile = mapData[row, col - 1]; if (IsNormalCollision(leftTile)) { --row; break; } } if (IsNormalCollision(currentTile)) { ++row; } else { break; } } leftRect.width = 0; leftRect.height = row - leftRect.y + 1; RectangleMesh leftMesh = new RectangleMesh(leftRect); leftMesh.BuildVerticalMesh(); meshes.Add(leftMesh.Mesh); } } } }
private MeshBase GetChoosenMesh(MeshCreator meshCreator) { float?minArea = meshCreator.splineSimplification != SplineSimplification.Type.None ? meshCreator.minAbsoluteSplineArea : (float?)null; switch (meshCreator.meshType) { case MeshCreator.MeshType.Triangle: return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1, meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Rectangle: return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Circle: return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius, meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Quadrangle: Vector2[] verts = new Vector2[4] { meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2, meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4 }; return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Ellipse: return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius, meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.PointedCircle: return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius, meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Cake: return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides, meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Convex: return(ConvexMesh.AddConvexMesh(meshCreator.transform.position, MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints), meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Star: return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB, meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Gear: return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius, meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Line: return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth, meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.TriangulatedMesh: return(TriangulatedMesh.Add(meshCreator.transform.position, meshCreator.triangulatedPoints.ToArray(), meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineShape: return(SplineShapeMesh.AddSplineShape(meshCreator.transform.position, meshCreator.splinePoints.ToArray(), meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineCurve: return(SplineCurveMesh.AddSplineCurve(meshCreator.transform.position, meshCreator.splineCurvePoints.ToArray(), meshCreator.splineResolution, meshCreator.splineCurveWidth, meshCreator.splineCurveUseDoubleCollider, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineConvexShape: return(ConvexSplineMesh.AddConvexSpline(meshCreator.transform.position, meshCreator.convexSplinePoints.ToArray(), meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); default: throw new System.ArgumentOutOfRangeException(); } }
private void GetDiagonalCollision () { Rect diagonalRect = new Rect(); for (int row = 0; row < mapData.Height; ++row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsDiagonalCollision(currentTile)) { if (IsLowerCollision(currentTile)) { diagonalRect.x = col; diagonalRect.y = row; diagonalRect.width = 1f; diagonalRect.height = 0.5f; } else // upper collision { diagonalRect.x = col; diagonalRect.y = row + 0.5f; diagonalRect.width = 1f; diagonalRect.height = 0.5f; } if (IsLeftCollision(currentTile)) { diagonalRect.x += 1; diagonalRect.width = -diagonalRect.width; } else { } RectangleMesh diagRectMesh = new RectangleMesh(diagonalRect); diagRectMesh.BuildDiagonalMesh(); if (IsTopCollision(currentTile) || IsLeftCollision(currentTile)) { diagRectMesh.InvertMesh(); } meshes.Add(diagRectMesh.Mesh); } } } }
private void GetRightCollision () { Rect rightRect = new Rect(); for (int col = 0; col < mapData.Width; ++col) { for (int row = 0; row < mapData.Height; ++row) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (col + 1 < mapData.Width) { Tile rightTile = mapData[row, col + 1]; if (IsNormalCollision(rightTile)) { continue; } } else { return; } rightRect.x = col + 1; rightRect.y = row; while (row + 1 < mapData.Height) { currentTile = mapData[row + 1, col]; if (col + 1 < mapData.Width) { Tile rightTile = mapData[row, col + 1]; if (IsNormalCollision(rightTile)) { --row; break; } } if (IsNormalCollision(currentTile)) { ++row; } else { break; } } rightRect.width = 0; rightRect.height = row - rightRect.y + 1; RectangleMesh rightMesh = new RectangleMesh(rightRect); rightMesh.BuildVerticalMesh(); rightMesh.InvertMesh(); meshes.Add(rightMesh.Mesh); } } } }
private void GetCeilingCollision() { Rect ceilingRect = new Rect(); for (int row = mapData.Height - 1; row >= 0; --row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (row - 1 >= 0) { Tile belowTile = mapData[row - 1, col]; if (IsNormalCollision(belowTile)) { continue; } } else { continue; } ceilingRect.x = col; ceilingRect.y = row; while (IsInBounds(row - 1, col + 1)) { currentTile = mapData[row, col + 1]; if (row - 1 >= 0) { Tile belowTile = mapData[row - 1, col]; if (IsNormalCollision(belowTile)) { --col; break; } } if (IsNormalCollision(currentTile)) { ++col; } else { break; } } float floorWidth = col - ceilingRect.x + 1; ceilingRect.width = floorWidth; ceilingRect.height = 0; RectangleMesh ceilingMesh = new RectangleMesh(ceilingRect); ceilingMesh.BuildHorizontalMesh(); ceilingMesh.InvertMesh(); meshes.Add(ceilingMesh.Mesh); } } } }
private void GetFloorCollision () { Rect floorRect = new Rect(); for (int row = 0; row < mapData.Height; ++row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (row + 1 < mapData.Height) { Tile aboveTile = mapData[row + 1, col]; if (IsNormalCollision(aboveTile)) { continue; } } else { return; } floorRect.x = col; floorRect.y = row; while (IsInBounds(row + 1, col + 1)) { currentTile = mapData[row, col + 1]; if (row + 1 < mapData.Height) { Tile aboveTile = mapData[row + 1, col]; if (IsNormalCollision(aboveTile)) { --col; break; } } if (IsNormalCollision(currentTile)) { ++col; } else { break; } } float floorWidth = col - floorRect.x + 1; floorRect.width = floorWidth; floorRect.height = 1; RectangleMesh floorMesh = new RectangleMesh(floorRect); floorMesh.BuildHorizontalMesh(); meshes.Add (floorMesh.Mesh); } } } }
private void GetCeilingCollision () { Rect ceilingRect = new Rect(); for (int row = mapData.Height - 1; row >= 0; --row) { for (int col = 0; col < mapData.Width; ++col) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (row - 1 >= 0) { Tile belowTile = mapData[row - 1, col]; if (IsNormalCollision(belowTile)) { continue; } } else { continue; } ceilingRect.x = col; ceilingRect.y = row; while (IsInBounds(row - 1, col + 1)) { currentTile = mapData[row, col + 1]; if (row - 1 >= 0) { Tile belowTile = mapData[row - 1, col]; if (IsNormalCollision(belowTile)) { --col; break; } } if (IsNormalCollision(currentTile)) { ++col; } else { break; } } float floorWidth = col - ceilingRect.x + 1; ceilingRect.width = floorWidth; ceilingRect.height = 0; RectangleMesh ceilingMesh = new RectangleMesh(ceilingRect); ceilingMesh.BuildHorizontalMesh(); ceilingMesh.InvertMesh(); meshes.Add (ceilingMesh.Mesh); } } } }
private void GetRightCollision() { Rect rightRect = new Rect(); for (int col = 0; col < mapData.Width; ++col) { for (int row = 0; row < mapData.Height; ++row) { Tile currentTile = mapData[row, col]; if (IsNormalCollision(currentTile)) { if (col + 1 < mapData.Width) { Tile rightTile = mapData[row, col + 1]; if (IsNormalCollision(rightTile)) { continue; } } else { return; } rightRect.x = col + 1; rightRect.y = row; while (row + 1 < mapData.Height) { currentTile = mapData[row + 1, col]; if (col + 1 < mapData.Width) { Tile rightTile = mapData[row, col + 1]; if (IsNormalCollision(rightTile)) { --row; break; } } if (IsNormalCollision(currentTile)) { ++row; } else { break; } } rightRect.width = 0; rightRect.height = row - rightRect.y + 1; RectangleMesh rightMesh = new RectangleMesh(rightRect); rightMesh.BuildVerticalMesh(); rightMesh.InvertMesh(); meshes.Add(rightMesh.Mesh); } } } }
public CoreUIImage(RectangleMesh mesh) : base(mesh) { }