Трехмерная графика
| Категория реферата: Рефераты по информатике, программированию
| Теги реферата: реферат на тему жизнь, реферат по экологии
| Добавил(а) на сайт: Суворов.
Предыдущая страница реферата | 1 2 3 4 5 6 7 8 | Следующая страница реферата
// Файл vector.h
#ifndef __VECTOR__
#define __VECTOR__
#include
class Vector
{
public: double x, y, z;
Vector () {};
Vector ( double v ) { x = y = z = v; };
Vector ( const Vector& v ) { x = v.x; y = v.y; z = v.z; };
Vector ( double vx, double vy, double vz ) { x = vx; y = vy; z = vz; };
Vector& operator = ( const Vector& v ) { x = v.x; y = v.y; z = v.z; return *this; }
Vector& operator = ( double f ) { x = y = z = f; return *this; };
Vector operator - () const;
Vector& operator += ( const Vector& );
Vector& operator -= ( const Vector& );
Vector& operator *= ( const Vector& );
Vector& operator *= ( double );
Vector& operator /= ( double ); friend Vector operator + ( const Vector&, const Vector& ); friend Vector operator - ( const Vector&, const Vector& ); friend Vector operator * ( const Vector&, const Vector& ); friend Vector operator * ( double, const Vector& ); friend Vector operator * ( const Vector&, double ); friend Vector operator / ( const Vector&, double ); friend Vector operator / ( const Vector&, const Vector& ); friend double operator & ( const Vector& u, const Vector& v )
{ return u.x * v.x + u.y * v.y + u.z * v.z; }; friend Vector operator ^ ( const Vector&, const Vector& ); double operator ! () { return (double) sqrt ( x * x + y * y + z * z ); }; double& operator [] ( int n ) { return *( &x + n ); }; int operator < ( double v ) { return x < v && y < v && z < v; }; int operator > ( double v ) { return x > v && y > v && z > v; };
};
class Ray
{
public:
Vector Org;
Vector Dir;
Ray () {};
Ray ( Vector& o, Vector& d ) { Org = o, Dir = d; };
Vector Point ( double t ) { return Org + Dir * t; };
};
inline Vector Vector :: operator - () const
{ return Vector ( -x, -y, -z );
}
inline Vector operator + ( const Vector& u, const Vector& v )
{ return Vector ( u.x + v.x, u.y + v.y, u.z + v.z );
}
inline Vector operator - ( const Vector& u, const Vector& v )
{ return Vector ( u.x - v.x, u.y - v.y, u.z - v.z );
}
inline Vector operator * ( const Vector& u, const Vector& v )
{ return Vector ( u.x * v.x, u.y * v.y, u.z * v.z );
}
inline Vector operator * ( const Vector& u, double f )
{ return Vector ( u.x * f, u.y * f, u.z * f );
}
inline Vector operator * ( double f, const Vector& v )
{ return Vector ( f * v.x, f * v.y, f * v.z );
}
inline Vector operator / ( const Vector& u, const Vector& v )
{ return Vector ( u.x / v.x, u.y / v.y, u.z / v.z );
}
inline Vector operator / ( const Vector& u, double f )
{ return Vector ( u.x / f, u.y / f, u.z / f );
}
inline Vector& Vector :: operator += ( const Vector& v )
{ x += v.x; y += v.y; z += v.z; return *this;
}
inline Vector& Vector :: operator -= ( const Vector& v )
{ x -= v.x; y -= v.y; z -= v.z; return *this;
}
inline Vector& Vector :: operator *= ( const Vector& v )
{ x *= v.x; y *= v.y; z *= v.z; return *this;
}
inline Vector& Vector :: operator *= ( double v )
{ x *= v; y *= v; z *= v; return *this;
}
inline Vector& Vector :: operator /= ( double v )
{ x /= v; y /= v; z /= v; return *this;
}
inline Vector Normalize ( Vector& v ) { return v / !v; }
Vector RndVector ();
Vector& Clip ( Vector& v );
#endif
----------------------------------------------------------------------------
// Файл vector.срр
#include
#include
#include "vector.h"
Vector operator ^ ( const Vector& u, const Vector& v )
{ return Vector ( u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x );
}
Vector RndVector ()
{
Vector v ( rand () - 0.5 * RAND_MAX, rand () - 0.5 * RAND_MAX, rand () - 0.5 * RAND_MAX ); return Normalize ( v );
}
Рекомендуем скачать другие рефераты по теме: рефераты рб, культурология шпаргалки.
Категории:
Предыдущая страница реферата | 1 2 3 4 5 6 7 8 | Следующая страница реферата