Пример #1
2
 public System.Windows.Point CanvasPointFrom3DPoint(Point3D modelPoint3D)
 {
     Point3D worldPoint = ViewportImage.ModelToWorld.Transform(modelPoint3D);
     SlimDX.Vector3 worldPointSlimDX = new SlimDX.Vector3((float)worldPoint.X, (float)worldPoint.Y, (float)worldPoint.Z);
     float width = (float)ViewportImage.imageWidth;
     float height = (float)ViewportImage.imageHeight;
     SlimDX.Matrix trans = SlimDX.Matrix.Multiply(ViewportImage.View, ViewportImage.Projection);
     //Vector3 point2DSlimDX = Vector3.Project(worldPointSlimDX, 0, 0, ViewportImage.Width, ViewportImage.Height, 0.0f, 1.0f, trans);
     Vector3 point2DSlimDX = Vector3.Project(worldPointSlimDX, 0, 0, width, height, 0.0f, 1.0f, trans);
     return new System.Windows.Point((double)(point2DSlimDX.X), (double)(point2DSlimDX.Y));
 }
Пример #2
0
 public void D3DMapping_Vector3_Test()
 {
     var actual = new Irelia.Render.Vector3(0.1f, 0.22f, 0.33f);
     var expected = new SlimDX.Vector3(actual.x, actual.y, actual.z);
     Assert.AreEqual(expected, actual.ToD3DVector3());
     Assert.AreEqual(actual, expected.ToVector3());
 }
Пример #3
0
        //SlimDX.Direct2D.RenderTarget renderTarget;

        //private void DrawBrush()
        //{
        //    // Create bitmap render target from DXGI surface
        //    renderTarget = SlimDX.Direct2D.RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties()
        //    {
        //        HorizontalDpi = 1024,
        //        VerticalDpi = 768,
        //        MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
        //        PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.Unknown, SlimDX.Direct2D.AlphaMode.Ignore),
        //        Type = SlimDX.Direct2D.RenderTargetType.Default,
        //        Usage = SlimDX.Direct2D.RenderTargetUsage.None
        //    });

        //    using (var brush = new SlimDX.Direct2D.SolidColorBrush(renderTarget, new Color4(Color.LightSlateGray)))
        //    {
        //        for (int x = 0; x < renderTarget.Size.Width; x += 10)
        //            renderTarget.DrawLine(brush, x, 0, x, renderTarget.Size.Height, 0.5f);

        //        for (int y = 0; y < renderTarget.Size.Height; y += 10)
        //            renderTarget.DrawLine(brush, 0, y, renderTarget.Size.Width, y, 0.5f);

        //        renderTarget.FillRectangle(brush, new RectangleF(renderTarget.Size.Width / 2 - 50, renderTarget.Size.Height / 2 - 50, 100, 100));
        //    }

        //    renderTarget.DrawRectangle(new SlimDX.Direct2D.SolidColorBrush(renderTarget, new Color4(Color.CornflowerBlue)),
        //        new RectangleF(renderTarget.Size.Width / 2 - 100, renderTarget.Size.Height / 2 - 100, 200, 200));
        //}

        // DrawMesh
        //private void DrawMesh(SlimDX.Direct3D9.Mesh mesh, SlimDX.Vector3 loc, bool wireframe = false, bool isFilled = false)

        /// <summary>
        /// ///////////////////////////////
        /// ///////////////////////////////
        /// ///////////////////////////////
        /// </summary>

        // DrawCubeTest
        private void DrawCubeTest(SlimDX.Vector3 loc, float width, float height, float depth, bool isFilled = true, bool wireframe = false)
        {
            if (_mesh == null)
            {
                _mesh = SlimDX.Direct3D9.Mesh.CreateBox(D3D.Device, width, height, depth);
            }

            _SB.Capture();

            //D3D.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Black, 1.0f, 0);

            var worldMatrix = SlimDX.Matrix.Translation(loc);

            D3D.Device.SetTransform(TransformState.World, worldMatrix);

            _mesh.DrawSubset(0);

            D3D.Device.SetRenderState(RenderState.FillMode, SlimDX.Direct3D9.FillMode.Solid);

            _SB.Apply();

            // cleanup
            if (Vertices != null)
            {
                Vertices.Dispose();
            }
        }
Пример #4
0
        public void DrawSector(Vector3 center, Color color, float radius, float angleGrad, float heading = 0.0f)
        {
            int slices = 30;
            if (angleGrad < 120)
            {
                slices = 10;
            }

            int colorInt = color.ToArgb();

            double h = ((Math.PI * 2) - heading) + (Math.PI / 2);
            if (h > (Math.PI * 2))
                h = h - (Math.PI * 2);

            float angle = (float)((angleGrad / 180f) * Math.PI);
            float angleStep = angle / slices;
            _vertexBuffer[0] = new ColoredVertex(center, colorInt);

            float currentAngle = -(angle / 2.0f) + (float)h;
            int vertexIndex = 1;
            for (int i = 0; i < slices; i++, currentAngle += angleStep, vertexIndex++)
            {
                var sine = (float)Math.Sin(currentAngle);
                var cose = (float)Math.Cos(currentAngle);
                _vertexBuffer[vertexIndex] = 
                    new ColoredVertex(center.X + cose * radius, center.Y, center.Z + sine * radius, colorInt);
            }

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleFan, slices - 1, _vertexBuffer);
        }
Пример #5
0
        public void DrawDonut(Vector3 center, float inRadius, float outRadius, Color color)
        {
            int slices = 30;
            var radsPerSlice = (float)(Math.PI * 2 / slices);
            int colorInt = color.ToArgb();
            // x -> cos
            // z -> sin

            _vertexBuffer[0] = new ColoredVertex(center, colorInt);
            _vertexBuffer[1] = new ColoredVertex(center, colorInt);

            _vertexBuffer[0].Position.X += inRadius;
            _vertexBuffer[1].Position.X += outRadius;

            float angle = 0.0f;
            int vertexIndex = 2;
            for (int i = 1; i < slices; i++, vertexIndex+=2)
            {
                angle += radsPerSlice;
                var sine = (float)Math.Sin(angle);
                var cose = (float)Math.Cos(angle);

                _vertexBuffer[vertexIndex] = new ColoredVertex(center.X + cose * inRadius, center.Y, center.Z + sine * inRadius, colorInt);
                _vertexBuffer[vertexIndex+1] = new ColoredVertex(center.X + cose * outRadius, center.Y, center.Z + sine * outRadius, colorInt);
            }

            _vertexBuffer[vertexIndex] = _vertexBuffer[0];
            _vertexBuffer[vertexIndex + 1] = _vertexBuffer[1];

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, slices*2, _vertexBuffer);
        }
Пример #6
0
        /// <summary>
        /// Renders all of our geometry each frame.
        /// </summary>
        public void DrawTriangleList(SlimDX.Vector3 loc)
        {
            _SB.Capture();

            // Create the vertex buffer and fill with the triangle vertices.
            Vertices = new VertexBuffer(D3D.Device, 3 * D3D.Vertex.SizeBytes, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            SlimDX.DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
            stream.WriteRange(D3D.BuildVertexData());
            Vertices.Unlock();

            var worldMatrix = SlimDX.Matrix.Translation(loc);

            D3D.Device.SetTransform(TransformState.World, worldMatrix);

            D3D.Device.VertexFormat = D3D.Vertex.Format;

            // Render the vertex buffer.
            D3D.Device.SetStreamSource(0, Vertices, 0, D3D.Vertex.SizeBytes);

            //D3D.Device.DrawPrimitives(PrimitiveType.LineStrip, 0, 1);
            D3D.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

            if (Vertices != null)
            {
                Vertices.Dispose();
            }

            _SB.Apply();
        }
Пример #7
0
        /// <summary>
        /// Creates cylinder. Its axis will be parallel with privided direction.
        /// </summary>
        public static Mesh CreateHalfCylinder(float length, float radius, SlimDX.Vector3 direction, float angle)
        {
            int pointCount = 20;

            List <Vertex> vertices = new List <Vertex>();

            vertices.Add(new Vertex(0.0f, 0.0f, 0.0f,
                                    0.0f, 0.0f, -1.0f));
            vertices.Add(new Vertex(0.0f, 0.0f, length,
                                    0.0f, 0.0f, 1.0f));

            for (int i = 0; i < pointCount; i++)
            {
                float alpha = (float)(i * Math.PI / (pointCount - 1));
                float cosa  = (float)Math.Cos(alpha);
                float sina  = (float)Math.Sin(alpha);
                vertices.Add(new Vertex(cosa * radius, sina * radius, 0.0f,
                                        0.0f, 0.0f, -1.0f));
                vertices.Add(new Vertex(cosa * radius, sina * radius, 0.0f,
                                        cosa, sina, 0.0f));
                vertices.Add(new Vertex(cosa * radius, sina * radius, length,
                                        0.0f, 0.0f, 1.0f));
                vertices.Add(new Vertex(cosa * radius, sina * radius, length,
                                        cosa, sina, 0.0f));
            }
            vertices.Add(new Vertex(radius, 0.0f, 0.0f,
                                    0.0f, -1.0f, 0.0f));
            vertices.Add(new Vertex(-radius, 0.0f, 0.0f,
                                    0.0f, -1.0f, 0.0f));
            vertices.Add(new Vertex(radius, 0.0f, length,
                                    0.0f, -1.0f, 0.0f));
            vertices.Add(new Vertex(-radius, 0.0f, length,
                                    0.0f, -1.0f, 0.0f));

            List <IndexedPolygon> indices = new List <IndexedPolygon>();

            for (int i = 0; i < pointCount - 1; i++)
            {
                int cur  = 4 * i + 2;
                int next = 4 * (i + 1) + 2;
                indices.Add(new IndexedPolygon((UInt16)0, (UInt16)next, (UInt16)cur));
                indices.Add(new IndexedPolygon((UInt16)(cur + 1), (UInt16)(next + 1), (UInt16)(cur + 3)));
                indices.Add(new IndexedPolygon((UInt16)(cur + 3), (UInt16)(next + 1), (UInt16)(next + 3)));
                indices.Add(new IndexedPolygon((UInt16)1, (UInt16)(cur + 2), (UInt16)(next + 2)));
            }
            int offset = 2 + pointCount * 4;

            indices.Add(new IndexedPolygon((UInt16)(offset + 0), (UInt16)(offset + 2), (UInt16)(offset + 1)));
            indices.Add(new IndexedPolygon((UInt16)(offset + 1), (UInt16)(offset + 2), (UInt16)(offset + 3)));

            Matrix mat = Matrix.RotationZ(angle);

            mat *= RotationVectors(direction, new Vector3(0, 0, 1));
            foreach (var v in vertices)
            {
                v.Transform(mat);
            }

            return(new Mesh(vertices, indices));
        }
Пример #8
0
        /// <summary> Draws a line. </summary>
        /// <param name="vecStartPos"> The vector start position. </param>
        /// <param name="vecEndPos">   The vector end position. </param>
        /// <param name="width">       The width. </param>
        /// <param name="color">       The color. </param>
        public static void DrawLine(Vector3 vecStartPos, Vector3 vecEndPos, float width, Color color)
        {
            var     cameraPos = StyxWoW.Camera.Position;
            Vector3 camPos    = new Vector3(cameraPos.X, cameraPos.Y, cameraPos.Z);

            var     forward    = StyxWoW.Camera.Forward;
            Vector3 forwardPos = new Vector3(forward.X, forward.Y, forward.Z);

            float dot1 = Vector3.Dot((vecEndPos - camPos), forwardPos);
            float dot2 = Vector3.Dot((vecStartPos - camPos), forwardPos);

            // If the startPoint or endPoint is behind the camera,
            // then the bugged ID3DXLine:DrawTransform fails, so lets
            // prevent that.. shall we?
            if (dot1 < 0f || dot2 < 0f)
            {
                return;
            }

            if (_line == null)
            {
                _line = new Line(Device);
            }

            _line.Width = width;
            _line.Begin();
            _line.DrawTransformed(new[] { vecStartPos, vecEndPos }, Matrix.Identity * WoWCameraEx.View * WoWCameraEx.Projection, color);
            _line.End();
        }
Пример #9
0
        public virtual void DrawImage(
            IRenderer device,
            string te,
            Rectangle _rect,
            bool leftpoint,
            Vector2 _point,
            Color color)
        {
            if (!ShanghaiEXE.rend)
            {
                return;
            }
            string _texture = te + ".png";

            try
            {
                var    dgDevice = (MySlimDG)device;
                Point  point    = new Point((int)_point.X, (int)_point.Y);
                var    dx_point = new SlimDX.Vector2(point.X, point.Y);
                Matrix matrix   = Matrix.AffineTransformation2D(1f, SlimDX.Vector2.Zero, MyMath.Rad(0.0f), dx_point);
                dgDevice.sprite.Transform = matrix;
                SlimDX.Vector3 vector3 = !leftpoint ? new SlimDX.Vector3(_rect.Width / 2, _rect.Height / 2, 0.0f) : new SlimDX.Vector3(0.0f, 0.0f, 0.0f);
                this.LoadTexture(_texture);
                dgDevice.sprite.Draw(this.form.Tex[_texture].Texture, new Rectangle?(_rect), new SlimDX.Vector3?(vector3), new SlimDX.Vector3?(new SlimDX.Vector3(0.0f, 0.0f, 0.0f)), new Color4(color));
                dgDevice.sprite.Transform = Matrix.Identity;
            }
            catch
            {
            }
        }
    public int Update(List <TouchFinger> allFingers, Vector2D scaleLimit)
    {
        //clean list (check if touches still exist)
        cleanList(allFingers);

        //check how many fingers are still on list and perform actions
        //TRANSLATE
        if (hitIds.Count == 1)
        {
            SlimDX.Vector2 delta = hitIds.First().touchPosition - hitIds.First().lastPosition;
            objectTransform = objectTransform * SlimDX.Matrix.Translation(delta.X, delta.Y, 0);
            return(1);
        }

        //SCALE AND ROTATE
        if (hitIds.Count > 1)
        {
            //SCALE
            float sx = new SlimDX.Vector3(objectTransform.M11, objectTransform.M12, objectTransform.M13).Length();
            float sy = new SlimDX.Vector3(objectTransform.M21, objectTransform.M22, objectTransform.M23).Length();
            //previous distance
            float pd = (float)new Vector2D((hitIds.Last().lastPosition.X - hitIds.First().lastPosition.X),
                                           (hitIds.Last().lastPosition.Y - hitIds.First().lastPosition.Y)).Length;

            //current distance
            float cd = (float)new Vector2D((hitIds.Last().touchPosition.X - hitIds.First().touchPosition.X),
                                           (hitIds.Last().touchPosition.Y - hitIds.First().touchPosition.Y)).Length;

            float scaleFactor = cd - pd;
            float fscale      = 1;
            if (scaleLimit.x < sx + scaleFactor && sx + scaleFactor < scaleLimit.y &&
                scaleLimit.x < sy + scaleFactor && sy + scaleFactor < scaleLimit.y)
            {
                fscale += scaleFactor;
            }

            //ROTATION
            //previous angle
            double pa = Math.Atan2(hitIds.Last().lastPosition.Y - hitIds.First().lastPosition.Y,
                                   hitIds.Last().lastPosition.X - hitIds.First().lastPosition.X);
            //current angle
            double ca = Math.Atan2(hitIds.Last().touchPosition.Y - hitIds.First().touchPosition.Y,
                                   hitIds.Last().touchPosition.X - hitIds.First().touchPosition.X);

            double da = ca - pa;
            //Final matrices
            SlimDX.Matrix  scale  = SlimDX.Matrix.Scaling(fscale, fscale, 1);
            SlimDX.Matrix  rot    = SlimDX.Matrix.RotationZ((float)da);
            SlimDX.Vector3 srcPos = new SlimDX.Vector3(objectTransform.M41, objectTransform.M42, 0);
            //Translate to origin
            objectTransform.M41 = 0;
            objectTransform.M42 = 0;
            //rotate scale and translate back to srcpos
            objectTransform = objectTransform * rot * scale * SlimDX.Matrix.Translation(srcPos);
            return(2);
        }

        return(0);
    }
Пример #11
0
        public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color color)
        {
            _vertexBuffer[0] = new ColoredVertex(a, color);
            _vertexBuffer[1] = new ColoredVertex(b, color);
            _vertexBuffer[2] = new ColoredVertex(c, color);

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, _vertexBuffer);
        }
Пример #12
0
        public bool Filter(RigidBody body)
        {
            var center = new SlimDX.Vector3(body.MotionState.WorldTransform.M41,
                                            body.MotionState.WorldTransform.M42, body.MotionState.WorldTransform.M43);

            var ct = BoundingBox.Contains(Bounds, center);

            return(this.Containments.Contains(ct));
        }
Пример #13
0
        // DrawTextMesh
        private void DrawText(SlimDX.Vector3 loc, string text)
        {
            var font = new System.Drawing.Font("Consolas", .875f);
            var mesh = Mesh.CreateText(D3D.Device, font, text, 0f, 0f);



            DrawMesh(mesh, loc + new SlimDX.Vector3(0, 0, 2f));
        }
Пример #14
0
        /// <summary>
        /// Creates thin tube with required length and orientation.
        /// </summary>
        public static Mesh CreateTube(float length, float width, SlimDX.Vector3 direction)
        {
            float         cos45    = (float)Math.Cos(Math.PI / 4);
            List <Vertex> vertices = new List <Vertex>();

            vertices.Add(new Vertex(-width / 2 * cos45, -width / 2 * cos45, 0,
                                    -cos45, -cos45, 0));
            vertices.Add(new Vertex(width / 2 * cos45, -width / 2 * cos45, 0,
                                    cos45, -cos45, 0));
            vertices.Add(new Vertex(0, width / 2, 0,
                                    0, 1, 0));

            vertices.Add(new Vertex(-width / 2 * cos45, -width / 2 * cos45, length,
                                    -cos45, -cos45, 0));
            vertices.Add(new Vertex(width / 2 * cos45, -width / 2 * cos45, length,
                                    cos45, -cos45, 0));
            vertices.Add(new Vertex(0, width / 2, length,
                                    0, 1, 0));

            vertices.Add(new Vertex(-width / 2 * cos45, -width / 2 * cos45, 0,
                                    0, 0, -1));
            vertices.Add(new Vertex(width / 2 * cos45, -width / 2 * cos45, 0,
                                    0, 0, -1));
            vertices.Add(new Vertex(0, width / 2, 0,
                                    0, 0, -1));

            vertices.Add(new Vertex(-width / 2 * cos45, -width / 2 * cos45, length,
                                    0, 0, 1));
            vertices.Add(new Vertex(width / 2 * cos45, -width / 2 * cos45, length,
                                    0, 0, 1));
            vertices.Add(new Vertex(0, width / 2, length,
                                    0, 0, 1));

            Matrix mat = RotationVectors(direction, new Vector3(0, 0, 1));

            foreach (var v in vertices)
            {
                v.Transform(mat);
            }

            List <IndexedPolygon> indices = new List <IndexedPolygon>();

            indices.Add(new IndexedPolygon(6, 8, 7));
            indices.Add(new IndexedPolygon(9, 10, 11));

            indices.Add(new IndexedPolygon(0, 3, 2));
            indices.Add(new IndexedPolygon(5, 2, 3));

            indices.Add(new IndexedPolygon(1, 2, 5));
            indices.Add(new IndexedPolygon(1, 5, 4));

            indices.Add(new IndexedPolygon(0, 1, 3));
            indices.Add(new IndexedPolygon(4, 3, 1));

            return(new Mesh(vertices, indices));
        }
Пример #15
0
        public void DrawLine(Vector3 start, Vector3 end, Color color, float width = 0.025f)
        {
            Vector3 dir = end - start;

            dir.Z = 0;

            Vector3 extDir1;
            Vector3 extDir2;

            if (dir.LengthSquared() > 0.0001f)
            {
                dir.Normalize();

                extDir1.X = -dir.Y;
                extDir1.Y = dir.X;
                extDir1.Z = 0;

                extDir2 = Vector3.Cross(dir, extDir1);
            }
            else
            {
                extDir1 = Vector3.UnitX;
                extDir2 = Vector3.UnitY;
            }

            _vertexBuffer[0] = new ColoredVertex(start + extDir1 * (width / 2), color);
            _vertexBuffer[1] = new ColoredVertex(start - extDir1 * (width / 2), color);
            _vertexBuffer[2] = new ColoredVertex(end + extDir1 * (width / 2), color);
            _vertexBuffer[3] = new ColoredVertex(end - extDir1 * (width / 2), color);

            _vertexBuffer[4] = new ColoredVertex(start + extDir2 * (width / 2), color);
            _vertexBuffer[5] = new ColoredVertex(start - extDir2 * (width / 2), color);
            _vertexBuffer[6] = new ColoredVertex(end + extDir2 * (width / 2), color);
            _vertexBuffer[7] = new ColoredVertex(end - extDir2 * (width / 2), color);

            _indexBuffer[0] = 0;
            _indexBuffer[1] = 1;
            _indexBuffer[2] = 2;

            _indexBuffer[3] = 1;
            _indexBuffer[4] = 2;
            _indexBuffer[5] = 3;

            _indexBuffer[6] = 4;
            _indexBuffer[7] = 5;
            _indexBuffer[8] = 6;

            _indexBuffer[9]  = 5;
            _indexBuffer[10] = 6;
            _indexBuffer[11] = 7;

            SetDeclaration();
            Device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, 8, 4, _indexBuffer,
                                             Format.Index32, _vertexBuffer, ColoredVertex.Stride);
        }
Пример #16
0
        public void rotateModel(SlimDX.Vector3 axis, float amount)
        {
            var invWorld = SlimDX.Matrix.RotationAxis(axis, (amount / 180.0f) * (float)Math.PI) * mResult.ModelMatrix;

            mResult.ModelMatrix = invWorld;
            mResult.Renderer.UpdateInstance(mResult.InstanceID, mResult.ModelMatrix);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.ModelMatrix);
            }
        }
Пример #17
0
        public void moveModel(SlimDX.Vector3 axis, float amount)
        {
            var newMatrix = mResult.ModelMatrix * SlimDX.Matrix.Translation(axis * amount);

            mResult.ModelMatrix = newMatrix;
            mResult.Renderer.UpdateInstance(mResult.InstanceID, mResult.ModelMatrix);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.ModelMatrix);
            }
        }
Пример #18
0
        private void addMdxModel(string modelName, SlimDX.Vector3 pos)
        {
            ADT.Wotlk.MDDF mdf = new MDDF();
            mdf.orientationX = mdf.orientationY = mdf.orientationZ = 0.0f;
            mdf.posX         = pos.X + Utils.Metrics.MidPoint;
            mdf.posZ         = pos.Y + Utils.Metrics.MidPoint;
            mdf.posY         = pos.Z;

            mdf.scaleFactor = 1024;
            mdf.idMMID      = (uint)mParent.addMdxName(modelName);
            mRefs.Add(mParent.addModelDefintion(mdf));
        }
Пример #19
0
        /// <summary> Draw outlined box.</summary>
        /// <remarks> Nesox, 2013-12-28.</remarks>
        /// <param name="center"> The min. </param>
        /// <param name="length"> The length. </param>
        /// <param name="width">  The width. </param>
        /// <param name="height"> The height. </param>
        /// <param name="color">  The color. </param>
        public static void DrawOutlinedBox(Vector3 center, float length, float width, float height, Color color)
        {
            float w = width / 2;
            float h = height / 2;
            float d = length / 2;

            Matrix mat = Matrix.Identity * Matrix.Scaling(w, d, h) * Matrix.Translation(center);

            Device.SetTransform(TransformState.World, mat);

            var min = new Vector3(-1, -1, 0);
            var max = new Vector3(1, 1, 1);

            var vtx = new[]
            {
                new ColoredVertex(new Vector3(min.X, max.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, max.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, min.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, min.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, min.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, min.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, max.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, max.Y, min.Z), color.ToArgb())
            };

            var ind = new short[]
            {
                //Top           [_]
                0, 1, 1, 3,
                3, 2, 2, 0,
                //Bottom        [_]
                6, 7, 7, 5,
                5, 4, 4, 6,
                // Back         | |
                0, 6, 1, 7,
                // Front        | |
                2, 4, 3, 5,
                // Left         | |
                0, 6, 2, 4,
                // Right        | |
                1, 7, 3, 5
            };

            var oldDecl = Device.VertexDeclaration;

            using (var newDecl = ColoredVertex.GetDecl(Device))
            {
                Device.VertexDeclaration = newDecl;
                Device.DrawIndexedUserPrimitives(PrimitiveType.LineList, 0, 8, 12, ind, Format.Index16, vtx, 16);
                Device.VertexDeclaration = oldDecl;
            }
        }
Пример #20
0
        // DrawLine
        private void DrawLine(SlimDX.Vector3 from, SlimDX.Vector3 to, System.Drawing.Color color)
        {
            var vertices = new List <PositionColored>();

            vertices.Add(new PositionColored(from, color.ToArgb()));
            vertices.Add(new PositionColored(to, color.ToArgb()));

            var buffer = vertices.ToArray();

            SetTarget(SlimDX.Vector3.Zero);

            D3D.Device.DrawUserPrimitives(SlimDX.Direct3D9.PrimitiveType.LineStrip, vertices.Count - 1, buffer);
        }
Пример #21
0
        public void moveModel(SlimDX.Vector3 axis, float amount)
        {
            var newData   = mResult.InstanceData;
            var newMatrix = newData.ModelMatrix * SlimDX.Matrix.Translation(axis * amount);

            newData.ModelMatrix  = newMatrix;
            mResult.InstanceData = newData;
            mResult.Renderer.InstanceLoader.setInstance(mResult.InstanceID, mResult.InstanceData);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.InstanceData.ModelMatrix);
            }
        }
Пример #22
0
        public void rotateModel(SlimDX.Vector3 axis, float amount)
        {
            var newData  = mResult.InstanceData;
            var invWorld = SlimDX.Matrix.RotationAxis(axis, (amount / 180.0f) * (float)Math.PI) * newData.ModelMatrix;

            newData.ModelMatrix  = invWorld;
            mResult.InstanceData = newData;
            mResult.Renderer.InstanceLoader.setInstance(mResult.InstanceID, mResult.InstanceData);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.InstanceData.ModelMatrix);
            }
        }
Пример #23
0
        // DrawCube
        //private void DrawCube(SlimDX.Vector3 loc, float width, float height, float depth)
        //{
        //    //var mesh = Mesh.CreateBox(D3D.Device, width, height, depth);
        //    if (_mesh == null)
        //        _mesh = Mesh.CreateBox(D3D.Device, width, height, depth);

        //    DrawMesh(_mesh, loc + new SlimDX.Vector3(0, 0, 1.3f), true);
        //}



        // DrawCubeTest
        private void DrawCubeTest(SlimDX.Vector3 loc, float width, float height, float depth, bool isFilled = true, bool wireframe = false)
        {
            //var mesh = Mesh.CreateBox(D3D.Device, width, height, depth);
            if (_mesh == null)
            {
                _mesh = Mesh.CreateBox(D3D.Device, width, height, depth);
            }

            //light = new Light();
            //light.Type = LightType.Point;
            //light.Range = 75;
            //light.Position = new SlimDX.Vector3(10, 25, 0);
            //light.Falloff = 1.0f;
            //light.Diffuse = System.Drawing.Color.LemonChiffon;
            //light.Ambient = ambient;

            //activeMaterial = new Material();
            //activeMaterial.Diffuse = System.Drawing.Color.Orange;
            //activeMaterial.Ambient = ambient;

            //passiveMaterial = new Material();
            //passiveMaterial.Diffuse = System.Drawing.Color.Red;
            //passiveMaterial.Ambient = ambient;

            //groundMaterial = new Material();
            //groundMaterial.Diffuse = System.Drawing.Color.Green;
            //groundMaterial.Ambient = ambient;



            //_mesh.Device.
            //_mesh.Device.ColorFill()

            //DrawMesh(_mesh, loc + new SlimDX.Vector3(0, 0, 0.3f));
            //DrawMesh(mesh, loc);


            //_mesh.

            DrawMesh(_mesh, loc + new SlimDX.Vector3(0, 0, (depth / 2)), wireframe, isFilled); // (depth / 2) prevent drawing below ground if using player coords to draw

            //DrawMesh(_mesh, loc + new SlimDX.Vector3(0, 0, (depth / 2)), wireframe, isFilled); // (depth / 2) prevent drawing below ground if using player coords to draw



            //SlimDX.Color4 w_color4 = new SlimDX.Color4();

            //w_color4

            // GetTexture(D3D.Device, 50, 50, System.Drawing.Color.Red;
        }
Пример #24
0
        public void moveModel(SlimDX.Vector3 newPos)
        {
            var newMatrix = mResult.ModelMatrix;

            newMatrix.M41       = newPos.X;
            newMatrix.M42       = newPos.Y;
            newMatrix.M43       = newPos.Z;
            mResult.ModelMatrix = newMatrix;
            mResult.Renderer.UpdateInstance(mResult.InstanceID, mResult.ModelMatrix);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.ModelMatrix);
            }
        }
Пример #25
0
        public System.Windows.Point CanvasPointFrom3DPoint(Point3D modelPoint3D)
        {
            Point3D worldPoint = ViewportImage.ModelToWorld.Transform(modelPoint3D);

            SlimDX.Vector3 worldPointSlimDX = new SlimDX.Vector3((float)worldPoint.X, (float)worldPoint.Y, (float)worldPoint.Z);
            float          width            = (float)ViewportImage.imageWidth;
            float          height           = (float)ViewportImage.imageHeight;

            SlimDX.Matrix trans = SlimDX.Matrix.Multiply(ViewportImage.View, ViewportImage.Projection);
            //Vector3 point2DSlimDX = Vector3.Project(worldPointSlimDX, 0, 0, ViewportImage.Width, ViewportImage.Height, 0.0f, 1.0f, trans);
            Vector3 point2DSlimDX = Vector3.Project(worldPointSlimDX, 0, 0, width, height, 0.0f, 1.0f, trans);

            return(new System.Windows.Point((double)(point2DSlimDX.X), (double)(point2DSlimDX.Y)));
        }
Пример #26
0
        /// <summary> Draws a line. </summary>
        /// <param name="vecStartPos"> The vector start position. </param>
        /// <param name="vecEndPos">   The vector end position. </param>
        /// <param name="width">       The width. </param>
        /// <param name="color">       The color. </param>
        public static void DrawLineEx2(Vector3[] points, float width, Color color)
        {
            float halfWidth    = width * 0.5f;
            int   segmentCount = points.Length / 2;

            var positions = new Point3DCollection(segmentCount * 4);

            for (int i = 0; i < segmentCount; i++)
            {
                int     startIndex = i * 2;
                Vector3 startPoint = points[startIndex];
                Vector3 endPoint   = points[startIndex + 1];
            }
        }
Пример #27
0
        public void moveModel(SlimDX.Vector3 newPos)
        {
            var newData   = mResult.InstanceData;
            var newMatrix = mResult.InstanceData.ModelMatrix;

            newMatrix.M41        = newPos.X;
            newMatrix.M42        = newPos.Y;
            newMatrix.M43        = newPos.Z;
            newData.ModelMatrix  = newMatrix;
            mResult.InstanceData = newData;
            mResult.Renderer.InstanceLoader.setInstance(mResult.InstanceID, mResult.InstanceData);
            if (ModelChanged != null)
            {
                ModelChanged(mResult.InstanceData.ModelMatrix);
            }
        }
Пример #28
0
        public void Update(uint mapid, SlimDX.Vector3 position)
        {
            if (Game.GameManager.IsPandaria)
            {
                return;
            }

            position.X = Utils.Metrics.MidPoint + position.X;
            position.Y = Utils.Metrics.MidPoint + position.Y;
            if (mSkyMapper.ContainsKey(mapid))
            {
                mSkyMapper[mapid].UpdateSky(position);
                Video.ShaderCollection.TerrainShader.SetValue("fogColor", new Vector4(mSkyMapper[mapid].GetColorEntry(ColorTableValues.Fog), 1.0f));
                Video.ShaderCollection.MDXShader.SetValue("fogColor", new Vector4(mSkyMapper[mapid].GetColorEntry(ColorTableValues.Fog), 1.0f));
                Video.ShaderCollection.WMOShader.SetValue("fogColor", new Vector4(mSkyMapper[mapid].GetColorEntry(ColorTableValues.Fog), 1.0f));
            }
        }
Пример #29
0
        /// <summary> Draw box. </summary>
        /// <remarks> Nesox, 2013-06-14. </remarks>
        /// <param name="center"> The min. </param>
        /// <param name="length"> The length. </param>
        /// <param name="width">  The width. </param>
        /// <param name="height"> The height. </param>
        /// <param name="color">  The color. </param>
        public static void DrawBox(Vector3 center, float length, float width, float height, Color color)
        {
            length /= 2f;
            width  /= 2f;
            height /= 2f;
            var extents = new Vector3(width, length, height);

            Device.SetTransform(TransformState.World, Matrix.Translation(center.X, center.Y, center.Z));

            var vtx = new[]
            {
                new ColoredVertex(new Vector3(-extents.X, extents.Y, extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(extents.X, extents.Y, extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(extents.X, -extents.Y, extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(-extents.X, -extents.Y, extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(-extents.X, extents.Y, -extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(extents.X, extents.Y, -extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(extents.X, -extents.Y, -extents.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(-extents.X, -extents.Y, -extents.Z), color.ToArgb())
            };

            var ind = new short[]
            {
                // front
                0, 1, 2, 2, 3, 0,
                // right
                1, 5, 6, 6, 2, 1,
                // back
                5, 4, 7, 7, 6, 5,
                // left
                4, 0, 3, 3, 7, 4,
                // top
                4, 5, 1, 1, 0, 4,
                // bottom
                3, 2, 6, 6, 7, 3
            };

            var oldDecl = Device.VertexDeclaration;

            using (var newDecl = ColoredVertex.GetDecl(Device))
            {
                Device.VertexDeclaration = newDecl;
                Device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, 8, 12, ind, Format.Index16, vtx, 16);
                Device.VertexDeclaration = oldDecl;
            }
        }
Пример #30
0
        private void addWmoModel(string modelName, SlimDX.Vector3 pos)
        {
            MODF modf = new MODF();

            modf.flags    = 0;
            modf.lextentX = modf.lextentY = modf.lextentZ = 0;
            modf.padding  = 0;
            modf.Position = new Vector3(pos.X + Utils.Metrics.MidPoint, pos.Z, pos.Y + Utils.Metrics.MidPoint);
            modf.Rotation = Vector3.Zero;
            modf.setIndex = 0;
            modf.uextentX = modf.uextentY = modf.uextentZ = 0;
            modf.uniqueId = 0;
            modf.unknown  = 0;

            modf.idMWID = (uint)mParent.addWmoName(modelName);
            mWmoRefs.Add(mParent.addWmoDefintion(modf));
        }
Пример #31
0
        public void DrawOutlinedBox(Vector3 center, Vector3 extents, Color color)
        {
            Vector3 min = center - extents;
            Vector3 max = center + extents;

            _vertexBuffer[0] = new ColoredVertex(new Vector3(min.X, max.Y, max.Z), color);
            _vertexBuffer[1] = new ColoredVertex(new Vector3(max.X, max.Y, max.Z), color);
            _vertexBuffer[2] = new ColoredVertex(new Vector3(min.X, min.Y, max.Z), color);
            _vertexBuffer[3] = new ColoredVertex(new Vector3(max.X, min.Y, max.Z), color);
            _vertexBuffer[4] = new ColoredVertex(new Vector3(min.X, min.Y, min.Z), color);
            _vertexBuffer[5] = new ColoredVertex(new Vector3(max.X, min.Y, min.Z), color);
            _vertexBuffer[6] = new ColoredVertex(new Vector3(min.X, max.Y, min.Z), color);
            _vertexBuffer[7] = new ColoredVertex(new Vector3(max.X, max.Y, min.Z), color);

            SetDeclaration();
            Device.DrawIndexedUserPrimitives(PrimitiveType.LineList, 0, 8, 12, s_boxOutlineIndices,
                                             Format.Index16, _vertexBuffer, 16);
        }
Пример #32
0
        /// <summary>
        /// Creates a right-handed spherical billboard that rotates around a specified object position.
        /// </summary>
        /// <param name="objectPosition">The position of the object around which the billboard will rotate.</param>
        /// <param name="cameraPosition">The position of the camera.</param>
        /// <param name="cameraUpVector">The up vector of the camera.</param>
        /// <param name="cameraForwardVector">The forward vector of the camera.</param>
        public static Matrix BillboardLh(ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, ref Vector3 cameraForwardVector)
        {
            var     result = new Matrix();
            Vector3 crossed;
            Vector3 final;
            Vector3 difference = cameraPosition - objectPosition;

            float lengthSq = difference.LengthSquared();

            if (IsZero(lengthSq))
            {
                difference = -cameraForwardVector;
            }
            else
            {
                difference *= (float)(1.0 / Math.Sqrt(lengthSq));
            }

            Vector3.Cross(ref cameraUpVector, ref difference, out crossed);
            crossed.Normalize();
            Vector3.Cross(ref difference, ref crossed, out final);

            result.M11 = crossed.X;
            result.M12 = crossed.Y;
            result.M13 = crossed.Z;
            result.M14 = 0.0f;

            result.M21 = final.X;
            result.M22 = final.Y;
            result.M23 = final.Z;
            result.M24 = 0.0f;

            result.M31 = difference.X;
            result.M32 = difference.Y;
            result.M33 = difference.Z;
            result.M34 = 0.0f;

            result.M41 = objectPosition.X;
            result.M42 = objectPosition.Y;
            result.M43 = objectPosition.Z;
            result.M44 = 1.0f;

            return(result);
        }
Пример #33
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            if (!this.FTextureOutput[0].Contains(context))
            {
                this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm);
                this.FPCOut[0][context] = new DX11DynamicStructuredBuffer<float>(context, 640 * 480 * 6);

            }

            if (this.FInvalidate)
            {
                fixed (int* f = &this.pic[0])
                {
                    IntPtr ptr = new IntPtr(f);
                    this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4);
                }

                /*fixed (float* f = &this.piccloud[0])
                {*
                    IntPtr ptr = new IntPtr(f);*/

                    DX11DynamicStructuredBuffer<float> db = (DX11DynamicStructuredBuffer<float>)this.FPCOut[0][context];
                    db.WriteData(this.piccloud);
                //}

                this.FInvalidate = false;
            }

            if (this.FInVoxels[0])
            {
                if (this.FOutVoxels[0].Contains(context))
                {
                    this.FOutVoxels[0].Dispose(context);
                }

                short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ];

                this.colorVolume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data);

                DX11DynamicStructuredBuffer<int> b = new DX11DynamicStructuredBuffer<int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ);

                int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ];

                for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++)
                {
                    idata[i] = data[i];
                }

                b.WriteData(idata);

                this.FOutVoxels[0][context] = b;
            }

            if (this.FInExport[0])
            {
                if (this.FGeomOut[0].Contains(context))
                {
                    this.FGeomOut[0].Dispose(context);
                }

                if (this.colorVolume != null)
                {
                    ColorMesh m = this.colorVolume.CalculateMesh(this.FInGeomVoxelStep[0]);

                    DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

                    ReadOnlyCollection<int> inds = m.GetTriangleIndexes();

                    DataStream ds = new DataStream(inds.Count*4,true,true);
                    ds.WriteRange<int>(inds.ToArray());
                    ds.Position = 0;

                    DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true);

                    ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> pos = m.GetVertices();
                    ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> norm = m.GetNormals();
                    ReadOnlyCollection<int> col = m.GetColors();

                    DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count,true,true);

                    SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                    SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue);

                    for (int i = 0; i < pos.Count; i++)
                    {
                        Microsoft.Kinect.Toolkit.Fusion.Vector3 p = pos[i];
                        Microsoft.Kinect.Toolkit.Fusion.Vector3 n = norm[i];

                        dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(p);
                        dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(n);
                        dsv.Write<int>(col[i]);

                        if (p.X < bmin.X) { bmin.X = p.X; }
                        if (p.Y < bmin.Y) { bmin.Y = p.Y; }
                        if (p.Z < bmin.Z) { bmin.Z = p.Z; }

                        if (p.X > bmax.X) { bmax.X = p.X; }
                        if (p.Y > bmax.Y) { bmax.Y = p.Y; }
                        if (p.Z > bmax.Z) { bmax.Z = p.Z; }
                    }

                    geom.IndexBuffer = ibo;
                    geom.HasBoundingBox = true;
                    geom.InputLayout = FusionColoredVertex.Layout;
                    geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
                    geom.VertexSize = FusionColoredVertex.VertexSize;
                    geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, dsv, false, true);
                    geom.VerticesCount = pos.Count;
                    geom.BoundingBox = new BoundingBox(bmin, bmax);

                    this.FGeomOut[0][context] = geom;

                    m.Dispose();
                }
            }
        }
Пример #34
0
        public Ray Get2DRayFromScreenPoint(Point screenLocation)
        {
            Point p = screenLocation;
            float h = mParent.Height;
            float w = mParent.Width;
            Vector3 rayDir = Vector3.UnitZ;
            Vector3 rayOrigin = new Vector3()
            {
                X = (((2.0f * p.X) / w) - 1) / 1,
                Y = -(((2.0f * p.Y) / h) - 1) / 1,
                Z = 0
            };

            Matrix trans = Matrix.Invert(Get2DTransform(false));
            //rayDir = Vector3.TransformCoordinate(rayDir, trans);
            rayOrigin = Vector3.TransformCoordinate(rayOrigin, trans);
            Ray ray = new Ray(rayOrigin, rayDir);
            return ray;
        }
Пример #35
0
        public Ray Get3DRayFromScreenPoint(Point screenLocation)
        {
            Point p = screenLocation;

            Vector3 v = new Vector3(0, 0, 0);
            float h = mParent.Height;
            float w = mParent.Width;
            Matrix iProj = camera.Proj;
            v.X = (((2.0f * p.X) / w) - 1) / iProj.M11;
            v.Y = -(((2.0f * p.Y) / h) - 1) / iProj.M22;
            v.Z = 1;

            Matrix m = Matrix.Invert(camera.View);
            Vector3 rayDir = new Vector3();
            rayDir.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31;
            rayDir.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32;
            rayDir.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33;
            rayDir = Vector3.Normalize(rayDir);
            Vector3 rayOrigin = new Vector3();
            rayOrigin.X = m.M41;
            rayOrigin.Y = m.M42;
            rayOrigin.Z = m.M43;
            Ray ray = new Ray(rayOrigin, rayDir);
            return ray;
        }
Пример #36
0
 public Float3(SlimDX.Vector3 original)
 {
     vec = original;
 }
 public void AddVertex(Vector3 position, ProjectionType type)
 {
     Vector3 normal = new Vector3(1,1,1);
     if ((Vertices.Count + 1) % 3 == 0)
     {
         normal = Vector3.Cross(position, (Vertices[Vertices.Count - 1] as VertexPosNorTex).Position);
         (Vertices[Vertices.Count - 1] as VertexPosNorTex).Normal = normal;
         (Vertices[Vertices.Count - 2] as VertexPosNorTex).Normal = normal;
     }
     AddVertex(new VertexPosNorTex(position, normal, GenerateUV(type, position, normal, new Vector2(1, 1))));
 }
 public void AddVertex(Vector3 position, Vector3 normal, ProjectionType type)
 {
     AddVertex(new VertexPosNorTex(position, normal, GenerateUV(type, position, normal, new Vector2(1, 1))));
 }
 public void AddVertex(Vector3 position, Vector3 normal, Vector2 textCoordinate)
 {
     AddVertex(new VertexPosNorTex(position, normal, textCoordinate));
 }
 public static Vector2 GenerateUV(ProjectionType type, Vector3 position, Vector3 normal, Vector2 scale)
 {
     if (type == ProjectionType.Spherical)
     {
         return MathHelper.Multiply(
             new Vector2(
                 0.5f - ((float)Math.Atan2(position.Z, position.X)) / ((float)Math.PI * 2),
                 0.5f - 2 * ((float)Math.Asin(position.Y)) / ((float)Math.PI * 2)), scale * 6);
     }
     else if (type == ProjectionType.Box)
     {
         //return MathHelper.Multiply(new Vector2((position.X * normal.Z) + (position.Y * normal.X) + (position.Z * normal.Y), (position.X * normal.Y) + (position.Y * normal.Z) + (position.Z * normal.X)), (textureScale * 0.1f));
         return MathHelper.Multiply(
             new Vector2(
                 (position.X * normal.Z) + (position.Y * normal.X) + (position.Z * normal.Y),
                 (position.X * normal.Y) + (position.Y * normal.Z) + (position.Z * normal.X)),
                 (scale * 0.1f)
                 );
     }
     else if (type == ProjectionType.Conical)
     {
         float phi = (float)Math.Atan2(normal.Z, normal.X);
         return MathHelper.Multiply(new Vector2(
             position.Y,
             phi
             ), scale);
     }
     return Vector2.Zero;
 }
        public void GenerateTangentFrame(out Vector3[] Tangent, out Vector3[] Bitangent)
        {
            Tangent = new Vector3[GeometryData.Vertices.Count];
            Bitangent = new Vector3[GeometryData.Vertices.Count];
            for (int i = 0; i < GeometryData.Indices.Count; i += 3)
            {
                Vector3 bitangent = Vector3.Zero;
                Vector3 tangent = MathHelper.CalculateTangent(
                    GeometryData.Vertices[GeometryData.Indices[i]].GetVertex<Vector3>(VertexParameterType.Position).Value,
                    GeometryData.Vertices[GeometryData.Indices[i + 1]].GetVertex<Vector3>(VertexParameterType.Position).Value,
                    GeometryData.Vertices[GeometryData.Indices[i + 2]].GetVertex<Vector3>(VertexParameterType.Position).Value,
                    GeometryData.Vertices[GeometryData.Indices[i]].GetVertex<Vector2>(VertexParameterType.TextureCoordinate).Value,
                    GeometryData.Vertices[GeometryData.Indices[i + 1]].GetVertex<Vector2>(VertexParameterType.TextureCoordinate).Value,
                    GeometryData.Vertices[GeometryData.Indices[i + 2]].GetVertex<Vector2>(VertexParameterType.TextureCoordinate).Value, out bitangent);
                Tangent[GeometryData.Indices[i]] += tangent;
                Tangent[GeometryData.Indices[i + 1]] += tangent;
                Tangent[GeometryData.Indices[i + 2]] += tangent;
                Bitangent[GeometryData.Indices[i]] += bitangent;
                Bitangent[GeometryData.Indices[i + 1]] += bitangent;
                Bitangent[GeometryData.Indices[i + 2]] += bitangent;
            }
            for (int a = 0; a < GeometryData.Vertices.Count; a++)
            {
                Vector3 n = GeometryData.Vertices[a].GetVertex<Vector3>(VertexParameterType.Normal).Value;
                Vector3 t = Tangent[a];

                // Gram-Schmidt orthogonalize
                Tangent[a] = Vector3.Normalize(t - n * Vector3.Dot(n, t));

                //Bitangent[a] = Vector3.Cross(n, Tangent[a]);

                // Calculate handedness
                //tangent[a].w = (Dot(Cross(n, t), tan2[a]) < 0.0F) ? -1.0F : 1.0F;
            }
        }
Пример #42
-12
 Prop(Common.Classes.Prop class_, Vector3 position, float rotation, float scale)
 {
     this.Class = class_;
     this.position = position;
 }