Powered by Invision Power Board

 
  Pages: (2) [1] 2  ( Go to first unread post ) Reply to this topicStart new topicStart Poll

> GML for C++, C++ Implementations of GML Functions
United States
OniLink10
Posted: Jun 24 2009, 03:11 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


GML.cpp:
CODE
#include <cmath>

const double pi = 3.14159265358979; // Pi to the max accuracy of double

double abs(double x)
{
return fabs(x); // Just a Wrapper
}

double sign(double x)
{
return -(x<0) + (x>0); // Xgoff is the best Poster
}

double round(double x)
{
if (x-floor(x) < 0.5) // If Rounding down
 return (x%1); // Round Down
else // Otherwise
 return ((x%1)+1); // Round Up
}

double point_distance(double x1, double y1, double x2, double y2)
{
return (sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))); // Pythagorean Theorem FTW
}

double point_direction(double x1, double y1, double x2, double y2)
{
double degrees = (atan2(y2-y1, x2-x1)*180/pi); // Get the Angle in Radians from atan2 and convert it to Degrees.
return (degrees < 0 ? 360+degrees : degrees); // Just correcting atan2
}

double lengthdir_x(double length, double dir)
{
return cos(dir*pi/180)*length; // Thanks RetroXYZ!
}

double lengthdir_y(double length, double dir)
{
return -sin(dir*pi/180)*length; // Thanks RetroXYZ!
}


Update History:
6/24/2009: Released with point_direction
6/26/2009: Added abs(x), sign(x), round(x), and point_distance(x1, y1, x2, y2)
6/27/2009: Fixed a really STUPID mistake is round(x), added lengthdir_x and lengthdir_y thanks to RetroXYZ, and edited sign(x) to use a very clever technique by Xgoff.

This post has been edited by OniLink10 on Jun 27 2009, 10:44 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Xgoff
Posted: Jun 24 2009, 04:00 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


i like this more :(

QUOTE
const double PI = 3.14159265358979;
const double RAD_TO_DEG = 180 / PI;

double direction_to_point(double x1, double y1, double x2, double y2)
{
double result = atan2(y2 - y1, x2 - x1) * RAD_TO_DEG;
return result < 0 ? 360 + result : result;
}


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
OniLink10
Posted: Jun 24 2009, 05:26 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Xgoff @ Jun 24 2009, 02:00 PM)
i like this more sad.gif


That would work. It's just a different way of writing it.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
Canada
DJ Yoshiman
  Posted: Jun 24 2009, 09:07 PM
Quote Post


My post is to the right.
[M][S][*][*][*]
[*][*][*][*][*]
[*][*]

Group Icon
Group: Moderators
Posts: 18175
Member No.: 141
Joined: 16-November 03

Status: (0d) [--]


QUOTE (OniLink10 @ Jun 24 2009, 03:26 PM)
That would work. It's just a different way of writing it.

i like Xgoff's better


it's shorter and won't take up as much room


--------------------

user posted image

The Music of DJ Yoshiman - Official Website

Latest News:
I Like To Bonk It Bonk It

NUMBER OF TRIALS:
12
PMEmail PosterUsers WebsiteAOLYahooMSN
Top
United Kingdom
Kyori
Posted: Jun 24 2009, 09:09 PM
Quote Post


I'm a GUY >.<
[*][*]

Group Icon
Group: Members
Posts: 1467
Member No.: 6088
Joined: 13-March 09

Status: (0d) [--]


QUOTE (OniLink10 @ Jun 24 2009, 10:26 PM)
That would work. It's just a different way of writing it.

Less variables in xgoff's.


--------------------
user posted image
PMEmail PosterAOLMSN
Top
United States
OniLink10
Posted: Jun 25 2009, 09:40 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


Took xgoff's and renamed the variable, removed the RADTODEG, and added Parenthesis in case your Compiler is retarded and doesn't know Order of Operations.

This post has been edited by OniLink10 on Jun 25 2009, 09:40 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
Austria
Guinea
Posted: Jun 26 2009, 05:44 AM
Quote Post


6
[A][*][*][*][*]
[*][*][*][*][*]
[*]

Group Icon
Group: Admins
Posts: 8600
Member No.: 893
Joined: 15-March 05

Status: (0d) [--]


May I ask why you posted this?
It's just one function, and that isn't really rocket science either.

Unless you're planning to expand on that and create a DLL with such.
PMEmail PosterAOLMSN
Top
United States
RetroXYZ
Posted: Jun 26 2009, 09:39 AM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


I'm half tempted to see if you copied that function from ENIGMA and posted it here. sad.gif

Anyways, why does this deserve a topic? No offense, but a majority of MFGG doesn't know C++, and the minority that does already knows how to do this.
PMEmail PosterMSN
Top
United States
OniLink10
Posted: Jun 26 2009, 02:47 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Guinea @ Jun 26 2009, 03:44 AM)
May I ask why you posted this?
It's just one function, and that isn't really rocket science either.

Unless you're planning to expand on that and create a DLL with such.

I'm planning on expanding with more functions, and probably going to turn it into a gml.cpp type of file that people can add to their projects so they can use GML functionality(Not a GML Compiler like ENIGMA).

@RetroX: No, I did not copy anything from ENIGMA.

This post has been edited by OniLink10 on Jun 26 2009, 03:00 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
SuperMarioMaster
Posted: Jun 26 2009, 03:16 PM
Quote Post


It's been real
[*]

Group Icon
Group: Members
Posts: 2145
Member No.: 4476
Joined: 22-September 07

Status: (0d) [--]


QUOTE (OniLink10 @ Jun 26 2009, 03:47 PM)
I'm planning on expanding with more functions, and probably going to turn it into a gml.cpp type of file that people can add to their projects so they can use GML functionality(Not a GML Compiler like ENIGMA).

I would like that :]


--------------------
PMEmail Poster
Top
Austria
Guinea
Posted: Jun 27 2009, 01:08 PM
Quote Post


6
[A][*][*][*][*]
[*][*][*][*][*]
[*]

Group Icon
Group: Admins
Posts: 8600
Member No.: 893
Joined: 15-March 05

Status: (0d) [--]


Why do you return "x-floor(x)" in the "round()" function?
Wouldn't just "floor(x)" be what you'd get?
PMEmail PosterAOLMSN
Top
United States
MrGuy
Posted: Jun 27 2009, 02:31 PM
Quote Post


NO WAY also im gay
[*][*][*]

Group Icon
Group: Members
Posts: 424
Member No.: 4680
Joined: 9-November 07

Status: (0d) [--]


QUOTE (Guinea @ Jun 27 2009, 01:08 PM)
Why do you return "x-floor(x)" in the "round()" function?
Wouldn't just "floor(x)" be what you'd get?

Yeah, I'm not understanding that logic either; x-floor(x) would return the decimal places of x.

Also, (x-floor(x)) can be replaced with (x % 1) anyway.

This post has been edited by MrGuy on Jun 27 2009, 02:31 PM
PMEmail Poster
Top
United States
OniLink10
Posted: Jun 27 2009, 08:56 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


Oh whoops, I was tired when I did that. Fixing...


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Xgoff
Posted: Jun 27 2009, 09:53 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


being an asshole again

QUOTE
double sign(double val)
{
return -(val < 0) + (val > 0);  
}


i bet someone can find an instance where that'll break horribly

This post has been edited by Xgoff on Jun 27 2009, 09:54 PM


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Retriever II
Posted: Jun 27 2009, 09:57 PM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Xgoff @ Jun 27 2009, 10:53 PM)
being an asshole again



i bet someone can find an instance where that'll break horribly

Well it's clever.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
United States
Xgoff
Posted: Jun 27 2009, 10:01 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Retriever II @ Jun 27 2009, 08:57 PM)
Well it's clever.

not as clever as me trying to shift out the sign bit

didn't want to work :(


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
RetroXYZ
Posted: Jun 27 2009, 10:02 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


P.S.: If someone gets to the point where they know C++ but don't know these simple math functions then I don't know what to say.

Also, here's something slightly more useful (although someone who knows C++ should still know how to do this, also uses the DEG_TO_RAD and pi variables from the first post):
CODE
double lengthdir_x(double length,double dir)
{
return cos(dir*DEG_TO_RAD)*length;
}

double lengthdir_y(double length,double dir)
{
return -sin(dir*DEG_TO_RAD)*length;
}


This post has been edited by RetroXYZ on Jun 27 2009, 10:16 PM
PMEmail PosterMSN
Top
United States
OniLink10
Posted: Jun 27 2009, 10:42 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (RetroXYZ @ Jun 27 2009, 08:02 PM)
P.S.: If someone gets to the point where they know C++ but don't know these simple math functions then I don't know what to say.

Also, here's something slightly more useful (although someone who knows C++ should still know how to do this, also uses the DEG_TO_RAD and pi variables from the first post):
CODE
double lengthdir_x(double length,double dir)
{
return cos(dir*DEG_TO_RAD)*length;
}

double lengthdir_y(double length,double dir)
{
return -sin(dir*DEG_TO_RAD)*length;
}

Nice job. Keep in mind that just because someone can program in C++, doesn't mean that they are good at math.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
RetroXYZ
Posted: Jun 27 2009, 10:45 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


QUOTE (OniLink10 @ Jun 27 2009, 11:42 PM)
just because someone can program in C++, doesn't mean that they are good at math.

Programming = Math

But not everyone knows trig, so I guess you're somewhat right.
PMEmail PosterMSN
Top
United States
Bacteriophage
Posted: Jun 27 2009, 10:49 PM
Quote Post


injustice anywhere is a threat to justice everywhere
[*][*][*][*][*]
[*][*][*][*][*]
[*][*][KFC]

Group Icon
Group: Members
Posts: 10716
Member No.: 2411
Joined: 31-July 06

Status: (0d) [--]


QUOTE (RetroXYZ @ Jun 27 2009, 08:45 PM)
Programming = Math

No?


--------------------
PMEmail PosterUsers WebsiteAOLMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Pages: (2) [1] 2  Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0895 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.29 ]