views:

4703

answers:

7

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.

A: 

You might try using WPF and the 3D Tools source code released by the WPF team.

3DTools

Scott
This link is not working for me
tomaszs
+3  A: 

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.

Vilx-
Sorry but this tutorial does not help much.
tomaszs
A: 

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

sindre j
Thank you, but I would like to do this in pure WinForms
tomaszs
+5  A: 

This is how you go about making a Cube in GDI+

C# 3D Drawing with GDI+ Euler Rotation

http://vckicks.110mb.com/3d-graphics-improved.html

C# 3D-Drawing Cube with Shading

http://vckicks.110mb.com/3d_gdiplus_drawing.html

Hath
Thank you. It's great!
tomaszs
A: 

Assuming you are using WPF for your GUI:

  1. Make an animated PNG of the cube using a graphics program.
  2. Use the APNG WPF Control to insert the image into your GUI.

This will yield a small assembly size and transparent background if needed.

NoizWaves
A: 

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.

A: 

I'm trying to use WPF integrated 3D classes to rotate a WPF 3D model. I'm stuck. I'm looking for the 10 or so C# instructions which in pure 3D WPF would rotate a model based on Euler's angles as input (yaw, pitch, roll):

RotateTransform3D myTransform = TheSolution (yaw, pitch, bank)

I'd then use myTransform to rotation myModel (myModel.Transform = myTransform). Any suggestion to write the method TheSolution using only WPF 3D classes? Though I have browsed a lot of pages that claim they do provide this solution, actually they don't.

I know this is not Euler's but Tait-Bryan's. Everybody names this representation "Euler's", so do I, to not start a confusion, even if the difference is quite significant. Euler's representation uses rotations around fixed axes while Tait-Bryan uses rotation for pitch and roll around previously rotated axes. Maybe Tait-Bryan is a member of the Euler's family, maybe it's a pure stranger, the relationship between these conventions is not clear to me.

It would be easy if it were actually Euler constuction, a matter of combining in the proper order three rotations around known axes. But with yaw, pitch, roll, the pitch rotation has to be executed around the cross product of Y (assuming a standard left handed system) and old Z now rotated by yaw in the XZ plan, same additional complexity for roll. I do hope we can use the 3D framework of WPF to directly obtain a Transformation3D object (or group) from Euler's triplet, without computing manually rotation axes.

By the way, I don't want to use a library to convert Euler's angles to a matrix or a quaternion, like it is done here: http://www.monroedavis.com/robert/code/cs/ (this library is handy, I used it, but I hope we have a more direct way with WPF 3D)

Rolling