added proj() and reflect() to util/Vector, changed util/Transform to use Vector::proj() in lookAt()
git-svn-id: svn://anubis/fart/trunk@66 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
c5ac957dff
commit
08a0047ba8
@ -19,8 +19,7 @@ void Transform::lookAt(const Vector & eye,
|
||||
{
|
||||
Vector forward = focus - eye;
|
||||
forward.normalize();
|
||||
Vector up_projected_onto_forward = forward * (up % forward) / up.mag2();
|
||||
Vector perpendicular_up = (up - up_projected_onto_forward).normalize();
|
||||
Vector perpendicular_up = (up - up.proj(forward)).normalize();
|
||||
Vector right = forward * perpendicular_up;
|
||||
Matrix mult;
|
||||
mult[0][0] = right[0];
|
||||
|
@ -40,6 +40,20 @@ double Vector::mag2() const
|
||||
+ m_array[2] * m_array[2];
|
||||
}
|
||||
|
||||
Vector Vector::proj(const Vector & target) const
|
||||
{
|
||||
Vector target_normalized = target;
|
||||
target_normalized.normalize();
|
||||
return target_normalized * ((*this) % target_normalized);
|
||||
}
|
||||
|
||||
Vector Vector::reflect(const Vector & target) const
|
||||
{
|
||||
Vector projected = proj(target);
|
||||
Vector me_to_proj = projected - (*this);
|
||||
return projected + me_to_proj * 2.0;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
||||
{
|
||||
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
||||
|
@ -14,6 +14,8 @@ class Vector
|
||||
Vector & normalize();
|
||||
double mag() const;
|
||||
double mag2() const;
|
||||
Vector proj(const Vector & target) const;
|
||||
Vector reflect(const Vector & target) const;
|
||||
|
||||
private:
|
||||
double m_array[3];
|
||||
|
Loading…
x
Reference in New Issue
Block a user