0

How do I generate basic 3D shapes (red and blue) that can be seen as 3D with cellophane 3D glasses, using C# in a desktop app? (Note that this question is not limited to any particular language. If I can get a head start in any language, then that's great. I can always learn from that and eventually know enough to attempt to implement this in my desired language.)

I've seen so many questions about this, but the answers seem very complicated and don't lead me to anywhere in the end. I can't even find any docs or articles about this.

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
uSeRnAmEhAhAhAhAhA
  • 2,527
  • 6
  • 39
  • 64
  • 1
    ... cellophane 3d glasses ... ???? What is this ? – Alex F Oct 14 '13 at 11:33
  • 1
    @Jasper I *think* what he means is those two-tone 'sunglasses' you used to get from the movie theater when 3D was a new thing. You know the ones that had 1 red lense and 1 blue lense? I think Giovani wants to create 2 shapes and layer them on top of each other so they look 3D.... No idea how to do that in just C# / Winforms though. – sab669 Oct 14 '13 at 21:06
  • @sab669 Exactly. You understand 100%. I am going to add some tags. This may not be possible in C#, but if I can work it in C++ or VB or another .NET language, I can work with that. Even non-.NET based languages will be a great starting point. – uSeRnAmEhAhAhAhAhA Oct 15 '13 at 05:07
  • Keyword: [Anaglyph 3D](http://en.wikipedia.org/wiki/Anaglyph_3D) – Markus Jarderot Oct 18 '13 at 05:17
  • @Giovani What sort of graphics do you want to display? Simple shapes, depth-mapped images or something else? – Markus Jarderot Oct 18 '13 at 05:34
  • @MarkusJarderot Thank you very much for the comments and the answer. I am now looking over your answer. I was just looking to start off with simple shapes like squares/cubes. – uSeRnAmEhAhAhAhAhA Oct 20 '13 at 04:30

1 Answers1

2

To generate Anaglyph 3D images, you first have to render the scene from two slightly different viewports, one for each eye. The further apart they are, the smaller the scene will look, and the higher the 3D-sense will be.

The easiest method would be to use some existing library to render the images. Using a "camera", position it slightly to the left (and right) of the center of view. Render two images, and get the pixels.

The second step is to combine the two images into an Anaglyph 3D image. One way to do this, is to combine the red channel from one image with the green and blue channels from the other.

(Pseduo-C#:)

Color Combine(Color left, Color right)
{
    return new Color(left.Red, right.Green, right.Blue);
}

Image Combine(Image left, Image right)
{
    Image result = new Image(left.Width, left.Height);
    for (int y = 0; y < left.Height; y++)
    for (int x = 0; x < left.Width; x++)
    {
        result.SetPixel(x, y, Combine(left.GetPixel(x, y), right.GetPixel(x, y)));
    }
}
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138