내 프로그래밍 기술이 너무 좋지 않아 여전히 C에서 매우 아마추어 # 내가 Draw_Context에 대해 물어보고 싶은데요 내가 뭘하고있는 건지 관절 사이의 각도를 찾는 것입니다 ... 내가 원했던 것 할 때 그때 각도가 70과 90 사이의 타이머가 시작되면 DrawContext.DrawText 메서드를 사용하여 화면에 메시지를 표시 하지만 볼 수 있듯이 나는 새로운 변수를 소개하려고하면 on_time_event에서 그리기 변수에 액세스 할 수 없습니다 DrawContext의 값을 지정하고 그 값에 draw 값을 할당합니다 ... 그리기 컨텍스트의 새 변수에 값이 할당되지 않았기 때문에 예외가 발생합니다. 어떻게해야합니까? 당신은 단순히 당신의 창에서 포맷 된 문자열을 표시하기 위해 찾고 있다면이 점에서 어떤 도움 내가DrawContext 변수에 전역으로 액세스 할 수 있습니까? (내 애플 리케이션의 모든 클래스에서)
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();
}