Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
So I have this program where a user touches the screen and it records its coordinates, and then the user can move around the screen and when they pick up their finger it records the coordinates again. Here's the code
So I want to find the angle between the two points. I have the right equations I think but when I try to use, for example, touchPointend.x outside of touchesEnded, it says it is undeclared.
Declare the touchPointend and touchPointbegin as an instance variable in your header file, then you can store their value in touchesBegin and End while still being able to access them in the rest of your program.
Declare the touchPointend and touchPointbegin as an instance variable in your header file, then you can store their value in touchesBegin and End while still being able to access them in the rest of your program.
Yea I'm trying to do that. In the header file I put
CGPoint *touchPointend; CGPoint *touchPointbegin;
But what do I change to my original code.
It says the local declaration hides the instance variable.
Yea I'm trying to do that. In the header file I put
CGPoint *touchPointend; CGPoint *touchPointbegin;
But what do I change to my original code.
It says the local declaration hides the instance variable.
Thanks for any help.
KP
Get rid of the local variables touchPointend and touchPointbegin. If you have 2 variables with the same name, the compiler can't tell which one your are referring to, and uses the local variable, ignoring the instance variable.
Once you get rid of the local variables, referring to touchPointend or touchPointbegin changes the value of the instance variable. The instance variable sticks around as long as the object sticks around, so you can do math with touchPointend and touchPointbegin.
BTW, the function you need to calculate the angle between two points is atan2(change_in_x, change_in_y). That will give you an angle in radians. You can then convert that to degrees if you need it in degrees.
First of thanks for everyones help so far. I am just still confused because I thought I dropped the local declaration, but it stil won't work so I must be doing something wrong.
First of thanks for everyones help so far. I am just still confused because I thought I dropped the local declaration, but it stil won't work so I must be doing something wrong.
I feel like there is something really simple that I am missing. Sorry if I'm asking a dumb question.
KP
I don't see anything obvious wrong. What doesn't work? Do you get a compiler error? Does it crash? Do you get a result different than you expect? Please be specific.
So I have this program where a user touches the screen and it records its coordinates, and then the user can move around the screen and when they pick up their finger it records the coordinates again. Here's the code
So I want to find the angle between the two points. I have the right equations I think but when I try to use, for example, touchPointend.x outside of touchesEnded, it says it is undeclared.
Any ideas?
-KP
You need 3 points to determine an angle, not 2. Unless you're looking for Euler angles?
I don't see anything obvious wrong. What doesn't work? Do you get a compiler error? Does it crash? Do you get a result different than you expect? Please be specific.
Sorry I should have been more specific. When I compile it I recieve an error that says...
touchPointend undeclared here
Kalimba;209922 said:
You've got this line of code floating out in the middle of nowhere. What is it supposed to be doing there?
Yes also I should have explained it. It is just a test to see if I can use touchPointend's coordinates outside of touchedEnded. So basically I have:
The statement that begins "float xpoint =" is not inside any method or function. You can't put executable code outside of the body of a method or function. That is why you are getting an error.
If you simply move the closing brace ("}") down below the NSLog statement, everything should be fine.
The statement that begins "float xpoint =" is not inside any method or function. You can't put executable code outside of the body of a method or function. That is why you are getting an error.
If you simply move the closing brace ("}") down below the NSLog statement, everything should be fine.
The equation might be a little off right now. When the angle of the swipe goes past 180 degrees it goes into negative 180 and then goes back to 0. I'd rather it go all the way to 360. I think that is easily fixed though.
Anyway thanks to Duncan C, hm50, Dudd, icebeing, and Kalimba for helping me out.
Once I get the angle to work the way I want I'll try to put this up for open source code
So what happens in the view is that when the user swipes anywhere on the screen it shows the angle of the swipe in a text view.
Now what I want is to have a button at the bottom so that when the user "touches down" it records the coordinates, and then when the user "lifts up outside" it records the coordinates and does all the computations. Basically I want to replace touchesBegan and touchesEnded with my Button actions.
So I first tried replacing -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event and -(void)touchesBegan with my IBAction but it would say touches isn't declared which I understand why. But then I put
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYea I'm trying to do that. In the header file I put
But what do I change to my original code.
It says the local declaration hides the instance variable.
Thanks for any help.
KP
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeOnce you get rid of the local variables, referring to touchPointend or touchPointbegin changes the value of the instance variable. The instance variable sticks around as long as the object sticks around, so you can do math with touchPointend and touchPointbegin.
BTW, the function you need to calculate the angle between two points is atan2(change_in_x, change_in_y). That will give you an angle in radians. You can then convert that to degrees if you need it in degrees.
Regards,
Duncan C
WareTo
Check out our apps in the Apple App store
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSupport Indie Devs!! (that goes for newbs too!)
Apps:
Spell Blocks
<a href="http://phobos.a
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere's my header file:
and here is the implementation:
I feel like there is something really simple that I am missing. Sorry if I'm asking a dumb question.
KP
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI don't see anything obvious wrong. What doesn't work? Do you get a compiler error? Does it crash? Do you get a result different than you expect? Please be specific.
Regards,
Duncan C
WareTo
Check out our apps in the Apple App store
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome/ice
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesometouchPointend undeclared here
Yes also I should have explained it. It is just a test to see if I can use touchPointend's coordinates outside of touchedEnded. So basically I have:
I check the console to see if it works, and it works great when I put it inside touchesEnded like this....
but when it like this:
I can't seem to get it to work. It says touchPointend is undeclared even though I thought I declared it globally.
Any ideas?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe statement that begins "float xpoint =" is not inside any method or function. You can't put executable code outside of the body of a method or function. That is why you are getting an error.
If you simply move the closing brace ("}") down below the NSLog statement, everything should be fine.
Regards,
Duncan C
WareTo
Check out our apps in the Apple App store
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks so much. That works great. Here's me revised code that works:
The equation might be a little off right now. When the angle of the swipe goes past 180 degrees it goes into negative 180 and then goes back to 0. I'd rather it go all the way to 360. I think that is easily fixed though.
Anyway thanks to Duncan C, hm50, Dudd, icebeing, and Kalimba for helping me out.
Once I get the angle to work the way I want I'll try to put this up for open source code
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSo what happens in the view is that when the user swipes anywhere on the screen it shows the angle of the swipe in a text view.
Now what I want is to have a button at the bottom so that when the user "touches down" it records the coordinates, and then when the user "lifts up outside" it records the coordinates and does all the computations. Basically I want to replace touchesBegan and touchesEnded with my Button actions.
Here's my code:
So I first tried replacing -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event and -(void)touchesBegan with my IBAction but it would say touches isn't declared which I understand why. But then I put
and it just says the method for endTracking is not found. I know what I am doing wrong but I just don't know how to do it right.
Any ideas?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome