Click here to Skip to main content
15,921,371 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to give access to ServiceAccount.LocalSystem to Registry (HKCU) Pin
Dave Kreskowiak12-Mar-12 10:42
mveDave Kreskowiak12-Mar-12 10:42 
GeneralRe: How to give access to ServiceAccount.LocalSystem to Registry (HKCU) Pin
jherome13-Mar-12 9:14
jherome13-Mar-12 9:14 
GeneralRe: How to give access to ServiceAccount.LocalSystem to Registry (HKCU) Pin
Dave Kreskowiak13-Mar-12 9:38
mveDave Kreskowiak13-Mar-12 9:38 
QuestionC# Cube Texture with Image Pin
Kaner TUNCEL12-Mar-12 7:48
Kaner TUNCEL12-Mar-12 7:48 
AnswerRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 9:16
mvePete O'Hanlon12-Mar-12 9:16 
GeneralRe: C# Cube Texture with Image Pin
djdanlib12-Mar-12 11:12
djdanlib12-Mar-12 11:12 
GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 11:20
mvePete O'Hanlon12-Mar-12 11:20 
GeneralRe: C# Cube Texture with Image Pin
Kaner TUNCEL12-Mar-12 11:38
Kaner TUNCEL12-Mar-12 11:38 
Thanks, but i must do it codebehind. I am really wondering how they actually do it in server side, the image I give in question is produced on runtime. I found a library and trying to create a cube with it. And I will try to use my uploaded image as image pattern here is my code to generate a cube:

C#
public static void CreateWPFImage(string fileName)
{
    Thread t = new Thread(() => CreateImage(fileName));
    t.SetApartmentState(ApartmentState.STA);
    t.Start();
    t.Join();
}

private static void CreateImage(string fileName)
{
    var viewport = CreateViewport();
    viewport.Children.Add(GetModel());
    var size = new Size();
    size.Width = 600;
    size.Height = 400;
    viewport.Measure(size);

    var rect = new Rect();
    rect.Width = 600;
    rect.Height = 400;
    viewport.Arrange(rect);

    SaveViewport(viewport, fileName);
}

private static Viewport3D CreateViewport()
{
    Viewport3D viewport = new Viewport3D();
    viewport.ClipToBounds = true;

    var camera = new PerspectiveCamera(new Point3D(500, 200, 500),
                                       new Vector3D(-0.01, -0.01, -0.1),
                                       new Vector3D(-0.1,1,-0.3), 500);
    viewport.Camera = camera;

    var light1 = new DirectionalLight(Colors.White, new Vector3D(-3, 1, -1));
    var model1 = new ModelVisual3D();
    model1.Content = light1;
    viewport.Children.Add(model1);

    var light2 = new DirectionalLight(Colors.White,
                                      new Vector3D(-3, -5, -1));
    var model2 = new ModelVisual3D();
    model2.Content = light2;
    viewport.Children.Add(model2);

    var light3 = new PointLight(Colors.White,
                                new Point3D(-5, 2.5, 150));
    var model3 = new ModelVisual3D();
    model3.Content = light3;
    viewport.Children.Add(model3);

    return viewport;
}

private static void SaveViewport(Viewport3D viewport3D, string fileName)
{
    FileStream fs = new FileStream(fileName, FileMode.Create);
    RenderTargetBitmap rtb = new RenderTargetBitmap(600, 400, 96d, 96d, PixelFormats.Default);
    rtb.Render(viewport3D);
    var encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(rtb));
    encoder.Save(fs);
    fs.Close();
}

public static ModelVisual3D GetModel()
{
    Model3DGroup cube = new Model3DGroup();

    Point3D p0 = new Point3D(-250, -250, 0);
    Point3D p1 = new Point3D(400, -400, 0);
    Point3D p2 = new Point3D(400, -400, 100);
    Point3D p3 = new Point3D(-250, -250, 100);
    Point3D p4 = new Point3D(-250, 250, 0);
    Point3D p5 = new Point3D(400, 400, 0);
    Point3D p6 = new Point3D(400, 400, 100);
    Point3D p7 = new Point3D(-250, 250, 100);

    //front side triangles
    cube.Children.Add(CreateBrushModel(p3, p2, p6, Colors.Gold));
    cube.Children.Add(CreateTriangleModel(p3, p6, p7, Colors.Gold));
    //right side triangles
    cube.Children.Add(CreateTriangleModel(p2, p1, p5, Colors.Green));
    cube.Children.Add(CreateTriangleModel(p2, p5, p6, Colors.Green));
    //back side triangles
    cube.Children.Add(CreateTriangleModel(p1, p0, p4, Colors.Green));
    cube.Children.Add(CreateTriangleModel(p1, p4, p5, Colors.Green));
    //left side triangles
    cube.Children.Add(CreateTriangleModel(p0, p3, p7, Colors.Green));
    cube.Children.Add(CreateTriangleModel(p0, p7, p4, Colors.Green));
    //top side triangles
    cube.Children.Add(CreateTriangleModel(p7, p6, p5, Colors.Green));
    cube.Children.Add(CreateTriangleModel(p7, p5, p4, Colors.Green));
    //bottom side triangles
    cube.Children.Add(CreateTriangleModel(p2, p3, p0, Colors.Green));
    cube.Children.Add(CreateTriangleModel(p2, p0, p1, Colors.Green));

    ModelVisual3D model = new ModelVisual3D();
    model.Content = cube;

    return model;
}

private static Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2, Color color)
{
    MeshGeometry3D mesh = new MeshGeometry3D();
    mesh.Positions.Add(p0);
    mesh.Positions.Add(p1);
    mesh.Positions.Add(p2);
    mesh.TriangleIndices.Add(0);
    mesh.TriangleIndices.Add(1);
    mesh.TriangleIndices.Add(2);
    Vector3D normal = CalculateNormal(p0, p1, p2);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    Material material = new DiffuseMaterial(new SolidColorBrush(color));
    GeometryModel3D model = new GeometryModel3D(mesh, material);
    //ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(@"http://www.kanertuncel.com/Test.png")));
    //GeometryModel3D model = new GeometryModel3D(mesh, new DiffuseMaterial(imgBrush));
    Model3DGroup group = new Model3DGroup();
    group.Children.Add(model);
    return group;
}

private static Model3DGroup CreateBrushModel(Point3D p0, Point3D p1, Point3D p2, Color color)
{
    MeshGeometry3D mesh = new MeshGeometry3D();
    mesh.Positions.Add(p0);
    mesh.Positions.Add(p1);
    mesh.Positions.Add(p2);
    mesh.TriangleIndices.Add(0);
    mesh.TriangleIndices.Add(1);
    mesh.TriangleIndices.Add(2);
    Vector3D normal = CalculateNormal(p0, p1, p2);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    //Material material = new DiffuseMaterial(new SolidColorBrush(color));
    //GeometryModel3D model = new GeometryModel3D(mesh, material);
    ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(@"http://www.kanertuncel.com/Test.png")));
    GeometryModel3D model = new GeometryModel3D(mesh, new DiffuseMaterial(imgBrush));
    Model3DGroup group = new Model3DGroup();
    group.Children.Add(model);
    return group;
}


private static Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
{
    Vector3D v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
    Vector3D v1 = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
    return Vector3D.CrossProduct(v0, v1);
}

GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 11:49
mvePete O'Hanlon12-Mar-12 11:49 
GeneralRe: C# Cube Texture with Image Pin
Kaner TUNCEL12-Mar-12 12:01
Kaner TUNCEL12-Mar-12 12:01 
GeneralRe: C# Cube Texture with Image Pin
Luc Pattyn12-Mar-12 11:38
sitebuilderLuc Pattyn12-Mar-12 11:38 
GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 11:47
mvePete O'Hanlon12-Mar-12 11:47 
GeneralRe: C# Cube Texture with Image Pin
Luc Pattyn12-Mar-12 11:50
sitebuilderLuc Pattyn12-Mar-12 11:50 
GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 11:51
mvePete O'Hanlon12-Mar-12 11:51 
GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 12:09
mvePete O'Hanlon12-Mar-12 12:09 
GeneralRe: C# Cube Texture with Image Pin
Luc Pattyn12-Mar-12 12:26
sitebuilderLuc Pattyn12-Mar-12 12:26 
GeneralRe: C# Cube Texture with Image Pin
Pete O'Hanlon12-Mar-12 12:27
mvePete O'Hanlon12-Mar-12 12:27 
GeneralRe: C# Cube Texture with Image Pin
Luc Pattyn12-Mar-12 13:08
sitebuilderLuc Pattyn12-Mar-12 13:08 
GeneralRe: C# Cube Texture with Image Pin
DaveyM6913-Mar-12 0:02
professionalDaveyM6913-Mar-12 0:02 
GeneralRe: C# Cube Texture with Image Pin
Luc Pattyn13-Mar-12 2:39
sitebuilderLuc Pattyn13-Mar-12 2:39 
GeneralRe: C# Cube Texture with Image Pin
Kaner TUNCEL12-Mar-12 11:44
Kaner TUNCEL12-Mar-12 11:44 
QuestionWhat is the correct way to do an ini file these days..... Pin
glennPattonWork312-Mar-12 7:15
professionalglennPattonWork312-Mar-12 7:15 
AnswerRe: What is the correct way to do an ini file these days..... Pin
PIEBALDconsult12-Mar-12 7:28
mvePIEBALDconsult12-Mar-12 7:28 
AnswerRe: What is the correct way to do an ini file these days..... Pin
OriginalGriff12-Mar-12 7:31
mveOriginalGriff12-Mar-12 7:31 
GeneralRe: What is the correct way to do an ini file these days..... Pin
jschell12-Mar-12 8:53
jschell12-Mar-12 8:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.