home dev games gallery work
Lewpen.com»Research & Development»3D Graphics»OpenGL»Reflective Sphere

Reflective Sphere

Analytical reflections in OpenGL

/ Source / common / 001 / vector.cpp

#include <math.h>

#include "vector.h"




//---- vector_length

double vector_length( double x, double y, double z )
{
  return sqrt( x*x + y*y + z*z );
}





//---- vector_normalise

void vector_normalise(double *x, double *y, double *z)
{
  double d = sqrt( *x * *x + *y * *y + *z * *z );

  d = 1.0 / d;

  *x *= d;
  *y *= d;
  *z *= d;
}





//---- vector_normalise

void vector_normalise( double *x, double *y, double *z, double length )
{
  double d = sqrt(*x**x+*y**y+*z**z);
  if( d <= 0 ) return;
  d = length / d;
  *x *= d;
  *y *= d;
  *z *= d;
}





//---- vector_cross

void vector_cross(double *x, double *y, double *z, double ax, double ay, double az, double bx, double by, double bz)
{
  *x = ay*bz - az*by;
  *y = az*bx - ax*bz;
  *z = ax*by - ay*bx;
}



//---- vector_rotate_x

void vector_rotate_x( double *x, double *y, double *z, double angle )
{
  double s = sin(angle*2.0*3.1415926), c = cos(angle*2.0*3.1415926);

  double ny = *y * c - *z * s;
         *z = *y * s + *z * c;

  *y = ny;
}



//---- vector_rotate_y

void vector_rotate_y( double *x, double *y, double *z, double angle )
{
  double s = sin(angle*2.0*3.1415926), c = cos(angle*2.0*3.1415926);

  double nx = *x * c - *z * s;
         *z = *x * s + *z * c;
  
  *x = nx;
}



//---- vector_rotate_z

void vector_rotate_z( double *x, double *y, double *z, double angle )
{
  double s = sin(angle*2.0*3.1415926), c = cos(angle*2.0*3.1415926);

  double nx = *x * c - *y * s;
         *y = *x * s + *y * c;
  
  *x = nx;
}
Related Articles

Procedural city block layout

Animated 4-dimensional objects mapped down to 3D

Simulating a cloth falling and slipping over objects

Windows C++ OpenGL example

Games

The Dodge Game
Flatspace

2-Player Games:

Quake 2D
Meteora

Puzzle Games:

Mini Tetris
Sudoku Solver

Development

3D Graphics:

3D Graphics Articles
WebGL Examples
OpenGL Examples
Flash 3D Engine
Java 3D Engine

Development:

Programming Articles
Game Development Examples

Work

Portfolio
Clients
Startups & Projects
Expertise

Links

CubeLogix Studios
PHP Charts & Graphs
Local Legends Football