public void Attach(Node attachPoint, int myPoint, GameObject sword, Player player) { this.player = player; parent = attachPoint.parent; // Attach this sword part by making the node point at myPoint // equivelant to the attach point FInt a1 = FInt.Atan(nodePoints[myPoint].dir.x, nodePoints[myPoint].dir.y); FInt a2 = FInt.Atan(attachPoint.dir.x, attachPoint.dir.y); FInt angle = a2 - a1 + new FInt(3.1415f); rotation = angle; FInt px = nodePoints[myPoint].pos.x; FInt py = nodePoints[myPoint].pos.y; FInt length = FInt.Sqrt((px * px) + (py * py)); FInt a3 = FInt.Atan(px, py); FInt transx = length * FInt.Cos(a3 + angle); FInt transy = length * FInt.Sin(a3 + angle); position = new FVector(attachPoint.pos.x - transx, attachPoint.pos.y - transy); transform.localEulerAngles = new Vector3(0, 0, rotation.ToFloat() * 180.0f / Mathf.PI); transform.localPosition = new Vector3(_position.x.ToFloat(), _position.y.ToFloat()); // TODO: Find depthInSword via recursive transformations // BREAKS: Proper sword construction }
public void AddPart(SwordPart part) { Node n = freeNodes[0]; FInt w = 0L; // First iteration counts the weight foreach (Node m in freeNodes) { if (m.parent.depthInSword < 0L) { continue; } w += new FInt(1.0f) + m.parent.depthInSword * m.parent.depthInSword; } if (w == 0L) { return; } FInt choose = FInt.RandomRange(OnlineNetwork.seed, 0L, w); // Second iteration finds the part at a random weight w = 0L; foreach (Node m in freeNodes) { if (m.parent.depthInSword < 0L) { continue; } w += new FInt(1.0f) + m.parent.depthInSword * m.parent.depthInSword; if (choose <= w) { n = m; break; } } part.transform.SetParent(n.parent.transform); int attachPoint = Random.Range(0, part.nodePoints.Length); part.Attach(n, attachPoint, this.gameObject, owner); freeNodes.Remove(n); part.consumedNode = n; for (int i = 0; i < part.nodePoints.Length; ++i) { if (i == attachPoint) { continue; } freeNodes.Add(part.nodePoints[i]); } parts.Add(part); weight += part.weight; }