public Primitive(GraphicsDevice graphics, float radius, GeometricPrimitive geometry) { primitive = geometry; Scale = new Vector3(radius); Up = Vector3.Up; Forward = Vector3.Forward; }
protected override async Task LoadContent() { await base.LoadContent(); var view = Matrix.LookAtRH(new Vector3(2, 2, 2), new Vector3(0, 0, 0), Vector3.UnitY); var projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.ViewWidth / GraphicsDevice.BackBuffer.ViewHeight, 0.1f, 100.0f); worldViewProjection = Matrix.Multiply(view, projection); geometry = GeometricPrimitive.Cube.New(GraphicsDevice); simpleEffect = new Effect(GraphicsDevice, SpriteEffect.Bytecode); parameterCollection = new ParameterCollection(); parameterCollectionGroup = new EffectParameterCollectionGroup(GraphicsDevice, simpleEffect, new[] { parameterCollection }); parameterCollection.Set(TexturingKeys.Texture0, UVTexture); // TODO DisposeBy is not working with device reset offlineTarget0 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); offlineTarget1 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); offlineTarget2 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); depthBuffer = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this); width = GraphicsDevice.BackBuffer.ViewWidth; height = GraphicsDevice.BackBuffer.ViewHeight; }
protected override void LoadContent() { // Instantiate a SpriteBatch spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); // Loads a sprite font // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project arial16Font = Content.Load <SpriteFont>("Arial16"); // Creates a basic effect basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)); basicEffect.DiffuseColor = Color.OrangeRed.ToVector4(); basicEffect.PreferPerPixelLighting = true; basicEffect.EnableDefaultLighting(); // Creates torus primitive sphere = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice, 1.75f)); pixelTexture = Texture2D.New(GraphicsDevice, 1, 1, GraphicsDevice.BackBuffer.Format); pixelTexture.SetData <Color>(new Color[] { Color.Green }); occlusionQuery = new OcclusionQuery(GraphicsDevice); offscreenBuffer = RenderTarget2D.New(GraphicsDevice, 128, 128, GraphicsDevice.BackBuffer.Format); base.LoadContent(); }
public virtual GeometricPrimitive BuildTerrainGeometricPrimitive(GraphicsDevice graphicsDevice, float size, float maxHeight, Vector2 uv) { var data = BuildTerrainData(size, maxHeight, uv); var terrainGeometry = new GeometricPrimitive(graphicsDevice, data); return(terrainGeometry); }
public ConvexHullColliderShape(IReadOnlyList <Vector3> points, IEnumerable <uint> indices) { Type = ColliderShapeTypes.ConvexHull; Is2D = false; InternalShape = new BulletSharp.ConvexHullShape(points); if (!PhysicsEngine.Singleton.CreateDebugPrimitives) { return; } var verts = new VertexPositionNormalTexture[points.Count]; for (var i = 0; i < points.Count; i++) { verts[i].Position = points[i]; verts[i].TextureCoordinate = Vector2.Zero; verts[i].Normal = Vector3.Zero; } var intIndices = indices.Select(x => (int)x).ToArray(); var meshData = new GeometricMeshData <VertexPositionNormalTexture>(verts, intIndices, false); DebugPrimitive = new GeometricPrimitive(PhysicsEngine.Singleton.DebugGraphicsDevice, meshData); DebugPrimitiveScaling = Matrix.Scaling(new Vector3(1, 1, 1) * 1.01f); }
private void LoadGeometry() { // constants for easy manipulation const float f = 0.5f; const float c = 0.75f; var vertices = new[] { new Vertex(new Vector3(f, f, f), new Vector3(c, 0f, 0f)), new Vertex(new Vector3(f, f, -f), new Vector3(0, c, 0f)), new Vertex(new Vector3(f, -f, f), new Vector3(0f, 0f, c)), new Vertex(new Vector3(f, -f, -f), new Vector3(c, c, 0f)), new Vertex(new Vector3(-f, f, f), new Vector3(c, 0f, c)), new Vertex(new Vector3(-f, f, -f), new Vector3(0f, c, c)), new Vertex(new Vector3(-f, -f, f), new Vector3(0f, 0f, 0f)), new Vertex(new Vector3(-f, -f, -f), new Vector3(c, c, c)) }; var indices = new short[] { 0,2,1, 1,2,3, 1,3,7, 7,5,1, 5,7,6, 5,6,4, 0,6,2, 0,4,6, 0,1,5, 0,5,4, 3,7,6, 3,6,2 }; _cubeGeometry = ToDisposeContent(new GeometricPrimitive<Vertex>(GraphicsDevice, vertices, indices, false)); }
public Component3D(GameCore game, GeometricPrimitive primitiveModel, Color color) : base(game, null) { this.primitiveModel = primitiveModel; this.mygame = game; this.color = color; }
protected override async Task LoadContent() { await base.LoadContent(); var view = Matrix.LookAtRH(new Vector3(2,2,2), new Vector3(0, 0, 0), Vector3.UnitY); var projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.ViewWidth / GraphicsDevice.BackBuffer.ViewHeight, 0.1f, 100.0f); worldViewProjection = Matrix.Multiply(view, projection); geometry = GeometricPrimitive.Cube.New(GraphicsDevice); simpleEffect = new Effect(GraphicsDevice, SpriteEffect.Bytecode); parameterCollection = new ParameterCollection(); parameterCollectionGroup = new EffectParameterCollectionGroup(GraphicsDevice, simpleEffect, new[] { parameterCollection }); parameterCollection.Set(TexturingKeys.Texture0, UVTexture); // TODO DisposeBy is not working with device reset offlineTarget0 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); offlineTarget1 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); offlineTarget2 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); depthBuffer = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this); width = GraphicsDevice.BackBuffer.ViewWidth; height = GraphicsDevice.BackBuffer.ViewHeight; }
/// <summary> /// Makes primitive into specified type using default values. /// </summary> /// <param name="type">Type of primitive to use.</param> public void MakePrimitive(GeometricPrimitiveType type) { // Create default primitive switch (type) { case GeometricPrimitiveType.Cube: primitive = new CubePrimitive(core.GraphicsDevice); break; case GeometricPrimitiveType.Cylinder: primitive = new CylinderPrimitive(core.GraphicsDevice); break; case GeometricPrimitiveType.Sphere: primitive = new SpherePrimitive(core.GraphicsDevice); break; case GeometricPrimitiveType.Teapot: primitive = new TeapotPrimitive(core.GraphicsDevice); break; case GeometricPrimitiveType.Torus: primitive = new TorusPrimitive(core.GraphicsDevice); break; default: return; } this.type = type; this.BoundingSphere = primitive.BoundingSphere; }
/// <summary> /// Makes primitive a cube. /// </summary> /// <param name="size">Size of cube.</param> public void MakeCube(float size) { // Create primitive primitive = new CubePrimitive(core.GraphicsDevice, size); type = GeometricPrimitiveType.Cube; BoundingSphere = primitive.BoundingSphere; }
public void InitializeRendering(WadToolClass tool, DeviceManager deviceManager) { if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) { return; } Configuration = tool.Configuration; base.InitializeRendering(deviceManager.Device, tool.Configuration.RenderingItem_Antialias); _tool = tool; // Legacy rendering { _device = deviceManager.___LegacyDevice; _wadRenderer = new WadRenderer(deviceManager.___LegacyDevice); new BasicEffect(_device); // This effect is used for editor special meshes like sinks, cameras, light meshes, etc _rasterizerWireframe = RasterizerState.New(_device, new SharpDX.Direct3D11.RasterizerStateDescription { CullMode = SharpDX.Direct3D11.CullMode.None, DepthBias = 0, DepthBiasClamp = 0, FillMode = SharpDX.Direct3D11.FillMode.Wireframe, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = true, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }); _plane = GeometricPrimitive.GridPlane.New(_device, 8, 4); } }
public BaseGizmo(GraphicsDevice device, Effect effect) { _effect = effect; _device = device; // Create the gizmo geometry _rotationHelperGeometry = Buffer.Vertex.New <SolidVertex>(device, _rotationTrianglesCount * 3 + 2); _cylinder = GeometricPrimitive.Cylinder.New(_device, 1.0f, 1.0f, _lineRadiusTesselation); _cube = GeometricPrimitive.Cube.New(_device, 1.0f); _cone = GeometricPrimitive.Cone.New(_device, 1.0f, 1.3f, 16); // Create the rasterizer state for wireframe drawing var renderStateDesc = new SharpDX.Direct3D11.RasterizerStateDescription { CullMode = SharpDX.Direct3D11.CullMode.None, DepthBias = 0, DepthBiasClamp = 0, FillMode = SharpDX.Direct3D11.FillMode.Wireframe, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = true, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }; _rasterizerWireframe = RasterizerState.New(_device, renderStateDesc); }
/// <summary> /// Makes primitive a torus. /// </summary> /// <param name="diameter">Diameter of torus.</param> /// <param name="radius">Radius of torus.</param> /// <param name="tessellation">Tessellation of torus.</param> public void MakeTorus(float radius, float thickness, int tessellation) { // Create primitive primitive = new TorusPrimitive(core.GraphicsDevice, radius * 2, thickness, tessellation); type = GeometricPrimitiveType.Torus; BoundingSphere = primitive.BoundingSphere; }
/// <summary> /// Makes primitive a teaport. /// </summary> /// <param name="size">Size of teapot.</param> /// <param name="tessellation">Tessellation of teapot.</param> public void MakeTeapot(float size, int tessellation) { // Create primitive primitive = new TeapotPrimitive(core.GraphicsDevice, size, tessellation); type = GeometricPrimitiveType.Teapot; BoundingSphere = primitive.BoundingSphere; }
/// <summary> /// Makes primitive a sphere. /// </summary> /// <param name="radius">Radius of sphere.</param> /// <param name="tessellation">Tessellation of sphere.</param> public void MakeSphere(float radius, int tessellation) { // Create primitive primitive = new SpherePrimitive(core.GraphicsDevice, radius * 2, tessellation); type = GeometricPrimitiveType.Cube; BoundingSphere = primitive.BoundingSphere; }
public StaticModel(GeometricPrimitive primitive, GraphicsDevice device) { // The vertex buffer that a GeometricPrimitive uses is not suitable for this engine, so we will // convert it to one that is. Vector2[] texCoords = { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0), new Vector2(1, 1) }; int texCoordIndex = 0; List <VertexStaticModel> newVerts = new List <VertexStaticModel>(); foreach (VertexPositionNormal vertex in primitive.Vertices) { VertexStaticModel newVert; ConvertVertexPositionNormalToStaticModelVertex(vertex, texCoords[texCoordIndex], out newVert); newVerts.Add(newVert); ++texCoordIndex; if (texCoordIndex > (texCoords.Length - 1)) { texCoordIndex = 0; } } vertexBuffer = new VertexBuffer(device, typeof(VertexStaticModel), newVerts.Count, BufferUsage.None); vertexBuffer.SetData(newVerts.ToArray()); indexBuffer = primitive.IndexBuffer; numPrimitives = primitive.Indices.Count / 3; numVertices = primitive.Vertices.Count; }
/// <summary> /// Makes primitive a cylinder. /// </summary> /// <param name="height">Height of cylinder.</param> /// <param name="diameter">Diameter of cylinder.</param> /// <param name="tessellation">Tessellation of cylinder.</param> public void MakeCylinder(float height, float diameter, int tessellation) { // Create primitive primitive = new CylinderPrimitive(core.GraphicsDevice, height, diameter, tessellation); type = GeometricPrimitiveType.Cylinder; BoundingSphere = primitive.BoundingSphere; }
protected override async Task LoadContent() { await base.LoadContent(); var view = Matrix.LookAtRH(new Vector3(2, 2, 2), new Vector3(0, 0, 0), Vector3.UnitY); var projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f); worldViewProjection = Matrix.Multiply(view, projection); geometry = GeometricPrimitive.Cube.New(GraphicsDevice); simpleEffect = new SimpleEffect(GraphicsDevice) { Texture = UVTexture }; // TODO DisposeBy is not working with device reset offlineTarget0 = Texture2D.New(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this).ToRenderTarget().DisposeBy(this); offlineTarget1 = Texture2D.New(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this).ToRenderTarget().DisposeBy(this); offlineTarget2 = Texture2D.New(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this).ToRenderTarget().DisposeBy(this); depthBuffer = Texture2D.New(GraphicsDevice, 512, 512, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this).ToDepthStencilBuffer(false).DisposeBy(this); width = GraphicsDevice.BackBuffer.Width; height = GraphicsDevice.BackBuffer.Height; }
public float LoadContent_BaslerCamera() { //config.streamController.Camera.StreamGrabber.ImageGrabbed += StreamGrabber_ImageGrabbed; cameraBasicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)); // size of imaginary camera picture plane [mm] float sizeX = 2040f; // [mm] - but pixels as it is auxilary - only depends on ratio float sizeY = 2046f; // [mm] cameraSurface = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, sizeX, sizeY)); // Load the texture //cameraTexture = Content.Load<Texture2D>("speaker"); lock (cameraTextureList_locker) { cameraTexture = Content.Load <Texture2D>("cameraDefault_2015-04-20_09-34-31"); //cameraTexture = Texture2D.New(GraphicsDevice, width, height, PixelFormat.B8G8R8A8.UNorm); cameraBasicEffect.Texture = cameraTexture; cameraBasicEffect.TextureEnabled = true; cameraBasicEffect.LightingEnabled = false; } return(sizeX); }
public Component3D(GameCore game, GeometricPrimitive primitiveModel, Texture2D texture) : base(game, texture) { this.primitiveModel = primitiveModel; this.mygame = game; this.texture = texture; }
private void LoadGeometry() { // constants for easy manipulation const float f = 0.5f; const float c = 0.75f; var vertices = new[] { new Vertex(new Vector3(f, f, f), new Vector3(c, 0f, 0f)), new Vertex(new Vector3(f, f, -f), new Vector3(0, c, 0f)), new Vertex(new Vector3(f, -f, f), new Vector3(0f, 0f, c)), new Vertex(new Vector3(f, -f, -f), new Vector3(c, c, 0f)), new Vertex(new Vector3(-f, f, f), new Vector3(c, 0f, c)), new Vertex(new Vector3(-f, f, -f), new Vector3(0f, c, c)), new Vertex(new Vector3(-f, -f, f), new Vector3(0f, 0f, 0f)), new Vertex(new Vector3(-f, -f, -f), new Vector3(c, c, c)) }; var indices = new short[] { 0, 2, 1, 1, 2, 3, 1, 3, 7, 7, 5, 1, 5, 7, 6, 5, 6, 4, 0, 6, 2, 0, 4, 6, 0, 1, 5, 0, 5, 4, 3, 7, 6, 3, 6, 2 }; _cubeGeometry = ToDisposeContent(new GeometricPrimitive <Vertex>(GraphicsDevice, vertices, indices, false)); }
protected override void LoadContent() { //initialize the array of cubes Random random = new Random(); for (int i = 0; i < cubes.Length; ++i) { cubes[i] = new Cube(random); } for (int i = 0; i < lights.Length; ++i) { lights[i] = new Light(random); } //Instantiate a SpriteBatch spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); // Loads a sprite font // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project arial16Font = Content.Load <SpriteFont>("Arial16"); skyEffect = Content.Load <Effect>("skybox"); skyEffect.Parameters["SkyBoxTexture"].SetResource(Content.Load <TextureCube>("SkyBoxTexture")); basicEffect = new BasicEffect(GraphicsDevice); cubeEffect = Content.Load <Effect>("point"); //textures[0] = Content.Load<Texture2D>("gorko"); //textures[1] = Content.Load<Texture2D>("hunsberger"); //textures[2] = Content.Load<Texture2D>("kontostathis"); //textures[3] = Content.Load<Texture2D>("mcdevitt"); //textures[4] = Content.Load<Texture2D>("mustardo"); //textures[5] = Content.Load<Texture2D>("young"); vertices = new VertexPositionNormalTexture[4] { new VertexPositionNormalTexture(new Vector3(0, 1, 0), Vector3.UnitZ, new Vector2(0, 0)), new VertexPositionNormalTexture(new Vector3(1, 1, 0), Vector3.UnitZ, new Vector2(1, 0)), new VertexPositionNormalTexture(new Vector3(0, 0, 0), Vector3.UnitZ, new Vector2(0, 1)), new VertexPositionNormalTexture(new Vector3(1, 0, 0), Vector3.UnitZ, new Vector2(1, 1)) }; vertexBuffer = Buffer.New <VertexPositionNormalTexture>(GraphicsDevice, 4, BufferFlags.VertexBuffer); vertexBuffer.SetData <VertexPositionNormalTexture>(vertices); inputLayout = VertexInputLayout.New <VertexPositionNormalTexture>(0); short[] indices = new short[4] { 0, 1, 2, 3 }; indexBuffer = Buffer.New <short>(GraphicsDevice, 4, BufferFlags.IndexBuffer); indexBuffer.SetData <short>(indices); primitive = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)); Cube.LoadCube(GraphicsDevice, primitive); ballPrimitive = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice)); base.LoadContent(); }
void LoadCube() { m_cube = ToDispose(GeometricPrimitive.Cube.New(this.GraphicsDevice, 1, toLeftHanded: true)); m_cubeTexture = this.Content.Load<Texture2D>("logo_large"); m_cubeTransform = Matrix.Identity; }
void LoadCube() { m_cube = ToDispose(GeometricPrimitive.Cube.New(this.GraphicsDevice, 1, toLeftHanded: true)); m_cubeTexture = this.Content.Load <Texture2D>("logo_large"); m_cubeTransform = Matrix.Identity; }
private void UpdateInput() { _keyboardState = _keyboard.GetState(); _oldMouseState = _mouseState; _mouseState = _mouse.GetState(); if (KeyPressed(Keys.Escape)) { Exit(); } if (KeyPressed(Keys.Space)) { _currentSkyBox = (_currentSkyBox + 1) % _skyBoxMaps.Count; _skyBoxMap = _skyBoxMaps[_currentSkyBox]; } if (KeyPressed(Keys.B)) { _skyBox.Dispose(); _skyBox = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)); } if (KeyPressed(Keys.D)) { _skyBox.Dispose(); _skyBox = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice)); } if (KeyDown(Keys.Home)) { _angleX = _angleY = 0.0f; } if (KeyDown(Keys.Up)) { _angleX -= 0.01f; } if (KeyDown(Keys.Down)) { _angleX += 0.01f; } if (KeyDown(Keys.Left)) { _angleY -= 0.01f; } if (KeyDown(Keys.Right)) { _angleY += 0.01f; } if (_mouseState.LeftButton.Down && _oldMouseState.LeftButton.Down) { _angleY += _mouseState.X - _oldMouseState.X; _angleX += _mouseState.Y - _oldMouseState.Y; } UpdateView(); }
/// <summary> /// Draw the geometry applying a rotation and translation. /// </summary> /// <param name="geometry">The geometry to draw.</param> /// <param name="transform">The transform to apply.</param> private void DrawGeometry(GeometricPrimitive geometry, Matrix transform) { var effect = geometry.Effect; effect.World = transform; effect.View = Camera.View; effect.Projection = Camera.Projection; geometry.Draw(effect); }
/// <summary> /// 立方体の GeometricPrimitive を生成します。 /// </summary> /// <param name="size"></param> /// <returns>生成された立方体の GeometricPrimitive。</returns> GeometricPrimitive CreateCubePrimitive(float size) { var cube = new Cube { Size = size }; var source = new VertexSource <VertexPositionNormal, ushort>(); cube.Make(source); return(GeometricPrimitive.Create(graphicsDevice, source)); }
/// <summary> /// Draw the geometry applying a rotation and translation. /// </summary> /// <param name="geometry">The geometry to draw.</param> /// <param name="position">The position of the geometry.</param> /// <param name="yaw">Vertical axis (yaw).</param> /// <param name="pitch">Transverse axis (pitch).</param> /// <param name="roll">Longitudinal axis (roll).</param> private void DrawGeometry(GeometricPrimitive geometry, Vector3 position, float yaw, float pitch, float roll) { var effect = geometry.Effect; effect.World = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll) * Matrix.CreateTranslation(position); effect.View = Camera.View; effect.Projection = Camera.Projection; geometry.Draw(effect); }
public void InitializeRendering(AnimationEditor editor, DeviceManager deviceManager, WadMoveable skin) { if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) { return; } base.InitializeRendering(deviceManager.Device, Configuration.RenderingItem_Antialias); ResetCamera(); _editor = editor; _wadRenderer = new WadRenderer(deviceManager.___LegacyDevice); _model = _wadRenderer.GetMoveable(editor.Moveable); Configuration = _editor.Tool.Configuration; if (skin != null) { _skinModel = _wadRenderer.GetMoveable(skin); } // Actual "InitializeRendering" _fontTexture = Device.CreateTextureAllocator(new RenderingTextureAllocator.Description { Size = new VectorInt3(512, 512, 2) }); _fontDefault = Device.CreateFont(new RenderingFont.Description { FontName = "Segoe UI", FontSize = 24, FontIsBold = true, TextureAllocator = _fontTexture }); // Legacy rendering { _device = deviceManager.___LegacyDevice; _deviceManager = deviceManager; new BasicEffect(_device); // This effect is used for editor special meshes like sinks, cameras, light meshes, etc SharpDX.Direct3D11.RasterizerStateDescription renderStateDesc = new SharpDX.Direct3D11.RasterizerStateDescription { CullMode = SharpDX.Direct3D11.CullMode.None, DepthBias = 0, DepthBiasClamp = 0, FillMode = SharpDX.Direct3D11.FillMode.Wireframe, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = true, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }; _rasterizerWireframe = RasterizerState.New(deviceManager.___LegacyDevice, renderStateDesc); _gizmo = new GizmoAnimationEditor(editor, _device, _deviceManager.___LegacyEffects["Solid"], this); _plane = GeometricPrimitive.GridPlane.New(_device, 8, 4); } }
public CubeMesh(GraphicsDevice graphicsDevice, float size) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); if (size < 0) throw new ArgumentOutOfRangeException("size"); this.graphicsDevice = graphicsDevice; Size = size; Effect = new BasicEffect(graphicsDevice); //Effect.EnableDefaultLighting(); mesh = CreateCubePrimitive(size); }
//============================= public void Load(GeometricPrimitive mesh, Effect effect) { this.mesh = mesh; this.effect = effect; // vCount = mesh.VertexCount; iCount = mesh.IndexCount / 3; // bindings = new VertexBufferBinding[2]; bindings[0] = new VertexBufferBinding(mesh.VertexBuffer, 0, 0); }
/// <summary> /// Loads cube geometry and anything related. /// </summary> private void LoadCube() { // build the cube geometry and mark it disposable when content will be uploaded _cube = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)); // load the texture using game's content manager _cubeTexture = Content.Load <Texture2D>("logo_large"); // the cube's transform will be updated in runtime _cubeTransform = Matrix.Identity; }
/// <summary> /// Loads plane geometry and anything related. /// </summary> private void LoadPlane() { // build the plane geometry of the specified size and subdivision segments _plane = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 50f, 50f)); // load the texture using game's content manager _planeTexture = Content.Load <Texture2D>("GeneticaMortarlessBlocks"); // rotate the plane horizontally and move it down a bit _planeTransform = Matrix.RotationX(-MathUtil.PiOverTwo) * Matrix.Translation(0f, -5f, 0f); }
private void LoadArrows(GeometricPrimitive primitive) { List <ushort> indices = primitive.Indices; List <VertexPositionColorNormal> vertices = primitive.Vertices; int indexCount = indices.Count; // Load arrows Vector3 vertexOne; Vector3 vertexTwo; Vector3 vertexThree; Vector3 normal; for (int index = 0; index < indexCount; index += 3) { vertexOne = vertices[indices[index]].Position; vertexTwo = vertices[indices[index + 1]].Position; vertexThree = vertices[indices[index + 2]].Position; Vector3 average = (vertexOne + vertexTwo + vertexThree) * BaseScaleScalar / 3f; normal = Vector3.Cross(vertexTwo - vertexOne, vertexThree - vertexOne); normal.Normalize(); bool isForward = Vector3.Dot(normal, Vector3.UnitZ) >= 0f; bool inside = InsideCylinder(vertexOne); inside |= InsideCylinder(vertexTwo); inside |= InsideCylinder(vertexThree); if (!inside || isForward) { // Center outer arrow AddArrow(average, normal, Color.Magenta); // Center inner arrow AddArrow(average, -normal, Color.Yellow); // Left outer arrow Vector3 displacedAverage = average - Displacement * Vector3.UnitX; AddArrow(displacedAverage, normal, Color.Magenta); // Left inner arrow AddArrow(displacedAverage, -normal, Color.Yellow); // Right outer arrow displacedAverage = average + Displacement * Vector3.UnitX; AddArrow(displacedAverage, normal, Color.Magenta); // Right outer arrow AddArrow(displacedAverage, -normal, Color.Yellow); } } }
protected override void LoadContent() { ergonWave = Content.Load<SoundEffect>("ergon.adpcm"); ergonWaveInstance = ergonWave.Create(); ergonWaveInstance.IsLooped = true; waveBank = Content.Load<WaveBank>("TestBank"); //waveBankXbox = Content.Load<WaveBank>("TestBankXbox.xwb"); //does not play correctly // SpriteFont supports the following font file format: // - DirectX Toolkit MakeSpriteFont or SharpDX Toolkit tkfont // - BMFont from Angelcode http://www.angelcode.com/products/bmfont/ arial16BMFont = Content.Load<SpriteFont>("Arial16"); // Instantiate a SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice); primitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice); primitiveBatchEffect = new BasicEffect(GraphicsDevice); primitiveBatchEffect.VertexColorEnabled = true; // setup tests tiles = new List<SoundTile>(); Rectangle border = new Rectangle(); border.X = SoundTile.Padding.X; border.Y = SoundTile.Padding.Y; AddTile(ref border, "Click to play looped SoundEffectInstance of " + ergonWave.Name, PlayMusic, PauseMusic); AddTile(ref border, "Click to play 'PewPew' wave bank entry", () => waveBank.Play("PewPew")); AddTile(ref border, "Click to play 'PewPew' wave bank entry with random pitch and pan", () => waveBank.Play("PewPew", 1, random.NextFloat(-1, 1), random.NextFloat(-1, 1))); AddTile(ref border, "Click to play 'PewPew' with 3D audio", PlayAudio3D, StopAudio3D); // setup 3D geometryEffect = ToDisposeContent(new BasicEffect(GraphicsDevice) { View = Matrix.LookAtRH(new Vector3(0, 10, 20), new Vector3(0, 0, 0), Vector3.UnitY), Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f), World = Matrix.Identity }); cube = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)); // Load the texture listenerTexture = Content.Load<Texture2D>("listen"); emitterTexture = Content.Load<Texture2D>("speaker"); geometryEffect.TextureEnabled = true; base.LoadContent(); }
/// <summary> /// Loads cube geometry and anything related. /// </summary> private void LoadCube() { // build the cube geometry and mark it disposable when content will be uploaded _cube = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)); // load the texture using game's content manager _cubeTexture = Content.Load<Texture2D>("logo_large"); // the cube's transform will be updated in runtime _cubeTransform = Matrix.Identity; }
/// <summary> /// Loads plane geometry and anything related. /// </summary> private void LoadPlane() { // build the plane geometry of the specified size and subdivision segments _plane = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 50f, 50f)); // load the texture using game's content manager _planeTexture = Content.Load<Texture2D>("GeneticaMortarlessBlocks"); // rotate the plane horizontally and move it down a bit _planeTransform = Matrix.RotationX(-MathUtil.PiOverTwo) * Matrix.Translation(0f, -5f, 0f); }
private void LoadCube() { m_cube = ToDispose(GeometricPrimitive.Cube.New(GraphicsDevice, Chunk.CHUNK_SIZE, toLeftHanded: true)); m_cubeTexture = this.Content.Load<Texture2D>("RectangleOutline"); }
protected override void LoadContent() { base.LoadContent(); _basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)); _basicEffect.EnableDefaultLighting(); _basicEffect.SpecularPower = 64; var desc = _basicEffect.Sampler.Description; desc.Filter = Filter.ComparisonMinMagMipPoint; desc.MaximumAnisotropy = 8; desc.AddressU = TextureAddressMode.Wrap; desc.AddressV = TextureAddressMode.Wrap; desc.AddressW = TextureAddressMode.Wrap; desc.MaximumLod = float.MaxValue; desc.MinimumLod = 0; _basicEffect.Sampler = SamplerState.New(GraphicsDevice, desc); _manTexture = Content.Load<Texture2D>("textures/mobs/man"); _man = ToDisposeContent(MeshGenerator.CreateTextureMesh(_manTexture)); _manTransform = Matrix.Scaling(.6f, 1.6f, .05f)*Matrix.Translation(-.4f, 1.4f, 1); _bookshelfTexture = Content.Load<Texture2D>("textures/walls/decorations/bookshelf"); _bookshelf = ToDisposeContent(MeshGenerator.CreateTextureMesh(_bookshelfTexture)); _bookshelfTransform = Matrix.Scaling(1.54f, 1f, .5f) * Matrix.Translation(-3.9f, 1f, -5f); _windowTexture = Content.Load<Texture2D>("textures/walls/decorations/window outside"); _window = ToDisposeContent(MeshGenerator.CreateTextureMesh(_windowTexture)); _windowTransform = Matrix.Scaling(1.5f, 1.5f, .03f) * Matrix.Translation(3f, 1.75f, -5f); _curtainTexture = Content.Load<Texture2D>("textures/walls/decorations/red curtain open"); _curtain = ToDisposeContent(MeshGenerator.CreateTextureMesh(_curtainTexture)); _curtainTransform = Matrix.Scaling(1.5f, 1.5f, .1f) * Matrix.Translation(3.1f, 1.75f, -5f); _curtain2Texture = Content.Load<Texture2D>("textures/walls/decorations/red curtain open inverse"); _curtain2 = ToDisposeContent(MeshGenerator.CreateTextureMesh(_curtain2Texture)); _curtain2Transform = Matrix.Scaling(1.5f, 1.5f, .1f) * Matrix.Translation(2.9f, 1.75f, -5f); _borderTexture = Content.Load<Texture2D>("textures/floors/moss border"); _border = ToDisposeContent(MeshGenerator.CreateTextureMesh(_borderTexture)); _borderTransform = Matrix.RotationX(-MathUtil.PiOverTwo)*Matrix.Scaling(10, 0.1f, 10) * Matrix.Translation(-5, 0, -5); _plane = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 10, 10, 1, new Vector2(2))); _planeTexture = Content.Load<Texture2D>("textures/floors/floorboards 1 large dds"); _planeTransform = Matrix.RotationX(-MathUtil.PiOverTwo)*Matrix.Translation(0, 0, 0); _carpetTexture = Content.Load<Texture2D>("textures/floors/carpets/carpet brown"); _carpet = ToDisposeContent(MeshGenerator.CreateTextureMesh(_carpetTexture)); _carpetTransform = Matrix.Scaling(4f, 2f, .05f) * Matrix.RotationX(-MathUtil.PiOverTwo) * Matrix.Translation(-2, 0f, 0); _pumpkinTexture = Content.Load<Texture2D>("textures/misc/pumkin"); _pumpkin = ToDisposeContent(MeshGenerator.CreateTextureMesh(_pumpkinTexture)); _pumpkinTransform = Matrix.Scaling(1f, 1f, .5f) * Matrix.Translation(3, 0.9f, -2); _wall = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 10, 2, 1, new Vector2(4, 1f))); _wallTexture = Content.Load<Texture2D>("textures/walls/wall testure warped"); _wallTransform1 = Matrix.Translation(0, 1, -5); _wallTransform2 = _wallTransform1*Matrix.RotationY(-MathUtil.PiOverTwo); _wallTransform3 = _wallTransform2*Matrix.RotationY(-MathUtil.PiOverTwo); _wallTransform4 = _wallTransform3*Matrix.RotationY(-MathUtil.PiOverTwo); _doorTexture = Content.Load<Texture2D>("textures/walls/doors/door"); _door = ToDisposeContent(MeshGenerator.CreateTextureMesh(_doorTexture)); _doorTransform1 = Matrix.Scaling(1f, 1.8f, .1f)*Matrix.Translation(-0.46f, 1.8f, -5)* Matrix.RotationY(-MathUtil.PiOverTwo); _doorTransform2 = _doorTransform1*Matrix.RotationY(-MathUtil.PiOverTwo); _doorTransform3 = _doorTransform2 * Matrix.RotationY(-MathUtil.PiOverTwo); _doorTransform4 = _doorTransform3 * Matrix.RotationY(-MathUtil.PiOverTwo); var blendStateDesc = new BlendStateDescription { AlphaToCoverageEnable = true, IndependentBlendEnable = false }; blendStateDesc.RenderTarget[0].IsBlendEnabled = true; blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; blendStateDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendStateDesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; blendStateDesc.RenderTarget[0].BlendOperation = BlendOperation.Add; blendStateDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.DestinationAlpha; blendStateDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; blendStateDesc.RenderTarget[0].SourceBlend = BlendOption.One; _blend = BlendState.New(GraphicsDevice, blendStateDesc); }
public void Initialize() { cube = GeometricPrimitive.Cube.New(graphicsDevice); var cubeBounds = new OrientedBoundingBox(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f)); cubeMesh = new RenderMesh { BoundingBox = cubeBounds, IndexBuffer = cube.IndexBuffer, IsIndex32Bits = cube.IsIndex32Bits, InputLayout = VertexInputLayout.New<VertexPositionNormalTexture>(0), ModelTransform = Matrix.Identity, VertexBuffer = cube.VertexBuffer }; basicEffect = new BasicEffect(graphicsDevice); basicEffect.EnableDefaultLighting(); // enable default lightning, useful for quick prototyping var debugEffectCompilerResult = new EffectCompiler().CompileFromFile("shaders/debug_solid.hlsl", EffectCompilerFlags.Debug); debugEffect = new Effect(graphicsDevice, debugEffectCompilerResult.EffectData, graphicsDevice.DefaultEffectPool); debugBatch = new PrimitiveBatch<VertexPositionColor>(graphicsDevice); }
protected override void LoadContent() { // Instantiate a SpriteBatch spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); // Loads the balls texture (32 textures (32x32) stored vertically => 32 x 1024 ). // The [Balls.dds] file is defined with the build action [ToolkitTexture] in the project ballsTexture = Content.Load<Texture2D>("Balls"); // Loads a sprite font // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project arial16Font = Content.Load<SpriteFont>("Arial16"); // Load a 3D model // The [Ship.fbx] file is defined with the build action [ToolkitModel] in the project model = Content.Load<Model>("Ship"); // Enable default lighting on model. BasicEffect.EnableDefaultLighting(model, true); // Creates a basic effect basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)); basicEffect.PreferPerPixelLighting = true; basicEffect.EnableDefaultLighting(); // Creates torus primitive primitive = ToDisposeContent(GeometricPrimitive.Torus.New(GraphicsDevice)); base.LoadContent(); }
protected override void LoadContent() { // Instantiate a SpriteBatch spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice)); // Loads a sprite font // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project arial16Font = Content.Load<SpriteFont>("Arial16"); // Creates a basic effect basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)); basicEffect.DiffuseColor = Color.OrangeRed.ToVector4(); basicEffect.PreferPerPixelLighting = true; basicEffect.EnableDefaultLighting(); // Creates torus primitive sphere = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice, 1.75f)); pixelTexture = Texture2D.New(GraphicsDevice, 1, 1, GraphicsDevice.BackBuffer.Format); pixelTexture.SetData<Color>(new Color[] { Color.Green }); occlusionQuery = new OcclusionQuery(GraphicsDevice); offscreenBuffer = RenderTarget2D.New(GraphicsDevice, 128, 128, GraphicsDevice.BackBuffer.Format); base.LoadContent(); }
void LoadContent() { m_basicEffect = ToDispose(new BasicEffect(this.GraphicsDevice)); m_basicEffect.VertexColorEnabled = true; m_basicEffect.LightingEnabled = false; m_plane = ToDispose(GeometricPrimitive.Plane.New(this.GraphicsDevice, 2, 2, 1, true)); m_buffer = ToDispose(Buffer<VertexPositionColor>.Vertex.New(this.GraphicsDevice, m_vertices)); m_layout = VertexInputLayout.FromBuffer(0, m_buffer); }