Example #1
0
        //method for updating the solid cam view
        private void SolidFrameT(object myObject)//Vector3D a, Double theta)
        {
            Stopwatch stopWatch = new Stopwatch();

            double[] times = new double[8];
            stopWatch.Start();

            if (solidFrameMutex.WaitOne(0))
            {
                //no update over "noise", no update during calibration
                solidMovement = MovementFilter();
                if (!solidMovement || !mpuStable)
                {
                    solidFrameMutex.ReleaseMutex();
                    return;
                }

                lastLockedQuat = quat;
                Quaternion tempQuat = GetCorrectedQuat();
                Vector3D   a        = tempQuat.Axis;
                double     theta    = tempQuat.Angle;
                theta *= Math.PI / 180;
                //move object instead of the camera
                theta = -theta;

                //0 ms
                times[0] = stopWatch.ElapsedMilliseconds;
                try
                {
                    if (!solidDoc)
                    {
                        //5-19 ms
                        if (_swApp.ActiveDoc != null)
                        {
                            solidDoc = true;
                        }
                    }
                    //avoiding exceptions if possible
                    if (solidDoc)
                    {
                        times[1] = stopWatch.ElapsedMilliseconds;
                        //5-14 ms
                        IModelDoc doc = _swApp.ActiveDoc;
                        try
                        {
                            times[2] = stopWatch.ElapsedMilliseconds;
                            //4-6 ms somehow solid won't allow this to happen at once
                            IModelView view = doc.ActiveView;
                            times[3] = stopWatch.ElapsedMilliseconds;
                            tempQuat.Invert();
                            double[,] rotation = QuatToRotation(tempQuat);
                            //TODO: translate :(
                            //15-23 ms no need to translate just yet!
                            //MathTransform translate = view.Translation3;
                            //TODO: rescale :(
                            //no need to rescale yet either
                            //double scale = view.Scale2;
                            times[4] = stopWatch.ElapsedMilliseconds;
                            double[] tempArr = new double[16];
                            //new X axis
                            tempArr[0] = rotation[0, 0];
                            tempArr[1] = rotation[1, 0];
                            tempArr[2] = rotation[2, 0];
                            //new Y axis
                            tempArr[3] = rotation[0, 1];
                            tempArr[4] = rotation[1, 1];
                            tempArr[5] = rotation[2, 1];
                            //new Z axis
                            tempArr[6] = rotation[0, 2];
                            tempArr[7] = rotation[1, 2];
                            tempArr[8] = rotation[2, 2];
                            //translation - doesn't mater for orientation!
                            tempArr[9]  = 0;
                            tempArr[10] = 0;
                            tempArr[11] = 0;
                            //scale - doesn't mater for orientation!
                            tempArr[12] = 1;
                            //?
                            tempArr[13] = 0;
                            tempArr[14] = 0;
                            tempArr[15] = 0;
                            //? ms
                            orientation.ArrayData = tempArr;
                            times[5] = stopWatch.ElapsedMilliseconds;
                            //? ms
                            view.Orientation3 = orientation;
                            times[6]          = stopWatch.ElapsedMilliseconds;
                            //? ms
                            view.RotateAboutCenter(1, 1);
                            //view.GraphicsRedraw(new int[] { });
                            times[7] = stopWatch.ElapsedMilliseconds;
                        }
                        //no active view
                        catch (Exception ex)
                        {
                            solidDoc = false;
                            //MessageBox.Show("Unable to rotate Solid Camera!\n" + ex.ToString());
                        }
                    }
                }
                //no _swApp
                catch (Exception ex)
                {
                    solidRunning = false;
                    MessageBox.Show("Oh no! Something went wrong with Solid!\n" + ex.ToString());
                }
                solidFrameMutex.ReleaseMutex();
                stopWatch.Stop();
            }
        }