private void renderSnapInformation(XNAGame game, Matrix transformation, SnapInformation snapInformation, Dictionary <SnapType, Color> colorTypeMap) { for (int j = 0; j < snapInformation.SnapList.Count; j++) { SnapPoint point = snapInformation.SnapList[j]; Vector3 startPos = point.Position; var color = colorTypeMap[point.SnapType]; game.LineManager3D.AddLine(Vector3.Transform(startPos, transformation), Vector3.Transform(startPos + point.Normal, transformation), color); game.LineManager3D.AddLine(Vector3.Transform(startPos, transformation), Vector3.Transform(startPos + point.Up, transformation), color); } }
public SnapInformation CreateFromTile(TileData data) { SnapInformation information = new SnapInformation(); for (int i = 0; i < 6; i++) { var tileFace = (TileFace)(i + 1); if (data.GetFaceType(tileFace) == null) { continue; } var faceType = data.GetFaceType(tileFace); SnapPoint point = GetPoint(data, tileFace, faceType, data.GetTotalWinding(tileFace)); point.TileFaceType = faceType; information.addSnapObject(point); } return(information); }
public void TestSnapPointToPoint() { XNAGame game = new XNAGame(); SnapInformation inf1 = new SnapInformation(); SnapInformation inf2 = new SnapInformation(); SnapPoint p1 = new SnapPoint(); p1.Position = new Vector3(1.7f, 1, 1); p1.Normal = new Vector3(0, 0, 1); p1.Normal.Normalize(); p1.Up = new Vector3(0, -1, 0); p1.Up.Normalize(); SnapPoint p2 = new SnapPoint(); p2.Position = new Vector3(1, 1, 1); p2.Normal = new Vector3(1, 0, 0); p2.Normal.Normalize(); p2.Up = new Vector3(0, -1, 0); p2.Up.Normalize(); SnapPoint p3 = new SnapPoint(); p3.Position = new Vector3(2, 0, 2); p3.Normal = new Vector3(1, 1, 0); p3.Normal.Normalize(); p3.Up = new Vector3(1, -1, 0); p3.Up.Normalize(); SnapType type = new SnapType("t1"); p1.SnapType = type; p2.SnapType = type; inf1.addSnapObject(p1); inf1.addSnapObject(p3); inf2.addSnapObject(p2); SnapEngineClass snapEngine = new SnapEngineClass(); snapEngine.addSnapInformation(inf1); snapEngine.addSnapInformation(inf2); SphereMesh sphere1 = new SphereMesh(0.2f, 24, Color.Green); SphereMesh sphere2 = new SphereMesh(0.2f, 24, Color.Yellow); SphereMesh sphere3 = new SphereMesh(0.2f, 24, Color.Green); sphere1.WorldMatrix = Matrix.CreateTranslation(p1.Position); sphere2.WorldMatrix = Matrix.CreateTranslation(p2.Position); sphere3.WorldMatrix = Matrix.CreateTranslation(p3.Position); game.AddXNAObject(sphere1); game.AddXNAObject(sphere2); game.AddXNAObject(sphere3); game.DrawEvent += delegate { game.LineManager3D.AddLine(p1.Position, p1.Position + 0.5f * p1.Normal, Color.Red); game.LineManager3D.AddLine(p1.Position, p1.Position + 0.5f * p1.Up, Color.Yellow); game.LineManager3D.AddLine(p3.Position, p3.Position + 0.5f * p3.Normal, Color.Red); game.LineManager3D.AddLine(p3.Position, p3.Position + 0.5f * p3.Up, Color.Yellow); game.LineManager3D.AddLine(p2.Position, p2.Position + 0.5f * p2.Normal, Color.Red); game.LineManager3D.AddLine(p2.Position, p2.Position + 0.5f * p2.Up, Color.Yellow); }; game.UpdateEvent += delegate { if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter)) { snapEngine.SnapTo(inf1, inf2); sphere1.WorldMatrix = Matrix.CreateTranslation(p1.Position); sphere2.WorldMatrix = Matrix.CreateTranslation(p2.Position); sphere3.WorldMatrix = Matrix.CreateTranslation(p3.Position); } }; game.Run(); }