views:

158

answers:

8

I understand what sin and cos (and some other trigonometric functions) means, but I don't really get what kind of problems they solve. Can you show me some real world examples when you'd use some of these functions in game development (specifically 3D game development)?

Thanks.

+1  A: 

Well, an application that instantly comes to mind to me, is for special effects in game... say you have a weapon or spell or ability, or an effect of sorts, that makes a beam of light... you can play around with maths to "shape that beam"...

Same way, say you have a portal that you wish to play some neat animations upon activation or entrance, you can play around with vectors and rotation matrixes, and you can do lots of amazing things with a mix of maths and your imagination...

Luis Miguel
+2  A: 

Games in 2D or 3D space require geometry for graphics. Physics engines for modeling motion faithfully require geometry. Trig is fundamental to geometry.

Take something as simple as bouncing. The physics of a projectile hitting and wall and bouncing back will quickly convince you of the utility of trig functions.

duffymo
+4  A: 

3D models are defined by vertices (numeric lists of coordinate pairs or triplets in 3D space), and lines that connect them. Those lines make surfaces that can be rendered, lit, textured, etc.

In order to, say, rotate an object, you have to be able to manipulate those vertices. If you want to rotate an object some number of degrees or radians, you'll have ton use trig functions to figure out where it winds up.

Basic trig is fundamental to ANY 3D manipulation required for games, simulation etc. It's worth your time to investigate and become familiar with the real meaning if those functions, their limitations, and how they apply to and amplify the usefulness of geometry, signals processing, etc.

This is a great question; most just nod and act like it's obvious. Unless your first name is Blaise or Renee, it's probably not.

David Lively
+7  A: 

In game development, there are a lot of situations where you need to use the trigonometric functions. When programming a game, you'll often need to do things like find the distance between two points or make an object move. Here are a few examples:

  • Rotating a spaceship or other vehicle

  • Properly handling the trajectory of projectiles shot from a rotated weapon

  • Calculating a new trajectory after a collision between two objects such as billiard balls or heads

  • Determining if a collision between two objects is happening

  • Finding the angle of trajectory (given the speed of an object in the x direction and y direction)

Here's a good link to different areas of Math required in various types of video game development

Check these links for further reading:

http://gamedev.stackexchange.com/questions/4436/camera-field-of-view-3d-projections-trigonometry

Trigonometry for Flash Game Design

Harpreet
+3  A: 

Trigonometry is crucial to produce almost all curves (as in from ellipses or circles) and therefore has PLENTY of use in game development. Additionally, the sine wave is useful for perlin noise and lots of other special effects.

TaslemGuy
+2  A: 

One example trig functions are used is in rotation matrices

For example

This matrix is used for rotating a point in the x,y plane around the origin.

|x'| = | cos a    -sin a | | x |
|y'|   | sin a     cos a | | y |
  • x,y original points
  • x',y' translated points
  • a angle to rotate counter clockwise
mikek3332002
+3  A: 

The most obvious use of trigonometry is to get an object to move in any given direction, without trigonometry this is impossible.

//Example code, will move the object speed units in the given direction (degrees)
d2r = pi / 180; //Conversion from degrees to radians
this.x += speed * cos (direction * d2r);
this.y += speed *-sin (direction * d2r);

It is also used for other things, such as:

  • Executing transformations on 2d sprites to create rotation.
  • Is used very extensively in projecting a 3d view.
  • Due to the shape of a sine wave it can be used to create smooth transitions between 2 values.
  • Creating sine waves for the purpose of audio synthesis.
  • Drawing circular objects such as circles and spheres.
  • Determining the location of a point which is on the arm of a pivot.
Andrew Dunn
+3  A: 

Write a program that draws and updates an analog clock.

The problems you encounter while doing so should give you the answer to your question. If you have a basic understanding of sin and cos you should be able to use them to make the clock drawing pretty easy.

If that doesn't give you your answer, try to draw it without sin and cos.

Bill K