| We hope you enjoy your visit. You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you are already a member please log in to your account to access all of our features: |
- Pages:
- 1
- 2
| Game Math c++ code snippets; Can be adapted to use in other languages | |
|---|---|
| Tweet Topic Started: Dec 12 2009, 10:28 PM (2,555 Views) | |
| Reikyrr | Dec 12 2009, 10:28 PM Post #1 |
|
Forum God
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Math snippets here! However I don't take full credit for it. Checking for a collision point inside a triangle. Returns 1 for true and 0 for false. The first six arguments are for the coordinates of the triangle. Tha last two for the position to check. Collision_point_tr (x1,y1,x2,y2,x3,y3,xx,yy); Changing Radials to Degrees. Returns Degrees RadToDeg(Radials Gets direction from a point. *NOTE* needs RadToDeg(); to function properly. Returns direction in degrees PointDirection( X1,Y1,X2,Y2 Moves a distance in a direction Returns location lengthdir That's it, if you guys want to add math snippets please do so. I will edit this post. Edited by Reikyrr, Dec 12 2009, 10:30 PM.
|
|
~Inspirational quote~ | |
![]() |
|
| Sothh | Jan 10 2010, 07:12 PM Post #2 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
In PointDirection() what is atan2'?) But I get an error: PointDirection(0,0,50,50) Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> PointDirection(0,0,50,50) File "C:\Users\Sothh\Desktop\Math.py", line 5, in PointDirection return RadToDeg(atan2(2-y1,x2-x1)) NameError: global name 'atan2' is not defined |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| skarik | Jan 10 2010, 07:18 PM Post #3 |
|
kitten eating scum
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Try Arctan2. It's the arctangent function that returns the angle in the correct quadrant unlike the regular arctanegent function. |
| Blog|EHS | |
![]() |
|
| MysteriXYZ | Jan 10 2010, 08:52 PM Post #4 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
There's a nice Python math module at your disposal . You should really use the tools available to you .
|
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| Sothh | Jan 10 2010, 10:58 PM Post #5 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I got it working! Thanks for these snippets! |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| Sothh | Feb 23 2010, 07:38 PM Post #6 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I created a handy PointMath.py package for Python. Have fun! |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| Sothh | Feb 24 2010, 06:56 PM Post #7 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Heres a snippet. It returns the distance between two points. Its in Python, but its not hard to change it for use in c++.
Edited by Sothh, Feb 24 2010, 06:57 PM.
|
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| Dr. Best | Feb 24 2010, 07:50 PM Post #8 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Interesting. So the distance from (1 1) to (0 0) is -2. I did not know that. |
![]() |
|
| Sothh | Feb 24 2010, 08:01 PM Post #9 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
What??? Thats correct... you have to go backwards by two to get to 0,0 from your current position. I am very confused...
|
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| Gandalf20000 | Feb 25 2010, 01:00 AM Post #10 |
![]()
Geek
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Try this formula instead: d=√((x2-x1)2+(y2-y1)2) Try and use that other formula, and you're as stupid as my geometry teacher at my old high school that tried to add in the distance formula when he should have been subtracting. |
![]() |
|
| Sothh | Feb 25 2010, 06:07 PM Post #11 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I fix my code (I think):
I will try to get yours working though. |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| skarik | Feb 25 2010, 06:11 PM Post #12 |
|
kitten eating scum
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Sothh, the distance from 0,0 to 1,1 is √2, not 2. You're not thinking at all about diagonals, and so your formula sort of returns the Manhattan distance. Use the Pythagorean theorem instead. |
| Blog|EHS | |
![]() |
|
| Sothh | Feb 25 2010, 06:30 PM Post #13 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Its supposed to return the Manhatten distance! |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| zeo | Feb 25 2010, 06:39 PM Post #14 |
|
I like turtles.
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I'll try contributing. This will find the area of any 2d triangle.
Oh yeah, and you need the cmath library included. (Do I really need to mention this :P?) Its useful foor.. I dunno. Edited by zeo, Feb 26 2010, 12:13 AM.
|
|
49 46 20 59 4F 55 20 43 41 4E 20 52 45 41 44 20 54 48 49 53 20 59 4F 55 20 52 45 41 4C 4C 59 20 4E 45 45 44 20 54 4F 20 47 45 54 20 4C 41 49 44 3A 29 recur-recur-recur-recur-recursion-sion-sion-sion-STACK OVERFLOW | |
![]() |
|
| Gandalf20000 | Feb 26 2010, 12:25 AM Post #15 |
![]()
Geek
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Um, even if it's Manhattan taxi distance, you're still never going to have negative distance... You should be asking for the absolute value after finding the end result. |
![]() |
|
| Go to Next Page | |
| « Previous Topic · Tutorials · Next Topic » |
- Pages:
- 1
- 2





![]](http://z1.ifrm.com/static/1/pip_r.png)



. You should really use the
.
PointMath.py (345 Bytes)

9:01 PM Jul 11