public static MetaBoundingImageGraphic Transform(MetaBoundingImageGraphic bounding, Matrix transformation) { return new MetaBoundingImageGraphic { Graphic = (Content.ImageGraphic)bounding.Graphic.Clone(), Transformation = bounding.Transformation * transformation }; }
public static MetaBoundingImageGraphic Transform(MetaBoundingImageGraphic bounding, Matrix transformation) { return(new MetaBoundingImageGraphic { Graphic = (Content.ImageGraphic)bounding.Graphic.Clone(), Transformation = bounding.Transformation * transformation }); }
public void Draw(Matrix world, MetaBoundingImageGraphic bounding, Color color) { var model = View.Content.Peek <Content.Model9>(bounding.Graphic); View.Device9.SetTexture(0, model.Texture); View.Device9.SetTransform(TransformState.World, world); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.FillMode, FillMode.Solid); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.AlphaBlendEnable, true); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.SourceBlend, Blend.BlendFactor); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.DestinationBlend, Blend.InverseSourceColor); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.BlendFactor, 0xFFFFFF); model.Mesh.Draw(View.Device9); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.FillMode, FillMode.Wireframe); }
public static bool Intersect(Ray a, MetaBoundingImageGraphic b, out object intersection) { #if false var model = content.Peek<Content.Model9>(b.Graphic); var sd = model.Texture.GetLevelDescription(0); var plane = b.Graphic.GetPlane(new Vector2(sd.Width, sd.Height)); var mesh = Software.Meshes.Construct(plane); var texture = new Software.Texture<Software.Texel.A8R8G8B8>(model.Texture, 0); Matrix invTransformation = Matrix.Invert(Matrix.Scaling(1, 1, -1) * b.Transformation); var newRay = new Ray( Vector3.TransformCoordinate(a.Position, invTransformation), Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation))); Software.Triangle t; float d; Vector2 uv; //mesh.BuildKDTree(); bool hit = mesh.Intersect(newRay, false, out t, out d, out uv); intersection = null; if (!hit) return false; var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * d, b.Transformation); intersection = new Common.RayIntersection { Distance = (newPos - a.Position).Length() }; var v = texture.Sample(uv); Console.WriteLine(uv); return v.R > 0.5f; #endif var t = content.Peek<SlimDX.Direct3D9.Texture>(b.Graphic.Texture); var sd = t.GetLevelDescription(0); var plane = b.Graphic.GetPlane(new Vector2(sd.Width, sd.Height)); Matrix invTransformation = Matrix.Invert(Matrix.Scaling(1, 1, -1) * b.Transformation); var newRay = new Ray( Vector3.TransformCoordinate(a.Position, invTransformation), Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation))); float worldX = newRay.Position.X - plane.Position.X; float worldY = newRay.Position.Y - plane.Position.Y; float percX = worldX; float percY = worldY; float u = plane.UVMin.X + percX * (plane.UVMax.X - plane.UVMin.X); float v = plane.UVMin.Y + percY * (plane.UVMax.Y - plane.UVMin.Y); var texture = content.Peek<Software.Texture<Software.Texel.A8R8G8B8>>(new Content.TextureUnconcretizer { Texture = t }); //var texture = new Software.Texture<Software.Texel.A8R8G8B8>(t, 0); intersection = new Common.RayIntersection { Distance = Vector3.TransformCoordinate(plane.Position, b.Transformation).Z }; var va = texture.Sample(new Vector2(u, v)); return va.R > 0.5f; }
public static bool Intersect(Ray a, MetaBoundingImageGraphic b, out object intersection) { #if false var model = content.Peek <Content.Model9>(b.Graphic); var sd = model.Texture.GetLevelDescription(0); var plane = b.Graphic.GetPlane(new Vector2(sd.Width, sd.Height)); var mesh = Software.Meshes.Construct(plane); var texture = new Software.Texture <Software.Texel.A8R8G8B8>(model.Texture, 0); Matrix invTransformation = Matrix.Invert(Matrix.Scaling(1, 1, -1) * b.Transformation); var newRay = new Ray( Vector3.TransformCoordinate(a.Position, invTransformation), Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation))); Software.Triangle t; float d; Vector2 uv; //mesh.BuildKDTree(); bool hit = mesh.Intersect(newRay, false, out t, out d, out uv); intersection = null; if (!hit) { return(false); } var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * d, b.Transformation); intersection = new Common.RayIntersection { Distance = (newPos - a.Position).Length() }; var v = texture.Sample(uv); Console.WriteLine(uv); return(v.R > 0.5f); #endif var t = content.Peek <SlimDX.Direct3D9.Texture>(b.Graphic.Texture); var sd = t.GetLevelDescription(0); var plane = b.Graphic.GetPlane(new Vector2(sd.Width, sd.Height)); Matrix invTransformation = Matrix.Invert(Matrix.Scaling(1, 1, -1) * b.Transformation); var newRay = new Ray( Vector3.TransformCoordinate(a.Position, invTransformation), Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation))); float worldX = newRay.Position.X - plane.Position.X; float worldY = newRay.Position.Y - plane.Position.Y; float percX = worldX; float percY = worldY; float u = plane.UVMin.X + percX * (plane.UVMax.X - plane.UVMin.X); float v = plane.UVMin.Y + percY * (plane.UVMax.Y - plane.UVMin.Y); var texture = content.Peek <Software.Texture <Software.Texel.A8R8G8B8> >(new Content.TextureUnconcretizer { Texture = t }); //var texture = new Software.Texture<Software.Texel.A8R8G8B8>(t, 0); intersection = new Common.RayIntersection { Distance = Vector3.TransformCoordinate(plane.Position, b.Transformation).Z }; var va = texture.Sample(new Vector2(u, v)); return(va.R > 0.5f); }
public void Draw(Matrix world, MetaBoundingImageGraphic bounding, Color color) { var model = View.Content.Peek<Content.Model9>(bounding.Graphic); View.Device9.SetTexture(0, model.Texture); View.Device9.SetTransform(TransformState.World, world); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.FillMode, FillMode.Solid); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.AlphaBlendEnable, true); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.SourceBlend, Blend.BlendFactor); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.DestinationBlend, Blend.InverseSourceColor); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.BlendFactor, 0xFFFFFF); model.Mesh.Draw(View.Device9); View.Device9.SetRenderState(SlimDX.Direct3D9.RenderState.FillMode, FillMode.Wireframe); }