protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // Initialize our render cube
     renderCube = new CubePrimitive(graphics.GraphicsDevice);
     // and then our font
     font = Content.Load <SpriteFont>("font");
 }
Пример #2
0
 public void Initialize(GraphicsDevice device, Color color, float angle, Vector3 positionVector, Vector3 rotationVector, Texture2D texture)
 {
     _cuboid        = new CubePrimitive(device, 2f);
     Color          = color;
     Angle          = angle;
     PositionVector = positionVector;
     RotationVector = rotationVector;
     Texture        = texture;
 }
Пример #3
0
 public DrawableBox(VisionContent vContent, Matrix world, Vector3 size, float texScale = 1)
     : base(vContent.LoadEffect("effects/SimpleTextureEffect"))
 {
     _texture = vContent.Load<Texture2D>("textures/brick_texture_map");
     _bumpMap = vContent.Load<Texture2D>("textures/brick_normal_map");
     _cube = new CubePrimitive<VertexPositionNormalTexture>(
         Effect.GraphicsDevice,
         (p,n,t) => createVertex(p,n,t,size,texScale),
         1);
     World = world;
 }
Пример #4
0
        private void InitializeContent()
        {
            //Geometry
            Box            = new CubePrimitive(GraphicsDevice);
            BoxPosition    = new Vector3(0, 0, 0);
            SpherePosition = Vector3.Zero;

            // Configuramos nuestras matrices de la escena.
            FloorWorld  = Matrix.CreateScale(2000, 0.1f, 2000) * Matrix.CreateTranslation(BoxPosition);
            SphereWorld = Matrix.CreateScale(0.02f);
        }
Пример #5
0
        public override void GenerateGeometry(string scenePath, List <PrimitiveBase> output)
        {
            CubePrimitive cube = CubePrimitive.Create();

            cube.position = Position;
            cube.scale    = Scale;
            cube.euler    = Vector3.zero;
            cube.material = shaders[0];

            output.Add(cube);
        }
Пример #6
0
        private void MonoGameControl_Loaded(object sender, MerjTek.WpfIntegration.GraphicsDeviceEventArgs e)
        {
            // Because this same event is hooked for all 4 controls, we check if the Stopwatch
            // is running to avoid loading our content 4 times.
            if (!watch.IsRunning)
            {
                // Create our 3D cube object
                cube = new CubePrimitive(e.GraphicsDevice);

                // Start the watch now that we're going to be starting our draw loop
                watch.Start();
            }
        }
Пример #7
0
        public override void Draw(GameTime gameTime, IDrawContext drawContext)
        {
            // todo: 先に LaF を描画。
            base.Draw(gameTime, drawContext);

            if (!CubeVisible)
            {
                return;
            }

            drawContext.Flush();

            // わざと Control の領域を越えるように調整。
            var renderSize = RenderSize;

            renderSize.Width  += 64;
            renderSize.Height += 64;

            using (var setViewport = drawContext.BeginViewport(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
            {
                using (var setClip = drawContext.BeginNewClip(new Rect(-32, -32, renderSize.Width, renderSize.Height)))
                {
                    var effect = Screen.BasicEffect;

                    var cameraPosition = new Vector3(0, 0, 2.5f);
                    var aspect         = ((float)renderSize.Width / (float)renderSize.Height);

                    effect.World        = Orientation * Matrix.CreateScale(Scale);
                    effect.View         = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection   = Matrix.CreatePerspectiveFieldOfView(1, aspect, 0.1f, 10);
                    effect.DiffuseColor = ForegroundColor.ToVector3();
                    // どうもデフォルトで Specular が設定されているようだ。
                    effect.SpecularColor = Color.Black.ToVector3();
                    effect.Alpha         = 1;
                    effect.EnableDefaultLighting();
                    effect.VertexColorEnabled = true;

                    CubePrimitive.Draw(effect);
                }
            }
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            Game.Background = Color.CornflowerBlue;
            Camera          = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(0, 20, 60), Vector3.Zero);

            Box = new CubePrimitive(GraphicsDevice, 10, Color.DarkCyan, Color.DarkMagenta, Color.DarkGreen,
                                    Color.MonoGameOrange, Color.Black, Color.DarkGray);
            BoxPosition      = Vector3.Zero;
            Cylinder         = new CylinderPrimitive(GraphicsDevice, 20, 10, 16);
            CylinderPosition = new Vector3(-20, 0, 0);
            Sphere           = new SpherePrimitive(GraphicsDevice, 10);
            SpherePosition   = new Vector3(0, -15, 0);
            Teapot           = new TeapotPrimitive(GraphicsDevice, 10);
            TeapotPosition   = new Vector3(20, 0, 0);
            Torus            = new TorusPrimitive(GraphicsDevice, 10, 1, 16);
            TorusPosition    = new Vector3(-20, 15, 0);
            Triangle         = new TrianglePrimitive(GraphicsDevice, new Vector3(-10f, 10f, 0f), new Vector3(0f, 20f, 0f),
                                                     new Vector3(10f, 10f, 0f), Color.Black, Color.Cyan, Color.Magenta);

            base.Initialize();
        }
Пример #9
0
        /// <summary>
        /// Creates a StaticModel from a GeometricPrimitive and specified dimensions.
        /// </summary>
        /// <param name="primitiveType">Type of primitive to create</param>
        /// <param name="height">Height of primitive, used by cubes and cylinders.</param>
        /// <param name="width">Width of primitive, used by cubes.</param>
        /// <param name="depth">Depth of primitive, used by cubes.</param>
        /// <param name="diameter">Diameter of primitive, used by cylinders, spheres, toruses, and teapots.</param>
        private void LoadModelFromPrimitive(GeometricPrimitiveType primitiveType, float height, float width, float depth, float diameter)
        {
            GeometricPrimitive primitive;

            switch (primitiveType)
            {
            case GeometricPrimitiveType.Box:
                primitive = new CubePrimitive(this.parentEntity.Game.GraphicsDevice, height, width, depth);
                break;

            case GeometricPrimitiveType.Sphere:
                primitive = new SpherePrimitive(this.parentEntity.Game.GraphicsDevice, diameter, 16);
                break;

            case GeometricPrimitiveType.Cylinder:
                primitive = new CylinderPrimitive(this.parentEntity.Game.GraphicsDevice, height, diameter, 16);
                break;

            case GeometricPrimitiveType.Cone:
                primitive = new ConePrimitive(this.parentEntity.Game.GraphicsDevice, height, diameter, 16);
                break;

            case GeometricPrimitiveType.Torus:
                primitive = new TorusPrimitive(this.parentEntity.Game.GraphicsDevice, diameter, 0.3333f, 16);
                break;

            case GeometricPrimitiveType.Teapot:
                primitive = new TeapotPrimitive(this.parentEntity.Game.GraphicsDevice, diameter, 8);
                break;

            default:
                throw new Exception("LoadPrimitive does not handle this type of GeometricPrimitive. Was a new primitive type made and not handled here?");
            }

            if (null != primitive)
            {
                model = new StaticModel(primitive, this.parentEntity.Game.GraphicsDevice);
            }
        }
Пример #10
0
        /// <inheritdoc />
        protected override void LoadContent()
        {
            // We load the city meshes into a model
            Model = Game.Content.Load <Model>(ContentFolder3D + "scene/city");

            // We get the mesh texture. All mesh parts use the same texture so we are fine
            var texture = ((BasicEffect)Model.Meshes.FirstOrDefault()?.MeshParts.FirstOrDefault()?.Effect)?.Texture;

            // We load the effect in the .fx file
            Effect = Game.Content.Load <Effect>(ContentFolderEffects + "BlinnPhong");

            // We assign the effect to each one of the models
            foreach (var modelMesh in Model.Meshes)
            {
                foreach (var meshPart in modelMesh.MeshParts)
                {
                    meshPart.Effect = Effect;
                }
            }

            // Set the texture. This won't change on this effect so we can assign it here
            Effect.Parameters["baseTexture"].SetValue(texture);

            // Set uniforms
            Effect.Parameters["ambientColor"].SetValue(new Vector3(0.25f, 0.0f, 0.0f));
            Effect.Parameters["diffuseColor"].SetValue(new Vector3(0.1f, 0.1f, 0.6f));
            Effect.Parameters["specularColor"].SetValue(new Vector3(1f, 1f, 1f));

            Effect.Parameters["KAmbient"].SetValue(0.1f);
            Effect.Parameters["KDiffuse"].SetValue(1.0f);
            Effect.Parameters["KSpecular"].SetValue(0.8f);
            Effect.Parameters["shininess"].SetValue(16.0f);

            lightBox = new CubePrimitive(GraphicsDevice, 25, Color.Blue);

            base.LoadContent();
        }
Пример #11
0
        /// <inheritdoc />
        protected override void LoadContent()
        {
            // We load the city meshes into a model
            Model = Game.Content.Load <Model>(ContentFolder3D + "scene/city");

            // Load the shadowmap effect
            Effect = Game.Content.Load <Effect>(ContentFolderEffects + "ShadowMap");

            BasicEffect = (BasicEffect)Model.Meshes.FirstOrDefault()?.Effects.FirstOrDefault();

            // Load the debug texture effect to visualize the shadow map
            DebugTextureEffect = Game.Content.Load <Effect>(ContentFolderEffects + "DebugTexture");
            // Assign the near and far plane distances of the light camera to debug depth
            DebugTextureEffect.Parameters["nearPlaneDistance"].SetValue(LightCameraNearPlaneDistance);
            DebugTextureEffect.Parameters["farPlaneDistance"].SetValue(LightCameraFarPlaneDistance);
            DebugTextureEffect.CurrentTechnique = DebugTextureEffect.Techniques["DebugDepth"];

            // Transform the quad to be in a smaller part of the screen
            QuadShadowsWorld = Matrix.CreateScale(0.2f) * Matrix.CreateTranslation(new Vector3(-0.75f, -0.75f, 0f));

            // Create a full screen quad to post-process
            FullScreenQuad = new FullScreenQuad(GraphicsDevice);

            // Create a shadow map. It stores depth from the light position
            ShadowMapRenderTarget = new RenderTarget2D(GraphicsDevice, ShadowmapSize, ShadowmapSize, false,
                                                       SurfaceFormat.Single, DepthFormat.Depth24, 0, RenderTargetUsage.PlatformContents);

            LightBox = new CubePrimitive(GraphicsDevice, 5, Color.White);

            SpriteFont = Game.Content.Load <SpriteFont>(ContentFolderSpriteFonts + "Arial");

            GraphicsDevice.BlendState = BlendState.Opaque;


            base.LoadContent();
        }
Пример #12
0
 public SceneView()
 {
     InitializeComponent();
     _output = IoC.Get <IOutput>();
     _cube   = new CubePrimitive();
 }
Пример #13
0
 /// <inheritdoc />
 public override void Initialize()
 {
     Box = new CubePrimitive(GraphicsDevice);
     base.Initialize();
 }
Пример #14
0
 protected override void LoadContent()
 {
     // Initialize our render cube
     renderCube = new CubePrimitive(graphics.GraphicsDevice);
 }
Пример #15
0
    public static void CreatePrimitives(GameObject gameObject, ref Dictionary <Material, List <Primitive> > primitives)
    {
        if (primitives == null)
        {
            primitives = new Dictionary <Material, List <Primitive> >();
        }
        MeshRenderer meshRenderer = gameObject.GetComponent <MeshRenderer>();
        Primitive    primitive    = null;

        if (!meshRenderer || !meshRenderer.sharedMaterial)
        {
            return;
        }
        if (primitive == null)
        {
            BoxCollider boxCollider = gameObject.GetComponent <BoxCollider>();
            if (boxCollider)
            {
                Vector3 scale = new Vector3(boxCollider.size.x * boxCollider.transform.lossyScale.x, boxCollider.size.y * boxCollider.transform.lossyScale.y, boxCollider.size.z * boxCollider.transform.lossyScale.z);
                if ((scale.x < 0.02f && scale.y >= 0.02f && scale.z >= 0.02f) ||
                    (scale.y < 0.02f && scale.z >= 0.02f && scale.x >= 0.02f) ||
                    (scale.z < 0.02f && scale.x >= 0.02f && scale.y >= 0.02f))
                {
                    primitive = new QuadPrimitive(boxCollider);
                }
                else
                {
                    primitive = new CubePrimitive(boxCollider);
                }
            }
        }
        if (primitive == null)
        {
            SphereCollider sphereCollider = gameObject.GetComponent <SphereCollider>();
            if (sphereCollider)
            {
                primitive = new SpherePrimitive(sphereCollider);
            }
        }
        if (primitive == null)
        {
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            if (meshFilter && meshFilter.sharedMesh)
            {
                int[]     triangles    = meshFilter.sharedMesh.triangles;
                Vector3[] vertices     = meshFilter.sharedMesh.vertices;
                Vector3[] normals      = meshFilter.sharedMesh.normals;
                Matrix4x4 localToWorld = meshFilter.transform.localToWorldMatrix;

                for (int i = 0; i < triangles.Length; i += 3)
                {
                    Vector3 vertex0 = localToWorld.MultiplyPoint(vertices[triangles[i]]);
                    Vector3 vertex1 = localToWorld.MultiplyPoint(vertices[triangles[i + 1]]);
                    Vector3 vertex2 = localToWorld.MultiplyPoint(vertices[triangles[i + 2]]);
                    Vector3 normal0 = localToWorld.MultiplyVector(normals[triangles[i]]);
                    Vector3 normal1 = localToWorld.MultiplyVector(normals[triangles[i + 1]]);
                    Vector3 normal2 = localToWorld.MultiplyVector(normals[triangles[i + 2]]);

                    Primitive trianglePrimitive = new TrianglePrimitive(vertex0, vertex1, vertex2, normal0, normal1, normal2);
                    if (primitives.ContainsKey(meshRenderer.sharedMaterial) == false)
                    {
                        primitives.Add(meshRenderer.sharedMaterial, new List <Primitive>());
                    }
                    primitives[meshRenderer.sharedMaterial].Add(trianglePrimitive);
                }
            }
        }
        else
        {
            if (primitives.ContainsKey(meshRenderer.sharedMaterial) == false)
            {
                primitives.Add(meshRenderer.sharedMaterial, new List <Primitive>());
            }
            primitives[meshRenderer.sharedMaterial].Add(primitive);
        }
    }
 private void InitializeLightBox()
 {
     LightBox = new CubePrimitive(GraphicsDevice, 10, Color.White);
     LightBox.Effect.LightingEnabled = false;
 }
Пример #17
0
        protected override void LoadContent()
        {
            Simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(),
                                           new PoseIntegratorCallbacks(new NumericVector3(0, -10, 0)), new PositionFirstTimestepper());

            SphereHandles      = new List <BodyHandle>();
            ActiveBoxesWorld   = new List <Matrix>();
            InactiveBoxesWorld = new List <Matrix>();
            SpheresWorld       = new List <Matrix>();
            Random             = new Random();
            BoxHandles         = new List <BodyHandle>(800);
            Radii = new List <float>();

            var boxShape = new Box(1, 1, 1);

            boxShape.ComputeInertia(1, out var boxInertia);
            var       boxIndex     = Simulation.Shapes.Add(boxShape);
            const int pyramidCount = 40;

            for (var pyramidIndex = 0; pyramidIndex < pyramidCount; ++pyramidIndex)
            {
                const int rowCount = 20;
                for (var rowIndex = 0; rowIndex < rowCount; ++rowIndex)
                {
                    var columnCount = rowCount - rowIndex;
                    for (var columnIndex = 0; columnIndex < columnCount; ++columnIndex)
                    {
                        var bh = Simulation.Bodies.Add(BodyDescription.CreateDynamic(
                                                           new NumericVector3((-columnCount * 0.5f + columnIndex) * boxShape.Width,
                                                                              (rowIndex + 0.5f) * boxShape.Height,
                                                                              (pyramidIndex - pyramidCount * 0.5f) * (boxShape.Length + 4)),
                                                           boxInertia,
                                                           new CollidableDescription(boxIndex, 0.1f),
                                                           new BodyActivityDescription(0.01f)));
                        BoxHandles.Add(bh);
                    }
                }
            }

            //Prevent the boxes from falling into the void.
            Simulation.Statics.Add(new StaticDescription(new NumericVector3(0, -0.5f, 0),
                                                         new CollidableDescription(Simulation.Shapes.Add(new Box(2500, 1, 2500)), 0.1f)));

            cubePrimitive = new CubePrimitive(GraphicsDevice, 1f, Color.White);

            spherePrimitive = new SpherePrimitive(GraphicsDevice);

            var count = BoxHandles.Count;

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            for (var index = 0; index < count; index++)
            {
                var bodyHandle    = BoxHandles[index];
                var bodyReference = Simulation.Bodies.GetBodyReference(bodyHandle);
                var position      = bodyReference.Pose.Position;
                var quaternion    = bodyReference.Pose.Orientation;
                var world         =
                    Matrix.CreateFromQuaternion(new Quaternion(quaternion.X, quaternion.Y, quaternion.Z,
                                                               quaternion.W)) * Matrix.CreateTranslation(new Vector3(position.X, position.Y, position.Z));

                cubePrimitive.Draw(world, Camera.View, Camera.Projection);
            }

            base.LoadContent();
        }