示例#1
0
 // Invoke Interaction with provided interactable
 public void Invoke(TInteractable a_interactable, InteractableCollection a_invokedInteractables = null, InteractableCollection a_invokerInteractables = null)
 {
     if (a_interactable != null)
     {
         OnInvoke(a_interactable, a_invokedInteractables, a_invokerInteractables);
     }
 }
        public override void Intercept(IInteraction a_interaction, InteractableCollection a_interactableCollection,
                                       InteractionEventType a_interactionType, int a_identifier = int.MinValue)
        {
            TInteractable interactable = a_interactableCollection.LocateInteractable <TInteractable>(a_eventType: a_interactionType, a_identifier: a_identifier);

            OnIntercept((TInteraction)a_interaction, (TInteractable)interactable);
        }
示例#3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (currentBuilder != null)
            {
                //	If we are currently using a builder, update it.
                if (currentBuilder.OnMouseMove(Scene.OpenGL, e))
                {
                    Invalidate();
                }
            }
            //	If we have selected items, move them.
            else if (hits.Count > 0)
            {
                //	The 'effect' vertex describes the mouse movement in 3D space.
                Vertex effect = new Vertex();

                //	Set the effect values.
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    effect.X += ((float)e.X - (float)curX) / 20.0f;
                    effect.Z += ((float)e.Y - (float)curY) / 20.0f;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    effect.Y -= ((float)e.Y - (float)curY) / 20.0f;
                }

                //	Interact with each hit object.
                foreach (IInteractable interact in hits)
                {
                    interact.DoMouseInteract(mouseOperation, effect.X, effect.Y, effect.Z);
                }

                //	Redraw.
                Invalidate();

                curX = e.X;
                curY = e.Y;
            }
            else
            {
                //	If we don't have it's, but we're over an object, change the cursor.
                if (mouseHover)
                {
                    InteractableCollection overhits = scene.DoHitTest(e.X, e.Y);
                    if (overhits.Count > 0)
                    {
                        Cursor.Current = Cursors.Hand;
                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }
示例#4
0
        //public abstract void Invoke(InteractableCollection a_unit, int a_identifier = 0);

        protected TInteractable LocateInteractable(InteractableCollection a_interactableCollection,
                                                   int a_identifier,
                                                   InteractionEventType a_interactionType = null)
        {
            if (a_interactableCollection == null)
            {
                throw new System.NullReferenceException("can't locate interactable from null collection");
            }
            return(a_interactableCollection.LocateInteractable <TInteractable>(a_eventType: a_interactionType, a_identifier: a_identifier));
        }
示例#5
0
        // Invoke Interaction with provided interactables
        public void Invoke(InteractableCollection a_interactableCollection, InteractionEventType a_interactionType = null,
                           int a_identifier = int.MinValue, InteractableCollection a_invokerInteractables = null)
        {
            TInteractable interactable = LocateInteractable(a_interactableCollection, a_identifier, a_interactionType);

            if (interactable != null)
            {
                OnInvoke(interactable, a_interactableCollection, a_invokerInteractables);
            }
        }
示例#6
0
 public MainForm()
 {
     InitializeComponent();
     cmbIconType.Items.Clear();
     foreach (var i in Enum.GetValues(typeof(Interaction.InteractionType)))
     {
         cmbIconType.Items.Add(i);
     }
     cmbIconType.SelectedIndex = 0;
     cmbIconType_SelectionChangeCommitted(this, EventArgs.Empty);
     ActiveCollection = new InteractableCollection();
 }
 protected override void OnInvoke(TResourceInteractable resourceInteractable,
                                  InteractableCollection a_invokedInteractables,
                                  InteractableCollection a_invokerInteractables)
 {
     resourceInteractable.Modify(ModifyResourceBy);
 }
示例#8
0
 protected abstract void OnInvoke(TInteractable a_interactable, InteractableCollection a_invokedInteractables, InteractableCollection a_invokerInteractables);
示例#9
0
文件: Scene.cs 项目: nromik/sharpgl
        /// <summary>
        /// This function performs hit testing on the scene (the scene being the light
        /// array, the quadric array, and the polygon array etc).
        /// </summary>
        /// <param name="x">X coord of the point to hit test.</param>
        /// <param name="y">Y coord of the point to hit test.</param>
        /// <returns>An array containing all of the object hit by the point.</returns>
        public virtual InteractableCollection DoHitTest(int x, int y)
        {
            //	If we don't have a current camera, we cannot hit test.
            if(currentCamera == null)
            {
                System.Windows.Forms.MessageBox.Show("There is no current camera!");
                return new InteractableCollection();
            }

            //	Create an array that will be the viewport.
            int[] viewport = new int[4];

            //	Get the viewport, then convert the mouse point to an opengl point.
            gl.GetInteger(OpenGL.VIEWPORT, viewport);
            y = viewport[3] - y;

            //	Create a select buffer.
            uint[] selectBuffer = new uint[512];
            gl.SelectBuffer(512, selectBuffer);

            //	Enter select mode.
            gl.RenderMode(OpenGL.SELECT);

            //	Create a combined array.
            InteractableCollection combined = new InteractableCollection();
            //	Polygon nullPoly = new Polygon();
            //	combined.Add(nullPoly);
            combined.AddRange(quadrics);
            combined.AddRange(lights);
            combined.AddRange(polygons);
            combined.AddRange(evaluators);
            combined.AddRange(cameras);
            combined.AddRange(sceneObjects);

            //	Initialise the names, and add the first name.
            gl.InitNames();
            gl.PushName(0);

            //	Push matrix, set up projection, then load matrix.
            gl.MatrixMode(OpenGL.PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.PickMatrix(x, y, 4, 4, viewport);
            currentCamera.TransformProjectionMatrix(gl);
            currentCamera.LookAt(gl);
            gl.MatrixMode(OpenGL.MODELVIEW);
            gl.LoadIdentity();

            //	Draw everything in the combined array, with the index as it's name.
            for(int i = 0; i < combined.Count; i++)
            {
                SceneObject ob = (SceneObject)combined[i];
                gl.LoadName((uint)(i+1));
                ((IInteractable)ob).DrawPick(gl);
            }

            //	Pop matrix and flush commands.
            gl.MatrixMode(OpenGL.PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.MODELVIEW);
            gl.Flush();

            //	End selection.
            int hits = gl.RenderMode(OpenGL.RENDER);
            uint posinarray = 0;
            InteractableCollection hitArray = new InteractableCollection();

            for(int hit = 0; hit < hits; hit++)
            {
                uint nameCount = selectBuffer[posinarray++];
                uint z1 = selectBuffer[posinarray++];
                uint z2 = selectBuffer[posinarray++];

                if(nameCount == 0)
                    continue;

                //	Create an array that'll hold the names.
                int[] names = new int[nameCount];

                //	Add each name to the array.
                for(int name = 0; name < nameCount; name++)
                    names[name] = (int)selectBuffer[posinarray++];

                //	Now ask the hit object what has been hit, then add it to the array.
                SceneObject hitObject = (SceneObject)combined[names[0] - 1];	//	names[0] is the object.
                hitArray.Add(((IInteractable)hitObject).GetObjectFromSelectNames(names));
            }

            return hitArray;
        }
示例#10
0
 private void newCollectionToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var answer = MessageBox.Show("Are you sure you want to start a new collection?\r\nYour current project will be lost.", "Are you sure?", MessageBoxButtons.YesNo);
     if (answer == System.Windows.Forms.DialogResult.Yes)
     {
         lastLoaded = null;
         ActiveCollection = new InteractableCollection();
     }
 }
示例#11
0
 private void loadToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     ofd.Filter = "XML Files|*.xml";
     ofd.Multiselect = false;
     ofd.ShowDialog();
     if (!String.IsNullOrEmpty(ofd.FileName))
     {
         lastLoaded = ofd.FileName;
         XmlSerializer xml = new XmlSerializer(typeof(InteractableCollection));
         using (TextReader tw = new StreamReader(lastLoaded))
         {
             ActiveCollection = (InteractableCollection)xml.Deserialize(tw);
             tw.Close();
         }
     }
 }
示例#12
0
        /// <summary>
        /// This function performs hit testing on the scene (the scene being the light
        /// array, the quadric array, and the polygon array etc).
        /// </summary>
        /// <param name="x">X coord of the point to hit test.</param>
        /// <param name="y">Y coord of the point to hit test.</param>
        /// <returns>An array containing all of the object hit by the point.</returns>
        public virtual InteractableCollection DoHitTest(int x, int y)
        {
            //	If we don't have a current camera, we cannot hit test.
            if (currentCamera == null)
            {
                System.Windows.Forms.MessageBox.Show("There is no current camera!");
                return(new InteractableCollection());
            }

            //	Create an array that will be the viewport.
            int[] viewport = new int[4];

            //	Get the viewport, then convert the mouse point to an opengl point.
            gl.GetInteger(OpenGL.VIEWPORT, viewport);
            y = viewport[3] - y;

            //	Create a select buffer.
            uint[] selectBuffer = new uint[512];
            gl.SelectBuffer(512, selectBuffer);

            //	Enter select mode.
            gl.RenderMode(OpenGL.SELECT);

            //	Create a combined array.
            InteractableCollection combined = new InteractableCollection();

            //	Polygon nullPoly = new Polygon();
            //	combined.Add(nullPoly);
            combined.AddRange(quadrics);
            combined.AddRange(lights);
            combined.AddRange(polygons);
            combined.AddRange(evaluators);
            combined.AddRange(cameras);
            combined.AddRange(sceneObjects);

            //	Initialise the names, and add the first name.
            gl.InitNames();
            gl.PushName(0);

            //	Push matrix, set up projection, then load matrix.
            gl.MatrixMode(OpenGL.PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.PickMatrix(x, y, 4, 4, viewport);
            currentCamera.TransformProjectionMatrix(gl);
            currentCamera.LookAt(gl);
            gl.MatrixMode(OpenGL.MODELVIEW);
            gl.LoadIdentity();

            //	Draw everything in the combined array, with the index as it's name.
            for (int i = 0; i < combined.Count; i++)
            {
                SceneObject ob = (SceneObject)combined[i];
                gl.LoadName((uint)(i + 1));
                ((IInteractable)ob).DrawPick(gl);
            }

            //	Pop matrix and flush commands.
            gl.MatrixMode(OpenGL.PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.MODELVIEW);
            gl.Flush();

            //	End selection.
            int  hits       = gl.RenderMode(OpenGL.RENDER);
            uint posinarray = 0;
            InteractableCollection hitArray = new InteractableCollection();

            for (int hit = 0; hit < hits; hit++)
            {
                uint nameCount = selectBuffer[posinarray++];
                uint z1        = selectBuffer[posinarray++];
                uint z2        = selectBuffer[posinarray++];

                if (nameCount == 0)
                {
                    continue;
                }

                //	Create an array that'll hold the names.
                int[] names = new int[nameCount];

                //	Add each name to the array.
                for (int name = 0; name < nameCount; name++)
                {
                    names[name] = (int)selectBuffer[posinarray++];
                }

                //	Now ask the hit object what has been hit, then add it to the array.
                SceneObject hitObject = (SceneObject)combined[names[0] - 1];                    //	names[0] is the object.
                hitArray.Add(((IInteractable)hitObject).GetObjectFromSelectNames(names));
            }

            return(hitArray);
        }
示例#13
0
 public abstract void Intercept(IInteraction a_interaction, InteractableCollection a_interactableCollection,
                                InteractionEventType a_interactionType, int a_identifier);
示例#14
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            //	Call the base.
            base.OnMouseDown(e);

            //	If we don't want any mouse operations then return.
            if(mouseOperation == MouseOperation.None)
                return;

            //	If we are either in select mode, or on always select, do a hit test.
            if(autoSelect || mouseOperation == MouseOperation.Select)
            {
                //	If we have control held down, then add to the selection.
                hits.Clear();
                hits = scene.DoHitTest(e.X, e.Y);

                //	If we hit nothing, then move the camera instead.
                if(hits.Count == 0)
                    hits.Add(scene.CurrentCamera);
            }

            //	If we've hit stuff, we hide the pointer.
            if(hits.Count > 0)
                Cursor.Current = null;

            //	If there is a Builder, then click it.
            if(currentBuilder != null)
            {
                //	Tell the builder there's been a click. It may return
                //	us an object, if so, we jam it into the scene.
                object val = currentBuilder.OnMouseDown(scene.OpenGL, e);
                if(val != null)
                {
                    //	Add the object.
                    scene.Jam(val);

                    //	We can now get rid of the builder and stop
                    //	capture.
                    Capture = false;
                    currentBuilder = null;
                }
            }

            curX = e.X;
            curY = e.Y;
        }