Наследование: Component
Пример #1
0
        /// <summary>
        /// Calculates a screen space scissor rectangle using the given Camera. If the Camera is null than the scissor will
        /// be calculated only with the batchTransform
        /// </summary>
        /// <returns>The scissors.</returns>
        /// <param name="camera">Camera.</param>
        /// <param name="batchTransform">Batch transform.</param>
        /// <param name="scissor">Area.</param>
        public static Rectangle calculateScissors( Camera camera, Matrix batchTransform, Rectangle scissor )
        {
            // convert the top-left point to screen space
            var tmp = new Vector2( scissor.X, scissor.Y );
            tmp = Vector2.Transform( tmp, batchTransform );

            if( camera != null )
                tmp = camera.worldToScreenPoint( tmp );

            var newScissor = new Rectangle();
            newScissor.X = (int)tmp.X;
            newScissor.Y = (int)tmp.Y;

            // convert the bottom-right point to screen space
            tmp.X = scissor.X + scissor.Width;
            tmp.Y = scissor.Y + scissor.Height;
            tmp = Vector2.Transform( tmp, batchTransform );

            if( camera != null )
                tmp = camera.worldToScreenPoint( tmp );
            newScissor.Width = (int)tmp.X - newScissor.X;
            newScissor.Height = (int)tmp.Y - newScissor.Y;

            return newScissor;
        }
Пример #2
0
        public override void render( Graphics graphics, Camera camera )
        {
            // we need to send the top of of the plane to the Effect
            var screenSpaceTop = entity.scene.camera.worldToScreenPoint( entity.transform.position );
            ( material as WaterReflectionMaterial ).effect.screenSpaceVerticalOffset = screenSpaceTop.Y / entity.scene.sceneRenderTargetSize.Y;

            graphics.batcher.draw( _texture, bounds, new Rectangle( 0, 0, 1, 1 ), color );
        }
Пример #3
0
 protected override void debugRender( Scene scene, Camera cam )
 {
     for( var i = 0; i < scene.renderableComponents.Count; i++ )
     {
         var renderable = scene.renderableComponents[i];
         if( !excludedRenderLayers.contains( renderable.renderLayer ) && renderable.enabled && renderable.isVisibleFromCamera( cam ) )
             renderable.debugRender( Graphics.instance );
     }
 }
Пример #4
0
        public override void render(Nez.Graphics graphics, Nez.Camera camera)
        {
            if (Core.debugRenderEnabled)
            {
                graphics.batcher.drawCircle(camera.screenToWorldPoint(_midSize), 10f, Color.Beige);
                graphics.batcher.drawCircle(_targetPos, 10f, Color.Orchid);

                graphics.batcher.drawCircle(_targetPos, 10f, Color.Green);
            }
        }
Пример #5
0
		public override void onAddedToEntity()
		{
			if( camera == null )
				camera = entity.scene.camera;

			follow( _targetEntity, _cameraStyle );

			// listen for changes in screen size so we can keep our deadzone properly positioned
			Core.emitter.addObserver( CoreEvents.GraphicsDeviceReset, onGraphicsDeviceReset );
		}
Пример #6
0
        public override void onAddedToEntity()
        {
            if (camera == null)
            {
                camera = entity.scene.camera;
            }

            follow(_targetEntity);

            // listen for changes in screen size so we can keep our deadzone properly positioned
            Core.emitter.addObserver(CoreEvents.GraphicsDeviceReset, onGraphicsDeviceReset);
        }
Пример #7
0
 protected override void debugRender( Scene scene, Camera cam )
 {
     for( var i = 0; i < renderLayers.Length; i++ )
     {
         var renderables = scene.renderableComponents.componentsWithRenderLayer( renderLayers[i] );
         for( var j = 0; j < renderables.Count; j++ )
         {
             var renderable = renderables[j];
             if( renderable.enabled && renderable.isVisibleFromCamera( cam ) )
                 renderable.debugRender( Graphics.instance );
         }
     }
 }
Пример #8
0
        public override void render(Nez.Graphics graphics, Nez.Camera camera)
        {
            // TODO figure out the height of the target dynamically.
            var barPos = entity.position + _targetOffset;
            var health = entity.getComponent <Health>();

            if (health != null)
            {
                var healthWidth = (float)health.Hp / health.MaxHp * BarWidth;

                graphics.batcher.drawRect(barPos, BarWidth, BarHeight, Color.Red);
                graphics.batcher.drawRect(barPos, healthWidth, BarHeight, Color.Chartreuse);
            }
        }
Пример #9
0
        public override void render(Graphics graphics, Nez.Camera camera)
        {
            if (Vertices == null)
            {
                return;
            }

            basicEffect.Projection = camera.projectionMatrix;
            basicEffect.View       = camera.transformMatrix;
            basicEffect.World      = entity.transform.localToWorldTransform * Matrix.CreateTranslation(Offset.X, Offset.Y, 0);
            basicEffect.CurrentTechnique.Passes[0].Apply();

            Nez.Core.graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
                                                              Vertices, 0, Vertices.Length,
                                                              indices, 0, primitiveCount);
        }
Пример #10
0
		public override void render( Graphics graphics, Camera camera )
		{
			if( _destRectsDirty )
			{
				subtexture.generateNinePatchRects( _finalRenderRect, _destRects, subtexture.top, subtexture.bottom, subtexture.right, subtexture.left );
				_destRectsDirty = false;
			}

			var pos = ( entity.transform.position + _localOffset ).ToPoint();

			for( var i = 0; i < 9; i++ )
			{
				// shift our destination rect over to our position
				var dest = _destRects[i];
				dest.X += pos.X;
				dest.Y += pos.Y;
				graphics.batcher.draw( subtexture, dest, subtexture.ninePatchRects[i], color );
			}
		}
Пример #11
0
		public override void render( Graphics graphics, Camera camera )
		{
			// flush the 2D batch so we render appropriately depth-wise
			graphics.batcher.flushBatch();

			Core.graphicsDevice.BlendState = BlendState.Opaque;
			Core.graphicsDevice.DepthStencilState = DepthStencilState.Default;

			for( var i = 0; i < _model.Meshes.Count; i++ )
			{
				var mesh = _model.Meshes[i];
				for( var j = 0; j < mesh.Effects.Count; j++ )
				{
					var effect = mesh.Effects[j] as BasicEffect;
					effect.World = worldMatrix;
					effect.View = camera.viewMatrix3D;
					effect.Projection = camera.projectionMatrix3D;
				}
				mesh.Draw();
			}
		}
Пример #12
0
 public override void render( Graphics graphics, Camera camera )
 {
     // we override render and use position instead of entityPosition. this keeps the text in place even if the entity moves
     graphics.batcher.drawString( _font, _text, localOffset, color, entity.transform.rotation, origin, entity.transform.scale, spriteEffects, layerDepth );
 }
Пример #13
0
 public override bool isVisibleFromCamera(Camera camera)
 {
     calculateVertices();
     return(base.isVisibleFromCamera(camera));
 }
Пример #14
0
		public override void render( Graphics graphics, Camera camera )
		{
			// TODO: make culling smarter and only render the lines that are actually on the screen rather than all or nothing
			var width = _points.GetLength( 0 );
			var height = _points.GetLength( 1 );

			for( var y = 1; y < height; y++ )
			{
				for( var x = 1; x < width; x++ )
				{
					var left = new Vector2();
					var up = new Vector2();
					var p = projectToVector2( _points[x, y].position );

					if( x > 1 )
					{
						float thickness;
						Color gridColor;
						if( y % gridMajorPeriodY == 1 )
						{
							thickness = gridMajorThickness;
							gridColor = gridMajorColor;
						}
						else
						{
							thickness = gridMinorThickness;
							gridColor = gridMinorColor;
						}


						// use Catmull-Rom interpolation to help smooth bends in the grid
						left = projectToVector2( _points[x - 1, y].position );
						var clampedX = Math.Min( x + 1, width - 1 );
						var mid = Vector2.CatmullRom( projectToVector2( _points[x - 2, y].position ), left, p, projectToVector2( _points[clampedX, y].position ), 0.5f );

						// If the grid is very straight here, draw a single straight line. Otherwise, draw lines to our new interpolated midpoint
						if( Vector2.DistanceSquared( mid, ( left + p ) / 2 ) > 1 )
						{
							drawLine( graphics.batcher, left, mid, gridColor, thickness );
							drawLine( graphics.batcher, mid, p, gridColor, thickness );
						}
						else
						{
							drawLine( graphics.batcher, left, p, gridColor, thickness );
						}
					}

					if( y > 1 )
					{
						float thickness;
						Color gridColor;
						if( x % gridMajorPeriodX == 1 )
						{
							thickness = gridMajorThickness;
							gridColor = gridMajorColor;
						}
						else
						{
							thickness = gridMinorThickness;
							gridColor = gridMinorColor;
						}

						up = projectToVector2( _points[x, y - 1].position );
						var clampedY = Math.Min( y + 1, height - 1 );
						var mid = Vector2.CatmullRom( projectToVector2( _points[x, y - 2].position ), up, p, projectToVector2( _points[x, clampedY].position ), 0.5f );

						if( Vector2.DistanceSquared( mid, ( up + p ) / 2 ) > 1 )
						{
							drawLine( graphics.batcher, up, mid, gridColor, thickness );
							drawLine( graphics.batcher, mid, p, gridColor, thickness );
						}
						else
						{
							drawLine( graphics.batcher, up, p, gridColor, thickness );
						}
					}

					// Add interpolated lines halfway between our point masses. This makes the grid look
					// denser without the cost of simulating more springs and point masses.
					if( x > 1 && y > 1 )
					{
						var upLeft = projectToVector2( _points[x - 1, y - 1].position );
						drawLine( graphics.batcher, 0.5f * ( upLeft + up ), 0.5f * ( left + p ), gridMinorColor, gridMinorThickness );  // vertical line
						drawLine( graphics.batcher, 0.5f * ( upLeft + left ), 0.5f * ( up + p ), gridMinorColor, gridMinorThickness );  // horizontal line
					}
				}
			}
		}
Пример #15
0
		public override void render( Graphics graphics, Camera camera )
		{
			stage.render( graphics, camera );
		}
Пример #16
0
 public PlatformSnapFollowCamera(Entity targetEntity, Nez.Camera camera)
 {
     _targetEntity = targetEntity;
     this.camera   = camera;
 }
Пример #17
0
        public override void render( Graphics graphics, Camera camera )
        {
            calculateVertices();
            _basicEffect.Projection = camera.projectionMatrix;
            _basicEffect.View = camera.transformMatrix;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            Core.graphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleStrip, _vertices, 0, _ribbonLength * 2 + 1 );
        }
Пример #18
0
 public DefaultRenderer( int renderOrder = 0, Camera camera = null )
     : base(renderOrder, camera)
 {
 }
Пример #19
0
 public override void render( Graphics graphics, Camera camera )
 {
     if( layerIndicesToRender == null )
     {
         tiledMap.draw( graphics.batcher, entity.transform.position + _localOffset, layerDepth, camera.bounds );
     }
     else
     {
         for( var i = 0; i < tiledMap.layers.Count; i++ )
         {
             if( tiledMap.layers[i].visible && layerIndicesToRender.contains( i ) )
                 tiledMap.layers[i].draw( graphics.batcher, entity.transform.position + _localOffset, layerDepth, camera.bounds );
         }
     }
 }
Пример #20
0
        public override void render( Graphics graphics, Camera camera )
        {
            _basicEffect.Projection = camera.projectionMatrix;
            _basicEffect.View = camera.transformMatrix;
            _basicEffect.World = entity.transform.localToWorldTransform;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            Core.graphicsDevice.SamplerStates[0] = Core.defaultSamplerState;
            Core.graphicsDevice.DrawUserPrimitives( primitiveType, verts, 0, _primitiveCount, VertexPositionColorTexture.VertexDeclaration );
        }
Пример #21
0
		public override void render( Graphics graphics, Camera camera )
		{
			graphics.batcher.drawString( _font, _text, entity.transform.position + _localOffset, color, entity.transform.rotation, origin, entity.transform.scale, spriteEffects, layerDepth );
		}
Пример #22
0
		public override void render( Graphics graphics, Camera camera )
		{
			if( _points.length < 2 )
				return;
			
			_basicEffect.Projection = camera.projectionMatrix;
			_basicEffect.View = camera.transformMatrix;
			_basicEffect.CurrentTechnique.Passes[0].Apply();

			if( !useWorldSpace )
				_basicEffect.World = transform.localToWorldTransform;

			var primitiveCount = _indices.length / 3;
			Core.graphicsDevice.SamplerStates[0] = Core.defaultWrappedSamplerState;
			Core.graphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, _vertices.buffer, 0, _vertices.length, _indices.buffer, 0, primitiveCount );
		}
Пример #23
0
 public ParalaxLayer(Nez.Camera camera) : this()
 {
     this.camera = camera;
 }
Пример #24
0
 public override bool isVisibleFromCamera( Camera camera )
 {
     calculateVertices();
     return base.isVisibleFromCamera( camera );
 }
Пример #25
0
 public override void render( Graphics graphics, Camera camera )
 {
     graphics.batcher.draw( subtexture, entity.transform.position + _localOffset, _sourceRect, color, entity.transform.rotation, origin, entity.transform.scale, spriteEffects, _layerDepth );
 }
Пример #26
0
        public override void render( Graphics graphics, Camera camera )
        {
            _basicEffect.Projection = camera.projectionMatrix;
            _basicEffect.View = camera.transformMatrix;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            // TODO: set the _basicEffect.World = entity.transform.localToWorldTransform instead of manualy mucking with verts and a local matrix
            // see the deferred lighting PolygonMesh class for details.

            Core.graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;
            Core.graphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleList, _verts, 0, _points.Length - 2, VertexPositionColor.VertexDeclaration );
        }
Пример #27
0
 public LockedCamera(Entity targetEntity, Nez.Camera camera)
 {
     _targetEntity = targetEntity;
     this.camera   = camera;
 }
Пример #28
0
 public override void onAddedToEntity()
 {
     _camera  = entity.getComponent <Nez.Camera>();
     _midSize = new Vector2(_camera.bounds.width, _camera.bounds.height) * 0.5f;
 }
Пример #29
0
		public override void render( Graphics graphics, Camera camera )
		{
			var topLeft = entity.transform.position + _localOffset;
			var destinationRect = RectangleExt.fromFloats( topLeft.X, topLeft.Y, _sourceRect.Width * entity.transform.scale.X * textureScale.X, _sourceRect.Height * entity.transform.scale.Y * textureScale.Y );

			graphics.batcher.draw( subtexture, destinationRect, _sourceRect, color, entity.transform.rotation, origin * _inverseTexScale, spriteEffects, _layerDepth );
		}
Пример #30
0
		public override void render( Graphics graphics, Camera camera )
		{
			_basicEffect.Projection = camera.projectionMatrix;
			_basicEffect.View = camera.transformMatrix;
			_basicEffect.World = entity.transform.localToWorldTransform;
			_basicEffect.CurrentTechnique.Passes[0].Apply();

			Core.graphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, _verts, 0, _verts.Length, _triangles, 0, _primitiveCount );
		}
Пример #31
0
		public override void render( Graphics graphics, Camera camera )
		{
			// flush the 2D batch so we render appropriately depth-wise
			graphics.batcher.flushBatch();

			Core.graphicsDevice.BlendState = BlendState.Opaque;
			Core.graphicsDevice.DepthStencilState = DepthStencilState.Default;

			// Set BasicEffect parameters.
			_basicEffect.World = worldMatrix;
			_basicEffect.View = camera.viewMatrix3D;
			_basicEffect.Projection = camera.projectionMatrix3D;
			_basicEffect.DiffuseColor = color.ToVector3();

			// Set our vertex declaration, vertex buffer, and index buffer.
			Core.graphicsDevice.SetVertexBuffer( _vertexBuffer );
			Core.graphicsDevice.Indices = _indexBuffer;

			_basicEffect.CurrentTechnique.Passes[0].Apply();
			var primitiveCount = _indices.Count / 3;
			Core.graphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, primitiveCount );
		}
Пример #32
0
		public override void render( Graphics graphics, Camera camera )
		{
			// First we draw all the trail nodes using the border color. we need to draw them slightly larger, so the border is left visible
			// when we draw the actual nodes

			// adjust the startScale and endScale to take into consideration the border
			var borderStartScale = startScale + borderSize / _cursorTexture.Width;
			var borderEndScale = endScale + borderSize / _cursorTexture.Width;

			// draw all nodes with the new scales
			for( var i = 0; i < _trailNodeCount; i++ )
			{
				var node = _trailNodes[i];
				var lerpFactor = (float)i / (float)( _trailNodeCount - 1 );
				lerpFactor = Mathf.pow( lerpFactor, lerpExponent );
				var scale = MathHelper.Lerp( borderStartScale, borderEndScale, lerpFactor );

				// draw using the border Color
				graphics.batcher.draw( _cursorTexture, node.position, null, borderColor, 0.0f, _textureCenter, scale, SpriteEffects.None, 0.0f );
			}

			// Next, we draw all the nodes normally, using the fill Color because before we drew them larger, after we draw them at
			// their normal size, a border will remain visible.
			for( var i = 0; i < _trailNodeCount; i++ )
			{
				var node = _trailNodes[i];
				var lerpFactor = (float)i / (float)( _trailNodeCount - 1 );
				lerpFactor = Mathf.pow( lerpFactor, lerpExponent );
				var scale = MathHelper.Lerp( startScale, endScale, lerpFactor );

				// draw using the fill color
				graphics.batcher.draw( _cursorTexture, node.position, null, fillColor, 0.0f, _textureCenter, scale, SpriteEffects.None, 0.0f );
			}
		}
Пример #33
0
		public FollowCamera( Entity targetEntity, Camera camera )
		{
			_targetEntity = targetEntity;
			this.camera = camera;
		}
Пример #34
0
 public override void render( Graphics graphics, Camera camera )
 {
     _sprite.drawOutline( graphics, camera, outlineColor, outlineWidth );
     _sprite.render( graphics, camera );
 }
Пример #35
0
		public override void render( Graphics graphics, Camera camera )
		{
			var pos = ( entity.transform.position - ( origin * entity.transform.localScale ) + localOffset );
			var size = new Point( (int)( _width * entity.transform.localScale.X ), (int)( _height * entity.transform.localScale.Y ) );
			var destRect = new Rectangle( (int)pos.X, (int)pos.Y, size.X, size.Y );
			graphics.batcher.draw( subtexture, destRect, subtexture.sourceRect, color, entity.transform.rotation, SpriteEffects.None, layerDepth, _skewTopX, _skewBottomX, _skewLeftY, _skewRightY );
		}
Пример #36
0
		/// <summary>
		/// renders the MarkupText
		/// </summary>
		/// <param name="graphics">Graphics.</param>
		/// <param name="camera">Camera.</param>
		public override void render( Graphics graphics, Camera camera )
		{
			if( _compiledMarkup == null )
				return;
			
			for( var i = 0; i < _compiledMarkup.Count; i++ )
				_compiledMarkup[i].render( graphics, transform.position );
		}