1

I'm working on a c# application that uses an ilpanel to show a 3d ILgroup of ILTriangles. I'm trying to set up three buttons each one of them should modify the ilplotcube orientation in order to show a x-y plane view, x-z plane view and y-z view.

On ILPlotcube creation I set up a default 3D (isometric) view using

pc.Rotation = Matrix4.Rotation(new Vector3(0.5299, 0.2195, 0.8192), 0.9363);

where pc is the reference to the ILPlotCube object. If I then use the mouse to rotate the view, what is that changes, the camera or the cube? I'm not able to find out how to obtain the "plane" view XY( or XZ, or YZ) from an arbitrary position of the ILPlotCube orientation. How should I set the ILPlotCube orientation matrix to achieve this result?

EDIT: To be more clear: if set the rotation matrix to the identity one it works only if before I haven't used the mouse to rotate the cube. If I use the mouse it seems that it creates a sort of clone cube with a rotation matrix equals to the identity one but it still visualizes a rotated view.

xanz
  • 221
  • 3
  • 10

1 Answers1

0

For rendering each panel/driver creates a synchronized copy of the scene. Mouse interaction manipulates the synchronized copy only. That copy should be used for setting the orientation of the plot cube manually.

private void button1_Click(object sender, EventArgs e) {
    //fetch a reference to the SYNCHRONIZED version of the plot cube
    var pc = ilPanel1.SceneSyncRoot.First<ILPlotCube>();

    // modify the plot cube rotation on the synched copy!
    // several example views - choose yours! 
    pc.Rotation = Matrix4.Identity;  // XY - view (default, double click)
    pc.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), Math.PI * 0.5);  // ZX - view
    pc.Rotation = Matrix4.Rotation(new Vector3(0, 1, 0), Math.PI * 0.5)
                            .Rotate(new Vector3(1, 0, 0), Math.PI * 0.5); // XZ - view 
    pc.Rotation = Matrix4.Rotation(new Vector3(0, 1, 0), Math.PI * 0.5);  // ZY - view
    ilPanel1.Refresh(); 
}

I can never really get the direction of these rotations right without drawing sketches. You will check yourself if the view is correct and prevent from looking from the wrong side/ from the back!

Also, don't get confused with ILCamera.RotateX(), ILCamera.RotateY() and ILCamera.RotateZ()! They are available on plot cubes also, since ILCamera is a base class of plot cube. The do similar things but work by adding a new rotation to the existing one, which is probably not, what you want here:

// pc.Rotate?(..) rotates the camera iteratively
pc.RotateZ(Math.PI * 0.5);  // <- this is another thing! Use pc.Rotation instead!
Haymo Kutschbach
  • 3,322
  • 1
  • 17
  • 25
  • Thank you very much, it was exactly what I was looking for. There is still a little problem with the axes if I perform a rotation like Matrix4.Rotation(new Vector3(1, 0, 0), Math.PI * 0.5).Rotate(new Vector3(0,1,0),-Math.PI*0.5); since the y axis seems not to show up. – xanz Jun 15 '14 at 21:26
  • The SO-way of saying 'thanks!' is upvoting ... ;) `Matrix4.Rotation(new Vector3(1, 0, 0), Math.PI * 0.5)` hides the Y axis and `.Rotate(new Vector3(0,1,0),-Math.PI*0.5)` doesn't bring it back. A sketch on paper sometimes helps significantly to get those rotations right ... – Haymo Kutschbach Jun 16 '14 at 08:47
  • Sorry still too low reputation to upvote! I'll come back when I'll be able to do so.. Thanks again :) – xanz Jun 16 '14 at 19:42