Exemple #1
0
 /// <summary>
 /// sets the triangle indices for rendering
 /// </summary>
 /// <returns>The triangles.</returns>
 /// <param name="triangles">Triangles.</param>
 public Mesh setTriangles(int[] triangles)
 {
     Insist.isTrue(triangles.Length % 3 == 0, "triangles must be a multiple of 3");
     _primitiveCount = triangles.Length / 3;
     _triangles      = triangles;
     return(this);
 }
        public Batcher(GraphicsDevice graphicsDevice)
        {
            Insist.isTrue(graphicsDevice != null);

            this.graphicsDevice = graphicsDevice;

            _vertexInfo   = new VertexPositionColorTexture4[MAX_SPRITES];
            _textureInfo  = new Texture2D[MAX_SPRITES];
            _vertexBuffer = new DynamicVertexBuffer(graphicsDevice, typeof(VertexPositionColorTexture), MAX_VERTICES, BufferUsage.WriteOnly);
            _indexBuffer  = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, MAX_INDICES, BufferUsage.WriteOnly);
            _indexBuffer.SetData(_indexData);

            _spriteEffect     = new SpriteEffect();
            _spriteEffectPass = _spriteEffect.CurrentTechnique.Passes[0];

            _projectionMatrix = new Matrix(
                0f,                 //(float)( 2.0 / (double)viewport.Width ) is the actual value we will use
                0.0f,
                0.0f,
                0.0f,
                0.0f,
                0f,                 //(float)( -2.0 / (double)viewport.Height ) is the actual value we will use
                0.0f,
                0.0f,
                0.0f,
                0.0f,
                1.0f,
                0.0f,
                -1.0f,
                1.0f,
                0.0f,
                1.0f
                );
        }
Exemple #3
0
        /// <summary>
        /// removes a PostProcessor. Note that unload is not called when removing so if you no longer need the PostProcessor be sure to call
        /// unload to free resources.
        /// </summary>
        /// <param name="postProcessor">Step.</param>
        public void removePostProcessor(PostProcessor postProcessor)
        {
            Insist.isTrue(_postProcessors.contains(postProcessor));

            _postProcessors.remove(postProcessor);
            postProcessor.unload();
        }
        public void addVertex(Vector2 vertex, Color color, PrimitiveType primitiveType)
        {
            Insist.isTrue(_hasBegun, "Invalid state. Begin must be called before AddVertex can be called.");
            Insist.isFalse(primitiveType == PrimitiveType.LineStrip || primitiveType == PrimitiveType.TriangleStrip, "The specified primitiveType is not supported by PrimitiveBatch");

            if (primitiveType == PrimitiveType.TriangleList)
            {
                if (_triangleVertsCount >= _triangleVertices.Length)
                {
                    flushTriangles();
                }

                _triangleVertices[_triangleVertsCount].Position = new Vector3(vertex, 0);
                _triangleVertices[_triangleVertsCount].Color    = color;
                _triangleVertsCount++;
            }

            if (primitiveType == PrimitiveType.LineList)
            {
                if (_lineVertsCount >= _lineVertices.Length)
                {
                    flushLines();
                }

                _lineVertices[_lineVertsCount].Position = new Vector3(vertex, 0);
                _lineVertices[_lineVertsCount].Color    = color;
                _lineVertsCount++;
            }
        }
        /// <summary>
        /// removes the item at the given index from the list but does NOT maintain list order
        /// </summary>
        /// <param name="index">Index.</param>
        public void removeAtWithSwap(int index)
        {
            Insist.isTrue(index < length, "Index out of range!");

            buffer[index]      = buffer[length - 1];
            buffer[length - 1] = default(T);
            --length;
        }
        /// <summary>
        /// removes the item at the given index from the list
        /// </summary>
        public void removeAt(int index)
        {
            Insist.isTrue(index < length, "Index out of range!");

            length--;
            if (index < length)
            {
                Array.Copy(buffer, index + 1, buffer, index, length - index);
            }
            buffer[length] = default(T);
        }
        public void end()
        {
            Insist.isTrue(_beginCalled, "End was called, but Begin has not yet been called. You must call Begin successfully before you can call End.");
            _beginCalled = false;

            if (!_disableBatching)
            {
                flushBatch();
            }

            _customEffect = null;
        }
Exemple #8
0
        /// <summary>
        /// maximum non-scaled value (0 - float.Max) that the camera zoom can be. Defaults to 3
        /// </summary>
        /// <param name="maxZoom">Max zoom.</param>
        public Camera setMaximumZoom(float maxZoom)
        {
            Insist.isTrue(maxZoom > 0, "MaximumZoom must be greater than zero");

            if (_zoom > maxZoom)
            {
                _zoom = maxZoom;
            }

            _maximumZoom = maxZoom;
            return(this);
        }
Exemple #9
0
        /// <summary>
        /// minimum non-scaled value (0 - float.Max) that the camera zoom can be. Defaults to 0.3
        /// </summary>
        /// <param name="value">Value.</param>
        public Camera setMinimumZoom(float minZoom)
        {
            Insist.isTrue(minZoom > 0, "minimumZoom must be greater than zero");

            if (_zoom < minZoom)
            {
                _zoom = minimumZoom;
            }

            _minimumZoom = minZoom;
            return(this);
        }
Exemple #10
0
        /// <summary>
        /// removes the Renderer from the scene
        /// </summary>
        /// <param name="renderer">Renderer.</param>
        public void removeRenderer(Renderer renderer)
        {
            Insist.isTrue(_renderers.contains(renderer) || _afterPostProcessorRenderers.contains(renderer));

            if (renderer.wantsToRenderAfterPostProcessors)
            {
                _afterPostProcessorRenderers.remove(renderer);
            }
            else
            {
                _renderers.remove(renderer);
            }
            renderer.unload();
        }
        public override void onAddedToEntity()
        {
            if (_colliderRequiresAutoSizing)
            {
                // we only deal with boxes and circles here
                Insist.isTrue(this is BoxCollider || this is CircleCollider, "Only box and circle colliders can be created automatically");

                var renderable = entity.getComponent <RenderableComponent>();
                Debug.warnIf(renderable == null, "Collider has no shape and no RenderableComponent. Can't figure out how to size it.");
                if (renderable != null)
                {
                    var renderableBounds = renderable.bounds;

                    // we need the size * inverse scale here because when we autosize the Collider it needs to be without a scaled Renderable
                    var width  = renderableBounds.width / entity.transform.scale.X;
                    var height = renderableBounds.height / entity.transform.scale.Y;

                    // circle colliders need special care with the origin
                    if (this is CircleCollider)
                    {
                        var circleCollider = this as CircleCollider;
                        circleCollider.radius = Math.Max(width, height) * 0.5f;

                        // fetch the Renderable's center, transfer it to local coordinates and use that as the localOffset of our collider
                        localOffset = renderableBounds.center - entity.transform.position;
                    }
                    else
                    {
                        var boxCollider = this as BoxCollider;
                        boxCollider.width  = width;
                        boxCollider.height = height;

                        // fetch the Renderable's center, transfer it to local coordinates and use that as the localOffset of our collider
                        localOffset = renderableBounds.center - entity.transform.position;
                    }
                }
            }
            _isParentEntityAddedToScene = true;
            registerColliderWithPhysicsSystem();
        }
        /// <summary>
        /// direct access to setting vert positions, UVs and colors. The order of elements is top-left, top-right, bottom-left, bottom-right
        /// </summary>
        /// <returns>The raw.</returns>
        /// <param name="texture">Texture.</param>
        /// <param name="verts">Verts.</param>
        /// <param name="textureCoords">Texture coords.</param>
        /// <param name="colors">Colors.</param>
        public void drawRaw(Texture2D texture, Vector3[] verts, Vector2[] textureCoords, Color[] colors)
        {
            Insist.isTrue(verts.Length == 4, "there must be only 4 verts");
            Insist.isTrue(textureCoords.Length == 4, "there must be only 4 texture coordinates");
            Insist.isTrue(colors.Length == 4, "there must be only 4 colors");

            // we're out of space, flush
            if (_numSprites >= MAX_SPRITES)
            {
                flushBatch();
            }

            _vertexInfo[_numSprites].position0 = verts[0];
            _vertexInfo[_numSprites].position1 = verts[1];
            _vertexInfo[_numSprites].position2 = verts[2];
            _vertexInfo[_numSprites].position3 = verts[3];

            _vertexInfo[_numSprites].textureCoordinate0 = textureCoords[0];
            _vertexInfo[_numSprites].textureCoordinate1 = textureCoords[1];
            _vertexInfo[_numSprites].textureCoordinate2 = textureCoords[2];
            _vertexInfo[_numSprites].textureCoordinate3 = textureCoords[3];

            _vertexInfo[_numSprites].color0 = colors[0];
            _vertexInfo[_numSprites].color1 = colors[1];
            _vertexInfo[_numSprites].color2 = colors[2];
            _vertexInfo[_numSprites].color3 = colors[3];

            if (_disableBatching)
            {
                _vertexBuffer.SetData(0, _vertexInfo, 0, 1, VertexPositionColorTexture4.realStride, SetDataOptions.None);
                drawPrimitives(texture, 0, 1);
            }
            else
            {
                _textureInfo[_numSprites] = texture;
                _numSprites += 1;
            }
        }
Exemple #13
0
 /// <summary>
 /// removes a SceneComponent from the SceneComponents list
 /// </summary>
 public void removeSceneComponent(SceneComponent component)
 {
     Insist.isTrue(_sceneComponents.contains(component), "SceneComponent {0} is not in the SceneComponents list!", component);
     _sceneComponents.remove(component);
     component.onRemovedFromScene();
 }
Exemple #14
0
 /// <summary>
 /// Change the rendering primitive type.
 /// If it is PrimitiveType.TriangleStrip then you don't need to setTriangles.
 /// </summary>
 /// <param name="primitiveType">The ordering of the verticies.</param>
 /// <returns>The mesh.</returns>
 public Mesh setPrimitiveType(PrimitiveType primitiveType)
 {
     Insist.isTrue(primitiveType == PrimitiveType.TriangleList || primitiveType == PrimitiveType.TriangleStrip, "Only triangles are supported.");
     _primitiveType = primitiveType;
     return(this);
 }
Exemple #15
0
 /// <summary>
 /// sets the number of degrees between each subdivision for use with EndCapType.Smooth
 /// </summary>
 /// <returns>The per subdivision.</returns>
 /// <param name="degreesPerSubdivision">Degrees per subdivision.</param>
 public LineRenderer setDegreesPerSubdivision(float degreesPerSubdivision)
 {
     Insist.isTrue(degreesPerSubdivision > 0, "degreesPerSubdivision must be greater than 0");
     this.degreesPerSubdivision = degreesPerSubdivision;
     return(this);
 }