fixed view plane distance calculation to use tan() and convert degrees to radians
git-svn-id: svn://anubis/fart/trunk@41 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
a1c81e5adc
commit
20eafaf9f4
@ -54,7 +54,7 @@ Scene::Scene(map<string, const char *> options,
|
||||
}
|
||||
|
||||
/* view plane distance is calculated based on the field of view */
|
||||
m_view_plane_dist = (m_height / 2.0) / atan(m_vfov / 2.0);
|
||||
m_view_plane_dist = (m_height / 2.0) / tan(M_PI * m_vfov / 360.0);
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
@ -73,7 +73,7 @@ void Scene::load(const char * filename)
|
||||
{
|
||||
/* TODO: parse file somehow */
|
||||
Shape * shape = new Sphere(1.0);
|
||||
m_transform.translate(2.0, 2.0, 0.0);
|
||||
m_transform.translate(2.0, 4.0, 1.0);
|
||||
shape->setTransform(m_transform);
|
||||
m_shapes.push_back(shape);
|
||||
}
|
||||
|
@ -19,15 +19,27 @@ Vector::Vector(double x, double y, double z)
|
||||
|
||||
Vector & Vector::normalize()
|
||||
{
|
||||
double length = sqrt(m_array[0] * m_array[0]
|
||||
+ m_array[1] * m_array[1]
|
||||
+ m_array[2] * m_array[2]);
|
||||
double length = mag();
|
||||
m_array[0] /= length;
|
||||
m_array[1] /= length;
|
||||
m_array[2] /= length;
|
||||
return *this;
|
||||
}
|
||||
|
||||
double Vector::mag()
|
||||
{
|
||||
return sqrt(m_array[0] * m_array[0]
|
||||
+ m_array[1] * m_array[1]
|
||||
+ m_array[2] * m_array[2]);
|
||||
}
|
||||
|
||||
double Vector::mag2()
|
||||
{
|
||||
return m_array[0] * m_array[0]
|
||||
+ m_array[1] * m_array[1]
|
||||
+ m_array[2] * m_array[2];
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
||||
{
|
||||
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
||||
|
@ -12,6 +12,8 @@ class Vector
|
||||
double & operator[](int idx) { return m_array[idx]; }
|
||||
double operator[](int idx) const { return m_array[idx]; }
|
||||
Vector & normalize();
|
||||
double mag();
|
||||
double mag2();
|
||||
|
||||
private:
|
||||
double m_array[3];
|
||||
|
Loading…
x
Reference in New Issue
Block a user