summaryrefslogtreecommitdiff
path: root/hw6/src/coordinateTransform.cpp
blob: 29e19f4c14b6052b3bc70aa129708a3e3e75ec96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************/
/* This file is part of the homework assignments for CSCI-427/527 */
/* at The College of William & Mary and authored by Pieter Peers. */
/* No part of this file, whether altered or in original form, can */
/* be distributed or used outside the context of CSCI-427/527     */
/* without consent of either the College of William & Mary or     */
/* Pieter Peers.                                                  */
/******************************************************************/
#include "coordinateTransform.h"

//////////////////
// Constructors //
//////////////////
coordinateTransformation::coordinateTransformation(void)
{
  // do nothing
}


coordinateTransformation::coordinateTransformation(const vec3d& normal)
{
  // normal == Z axis
  vec3d X, Y, Z = normalize(normal);
  
  // select Y axis
  if(fabs(Z.x) < fabs(Z.y) && fabs(Z.x) < fabs(Z.z))
    Y = normalize(vec3d(0.0f, Z.z, -Z.y));
  else if(fabs(Z.y) < fabs(Z.z))
    Y = normalize(vec3d(Z.z, 0.0f, -Z.x));
  else
    Y = normalize(vec3d(Z.y, -Z.x, 0.0f));
  
  // create other axis
  X = Y.cross(Z).normalize();

  // copy
  _transformation = mat3d(X, Y, Z);
  _inverseTransformation = transpose(_transformation);

  // Done.
}


coordinateTransformation::coordinateTransformation(const vec3d& normal, const vec3d& axis)
{
  // normal == Z axis
  vec3d Z = normalize(normal);
  
  // create other axis
  vec3d axis_normalized = normalize(axis);
  vec3d Y = Z.cross(axis_normalized).normalize();
  vec3d X = Y.cross(Z).normalize();

  // copy
  _transformation = mat3d(X, Y, Z);
  _inverseTransformation = transpose(_transformation);

  // Done.
}


coordinateTransformation::coordinateTransformation(const vec3d& X, const vec3d& Y, const vec3d& Z)
{
  // trust user to provide an orthogonal set of vectors.
  _transformation = mat3d(X, Y, Z);
  _inverseTransformation = transpose(_transformation);
}