70001254 Four buttons to simulate VROT

Article 70001254
Type HowTo
Product Engine
Version 7
Date Added 1/17/2018
Fixed 7.7014.0.5 (1/17/2018)
Submitted by Hermann Deeg

Summary

I would like to develop a function that simulates CommandAction.View3D ( "VROT" ) with a kind of directional pad like UP, DOWN, LEFT RIGHT. With every click on a direction button, I would like to rotate scene in this direction by a predefined vaue. Could you please give me a hint how to do that.

Solution

Add in a form a vdFramed or vdScrollable Control and five buttons and try a code like:

       private void buttonCreateScene_Click(object sender, EventArgs e)
       {
           //doc is the vdFramed.BaseControl.ActiveDocument
           doc.New(); // just create some 3D objects for testing
           doc.CommandAction.CmdBox3d(new gPoint(2000, 1000), 3.0d, 4.0d, 5.0d, 0.0d);
           doc.CommandAction.CmdSphere(new gPoint(2008, 1003), 2.0d, 6, 7);
           doc.CommandAction.View3D("SHADEON");
           doc.CommandAction.View3D("VISE");
           doc.CommandAction.Zoom("S", 0.5, 0);
       }

       // this is the step you need to set
       double step =  VectorDraw.Geometry.Globals.DegreesToRadians(5.0d); // 5 degrees step
   
       private void buttonUP_Click(object sender, EventArgs e)
       {
           gPoint ptV = doc.ActiveLayOut.Render.ProjectionMatrix.GetInvertion().projectTransform(0, 0, 0);
           Matrix mat = new Matrix();
           mat.Multiply(doc.ActiveLayOut.World2ViewMatrix);
           mat.TranslateMatrix(ptV * -1.0d);
           mat.RotateXMatrix(step * -1.0d);
           mat.TranslateMatrix(ptV);
           doc.World2ViewMatrix = mat;
           doc.Redraw(true);
       }

       private void buttonDOWN_Click(object sender, EventArgs e)
       {
           gPoint ptV = doc.ActiveLayOut.Render.ProjectionMatrix.GetInvertion().projectTransform(0, 0, 0);
           Matrix mat = new Matrix();
           mat.Multiply(doc.ActiveLayOut.World2ViewMatrix);
           mat.TranslateMatrix(ptV * -1.0d);
           mat.RotateXMatrix(step);
           mat.TranslateMatrix(ptV);
           doc.World2ViewMatrix = mat;
           doc.Redraw(true);
       }

       private void buttonRIGHT_Click(object sender, EventArgs e)
       {
           gPoint ptV = doc.ActiveLayOut.Render.ProjectionMatrix.GetInvertion().projectTransform(0, 0, 0);
           Matrix mat = new Matrix();
           mat.Multiply(doc.ActiveLayOut.World2ViewMatrix);
           mat.TranslateMatrix(ptV * -1.0d);
           mat.RotateYMatrix(step * -1.0d);
           mat.TranslateMatrix(ptV);
           doc.World2ViewMatrix = mat;
           doc.Redraw(true);
       }

       private void buttonLEFT_Click(object sender, EventArgs e)
       {
           gPoint ptV = doc.ActiveLayOut.Render.ProjectionMatrix.GetInvertion().projectTransform(0, 0, 0);
           Matrix mat = new Matrix();
           mat.Multiply(doc.ActiveLayOut.World2ViewMatrix);
           mat.TranslateMatrix(ptV * -1.0d);
           mat.RotateYMatrix(step);
           mat.TranslateMatrix(ptV);
           doc.World2ViewMatrix = mat;
           doc.Redraw(true);
       }

 

Send comments on this topic.