Exemple #1
0
        public void AddGameObject(GameObject gameObject)
        {
            gameObject.Scene = this;
            gameObject.Load();

            _gameObjects.Add(gameObject);
        }
Exemple #2
0
        protected override void Init()
        {
            ShowUniformSphere = true;
            YDirectionArrow = new GameObject("yDirectionArrow");
            ZDirectionArrow = new GameObject("zDirectionArrow");
            XDirectionArrow = new GameObject("xDirectionArrow");

            AddChild(XDirectionArrow);
            AddChild(YDirectionArrow);
            AddChild(ZDirectionArrow);

            _xDirection = new Cube() { Name = "xDirection" };
            _yDirection = new Cube() { Name = "yDirection" };
            _zDirection = new Cube() { Name = "zDirection" };

            AddChild(_xDirection);
            AddChild(_yDirection);
            AddChild(_zDirection);

            UniformSphere = new Sphere() { Scale = new Vector3(2.0f) };

            AddChild(UniformSphere);

            ArrowLength = 7.0f;

            RenderQueuePriority = -1;
            ClearsZBuffer = true;

            foreach (var child in Children)
            {
                child.RenderQueuePriority = RenderQueuePriority - 1;
                child.Designer = true;
            }
        }
Exemple #3
0
        public CameraComponent(GameObject gameObject, float fieldOfViewRadians, float aspectRatio, float zNear, float zFar)
            : base(gameObject)
        {
            FieldOfViewRadians = fieldOfViewRadians;
            AspectRatio = aspectRatio;
            ZNear = zNear;
            ZFar = zFar;

            Up = new Vector3(0.0f, 1.0f, 0.0f);

            ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(FieldOfViewRadians, AspectRatio, ZNear, ZFar);
        }
        public void Follow(GameObject target, bool smoothFollow = false)
        {
            _target = target;

            if (_target == null) return;

            if (_target is SlingshotBallFarseer2D)
            {
                _adjustment = new Vector3(0, 2, 0);
            }
            else
            {
                _adjustment = Vector3.Zero;
            }

            if (!smoothFollow)
            {
                CameraComponent.Target = _target.WorldPosition + _adjustment;
                CameraComponent.GameObject.Position = _target.WorldPosition + new Vector3(0, 0, _distance);
            }
        }
Exemple #5
0
        internal void deleteMenuItem_Click(object sender, EventArgs e)
        {
            /* delete selected object */
            if (_selectedObject == null) return;

            Game.Scene.UnloadObject(_selectedObject);
            if (_objectRemovedEvent != null) _objectRemovedEvent(this, new ObjectRemovedEvent() { RemovedObject = _selectedObject });

            _selectedObject = null;
        }
Exemple #6
0
        private void ProcessInteractiviy()
        {
            Vector4 nearPlane, farPlane;
            ScreenPointToWorld(MousePosition, out nearPlane, out farPlane);

            /* hold a reference to the nearplane vector in order to calculate mouse input directional vector */
            if (LastNearPlaneMousePosition != null)
            {
                var direction = nearPlane - LastNearPlaneMousePosition.Value;
                if (direction.LengthSquared != 0)
                {
                    if (OnMouseMoveEvent != null)
                    {
                        _mouseMoveEvent.DirectionOnNearPlane = new Vector3(direction.X, direction.Y, direction.Z);
                        _mouseMoveEvent.NearPlane = new Vector3(nearPlane.X, nearPlane.Y, nearPlane.Z);

                        OnMouseMoveEvent(this, _mouseMoveEvent);
                    }
                }
            }

            UpdateCurrentMousePosition();

            var ray = new Vector4(farPlane - nearPlane);

            Vector3 hitLocation;

            GameObject result = RayCast(nearPlane, ray, out hitLocation);

            /* call events on raycast results */

            if (result != null)
            {
                /* target changed */
                if (_currentMouseOverObj != null && _currentMouseOverObj != result)
                {
                    _currentMouseOverObj.OnMouseOutEvent(_currentMouseOverObj, new MouseOutEvent());
                    result.OnMouseInEvent(result, new MouseInEvent());

                }
                else if (_currentMouseOverObj == null)
                {
                    result.OnMouseInEvent(result, new MouseInEvent());
                }

                _currentMouseOverObj = result;
            }
            else if (_currentMouseOverObj != null)
            {
                _currentMouseOverObj.OnMouseOutEvent(_currentMouseOverObj, new MouseOutEvent());
                _currentMouseOverObj = null;
            }
        }
Exemple #7
0
        private void AddSceneNode(TreeNode sceneNode, GameObject gameObject)
        {
            var objName = string.IsNullOrEmpty(gameObject.Name) ? string.Format("[{0}] Unnamed", gameObject.GetType().ToString()) : gameObject.Name;
            var newNode = sceneNode.Nodes.Add(objName);
            newNode.Tag = gameObject;

            foreach (var child in gameObject.Children.Where(g => !g.Designer))
            {
                AddSceneNode(newNode, child);
            }
        }
Exemple #8
0
 public GameComponent(GameObject gameObject)
 {
     GameObject = gameObject;
 }
Exemple #9
0
        public void AddChild(GameObject gameObject)
        {
            gameObject.Parent = this;

            _children.Add(gameObject);

            /* if this object is loaded, load the child */
            if (IsLoaded)
            {
                if (gameObject.IsLoaded) throw new NotSupportedException("Cannot have a loaded child");
                gameObject.Scene = this.Scene;

                gameObject.Load();
            }

            _compositionChanged = true;
        }
Exemple #10
0
        private void ClearSelection()
        {
            _selectedObject = null;
            if (_selectObjectEvent != null)
            {
                _selectObjectEvent(this, new SelectObjectEvent());
            }

            UpdateGizmo();
        }
Exemple #11
0
        public void DisposeGameObject(GameObject gameObject)
        {
            if (!gameObject.IsDisposing)
            {
                //var loadedObj = _gameObjects.First(g => g == gameObject);
                _disposableGameObjects.Add(gameObject);

                gameObject.IsDisposing = true;
            }
        }
Exemple #12
0
        public void AddGameObject(GameObject gameObject)
        {
            if (gameObject.IsLoaded) throw new InvalidOperationException("GameObject cannot be loaded");

            gameObject.Scene = this;

            _gameObjects.Add(gameObject);

            if (Loaded) gameObject.Load();

            if (OnObjectAddedEvent != null)
            {
                _gameObjectAddedEvent.GameObject = gameObject;
                OnObjectAddedEvent(this, _gameObjectAddedEvent);
            }

            _compositionChanged = true;
        }
Exemple #13
0
 public MeshRenderComponent(GameObject gameObject)
     : base(gameObject)
 {
     _bufferIds = new int[3];
 }
Exemple #14
0
 public RenderComponent(GameObject gameObject)
     : base(gameObject)
 {
 }
Exemple #15
0
        internal void SelectObjectAction(object a, MouseButtonDownEvent b)
        {
            if (Operation == OperationType.PANVIEW ||
                (b.Button != MouseButton.Button1 && b.Button != MouseButton.Button2)) return;

            _selectedObject = (a as GameObject);

            UpdateGizmo();

            if (_selectObjectEvent != null)
            {
                _selectObjectEvent(this, new SelectObjectEvent() { SelectedObject = _selectedObject });
            }
        }
Exemple #16
0
        private void BindEvents(GameObject instance)
        {
            /* hook up mouse events */

            instance.OnMouseIn += (a, b) =>
            {
                if (Operation == OperationType.PANVIEW) return;

                Cursor = Cursors.Cross;
            };

            instance.OnMouseOut += (a, b) =>
            {
                if (Operation == OperationType.PANVIEW) return;

                Cursor = Cursors.Arrow;
            };

            instance.OnMouseDown += (a, b) =>
            {
                SelectObjectAction(a, b);
                return;
            };
        }
Exemple #17
0
        public void SetCurrentLight(GameObject light)
        {
            if (light == null)
            {
                CurrentLight = null;
                return;
            }

            if (light.Scene != this) throw new Exception("Light is not part of this scene");

            var component = light.Components.FirstOrDefault(c => c is LightComponent) as LightComponent;

            if (component == null) throw new Exception("GameObject does not have a light component");

            CurrentLight = component;
        }
Exemple #18
0
 public void Follow(GameObject target)
 {
     _target = target;
 }
Exemple #19
0
        public void SetPlayCamera(GameObject camera)
        {
            if (camera == null)
            {
                PlayCamera = null;
                return;
            }

            if (camera.Scene != this) throw new Exception("Camera is not part of this scene");

            var component = camera.Components.FirstOrDefault(c => c is CameraComponent) as CameraComponent;

            if (component == null) throw new Exception("GameObject does not have a camera component");

            PlayCamera = component;
        }
Exemple #20
0
 public LightComponent(GameObject gameObject, ILight light)
     : base(gameObject)
 {
     Light = light;
 }
Exemple #21
0
        public void SetPlayerObject(GameObject player)
        {
            if (player == null)
            {
                PlayerObject = null;
                return;
            }

            if (player.Scene != this) throw new Exception("Player object is not part of this scene");

            PlayerObject = player;
        }
Exemple #22
0
        private void SelectObject(GameObject obj)
        {
            if (obj != null)
            {
                toolStripStatusLabel.Text = string.Format("Selected: {0}", obj.Name == string.Empty ? "[Unnamed]" : obj.Name);
                openTKControl.SetOperation(iGL.Designer.OpenTKControl.OperationType.MOVE);
            }
            else
            {
                toolStripStatusLabel.Text = "Ready";
            }

            sceneControl.SelectNodeWithValue(obj);
        }
Exemple #23
0
        public void UnloadObject(GameObject gameObject)
        {
            if (!GameObjects.Contains(gameObject)) throw new InvalidOperationException();

            _gameObjects.Remove(gameObject);

            if (CurrentCamera != null && gameObject.Components.Contains(CurrentCamera)) CurrentCamera = null;
            if (CurrentLight != null && gameObject.Components.Contains(CurrentLight)) CurrentLight = null;
        }
Exemple #24
0
        internal void UpdateMouseButton(MouseButton button, bool down, int x, int y)
        {
            MouseButtonState[button] = down;
            MousePosition = new Point(x, y);
            ProcessInteractiviy();

            /* selected target is now updated, process button event */

            if (down)
            {
                if (_currentMouseOverObj != null)
                {
                    _mouseButtonDownEvent.Button = button;
                    _currentMouseOverObj.OnMouseDownEvent(_currentMouseOverObj, _mouseButtonDownEvent);
                }

                /* can be null */
                _currentMouseDownObj = _currentMouseOverObj;
            }
            else
            {
                /* send a mouse up event to the last target, even if it is not the current hover target anymore */
                if (_currentMouseDownObj != null && _currentMouseDownObj != _currentMouseOverObj)
                {
                    _mouseButtonUpEvent.Button = button;
                    _currentMouseDownObj.OnMouseUpEvent(_currentMouseDownObj, _mouseButtonUpEvent);
                }

                /* send mouse up to the current obj */
                if (_currentMouseOverObj != null)
                {
                    _mouseButtonUpEvent.Button = button;
                    _currentMouseOverObj.OnMouseUpEvent(_currentMouseOverObj, _mouseButtonUpEvent);
                }
            }
        }
Exemple #25
0
 public MeshComponent(GameObject gameObject)
     : base(gameObject)
 {
     Material = new Material();
 }