Пример #1
0
        private void calibrationVRtoRobot()
        {
            Vector3 vrPoint = Util.Math.GetTranslationVector3(UtilOld.getControllerTipPosition(ref mScene, true));

            vrCallibrationPoints.Add(vrPoint);
            Rhino.RhinoApp.WriteLine("add vrCallibrationPoints: " + vrPoint.ToString());
            UtilOld.MarkPoint(ref mScene.staticGeometry, vrPoint, 1, 1, 0);
            if (vrCallibrationPoints.Count == 8)
            {
                Util.Math.solveForAffineTransformOpenCV(vrCallibrationPoints, robotCallibrationPoints, ref mScene.vrToRobot);
                foreach (Vector3 v in robotCallibrationPoints)
                {
                    Vector4 v4 = new Vector4(v.X, v.Y, v.Z, 1);
                    v4 = mScene.vrToRobot.Inverted() * v4;
                    UtilOld.MarkPoint(ref mScene.staticGeometry, new Vector3(v4.X, v4.Y, v4.Z), 0, 1, 0);
                }
                Rhino.RhinoApp.WriteLine(mScene.vrToRobot.ToString());
                Rhino.RhinoApp.WriteLine(mScene.vrToRobot.M11 + "f, " + mScene.vrToRobot.M12 + "f, " + mScene.vrToRobot.M13 + "f, " + mScene.vrToRobot.M14 + "f,");
                Rhino.RhinoApp.WriteLine(mScene.vrToRobot.M21 + "f, " + mScene.vrToRobot.M22 + "f, " + mScene.vrToRobot.M23 + "f, " + mScene.vrToRobot.M24 + "f,");
                Rhino.RhinoApp.WriteLine(mScene.vrToRobot.M31 + "f, " + mScene.vrToRobot.M32 + "f, " + mScene.vrToRobot.M33 + "f, " + mScene.vrToRobot.M34 + "f,");
                Rhino.RhinoApp.WriteLine(mScene.vrToRobot.M41 + "f, " + mScene.vrToRobot.M42 + "f, " + mScene.vrToRobot.M43 + "f, " + mScene.vrToRobot.M44 + "f");
                robotCallibrationPoints.Clear();
                vrCallibrationPoints.Clear();
            }
        }
Пример #2
0
        public void getMatrixHeadtoCamera(uint primaryDeviceIndex)
        {
            Vector3 center = new Vector3(0, 0, 0);

            if (vr_points.Count < 8)
            {
                //only use left controller for the calibration
                center = Math.GetTranslationVector3(UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx));
                Rhino.RhinoApp.WriteLine(center.ToString());

                vr_points.Add(new MCvPoint3D32f(center.X, center.Y, center.Z));
                calib_status = 0;
            }
            else
            {
                marker_points.Add(new MCvPoint3D32f(0, 0, 0));
                marker_points.Add(new MCvPoint3D32f(3, 0, 0));
                marker_points.Add(new MCvPoint3D32f(3, 3, 0));
                marker_points.Add(new MCvPoint3D32f(0, 3, 0));

                marker_points.Add(new MCvPoint3D32f(0, 0, -4.0f));
                marker_points.Add(new MCvPoint3D32f(3.0f, 0, -4.0f));
                marker_points.Add(new MCvPoint3D32f(3.0f, 3.0f, -4.0f));
                marker_points.Add(new MCvPoint3D32f(0, 3.0f, -4.0f));

                CvInvoke.EstimateAffine3D(vr_points.ToArray(), marker_points.ToArray(), out mVRtoMarker, out inliers, 3, 0.99);

                glmVRtoMarker = new Matrix4(
                    (float)mVRtoMarker[0, 0], (float)mVRtoMarker[0, 1], (float)mVRtoMarker[0, 2], (float)mVRtoMarker[0, 3],
                    (float)mVRtoMarker[1, 0], (float)mVRtoMarker[1, 1], (float)mVRtoMarker[1, 2], (float)mVRtoMarker[1, 3],
                    (float)mVRtoMarker[2, 0], (float)mVRtoMarker[2, 1], (float)mVRtoMarker[2, 2], (float)mVRtoMarker[2, 3],
                    0, 0, 0, 1
                    );

                calib_status = 1;
                Rhino.RhinoApp.WriteLine("VRtoMarker matrix");
                Rhino.RhinoApp.WriteLine(glmVRtoMarker.ToString());

                vr_points.Clear();
                marker_points.Clear();

                //Thread start to calculate the view matrix
                ThreadEnd    = false;
                UpdateThread = new Thread(new ThreadStart(Camera_UpdateThread));
                UpdateThread.Start();
            }
        }
Пример #3
0
        protected override void onClickOculusGrip(ref VREvent_t vrEvent)
        {
            if (targetPRhObjID == Guid.Empty || currentState != State.READY)
            {
                return;
            }

            currentState  = State.MOVEPLANE;
            movePlaneRef  = new ObjRef(targetPRhObjID);
            lastTranslate = 0.0f;

            //get the plane info
            RhinoObject movePlaneObj = movePlaneRef.Object();

            planeNormal = new Rhino.Geometry.Vector3d();
            //PointOnObject still null at this point
            if (movePlaneObj.Attributes.Name.Contains("planeXY"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(0, 0, 1);
            }
            else if (movePlaneObj.Attributes.Name.Contains("planeYZ"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(1, 0, 0);
            }
            else if (movePlaneObj.Attributes.Name.Contains("planeXZ"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(0, 1, 0);
            }

            OpenTK.Vector4 controller_p     = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z));

            float translate = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;

            //move from the porjection point not origin
            moveControlerOrigin = new Point3d(0 + translate * planeNormal.X, 0 + translate * planeNormal.Y, 0 + translate * planeNormal.Z);
        }
Пример #4
0
        public override void draw(bool isTop)
        {
            //visualize the point on the plane
            if (onPlane && isTop)
            {
                //ray casting to the pre-defind planes
                OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
                OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
                Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
                Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));

                Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_pRhino.X, controller_pZRhin.Y - controller_pRhino.Y, controller_pZRhin.Z - controller_pRhino.Z);
                Ray3d ray = new Ray3d(controller_pRhino, direction);

                Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep;
                //settings.NameFilter = "plane";
                float mimD = 1000000f;
                hitPlane = false;
                if (!lockPlane)
                {
                    foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings))
                    {
                        //only drawing on planes for now rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("plane")
                        if (rhObj.Attributes.Name.Contains("plane"))
                        {
                            List <GeometryBase> geometries = new List <GeometryBase>();
                            geometries.Add(rhObj.Geometry);
                            //must be a brep or surface, not mesh
                            Point3d[] rayIntersections = Rhino.Geometry.Intersect.Intersection.RayShoot(ray, geometries, 1);
                            if (rayIntersections != null)
                            {
                                //get the nearest one
                                OpenTK.Vector3 tmpP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                                float          distance = (float)Math.Sqrt(Math.Pow(tmpP.X - controller_p.X, 2) + Math.Pow(tmpP.Y - controller_p.Y, 2) + Math.Pow(tmpP.Z - controller_p.Z, 2));

                                if (distance < mimD)
                                {
                                    hitPlane     = true;
                                    targetPRhObj = rhObj;
                                    mimD         = distance;
                                    projectP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (targetPRhObj != null)
                    {
                        List <GeometryBase> geometries = new List <GeometryBase>();
                        geometries.Add(targetPRhObj.Geometry);
                        //must be a brep or surface, not mesh
                        Point3d[] rayIntersections = Rhino.Geometry.Intersect.Intersection.RayShoot(ray, geometries, 1);
                        if (rayIntersections != null)
                        {
                            //get the nearest one
                            OpenTK.Vector3 tmpP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                            float          distance = (float)Math.Sqrt(Math.Pow(tmpP.X - controller_p.X, 2) + Math.Pow(tmpP.Y - controller_p.Y, 2) + Math.Pow(tmpP.Z - controller_p.Z, 2));

                            if (distance < mimD)
                            {
                                hitPlane = true;
                                mimD     = distance;
                                projectP = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                            }
                        }
                    }
                }

                if (!hitPlane)
                {
                    targetPRhObj = null;
                    projectP     = new OpenTK.Vector3(100, 100, 100); //make it invisable
                }

                //visualize the projection points
                // inverted rotation first

                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(UtilOld.transformPoint(mScene.tableGeometry.transform.Inverted(), projectP));
                t.Transpose();
                drawPoint.transform = t;
            }


            if (currentState != State.PAINT || !isTop)
            {
                return;
            }

            // drawing curve
            Vector3 pos = new Vector3();

            if (onPlane)
            {
                pos = projectP;
                if (hitPlane)
                {
                    //GeometryStroke handle rotation
                    ((Geometry.GeometryStroke)stroke_g).addPoint(pos);
                    rhihoPointList.Add(UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, pos)));
                }
            }
            else
            {
                pos = Util.Math.GetTranslationVector3(UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx));
                //GeometryStroke handle rotation already
                ((Geometry.GeometryStroke)stroke_g).addPoint(pos);
                rhihoPointList.Add(UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, pos)));
            }

            if (((Geometry.GeometryStroke)stroke_g).mNumPrimitives == 1)
            {
                SceneNode stroke = new SceneNode("Stroke", ref stroke_g, ref stroke_m);
                mScene.tableGeometry.add(ref stroke);
                //mScene.staticGeometry.add(ref stroke);
                strokeId = stroke.guid;
            }

            //testing the performance of rhino curve
            if (rhihoPointList.Count == 2)
            {
                rcurve = Curve.CreateInterpolatedCurve(rhihoPointList.ToArray(), 3);
            }
            else if (rhihoPointList.Count > 2)
            {
                rcurve.Extend(Rhino.Geometry.CurveEnd.End, Rhino.Geometry.CurveExtensionStyle.Line, rhihoPointList[rhihoPointList.Count - 1]);
            }
        }
Пример #5
0
        private void createModel()
        {
            /*
             * Rhino.Geometry.Point3d origin = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, 0)));
             * Rhino.Geometry.Point3d normalP1 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -0.05f)));
             * Rhino.Geometry.Point3d normalP2 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -1)));
             * Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(normalP2.X - normalP1.X, normalP2.Y - normalP1.Y, normalP2.Z - normalP1.Z);
             * Plane plane = new Plane(origin, normal);
             * float radius = 20;
             * Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, origin, radius);
             * NurbsCurve circleCurve = circle.ToNurbsCurve();
             *
             * //compute transform to follow controllers
             * OpenTK.Matrix4 tansform = mScene.robotToPlatform * mScene.vrToRobot * Util.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx);
             * Transform t = Util.OpenTKToRhinoTransform(tansform);
             * circleCurve.Transform(t);
             * Brep[] shapes = Brep.CreatePlanarBreps(circleCurve);
             * Brep circle_s = shapes[0];
             * Brep circleBrep = circle_s;
             *
             * Guid renderObjId = Util.addSceneNode(ref mScene, circleBrep, ref mesh_m, "circle");
             */


            //offset the point a little bit to make the plane better
            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -0.05f, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));


            //fix the x and y axis of the model Plane
            OpenTK.Vector4 controller_x1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(1, 0, 0, 1);
            OpenTK.Vector4 controller_y1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 1, 0, 1);
            Point3d        controller_x1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_x1.X, controller_x1.Y, controller_x1.Z)));
            Point3d        controller_y1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_y1.X, controller_y1.Y, controller_y1.Z)));

            OpenTK.Vector4 controller_o      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            Point3d        controller_oRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_o.X, controller_o.Y, controller_o.Z)));

            Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_oRhino.X, controller_pZRhin.Y - controller_oRhino.Y, controller_pZRhin.Z - controller_oRhino.Z);
            normal.Unitize();
            modelPlane = new Plane(controller_oRhino, normal);

            if (shapeType == ShapeType.Circle)
            {
                Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(modelPlane, controller_oRhino, radius);
                modelcurve = circle.ToNurbsCurve();
            }
            else if (shapeType == ShapeType.Rect)
            {
                Rhino.Geometry.Vector3d xAxis = new Rhino.Geometry.Vector3d(controller_x1Rhino.X - controller_oRhino.X, controller_x1Rhino.Y - controller_oRhino.Y, controller_x1Rhino.Z - controller_oRhino.Z);
                xAxis.Unitize();
                Rhino.Geometry.Vector3d yAxis = new Rhino.Geometry.Vector3d(controller_y1Rhino.X - controller_oRhino.X, controller_y1Rhino.Y - controller_oRhino.Y, controller_y1Rhino.Z - controller_oRhino.Z);
                yAxis.Unitize();

                modelPlane.XAxis = xAxis;
                modelPlane.YAxis = yAxis;

                //Rectangle3d rect = new Rectangle3d(modelPlane, width, height);
                Rectangle3d rect = new Rectangle3d(modelPlane, new Interval(-width / 2, width / 2), new Interval(-height / 2, height / 2));
                modelcurve = rect.ToNurbsCurve();
            }

            if (modelcurve != null)
            {
                Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                modelBrep = shapes[0];
                UtilOld.updateSceneNode(ref mScene, modelBrep, ref mesh_m, "3D-" + shapeType.ToString(), ref previewObjSN);
            }
        }
Пример #6
0
        public override void draw(bool isTop)
        {
            if (!isTop)
            {
                return;
            }

            // Clean this monstrosity
            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));

            Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_pRhino.X, controller_pZRhin.Y - controller_pRhino.Y, controller_pZRhin.Z - controller_pRhino.Z);

            if (drawnType != DrawnType.In3D)
            {
                UtilOld.rayCasting(controller_pRhino, direction, ref rayCastingObjs, ref projectP, out targetPRhObjID);
            }
            else
            {
                projectP = controller_pRhino;
            }

            //only snap for the first drawing point
            if (currentState != State.DRAW && snapPointsList.Count > 0)
            {
                if (UtilOld.snapToPoints(ref projectP, ref snapPointsList) != -1)
                {
                    isSnap = true;
                    snapPointSN.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    isSnap = false;
                    snapPointSN.material = new Material.SingleColorMaterial(0, 1, 0, 1);
                }
            }

            //
            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            if (drawnType != DrawnType.In3D)
            {
                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(projectPVR);
                t.Transpose();
                drawPoint.transform = t;
                if (targetPRhObjID != Guid.Empty)
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 0);
                }
            }



            //moving XYZ planes
            if (currentState == State.MOVEPLANE)
            {
                OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)) - UtilOld.RhinoToOpenTKPoint(moveControlerOrigin);

                float translate    = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;
                float relTranslate = translate - lastTranslate;
                lastTranslate = translate;

                Matrix4 transM = Matrix4.CreateTranslation(new Vector3(relTranslate * (float)planeNormal.X, relTranslate * (float)planeNormal.Y, relTranslate * (float)planeNormal.Z));
                transM.Transpose();
                UtilOld.updateRhinoObjectSceneNode(ref mScene, ref movePlaneRef, UtilOld.OpenTKToRhinoTransform(transM));
            }



            if (currentState != State.DRAW)
            {
                return;
            }
            else
            {
                //checking the projectPoint is valid
                if (drawnType != DrawnType.In3D && targetPRhObjID == Guid.Empty)
                {
                    return;
                }
            }

            //drawing curve section belows
            if (shouldSnap && ((Geometry.GeometryStroke)stroke_g).mNumPoints == 0)
            {
                ((Geometry.GeometryStroke)stroke_g).addPoint(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(snapPointsList[0])));
            }

            ((Geometry.GeometryStroke)stroke_g).addPoint(projectPVR);
            rhinoCurvePoints.Add(projectP);

            if (((Geometry.GeometryStroke)stroke_g).mNumPrimitives == 1)
            {
                strokeSN = new SceneNode("Stroke", ref stroke_g, ref stroke_m);
                UtilOld.addSceneNode(ref mScene, ref strokeSN);
            }

            //create rhino curve for comoputing length of the curve
            if (rhinoCurvePoints.Count == 2)
            {
                if (shouldSnap)
                {
                    //make sure the first point is the snap point if necessary
                    if (UtilOld.computePointDistance(UtilOld.RhinoToOpenTKPoint(rhinoCurvePoints[0]), UtilOld.RhinoToOpenTKPoint(snapPointsList[0])) != 0)
                    {
                        rhinoCurvePoints.Insert(0, snapPointsList[0]);
                    }
                }
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
            }
            else if (rhinoCurvePoints.Count > 2)
            {
                double length1 = rhinoCurve.GetLength();
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
                double length2 = rhinoCurve.GetLength();
                displacement = displacement + (float)Math.Abs(length2 - length1);

                //TODO-Debug why it failed
                //rhinoCurve = rhinoCurve.Extend(Rhino.Geometry.CurveEnd.End, Rhino.Geometry.CurveExtensionStyle.Line, rhinoCurvePoints[rhinoCurvePoints.Count - 1]);

                //dynamic render model
                //TODO: finding the right curve
                if (dynamicRender != "none" && backgroundStart == false && displacement > 10)
                {
                    backgroundStart = true;
                    R = d.BeginInvoke(new AsyncCallback(modelCompleted), null);
                }
            }
        }
Пример #7
0
        public override void draw(bool isTop)
        {
            if (!isTop)
            {
                return;
            }


            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));

            Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_pRhino.X, controller_pZRhin.Y - controller_pRhino.Y, controller_pZRhin.Z - controller_pRhino.Z);

            if (drawnType != DrawnType.In3D)
            {
                UtilOld.rayCasting(controller_pRhino, direction, ref rayCastingObjs, ref projectP, out targetPRhObjID);
            }
            else
            {
                projectP = controller_pRhino;
            }

            //TODO-only snap for the first drawing point
            if (pointMarkers.Count == 0 && targetPRhObjID != Guid.Empty)
            {
                computeContourCurve();
                UtilOld.snapToPoints(ref projectP, ref snapPointsList);
            }

            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            if (drawnType != DrawnType.In3D)
            {
                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(projectPVR);
                t.Transpose();
                drawPoint.transform = t;
                if (targetPRhObjID != Guid.Empty)
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 0);
                }
            }



            //moving XYZ planes
            if (currentState == State.MOVEPLANE)
            {
                OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)) - UtilOld.RhinoToOpenTKPoint(moveControlerOrigin);

                float translate    = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;
                float relTranslate = translate - lastTranslate;
                lastTranslate = translate;

                Matrix4 transM = Matrix4.CreateTranslation(new Vector3(relTranslate * (float)planeNormal.X, relTranslate * (float)planeNormal.Y, relTranslate * (float)planeNormal.Z));
                transM.Transpose();
                UtilOld.updateRhinoObjectSceneNode(ref mScene, ref movePlaneRef, UtilOld.OpenTKToRhinoTransform(transM));
            }
        }