Пример #1
0
        private void MoveDynamicCamera(ComplexObject sceneObjects)
        {
            var complexObjects = sceneObjects.GetComplexObjectsWiThGlobalModelMatrices();
            var cameras        = sceneObjects.GetCamerasWiThGlobalModelMatrices();

            var car           = complexObjects.FirstOrDefault(x => x.Object.Name == "RedCar");
            var dynamicCamera = cameras.FirstOrDefault(x => x.Object.Name == "DynamicCamera");

            if (car != null && dynamicCamera != null)
            {
                var direction        = dynamicCamera.Object.Position - car.Object.Position;
                var vectorY          = new Vector3(direction.X, 0, direction.Z);
                var defaultDirection = -Vector3.UnitZ;

                var angleX = Vector3.CalculateAngle(direction, vectorY);

                var angleY = Vector3.CalculateAngle(vectorY, defaultDirection);
                if (vectorY.X > 0)
                {
                    angleY = 2 * (float)Math.PI - angleY;
                }

                dynamicCamera.Object.Rotation = new Vector3(angleX, angleY, 0);
            }
        }