コード例 #1
0
ファイル: CameraController.cs プロジェクト: winterdl/LD10
        public override void Update(TimeSpan elapsed)
        {
            if (!manual)
            {
                sphere = BoundingSphere.CreateFromPoints(
                    new Vector3[] {
                    player1Tail.BoundingSphere.Center,
                    player2Tail.BoundingSphere.Center,
                    ballTransform.Position
                });

                //transform.Position.X = ballTransform.Position.X;
                transform.Position.Y = sphere.Radius * 2.5f;
            }
            else
            {
                float rX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X;
                float rY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y;

                transform.Position.Y += -rY;
            }

            if (transform.Position.Y < 13)
            {
                transform.Position.Y = 13;
            }
        }
コード例 #2
0
        /// <summary>
        /// The main method in charge of processing the content.
        /// </summary>
        public override ModelContent Process(NodeContent input,
                                             ContentProcessorContext context)
        {
            // Look up the input vertex positions.
            FindVertices(input);

            // Chain to the base ModelProcessor class.
            ModelContent model = base.Process(input, context);

            // You can store any type of object in the model Tag property. This
            // sample only uses built-in types such as string, Vector3, BoundingSphere,
            // dictionaries, and arrays, which the content pipeline knows how to
            // serialize by default. We could also attach custom data types here, but
            // then we would have to provide a ContentTypeWriter and ContentTypeReader
            // implementation to tell the pipeline how to serialize our custom type.
            //
            // We are setting our model Tag to a dictionary that maps strings to
            // objects, and then storing two different kinds of custom data into that
            // dictionary. This is a useful pattern because it allows processors to
            // combine many different kinds of information inside the single Tag value.

            Dictionary <string, object> tagData = new Dictionary <string, object>();

            model.Tag = tagData;

            // Store vertex information in the tag data, as an array of Vector3.
            tagData.Add("Vertices", vertices.ToArray());

            // Also store a custom bounding sphere.
            tagData.Add("BoundingSphere", BoundingSphere.CreateFromPoints(vertices));

            return(model);
        }
コード例 #3
0
ファイル: Shape.cs プロジェクト: roy-t/gear-physics
        public Shape(GraphicsDevice device, Color color, List <Vector2> outline, bool connect)
        {
            texture = new Texture2D(device, 1, 1);
            texture.SetData(new Color[] { color });


            vertices = new VertexPositionColor[outline.Count];
            indices  = new short[vertices.Length * 2];

            var min = Vector2.One * float.MaxValue;
            var max = Vector2.One * float.MinValue;

            var ii = 0;

            for (var i = 0; i < vertices.Length; i++)
            {
                var vertex = outline[i];
                vertices[i] = new VertexPositionColor(new Vector3(vertex.X, 0, vertex.Y), color);

                indices[ii++] = (short)i;

                if (connect)
                {
                    indices[ii++] = (short)((i + 1) % vertices.Length);
                }

                min.X = Min(min.X, vertex.X);
                min.Y = Min(min.Y, vertex.Y);
                max.X = Max(max.X, vertex.X);
                max.Y = Max(max.Y, vertex.Y);
            }

            Radius = BoundingSphere.CreateFromPoints(vertices.Select(v => v.Position)).Radius;
        }
コード例 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="max">Punto máximo de un AABB</param>
        /// <param name="min">Punto mínimo de un AABB</param>
        /// <param name="mass">Masa</param>
        public CollisionBox(Vector3 max, Vector3 min, float mass)
            : base(mass)
        {
            this.HalfSize = (max - min) * 0.5f;

            this.m_SPH = BoundingSphere.CreateFromPoints(this.GetCorners());
        }
コード例 #5
0
        /// <summary>
        /// Converts a single piece of input geometry into our custom format.
        /// </summary>
        void ProcessGeometry(GeometryContent geometry, MyreModelContent model)
        {
            int triangleCount = geometry.Indices.Count / 3;
            int vertexCount   = geometry.Vertices.VertexCount;

            // Flatten the flexible input vertex channel data into
            // a simple GPU style vertex buffer byte array.
            var vertexBufferContent = geometry.Vertices.CreateVertexBuffer();

            // Convert the input material.
            var materials = ProcessMaterial(geometry.Material, geometry.Parent);

            var boundingSphere = BoundingSphere.CreateFromPoints(geometry.Vertices.Positions);

            // Add the new piece of geometry to our output model.
            model.AddMesh(new MyreMeshContent()
            {
                //Parent = geometry.Parent,
                Name           = geometry.Parent.Name,
                BoundingSphere = boundingSphere,
                Materials      = materials,
                IndexBuffer    = geometry.Indices,
                VertexBuffer   = vertexBufferContent,
                VertexCount    = vertexCount,
                TriangleCount  = triangleCount
            });
        }
コード例 #6
0
        private static M.GeometryModelContent BuildModel(List <MeshContent> meshes, Dictionary <GeometryContent, M.MaterialContent> materials)
        {
            var model = new M.GeometryModelContent();

            var meshCounter = 0;

            foreach (var mesh in meshes)
            {
                var meshName = string.IsNullOrWhiteSpace(mesh.Name) ? $"{meshCounter}" : mesh.Name;
                meshCounter++;

                var geometryCounter = 0;
                foreach (var geometry in mesh.Geometry)
                {
                    var geometryName = string.IsNullOrWhiteSpace(geometry.Name) ? $"{geometryCounter}" : geometry.Name;
                    geometryCounter++;

                    StripVertexChannels(geometry);

                    var name         = string.Join(".", meshName, geometryName);
                    var vertexBuffer = geometry.Vertices.CreateVertexBuffer();
                    var indices      = geometry.Indices;
                    var bounds       = BoundingSphere.CreateFromPoints(mesh.Positions);

                    var geometryData = new M.GeometryDataContent(name, vertexBuffer, indices, bounds);

                    var material     = materials[geometry];
                    var geometryMesh = new M.GeometryMeshContent(geometryData, material, mesh.AbsoluteTransform);

                    model.Add(geometryMesh);
                }
            }

            return(model);
        }
コード例 #7
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            // DEBUG
            printNodeTree(input, context, "");

            // Hack (THERES IS A BUG IN THE XNA 2 BETA VERSION. THIS LINE SHOULD BE REMOVED IN THE FINAL VERSION)
            Scale *= 0.1f;

            // Process model
            ModelContent model = base.Process(input, context);

            // Transform all mesh in a absolute coordinate system
            //FlattenMesh(skeleton, input, context);

            // Now extract the model skeleton and all animations
            AnimatedModelData animatedModelData = ExtractSkeletonAndAnimations(input, context);

            // Extract all points from the mesh
            List <Vector3> vertexList = new List <Vector3>();

            GetModelVertices(input, vertexList);

            // Generate bounding volumes
            BoundingBox    modelBoundBox    = BoundingBox.CreateFromPoints(vertexList);
            BoundingSphere modelBoundSphere = BoundingSphere.CreateFromPoints(vertexList);

            Dictionary <string, object> tagDictionary = new Dictionary <string, object>();

            tagDictionary.Add("AnimatedModelData", animatedModelData);
            tagDictionary.Add("ModelBoudingBox", modelBoundBox);
            tagDictionary.Add("ModelBoudingSphere", modelBoundSphere);
            model.Tag = tagDictionary;

            return(model);
        }
コード例 #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="halfSize">Medias longitudes en los ejes de coordenadas</param>
        /// <param name="mass">Masa</param>
        public CollisionBox(Vector3 halfSize, float mass)
            : base(mass)
        {
            this.HalfSize = halfSize;

            this.m_SPH = BoundingSphere.CreateFromPoints(this.GetCorners());
        }
コード例 #9
0
        //Generates a mesh from required parameters, as well as specifying a parent bone to be used, used to simplify and clean up code.
        public static ModelMesh makeMeshFromPolygonList(List <Polygon> polys, GraphicsDevice graphics, ModelBone parentBone)
        {
            List <ModelMeshPart> parts = new List <ModelMeshPart>();
            ModelBone            bone  = new ModelBone();

            bone.Transform      = Matrix.CreateTranslation(0, 0, 0);
            bone.ModelTransform = parentBone.ModelTransform;

            List <Vector3> points = new List <Vector3>();

            foreach (Polygon p in polys)
            {
                ModelMeshPart part = makePartFromPolygon(p, graphics);
                parts.Add(part);
                foreach (Vector3 point in p.points)
                {
                    points.Add(point);
                }
            }

            ModelMesh mesh = new ModelMesh(graphics, parts);

            bone.AddMesh(mesh);
            parentBone.AddChild(bone);
            bone.Parent         = parentBone;
            mesh.ParentBone     = bone;
            mesh.BoundingSphere = BoundingSphere.CreateFromPoints(points);

            return(mesh);
        }
コード例 #10
0
        protected virtual void ProcessGeometryUsingMaterial(MaterialContent material,
                                                            IEnumerable <GeometryContent> geometryCollection,
                                                            ContentProcessorContext context)
        {
            if (material == null)
            {
                material = new BasicMaterialContent();
            }

            foreach (var geometry in geometryCollection)
            {
                ProcessBasicMaterial(material as BasicMaterialContent, geometry);

                var vertexBuffer   = geometry.Vertices.CreateVertexBuffer();
                var primitiveCount = geometry.Vertices.PositionIndices.Count;
                var parts          = new List <ModelMeshPartContent>
                {
                    new ModelMeshPartContent(vertexBuffer, geometry.Indices, 0, primitiveCount, 0,
                                             primitiveCount / 3)
                };

                var parent = geometry.Parent;
                var bounds = BoundingSphere.CreateFromPoints(geometry.Vertices.Positions);
                _meshes.Add(new ModelMeshContent(parent.Name, geometry.Parent, null, bounds, parts));
            }
        }
コード例 #11
0
        public override void Initialize()
        {
            var model = TryAndGetModelFromOwner();

            if (model != null)
            {
                Vector3[] vertices;
                int[]     indices;

                ModelDataExtractor.GetVerticesAndIndicesFromModel(model, out vertices, out indices);

                BoundingSphere _aabb = BoundingSphere.CreateFromPoints(vertices);

                if (Mass <= 0)
                {
                    //kinematic
                    Entity = new Sphere(MathConverter.Convert(Owner.World.Translation),
                                        _aabb.Radius);
                }
                else
                {
                    //dynamic
                    Entity = new Sphere(MathConverter.Convert(Owner.World.Translation),
                                        _aabb.Radius, Mass);
                }
            }

            base.Initialize();
        }
コード例 #12
0
        public override void Initialized()
        {
            if (Owner.HasComponent <BasicEffectModel>())
            {
                BasicEffectModel modelComp = Owner.GetComponent <BasicEffectModel>();

                Vector3[] vertices;
                int[]     indices;

                ModelDataExtractor.GetVerticesAndIndicesFromModel(modelComp.Model, out vertices, out indices);

                AABB = BoundingBox.CreateFromPoints(vertices);
                AABS = BoundingSphere.CreateFromPoints(vertices);

                AABS.Center = Vector3.Transform(AABS.Center, Owner.World);
                AABB.Max    = Vector3.Transform(AABB.Max, Owner.World);
                AABB.Min    = Vector3.Transform(AABB.Min, Owner.World);

                ray = new Ray(Owner.World.Translation, new Vector3(-1, 0, 0));
            }
            else
            {
                Destroy();
            }
            base.Initialized();
        }
コード例 #13
0
ファイル: BoundingSphereTests.cs プロジェクト: klenin/Citrus
        public void CreateFromPointsTest()
        {
            Assert.Catch <ArgumentNullException>(() => BoundingSphere.CreateFromPoints(null));
            var actualPoints = new List <Vector3> ();

            Assert.Catch <ArgumentException>(() => BoundingSphere.CreateFromPoints(actualPoints));
            actualPoints = new List <Vector3> {
                Vector3.Zero
            };
            var actual = BoundingSphere.CreateFromPoints(actualPoints);

            Assert.That(actual, Is.EqualTo(new BoundingSphere(Vector3.Zero, 0)));
            actualPoints = new List <Vector3> {
                new Vector3(1, 0, 0),
                new Vector3(-1, 0, 0),
            };
            actual = BoundingSphere.CreateFromPoints(actualPoints);
            Assert.That(actual, Is.EqualTo(unitSphere));
            actualPoints = new List <Vector3> {
                new Vector3(0, 1, 0),
                new Vector3(0, -1, 0),
            };
            actual = BoundingSphere.CreateFromPoints(actualPoints);
            Assert.That(actual, Is.EqualTo(unitSphere));
            actualPoints = new List <Vector3> {
                new Vector3(0, 0, 1),
                new Vector3(0, 0, -1)
            };
            actual = BoundingSphere.CreateFromPoints(actualPoints);
            Assert.That(actual, Is.EqualTo(unitSphere));
        }
コード例 #14
0
ファイル: ModelProcessor.cs プロジェクト: Breadmouth/Gravitas
        private ModelMeshContent ProcessMesh(MeshContent mesh, ModelBoneContent parent, ContentProcessorContext context)
        {
            var bounds       = new BoundingSphere();
            var parts        = new List <ModelMeshPartContent>();
            var vertexBuffer = new VertexBufferContent();
            var indexBuffer  = new IndexCollection();

            var startVertex = 0;

            foreach (var geometry in mesh.Geometry)
            {
                var vertices    = geometry.Vertices;
                var vertexCount = vertices.VertexCount;
                var geomBuffer  = geometry.Vertices.CreateVertexBuffer();
                vertexBuffer.Write(vertexBuffer.VertexData.Length, 1, geomBuffer.VertexData);

                var startIndex = indexBuffer.Count;
                indexBuffer.AddRange(geometry.Indices);

                var partContent = new ModelMeshPartContent(vertexBuffer, indexBuffer, startVertex, vertexCount, startIndex, geometry.Indices.Count / 3);
                partContent.Material = geometry.Material;
                parts.Add(partContent);

                // Update mesh bounding box
                bounds = BoundingSphere.CreateMerged(bounds, BoundingSphere.CreateFromPoints(geometry.Vertices.Positions));

                // Geoms are supposed to all have the same decl, so just steal one of these
                vertexBuffer.VertexDeclaration = geomBuffer.VertexDeclaration;

                startVertex += vertexCount;
            }

            return(new ModelMeshContent(mesh.Name, mesh, parent, bounds, parts));
        }
コード例 #15
0
ファイル: Shape.cs プロジェクト: sp-alex-osou/Shaders
        public BoundingSphere GetBoundingSphere()
        {
            if (boundingSphere.Radius == 0.0f)
            {
                boundingSphere = BoundingSphere.CreateFromPoints((IEnumerable <Vector3>)Model.Tag);
            }

            return(boundingSphere);
        }
コード例 #16
0
            public unsafe BoundingSphere GetBoundingSphere()
            {
                fixed(VertexPositionTexture *vertexPtr = &Vertices[0])
                {
                    Vector3 *positionPtr = (Vector3 *)vertexPtr;

                    return(BoundingSphere.CreateFromPoints(positionPtr, Vertices.Length, VertexPositionTexture.SizeInBytes));
                }
            }
コード例 #17
0
        public void GenerateGeometry(Effect testEffect, IModule module)
        {
            this.effect = testEffect;
            this.module = module;
            vertices    = new VertexPositionColorTextureNormal[heightMapSize * heightMapSize];

            int vertIndex = 0;



            for (float i = 0; i < heightMapSize; i++)
            {
                for (float j = 0; j < heightMapSize; j++)
                {
                    var vert = new VertexPositionColorTextureNormal();

                    vert.Position       = CalculateVertexPosition(i, j);
                    vert.Texture        = new Vector2(i * 2f / heightMapSize, j * 2f / heightMapSize);
                    vert.Normal         = normal;
                    vert.Color          = NodeColor;
                    vertices[vertIndex] = vert;
                    vertIndex++;
                }
            }


            GenerateIndices();

            if (normal == Vector3.Down || normal == Vector3.Backward || normal == Vector3.Right)
            {
                indices = indices.Reverse().ToArray();
            }



            indices = indices.Reverse().ToArray();


            Sphereify(sphereSize);

            GenerateNormals(ref vertices);


            short[] ind = indices;
            var     p   = vertices.Select(x => x.Position).ToList();
            var     s   = BoundingSphere.CreateFromPoints(p);


            ProceduralShape spherePatch = new ProceduralShape(vertices, indices);

            spherePatch.Translate(positionOffset);
            gameObject = GameObjectFactory.CreateRenderableGameObjectFromShape(spherePatch, effect);
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObject);

            isLeaf = true;
        }
コード例 #18
0
 /// <summary>
 /// Creates a box model.
 /// </summary>
 /// <param name="width">Width</param>
 /// <param name="height">Height</param>
 /// <param name="depth">Depth</param>
 public Box(float width, float height, float depth)
 {
     Name        = "Box Primitive";
     this.width  = width;
     this.height = height;
     this.depth  = depth;
     RecreateResource();
     boundingSphere = BoundingSphere.CreateFromPoints(Vertices);
     boundingBox    = BoundingBox.CreateFromPoints(Vertices);
 } // Box
コード例 #19
0
ファイル: TeapotRenderer.cs プロジェクト: GavinHwa/veldrid
        public TeapotRenderer(RenderContext rc)
        {
            _worldProvider = new DynamicDataProvider <Matrix4x4>();
            _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, CalculateInverseTranspose);
            _perObjectProviders            = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider };

            _centeredBounds = BoundingSphere.CreateFromPoints(LoadTeapotMesh().Vertices);

            InitializeContextObjects(rc);
        }
コード例 #20
0
        private void GenerateSphereCollider()
        {
            RenderGeometryComponent geometry = ParentObject.GetComponent <RenderGeometryComponent>();
            List <Vector3>          verts    = geometry.GetVertices();
            BoundingSphere          sphere   = BoundingSphere.CreateFromPoints(verts);

            PhysicsEntity = new Sphere(MonoMathHelper.Translate(ParentObject.Transform.AbsoluteTransform.Translation),
                                       sphere.Radius, 1);
            PhysicsEntity.Tag = ParentObject;
        }
コード例 #21
0
 /// <summary>
 /// Creates a cylinder model.
 /// </summary>
 /// <param name="radius">Radius</param>
 /// <param name="length">Length</param>
 /// <param name="slices">Slices</param>
 public Cylinder(float radius, float length, int slices)
 {
     Name        = "Cylinder Primitive";
     this.radius = radius;
     this.length = length;
     this.slices = slices;
     RecreateResource();
     boundingSphere = BoundingSphere.CreateFromPoints(Vertices);
     boundingBox    = BoundingBox.CreateFromPoints(Vertices);
 } // Cylinder
コード例 #22
0
ファイル: BoundingCircle.cs プロジェクト: Hengle/Engine-Nine
        /// <summary>
        /// Creates a BoundingCircle that can contain a specified list of points.
        /// </summary>
        public static BoundingCircle CreateFromPoints(IEnumerable <Vector2> points)
        {
            var sphere = BoundingSphere.CreateFromPoints(points.Select(pt => new Vector3(pt, 0)));
            var result = new BoundingCircle();

            result.Center.X = sphere.Center.X;
            result.Center.Y = sphere.Center.Y;
            result.Radius   = sphere.Radius;
            return(result);
        }
コード例 #23
0
 /// <summary>
 /// Creates a sphere model.
 /// </summary>
 /// <param name="stacks">Stacks</param>
 /// <param name="slices">Slices</param>
 /// <param name="radius">Radius</param>
 public Sphere(int stacks, int slices, float radius)
 {
     Name        = "Sphere Primitive";
     this.stacks = stacks;
     this.slices = slices;
     this.radius = radius;
     RecreateResource();
     boundingSphere = BoundingSphere.CreateFromPoints(Vertices);
     boundingBox    = BoundingBox.CreateFromPoints(Vertices);
 } // Sphere
コード例 #24
0
ファイル: Text3D.cs プロジェクト: ARLM-Attic/goblin-xna
        /// <summary>
        /// Actually builds the text
        /// </summary>
        /// <returns> The custom mesh that has all of the geometry information</returns>
        private void CreateText()
        {
            customMesh = new CustomMesh();

            CreateShape();

            foreach (VertexPositionNormalTexture aVertex in basicTextIn3D.Vertices)
            {
                vertices.Add(aVertex.Position);
            }

            if (styleToUse == UI3DRenderer.Text3DStyle.Fill)
            {
                for (int i = 0; i < basicTextIn3D.Vertices.Length; ++i)
                {
                    basicTextIn3D.Vertices[i].Normal = -basicTextIn3D.Vertices[i].Normal;
                }
            }

            foreach (short index in basicTextIn3D.Indices)
            {
                indices.Add((int)index);
            }

            customMesh.VertexDeclaration = VertexPositionNormalTexture.VertexDeclaration;

            customMesh.VertexBuffer = new VertexBuffer(State.Device, typeof(VertexPositionNormalTexture),
                                                       basicTextIn3D.Vertices.Length, BufferUsage.None);

            customMesh.VertexBuffer.SetData(basicTextIn3D.Vertices);

            customMesh.IndexBuffer = new IndexBuffer(State.Device, typeof(short), basicTextIn3D.Indices.Length,
                                                     BufferUsage.None);
            customMesh.IndexBuffer.SetData(basicTextIn3D.Indices);

            customMesh.NumberOfVertices   = basicTextIn3D.Vertices.Length;
            customMesh.NumberOfPrimitives = basicTextIn3D.Indices.Length / 3;
            customMesh.PrimitiveType      = basicTextIn3D.PrimitiveType;

            if (vertices.Count == 0)
            {
                throw new GoblinException("Corrupted model vertices. Failed to calculate MBB.");
            }
            else
            {
                boundingBox    = BoundingBox.CreateFromPoints(vertices);
                boundingSphere = BoundingSphere.CreateFromPoints(vertices);
                if (offsetTransform.Equals(Matrix.Identity))
                {
                    offsetTransform.Translation = (boundingBox.Min + boundingBox.Max) / 2;
                }
            }

            triangleCount = indices.Count / 3;
        }
コード例 #25
0
        public static BoundingSphere CreateBoundingSphere(this Schema2.Mesh mesh)
        {
            var points = mesh
                         .Primitives
                         .Select(item => item.GetVertexAccessor("POSITION"))
                         .Where(item => item != null)
                         .SelectMany(item => item.AsVector3Array())
                         .Select(item => item.ToXna());

            return(BoundingSphere.CreateFromPoints(points));
        }
コード例 #26
0
        } // Plane

        /// <summary>
        /// Creates a plane model.
        /// </summary>
        /// <param name="topLeft">Top left vertex's position</param>
        /// <param name="bottomLeft">Bottom left vertex's position</param>
        /// <param name="topRight">Top right vertex's position</param>
        /// <param name="bottomRight">Bottom right vertex's position</param>
        public Plane(Vector3 topLeft, Vector3 bottomLeft, Vector3 topRight, Vector3 bottomRight)
        {
            Name             = "Plane Primitive";
            this.topLeft     = topLeft;
            this.bottomLeft  = bottomLeft;
            this.topRight    = topRight;
            this.bottomRight = bottomRight;
            RecreateResource();
            boundingSphere = BoundingSphere.CreateFromPoints(Vertices);
            boundingBox    = BoundingBox.CreateFromPoints(Vertices);
        } // Plane
コード例 #27
0
 public BoundingSphere CalculateBoundingSphere()
 {
     Vector3[] points = new Vector3[curveX.Keys.Count];
     for (int i = 0; i < curveX.Keys.Count; i++)
     {
         points[i] = new Vector3(
             curveX.Keys[i].Value,
             curveY.Keys[i].Value,
             curveZ.Keys[i].Value);
     }
     return(BoundingSphere.CreateFromPoints(points));
 }
コード例 #28
0
ファイル: Edge.cs プロジェクト: willcraftia/TestBlocks
        void DrawNormalDepth(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawNormalDepth);

            var viewerCamera = context.ActiveCamera;

            //----------------------------------------------------------------
            // 内部カメラの準備

            internalCamera.View.Position                = viewerCamera.View.Position;
            internalCamera.View.Direction               = viewerCamera.View.Direction;
            internalCamera.View.Up                      = viewerCamera.View.Up;
            internalCamera.Projection.Fov               = viewerCamera.Projection.Fov;
            internalCamera.Projection.AspectRatio       = viewerCamera.Projection.AspectRatio;
            internalCamera.Projection.NearPlaneDistance = viewerCamera.Projection.NearPlaneDistance;
            internalCamera.Projection.FarPlaneDistance  = FarPlaneDistance;
            internalCamera.Update();

            internalCamera.Frustum.GetCorners(frustumCorners);
            frustumSphere = BoundingSphere.CreateFromPoints(frustumCorners);

            //----------------------------------------------------------------
            // エフェクト

            normalDepthMapEffect.View       = internalCamera.View.Matrix;
            normalDepthMapEffect.Projection = internalCamera.Projection.Matrix;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;

            GraphicsDevice.SetRenderTarget(normalDepthMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            // 不透明オブジェクトのみ対象。
            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];

                // 専用カメラの視錐台に含まれるもののみを描画。
                if (IsVisibleObject(opaque))
                {
                    opaque.Draw(normalDepthMapEffect);
                }
            }

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
コード例 #29
0
        public ShadowCaster(
            RenderContext rc,
            AssetDatabase ad,
            VertexPositionNormalTexture[] vertices,
            ushort[] indices,
            TextureData texture)
        {
            _meshData       = new SimpleMeshDataProvider(vertices, indices);
            _textureData    = texture;
            _centeredBounds = BoundingSphere.CreateFromPoints(vertices);

            InitializeContextObjects(ad, rc);
        }
コード例 #30
0
        /*internal override void CreateRuntimeCollisionData(CollisionType collType)
         * {
         *  // Note: Also update AssetImporterMeshStaticMesh
         *
         *  // Create 2D version of the mesh (individual triangles)
         *  Vector2[] allVertices2D = new Vector2[objectIndices.Length];
         *  for (int i = 0; i < objectIndices.Length; i++)
         *  {
         *      allVertices2D[i] = new Vector2(
         *          objectVertices[objectIndices[i]].pos.X,
         *          objectVertices[objectIndices[i]].pos.Y);
         *  }
         *  // Create 3D version of the mesh
         *  Vector3[] allVertices3D = new Vector3[objectVertices.Length];
         *  for (int i = 0; i < allVertices3D.Length; i++)
         *  {
         *      allVertices3D[i] = new Vector3(
         *          objectVertices[i].pos.X, objectVertices[i].pos.Y,
         *          objectVertices[i].pos.Z);
         *  }
         *
         *  switch (collType)
         *  {
         *      case CollisionType.BoundingBox:
         *          collisionData = CollisionDataBox.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *
         *      case CollisionType.BoundingEllipse:
         *          collisionData = CollisionDataEllipse.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *
         *      case CollisionType.BoundingSphere:
         *          collisionData = CollisionDataSphere.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *
         *      case CollisionType.ConvexHull:
         *          collisionData = CollisionDataConvexHull.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *
         *      case CollisionType.SkeletonBox:
         *          collisionData = CollisionDataSkeletonBox.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *
         *      case CollisionType.Vertices:
         *          collisionData = CollisionDataVertices.FromMesh(allVertices2D, allVertices3D);
         *          break;
         *  }
         * }*/
        #endregion

        #region CreateBoundingSphere
        internal override void CreateBoundingSphere()
        {
            // Create 3D version of the mesh
            Vector3[] allVertices3D = new Vector3[objectVertices.Length];
            for (int i = 0; i < allVertices3D.Length; i++)
            {
                allVertices3D[i] = new Vector3(
                    objectVertices[i].Position.X, objectVertices[i].Position.Y,
                    objectVertices[i].Position.Z);
            }

            BoundingSphere = BoundingSphere.CreateFromPoints(allVertices3D);
        }