public PolygonShape(GraphicsDevice graphicsDevice, VertexPositionColorTexture[] vertices)
	{
		this.graphicsDevice = graphicsDevice;
		this.vertices = vertices;
		this.triangulated = false;

		triangulatedVertices = new VertexPositionColorTexture[vertices.Length * 3];
		indexes = new int[vertices.Length];
	}
	public static void PostUpdate() {
		if (style == "circular_bottomleft") {
			int xx = 4;
			
			List<ModWorld.NPCInst> list = ModWorld.GetActualNPCs();
			foreach (ModWorld.NPCInst npci in list) {
				if (!ModWorld.IsBoss(npci)) continue;
				var gd = Config.mainInstance.graphics.GraphicsDevice;
				
				Player p = Main.player[Main.myPlayer];
				if (Vector2.Distance(p.position+new Vector2(p.width/2f,p.height/2f),npci.GetCenterPos()) > 2*Math.Sqrt(Math.Pow(Main.screenWidth,2)+Math.Pow(Main.screenHeight,2))) continue;
				
				gd.SetRenderTarget(rt);
				
				float hpPercent = 1f*npci.GetLife()/npci.GetLifeMax();
				int phase = -1;
				
				Object[] ret = new Object[]{null,null};
				if (Codable.RunGlobalMethod("ModWorld","ExternalGetBossPhase",npci.parts,npci.GetName(),npci.GetCenterPos(),npci.GetLife(),npci.GetLifeMax(),ret)) {
					if (ret[0] != null && ret[1] != null) {
						phase = (int)ret[0];
						hpPercent = (float)ret[1];
					}
				}
				int angle = (int)(hpPercent*270);
				
				sb.Begin(SpriteSortMode.Immediate,bs1,null,dss1,null);
				gd.Clear(ClearOptions.Target | ClearOptions.Stencil,Color.Transparent,0,0);
				VertexPositionColorTexture[] pointList = new VertexPositionColorTexture[Math.Max(angle/2+1,3)];
				pointList[0] = new VertexPositionColorTexture(new Vector3(48,48,0),Color.White,default(Vector2));
				for (int i = 1; i <= 2; i++) pointList[pointList.Length-i] = new VertexPositionColorTexture(new Vector3(48+LdirX(48,270),48+LdirY(48,270),0),Color.White,default(Vector2));
				for (int i = 0; i < angle/2; i++) pointList[i+1] = new VertexPositionColorTexture(new Vector3(48+LdirX(48,270-i*2),48+LdirY(48,270-i*2),0),Color.White,default(Vector2));
				new ModWorld.PolygonShape(Config.mainInstance.graphics.GraphicsDevice,pointList).Draw();;
				sb.End();
				
				sb.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied,null,dss2,null);
				sb.Draw(phase == -1 ? ModWorld.texTop : ModWorld.texPhase[phase],default(Vector2),Color.White);
				sb.End();
				gd.SetRenderTarget(null);
				
				string s = ""+npci.GetLife()+"/"+npci.GetLifeMax();
				xx += (int)(Math.Max(Main.fontMouseText.MeasureString(s).X,Main.fontMouseText.MeasureString(npci.GetName()).X)+68);
			}
		}
	}
Ejemplo n.º 3
0
        public void TestVertexPositionColorTexture()
        {
            Assert.That(VertexPositionColorTexture.VertexDeclaration.VertexStride, Is.EqualTo(24));

            var vertexElements = VertexPositionColorTexture.VertexDeclaration.GetVertexElements();

            Assert.That(vertexElements, Has.Length.EqualTo(3));
            Assert.That(vertexElements[0].Offset, Is.EqualTo(0));
            Assert.That(vertexElements[0].UsageIndex, Is.EqualTo(0));
            Assert.That(vertexElements[0].VertexElementFormat, Is.EqualTo(VertexElementFormat.Vector3));
            Assert.That(vertexElements[0].VertexElementUsage, Is.EqualTo(VertexElementUsage.Position));
            Assert.That(vertexElements[1].Offset, Is.EqualTo(12));
            Assert.That(vertexElements[1].UsageIndex, Is.EqualTo(0));
            Assert.That(vertexElements[1].VertexElementFormat, Is.EqualTo(VertexElementFormat.Color));
            Assert.That(vertexElements[1].VertexElementUsage, Is.EqualTo(VertexElementUsage.Color));
            Assert.That(vertexElements[2].Offset, Is.EqualTo(16));
            Assert.That(vertexElements[2].UsageIndex, Is.EqualTo(0));
            Assert.That(vertexElements[2].VertexElementFormat, Is.EqualTo(VertexElementFormat.Vector2));
            Assert.That(vertexElements[2].VertexElementUsage, Is.EqualTo(VertexElementUsage.TextureCoordinate));

            var vertex1 = new VertexPositionColorTexture(Vector3.One, Color.Blue, Vector2.One);
            var vertex2 = new VertexPositionColorTexture(Vector3.One, Color.Blue, Vector2.One);
            var vertex3 = new VertexPositionColorTexture(Vector3.One, Color.Red, Vector2.One);
            var vertex4 = new VertexPositionColorTexture(Vector3.Forward, Color.Blue, Vector2.One);
            var vertex5 = new VertexPositionColorTexture(Vector3.Forward, Color.Blue, Vector2.Zero);

            Assert.That(vertex1 == vertex2, Is.True);
            Assert.That(vertex1 != vertex2, Is.False);
            Assert.That(vertex1 == vertex3, Is.False);
            Assert.That(vertex1 != vertex3, Is.True);
            Assert.That(vertex1 == vertex4, Is.False);
            Assert.That(vertex1 != vertex4, Is.True);
            Assert.That(vertex4 == vertex5, Is.False);
            Assert.That(vertex4 != vertex5, Is.True);
            Assert.That(vertex1.Equals(vertex2), Is.True);
            Assert.That(vertex1.Equals(vertex3), Is.False);
            Assert.That(vertex1.Equals(vertex4), Is.False);
            Assert.That(vertex4.Equals(vertex5), Is.False);
        }
Ejemplo n.º 4
0
        //public virtual void Update(GameTime gameTime)
        //{

        //}

        public virtual void Initialize()
        {
            //DestinationRectangle = new Rectangle((int)Position.X, (int)Position.Y

            vertices[0] = new VertexPositionColorTexture()
            {
                Position          = new Vector3(DestinationRectangle.Left, DestinationRectangle.Top, 0),
                TextureCoordinate = new Vector2(0, 0),
                Color             = Color
            };

            vertices[1] = new VertexPositionColorTexture()
            {
                Position          = new Vector3(DestinationRectangle.Left + DestinationRectangle.Width, DestinationRectangle.Top, 0),
                TextureCoordinate = new Vector2(1, 0),
                Color             = Color
            };

            vertices[2] = new VertexPositionColorTexture()
            {
                Position          = new Vector3(DestinationRectangle.Left + DestinationRectangle.Width, DestinationRectangle.Top + DestinationRectangle.Height, 0),
                TextureCoordinate = new Vector2(1, 1),
                Color             = Color
            };

            vertices[3] = new VertexPositionColorTexture()
            {
                Position          = new Vector3(DestinationRectangle.Left, DestinationRectangle.Top + DestinationRectangle.Height, 0),
                TextureCoordinate = new Vector2(0, 1),
                Color             = Color
            };

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 3;
            indices[5] = 0;
        }
            private void RecalculateVertices(Wire wire, float width)
            {
                if (MathUtils.NearlyEqual(cachedWidth, width))
                {
                    return;
                }
                cachedWidth = width;

                vertices = new VertexPositionColorTexture[4];

                Vector2 expandDir = start - end;

                expandDir.Normalize();
                float temp = expandDir.X;

                expandDir.X = -expandDir.Y;
                expandDir.Y = -temp;

                Rectangle srcRect = wire.wireSprite.SourceRect;

                expandDir *= width * srcRect.Height * 0.5f;

                Vector2 rectLocation = srcRect.Location.ToVector2();
                Vector2 rectSize     = srcRect.Size.ToVector2();
                Vector2 textureSize  = new Vector2(wire.wireSprite.Texture.Width, wire.wireSprite.Texture.Height);

                Vector2 topLeftUv     = rectLocation / textureSize;
                Vector2 bottomRightUv = (rectLocation + rectSize) / textureSize;

                Vector2 invStart = new Vector2(start.X, -start.Y);
                Vector2 invEnd   = new Vector2(end.X, -end.Y);

                vertices[0] = new VertexPositionColorTexture(new Vector3(invStart + expandDir, 0f), Color.White, topLeftUv);
                vertices[2] = new VertexPositionColorTexture(new Vector3(invEnd + expandDir, 0f), Color.White, new Vector2(bottomRightUv.X, topLeftUv.Y));
                vertices[1] = new VertexPositionColorTexture(new Vector3(invStart - expandDir, 0f), Color.White, new Vector2(topLeftUv.X, bottomRightUv.Y));
                vertices[3] = new VertexPositionColorTexture(new Vector3(invEnd - expandDir, 0f), Color.White, bottomRightUv);

                shiftedVertices = (VertexPositionColorTexture[])vertices.Clone();
            }
Ejemplo n.º 6
0
        public override void Render(NkHandle Userdata, Texture2D Texture, NkRect ClipRect, uint Offset, uint Count)
        {
            VertexPositionColorTexture[] MonoVerts = new VertexPositionColorTexture[Count];

            for (int i = 0; i < Count; i++)
            {
                NkVertex V = _verts[_inds[Offset + i]];
                MonoVerts[i] = new VertexPositionColorTexture(new Vector3(V.Position.X, V.Position.Y, 0), new Color(V.Color.R, V.Color.G, V.Color.B, V.Color.A), new Vector2(V.UV.X, V.UV.Y));
            }

            _vertexBuffer = new VertexBuffer(_graphics, typeof(VertexPositionColorTexture), (int)Count, BufferUsage.WriteOnly);
            _vertexBuffer.SetData <VertexPositionColorTexture>(MonoVerts);
            _graphics.SetVertexBuffer(_vertexBuffer);

            _basicEffect.Texture = Texture;

            foreach (EffectPass pass in _basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                _graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Count);
            }
        }
Ejemplo n.º 7
0
        protected override void Initialize()
        {
            // must be initialized. required by Content loading and rendering(will add itself to the Services)
            // note that MonoGame requires this to be initialized in the constructor, while WpfInterop requires it to
            // be called inside Initialize (before base.Initialize())
            _graphicsDeviceManager = new WpfGraphicsDeviceService(this)
            {
                DpiScalingFactor = 1, PreferMultiSampling = true
            };

            // wpf and keyboard need reference to the host control in order to receive input
            // this means every WpfGame control will have it's own keyboard & mouse manager which will only react if the mouse is in the control
            _keyboard = new WpfKeyboard(this);
            _mouse    = new WpfMouse(this);

            // must be called after the WpfGraphicsDeviceService instance was created
            base.Initialize();
            UpdateUniforms(0);
            VertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, 4, BufferUsage.None);
            IndexBuffer  = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, 6, BufferUsage.None);
            var vertices = new VertexPositionColorTexture[4];

            vertices[0] = new VertexPositionColorTexture(new Vector3(-1, -1, 0), Color.White, new Vector2(0, 1));
            vertices[1] = new VertexPositionColorTexture(new Vector3(1, 1, 0), Color.White, new Vector2(1, 0));
            vertices[2] = new VertexPositionColorTexture(new Vector3(-1, 1, 0), Color.White, new Vector2(0, 0));
            vertices[3] = new VertexPositionColorTexture(new Vector3(1, -1, 0), Color.White, new Vector2(1, 1));
            var indices = new int[] { 0, 2, 1, 0, 3, 1 };

            VertexBuffer.SetData(vertices);
            IndexBuffer.SetData(indices);
            Channel0 = new Channel(Texture2D.FromStream(GraphicsDevice, File.OpenRead("assets/textures/test.png")), TextureType.Texture2D);
            if (CompileShader(out var error))
            {
                var shaderbinary = File.ReadAllBytes($"temp/tempshader.dx11");
                Shader = new Effect(GraphicsDevice, shaderbinary);
                SetUniforms(Shader);
            }
        }
        //private VertexPositionColorTexture[] CreateSphere2(float radius, float slices, float stacks, out ushort[] indicess)
        //{
        //    List<VertexPositionColorTexture> vertex = new List<VertexPositionColorTexture>();

        //    float R = 1f;//球的半径

        //    float statckStep = (float)(Math.PI / stacks);//单位角度值

        //    float sliceStep = (float)(Math.PI / slices);//水平圆递增的角度

        //    float r0, r1, x0, x1, y0, y1, z0, z1; //r0、r1为圆心引向两个临近切片部分表面的两条线 (x0,y0,z0)和(x1,y1,z1)为临近两个切面的点。
        //    float alpha0 = 0, alpha1 = 0; //前后两个角度
        //    float beta = 0; //切片平面上的角度
        //    //List<Float> coordsList = new ArrayList<Float>();
        //    //外层循环
        //    for (int i = 0; i < stacks; i++)
        //    {
        //        alpha0 = (float)(-Math.PI / 2 + (i * statckStep));
        //        alpha1 = (float)(-Math.PI / 2 + ((i + 1) * statckStep));
        //        y0 = (float)(R * Math.Sin(alpha0));
        //        r0 = (float)(R * Math.Cos(alpha0));
        //        y1 = (float)(R * Math.Sin(alpha1));
        //        r1 = (float)(R * Math.Cos(alpha1));

        //        //循环每一层圆
        //        for (int j = 0; j <= (slices * 2); j++)
        //        {
        //            beta = j * sliceStep;
        //            x0 = (float)(r0 * Math.Cos(beta));
        //            z0 = -(float)(r0 * Math.Sin(beta));
        //            x1 = (float)(r1 * Math.Cos(beta));
        //            z1 = -(float)(r1 * Math.Sin(beta));

        //            //添加顶点
        //            var vpct = new VertexPositionColorTexture(new Vector3((float)x0, (float)y0, (float)z0), new Vector3(1, 1, 1), new Vector2((float)U, (float)V));
        //            vertex.Add(vpct);
        //        }
        //    }
        //}


        private static VertexPositionColorTexture[] GetCubeVertices()
        {
            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[]
            {
                // Top
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(0, 1)),
                // Bottom
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(0, 1)),
                // Left
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(0, 1)),
                // Right
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(0, 1)),
                // Back
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, -0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, -0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, -0.5f), new Vector2(0, 1)),
                // Front
                new VertexPositionColorTexture(new Vector3(-0.5f, +0.5f, +0.5f), new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, +0.5f, +0.5f), new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(+0.5f, -0.5f, +0.5f), new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, +0.5f), new Vector2(0, 1)),
            };

            return(vertices);
        }
        public override bool drawPoint(Vector3 position)
        {
            GraphicsDevice device = UWB_XNAGraphicsDevice.m_TheAPI.GraphicsDevice;
            Debug.Assert(device != null, "device not valid on DrawHelper drawCircle call");

            // Draw points as rectangles
            VertexPositionColorTexture[] v = new VertexPositionColorTexture[4];
            float offset = mPointSize / 2f;

            for (int i = 0; i < 4; i++)
            {
                v[i] = new VertexPositionColorTexture();
                v[i].Color = mColor1;
            }

            v[0].Position = new Vector3(position.X - offset, position.Y + offset, 0);
            v[0].TextureCoordinate = new Vector2(0f, 0f);

            v[1].Position = new Vector3(position.X - offset, position.Y - offset, 0);
            v[1].TextureCoordinate = new Vector2(0f, 1f);

            v[2].Position = new Vector3(position.X + offset, position.Y + offset, 0);
            v[2].TextureCoordinate = new Vector2(1f, 0f);

            v[3].Position = new Vector3(position.X + offset, position.Y - offset, 0);
            v[3].TextureCoordinate = new Vector2(1f, 1f);

            if (device.RasterizerState.FillMode != FillMode.Solid)
            {
                RasterizerState s = new RasterizerState();
                s.CullMode = CullMode.None;
                s.FillMode = FillMode.Solid;
                device.RasterizerState = s;
            }

            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, v, 0, 2);
            return true;
        }
Ejemplo n.º 10
0
        public void AddCap(VertexPositionColorTexture[] array, ref int currentIndex, Color colour, Vector2 position, Vector2 startNormal, float width)
        {
            //initial info
            float halfWidth = width * 0.5f;
            float arcStart  = startNormal.ToRotation();
            float arcAmount = MathHelper.Pi;
            //int segments = (int)Math.Ceiling(6 * Math.Sqrt(halfWidth) * (arcAmount / MathHelper.TwoPi));
            int   segments = ExtraTris;
            float theta    = arcAmount / segments;
            float cos      = (float)Math.Cos(theta);
            float sin      = (float)Math.Sin(theta);
            float t;
            float x = (float)Math.Cos(arcStart) * halfWidth;
            float y = (float)Math.Sin(arcStart) * halfWidth;

            position -= Main.screenPosition;

            //create initial vertices
            VertexPositionColorTexture center = new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0f), colour, Vector2.One * 0.5f);
            VertexPositionColorTexture prev   = new VertexPositionColorTexture(new Vector3(position.X + x, position.Y + y, 0f), colour, Vector2.One);

            for (int i = 0; i < segments; i++)
            {
                //apply matrix transformation
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;

                VertexPositionColorTexture next = new VertexPositionColorTexture(new Vector3(position.X + x, position.Y + y, 0f), colour, Vector2.One);

                //Add triangle vertices
                array[currentIndex++] = center;
                array[currentIndex++] = prev;
                array[currentIndex++] = next;

                prev = next;
            }
        }
Ejemplo n.º 11
0
        public static void DrawDottedCircle(float radius, Vector2 center, int segments, float rotation, Renderer renderer,
                                            Color col)
        {
            if (segments == 0)
            {
                return;
            }
            VertexPositionColorTexture[] arr = new VertexPositionColorTexture[segments];

            int     c   = 0;
            Vector2 off = center;

            for (double i = 0; i <= Math.PI * 2 - 0.001d; i += Math.PI * 2 / segments)
            {
                arr[c] = new VertexPositionColorTexture(
                    new Vector3((float)Math.Cos(i + rotation) * radius + off.X, (float)Math.Sin(i + rotation) * radius + off.Y, 0),
                    col, new Vector2());
                c++;
            }

            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;

            if (!renderer.IsDrawing)
            {
                renderer.BeginUnscaled();
            }
            Main.renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(0, 0, 0, 0), Color.White);
            renderer.End();

            renderer.GraphicsDevice.DrawUserPrimitives <VertexPositionColorTexture>(PrimitiveType.LineList,
                                                                                    arr, 0, arr.Length / 2);

            if (a)
            {
                renderer.Begin(b);
            }
        }
Ejemplo n.º 12
0
        public VertexBuffer PrepareStrip(Vector2 offset)
        {
            var buff = new VertexBuffer(Main.graphics.GraphicsDevice, typeof(VertexPositionColorTexture), chain.segmentCount * 9 - 6, BufferUsage.WriteOnly);

            VertexPositionColorTexture[] verticies = new VertexPositionColorTexture[chain.segmentCount * 9 - 6];

            float rotation = (chain.ropeSegments[0].posScreen - chain.ropeSegments[1].posScreen).ToRotation() + (float)Math.PI / 2;

            verticies[0] = new VertexPositionColorTexture((chain.ropeSegments[0].posScreen + offset + Vector2.UnitY.RotatedBy(rotation - Math.PI / 4) * -5).Vec3().ScreenCoord(), chain.ropeSegments[0].color, new Vector2(0, 0.2f));
            verticies[1] = new VertexPositionColorTexture((chain.ropeSegments[0].posScreen + offset + Vector2.UnitY.RotatedBy(rotation + Math.PI / 4) * -5).Vec3().ScreenCoord(), chain.ropeSegments[0].color, new Vector2(0, 0.8f));
            verticies[2] = new VertexPositionColorTexture((chain.ropeSegments[1].posScreen + offset).Vec3().ScreenCoord(), chain.ropeSegments[1].color, new Vector2(0, 0.5f));

            for (int k = 1; k < chain.segmentCount - 1; k++)
            {
                float progress  = k / 3f;
                float rotation2 = (chain.ropeSegments[k - 1].posScreen - chain.ropeSegments[k].posScreen).ToRotation() + (float)Math.PI / 2;
                float scale     = 2.4f;

                int point = k * 9 - 6;

                verticies[point]     = new VertexPositionColorTexture((chain.ropeSegments[k].posScreen + offset + Vector2.UnitY.RotatedBy(rotation2 - Math.PI / 4) * -(chain.segmentCount - k) * scale).Vec3().ScreenCoord(), chain.ropeSegments[k].color, new Vector2(progress, 0.2f));
                verticies[point + 1] = new VertexPositionColorTexture((chain.ropeSegments[k].posScreen + offset + Vector2.UnitY.RotatedBy(rotation2 + Math.PI / 4) * -(chain.segmentCount - k) * scale).Vec3().ScreenCoord(), chain.ropeSegments[k].color, new Vector2(progress, 0.8f));
                verticies[point + 2] = new VertexPositionColorTexture((chain.ropeSegments[k + 1].posScreen + offset).Vec3().ScreenCoord(), chain.ropeSegments[k + 1].color, new Vector2(progress + 1 / 3f, 0.5f));

                int extra = k == 1 ? 0 : 6;
                verticies[point + 3] = verticies[point];
                verticies[point + 4] = verticies[point - (3 + extra)];
                verticies[point + 5] = verticies[point - (1 + extra)];

                verticies[point + 6] = verticies[point - (2 + extra)];
                verticies[point + 7] = verticies[point + 1];
                verticies[point + 8] = verticies[point - (1 + extra)];
            }

            buff.SetData(verticies);

            return(buff);
        }
Ejemplo n.º 13
0
        public static MeshGroup FromFbx(GraphicsDevice graphics, string filePath)
        {
            const float Scale        = 96.0f;
            var         assimp       = new Assimp.AssimpContext();
            var         scene        = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices);
            var         baseFilePath = Path.GetDirectoryName(filePath);

            return(new MeshGroup()
            {
                MeshDescriptors = scene.Meshes
                                  .Select(x =>
                {
                    var vertices = new VertexPositionColorTexture[x.Vertices.Count];
                    for (var i = 0; i < vertices.Length; i++)
                    {
                        vertices[i].Position.X = x.Vertices[i].X * Scale;
                        vertices[i].Position.Y = x.Vertices[i].Y * Scale;
                        vertices[i].Position.Z = x.Vertices[i].Z * Scale;
                        vertices[i].TextureCoordinate.X = x.TextureCoordinateChannels[0][i].X;
                        vertices[i].TextureCoordinate.Y = 1.0f - x.TextureCoordinateChannels[0][i].Y;
                        vertices[i].Color = Color.White;
                    }

                    return new MeshDesc
                    {
                        Vertices = vertices,
                        Indices = x.Faces.SelectMany(f => f.Indices).ToArray(),
                        IsOpaque = true,
                        TextureIndex = x.MaterialIndex
                    };
                }).ToList(),
                Textures = scene.Materials.Select(x =>
                {
                    var path = Path.Join(baseFilePath, $"{x.Name}.png");
                    return new PngKingdomTexture(path, graphics);
                }).ToArray(),
            });
        }
Ejemplo n.º 14
0
        public void DrawFBO(Renderer r)
        {
            VertexPositionColorTexture[] v = new VertexPositionColorTexture[indices.Length * 3];
            VertexPositionColorTexture   v1, v2, v3, v4;

            for (int i = 0; i < indices.Length; i += 2)
            {
                v1 = new VertexPositionColorTexture(new Vector3(vertices[indices[i]].X, vertices[indices[i]].Y - w, 0), Color.White, new Vector2());
                v2 = new VertexPositionColorTexture(new Vector3(vertices[indices[i]].X, vertices[indices[i]].Y + w, 0), Color.White, new Vector2());
                v3 = new VertexPositionColorTexture(new Vector3(vertices[indices[i + 1]].X, vertices[indices[i + 1]].Y - w, 0), Color.White, new Vector2());
                v4 = new VertexPositionColorTexture(new Vector3(vertices[indices[i + 1]].X, vertices[indices[i + 1]].Y + w, 0), Color.White, new Vector2());

                v[i * 3 + 0] = v1;
                v[i * 3 + 1] = v2;
                v[i * 3 + 2] = v3;
                v[i * 3 + 3] = v2;
                v[i * 3 + 4] = v3;
                v[i * 3 + 5] = v4;
            }

            r.GraphicsDevice.Textures[0] = Graphics.GraphicsEngine.pixel;
            r.GraphicsDevice.DrawUserPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, v, 0, v.Length / 3);
        }
Ejemplo n.º 15
0
        public VertexPositionColorTexture GetVForAngle(double a)
        {
            VertexPositionColorTexture v = new VertexPositionColorTexture();
            Vector2 t = new Vector2((float)Math.Cos(a), (float)Math.Sin(a));

            if (Math.Abs(t.X) > Math.Abs(t.Y))
            {
                t *= 1 / Math.Abs(t.X);
            }
            else
            {
                t *= 1 / Math.Abs(t.Y);
            }
            t  += new Vector2(1, 1);
            t  /= 2;
            t.Y = 1 - t.Y;
            v.TextureCoordinate = t;
            v.Position          = new Vector3((t.X - 0.5f) * circle.Width / divider + circleCenter.X + Position.X,
                                              (t.Y - 0.5f) * circle.Height / divider + circleCenter.Y + Position.Y, 0);
            v.Color = circleColor;

            return(v);
        }
Ejemplo n.º 16
0
        public RenderingRectangle()
        {
            UseFrameRectLines            = true;
            UseFrameRectProjectingEffect = false;
            for (int i = 0; i < m_Vectors.Length; ++i)
            {
                m_Vectors[i] = new VertexPositionColorTexture();
            }
            m_Vectors[0].TextureCoordinate = new Vector2(0, 0);
            m_Vectors[1].TextureCoordinate = new Vector2(1, 0);
            m_Vectors[2].TextureCoordinate = new Vector2(1, 1);
            m_Vectors[3].TextureCoordinate = new Vector2(0, 1);

            for (int i = 0; i < m_RectLines.Length; ++i)
            {
                m_RectLines[i]       = new VertexPositionColor();
                m_RectLines[i].Color = Color.Black;
            }
            FrameRectLineColorLight = Color.White;
            FrameRectLineColorDark  = Color.Gray;
            RenderOffsetX           = 0;
            RenderOffsetY           = 0;
        }
        /******************************************** Textured - Quad, Cube & Pyramid ********************************************/

        public static VertexPositionColorTexture[] GetVerticesPositionColorTextureQuad(int sidelength,
                                                                                       out PrimitiveType primitiveType, out int primitiveCount)
        {
            primitiveType  = PrimitiveType.TriangleStrip;
            primitiveCount = 2;

            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4];

            float halfSideLength = sidelength / 2.0f;

            Vector3 topLeft     = new Vector3(-halfSideLength, halfSideLength, 0);
            Vector3 topRight    = new Vector3(halfSideLength, halfSideLength, 0);
            Vector3 bottomLeft  = new Vector3(-halfSideLength, -halfSideLength, 0);
            Vector3 bottomRight = new Vector3(halfSideLength, -halfSideLength, 0);

            //quad coplanar with the XY-plane (i.e. forward facing normal along UnitZ)
            vertices[0] = new VertexPositionColorTexture(topLeft, Color.White, Vector2.Zero);
            vertices[1] = new VertexPositionColorTexture(topRight, Color.White, Vector2.UnitX);
            vertices[2] = new VertexPositionColorTexture(bottomLeft, Color.White, Vector2.UnitY);
            vertices[3] = new VertexPositionColorTexture(bottomRight, Color.White, Vector2.One);

            return(vertices);
        }
Ejemplo n.º 18
0
        private void AddTextureSquare(int layer, int x, int y)
        {
            int tileX      = x + Location.X * SIZE;
            int tileY      = y + Location.Y * SIZE;
            int tileIndex  = GraphicsTiles[layer][x, y];
            int visualType = Tiles[x, y].visualType;

            short layerVertexIndex   = vertexIndex[layer];
            short layerIndiciesIndex = indiciesIndex[layer];

            // x and y are shifted downwards by half a unit so that they are drawn between world tiles
            // Bottom Left
            graphicsVertexTiles[layer][layerVertexIndex] = new VertexPositionColorTexture(
                new Vector3(tileX - 0.5f, tileY - 0.5f, 0), Color.White,
                GetTextureMapCoord(tileIndex, visualType, false, false));
            graphicsTileIndices[layer][layerIndiciesIndex++] = layerVertexIndex++;
            // Bottom Right
            graphicsVertexTiles[layer][layerVertexIndex] = new VertexPositionColorTexture(
                new Vector3(tileX + 0.5f, tileY - 0.5f, 0), Color.White,
                GetTextureMapCoord(tileIndex, visualType, false, true));
            graphicsTileIndices[layer][layerIndiciesIndex++] = layerVertexIndex++;
            // Top Left
            graphicsVertexTiles[layer][layerVertexIndex] = new VertexPositionColorTexture(
                new Vector3(tileX - 0.5f, tileY + 0.5f, 0), Color.White,
                GetTextureMapCoord(tileIndex, visualType, true, false));
            graphicsTileIndices[layer][layerIndiciesIndex++] = layerVertexIndex++;
            graphicsTileIndices[layer][layerIndiciesIndex++] = (short)(layerVertexIndex - 2);
            // Top Right
            graphicsVertexTiles[layer][layerVertexIndex] = new VertexPositionColorTexture(
                new Vector3(tileX + 0.5f, tileY + 0.5f, 0), Color.White,
                GetTextureMapCoord(tileIndex, visualType, true, true));
            graphicsTileIndices[layer][layerIndiciesIndex++] = layerVertexIndex++;
            graphicsTileIndices[layer][layerIndiciesIndex++] = (short)(layerVertexIndex - 2);

            vertexIndex[layer]   = layerVertexIndex;
            indiciesIndex[layer] = layerIndiciesIndex;
        }
Ejemplo n.º 19
0
        public void ShowBoxOnce(Vector2 min, Vector2 max)
        {
            if ((_boxCount + 6) > MaxBoxes)
            {
                return;
            }
            var tl = new Vector3(min, 0);
            var tr = new Vector3(max.X, min.Y, 0);
            var br = new Vector3(max, 0);
            var bl = new Vector3(min.X, max.Y, 0);

            var color = new Color(32, 32, 32, 127);

            var i = _boxCount * 6;

            _vertices[i + 0] = new VertexPositionColorTexture(tl, color, new Vector2(0, 0));
            _vertices[i + 1] = new VertexPositionColorTexture(tr, color, new Vector2(1, 0));
            _vertices[i + 2] = new VertexPositionColorTexture(br, color, new Vector2(1, 1));
            _vertices[i + 3] = new VertexPositionColorTexture(tl, color, new Vector2(0, 0));
            _vertices[i + 4] = new VertexPositionColorTexture(br, color, new Vector2(1, 1));
            _vertices[i + 5] = new VertexPositionColorTexture(bl, color, new Vector2(0, 1));

            _boxCount += 6;
        }
Ejemplo n.º 20
0
        public void AddBackgroundTile(int i, int j, short type)
        {
            // Register into the grid here

            int tile_size = PhysicsSystem.TileSize;
            // var rect = new Rectangle(i * tile_size - tile_size / 2, j * tile_size - tile_size / 2, tile_size, tile_size);
            var rect  = new Rectangle(i * tile_size, j * tile_size, tile_size, tile_size);
            var color = Color.White;

            var(offset, size) = GetTileTexCoords(type);

            _backbuffer[tile_vertex_count++] = new VertexPositionColorTexture(new Vector3(rect.Left, -rect.Bottom, 0), color, offset);
            _backbuffer[tile_vertex_count++] = new VertexPositionColorTexture(new Vector3(rect.Right, -rect.Bottom, 0), color, offset + new Vector2(size.X, 0));
            _backbuffer[tile_vertex_count++] = new VertexPositionColorTexture(new Vector3(rect.Left, -rect.Top, 0), color, offset + new Vector2(0, size.Y));
            _backbuffer[tile_vertex_count++] = new VertexPositionColorTexture(new Vector3(rect.Right, -rect.Top, 0), color, offset + size);

            _back_index_buffer[tile_index_count++] = tile_vertex_count - 4;
            _back_index_buffer[tile_index_count++] = tile_vertex_count - 3;
            _back_index_buffer[tile_index_count++] = tile_vertex_count - 2;

            _back_index_buffer[tile_index_count++] = tile_vertex_count - 2;
            _back_index_buffer[tile_index_count++] = tile_vertex_count - 3;
            _back_index_buffer[tile_index_count++] = tile_vertex_count - 1;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Erstellt eine Representation eines Projektils.
        /// </summary>
        /// <param name="projectile">Projektil(Typ)</param>
        /// <param name="texture">Projektiltextur</param>
        /// <param name="graphics">DeviceManager</param>
        /// <param name="effect">BasicEffect</param>
        /// <param name="color">Projektilfärbung</param>
        public ProjectileRepresentation(Projectile projectile, Texture2D texture, GraphicsDeviceManager graphics, BasicEffect effect, Vector3 color)
        {
            GameItem             = projectile;
            this.texture         = texture;
            this.colorProjectile = color;
            this.position        = PlaneProjector.Convert2DTo3D(GameItem.Position);
            this.graphics        = graphics;
            this.effect          = effect;
            this.World           = Matrix.CreateWorld(this.position, Vector3.Forward, Vector3.Up);

            //Eckpunkte des Rechtecks
            this.vertices = new VertexPositionColorTexture[4];

            //6 Punkte für zwei polygone, um ein Rechteck zu zeichnen
            this.indices = new int[6];

            //1. Polygon: Punkte 0,1,2 im Urzeigersinn
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            //2. Polygon: Punkte 1,3,2 im Urzeigersinn
            indices[3] = 1;
            indices[4] = 3;
            indices[5] = 2;

            //3-dimensionales Rechteck aufbauen für die 3 dimensionale Darstellung des Projektils (mit Hitsphere)
            Vector3 leftBot  = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, -texture.Height / 2.0f));
            Vector3 leftTop  = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, texture.Height / 2.0f));
            Vector3 rightBot = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, -texture.Height / 2.0f));
            Vector3 rightTop = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, texture.Height / 2.0f));

            vertices[0] = new VertexPositionColorTexture(leftBot, Color.Red, new Vector2(0, 0));
            vertices[1] = new VertexPositionColorTexture(leftTop, Color.Red, new Vector2(0, 1));
            vertices[2] = new VertexPositionColorTexture(rightBot, Color.Red, new Vector2(1, 0));
            vertices[3] = new VertexPositionColorTexture(rightTop, Color.Red, new Vector2(1, 1));
        }
Ejemplo n.º 22
0
        public override void Initialize()
        {
            base.Initialize();

            effect = new BasicEffect(GameContainer.Graphics.GraphicsDevice, null);

            score0 = GameContainer.Content.Load <Texture2D>("Content\\Textures\\Score_0");
            score1 = GameContainer.Content.Load <Texture2D>("Content\\Textures\\Score_1");
            score2 = GameContainer.Content.Load <Texture2D>("Content\\Textures\\Score_2");
            //score3 = GameContainer.Content.Load<Texture2D>("Content\\Textures\\Score_3");

            vertexDecl = new VertexDeclaration(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.VertexElements);

            float w = width / 2;
            float d = depth / 2;

            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4]
            {
                new VertexPositionColorTexture(new Vector3(-w, 0, d), Color.Black, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(w, 0, d), Color.Black, new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(w, 0, -d), Color.Black, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-w, 0, -d), Color.Black, new Vector2(0, 0))
            };

            short[] indices = new short[6]
            {
                0, 1, 2,
                0, 3, 2
            };

            vb = new VertexBuffer(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.SizeInBytes * vertices.Length, ResourceUsage.None);
            vb.SetData(vertices);

            ib = new IndexBuffer(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.SizeInBytes * indices.Length, ResourceUsage.None, IndexElementSize.SixteenBits);
            ib.SetData(indices);
        }
Ejemplo n.º 23
0
        public void ShowBoxOnce(Vector2 min, Vector2 max)
        {
            if (boxCount >= MaxBoxes)
            {
                return;
            }
            Vector3 tl = new Vector3(min, 0);
            Vector3 tr = new Vector3(max.X, min.Y, 0);
            Vector3 br = new Vector3(max, 0);
            Vector3 bl = new Vector3(min.X, max.Y, 0);

            Color color = new Color(32, 32, 32, 127);

            int i = boxCount * 6;

            Vertices[i + 0] = new VertexPositionColorTexture(tl, color, new Vector2(0, 0));
            Vertices[i + 1] = new VertexPositionColorTexture(tr, color, new Vector2(1, 0));
            Vertices[i + 2] = new VertexPositionColorTexture(br, color, new Vector2(1, 1));
            Vertices[i + 3] = new VertexPositionColorTexture(tl, color, new Vector2(0, 0));
            Vertices[i + 4] = new VertexPositionColorTexture(br, color, new Vector2(1, 1));
            Vertices[i + 5] = new VertexPositionColorTexture(bl, color, new Vector2(0, 1));

            boxCount += 6;
        }
Ejemplo n.º 24
0
        public override void Initialize()
        {
            base.Initialize();

            effect = new BasicEffect(GameContainer.Graphics.GraphicsDevice, null);

            vertexDecl = new VertexDeclaration(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.VertexElements);

            float w = width / 2;
            float h = height / 2;

            Vector2 textureUpperLeft  = new Vector2(0.0f, 0.0f);
            Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
            Vector2 textureLowerLeft  = new Vector2(0.0f, 1.0f);
            Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);

            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4]
            {
                new VertexPositionColorTexture(new Vector3(-w, -h, 0), Color.Black, textureLowerLeft),
                new VertexPositionColorTexture(new Vector3(-w, h, 0), Color.Black, textureUpperLeft),
                new VertexPositionColorTexture(new Vector3(w, -h, 0), Color.Black, textureLowerRight),
                new VertexPositionColorTexture(new Vector3(w, h, 0), Color.Black, textureUpperRight)
            };

            short[] indices = new short[6]
            {
                0, 1, 2,
                2, 1, 3
            };

            vb = new VertexBuffer(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.SizeInBytes * vertices.Length, ResourceUsage.None);
            vb.SetData(vertices);

            ib = new IndexBuffer(GameContainer.Graphics.GraphicsDevice, VertexPositionColorTexture.SizeInBytes * indices.Length, ResourceUsage.None, IndexElementSize.SixteenBits);
            ib.SetData(indices);
        }
Ejemplo n.º 25
0
        public void ShowGradientBoxOnce(Vector2 min, Vector2 max, Color top, Color bottom)
        {
            if (boxCount >= MaxBoxes)
            {
                return;
            }
            Vector3 tl = new Vector3(min, 0);
            Vector3 tr = new Vector3(max.X, min.Y, 0);
            Vector3 br = new Vector3(max, 0);
            Vector3 bl = new Vector3(min.X, max.Y, 0);

            int i = boxCount * 6;

            Vector2 tiling = (max - min) * 1 / 128f;

            Vertices[i + 0] = new VertexPositionColorTexture(tl, top, new Vector2(0, 0));
            Vertices[i + 1] = new VertexPositionColorTexture(tr, top, new Vector2(tiling.X, 0));
            Vertices[i + 2] = new VertexPositionColorTexture(br, bottom, new Vector2(tiling.X, tiling.Y));
            Vertices[i + 3] = new VertexPositionColorTexture(tl, top, new Vector2(0, 0));
            Vertices[i + 4] = new VertexPositionColorTexture(br, bottom, new Vector2(tiling.X, tiling.Y));
            Vertices[i + 5] = new VertexPositionColorTexture(bl, bottom, new Vector2(0, tiling.Y));

            boxCount += 6;
        }
Ejemplo n.º 26
0
        static VertexPositionColorTexture[] CreateVertexArray(short[,] baseTileTypes)
        {
            var vertices = new VertexPositionColorTexture[TileChunk.Size * TileChunk.Size * 4];

            int vi = 0;

            for (int y = 0; y < TileChunk.Size; y++)
            {
                for (int x = 0; x < TileChunk.Size; x++)
                {
                    int blockIndex = baseTileTypes[x, y];
                    for (int corner = 0; corner < 4; corner++, vi++)
                    {
                        int cx = corner % 2;
                        int cy = corner / 2;
                        vertices[vi].Position          = new Vector3((x + cx) * Tile.Size, (y + cy) * Tile.Size, 0);
                        vertices[vi].TextureCoordinate = GetUVCoordsFromIndex(blockIndex, corner);
                        vertices[vi].Color             = Color.White;
                    }
                }
            }

            return(vertices);
        }
Ejemplo n.º 27
0
        public void triangulate()
        {
            List <PolygonPoint> points  = new List <PolygonPoint>();
            PointListNode       current = _headPoint;

            _polygonPosition = current.position;
            while (current != null)
            {
                _polygonPosition = Vector2.Min(current.position, _polygonPosition);
                points.Add(new PolygonPoint(current.position.X, current.position.Y));
                current = current.next;
            }
            Polygon polygon = new Polygon(points);

            P2T.Triangulate(polygon);
            _primitiveCount = polygon.Triangles.Count;

            int index = 0;

            foreach (DelaunayTriangle triangle in polygon.Triangles)
            {
                for (int i = 0; i < 3; i++)
                {
                    _vertices[index++] = new VertexPositionColorTexture(
                        new Vector3(triangle.Points[i].Xf, triangle.Points[i].Yf, 0),
                        Color.White,
                        Vector2.Zero);
                }
            }

            if (_polygonTexture != null)
            {
                _polygonTexture.Dispose();
            }
            _polygonTexture = _level.controller.view.renderPolygon(_vertices, _primitiveCount);
        }
Ejemplo n.º 28
0
        public void ShowGradientBoxOnce(Vector2 min, Vector2 max, Color top, Color bottom)
        {
            if ((_boxCount + 6) > MaxBoxes)
            {
                return;
            }
            var tl = new Vector3(min, 0);
            var tr = new Vector3(max.X, min.Y, 0);
            var br = new Vector3(max, 0);
            var bl = new Vector3(min.X, max.Y, 0);

            var i = _boxCount * 6;

            var tiling = (max - min) * 1 / 128f;

            _vertices[i + 0] = new VertexPositionColorTexture(tl, top, new Vector2(0, 0));
            _vertices[i + 1] = new VertexPositionColorTexture(tr, top, new Vector2(tiling.X, 0));
            _vertices[i + 2] = new VertexPositionColorTexture(br, bottom, new Vector2(tiling.X, tiling.Y));
            _vertices[i + 3] = new VertexPositionColorTexture(tl, top, new Vector2(0, 0));
            _vertices[i + 4] = new VertexPositionColorTexture(br, bottom, new Vector2(tiling.X, tiling.Y));
            _vertices[i + 5] = new VertexPositionColorTexture(bl, bottom, new Vector2(0, tiling.Y));

            _boxCount += 6;
        }
Ejemplo n.º 29
0
        public Quad(Texture2D texture, Color color)
        {
            Vector3 position = new Vector3(-1f, 0f, -1f);

            verts = new VertexPositionColorTexture[4];

            verts[0] = new VertexPositionColorTexture(position, color, new Vector2(0, 1));

            position = new Vector3(-1f, 0f, 1f);
            verts[1] = new VertexPositionColorTexture(position, color, Vector2.Zero);

            position = new Vector3(1f, 0f, 1f);
            verts[2] = new VertexPositionColorTexture(position, color, new Vector2(1, 0));

            position = new Vector3(1f, 0f, -1f);
            verts[3] = new VertexPositionColorTexture(position, color, new Vector2(1, 1));

            indices = new short[6];

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 3;
            indices[3] = 1;
            indices[4] = 2;
            indices[5] = 3;

            vertexBuffer = new VertexBuffer(Global.graphics.GraphicsDevice, typeof(VertexPositionColorTexture), verts.Length, BufferUsage.None);
            vertexBuffer.SetData(verts);
            effect = new BasicEffect(Global.graphics.GraphicsDevice);
            effect.TextureEnabled     = true;
            effect.VertexColorEnabled = false;
            effect.Texture            = texture;

            wireFrame     = false;
            mirrorTexture = false;
        }
Ejemplo n.º 30
0
        private void Initialize(GraphicsDevice graphicsDevice)
        {
            var s  = new SpriteBatch(graphicsDevice);
            var vp = graphicsDevice.Viewport;

            _cameraMatrix =
                Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, 0, 1);

            _texture = _drawable.RenderToTexture(s);

            // TODO these are all structs, so efficiency can be improved by working with pointers!
            for (int i = 0; i < _originalVertices.Length; i += 2)
            {
                var v = new VertexPositionColorTexture(
                    new Vector3(_originalVertices[i], _originalVertices[i + 1], 0f),
                    Color.White,
                    new Vector2(_uvs[i], _uvs[i + 1]));
                _vertices[i / 2] = v;
            }

            _indexBuffer = new IndexBuffer(graphicsDevice, typeof(short),
                                           _indices.Length, BufferUsage.WriteOnly);

            _vertexBuffer = new DynamicVertexBuffer(graphicsDevice,
                                                    typeof(VertexPositionColorTexture),
                                                    _vertices.Length, BufferUsage.WriteOnly);

            _effect = new BasicEffect(s.GraphicsDevice)
            {
                World              = Matrix.Identity,
                View               = Matrix.Identity,
                Texture            = _texture,
                VertexColorEnabled = true,
                TextureEnabled     = true,
            };
        }
Ejemplo n.º 31
0
        public Background()
        {
            //Initialize the Grid
            int xCoord = -127;

            for (int i = 0; i < 255; i++)
            {
                Lines[i * 3] = new VertexPositionColor(
                    new Vector3(xCoord, 0, -127)
                    , new Color(Color.MidnightBlue, 0.0f));
                Lines[i * 3 + 1] = new VertexPositionColor(
                    new Vector3(xCoord, 0, 0)
                    , new Color(Color.DeepSkyBlue
                                , 1.0f - Math.Abs(xCoord * 2.0f) / 255.0f));
                Lines[i * 3 + 2] = new VertexPositionColor(
                    new Vector3(xCoord, 0, 127)
                    , new Color(Color.DodgerBlue, 0.0f));
                xCoord++;
            }
            for (int i = 255; i < 510; i++)
            {
                Lines[i * 3] = new VertexPositionColor(
                    new Vector3(-127, 0, xCoord)
                    , new Color(Color.DarkBlue, 0.0f));
                Lines[i * 3 + 1] = new VertexPositionColor(
                    new Vector3(0, 0, xCoord)
                    , new Color(Color.Blue
                                , 1.0f - Math.Abs(xCoord * 2.0f) / 255f));
                Lines[i * 3 + 2] = new VertexPositionColor(
                    new Vector3(127, 0, xCoord)
                    , new Color(Color.LightBlue, 0.0f));
                xCoord--;
            }
            GridDeclaration       = new VertexDeclaration(MyGame.graphics.GraphicsDevice, VertexPositionColor.VertexElements);
            BackgroundDeclaration = new VertexDeclaration(MyGame.graphics.GraphicsDevice, VertexPositionColorTexture.VertexElements);
            StarMap = MyGame.content.Load <Texture2D>("Textures\\Stars");

            //Initialize the Stars
            RefreshBackground(10000);

            //Initialize the Skybox
            int width  = 32;
            int height = 32;

            SkyTexture1           = Manager.GeneratePerlinNoise(MyGame.random.Next(width / 2, (width + height) / 2));
            SkyTexture1           = Manager.SphericalWrap(SkyTexture1);
            SkyTexture2           = Manager.GeneratePerlinNoise(MyGame.random.Next(width / 2, (width + height) / 2));
            SkyTexture2           = Manager.SphericalWrap(SkyTexture2);
            TransparencyThreshold = 0.3f + 0.1f * (float)MyGame.random.NextDouble();

            SkyBox = new VertexPositionColorTexture[width * height];
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    SkyBox[x + y * width] = new VertexPositionColorTexture(
                        new Vector3((float)Math.Cos((double)x / (width - 1.0) * 2.0 * Math.PI)
                                    * (float)Math.Sin((double)y / (height - 1.0) * Math.PI)
                                    , -(float)Math.Cos((double)y / (height - 1.0) * Math.PI)
                                    , (float)(Math.Sin((double)x / (width - 1.0) * 2.0 * Math.PI))
                                    * (float)Math.Sin((double)y / (height - 1.0) * Math.PI))
                        , Color.White
                        , new Vector2((float)x / (width - 1.0f), (float)y / (height - 1.0f)));
                }
            }
            int counter = 0;

            SkyBoxIndexBuffer = new int[6 * (width - 1) * (height - 1)];
            for (int x = 0; x < width - 1; x++)
            {
                for (int y = 0; y < height - 1; y++)
                {
                    SkyBoxIndexBuffer[counter++] = x + y * width;
                    SkyBoxIndexBuffer[counter++] = x + 1 + (y + 1) * width;
                    SkyBoxIndexBuffer[counter++] = x + 1 + y * width;
                    SkyBoxIndexBuffer[counter++] = x + y * width;
                    SkyBoxIndexBuffer[counter++] = x + (y + 1) * width;
                    SkyBoxIndexBuffer[counter++] = x + 1 + (y + 1) * width;
                }
            }

            //Set the colors
            ColorScheme1 = Manager.GenerateStaticNoise(5, 5);
            ColorScheme2 = Manager.GenerateStaticNoise(5, 5);
        }
Ejemplo n.º 32
0
 public void GenerateMesh(Vector2 trailTipPosition, Vector2 trailTipNormal, int startFromIndex, out VertexPositionColorTexture[] vertices, out short[] indices, TrailWidthFunction trailWidthFunction, TrailColorFunction trailColorFunction)
 {
     vertices = new VertexPositionColorTexture[0];
     indices  = new short[0];
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Initialize the starfield mesh
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Indices
            var indices = new ushort[this.NStars * 6];
            for (int i = 0; i < this.NStars; i++)
            {
                indices[i * 6] = (ushort)(i * 4);
                indices[(i * 6) + 1] = (ushort)((i * 4) + 1);
                indices[(i * 6) + 2] = (ushort)((i * 4) + 2);
                indices[(i * 6) + 3] = (ushort)((i * 4) + 3);
                indices[(i * 6) + 4] = (ushort)(i * 4);
                indices[(i * 6) + 5] = (ushort)((i * 4) + 2);
            }

            var indexBuffer = new IndexBuffer(indices);

            // Vertices
            var vertices = new VertexPositionColorTexture[this.NStars * 4];

            System.Random rand = new System.Random();

            for (int i = 0; i < this.NStars; i++)
            {
                float scale = (float)(rand.NextDouble() * scaleInterval) + minScale;
                float depth = (float)(rand.NextDouble() * depthInterval) + minDepth;
                // scale
                Matrix scaleTransform = Matrix.CreateScale(new Vector3(
                    scale,
                    scale,
                    depth
                    ));

                // rotation
                Matrix rotationTransform = Matrix.CreateFromYawPitchRoll(
                    (float)(rand.NextDouble() * MathHelper.TwoPi),
                    (float)(Math.Asin((rand.NextDouble() * 2) - 1)),
                    0);
                Matrix transform = scaleTransform * rotationTransform;
                int quadSize = referenceData.Length;
                Color color = this.ColorFromLerp((float)rand.NextDouble());
                float alpha = (float)(rand.NextDouble() * alphaInterval + minAlpha);

                color = Color.White * whiteProportion + color * (1 - whiteProportion);
                color = color * alpha;

                for (int j = 0; j < quadSize; j++)
                {
                    Vector3.Transform(ref referenceData[j].Position, ref transform, out vertices[i * quadSize + j].Position);
                    vertices[i * quadSize + j].TexCoord = referenceData[j].TexCoord;
                    vertices[i * quadSize + j].Color = color;
                }
            }

            var vertexBuffer = new VertexBuffer(VertexPositionColorTexture.VertexFormat);
            vertexBuffer.SetData(vertices);

            this.mesh = new Mesh(0, vertices.Length, 0, this.NStars * 2, vertexBuffer, indexBuffer, PrimitiveType.TriangleList);
        }