 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
Posted: Fri Aug 24, 2007 8:54 am Post subject: |
|
|
| Jani wrote: | | zart wrote: | | Power^2. Thats the mathematical equivalent to raising a number to a certain power in c/cpp. | That's Power xor'd by 2.
|
Doh! I'm stuck in my math world again, i ment to type pow(number to raise, raise by this number) since he was already using the cmath lib. Why reinvent the wheel _________________
0x7A 0x61 0x72 0x74
TEAM RESURRECTiON |
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Fri Aug 24, 2007 10:15 am Post subject: |
|
|
Just a mathematical comment... if you are taking degrees as input, degrees^2 (math syntax not C syntax) is NOT radians, it is degrees^2.
To convert degrees to radians, you do (Degrees*2/Pi).
Wait... now I see what you are doing. Why the hell would you overload Radians() like that? That is pretty terrible. Do (Power*Power) instead. If you need to check for sign, use ternary operator:
(Power>0?(Power*Power):cout << "Power was negative")
And, why check if radians/power are positive/negative anyways? With Power it doesn't matter at all, with Radians it will just change the sign of the result. Either way, when you fail the sign test, you return the original input rather than performing the operation, that just makes the result less useful. _________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Fri Aug 24, 2007 10:50 am Post subject: |
|
|
| nog_lorp wrote: | Just a mathematical comment... if you are taking degrees as input, degrees^2 (math syntax not C syntax) is NOT radians, it is degrees^2.
To convert degrees to radians, you do (Degrees*2/Pi).
Wait... now I see what you are doing. Why the hell would you overload Radians() like that? That is pretty terrible. Do (Power*Power) instead. If you need to check for sign, use ternary operator:
(Power>0?(Power*Power):cout << "Power was negative")
And, why check if radians/power are positive/negative anyways? With Power it doesn't matter at all, with Radians it will just change the sign of the result. Either way, when you fail the sign test, you return the original input rather than performing the operation, that just makes the result less useful. |
This was just for me to test what forms can do so i just overloaded radians to tst it. And really I need a example of the use to do it.
The main goal of the program was to test what simple functions can do.
Then i decided i would post it here in hopes of getting example code of how i can make it better. You tell me do it this wayand i look it up and try it that way.
And too the person who complains about not prototyping i did do it in my third or fourth posting of the code. And i read your posts and i repped you for giving me information.And tryed as much as i could with my limited knowledge to make it better
And also you are correct about making no check for postive or negative on the angle but i still need the check for if it is over 99 since the max degree angle is 99 in the game and the min degree angle is -99 so i used Answer<100 in the if.
And on the power you can only have a postive input under 400 which = 4.0 bars of power in the game.
Oh and radians to degrees is (pi/180)*Degrees.
From "Teacherschoice.com"
| Quote: | Converting degrees to radians:
To convert degrees to radians, first find the number of half circles in the answer by dividing by 180º. But each half circle equals p radians, so multiply the number of half circles by p.
So, to convert degrees to radians, multiply by p/180,
|
I will use and try your code you offered and the formula for radians with a shot distance i know and tell you how it works. Since i dont think mine comes out right.
This is the original formula
Thanks to rhinojockey
| Quote: |
R = V^2 * sin(2ß) / g.
|
Here is my formula
| Quote: | pow(Power,2)*(sin (2 * Answer) / Gravity);
|
They come out exactly the same answer when rounded
with angle of 70 power of 295 and a gravity of 70.1
I will try your suggestions and post the results.
using (A*2/Pi) to convert to radians yeilds a result of 1139.27 or 1139 rounded.
I hate working with radians is there anyway to get a sin math function that uses degrees?
And jani nice coding but im a noob and dont fully understand all the fancy coding you did but i know this it has to be
| Code: | | return ( angle*(pi/180)); |
Also | Code: | | power = makeRadians(power); |
Was a int type in my program which was a mistake so it was overloading the function that was used to square power.
Since i was shown the pow() function the formula is now
| Code: | | ( ( pow(power,2)*sin(2*angle) ) / gravity ) |
In your program / mine.
And thank you all for replying
Especially jani for the example of this program written his way Im learning alot from it.
Im looked at the advance ones first now im looking at the simple one maybe i can understand more of it. _________________
Earthbound = 31337 |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Aug 24, 2007 12:13 pm Post subject: |
|
|
| Losplagos wrote: | Here is my formula
pow(Power,2)*(sin (2 * Answer) / Gravity); | Note that I copied your formula from your first code, so it isn't right in my code! You did "double Radians()", "not int Radians()", to Power, so I did too. (I hope you noticed how confusing your prototypes were/are.) That's why there's the question "what the hell is this used for" or something like that.
| Losplagos wrote: | | angle*(pi/180) | That's totally same as angle*pi/180( which is same as (angle*pi)/180 ), angle/180*pi, pi/180*angle.
| Losplagos wrote: | | Was a int type in my program which was a mistake so it was overloading the function that was used to square power. | I think I read somewhere that you were declaring all the variables as doubles, so I was kinda confused -> I was wondering what are you doing with "int Radians()".
EDIT: found it. Check the post posted on Fri Aug 24, 2007 6:15 am. There you changed 'em to double and I coded my things based on that post. It also affects the formula etc. My program is similar to the program in this post. I tested and it does return all the same values.
| Losplagos wrote: | | I hate working with radians is there anyway to get a sin math function that uses degrees? | Use my variable class and eg. angle.getValueAsRads() ;D Or just write a function it, like you did, but properly this time and call it always. If you learn object oriented programming, you could expand my variable class... Altho, using classes for a simple program like this, is a bit like shooting a fly with a cannon.
| Losplagos wrote: | | Especially jani for the example of this program written his way Im learning alot from it. | No problems. I'm glad to help. |
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Fri Aug 24, 2007 12:41 pm Post subject: |
|
|
Wow, not sure what the hell I was thinking when I said that for converting to radians ><.
A nice example of overloading using same function (although not uses for both):
| Code: |
double Radians(double Degrees) {
return Degrees*M_PI/180; // anyone point out yet that you should be using math.h's pi constant? :D
}
double Radians(String Degrees) {
return atof(Degrees.c_str)*M_PI/180;
} |
~nog_lorp _________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Aug 24, 2007 1:07 pm Post subject: |
|
|
| nog_lorp wrote: | | anyone point out yet that you should be using math.h's pi constant? :D | M_PI isn't a standard in C++. If someone knows more about Pi in C++, please tell. I think I used something similar like acos(-1.0); back in the days when I was messing with Pi. I don't know if it's accurate or anything, but it does it's job. |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Fri Aug 24, 2007 3:02 pm Post subject: |
|
|
| Code: |
# include <iostream>
# include <cmath>
double Radians(double);
int quitMessage();
int main ()
{
double Answer,Power, Gravity; //This Loop gets all the variables and checks them
int D;
int Z;
std::cout << "If you input a number that is not postive"
<<std::endl
<<"or over 400 for the power the " // explaining the rules
<<"program will not work Enter 0 to exit."
<<std::endl;
for (;;)
{
std::cout << "Angle?: ";
std::cin >> Answer; // The next comment full of code i need to improve any ideas?
if(Answer==0)
return quitMessage(); // Returns EXIT_SUCCESS;
Answer = Radians (Answer);
std::cout
<< "Power in pixels up too 400?"
<<std::endl;
std::cin >> Power;
if(Power==0)
return quitMessage(); // Returns EXIT_SUCCESS;
std::cout
<< "Gravity of the shot"
<<std::endl;
std::cin >> Gravity;
if(Gravity==0)
return quitMessage(); // Returns EXIT_SUCCESS;
Answer = pow(Power,2)*(sin (2 * Answer) / Gravity); // The formula*
std::cout
<< "Shot distance traveled is: "
<< Answer
<< std::endl<<std::endl;
}
return EXIT_SUCCESS;
}
double Radians (double A)// This function calculates The angle
{
const double Pi = 3.14159;
double R;
R = (A*2/Pi);
return R;
}
int quitMessage(){
std::cout << "Yawns!" << std::endl;
return EXIT_SUCCESS;} |
There is my new'st code after looking at jani's and adding a little _________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Fri Aug 24, 2007 9:20 pm Post subject: |
|
|
| Jani wrote: | | nog_lorp wrote: | anyone point out yet that you should be using math.h's pi constant?  | M_PI isn't a standard in C++. If someone knows more about Pi in C++, please tell. I think I used something similar like acos(-1.0); back in the days when I was messing with Pi. I don't know if it's accurate or anything, but it does it's job. |
Why waste CPU power to calculate an approximation for PI when you could simply define it/use a predefined constant?
And PI = 4atan(1rad). _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Aug 25, 2007 3:34 am Post subject: |
|
|
| DeltaFlyer wrote: | | Why waste CPU power to calculate an approximation for PI when you could simply define it/use a predefined constant? | What if you want to change the calculation precision? If it was defined, you need to check out the next desimals from the web etc. Calculating a few desimals of Pi on nowdays CPUs is nothing for 'em. So, why not to take advantage of our fast CPUs?
| DeltaFlyer wrote: | | And PI = 4atan(1rad). | Why this one?
@Losplagos: I'll read your code a bit later, now I've something better to do ;)
EDIT: Looks better now. Your formatting still fails a bit tho :p (eg. "if(Gravity==0)" ) What are those "int D" and "int Z" used for? It's good to keep the variable amount as low as possible. Lots of variables -> more confusing.
There are things that you could write shorter, but there's no need if you don't want to. |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sat Aug 25, 2007 9:43 am Post subject: |
|
|
| Jani wrote: | | DeltaFlyer wrote: | | Why waste CPU power to calculate an approximation for PI when you could simply define it/use a predefined constant? | What if you want to change the calculation precision? If it was defined, you need to check out the next desimals from the web etc. Calculating a few desimals of Pi on nowdays CPUs is nothing for 'em. So, why not to take advantage of our fast CPUs?
| DeltaFlyer wrote: | | And PI = 4atan(1rad). | Why this one?
@Losplagos: I'll read your code a bit later, now I've something better to do
EDIT: Looks better now. Your formatting still fails a bit tho :p (eg. "if(Gravity==0)" ) What are those "int D" and "int Z" used for? It's good to keep the variable amount as low as possible. Lots of variables -> more confusing.
There are things that you could write shorter, but there's no need if you don't want to. |
I think the int D and int Z are left overs from a earlyer revision that i forgot to take out and thanks fo replying and being helpful. _________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sat Aug 25, 2007 10:28 am Post subject: |
|
|
| Jani wrote: | | What if you want to change the calculation precision? If it was defined, you need to check out the next desimals from the web etc. Calculating a few desimals of Pi on nowdays CPUs is nothing for 'em. So, why not to take advantage of our fast CPUs? | Just because CPUs have become more powerful, it doesn't mean that programmers should abuse them with unnecessary calculations. Also, instead of checking on the internet, one could simply write a program to do the calculation, then define it as a constant.
| Jani wrote: | | Why this one? |
Just a slower alternative. Another would be imag(log(complex(-1.0,0.0))). _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun Aug 26, 2007 8:14 am Post subject: |
|
|
| DeltaFlyer wrote: | | Just because CPUs have become more powerful, it doesn't mean that programmers should abuse them with unnecessary calculations. | That's true, but calculating a few extra desimals for pi, c'mon!
| DeltaFlyer wrote: | | Just a slower alternative. Another would be imag(log(complex(-1.0,0.0))). | I know there are many alternatives, but I don't see why to choose the one. Of course accuracy affects the matter, but what else? Speed? |
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Aug 26, 2007 11:42 am Post subject: |
|
|
Alright here is my optimized source to be nice and small.
| Code: | #include <iostream>
int main()
{
std::cout << "Ok so enter a negetive number to exit the calculation program\n";
std::cout << "This program calculates how far a gunbound shot will travel\n";
std::cout << "There are your shot calculations\n Put in 0 to quit\n";
double PI,g,B,V,U,R;
for(;;)
{
std::cout << "What is The gravity of your shot?: ";
std::cin >> g;
if (g==0)
return EXIT_SUCCESS;
std::cout << "What is The angle of the shot?: ";
std::cin >> B;
if (B==0)
return EXIT_SUCCESS;
std::cout << "What is the power of the shot in pixels?: ";
std::cin >> V;
if (V==0&V>400)
return EXIT_SUCCESS;
PI = 3.14159;
U = (PI/180)*B;
R = (V*V)*sin(2*U) / g;
}
}
|
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Aug 26, 2007 6:29 pm Post subject: |
|
|
That is not called optimizing, that's called being cheap with your screen space. Not indenting the code not only hurts others when trying to read your code, but also yourself when you try to debug it.
Also,
As I understand, should be
One more thing: as by convention, variable names should be in lowerCamel case, beginning the first word with a lower case, then every other word with a capital letter. Constants such as PI should be in ALL CAPS. You can find more naming conventions online. These help people reading your code to more easily distinguish between elements. _________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|