public Quad(QuadRoot tree, Quad parent, Rectangle rectangle) { this.tree = tree; this.parent = parent; this.rectangle = rectangle; this.imageX = this.rectangle.X / this.rectangle.Width; this.imageY = this.rectangle.Y / this.rectangle.Height; // Console.Out.WriteLine("Creating quad with " + this.rectangle + " this.GetDepth() = " + this.GetDepth() + ", maxDepth = " + tree.depth); if (this.GetDepth() == tree.depth) { this.isLeaf = true; tree.leafList.AddLast(this); if (tree.collisionMap.game != null) { if (!tree.collisionMap.drawMode) { this.collisionTexture = new CollisionTexture(this, tree.collisionMap.game.Content.Load<Texture2D> (tree.collisionMap.collisionMapPath + "/" + tree.collisionMap.collisionMapName + "_" + imageX + "_" + imageY)); } else this.collisionTexture = new CollisionTexture(this, new Texture2D(tree.collisionMap.graphicsDevice, this.rectangle.Width, this.rectangle.Height)); } else { this.collisionTexture = new CollisionTexture(this, new Texture2D(tree.collisionMap.graphicsDevice, this.rectangle.Width, this.rectangle.Height)); } } }
public static QuadRoot Quad(double yminus, double yzero, double yplus) { //Finds a parabola through three points // (-1,yminus), (0,yzero), (1,yplus) // that do not lie on a straight line. double a, b, c, dis, dx; QuadRoot qr = new QuadRoot(); qr.nz = 0; a = 0.5 * (yminus + yplus) - yzero; b = 0.5 * (yplus - yminus); c = yzero; qr.xe = -b / (2 * a); qr.ye = ((a * qr.xe + b) * qr.xe) + c; dis = Math.Pow(b, 2) - (4 * a * c); if (dis >= 0) { dx = 0.5 * Math.Sqrt(dis) / Math.Abs(a); qr.zero1 = qr.xe - dx; qr.zero2 = qr.xe + dx; if (Math.Abs(qr.zero1) <= 1) { qr.nz = qr.nz + 1; } if (Math.Abs(qr.zero2) <= 1) { qr.nz = qr.nz + 1; } if (qr.zero1 < -1) { qr.zero1 = qr.zero2; } } return(qr); }