Esempio n. 1
0
 private void Control_MouseUp(object sender, MouseEventArgs e)
 {
     if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
     {
         Unhighlight();
         _selectedAxis = null;
         _pressedAxis  = null;
         _dragPlane    = null;
     }
 }
Esempio n. 2
0
        private void SetPlanes()
        {
            _xyzPlane = new Plane(Vector3.One.Normalized, -CrossInner / MathF.Sqrt(3));
            _xyPlane  = new Plane(Vector3.UnitZ, 0);
            _xzPlane  = new Plane(Vector3.UnitY, 0);
            _yzPlane  = new Plane(Vector3.UnitX, 0);

            _xBox = new Box(new Vector3(0.5f, 0, 0), new Vector3(1, ColliderWidth, ColliderWidth));
            _yBox = new Box(new Vector3(0, 0.5f, 0), new Vector3(ColliderWidth, 1, ColliderWidth));
            _zBox = new Box(new Vector3(0, 0, 0.5f), new Vector3(ColliderWidth, ColliderWidth, 1));
        }
Esempio n. 3
0
        private void StartMove()
        {
            _pressedAxis = _selectedAxis;

            var camDirection = Transform.WorldPosition - Scene.MainCamera.Transform.WorldPosition;

            switch (_pressedAxis)
            {
            case Axis.X:
                _movePlane = new Plane(new Vector3(0, camDirection.Y, camDirection.Z), 0);
                break;

            case Axis.Y:
                _movePlane = new Plane(new Vector3(camDirection.X, 0, camDirection.Z), 0);
                break;

            case Axis.Z:
                _movePlane = new Plane(new Vector3(camDirection.X, camDirection.Y, 0), 0);
                break;

            case Axis.XY:
                _movePlane = _xyPlane;
                break;

            case Axis.YZ:
                _movePlane = _yzPlane;
                break;

            case Axis.XZ:
                _movePlane = _xzPlane;
                break;

            case Axis.XYZ:
                _movePlane = _xyzPlane;
                break;

            default:
                throw new NotImplementedException();
            }

            var hit = GetMovePlaneIntersection();

            _startMovePoint = hit.Point;
        }
Esempio n. 4
0
        protected override void OnInit()
        {
            base.OnInit();

            _material = new Material(MaterialType.FlatVertexColor);

            var frag = @"
void getFragment(inout fragment_info fragment) {
    fragment.normal = frag_in.normal;

	if(dot(normalize(fragment.normal), normalize(-frag_in.view_pos)) > -0.25)
		fragment.emission = frag_in.color.xyz;
	else
		fragment.emission = vec3(0.75, 0.75, 0.75);
    fragment.albedo = vec4(0.0, 0.0, 0.0, 1.0);
}
";

            _renderer          = SceneObject.AddComponent <MeshRenderable>();
            _renderer.Material = new Material(null, frag, RenderQueue.Opaque);

            var circle = Ellipse.Create(Quaternion.Identity, Vector2.One * Radius, CircleSegmentCount);

            var meshBuilder = new MeshBuilder();

            meshBuilder.AddMesh(circle);
            meshBuilder.AddMesh(circle, Quaternion.CreateFromYawPitchRoll(0, MathF.PIOver2, 0));
            meshBuilder.AddMesh(circle, Quaternion.CreateFromYawPitchRoll(MathF.PIOver2, 0, 0));

            var mesh = meshBuilder.GetMesh();

            mesh.DrawStyle = PolygonMode.Line;
            mesh.Type      = PrimitiveType.Lines;
            mesh.Colors    = new Vector3Buffer(CircleSegmentCount * 3);
            _renderer.Mesh = mesh;

            RestoreColors();

            _sphere = new Sphere(Vector3.Zero, Radius);
            _xPlane = new Plane(new Vector3(1, 0, 0), 0);
            _yPlane = new Plane(new Vector3(0, 1, 0), 0);
            _zPlane = new Plane(new Vector3(0, 0, 1), 0);
        }
Esempio n. 5
0
        private RaycastHit RaycastAxisPlane(Ray ray, Plane plane)
        {
            var hit = plane.Raycast(ray);

            if (hit == null)
            {
                return(null);
            }

            var distanceToCenter = hit.Point.Length;

            if (distanceToCenter > Radius - MinDistance && distanceToCenter < Radius + MinDistance)
            {
                return(hit);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        private void StartMove()
        {
            _dragPlane = new Plane();
            var camDirection = Transform.WorldPosition - Scene.MainCamera.Transform.WorldPosition;

            switch (_pressedAxis.Value)
            {
            case Axis.X:
                _dragPlane.Normal = new Vector3(0, camDirection.Y, camDirection.Z);
                break;

            case Axis.Y:
                _dragPlane.Normal = new Vector3(camDirection.X, 0, camDirection.Z);
                break;

            case Axis.Z:
                _dragPlane.Normal = new Vector3(camDirection.X, camDirection.Y, 0);
                break;

            case Axis.XY:
                _dragPlane.Normal = new Vector3(0, 0, 1);
                break;

            case Axis.YZ:
                _dragPlane.Normal = new Vector3(1, 0, 0);
                break;

            case Axis.XZ:
                _dragPlane.Normal = new Vector3(0, 1, 0);
                break;

            default:
                throw new NotImplementedException();
            }

            var hit = GetMovePlaneIntersection();

            _moveOffset = Transform.LocalPosition - hit.Point;
        }