Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / Roma / POINT

.CPP
Скачиваний:
20
Добавлен:
16.04.2013
Размер:
2.81 Кб
Скачать
#include "types.h"
class POINT {
public :
REAL v [3];
REAL vn [2];
REAL offset[3];
POINT ( void );
POINT ( REAL x, REAL y, REAL z );
POINT ( POINT& Point );
POINT& operator = ( POINT& Point );
void Set ( REAL x, REAL y, REAL z );
void Perspective();
void SetOffset(int,int,int);
POINT& operator -= ( POINT& Point );
POINT& operator += ( POINT& Point );
POINT& operator /= ( REAL Value );
POINT& operator *= ( REAL Value );
};

// Constructor to create a point does nothing. //
POINT :: POINT ( void )
{
}
// Constructor to initialise a point with 3 triple values. //

POINT :: POINT ( REAL x, REAL y, REAL z ) {
v [0] = x;
v [1] = y;
v [2] = z;
}

// Constructor to initialise one point with another. //

POINT :: POINT ( POINT& Point ){
v [0] = Point.v [0];
v [1] = Point.v [1];
v [2] = Point.v [2];
vn[0] = Point.vn[0];
vn[1] = Point.vn[1];
}

// Set the values for a point. //
void POINT :: Set ( REAL x, REAL y, REAL z ){
v [0] = x;
v [1] = y;
v [2] = z;
Perspective();
}

// Create a real (x,y) coordinate for monitor plane (normalize) //
void POINT :: Perspective() {
vn[0]=256*v[0]/(v[2]-offset[2])+offset[0]; //256-Є®­бв ­в  е㤮¦­ЁЄ . ў§пв  Ё§ бЇа ў®з­ЁЄ 
vn[1]=256*v[1]/(v[2]-offset[2])+offset[1];
};
// Set center of coordinates axis //
void POINT::SetOffset(int xoff, int yoff, int zoff) {
offset[0]=xoff;
offset[1]=yoff;
offset[2]=zoff;
};

// Function to make this point equal another point. //
POINT& POINT :: operator = ( POINT& Point ){
v [0] = Point.v [0];
v [1] = Point.v [1];
v [2] = Point.v [2];
vn [0] = Point.vn [0];
vn [1] = Point.vn [1];

return ( *this );
}

// Function to subtract a point from this point. //
POINT& POINT :: operator -= ( POINT& Point ){
v [0] -= Point.v [0];
v [1] -= Point.v [1];
v [2] -= Point.v [2];
Perspective();
return ( *this );
}

// Function to add a point to this point. //
POINT& POINT :: operator += ( POINT& Point ){
v [0] += Point.v [0];
v [1] += Point.v [1];
v [2] += Point.v [2];
Perspective();
return ( *this );
}

// Function to add a point to this point. //

POINT& POINT :: operator /= ( REAL Value ){
v [0] /= Value;
v [1] /= Value;
v [2] /= Value;
Perspective();
return ( *this );
}

// Scale the vector by the given amount along all axis. //
POINT& POINT :: operator *= ( REAL Amount ){
v [0] *= Amount;
v [1] *= Amount;
v [2] *= Amount;
Perspective();
return ( *this );
}

Соседние файлы в папке Roma