private static void AssertVerticesEqual(ObjVector4 expected, Vertex3DNoTex2 actual, float threshold, bool switchZ = false) { var sign = switchZ ? -1 : 1; actual.X.Should().BeApproximately(expected.X, threshold); actual.Y.Should().BeApproximately(expected.Y, threshold); actual.Z.Should().BeApproximately(sign * expected.Z, threshold); }
public void New3() { var v = new ObjVector4(2.0f, 3.0f, 4.0f); Assert.Equal(2.0f, v.X); Assert.Equal(3.0f, v.Y); Assert.Equal(4.0f, v.Z); Assert.Equal(1.0f, v.W); }
public void New() { var v = new ObjVector4 { X = 2.0f, Y = 3.0f, Z = 4.0f, W = 5.0f }; Assert.Equal(2.0f, v.X); Assert.Equal(3.0f, v.Y); Assert.Equal(4.0f, v.Z); Assert.Equal(5.0f, v.W); }
private static void AssertVerticesEqual(ObjVector4 expected, Vertex3DNoTex2 actual, double threshold = FloatThresholdComparer.Threshold) { Assert.Equal(expected.X, actual.X, new FloatThresholdComparer(threshold)); Assert.Equal(expected.Y, actual.Y, new FloatThresholdComparer(threshold)); Assert.Equal(expected.Z, actual.Z, new FloatThresholdComparer(threshold)); }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; var d3dDevice = this.deviceResources.D3DDevice; this.tessellator.CreateDeviceDependentResources(this.deviceResources); XMFloat4[] initData; // Parse the .obj file. Both triangle faces and quad faces are supported. // Only v and f tags are processed, other tags like vn, vt etc are ignored. { var initFile = ObjFile.FromFile("BaseMesh.obj"); var data = new List <XMFloat4>(); var v = new List <XMFloat4>(); for (int i = 0; i < initFile.Vertices.Count; i++) { ObjVector4 objPosition = initFile.Vertices[i].Position; XMFloat4 pos = new XMFloat4( objPosition.X, objPosition.Y, objPosition.Z, 1.0f); v.Add(pos); } foreach (ObjFace face in initFile.Faces) { if (face.Vertices.Count < 3) { continue; } data.Add(v[face.Vertices[0].Vertex - 1]); data.Add(v[face.Vertices[1].Vertex - 1]); data.Add(v[face.Vertices[2].Vertex - 1]); if (face.Vertices.Count >= 4) { data.Add(v[face.Vertices[2].Vertex - 1]); data.Add(v[face.Vertices[3].Vertex - 1]); data.Add(v[face.Vertices[0].Vertex - 1]); } } initData = data.ToArray(); } this.g_pBaseVB = d3dDevice.CreateBuffer( D3D11BufferDesc.From(initData, D3D11BindOptions.ShaderResource | D3D11BindOptions.VertexBuffer), initData, 0, 0); this.tessellator.SetBaseMesh((uint)initData.Length, this.g_pBaseVB); this.g_pVS = d3dDevice.CreateVertexShader(File.ReadAllBytes("RenderVertexShader.cso"), null); { byte[] shaderBytecode = File.ReadAllBytes("RenderBaseVertexShader.cso"); this.g_pBaseVS = d3dDevice.CreateVertexShader(shaderBytecode, null); D3D11InputElementDesc[] layoutDesc = new[] { new D3D11InputElementDesc( "POSITION", 0, DxgiFormat.R32G32B32A32Float, 0, 0, D3D11InputClassification.PerVertexData, 0) }; this.g_pBaseVBLayout = d3dDevice.CreateInputLayout(layoutDesc, shaderBytecode); } this.g_pPS = d3dDevice.CreatePixelShader(File.ReadAllBytes("RenderPixelShader.cso"), null); // Setup constant buffer this.g_pVSCB = d3dDevice.CreateBuffer(new D3D11BufferDesc { BindOptions = D3D11BindOptions.ConstantBuffer, ByteWidth = 4 * 16 }); // Rasterizer state this.g_pRasWireFrame = d3dDevice.CreateRasterizerState(new D3D11RasterizerDesc { CullMode = D3D11CullMode.None, FillMode = D3D11FillMode.WireFrame }); }
private static void AssertVerticesEqual(ObjVector4 expected, Vertex3DNoTex2 actual, float threshold) { actual.X.Should().BeApproximately(expected.X, threshold); actual.Y.Should().BeApproximately(expected.Y, threshold); actual.Z.Should().BeApproximately(expected.Z, threshold); }
public static Vector3 ToVector3(this ObjVector4 objVector4) { return(new Vector3(objVector4.X, objVector4.Y, objVector4.Z)); }