My programming skills are not too good and em still very amateur at C# i would like to ask about Draw_Context what i am doing here is finding out angle between the joint ... what i wanted to do is when then angle comes between 70 and 90 timer starts and using Drawcontext.DrawText method show any message on the screen but as you can see i can't access the draw variable in on_time_event if i try to introduce a new variable of DrawContext and assign value of draw to it ... it gives and exception ... because new variable of Draw context never assigned a value what should i do? Please Please any help in this regard i will be very helpful
class angle
{
System.Timers.Timer timer = new System.Timers.Timer();
bool timer_start = false;
int index = 5;
public DrawingContext draw_contex;
public void angle_between_left_shoulder(Skeleton sk1, DrawingContext draw, JointType
Shoulder_cntre,
JointType Shoulder_left, JointType Elbow_left, KinectSensor sen)
{
//draw_contex= draw;
Joint sh_cntr = sk1.Joints[Shoulder_cntre];
Joint sh_left = sk1.Joints[Shoulder_left];
Joint elb_left = sk1.Joints[Elbow_left];
Vector3 v_shoulder = new Vector3(sh_cntr.Position.X, sh_left.Position.Y,
sh_cntr.Position.Z);
Vector3 v_should_l = new Vector3(sh_left.Position.X, sh_left.Position.Y,
sh_left.Position.Z);
Vector3 v_elbow_l = new Vector3(elb_left.Position.X, elb_left.Position.Y,
elb_left.Position.Z);
Vector3 va = v_shoulder - v_should_l;
Vector3 vb = v_elbow_l - v_should_l;
va = Vector3.Normalize(va);
vb = Vector3.Normalize(vb);
float len_prod = va.Length() * va.Length();
float dot_pro = Vector3.Dot(va, vb);
double angle = Math.Acos(dot_pro);
angle = angle * 180 / Math.PI;
angle = 180 - angle;
System.Windows.Point shoul_l = this.point_toScreen(sh_left.Position, sen);
draw.DrawText(new FormattedText(angle.ToString("0"), new
System.Globalization.CultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"), 16, Brushes.OrangeRed),
new System.Windows.Point(shoul_l.X+10, shoul_l.Y +20));
if (angle > 70 && angle < 90)
{
if (timer_start == false)
{
timer.Interval = 2000;
timer.Start();
timer.Elapsed += new ElapsedEventHandler(on_time_event);
}
}
}
void on_time_event(object sender, ElapsedEventArgs e)
{
--index;
if (index != 0)
{
MessageBox.Show(index.ToString());
/*
draw_contex.DrawText(new FormattedText(index.ToString("0"), new
System.Globalization.CultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"), 16, Brushes.OrangeRed),
new System.Windows.Point(10, 120));
}
else
{
timer.Stop();
}
If you're looking to simply display a formatted string in your window, you can write to a TextBlock. In your XAML, you'll have something along the lines of:
<Grid>
<!-- whatever other controls you have -->
<TextBlock Name="MyMessage" />
</Grid>
Then in your code-behind you can just write a new string to the TextBlock:
MyMessage.Text = "You moved too soon!";
You can just as easily format a string and send it to that as well.
Also, if my answer in your previous question on this subject was useful please accept it. It would be appreciated! :) body joints angle using kinect (checking time interval)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.