I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?
I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.
This is how you go about making a Cube in GDI+
C# 3D Drawing with GDI+ Euler Rotation
http://www.vcskicks.com/3d-graphics-improved.html
C# 3D-Drawing Cube with Shading
http://www.vcskicks.com/3d_gdiplus_drawing.html
Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.
Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.
You might try using WPF and the 3D Tools source code released by the WPF team.
3DTools
Assuming you are using WPF for your GUI:
Make an animated PNG of the cube using a graphics program.
Use the APNG WPF Control to insert the image into your GUI.
This will yield a small assembly size and transparent background if needed.
You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.
Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.
After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.
Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.
http://msdn.microsoft.com/en-us/library/aa970268.aspx
Related
I currently have a WinForms C# application. I have a .txt file with GPS coordinates of some points (borders of buildings, roads etc.), and using Graphics.FillPolygon method in System.Drawing I am drawing these on a Panel. However, I got an idea that for what I am trying to do (it basically is a 2D game), a Unity 2D project would be more suitable and easy to use (mainly because of easier view handling using the cameras). However, I don't know how to do this drawing in it. I just need to somehow get these coordinates drawn in Unity, but I don't know how to do it.
Note: I already have some minor expirience with 3D in Unity, but I am a total newbie to 2D.
Thanks
There is no GDI/canvas implementation built into Unity. Drawing these in rastered 2D would be quite hard in Unity (basically putpixel level, or finding some third party library).
You have an alternative, though - you can draw these shapes in 3D, ignoring the third dimension. You have a few methods for this:
Line renderers - this one will be the easiest, but forget about anything else than just drawing the outline, no fill etc.
Make your own mesh - This will let you use the geometry with your scene. It's an retained mode API (you init your geometry once)
Use the GL namespace - This will be only rendered on the screen, no interaction with the scene. It's an immidiate mode API (draw everything on every frame)
I need to visualize constructive geometry in 3d using C#. And for that I want choose a library. Ideally, that library should be able to provide the following:
Rendering arbitrary polygons in 3d. Wireframe representation.
Orhtographic projection
Camera control. I need to be able to zoom-in/out, set center of rotation to turn camera around it.
Pick my polygons, edges, vertices with a mouse.
Draw text on top of vertices, edges and polygons.
Efficency isn't the priority, so it can be resonably slow if it can do these things right out of the box or provide a good high level service for it.
I tried to look at XNA. But as far as I understood it doesn't support visualization of polygons directly.
XNA does support visualization of polygons directly by providing access to the underlying Direct3D 9 GraphicsDevice object. You can also dynamically create a mesh and draw it in a managed way, however that will be slower.
See:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.xna.framework.graphics.graphicsdevice.drawprimitives.aspx
and related methods.
There's several DirectX wrappers in c#. I would avoid Managed DirectX since it's deprecated, and you have only access to direct3d9.
The two most common libraries for DirectX are:
SlimDX
SharpDX
Both work pretty well, and support latest DirectX feature set (SlimDX up to 11, SharpDX supports windows 8 and 11.1).
They both support what you need to do, it of course implies a bit of coding on your side.
I'm planning to draw these shapes in WPF. It's for an educational software.
What idea's do you have in how to implement these cubes and views?
I was planning at the beginning starting using canvas and draw, but I guess it will be become eternal. So I supposed if exists some library to help me drawing them?
The ability to draw 3D shapes (such as cubes) and render them from different angles is built right into WPF. From the look of your cubes, you're going to want an orthographic camera, rather than a perspective camera, because the lines composing your cubes are parallel.
You might also find the Petzold.Media3D library helpful, because it has objects like cubes built in (you don't have to write your own algorithms to build them).
Finally, you might this primer helpful in getting started with WPF 3D.
Once you have some idea of how to use 3D, it will just be a matter of putting cubes in your scene at the proper locations and positioning the cameras properly for viewing the cubes. You will probably want to keep reusing the same four camera positions: one for the "3D view", and one each for the top, side, and front views.
This should be a lot less work than trying to draw the cubes using 2D.
I need to show points array in three-dimensional coordinate system. Which component or library should I use for it(Winforms/WPF)?
Here is a tutorial for Direct3D in C#, it's for winforms: http://msdn.microsoft.com/en-us/library/ms920768.aspx. I don't think it matters whether you use winforms or wpf, the trick is to get your videocard do you drawing and that bypasses wpf.
image http://prod.triplesign.com/map.jpg
How can I produce a similar output in C# window forms in the easiest way?
Is there a good library for this purpose?
I just needs to be pointed in the direction of which graphic library is best for this.
You should just roll your own in a 3d graphics library. You could use directx. If using WPF it is built-in, you can lookup viewport3d. http://msdn.microsoft.com/en-us/magazine/cc163449.aspx
In graphics programming what you are building is a very simple version of a heightmap. I think building your own would give your greater flexibility in the long run.
So a best library doesn't exist. There are plenty of them and some are just for different purposes. Here a small list of possibilities:
Tao: Make anything yourself with OpenGL
OpenTK: The successor of the Tao framework
Dundas: One of the best but quite expensive (lacks in real time performance)
Nevron: Quite good, but much cheaper (also has problems with real time data)
National Instruments: Expensive, not the best looking ones, but damn good in real time data.
... Probably someone else made some other experiences.
Checkout Microsoft Chart Controls library.
Here's how I'd implement this using OpenGL.
First up, you will need a wrapper to import the OpenGL API into C#. A bit of Googling led me to this:
CsGL - OpenGL .NET
There a few example programs available to demonstrate how the OpenGL interface works. Play around with them to get an idea of how the system works.
To implement the 3D map:
Create an array of vectors (that's not the std::vector/List type but x,y,z triplets) where x and y are along the horizontal plane and z is the up amount.
Set the Z compare to less-than-or-equal (so the overlaid line segments are visible).
Create a list of quads where the vertices of the quads are taken from the array in (1)
Calculate the colour of the quad. Use a dot-product of the quad's normal and a light source direction to get a value to shade value, i.e. normal.light of 1 is black and -1 is white.
Create a list of line segments, again from the array in (1).
Calculate the screen position of the various projected axes points.
Set up your camera and world->view transform (use the example programs to get an idea of how to do this).
Render the quads and lines, OpenGL will do the transformation from world co-ordinates (the list in (1)) to screen space. Draw the labels, you might not want to do this using OpenGL as the labels shouldn't scale with distance from camera, otherwise they could get too small to read.
Since the above is quite a lot of stuff, there isn't really the space (and time on my part) to post working code (but someone else might add something if you're lucky). You could break the task down and ask questions on the parts you don't quite understand.
Have you tried this... gigasoft data visualization tools (Its not free)
And you can checkout the online wireframe demo here