added normalize() to Vector, made Ray normalize its direction
git-svn-id: svn://anubis/gvsu@369 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
a970d30fed
commit
aca3651366
@ -9,6 +9,7 @@ Ray::Ray(const Vector & origin, const Vector & direction)
|
|||||||
{
|
{
|
||||||
m_origin = origin;
|
m_origin = origin;
|
||||||
m_direction = direction;
|
m_direction = direction;
|
||||||
|
m_direction.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
Vector::Vector()
|
Vector::Vector()
|
||||||
{
|
{
|
||||||
@ -9,6 +10,16 @@ Vector::Vector()
|
|||||||
m_array[2] = 0.0;
|
m_array[2] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vector::normalize()
|
||||||
|
{
|
||||||
|
double length = sqrt(m_array[0] * m_array[0]
|
||||||
|
+ m_array[1] * m_array[1]
|
||||||
|
+ m_array[2] * m_array[2]);
|
||||||
|
m_array[0] /= length;
|
||||||
|
m_array[1] /= length;
|
||||||
|
m_array[2] /= length;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
||||||
{
|
{
|
||||||
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
||||||
|
@ -11,6 +11,7 @@ class Vector
|
|||||||
~Vector();
|
~Vector();
|
||||||
double & operator[](int idx) { return m_array[idx]; }
|
double & operator[](int idx) { return m_array[idx]; }
|
||||||
double operator[](int idx) const { return m_array[idx]; }
|
double operator[](int idx) const { return m_array[idx]; }
|
||||||
|
void normalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_array[3];
|
double m_array[3];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user