Ejemplo n.º 1
0
 public void BufferConeData(int arrayBuffer, ref int arrayBufferOffset, int elementBuffer, ref int elementBufferOffset)
 {
     base.BufferPrimitiveData(
         this.VertexCoordinates
         .SelectMany(vector =>
         {
             byte[] buffer = new byte[Vector3.SizeInBytes];
             var array = new[] { vector.X, vector.Y, vector.Z };
             Buffer.BlockCopy(array, 0, buffer, 0, buffer.Length);
             return buffer;
         }).ToArray(), this.Indices, Vector3.SizeInBytes, arrayBuffer, ref arrayBufferOffset, elementBuffer, ref elementBufferOffset);
 }
Ejemplo n.º 2
0
        private void glControl1_MouseClick_1(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!gl_loaded) return;
            var mouse = new
            {
                Close = camera.Project(new Vector2(e.X, e.Y), depth: -1),
                Far = camera.Project(new Vector2(e.X, e.Y), depth: 1)
            };

            var callback = new BulletSharp.CollisionWorld.ClosestRayResultCallback(mouse.Close, mouse.Far);
            collisionWorld.PerformDiscreteCollisionDetection();
            collisionWorld.RayTest(mouse.Close, mouse.Far, callback);

            if (callback.HasHit)
            {
                var clickableInterface = callback.CollisionObject.UserObject as IClickable;
                if (clickableInterface != null)
                {
                    clickableInterface.OnMouseClickHandler(this, new MouseEventArgs(camera, new Vector2(e.X, e.Y), callback.CollisionObject.WorldTransform.ExtractTranslation(), e.Button));
                }
            }
        }
Ejemplo n.º 3
0
        private void BufferData(Vector3[] coordinates, ushort[] indices)
        {
            this.glBuffers = new[] { GL.GenVertexArray(), GL.GenBuffer(), GL.GenBuffer() };

            GL.BindVertexArray(glBuffers[0]);

            GL.BindBuffer(BufferTarget.ArrayBuffer, glBuffers[1]);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, glBuffers[2]);

            // assign colours
            var colourPallet = new[] 
            {
                selectedAxis.HasFlag(SelectedAxis.U) ? Colours.Selection : Colours.Red,
                selectedAxis.HasFlag(SelectedAxis.V) ? Colours.Selection : Colours.Green,
                selectedAxis.HasFlag(SelectedAxis.W) ? Colours.Selection : Colours.Blue
            };
            var colours = colourPallet.SelectMany(x => x.ToFloatRgb()).Concat(colourPallet.SelectMany(x => x.ToFloatRgb()));

            var colourCount = coordinates.Length - 6;
            var palletDivisor = colourCount / 3;
            for (int i = 0; i < colourCount; ++i)
            {
                var index = (i / palletDivisor) % palletDivisor;
                colours = colours.Concat(colourPallet[index].ToFloatRgb());
            }

            var colourArray = colours.ToArray();

            GL.BufferData<ushort>(
                BufferTarget.ElementArrayBuffer,
                (IntPtr)(sizeof(ushort) * indices.Length),
                indices,
                BufferUsageHint.StreamDraw);
            GL.BufferData(
                BufferTarget.ArrayBuffer,
                (IntPtr)(Vector3.SizeInBytes * coordinates.Length + sizeof(float) * colourArray.Length),
                IntPtr.Zero,
                BufferUsageHint.StreamDraw);

            BufferPositionData(coordinates);

            BufferColourData(Vector3.SizeInBytes * coordinates.Length, colourArray);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 0, (IntPtr)(Vector3.SizeInBytes * coordinates.Length));

            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);

            GL.BindVertexArray(0);
        }