예제 #1
0
        public static void OrbitYZ(this Camera camera, double alpha)
        {
            var offset = camera.Frame.Offset;
            var ex     = camera.Frame.Ex;
            var ey     = camera.Frame.Ey;
            var ez     = camera.Frame.Ez;
            var target = offset + ey * camera.Distance;
            var back   = Matrix44D.CreateCoordinateSystem(target, ex, ey, ez);
            var trans  = back.Inverse();

            ey     = new Vector3D(0.0, 1.0, 0.0);
            ez     = new Vector3D(0.0, 0.0, 1.0);
            offset = trans * offset;
            var rotateYZ = Matrix44D.CreateRotation(new Vector3D(1, 0, 0), alpha);

            ey     = rotateYZ * ey;
            ez     = rotateYZ * ez;
            offset = rotateYZ * offset;
            offset = back * offset;
            ey     = back * ey;
            ez     = back * ez;
            ey.Normalize();
            ez.Normalize();
            var newFrame = Matrix44D.CreateCoordinateSystem(offset, ex, ez);

            camera.Frame = newFrame;
        }
예제 #2
0
        public static void MoveTargetTo(this Camera camera, Position3D target)
        {
            var offset = target - (camera.Target - camera.Frame.Offset);
            var ex     = camera.Frame.Ex;
            var ey     = camera.Frame.Ey;
            var ez     = camera.Frame.Ez;

            camera.Target = target;
            camera.Frame  = Matrix44D.CreateCoordinateSystem(offset, ex, ey, ez);
        }
예제 #3
0
        public void InverseTest_WhenStandardCoordinateSystemIsGiven_ThenInverseMultiplyWithCoordinateSystemIsIdentity()
        {
            var vec = Matrix44D.CreateCoordinateSystem(new Position3D(0.0, 0.0, 0.0), new Vector3D(1.0, 0.0, 0.0), new Vector3D(0.0, 0.0, 1.0));

            var inverse = vec.Inverse();

            var ident = inverse * vec;

            Assert.Equal(Matrix44D.Identity, ident);
        }
예제 #4
0
        public void MultiplicationOperatorTest_WhenMatrixMultpliedWithYAxis_ThenResultVectorIsEyOfMatrix()
        {
            var ex    = new Vector3D(1.0, 1.0, 0.0);
            var ey    = new Vector3D(-1.0, 1.0, 0.0);
            var ez    = new Vector3D(0.0, 0.0, 1.0);
            var mat   = Matrix44D.CreateCoordinateSystem(new Position3D(), ex, ey, ez);
            var yAxis = new Vector3D(0.0, 1.0, 0.0);

            var eyNew = mat * yAxis;

            Assert.Equal(ey, eyNew);
        }
예제 #5
0
        public static void Zoom(this Camera camera, double delta)
        {
            if (delta >= camera.Distance)
            {
                delta = camera.Distance;
            }
            var offset = camera.Frame.Offset;
            var ex     = camera.Frame.Ex;
            var ey     = camera.Frame.Ey;
            var ez     = camera.Frame.Ez;

            offset       = offset + ey * delta;
            camera.Frame = Matrix44D.CreateCoordinateSystem(offset, ex, ey, ez);
        }
예제 #6
0
        public void CreateCoordinateSystemTest_WhenCoordinateSystemIsCalledExEz_ThenExEyEzAreEqualToParametersAndAndTranslationIsOrigin()
        {
            var ex = new Vector3D(1.0, 0.0, 0.0);
            var ez = new Vector3D(-1.0, 1.0, 0.0);

            var mat = Matrix44D.CreateCoordinateSystem(ex, ez);

            var ey = new Vector3D(0.0, 0.0, -1.0);

            Assert.Equal(ex, mat.Ex);
            Assert.Equal(ey, mat.Ey);
            Assert.Equal(ez, mat.Ez);
            Assert.Equal(new Position3D(), mat.Offset);
            Assert.Equal(new Vector3D(), mat.Translation);
        }
예제 #7
0
        public void CreateCoordinateSystemTest_WhenCoordinateSystemIsCalledWithExEyEzAndTranslation_ThenExEyEzAndTranslationAreEqualToParameters()
        {
            var ex     = new Vector3D(1.0, 0.0, 0.0);
            var ey     = new Vector3D(0.0, 0.0, -1.0);
            var ez     = new Vector3D(-1.0, 1.0, 0.0);
            var offset = new Position3D(2, 3, 4);

            var mat = Matrix44D.CreateCoordinateSystem(offset, ex, ey, ez);

            Assert.Equal(ex, mat.Ex);
            Assert.Equal(ey, mat.Ey);
            Assert.Equal(ez, mat.Ez);
            Assert.Equal(offset, mat.Offset);
            Assert.Equal(offset.ToVector3D(), mat.Translation);
        }
예제 #8
0
        public static double CounterClockwiseAngleWith(this Vector3D first, Vector3D second)
        {
            double alpha = 0.0f;

            // Calculates coordinate system of t_vecA as X axis
            var ex  = first.Normalize();
            var ez  = ex & second.Normalize();
            var len = ez.Length;

            if (len > ConstantsMath.Epsilon)
            {
                ez = ez.Normalize();

                // Vectors are linear independent
                var ey = ez & ex;
                ey = ey.Normalize();

                // Transforms t_vecB to this coordinate system
                var origin = new Position3D(0.0f, 0.0f, 0.0f);
                var matrix = Matrix44D.CreateCoordinateSystem(origin, ex, ey, ez).Inverse();
                second = matrix * second;

                // Angle between t_vecA as X-Axis and t_vecB
                alpha = (second.X, second.Y).ToAngle();
            }
            else
            {
                // Vectors lies on same line
                if (ex == second)
                {
                    // Vectors have same direction
                    alpha = 0.0f;
                }
                else
                {
                    // Vectors have opposite direction
                    alpha = ConstantsMath.Pi;
                }
            }

            return(alpha);
        }
예제 #9
0
        public SceneStateDto GetScene(int canvasWidth, int canvasHeight)
        {
            var camera = new Camera();

            camera.NearPlane = 1.0;
            camera.Frame     = Matrix44D.CreateCoordinateSystem(
                new Position3D(-56.19932556152344, 77.98228454589844, 50.94441223144531),
                new Vector3D(-0.7851186990737915, -0.6140340566635132, 0.07365952432155609),
                new Vector3D(0.34082478284835815, -0.3296760022640228, 0.8801576495170593));

            _scene.SetBodyStates(_bodyStates);

            var sceneState = new SceneStateDto()
            {
                Camera     = camera.ToCameraDto(),
                BodyStates = _bodyStates,
                DrawLines  = _hiddenLineService.GetHiddenLineGraphics(_scene, camera, canvasWidth, canvasHeight).ToArray()
            };

            return(sceneState);
        }