public void SetParent(Anchor parent, bool translate=true) { if (!IsPivot) { throw new Exception("SetParent can only be called on a Pivot."); } var absolutePosition = GetAbsolutePosition(); if (Parent != null) { Parent.Children.Remove(ModelPart); } Parent = parent; Parent.Children.Add(ModelPart); if (translate) { ModelPart.Position = absolutePosition - parent.GetAbsolutePosition(); } }
public static AnchorAnimState FromAnchor(Anchor anchor) { return new AnchorAnimState(anchor, anchor.Rotation); }
public bool Ignores(Anchor anchor) { return _ignoredModelParts.Contains(anchor.ModelPart); }
public AnchorAnimState(Anchor anchor, Vector3 rotation) { Anchor = anchor; Rotation = rotation; }
public void Anchor(Anchor anchor) { var dataStream = _vertexRenderer.LockVertexBuffer(); var colour = anchor == SelectedAnchor ? Colours.Yellow : Colours.Green; _anchorCuboid.Position = new Vector3(); int renderCount = 12; // front clockwise dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontTop, colour)); // rear clockwise dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackTop, colour)); // front to back dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.LeftBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackBottom, colour)); // spike. if (anchor.Rotation.Length > 0) { var pos = _anchorCuboid.RightFrontTop.Translate(0.2f, 0, 0); pos = pos.Translate(0, _anchorCuboid.Size.Y / 2.0f, _anchorCuboid.Size.Z); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontTop, colour)); dataStream.Write(new TexturedColouredVertex4(pos, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackTop, colour)); dataStream.Write(new TexturedColouredVertex4(pos, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightBackBottom, colour)); dataStream.Write(new TexturedColouredVertex4(pos, colour)); dataStream.Write(new TexturedColouredVertex4(_anchorCuboid.RightFrontBottom, colour)); dataStream.Write(new TexturedColouredVertex4(pos, colour)); renderCount += 4; } _vertexRenderer.UnlockVertexBuffer(); SetTexture(-1); var posMat = Matrix.Translation(anchor.Position); var tmat = WorldMatrix; WorldMatrix = anchor.GetRotationMatrix() * posMat * WorldMatrix; _effect.SetMatrix("worldMat", WorldMatrix); _effect.SetMatrix("worldViewProjMat", WorldMatrix * _viewMat * _projection); _effect.CommitChanges(); WorldMatrix = tmat; _vertexRenderer.RenderForShader(PrimitiveType.LineList, 0, renderCount); // render child anchor lines. var wmat = WorldMatrix; foreach (var child in anchor.Children) { var dataStream2 = _vertexRenderer.LockVertexBuffer(); dataStream2.Write(new TexturedColouredVertex4(new Vector3(), colour)); dataStream2.Write(new TexturedColouredVertex4(child.Position, colour)); _vertexRenderer.UnlockVertexBuffer(); _vertexRenderer.RenderForShader(PrimitiveType.LineList, 0, 1); } WorldMatrix = wmat; }