コード例 #1
0
        public static BaseComponent LoadFromDefinition(ContentManager content, string definitionPath, BaseEntity parent)
        {
            CameraComponentDefinition compDef = content.Load <CameraComponentDefinition>(definitionPath);

            CameraComponent newComponent = new CameraComponent(parent, compDef);

            return(newComponent);
        }
コード例 #2
0
        public CameraComponent(BaseEntity parent, CameraComponentDefinition compDef)
            : base(parent)
        {
            ActivateComponent();

            // If the definition file specifies something greater than zero for the aspect ratio then we
            // ignore it and let the default take over.
            if (compDef.AspectRatio > 0.0f)
            {
                this.lockAspectRatioToViewport = false;
                this.aspectRatio = compDef.AspectRatio;
            }
            else
            {
                this.lockAspectRatioToViewport = true;
                this.aspectRatio = this.parentEntity.Game.GraphicsDevice.Viewport.AspectRatio;
            }

            if (this.aspectRatio < float.Epsilon)
            {
                throw new ArgumentOutOfRangeException("aspectRatio cannot be zero or a negative value");
            }

            if (compDef.DefaultFOV > 0.0f)
            {
                this.defaultFOV = compDef.DefaultFOV;
            }

            if (compDef.StartingFOV > 0.0f)
            {
                this.FOV = compDef.StartingFOV;
            }

            this.zoomLevel = compDef.StartingZoomLevel;

            if (compDef.NearPlane > 0.0f)
            {
                this.NearPlane = compDef.NearPlane;
            }

            if (compDef.FarPlane > 0.0f)
            {
                this.FarPlane = compDef.FarPlane;
            }

            this.forceFrustumAboveTerrain = compDef.ForceFrustumAboveTerrain;

            SetFrustum(FOV, aspectRatio, nearPlane, farPlane);
            UpdateProjectionMatrix();

            // @todo: Set hasChanged flag to true (if we use a bool)
        }