Exemple #1
0
		public void Transform(Matrix world, Matrix view)
		{
			TransformedVector = Vector.Transform(Vector, world);
			TransformedVector = Vector.Transform(TransformedVector, view);
			TransformedNormal = Vector.TransformNormal(Normal, world);
			TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
		}
Exemple #2
0
        // The update method is called every frame
        public override void Update()
        {
            _audi.World    = Matrix.CreateRotationY(_audiRotation);
            _audiRotation += 0.5f;

            base.Update();
        }
Exemple #3
0
        public override void LoadContent()
        {
            var mesh = ContentManager.Load <Mesh>("audi.ASE");

            //mesh.Position.X = -30;
            mesh.World = Matrix.CreateScale(new Vector(10f, 10f, 10f));
            Scene.AddNode(mesh);

            _lightSprite = ContentManager.Load <Sprite>("sun.png");
            Scene.AddNode(_lightSprite);


            var sprite = ContentManager.Load <Sprite>("recycle.png");

            sprite.Position = new Vector(-10, 0, 0);
            //Scene.AddNode(sprite);

            Display.BackgroundColor = Color.FromArgb(0xff, 0, 0, 0);

            var cylinder = ContentManager.CreateCylinder(10f, 20f, 8, 1);

            light               = new OmniLight();
            light.Range         = 3.0f;
            light.Position.X    = 0;
            light.Position.Y    = 0;
            light.Position.Z    = -30;
            light.ColorDiffuse  = Color.FromArgb(0xff, 0x1f, 0x1f, 0x6f);
            light.ColorSpecular = Color.FromArgb(0xff, 0xff, 0xff, 0xff);
            light.ColorAmbient  = Color.FromArgb(0xff, 0, 0x5f, 0);
            Scene.AddNode(light);
        }
Exemple #4
0
 public void Transform(Matrix world, Matrix view)
 {
     TransformedVector = Vector.Transform(Vector, world);
     TransformedVector = Vector.Transform(TransformedVector, view);
     TransformedNormal = Vector.TransformNormal(Normal, world);
     TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
 }
Exemple #5
0
		public void Transform(Matrix world, Matrix view)
		{
			TransformedNormal = Vector.TransformNormal(Normal, world);
			TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
			TransformedPosition = Vector.Transform(Position, world, view);

			TransformedDebugNormal = TransformedPosition +(TransformedNormal); //*DebugNormalLength);
		}
Exemple #6
0
		public void Render(IViewport viewport, Matrix view, Matrix projection)
		{
			foreach( RenderableNode node in _renderableNodes )
			{
				node.PrepareRender();
				node.Render(viewport,view,projection);
			}
		}
Exemple #7
0
        public void Transform(Matrix world, Matrix view)
        {
            TransformedNormal   = Vector.TransformNormal(Normal, world);
            TransformedNormal   = Vector.TransformNormal(TransformedNormal, view);
            TransformedPosition = Vector.Transform(Position, world, view);

            TransformedDebugNormal = TransformedPosition + (TransformedNormal);            //*DebugNormalLength);
        }
Exemple #8
0
 public void Render(IViewport viewport, Matrix view, Matrix projection)
 {
     foreach (RenderableNode node in _renderableNodes)
     {
         node.PrepareRender();
         node.Render(viewport, view, projection);
     }
 }
Exemple #9
0
 public void Transform(Matrix world, Matrix view)
 {
     //var matrix = world*view;
     var matrix = view;
     TransformedVector = Vector.Transform(Vector, matrix);
     //TransformedVector = Vector.Transform(TransformedVector, view);
     TransformedNormal = Vector.TransformNormal(Normal, matrix);
     //TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
 }
Exemple #10
0
		public override void Render(IViewport viewport, Matrix view, Matrix projection)
		{
			for( var geometryIndex=0; geometryIndex<_geometries.Length; geometryIndex++ )
			{
				var geometry = _geometries[geometryIndex];

				var localWorld = World*geometry.World;

				geometry.GeometryContext.Render(viewport,view,projection,localWorld);
			}
		}
Exemple #11
0
 public static Vector Transform(Vector position, Matrix matrix)
 {
     Vector vector = Vector.Zero;
     float num3 = (((position.X * matrix[0, 0]) + (position.Y * matrix[1, 0])) + (position.Z * matrix[2, 0])) + matrix[3, 0];
     float num2 = (((position.X * matrix[0, 1]) + (position.Y * matrix[1, 1])) + (position.Z * matrix[2, 1])) + matrix[3, 1];
     float num = (((position.X * matrix[0, 2]) + (position.Y * matrix[1, 2])) + (position.Z * matrix[2, 2])) + matrix[3, 2];
     vector.X = num3;
     vector.Y = num2;
     vector.Z = num;
     return vector;
 }
Exemple #12
0
		public static Vector Unproject(this IViewport viewport, Vector source, Matrix projection, Matrix view, Matrix world)
		{
			var matrix = Matrix.Invert((world * view) * projection);
			source.X = (((source.X - viewport.XPosition) / ((float)viewport.Width)) * 2f) - 1f;
			source.Y = -((((source.Y - viewport.YPosition) / ((float)viewport.Height)) * 2f) - 1f);
			source.Z = (source.Z - MinDepth) / (MaxDepth - MinDepth);
			var vector = Vector.Transform(source, matrix);
			var a = (((source.X * matrix[0,3]) + (source.Y * matrix[1,3])) + (source.Z * matrix[2,3])) + matrix[3,3];
			if (!WithinEpsilon(a, 1f))
			{
				vector = (Vector)(vector / a);
			}
			return vector;
		}
Exemple #13
0
		public override void Render(IViewport viewport, Matrix view, Matrix projection)
		{
			/*
			var xRotation = Matrix.CreateRotationX(XRotation);
			var yRotation = Matrix.CreateRotationY(YRotation);
			var zRotation = Matrix.CreateRotationZ(ZRotation);
			var translation = Matrix.CreateTranslation(Position);
			var scale = Matrix.CreateScale(Scale);

			var localToWorld = World * xRotation * yRotation * zRotation * translation * scale;
			*/

			GeometryContext.Render(viewport, view, projection, World);
		}
Exemple #14
0
        public void RenderBoundingSphere(BoundingSphere sphere, Viewport viewport, Matrix view, Matrix projection, Matrix world)
        {
            var scaleMatrix = Matrix.CreateScale(sphere.Radius);
            var translationMatrix = Matrix.CreateTranslation(sphere.Center) * world;
            var rotateYMatrix = Matrix.CreateRotationY(90);
            var rotateXMatrix = Matrix.CreateRotationX(90);

            _boundingSphereDebugShape.World = scaleMatrix * translationMatrix;
            _boundingSphereDebugShape.Render(viewport, view, projection);

            _boundingSphereDebugShape.World = rotateYMatrix * scaleMatrix * translationMatrix;
            _boundingSphereDebugShape.Render(viewport, view, projection);

            _boundingSphereDebugShape.World = rotateXMatrix * scaleMatrix * translationMatrix;
            _boundingSphereDebugShape.Render(viewport, view, projection);
        }
Exemple #15
0
		public override void Render(IViewport viewport, Matrix view, Matrix projection)
		{
			/* From DirectX sample
				w = width passed to D3DXMatrixPerspectiveLH
				h = height passed to D3DXMatrixPerspectiveLH
				n = z near passed to D3DXMatrixPerspectiveLH
				f = z far passed to D3DXMatrixPerspectiveLH
				d = distance of sprite from camera along Z
				qw = width of sprite quad
				qh = height of sprite quad
				vw = viewport height
				vh = viewport width
				scale = n / d
				(i.e. near/distance, such that at d = n, scale = 1.0)
				renderedWidth = vw * qw * scale / w 
				renderedHeight = vh * qh * scale / h
			 */

			var position = new Vector(0, 0, 0);
			var actualPosition = new Vector(World.data[12], World.data[13], World.data[14]);
			var transformedPosition = Vector.Transform(position, World, view);
			var translatedPosition = Vector.Translate(transformedPosition, projection, viewport.Width, viewport.Height);

			var distanceVector = viewport.Camera.Position - actualPosition;
			var distance = distanceVector.Length;
			var n = 100.0f;
			distance = MathHelper.Abs(distance);

			var scale = 0.0f + ((2 * n) / distance);
			if (scale <= 0)
			{
				scale = 0;
			}

			var xscale = scale;
			var yscale = scale;

			_spriteContext.Render(viewport,this,view,projection,World,xscale,yscale,0f);
		}
		public void Render(IViewport viewport, Matrix view, Matrix projection, Matrix world)
		{
			var actualViewport = viewport as Viewport;

			var position = new Vector(0, 0, 0);
            var actualPosition = new Vector(world.data[12], world.data[13], world.data[14]);
			var transformedPosition = Vector.Transform(position, world, view);
			var translatedPosition = Vector.Translate(transformedPosition, projection, viewport.Width, viewport.Height);
            /*

                w = width passed to D3DXMatrixPerspectiveLH
                h = height passed to D3DXMatrixPerspectiveLH
                n = z near passed to D3DXMatrixPerspectiveLH
                f = z far passed to D3DXMatrixPerspectiveLH
                d = distance of sprite from camera along Z
                qw = width of sprite quad
                qh = height of sprite quad
                vw = viewport height
                vh = viewport width
                scale = n / d
                (i.e. near/distance, such that at d = n, scale = 1.0)
                renderedWidth = vw * qw * scale / w 
                renderedHeight = vh * qh * scale / h

             */

            var distanceVector = actualViewport.Camera.Position - actualPosition;
            float distance = distanceVector.Length;
            float N = 30.0f;
            distance = MathHelper.Abs(distance);

            float scale = 0.0f + ((2 * N) / distance);
            if (scale <= 0)
                scale = 0;

			actualViewport.RenderImage(_frame,transformedPosition,translatedPosition, scale);
		}
Exemple #17
0
 public void Transform(Matrix matrix)
 {
     TransformedNormal = Vector.TransformNormal(Normal, matrix);
     TransformedPosition = Vector.Transform(Position, matrix);
 }
Exemple #18
0
 public void Translate(Matrix projectionMatrix, float width, float height)
 {
     TranslatedVector = Vector.Translate(TransformedVector, projectionMatrix, width, height);
 }
Exemple #19
0
 public void Render(Viewport viewport, RenderableNode node, Matrix view, Matrix projection, Matrix world)
 {
     TransformAndTranslateVertices(viewport, node,view,projection,world);
     RenderFaces(viewport, view, projection, world);
     RenderLines(viewport, view, projection, world);
 }
Exemple #20
0
 public void Translate(Matrix projectionMatrix, float width, float height)
 {
     TranslatedPosition    = Vector.Translate(TransformedPosition, projectionMatrix, width, height);
     TranslatedDebugNormal = Vector.Translate(TransformedDebugNormal, projectionMatrix, width, height);
 }
Exemple #21
0
 public void Update(Viewport viewport)
 {
     ViewMatrix = Matrix.CreateLookAt(Position, Target, Up);
     SetupProjection(viewport);
     UpdateDepthDivisor();
     _frustum.SetCameraDefinition(viewport, this);
 }
Exemple #22
0
		public void Translate(Matrix projectionMatrix, float width, float height)
		{
			TranslatedPosition = Vector.Translate(TransformedPosition, projectionMatrix, width, height);
			TranslatedDebugNormal = Vector.Translate(TransformedDebugNormal, projectionMatrix, width, height);
		}
Exemple #23
0
 public void Transform(Matrix matrix)
 {
     TransformedVector = Vector.Transform(Vector, matrix);
     TransformedNormal = Vector.TransformNormal(Normal, matrix);
 }
		public void Render(IViewport viewport, Sprite sprite, Matrix view, Matrix projection, Matrix world, float xScale, float yScale, float rotation)
		{
			
		}
Exemple #25
0
        private void TransformAndTranslateVertices(Viewport viewport, Node node, Matrix view, Matrix projection, Matrix world)
        {
            var negativePivot = -(Vector)node.PivotPoint;

            var localView = (world * view);
            for (var vertexIndex = 0; vertexIndex < Vertices.Length; vertexIndex++)
            {
                var vertex = Vertices[vertexIndex];
                vertex.Vector += negativePivot;

                TransformAndTranslateVertex(ref vertex, viewport, localView, projection);
                //CalculateColorForVertex(ref vertex, viewport, node);
                vertex.Vector -= negativePivot;
                Vertices[vertexIndex] = vertex;
            }
        }
Exemple #26
0
 private void TransformAndTranslateVertices(Viewport viewport, RenderableNode node, Matrix view, Matrix projection, Matrix world)
 {
     for (var vertexIndex = 0; vertexIndex < Vertices.Length; vertexIndex++)
     {
         var vertex = Vertices[vertexIndex];
         TransformAndTranslateVertex(ref vertex, viewport, view, projection, world);
         CalculateColorForVertex(ref vertex, viewport, node);
         Vertices[vertexIndex] = vertex;
     }
 }
Exemple #27
0
 private void RenderVertices(Node node, Viewport viewport, Matrix view, Matrix projection, Matrix world)
 {
     for (var vertexIndex = 0; vertexIndex < Vertices.Length; vertexIndex++)
     {
         PointRenderer.Draw((int)Vertices[vertexIndex].TranslatedScreenCoordinates.X,
                             (int)Vertices[vertexIndex].TranslatedScreenCoordinates.Y,
                             viewport.DebugInfo.Color,
                             4);
     }
 }
Exemple #28
0
 private void RenderLines(Node node, Viewport viewport, Matrix view, Matrix projection, Matrix world)
 {
     if (null == Lines)
     {
         return;
     }
     for (var lineIndex = 0; lineIndex < Lines.Length; lineIndex++)
     {
         var line = Lines[lineIndex];
         var a = Vertices[line.A];
         var b = Vertices[line.B];
         var xstart = a.TranslatedScreenCoordinates.X;
         var ystart = a.TranslatedScreenCoordinates.Y;
         var xend = b.TranslatedScreenCoordinates.X;
         var yend = b.TranslatedScreenCoordinates.Y;
         Shapes.DrawLine(viewport,
                         (int)xstart,
                         (int)ystart,
                         (int)xend,
                         (int)yend, node.Color);
     }
 }
Exemple #29
0
		internal void OnBeforeRendering(Viewport viewport, Matrix view, Matrix projection, Matrix world)
		{
			BeforeRendering(viewport, view, projection, world);
		}
Exemple #30
0
		public void Translate(Matrix projectionMatrix, float width, float height)
		{
			TranslatedVector = Vector.Translate(TransformedVector, projectionMatrix, width, height);
		}
Exemple #31
0
 private void TransformAndTranslateVertex(ref Vertex vertex, Viewport viewport, Matrix view, Matrix projection, Matrix world)
 {
     var matrix = (world*view)*projection;
     vertex.Transform(world, matrix);
     vertex.Translate(projection, viewport.Width, viewport.Height);
     vertex.MakeScreenCoordinates();
     vertex.TransformedVectorNormalized = vertex.TransformedNormal;
     vertex.TransformedVectorNormalized.Normalize();
     var z = ((vertex.TransformedVector.Z/viewport.Camera.DepthDivisor) + viewport.Camera.DepthZero);
     vertex.DepthBufferAdjustedZ = z;
 }
Exemple #32
0
 public override void Render(Viewport viewport, Matrix view, Matrix projection)
 {
     GeometryContext.Render(viewport, this, view, projection, World);
 }
Exemple #33
0
        private void RenderFaces(Viewport viewport, Matrix view, Matrix projection, Matrix world)
        {
            if( null == Faces )
            {
                return;
            }
            for (var faceIndex = 0; faceIndex < Faces.Length; faceIndex++)
            {
                var face = Faces[faceIndex];

                var a = Vertices[face.A];
                var b = Vertices[face.B];
                var c = Vertices[face.C];

                face.Transform(world, view);
                face.Translate(projection, viewport.Width, viewport.Height);

                var mixedProduct = (b.TranslatedVector.X - a.TranslatedVector.X) * (c.TranslatedVector.Y - a.TranslatedVector.Y) -
                                   (c.TranslatedVector.X - a.TranslatedVector.X) * (b.TranslatedVector.Y - a.TranslatedVector.Y);

                var visible = (mixedProduct < 0) && viewport.Camera.IsVectorVisible(a.TransformedVector);
                if (!visible)
                {
                    continue;
                }

                face.Color = viewport.Scene.CalculateColorForVector(viewport, face.TransformedPosition, face.TransformedNormal);
                Triangle.Draw(BufferManager.Instance.Current, SpanRenderer, TriangleShade.Gouraud, face, Vertices,
                              TextureCoordinates);
            }
        }
Exemple #34
0
 private static void TransformAndTranslateVertex(ref Vertex vertex, Viewport viewport, Matrix view, Matrix projection)
 {
     vertex.Transform(view);
     vertex.Translate(projection, viewport.Width, viewport.Height);
     vertex.MakeScreenCoordinates();
     vertex.TransformedVectorNormalized = vertex.TransformedNormal;
     vertex.TransformedVectorNormalized.Normalize();
     var z = ((vertex.TransformedVector.Z / viewport.View.DepthDivisor) + viewport.View.DepthZero);
     vertex.DepthBufferAdjustedZ = z;
 }
Exemple #35
0
        public void Render(Viewport viewport, RenderableNode node, Matrix view, Matrix projection, Matrix world)
        {
            if (null == Vertices)
            {
                return;
            }
            if (!_hasPrepared)
            {
                Prepare();
                _hasPrepared = true;
            }

            TransformAndTranslateVertices(viewport, node, view, projection, world);

            RenderFaces(node, viewport, view, projection, world);
            RenderLines(node, viewport, view, projection, world);

            if (viewport.DebugInfo.ShowVertices)
            {
                RenderVertices(node, viewport, view, projection, world);
            }
        }
Exemple #36
0
        private void RenderFaces(Node node, Viewport viewport, Matrix view, Matrix projection, Matrix world)
        {
            if (null == Faces)
            {
                return;
            }

            var matrix = world*view;

            for (var faceIndex = 0; faceIndex < Faces.Length; faceIndex++)
            {
                var face = Faces[faceIndex];

                var a = Vertices[face.A];
                var b = Vertices[face.B];
                var c = Vertices[face.C];

                var mixedProduct = (b.TranslatedVector.X - a.TranslatedVector.X) * (c.TranslatedVector.Y - a.TranslatedVector.Y) -
                                   (c.TranslatedVector.X - a.TranslatedVector.X) * (b.TranslatedVector.Y - a.TranslatedVector.Y);

                var visible = mixedProduct < 0; // && viewport.View.IsInView(a.TransformedVector);
                if (null != face.Material)
                {
                    visible |= face.Material.DoubleSided;
                }
                if (!visible)
                {
                    continue;
                }

                CalculateVertexColorsForFace(ref face, viewport, node);
                if (null != face.Material)
                {
                    switch (face.Material.Shade)
                    {
                        case MaterialShade.None:
                            {
                                face.Color = face.Material.Diffuse;
                                if (null != face.Material.DiffuseMap || null != face.Material.ReflectionMap)
                                {
                                    TextureTriangleRenderer.Draw(face, Vertices);
                                }
                                else
                                {
                                    FlatTriangleRenderer.Draw(face, Vertices);
                                }
                            }
                            break;

                        case MaterialShade.Flat:
                            {
                                face.Transform(matrix);
                                var color = face.Material.Diffuse;
                                face.Color = color.Additive(_colorCalculator.Calculate(viewport, face.TransformedPosition, face.TransformedNormal));
                                if (null != face.Material.DiffuseMap || null != face.Material.ReflectionMap)
                                {
                                    TextureTriangleRenderer.Draw(face, Vertices);
                                }
                                else
                                {
                                    FlatTriangleRenderer.Draw(face, Vertices);
                                }
                            }
                            break;

                        case MaterialShade.Gouraud:
                            {
                                var color = face.Material.Diffuse;
                                Vertices[face.A].CalculatedColor = color.Additive(Vertices[face.A].CalculatedColor);
                                Vertices[face.B].CalculatedColor = color.Additive(Vertices[face.B].CalculatedColor);
                                Vertices[face.C].CalculatedColor = color.Additive(Vertices[face.C].CalculatedColor);

                                if (null != face.Material.DiffuseMap || null != face.Material.ReflectionMap)
                                {
                                    TextureTriangleRenderer.Draw(face, Vertices);
                                }
                                else
                                {
                                    GouraudTriangleRenderer.Draw(face, Vertices);
                                }

                            }
                            break;
                    }
                }
                else
                {
                    var color = node.Color;

                    var aColor = Vertices[face.A].CalculatedColor;
                    var bColor = Vertices[face.B].CalculatedColor;
                    var cColor = Vertices[face.C].CalculatedColor;
                    Vertices[face.A].CalculatedColor = Vertices[face.A].CalculatedColor.Additive(color);
                    Vertices[face.B].CalculatedColor = Vertices[face.B].CalculatedColor.Additive(color);
                    Vertices[face.C].CalculatedColor = Vertices[face.C].CalculatedColor.Additive(color);
                    GouraudTriangleRenderer.Draw(face, Vertices);
                    Vertices[face.A].CalculatedColor = aColor;
                    Vertices[face.B].CalculatedColor = bColor;
                    Vertices[face.C].CalculatedColor = cColor;
                }
            }
        }
Exemple #37
0
		protected virtual void BeforeRendering(Viewport viewport, Matrix view, Matrix projection, Matrix world) { }