Inheritance: MonoBehaviour
Beispiel #1
0
        private void InitParallelCamera(Scene scene, SceneControl control)
        {
            parallelCamera             = new LookAtCamera();
            parallelCamera.AspectRatio = (double)AxisWidth / (double)AxisHeight;
            parallelCamera.Near        = 0.001f;
            parallelCamera.Far         = float.MaxValue;

            LookAtCamera modelSceneCamera = control.Scene.CurrentCamera as LookAtCamera;

            if (modelSceneCamera != null)
            {
                Vertex position = modelSceneCamera.Position - modelSceneCamera.Target;
                position.Normalize();
                parallelCamera.Position    = position * 7;
                parallelCamera.UpVector    = modelSceneCamera.UpVector;
                parallelCamera.FieldOfView = modelSceneCamera.FieldOfView;
            }
            else
            {
                parallelCamera.Position    = new Vertex(0f, 0f, 7f);
                parallelCamera.UpVector    = new Vertex(0f, 1f, 0f);
                parallelCamera.FieldOfView = 60;
            }

            scene.CurrentCamera = this.parallelCamera;
        }
Beispiel #2
0
        private FireworksDemo(IntPtr hInstance)
            : base(hInstance)
        {
            MainWindowCaption = "Fireworks Demo";

            _lastMousePos = new Point();

            _camera = new LookAtCamera();
            _camera.LookAt(new Vector3(10, 2, -10), new Vector3(0, 1, 0), Vector3.UnitY);

            _dirLights = new[] {
                new DirectionalLight {
                    Ambient   = new Color4(0.9f, 0.9f, 0.9f),
                    Diffuse   = new Color4(0.7f, 0.7f, 0.7f),
                    Specular  = new Color4(0.8f, 0.8f, 0.8f),
                    Direction = new Vector3(-0.57735f, -0.57735f, 0.57735f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(1.0f, 0.4f, 0.4f, 0.4f),
                    Specular  = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(-0.707f, -0.707f, 0)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Specular  = new Color4(0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(0, 0, -1)
                }
            };
        }
    public virtual void SetActive(bool _value, bool _instantaneously = false)
    {
        if (setActiveRoutine != null)
        {
            StopCoroutine(setActiveRoutine);
        }
        if (lookAtCamera && lookAtCameraScript == null)
        {
            lookAtCameraScript = gameObject.AddComponent <LookAtCamera>();
        }

        //Without animation
        if (_instantaneously)
        {
            transform.localScale = _value ? openedScale : closedScale;
            if (lookAtCamera)
            {
                lookAtCameraScript.SetActive(_value);
            }
        }

        //With animation
        else
        {
            setActiveRoutine = StartCoroutine(IESetActive(_value));
        }
    }
Beispiel #4
0
        /// <summary>
        /// Draw axis at corner of view.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void SceneControl_GDIDraw(object sender, RenderEventArgs args)
        {
            SceneControl control = this.control;

            if (control == null)
            {
                return;
            }

            LookAtCamera modelSceneCamera = control.Scene.CurrentCamera as LookAtCamera;

            if (modelSceneCamera != null)
            {
                UpdateParallelCamera(modelSceneCamera);
            }

            // update data of this.axisSpy.projectedAxisVertexes
            this.axisScene.OpenGL.MakeCurrent();
            this.axisScene.Draw();

            Vertex[] targets = this.axisSpy.projectedAxisVertexes;
            for (int i = 1; i < targets.Length; i++)
            {
                args.Graphics.DrawLine(this.pens[i - 1],
                                       targets[0].X, control.Height - targets[0].Y,
                                       targets[i].X, control.Height - targets[i].Y);
            }
        }
Beispiel #5
0
        private SsaoDemo(IntPtr hInstance)
            : base(hInstance)
        {
            MainWindowCaption = "SSAO Demo";

            _lastMousePos = new Point();

            _camera = new LookAtCamera {
                Position = new Vector3(0, 2, -15)
            };


            _dirLights = new[] {
                new DirectionalLight {
                    Ambient   = new Color4(1f, 1f, 1f),
                    Diffuse   = new Color4(0.0f, 0.0f, 0.0f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(-0.57735f, -0.57735f, 0.57735f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(0.0f, 0.0f, 0.0f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(0.707f, -0.707f, 0)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(0.0f, 0.0f, 0.0f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(0, 0, -1)
                }
            };
        }
Beispiel #6
0
        public static void DrawSimpleQuad3D()
        {
            // We create a 3d quad, so we need a camera.
            BaseCamera cam = new LookAtCamera(new Vector(4, -4, 4));

            // Create a geometry data instance which will hold the actual data.
            GeometryData geometryData = new GeometryData("<SimpleQuad3D>", 4,
                                                         VertexFormat.Position3DTextured, 6, true, false);

            // Fill the geometry with actual data.
            geometryData.SetVertexData(0, new Vector(1, 0, 0), Point.One);
            geometryData.SetVertexData(1, new Vector(-1, 0, 0), Point.UnitY);
            geometryData.SetVertexData(2, new Vector(-1.25f, 0, 1), Point.Zero);
            geometryData.SetVertexData(3, new Vector(1.25f, 0, 1), Point.UnitX);

            geometryData.Indices = new ushort[]
            {
                0, 2, 1,
                0, 3, 2,
            };
            // Now create a geometry from the data.
            Geometry geometry = Geometry.Create(geometryData);

            // We need a material to draw the geometry. Simply use the default.
            MaterialColored material = MaterialColored.Default;

            // Now start the application...
            Application.Start(delegate
            {
                // ...and draw the geometry.
                material.Draw(geometry);
            });
        }
Beispiel #7
0
        public static void DrawCulledLines3D()
        {
            BaseCamera cam = new LookAtCamera(new Vector(4, -4, 4));

            Application.Start(delegate
            {
                int numberOfTotalLines = 0;
                int numberOfDrawnLines = 0;
                for (float posX = -100f; posX <= 100f; posX += 5f)
                {
                    for (float posY = -100f; posY <= 100f; posY += 5f)
                    {
                        numberOfTotalLines++;
                        Vector pos = new Vector(posX, posY, 0f);
                        Line.Draw(pos, pos + Vector.UnitZ, Color.Green);
                        if (Line.WasLastLineCulled == false)
                        {
                            numberOfDrawnLines++;
                        }
                    }
                }

                Application.Window.Title = "Number of lines drawn: " +
                                           numberOfDrawnLines + "/" + numberOfTotalLines +
                                           " | FPS=" + Time.Fps;
            });
        }
 /// <summary> Loads the content for the game </summary>
 public override void LoadContent()
 {
     Camera     = new LookAtCamera(Vector2.Zero, Renderer.Instance.TargetDimensions);
     MainCanvas = new Canvas(Camera, 0, new Shader("Content/Shaders/VertexShader.txt", "Content/Shaders/FragmentShader.txt"));
     UICanvas   = new Canvas(new Camera(Vector2.Zero, Renderer.Instance.TargetDimensions), 1, new Shader("Content/Shaders/VertexShader.txt", "Content/Shaders/FragmentShader.txt"));
     StateManager.Instance.StartState(new MenuState());
 }
Beispiel #9
0
        public static void GetRayFromScreenPoint()
        {
            BaseCamera cam      = new LookAtCamera(new Vector(10, 10, 10));
            Vector     halfSize = new Vector(3, 3, 3);

            Application.Start(delegate
            {
                Grid.Draw();

                // Get a ray from the middle of the screen
                Point input   = Input.Mouse.Position;
                Ray screenRay = ScreenSpace.GetRayFromScreenPoint(input);
                // And convert it back to 2D to make sure it works.
                Vector resultingPosition =
                    ScreenSpace.Project(screenRay.Position + screenRay.Direction);
                bool isIntersecting = false;

                // draw a simple cube from (-3, -3, -3) to (3, 3, 3)
                Box.DrawOutline(-halfSize, halfSize,
                                isIntersecting
                                                ? Color.Green
                                                : Color.Red);

                Font.Default.Draw(
                    "input=" + input + "\n" +
                    "screenRay=" + screenRay + "\n" +
                    "resultingPosition=" + resultingPosition,
                    Rectangle.FromCenter(new Point(0.5f, 0.3f), Size.Half));
            });
        }
Beispiel #10
0
        protected RandomTerrainDemo(IntPtr hInstance) : base(hInstance)
        {
            MainWindowCaption = "Random Terrain Demo";
            //Enable4xMsaa = true;
            _lastMousePos = new Point();

            _camera = new LookAtCamera {
                Position = new Vector3(0, 20, 100)
            };
            _dirLights = new[] {
                new DirectionalLight {
                    Ambient   = new Color4(0.3f, 0.3f, 0.3f),
                    Diffuse   = new Color4(1.0f, 1.0f, 1.0f),
                    Specular  = new Color4(0.8f, 0.8f, 0.7f),
                    Direction = new Vector3(.707f, -0.707f, 0.0f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Specular  = new Color4(1.0f, 0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(0.57735f, -0.57735f, 0.57735f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(0.2f, 0.2f, 0.2f),
                    Specular  = new Color4(0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(-0.57735f, -0.57735f, -0.57735f)
                }
            };
        }
Beispiel #11
0
        private TerrainPickingDemo(IntPtr hInstance)
            : base(hInstance)
        {
            MainWindowCaption = "Terrain Picking Demo";
            //Enable4xMsaa = true;
            _lastMousePos = new Point();

            _camera = new LookAtCamera {
                Position = new Vector3(0, 20, 100)
            };
            _dirLights = new[] {
                new DirectionalLight {
                    Ambient   = new Color4(0.8f, 0.8f, 0.8f),
                    Diffuse   = new Color4(0.6f, 0.6f, 0.5f),
                    Specular  = new Color4(0.8f, 0.8f, 0.7f),
                    Direction = new Vector3(0, 0, 0.707f)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(0.4f, 0.4f, 0.4f),
                    Specular  = new Color4(0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(0.707f, -0.707f, 0)
                },
                new DirectionalLight {
                    Ambient   = new Color4(0, 0, 0),
                    Diffuse   = new Color4(0.2f, 0.2f, 0.2f),
                    Specular  = new Color4(0.2f, 0.2f, 0.2f),
                    Direction = new Vector3(0, 0, -1)
                }
            };
            _originalLightDirs = _dirLights.Select(l => l.Direction).ToArray();
        }
Beispiel #12
0
 void Start()
 {
     rb                    = GetComponent <Rigidbody>();
     childSprite           = this.gameObject.transform.GetChild(0);
     lookAtCamera          = childSprite.GetComponent <LookAtCamera>();
     pedestrianDestination = GetComponent <PedestrianDestination>();
     agent                 = GetComponent <NavMeshAgent>();
 }
 protected virtual void Awake()
 {
     transform.localScale = activeOnAwake ? openedScale : closedScale;
     if (lookAtCamera && lookAtCameraScript == null)
     {
         lookAtCameraScript = gameObject.AddComponent <LookAtCamera>();
     }
 }
Beispiel #14
0
    public static LookAtCamera Attach(GameObject go, Transform cameratransform)
    {
        LookAtCamera la = go.AddComponent <LookAtCamera>();

        la.m_camera_transform = cameratransform;
        la.Init();
        return(la);
    }
 void Awake()
 {
     movementScript = GetComponent <MovementInterface> ();
     snappingScript = GetComponent <SnapToCollision> ();
     lookAtScript   = GetComponent <LookAtCamera> ();
     runningScript  = GetComponent <Input_ModifySpeed> ();
     spriteAnimationHandlerScript = GetComponent <SpriteAnimationHandler> ();
 }
Beispiel #16
0
    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }

        Instance = this;
    }
Beispiel #17
0
        private void SetUpCamera()
        {
            Camera.Use <LookAtCamera>();
            var camera = new LookAtCamera(Resolve <Device>(), Resolve <Window>());

            Camera.Current  = camera;
            camera.Target   = Vector3D.Zero;
            camera.Position = new Vector3D(0.0f, -0.00001f, 10.0f);
        }
 void Awake() {
     _camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
     _topDownCamera = _camera.GetComponent<TopDownCamera>();
     _lookAtCamera = _camera.GetComponent<LookAtCamera>();
     _slothAnimator = GameObject.FindGameObjectWithTag("SlothNinja").GetComponentInChildren<Animator>();
     _ikSlothController = _slothAnimator.GetComponent<IKSlothController>();
     killCamCanvas.worldCamera = _camera;
     killCamCanvas.planeDistance = planeDistance;
 }
Beispiel #19
0
        private void UpdateParallelCamera(LookAtCamera modelSceneCamera)
        {
            Vertex position = modelSceneCamera.Position - modelSceneCamera.Target;

            position.Normalize();
            parallelCamera.Position            = position * 7;
            parallelCamera.UpVector            = modelSceneCamera.UpVector;
            parallelCamera.FieldOfView         = modelSceneCamera.FieldOfView;
            this.rotationEffect.ArcBall.Camera = parallelCamera;
        }
Beispiel #20
0
        public static void DrawGrid()
        {
            LookAtCamera cam = new LookAtCamera(new Vector(1, -5, 3));

            Application.Start(delegate
            {
                // Draw a grid.
                Grid.Draw();
            });
        }
Beispiel #21
0
    private void Start()
    {
        if (!lines)
        {
            lines = transform.GetChild(0).gameObject;
        }

        lines.SetActive(false);

        this.lookAtCamera = LookAtCamera.Instance;
    }
Beispiel #22
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            LookAtCamera camera = this.sceneControl1.Scene.CurrentCamera as LookAtCamera;


            this.sceneControl1.MouseWheel += sceneControl1_MouseWheel;
            this.sceneControl1.MouseDown  += sceneControl1_MouseDown;
            this.sceneControl1.MouseMove  += sceneControl1_MouseMove;
            this.sceneControl1.MouseUp    += sceneControl1_MouseUp;
        }
Beispiel #23
0
        private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
        {
            //clear grid and axis
            openGLControl1.Scene.SceneContainer.Children.Clear();
            //set background color
            GLColor background = new GLColor(11 / 255f, 18 / 255f, 34 / 255f, 1);

            openGLControl1.Scene.ClearColour = background;

            //  Create some lights.
            Light light1 = new Light()
            {
                Name     = "Light 1",
                On       = true,
                Position = new Vertex(-9, -9, 11),
                GLCode   = OpenGL.GL_LIGHT0
            };
            Light light2 = new Light()
            {
                Name     = "Light 2",
                On       = true,
                Position = new Vertex(9, -9, 11),
                GLCode   = OpenGL.GL_LIGHT1
            };
            Light light3 = new Light()
            {
                Name     = "Light 3",
                On       = true,
                Position = new Vertex(0, 15, 15),
                GLCode   = OpenGL.GL_LIGHT2
            };

            //  Add the lights.
            var folder = new Folder()
            {
                Name = "Lights"
            };

            folder.AddChild(light1);
            folder.AddChild(light2);
            folder.AddChild(light3);
            openGLControl1.Scene.SceneContainer.AddChild(folder);


            var lookAtCamera = new LookAtCamera()
            {
                Position = new Vertex(0f, -20f, 2f),
                Target   = new Vertex(0f, 0f, 0f),
                UpVector = new Vertex(0f, 0f, 1f)
            };

            //  Set the look at camera as the current camera.
            openGLControl1.Scene.CurrentCamera = lookAtCamera;
        }
    private void LookAtCamera()
    {
        LookAtCamera LookAtScript = (LookAtCamera)target;

        if (!ViewersCamera)
        {
            ViewersCamera = Camera.main;
        }

        LookAtScript.LookAt(ViewersCamera.gameObject);
    }
Beispiel #25
0
        public static void DrawLines3D()
        {
            BaseCamera cam = new LookAtCamera(new Vector(4, -4, 4));

            Application.Start(delegate
            {
                // Draw a simple 3d axis for basic line testing.
                Line.Draw(Vector.Zero, Vector.UnitX, Color.Red);
                Line.Draw(Vector.Zero, Vector.UnitY, Color.Blue);
                Line.Draw(Vector.Zero, Vector.UnitZ, Color.Green);
            });
        }
Beispiel #26
0
        public static void DrawRotatedBox3D()
        {
            BaseCamera cam      = new LookAtCamera(new Vector(7, -10, 8));
            Vector     rotation = new Vector();
            Vector     halfSize = new Vector(3, 3, 3);

            Application.Start(delegate
            {
                rotation.X += Time.Delta * 10.0f;
                Box.DrawOutline(-halfSize, halfSize, Color.Red, rotation);
            });
        }
Beispiel #27
0
        protected LookAtCamera GetCamera(float zoom, UiContext context, RectangleF rect)
        {
            var pxRect = context.PointsToPixels(rect);
            var cam    = new LookAtCamera();

            OrbitPan.Y = MathHelper.Clamp(OrbitPan.Y, -MathHelper.PiOver2 + 0.02f, MathHelper.PiOver2 - 0.02f);
            var mat  = Matrix4x4.CreateFromYawPitchRoll(-OrbitPan.X, OrbitPan.Y, 0);
            var from = Vector3.Transform(new Vector3(0, 0, zoom), mat);

            cam.Update(pxRect.Width, pxRect.Height, from, Vector3.Zero);
            return(cam);
        }
        /// <summary>
        /// Pops the specified parent element.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="parentElement">The parent element.</param>
        public override void Pop(OpenGL gl, SceneElement parentElement)
        {
            LookAtCamera camera = parentElement.TraverseToRootElement().ParentScene.CurrentCamera as LookAtCamera;

            if (camera != null)
            {
                gl.Viewport(0, 0, result[2], result[3]);
            }

            //  Pop the stack.
            gl.PopMatrix();
        }
        private void SetTranslate(OpenGL gl, LookAtCamera camera)
        {
            gl.Flush();

            Vertex towards = camera.Target - camera.Position;

            towards.Normalize();
            Vertex position = camera.Position + towards * 5f;

            this.linearTransformation.TranslateX = position.X;
            this.linearTransformation.TranslateY = position.Y;
            this.linearTransformation.TranslateZ = position.Z;
        }
Beispiel #30
0
        public static void DrawBox3D()
        {
            BaseCamera cam      = new LookAtCamera(new Vector(10, 10, 10));
            Vector     halfSize = new Vector(3, 3, 3);

            Application.Start(delegate
            {
                Grid.Draw();

                // draw a simple cube from (-3, -3, -3) to (3, 3, 3)
                Box.DrawOutline(-halfSize, halfSize, Color.Red);
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="camera">if null, please set camera for result's orthoArcBallEffect.Camera property later.</param>
        /// <returns></returns>
        public static OrthoAxisElement Create(LookAtCamera camera = null)
        {
            OrthoAxisElement element = new OrthoAxisElement()
            {
                Name = "orthogonal axis element"
            };

            //  Create a set of scene attributes.
            OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect()
            {
                Name = "Scene Attributes"
            };

            //  Specify the scene attributes.
            sceneAttributes.EnableAttributes.EnableDepthTest = true;
            sceneAttributes.EnableAttributes.EnableNormalize = true;
            sceneAttributes.EnableAttributes.EnableLighting  = false;
            //sceneAttributes.EnableAttributes.EnableTexture2D = true;
            //sceneAttributes.EnableAttributes.EnableBlend = true;
            //sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha;
            //sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha;
            //sceneAttributes.LightingAttributes.TwoSided = true;
            //sceneAttributes.TransformAttributes.MatrixMode = MatrixMode.Projection;
            element.AddEffect(sceneAttributes);

            OrthoArcBallEffect orthoAxisArcBallEffect = new OrthoArcBallEffect(camera);

            element.AddEffect(orthoAxisArcBallEffect);

            Axies axies = new Axies();

            element.AddChild(axies);
            LinearTransformationEffect transform = new LinearTransformationEffect();

            transform.LinearTransformation.ScaleX = 10;
            transform.LinearTransformation.ScaleY = 10;
            transform.LinearTransformation.ScaleZ = 10;
            axies.AddEffect(transform);

            //Grid grid = new Grid();
            //element.AddChild(grid);
            //LinearTransformationEffect transform = new LinearTransformationEffect();
            //transform.LinearTransformation.ScaleX = 0.1f;
            //transform.LinearTransformation.ScaleY = 0.1f;
            //transform.LinearTransformation.ScaleZ = 0.1f;
            //grid.AddEffect(transform);

            element.orthoArcBallEffect = orthoAxisArcBallEffect;

            return(element);
        }