public CQuad Clone() { CQuad newQuad = new CQuad(); verts.CopyTo(newQuad.verts, 0); return(newQuad); }
public override void Load() { // load shader Engine.Global.Device3d.CreateEffect(new Device3dD3d11.CreateEffectCmd() { Name = "FxRendercraft_Terrain", SrcFileName = Engine.Global.FileSystem.GetResourcePath("Engine/Shaders/FxRendercraft_Terrain.fx") }); // create meshes for the lookup m_LookupMesh[0] = CQuad.CreateFromPlane(Vector3.UnitX, 0.5f, 0.5f); m_LookupMesh[1] = CQuad.CreateFromPlane(-Vector3.UnitX, 0.5f, 0.5f); m_LookupMesh[2] = CQuad.CreateFromPlane(Vector3.UnitY, 0.5f, 0.5f); m_LookupMesh[3] = CQuad.CreateFromPlane(-Vector3.UnitY, 0.5f, 0.5f); m_LookupMesh[4] = CQuad.CreateFromPlane(Vector3.UnitZ, 0.5f, 0.5f); m_LookupMesh[5] = CQuad.CreateFromPlane(-Vector3.UnitZ, 0.5f, 0.5f); }
public CQuad Clone() { CQuad newQuad = new CQuad(); verts.CopyTo(newQuad.verts, 0); return newQuad; }
public static CQuad CreateFromPlane(Vector3 normal, float dist, float size) { Vector3 u, v; if (normal == Vector3.UnitZ) { u = Vector3.UnitX; v = Vector3.UnitY; } else if (normal == -Vector3.UnitZ) { u = Vector3.UnitY; v = Vector3.UnitX; } else { u = Vector3.Cross(normal, Vector3.UnitZ); v = Vector3.Cross(normal, u); } Vector3 p0 = normal * dist; Vector3 fu = u * size; Vector3 fv = v * size; Vector3 p1 = p0 - fu + fv; Vector3 p2 = p0 - fu - fv; Vector3 p3 = p0 + fu - fv; Vector3 p4 = p0 + fu + fv; CQuad newQuad = new CQuad(); newQuad.verts[0] = new FatVertex() { Position = new Vector4(p1, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[1] = new FatVertex() { Position = new Vector4(p2, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[2] = new FatVertex() { Position = new Vector4(p3, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[3] = new FatVertex() { Position = new Vector4(p1, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[4] = new FatVertex() { Position = new Vector4(p3, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[5] = new FatVertex() { Position = new Vector4(p4, 1.0f), Normal = new Vector4(normal, 0.0f) }; return newQuad; }
public static CQuad CreateFromPlane(Vector3 normal, float dist, float size) { Vector3 u, v; if (normal == Vector3.UnitZ) { u = Vector3.UnitX; v = Vector3.UnitY; } else if (normal == -Vector3.UnitZ) { u = Vector3.UnitY; v = Vector3.UnitX; } else { u = Vector3.Cross(normal, Vector3.UnitZ); v = Vector3.Cross(normal, u); } Vector3 p0 = normal * dist; Vector3 fu = u * size; Vector3 fv = v * size; Vector3 p1 = p0 - fu + fv; Vector3 p2 = p0 - fu - fv; Vector3 p3 = p0 + fu - fv; Vector3 p4 = p0 + fu + fv; CQuad newQuad = new CQuad(); newQuad.verts[0] = new FatVertex() { Position = new Vector4(p1, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[1] = new FatVertex() { Position = new Vector4(p2, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[2] = new FatVertex() { Position = new Vector4(p3, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[3] = new FatVertex() { Position = new Vector4(p1, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[4] = new FatVertex() { Position = new Vector4(p3, 1.0f), Normal = new Vector4(normal, 0.0f) }; newQuad.verts[5] = new FatVertex() { Position = new Vector4(p4, 1.0f), Normal = new Vector4(normal, 0.0f) }; return(newQuad); }
public void Generate(CVolumeBuffer volume) { int quad_count = Primitive_Count(volume); int tri_count = quad_count * 2; int vert_count = tri_count * 3; // calculate total vertices we need List <FatVertex> verts = new List <FatVertex>(vert_count); int size = volume.Size; for (int z = 0; z < size; ++z) { for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { int value = volume.GetData(new Vector3(x, y, z)); if (value == 0) { if (volume.GetData_BoundarySafe(new Vector3(x + 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[1].Clone(); newQuad.Translate(new Vector3(x + 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x - 1, y, z)) > 0) { CQuad newQuad = m_LookupMesh[0].Clone(); newQuad.Translate(new Vector3(x - 1, y, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y + 1, z)) > 0) { CQuad newQuad = m_LookupMesh[3].Clone(); newQuad.Translate(new Vector3(x, y + 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y - 1, z)) > 0) { CQuad newQuad = m_LookupMesh[2].Clone(); newQuad.Translate(new Vector3(x, y - 1, z)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z + 1)) > 0) { CQuad newQuad = m_LookupMesh[5].Clone(); newQuad.Translate(new Vector3(x, y, z + 1)); verts.AddRange(newQuad.verts); } if (volume.GetData_BoundarySafe(new Vector3(x, y, z - 1)) > 0) { CQuad newQuad = m_LookupMesh[4].Clone(); newQuad.Translate(new Vector3(x, y, z - 1)); verts.AddRange(newQuad.verts); } } } } } var vb = Engine.Global.Device3d.CreateBuffer(new Device3dD3d11.SCreateBufferCmd() { Name = "VolumeDataVB", SizeInBytes = (int)vert_count * m_VertDesc.SizeInBytes, BufferBindFlags = BindFlags.VertexBuffer }); m_MeshDesc.VBBinding = new VertexBufferBinding(vb, m_VertDesc.SizeInBytes, 0); // update data buffer Engine.Global.Device3d.UpdateBufferData("VolumeDataVB", new DataStream(verts.ToArray(), false, false)); m_MeshDesc.VertexCount = vert_count; }