Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            if (Joint == null)
            {
                try
                {
                    // A GearJoint can only have two revolutes or a revolute and a prismatic joint
                    if (Joint1.GetType() == typeof(PrismaticJointObject))
                    {
                        if (Joint2.GetType() == typeof(RevoluteJointObject))
                        {
                            Joint = JointFactory.CreateGearJoint(Level.Physics, Joint1.Joint, Joint2.Joint, Ratio);
                        }
                    }
                    else if (Joint1.GetType() == typeof(RevoluteJointObject))
                    {
                        if (Joint2.GetType() == typeof(RevoluteJointObject) || Joint2.GetType() == typeof(PrismaticJointObject))
                        {
                            Joint = JointFactory.CreateGearJoint(Level.Physics, Joint1.Joint, Joint2.Joint, Ratio);
                        }
                    }
                }
                catch (Exception e)
                {
                    #if DEBUG
                    Console.WriteLine("OMG - Wasn't able to create Gear Joint.");
                    #endif
                }
            }

            Circle.position = position;
        }
Esempio n. 2
0
        /// <inheritdoc />
        protected override void OnRender()
        {
            ImGui.SetNextWindowPos(new Vector2(10.0f, 100.0f));
            ImGui.SetNextWindowSize(new Vector2(200.0f, 100.0f));
            ImGui.Begin("Joint Controls", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize);

            if (ImGui.Checkbox("Limit", ref EnableLimit))
            {
                Joint1.EnableLimit(EnableLimit);
            }

            if (ImGui.Checkbox("Motor", ref EnableMotor))
            {
                Joint1.EnableMotor(EnableMotor);
            }

            if (ImGui.SliderFloat("Speed", ref MotorSpeed, -20.0f, 20.0f, "%.0f"))
            {
                Joint1.SetMotorSpeed(MotorSpeed);
            }

            ImGui.End();
        }
Esempio n. 3
0
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            bool dataReceived  = false;
            var  currentrecord = record;

            using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null)
                    {
                        this.bodies = new Body[bodyFrame.BodyCount];
                    }

                    // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                    // As long as those body objects are not disposed and not set to null in the array,
                    // those body objects will be re-used.
                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                    dataReceived = true;
                }
            }
            //Console.WriteLine(" foo");
            if (dataReceived)
            {
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    // Draw a transparent background to set the render size
                    dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                    int penIndex = 0;
                    foreach (Body body in this.bodies)
                    {
                        Pen drawPen = this.bodyColors[penIndex++];

                        if (body.IsTracked)
                        {
                            this.DrawClippedEdges(body, dc);

                            IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                            // convert the joint points to depth (display) space
                            Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();
                            var frame = new Frame();
                            foreach (JointType jointType in joints.Keys)
                            {
                                // sometimes the depth(Z) of an inferred joint may show as negative
                                // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                                CameraSpacePoint position = joints[jointType].Position;
                                if (position.Z < 0)
                                {
                                    position.Z = InferredZPositionClamp;
                                }

                                DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);
                                jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                var z     = joints[jointType].Position.Z * 275.36339626;
                                var joint = new Joint1();
                                joint.Name = Enum.GetName(typeof(JointType), jointType);
                                joint.X    = jointPoints[jointType].X.ToString();
                                joint.Y    = jointPoints[jointType].Y.ToString();
                                joint.Z    = z.ToString();
                                if (currentrecord)
                                {
                                    frame.Joint.Add(joint);
                                }
                            }
                            if (currentrecord)
                            {
                                signs.Sign.Frame.Add(frame);
                            }


                            this.DrawBody(joints, jointPoints, dc, drawPen);


                            this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                            this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
                        }
                    }

                    // prevent drawing outside of our render area
                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                }
            }
        }