public void Transform(Igneel.SceneManagement.Frame frame, GlypComponent component, Igneel.Vector2 p0, Igneel.Vector2 p1) { var disp = p1 - p0; var position = frame.BoundingSphere.Radius > 0? frame.BoundingSphere.Center: frame.GlobalPosition; var Tw = Matrix.Translate(-position); switch (component.Id) { case X: Tw *= Matrix.RotationX(Numerics.ToRadians(disp.Y)); break; case Y: Tw *= Matrix.RotationY(Numerics.ToRadians(disp.X)); break; case Z: Tw *= Matrix.RotationZ(Numerics.ToRadians(disp.Y)); break; } Tw *= Matrix.Translate(position); var localPose = frame.LocalPose; var P = Matrix.Invert(localPose) * frame.GlobalPose; var Tl = P * Tw * Matrix.Invert(P); frame.LocalPose *= Tl; frame.CommitChanges(); }
public GlypComponent HitTest(Vector2 screenPosition) { if (currentGlyp == null || !currentGlyp.Visible) { transformComponent = null; return(null); } transformComponent = currentGlyp.DoHitTest(screenPosition); if (transformComponent != null) { p0 = screenPosition; //MessageBox.Show(transformComponent.Id.ToString()); } return(transformComponent); }
private void CreateMarquer(Matrix transform, GlypComponent component, ShapeBuilder <MeshVertex> builder, Color4 color, GraphicDevice graphics, float offset) { //x*radius = radius+offset //x=(radius+offset)/radius //x=1 + offset/radius var scale = 1 + offset / radius; var scaling = Matrix.Scale(scale, 1, scale); transform = scaling * transform; var data = new VertexPositionColor[builder.Vertices.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(Vector3.TransformCoordinates(builder.Vertices[i].Position, transform), color); } component.VertexBuffer = graphics.CreateVertexBuffer(data: data); component.IndexBufffer = graphics.CreateIndexBuffer(data: builder.Indices); }
public CoordinateGlyp Initialize() { var graphics = Engine.Graphics; GlypComponent[] components; if (EnablePlanes) { components = new GlypComponent[6] { new GlypComponent { Id = X }, new GlypComponent { Id = Y }, new GlypComponent { Id = Z }, new GlypComponent { Id = XY }, new GlypComponent { Id = XZ }, new GlypComponent { Id = YZ } }; } else { components = new GlypComponent[3] { new GlypComponent { Id = X }, new GlypComponent { Id = Y }, new GlypComponent { Id = Z } }; } Components = components; var arrow = new ConeBuilder(16, 16, arrowRadius, arrowHeight); //var trunk2 = trunk; // new CylindreBuilder(16, 16, 1, 10, false); //cylyndre = new Component { Color = new Color4(1, 1, 1, 1), Axix = AxisName.None }; //VertexPositionColor[] data2 = new VertexPositionColor[trunk2.Vertices.Length]; //var transform2 = Matrix.RotationZ(-Numerics.PIover2) * Matrix.Translate(0.5f * trunk2.height, 0, 0); //for (int i = 0; i < data2.Length; i++) //{ // data2[i] = new VertexPositionColor(Vector3.TransformCoordinates(trunk2.Vertices[i].Position, transform2), new Color4(1, 1, 0, 0)); //} //cylyndre.VertexBuffer = graphics.CreateVertexBuffer(data: data2); //cylyndre.IndexBufffer = graphics.CreateIndexBuffer(data: trunk2.Indices); // X Axis var xAxis = components[0]; VertexPositionColor[] data = new VertexPositionColor[arrow.Vertices.Length]; Matrix transform = Matrix.RotationZ(-Numerics.PIover2) * Matrix.Translate(0.5f * arrow.height + trunkHeight, 0, 0); for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(Vector3.TransformCoordinates(arrow.Vertices[i].Position, transform), new Color4(alpha, 1, 0, 0)); } xAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); xAxis.IndexBufffer = graphics.CreateIndexBuffer(data: arrow.Indices); //Y Axis var yAxis = components[1]; transform = Matrix.Translate(0, 0.5f * arrow.height + trunkHeight, 0); for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(Vector3.TransformCoordinates(arrow.Vertices[i].Position, transform), new Color4(alpha, 0, 1, 0)); } yAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); yAxis.IndexBufffer = graphics.CreateIndexBuffer(data: arrow.Indices); // Z axis var zAxis = components[2]; transform = Matrix.RotationX(Numerics.PIover2) * Matrix.Translate(0, 0, 0.5f * arrow.height + trunkHeight); for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(Vector3.TransformCoordinates(arrow.Vertices[i].Position, transform), new Color4(alpha, 0, 0, 1)); } zAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); zAxis.IndexBufffer = graphics.CreateIndexBuffer(data: arrow.Indices); if (EnablePlanes) { //XY BoxBuilder box = new BoxBuilder(width, width, tick); var xyAxis = components[3]; data = new VertexPositionColor[box.Vertices.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(box.Vertices[i].Position, new Color4(alpha, 1, 0, 0)); } xyAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); xyAxis.IndexBufffer = graphics.CreateIndexBuffer(data: box.Indices); //XZ box = new BoxBuilder(width, tick, width); var xzAxis = components[4]; data = new VertexPositionColor[box.Vertices.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(box.Vertices[i].Position, new Color4(alpha, 0, 0, 1)); } xzAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); xzAxis.IndexBufffer = graphics.CreateIndexBuffer(data: box.Indices); //YZ box = new BoxBuilder(tick, width, width); var yzAxis = components[5]; data = new VertexPositionColor[box.Vertices.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new VertexPositionColor(box.Vertices[i].Position, new Color4(alpha, 0, 1, 0)); } yzAxis.VertexBuffer = graphics.CreateVertexBuffer(data: data); yzAxis.IndexBufffer = graphics.CreateIndexBuffer(data: box.Indices); } return(this); }
public void Transform(Igneel.SceneManagement.Frame tranlatable, GlypComponent component, Igneel.Vector2 p0, Igneel.Vector2 p1) { throw new NotImplementedException(); }
public void Transform(Frame frame, GlypComponent component, Vector2 p0, Vector2 p1) { var dp = p1 - p0; var viewPort = Engine.Graphics.ViewPort; var camera = Engine.Scene.ActiveCamera; var view = camera.View; var proj = camera.Projection; var world = frame.GlobalPose; var invWorld = Matrix.Invert(frame.GlobalPose); var worlPosition = frame.BoundingSphere.Center; var vpSize = new Size(viewPort.Width, viewPort.Height); //var viewDisplacement = ComputeViewDisplacement(dp.X, dp.Y, worlPosition, vpSize, view, proj); //var localDisplacement = Vector3.TransformCoordinates(viewDisplacement, invWorld); //var d = localDisplacement.Length(); //float sigh; //Compute View Translation var projPosition = Vector3.TransformCoordinates(frame.GlobalPosition, camera.ViewProj); Vector3 pw0 = ScreenToWorld(camera.InvViewProjection, p0, vpSize, projPosition.Z); Vector3 pw1 = ScreenToWorld(camera.InvViewProjection, p1, vpSize, projPosition.Z); var dw = pw1 - pw0; if (dw.IsZero()) { return; } Vector3 translation = new Vector3(); switch (component.Id) { case X: translation = new Vector3(dw.X, 0, 0); break; case Y: translation = new Vector3(0, dw.Y, 0); break; case Z: translation = new Vector3(0, 0, dw.Z); break; case XY: translation = new Vector3(dw.X, dw.Y, 0); break; case XZ: translation = new Vector3(dw.X, 0, dw.Z); break; case YZ: translation = new Vector3(0, dw.Y, dw.Z); break; } var localPose = frame.LocalPose; var Tw = Matrix.Translate(translation); var P = Matrix.Invert(localPose) * frame.GlobalPose; var Tl = P * Tw * Matrix.Invert(P); frame.LocalPose *= Tl; frame.CommitChanges(); }