|
3 Questions on crossed_function in lesson 14 ,thanks guru
Hello, Guru!
I'm new fans of your course, thank you so much for making a fruit pudding from hard nut.
You remind us don't forget ask questions in the end of every lessons, here they come:
When I enjoy your lesson 14, crossed funtion part, I'm confused,
Q1) At the 1st time you call crossed fuction:
int Crossed (double line1 , double line2)
{
static int last_direction = 0; //last_direction = 0
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down current_direction = 1 or 2 right?
if(current_direction != last_direction) //changed That means current_direction != last_direction will be true, then a cross signal will be given, right?
[color="Black"]
Q2: 2nd time you call it
int Crossed (double line1 , double line2)
{
static int last_direction = 0; //would last_direction be reset to 0 from =current_direction ?
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
Thanks and have a nice day!
|