Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / cos sin tan

Author
Message
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 3rd Jun 2005 03:24
would it be possible to explain how these work in game making as ive only ever used them to do stuff with triangles in school which was about 2 years ago?

thanks

kR

kR
FROGGIE!
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: in front of my computer
Posted: 3rd Jun 2005 03:36
it works in pretty much the same way as triangles, you just need to know how to get the triangle first. Basically if you're trying to find the tan of angle A then it can be done like this:

Tan(A) = Opposite/Adjacent which could also be:
Tan(A) = difference in x axis/difference in z axis

Ive used tan because it is the easiest to work out. The hypotenuse can be worked out using pythagoras: SQRT(X_difference^2 + Z_difference^2) = hypotenuse. This would allow you to use Sin and Cos.

The only problem i find is that the sin, cos, tan commands are pretty slow when used in every sync so you're probably better using the newx/zvalue wherever you can instead.
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd Jun 2005 05:13
Here's a code that uses cos/sin:



Immunity and Annihalation makes Immunihalation...
EddieB
20
Years of Service
User Offline
Joined: 29th Sep 2004
Location: United Kingdom
Posted: 3rd Jun 2005 05:15
Sven B, He he , Thats fun watching. Great bit of code there
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd Jun 2005 05:20
no problem.

If you want to see how this effect is done with text:
http://forum.thegamecreators.com/?m=forum_view&t=54923&b=10

Immunity and Annihalation makes Immunihalation...
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 3rd Jun 2005 06:46
OMG its the way that the sin cos commands are presented is what daunts me so confusing

kR
Evil Inside
19
Years of Service
User Offline
Joined: 1st Jun 2005
Location:
Posted: 3rd Jun 2005 08:01
sin cos tan, are thingy ma jigys in calculators arn't they?

-- EVIL INSIDE PENTIUM 666 666.0Ghz || 4GB DDR RAM || 80GB HARD DRIVE || WINXP PRO ||
LordDario
22
Years of Service
User Offline
Joined: 26th Apr 2003
Location:
Posted: 3rd Jun 2005 08:35
trig is actually pretty useful in programming. In terms of gaming you could create really nice looking menu's or sweet effects by using these commands.
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 4th Jun 2005 01:04 Edited at: 4th Jun 2005 01:05
I usually use them for FPS games. Either to find the distance between things such as walls, checkpoints, save points, enemies, etc. Also, I use them for gun swaying(To make the gun move back and forth when the player walks or jumps). I use parabola equations to make the player jump. Physics is used for better collision and advanced effects, but it gets really gets complicated, so I usually don't add any real physics in my FPS games.

kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 4th Jun 2005 02:23
whoa collison with these! thats gonna be complicated! my collsion sysem is so boringiy simplistic. maths collison will be somethign ill have to learn someday soon

kR
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 5th Jun 2005 11:30 Edited at: 5th Jun 2005 11:58
kRx,

It is standard for me to use cos and sin to move my character with a given angle.



In my experiments, which are usually done with basic 2d commands, for quickness, I draw with cos and sin. For example, in any experiment that contains a character holding a gun, I use cos and sin to draw an offsetted line from the character, as the barrel of the gun.



I've also used them, in the same manner as above, to create the physics of a bouncing ball, by changing the rate of change of 'angle'. The snippet below is a fully runnable program.



I have used them in my experiments on raycasting, which ruled very well results.



If you notice the showcase section of thegamecreators homepage, you will see a program, which I believe is called Chaos. It displays many 3d spheres all in one clean mess. It's nice.

My knowledge of cos and sin is very, very limited. However, these are a couple of great examples of their abilities. Though, much more complex tasks are doable with them.


+NanoBrain+
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 5th Jun 2005 14:03
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 6th Jun 2005 04:35
cheers that was helpful

kR
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 6th Jun 2005 16:40
Forgive me, I have a wonderful acronym for remembering SOH CAH TOA.

Some
Old
Hippie

Caught
A
High

Trippin
On
Acid

Crazy Donut Productions
Current Project: A Redneck game
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 6th Jun 2005 23:23
LOL very good ill never forget that i always forgot SOH CAH TOA back in the old fays when i did maths. not much use for trig in law so forgotten it all

kR
Robot
20
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 7th Jun 2005 00:17
or maybe

The Cat Sat
On An Orange
And Howled Horribly

The happenings of tommorow are behind us now

Login to post a reply

Server time is: 2025-05-22 20:30:39
Your offset time is: 2025-05-22 20:30:39