Lerp

Math | Sunday 5 October 2008 6:57 pm

Lerp is the procedure to interpolate between two vectors with a specified weight. An example below

float weight; // the weight for lerping
 
vec2 input1, input2; // the inputs to lerp between
 
vec2 lerpResult = input1(1.0-weight)+input2(weight);

In GLSL it’s named mix( genType, genType, float ) instead of lerp which can be misleading. But when testing, it actually works to use lerp instead of mix in GLSL shaders when running them on a Nvidia GeForce 8800GTS although it’s not recommended.

Here’s the OpenGL GLSL quick reference guide which contains all functions you can use inside of a shader (and much more).
 http://www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf

Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

Scaling

Math | Sunday 5 October 2008 12:35 am

 Scaling can be archived by the following matrix:

Scale Matrix

The s components are the scaling factor in the x-,y- and z-directions. If they are all the same then the scaling is uniform.

Uniform Scaling

In OpenGL you can do scaling with the following code:

glMatrixMode(GL_MODELVIEW);
glScalef(sx,sy, sz);
Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

Translation

Math | Sunday 5 October 2008 12:22 am

In 3D programming translation is often represented as a matrix. The following matrix translates a point by a vector Translation Vector.

The matrix for translation is given below (notice that only points can be translated, not vectors)
Translation Matrix
The inverse of the matrix is simply T(-t).

In OpenGL you can do translation on objects with the following two lines of code. The first line sets that it’s the modelview matrix that you want to perform calculations on.

glMatrixMode(GL_MODELVIEW); 
glTranslatef(tx, ty, tz);
Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

Angle between two vectors

Math | Sunday 28 September 2008 7:49 pm

Here’s the formula to get the angle between two vectors in 2D space.

vector2 diff = target - position;
float angle = atan2(diff.y, diff.x);
Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks
« Previous PageNext Page »