public Batcher(GraphicsDevice graphicsDevice) { Assert.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 ); }
public void addVertex(Vector2 vertex, Color color, PrimitiveType primitiveType) { Assert.isTrue(_hasBegun, "Invalid state. Begin must be called before AddVertex can be called."); Assert.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> /// sets the triangle indices for rendering /// </summary> /// <returns>The triangles.</returns> /// <param name="triangles">Triangles.</param> public Mesh setTriangles(int[] triangles) { Assert.isTrue(triangles.Length % 3 == 0, "triangles must be a multiple of 3"); _primitiveCount = triangles.Length / 3; _triangles = triangles; return(this); }
/// <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) { Assert.isTrue( primitiveType == PrimitiveType.TriangleList || primitiveType == PrimitiveType.TriangleStrip, "Only triangles are supported."); _primitiveType = primitiveType; return(this); }
/// <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) { Assert.isTrue(index < length, "Index out of range!"); buffer[index] = buffer[length - 1]; buffer[length - 1] = default(T); --length; }
/// <summary> /// removes a SceneComponent from the SceneComponents list /// </summary> public void removeSceneComponent(SceneComponent component) { Assert.isTrue( _sceneComponents.contains(component), "SceneComponent {0} is not in the SceneComponents list!", component); _sceneComponents.remove(component); component.onRemovedFromScene(); }
/// <summary> /// removes the item at the given index from the list /// </summary> public void removeAt(int index) { Assert.isTrue(index < length, "Index out of range!"); length--; if (index < length) { Array.Copy(buffer, index + 1, buffer, index, length - index); } buffer[length] = default(T); }
/// <summary> /// maximum non-scaled value (0 - float.Max) that the camera zoom can be. Defaults to 3 /// </summary> /// <returns>The maximum zoom.</returns> /// <param name="maxZoom">Max zoom.</param> public Camera setMaximumZoom(float maxZoom) { Assert.isTrue(maxZoom > 0, "MaximumZoom must be greater than zero"); if (_zoom > maxZoom) { _zoom = maxZoom; } _maximumZoom = maxZoom; return(this); }
public StateKitLite() { Assert.isTrue(typeof(TEnum).IsEnum, "[StateKitLite] TEnum generic constraint failed! You must use an enum when declaring your subclass!"); // cache all of our state methods var enumValues = (TEnum[])Enum.GetValues(typeof(TEnum)); foreach (var e in enumValues) { configureAndCacheState(e); } }
/// <summary> /// minimum non-scaled value (0 - float.Max) that the camera zoom can be. Defaults to 0.3 /// </summary> /// <returns>The minimum zoom.</returns> /// <param name="value">Value.</param> public Camera setMinimumZoom(float minZoom) { Assert.isTrue(minZoom > 0, "minimumZoom must be greater than zero"); if (_zoom < minZoom) { _zoom = minimumZoom; } _minimumZoom = minZoom; return(this); }
public void end() { Assert.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; }
public override void render() { var text = getValue <string>(); Assert.isTrue(text.Length < 1024); var len = System.Text.Encoding.UTF8.GetBytes(text, 0, text.Length, _textInputBuffer, 0); ImGui.InputText(_name, _textInputBuffer, (uint)_textInputBuffer.Length, InputTextFlags.Default, null); text = System.Text.Encoding.UTF8.GetString(_textInputBuffer, 0, len); setValue(text); }
public override void onAddedToEntity() { if (_colliderRequiresAutoSizing) { // we only deal with boxes and circles here Assert.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) { Assert.isTrue(verts.Length == 4, "there must be only 4 verts"); Assert.isTrue(textureCoords.Length == 4, "there must be only 4 texture coordinates"); Assert.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; } }
/// <summary> /// Called when the parent entity is added to a scene /// </summary> public virtual void onEntityAddedToScene() { if (shape == null) { // we only deal with boxes and circles here Assert.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; var width = renderableBounds.width; var height = renderableBounds.height; // circle colliders need special care with the origin if (this is CircleCollider) { var circle = this as CircleCollider; circle.shape = new Circle(width * 0.5f); circle.radius = width * 0.5f; // fetch the Renderable's center, transfer it to local coordinates and use that as the origin of our collider var localCenter = renderableBounds.center - entity.transform.position; origin = localCenter; } else { var box = this as BoxCollider; box.shape = new Box(width, height); box.width = width; box.height = height; originNormalized = renderable.originNormalized; } shape.position = entity.transform.position; } } _isParentEntityAddedToScene = true; registerColliderWithPhysicsSystem(); }
/// <summary> /// removes the Collider and unregisters it from the Pysics system /// </summary> /// <param name="collider">Collider.</param> public void remove(Collider collider) { Assert.isTrue(_colliders.Contains(collider), "Collider {0} is not in the ColliderList", collider); removeAt(_colliders.IndexOf(collider)); }
/// <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) { Assert.isTrue(degreesPerSubdivision > 0, "degreesPerSubdivision must be greater than 0"); this.degreesPerSubdivision = degreesPerSubdivision; return(this); }