コード例 #1
0
        private void CreateCamera()
        {
            // Create a camera
            Camera camera = new Camera();

            // Set the vertical field of view to be 60 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(60);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Now assign this camera to a camera node, and add this camera node to our scene graph
            CameraNode cameraNode = new CameraNode(camera);

            scene.RootNode.AddChild(cameraNode);

            // Assign the camera node to be our scene graph's current camera node
            scene.CameraNode = cameraNode;
        }
コード例 #2
0
ファイル: CameraNode.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Creates a scene graph node that holds the camera properties of the viewer with a specified
        /// node name.
        /// </summary>
        /// <param name="name">The name of this camera node</param>
        /// <param name="camera">The actual camera properties associated with this node</param>
        public CameraNode(String name, Camera camera)
            : base(name)
        {
            this.camera = camera;
            
            worldTransform = Matrix.Identity;
            compoundViewMatrix = Matrix.Identity;
            leftCompoundMatrix = Matrix.Identity;
            rightCompoundMatrix = Matrix.Identity;

            if (camera != null)
            {
                if (camera is StereoCamera)
                    isStereo = true;
                else
                    isStereo = false;

                viewFrustum = new BoundingFrustum(camera.Projection);
                leftViewFrustum = new BoundingFrustum(camera.Projection);
                rightViewFrustum = new BoundingFrustum(camera.Projection);
            }
        }
コード例 #3
0
        private void CreateCamera()
        {
            // Create a camera
            Camera camera = new Camera();

            if (State.IsServer)
            {
                camera.Translation = new Vector3(0, 5, 10);
                camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-25));
            }
            else
            {
                camera.Translation = new Vector3(0, 0, -30);
                camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.Pi);
            }
            // Set the vertical field of view to be 60 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(60);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Now assign this camera to a camera node, and add this camera node to our scene graph
            CameraNode cameraNode = new CameraNode(camera);
            scene.RootNode.AddChild(cameraNode);

            // Assign the camera node to be our scene graph's current camera node
            scene.CameraNode = cameraNode;
        }
コード例 #4
0
ファイル: Tutorial6.cs プロジェクト: NinjaSteph/SureShot
        private void CreateCamera()
        {
            // Set up the camera of the scene graph
            Camera camera = new Camera();
            // Put the camera at (0, 0, 0)
            camera.Translation = new Vector3(0, 50, 120);
            // Rotate the camera -45 degrees along the X axis
            camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(-30));
            // Set the vertical field of view to be 45 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(45);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Now assign this camera to a camera node, and add this camera node to our scene graph
            CameraNode cameraNode = new CameraNode(camera);
            scene.RootNode.AddChild(cameraNode);

            // Assign the camera node to be our scene graph's current camera node
            scene.CameraNode = cameraNode;
        }
コード例 #5
0
ファイル: Tutorial17.cs プロジェクト: NinjaSteph/SureShot
        private void CreateCamera()
        {
            // Create a camera
            Camera camera = new Camera();
            // Put the camera at (0, 0, 10)
            camera.Translation = new Vector3(0, 0, 10);
            // Set the vertical field of view to be 60 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(60);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Now assign this camera to a camera node, and add this camera node to our scene graph
            CameraNode cameraNode = new CameraNode(camera);
            scene.RootNode.AddChild(cameraNode);

            // Assign the camera node to be our scene graph's current camera node
            scene.CameraNode = cameraNode;
        }
コード例 #6
0
ファイル: Tutorial7.cs プロジェクト: NinjaSteph/SureShot
        private void CreateCamera()
        {
            // Set up the camera of the scene graph
            Camera camera = new Camera();
            // Put the camera at (0, 3, 7)
            camera.Translation = new Vector3(0, 3, 7);
            // Rotate the camera -15 degrees along the X axis
            camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(-15));
            // Set the vertical field of view to be 45 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(45); 
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Set the initial translation and rotation of the generic input which controls 
            // the camera transform in this application
            GenericInput.Instance.InitialTranslation = camera.Translation;
            GenericInput.Instance.InitialRotation = camera.Rotation;

            // Adjust the speed of the camera control
            GenericInput.Instance.PanSpeed = 0.05f;
            GenericInput.Instance.ZoomSpeed = 0.5f;
            GenericInput.Instance.RotateSpeed = 0.02f;

            // Now assign this camera to a camera node
            CameraNode cameraNode = new CameraNode(camera);

            // Add a transform node which will be updated based on GenericInput class
            // which implements simple camera rotation and translation based on mouse
            // drag and key presses.
            // To rotate the camera, hold right mouse button and drag around
            genericInputNode = new TransformNode();

            scene.RootNode.AddChild(genericInputNode);
            genericInputNode.AddChild(cameraNode);

            // Assign the camera node to be our scene graph's current camera node
            scene.CameraNode = cameraNode;
        }
コード例 #7
0
        private void CreateCamera()
        {
            // Create a camera for 2D visualization 
            staticCamera = new Camera();
            staticCamera.Translation = new Vector3(0, 0, 0);
            staticCamera.FieldOfViewY = MathHelper.ToRadians(45);
            staticCamera.ZNearPlane = 1.0f;
            staticCamera.ZFarPlane = 1000;
            staticCamera.AspectRatio = (float)(graphics.PreferredBackBufferWidth / graphics.PreferredBackBufferHeight);

            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(staticCamera.FieldOfViewY, staticCamera.AspectRatio,
                                                        staticCamera.ZNearPlane, staticCamera.ZFarPlane);
            viewMatrix = Matrix.CreateLookAt(new Vector3(0,0,-10),Vector3.Zero, Vector3.Up);
            staticCamera.View = viewMatrix;
            staticCamera.Projection = projectionMatrix;
          
            // Now assign camera to a camera node, and add this camera node to our scene graph
            staticCameraNode = new CameraNode(staticCamera);
            scene.RootNode.AddChild(staticCameraNode);

            scene.CameraNode = staticCameraNode;

        }
コード例 #8
0
ファイル: Camera.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="cam"></param>
        public Camera(Camera cam)
        {
            translation = cam.Translation;
            rotation = cam.Rotation;
            view = cam.View;
            projection = cam.Projection;
            fieldOfView = cam.FieldOfViewY;
            aspectRatio = cam.AspectRatio;
            zNearPlane = cam.ZNearPlane;
            zFarPlane = cam.ZFarPlane;

            modifyView = false;
            modifyProjection = false;
        }
コード例 #9
0
ファイル: CameraNode.cs プロジェクト: NinjaSteph/SureShot
 /// <summary>
 /// Creates a scene graph node that holds the camera properties of the viewer.
 /// </summary>
 /// <param name="camera"></param>
 public CameraNode(Camera camera) : this("", camera) { }
コード例 #10
0
ファイル: CameraNode.cs プロジェクト: NinjaSteph/SureShot
        public override void Load(XmlElement xmlNode)
        {
            base.Load(xmlNode);

            if (xmlNode.HasAttribute("Stereo"))
                isStereo = bool.Parse(xmlNode.GetAttribute("Stereo"));

            camera = (Camera)Activator.CreateInstance(Type.GetType(xmlNode.FirstChild.Name));
            camera.Load((XmlElement)xmlNode.FirstChild);

            viewFrustum = new BoundingFrustum(camera.Projection);
            leftViewFrustum = new BoundingFrustum(camera.Projection);
            rightViewFrustum = new BoundingFrustum(camera.Projection);
        }
コード例 #11
0
        private void CreateCameras()
        {
            // Create the main camera
            mainCamera = new Camera();
            mainCamera.Translation = new Vector3(0, -30, -100);
            mainCamera.ZNearPlane = 1;
            mainCamera.ZFarPlane = 2000;

            mainCameraNode = new CameraNode(mainCamera);
            scene.RootNode.AddChild(mainCameraNode);

            // Create the flying camera
            flyingCamera = new Camera();
            flyingCamera.Translation = new Vector3(0, 0, 200);
            flyingCamera.ZNearPlane = 1;
            flyingCamera.ZFarPlane = 2000;

            cameraTrans = new TransformNode();

            flyingCameraNode = new CameraNode(flyingCamera);
            groundMarkerNode.AddChild(cameraTrans);
            cameraTrans.AddChild(flyingCameraNode);

            scene.CameraNode = mainCameraNode;
        }
コード例 #12
0
        private void CreateCameras()
        {
            // Create a camera for VR scene 
            Camera vrCamera = new Camera();
            vrCamera.Translation = new Vector3(0, -280, 480);
            vrCamera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(45));
            vrCamera.FieldOfViewY = MathHelper.ToRadians(60);
            vrCamera.ZNearPlane = 1;
            vrCamera.ZFarPlane = 2000;

            vrCameraNode = new CameraNode(vrCamera);
            scene.RootNode.AddChild(vrCameraNode);

            // Create a camera for AR scene
            Camera arCamera = new Camera();
            arCamera.ZNearPlane = 1;
            arCamera.ZFarPlane = 2000;

            arCameraNode = new CameraNode(arCamera);
            scene.RootNode.AddChild(arCameraNode);

            // Set the AR camera to be the main camera so that at the time of setting up the marker tracker,
            // the marker tracker will assign the right projection matrix to this camera
            scene.CameraNode = arCameraNode;
        }
コード例 #13
0
ファイル: Tutorial12.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Creates a camera that chases a given object.
        /// </summary>
        /// <param name="chasedObject"></param>
        private void CreateChasingCamera(GeometryNode chasedObject)
        {
            // Set up the camera of the scene graph
            Camera camera = new Camera();

            camera.Translation = new Vector3(5, 3, 0);
            // Rotate the camera -20 degrees along the X axis
            camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 
                MathHelper.ToRadians(90)) * Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(-20));
            // Set the vertical field of view to be 60 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(45);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Add this camera node to a geometry node we want to chase for
            CameraNode cameraNode = new CameraNode("ChasingCamera", camera);
            chasedObject.AddChild(cameraNode);

            // Initially assign the chasing camera to be our scene graph's active camera node
            scene.CameraNode = cameraNode;
        }
コード例 #14
0
ファイル: Tutorial12.cs プロジェクト: NinjaSteph/SureShot
        private void CreateStaticCamera(bool near)
        {
            // Set up the camera of the scene graph
            Camera camera = new Camera();

            if (near)
                camera.Translation = new Vector3(0, 0, 0);
            else
                camera.Translation = new Vector3(0, 10, 55);

            // Rotate the camera -20 degrees along the X axis
            camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(-20));
            // Set the vertical field of view to be 45 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(45);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            String prefix = (near) ? "Near" : "Far";
            // Add this camera node to our scene graph
            CameraNode cameraNode = new CameraNode(prefix + "Camera", camera);
            scene.RootNode.AddChild(cameraNode);
        }